Built motion from commit 06eb8eb0.|2.6.31
[motion2.git] / server / api / squareMessage / squareMessage.rpc.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x8801=['options','raw','then','CreateSquareMessage','debug','util','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','client','http','info','request\x20sent','SquareMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','SquareMessage,\x20%s,\x20%s','message','result','catch','create','body'];(function(_0x201319,_0xed17ce){var _0x84c5be=function(_0x37db25){while(--_0x37db25){_0x201319['push'](_0x201319['shift']());}};_0x84c5be(++_0xed17ce);}(_0x8801,0xad));var _0x1880=function(_0x28f09f,_0x5d7c60){_0x28f09f=_0x28f09f-0x0;var _0x1d7650=_0x8801[_0x28f09f];return _0x1d7650;};'use strict';var _=require('lodash');var util=require(_0x1880('0x0'));var moment=require(_0x1880('0x1'));var BPromise=require('bluebird');var rs=require(_0x1880('0x2'));var fs=require('fs');var Redis=require(_0x1880('0x3'));var db=require(_0x1880('0x4'))['db'];var utils=require(_0x1880('0x5'));var logger=require(_0x1880('0x6'))(_0x1880('0x7'));var config=require(_0x1880('0x8'));var jayson=require('jayson/promise');var client=jayson[_0x1880('0x9')][_0x1880('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x5eae09,_0x3135aa,_0x294a55){return new BPromise(function(_0x18801e,_0x1a84ea){return client['request'](_0x5eae09,_0x294a55)['then'](function(_0x3b36ff){logger[_0x1880('0xb')]('SquareMessage,\x20%s,\x20%s',_0x3135aa,_0x1880('0xc'));logger['debug'](_0x1880('0xd'),_0x3135aa,_0x1880('0xc'),JSON[_0x1880('0xe')](_0x3b36ff));if(_0x3b36ff[_0x1880('0xf')]){if(_0x3b36ff['error'][_0x1880('0x10')]===0x1f4){logger[_0x1880('0xf')](_0x1880('0x11'),_0x3135aa,_0x3b36ff['error'][_0x1880('0x12')]);return _0x1a84ea(_0x3b36ff[_0x1880('0xf')][_0x1880('0x12')]);}logger[_0x1880('0xf')](_0x1880('0x11'),_0x3135aa,_0x3b36ff[_0x1880('0xf')][_0x1880('0x12')]);return _0x18801e(_0x3b36ff['error'][_0x1880('0x12')]);}else{logger['info']('SquareMessage,\x20%s,\x20%s',_0x3135aa,_0x1880('0xc'));_0x18801e(_0x3b36ff[_0x1880('0x13')]['message']);}})[_0x1880('0x14')](function(_0x1b3bbf){logger[_0x1880('0xf')]('SquareMessage,\x20%s,\x20%s',_0x3135aa,_0x1b3bbf);_0x1a84ea(_0x1b3bbf);});});}exports['CreateSquareMessage']=function(_0x30fa17){var _0x2fe3d1=this;return new Promise(function(_0x58407c,_0x52c646){return db['SquareMessage'][_0x1880('0x15')](_0x30fa17[_0x1880('0x16')],{'raw':_0x30fa17[_0x1880('0x17')]?_0x30fa17[_0x1880('0x17')][_0x1880('0x18')]===undefined?!![]:![]:!![]})[_0x1880('0x19')](function(_0x590f9c){logger[_0x1880('0xb')](_0x1880('0x1a'),_0x30fa17);logger[_0x1880('0x1b')](_0x1880('0x1a'),_0x30fa17,JSON[_0x1880('0xe')](_0x590f9c));_0x58407c(_0x590f9c);})[_0x1880('0x14')](function(_0x3a5d95){logger[_0x1880('0xf')](_0x1880('0x1a'),_0x3a5d95['message'],_0x30fa17);_0x52c646(_0x2fe3d1[_0x1880('0xf')](0x1f4,_0x3a5d95[_0x1880('0x12')]));});});};