8a50e151310b69872bbc2f140661950c918ed24b
[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 _0xd1b3=['../../config/logger','../../config/environment','jayson/promise','http','request','then','SquareMessage,\x20%s,\x20%s','request\x20sent','SquareMessage,\x20%s,\x20%s,\x20%s','stringify','code','error','message','info','result','catch','CreateSquareMessage','body','options','raw','debug','lodash','util','../../mysqldb','../../config/utils'];(function(_0x58dc25,_0x49b9d5){var _0x21b0a7=function(_0x38a186){while(--_0x38a186){_0x58dc25['push'](_0x58dc25['shift']());}};_0x21b0a7(++_0x49b9d5);}(_0xd1b3,0xdd));var _0x3d1b=function(_0x31ae68,_0x2a0f26){_0x31ae68=_0x31ae68-0x0;var _0x6a8201=_0xd1b3[_0x31ae68];return _0x6a8201;};'use strict';var _=require(_0x3d1b('0x0'));var util=require(_0x3d1b('0x1'));var moment=require('moment');var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0x3d1b('0x2'))['db'];var utils=require(_0x3d1b('0x3'));var logger=require(_0x3d1b('0x4'))('rpc');var config=require(_0x3d1b('0x5'));var jayson=require(_0x3d1b('0x6'));var client=jayson['client'][_0x3d1b('0x7')]({'port':0x232a});function respondWithRpcPromise(_0x1a8fda,_0x4e969d,_0x4cb6f5){return new BPromise(function(_0x268708,_0x2232db){return client[_0x3d1b('0x8')](_0x1a8fda,_0x4cb6f5)[_0x3d1b('0x9')](function(_0xfbf092){logger['info'](_0x3d1b('0xa'),_0x4e969d,_0x3d1b('0xb'));logger['debug'](_0x3d1b('0xc'),_0x4e969d,_0x3d1b('0xb'),JSON[_0x3d1b('0xd')](_0xfbf092));if(_0xfbf092['error']){if(_0xfbf092['error'][_0x3d1b('0xe')]===0x1f4){logger[_0x3d1b('0xf')](_0x3d1b('0xa'),_0x4e969d,_0xfbf092[_0x3d1b('0xf')][_0x3d1b('0x10')]);return _0x2232db(_0xfbf092[_0x3d1b('0xf')][_0x3d1b('0x10')]);}logger[_0x3d1b('0xf')]('SquareMessage,\x20%s,\x20%s',_0x4e969d,_0xfbf092[_0x3d1b('0xf')][_0x3d1b('0x10')]);return _0x268708(_0xfbf092[_0x3d1b('0xf')][_0x3d1b('0x10')]);}else{logger[_0x3d1b('0x11')]('SquareMessage,\x20%s,\x20%s',_0x4e969d,_0x3d1b('0xb'));_0x268708(_0xfbf092[_0x3d1b('0x12')][_0x3d1b('0x10')]);}})[_0x3d1b('0x13')](function(_0xd37d51){logger[_0x3d1b('0xf')](_0x3d1b('0xa'),_0x4e969d,_0xd37d51);_0x2232db(_0xd37d51);});});}exports[_0x3d1b('0x14')]=function(_0x3b5b14){var _0x5bfcbc=this;return new Promise(function(_0x33d7e9,_0x3f187e){return db['SquareMessage']['create'](_0x3b5b14[_0x3d1b('0x15')],{'raw':_0x3b5b14[_0x3d1b('0x16')]?_0x3b5b14[_0x3d1b('0x16')][_0x3d1b('0x17')]===undefined?!![]:![]:!![]})['then'](function(_0x46bced){logger[_0x3d1b('0x11')](_0x3d1b('0x14'),_0x3b5b14);logger[_0x3d1b('0x18')]('CreateSquareMessage',_0x3b5b14,JSON[_0x3d1b('0xd')](_0x46bced));_0x33d7e9(_0x46bced);})[_0x3d1b('0x13')](function(_0x2337cf){logger[_0x3d1b('0xf')](_0x3d1b('0x14'),_0x2337cf[_0x3d1b('0x10')],_0x3b5b14);_0x3f187e(_0x5bfcbc[_0x3d1b('0xf')](0x1f4,_0x2337cf[_0x3d1b('0x10')]));});});};