285a179d472cf70d388781b2929a5e04da4b274a
[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 _0xb3c4=['stringify','error','message','result','catch','CreateSquareMessage','SquareMessage','body','options','raw','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','client','then','info','SquareMessage,\x20%s,\x20%s','request\x20sent','debug','SquareMessage,\x20%s,\x20%s,\x20%s'];(function(_0x34e111,_0x3c2abd){var _0x4dcc22=function(_0x5d9293){while(--_0x5d9293){_0x34e111['push'](_0x34e111['shift']());}};_0x4dcc22(++_0x3c2abd);}(_0xb3c4,0xb2));var _0x4b3c=function(_0x3d99c8,_0x5a87e4){_0x3d99c8=_0x3d99c8-0x0;var _0x1a9782=_0xb3c4[_0x3d99c8];return _0x1a9782;};'use strict';var _=require(_0x4b3c('0x0'));var util=require(_0x4b3c('0x1'));var moment=require(_0x4b3c('0x2'));var BPromise=require(_0x4b3c('0x3'));var rs=require(_0x4b3c('0x4'));var fs=require('fs');var Redis=require(_0x4b3c('0x5'));var db=require(_0x4b3c('0x6'))['db'];var utils=require(_0x4b3c('0x7'));var logger=require(_0x4b3c('0x8'))(_0x4b3c('0x9'));var config=require(_0x4b3c('0xa'));var jayson=require('jayson/promise');var client=jayson[_0x4b3c('0xb')]['http']({'port':0x232a});function respondWithRpcPromise(_0xfd523e,_0xebe36,_0x13a7aa){return new BPromise(function(_0x9ca4d3,_0x4cc572){return client['request'](_0xfd523e,_0x13a7aa)[_0x4b3c('0xc')](function(_0x351875){logger[_0x4b3c('0xd')](_0x4b3c('0xe'),_0xebe36,_0x4b3c('0xf'));logger[_0x4b3c('0x10')](_0x4b3c('0x11'),_0xebe36,_0x4b3c('0xf'),JSON[_0x4b3c('0x12')](_0x351875));if(_0x351875[_0x4b3c('0x13')]){if(_0x351875['error']['code']===0x1f4){logger['error'](_0x4b3c('0xe'),_0xebe36,_0x351875[_0x4b3c('0x13')][_0x4b3c('0x14')]);return _0x4cc572(_0x351875[_0x4b3c('0x13')][_0x4b3c('0x14')]);}logger['error']('SquareMessage,\x20%s,\x20%s',_0xebe36,_0x351875['error'][_0x4b3c('0x14')]);return _0x9ca4d3(_0x351875[_0x4b3c('0x13')][_0x4b3c('0x14')]);}else{logger[_0x4b3c('0xd')](_0x4b3c('0xe'),_0xebe36,_0x4b3c('0xf'));_0x9ca4d3(_0x351875[_0x4b3c('0x15')][_0x4b3c('0x14')]);}})[_0x4b3c('0x16')](function(_0xe919){logger['error']('SquareMessage,\x20%s,\x20%s',_0xebe36,_0xe919);_0x4cc572(_0xe919);});});}exports[_0x4b3c('0x17')]=function(_0x35fabc){var _0x10f59c=this;return new Promise(function(_0x523113,_0x22fd48){return db[_0x4b3c('0x18')]['create'](_0x35fabc[_0x4b3c('0x19')],{'raw':_0x35fabc[_0x4b3c('0x1a')]?_0x35fabc[_0x4b3c('0x1a')][_0x4b3c('0x1b')]===undefined?!![]:![]:!![]})['then'](function(_0x2f615e){logger[_0x4b3c('0xd')](_0x4b3c('0x17'),_0x35fabc);logger[_0x4b3c('0x10')](_0x4b3c('0x17'),_0x35fabc,JSON['stringify'](_0x2f615e));_0x523113(_0x2f615e);})['catch'](function(_0x151dc6){logger[_0x4b3c('0x13')](_0x4b3c('0x17'),_0x151dc6[_0x4b3c('0x14')],_0x35fabc);_0x22fd48(_0x10f59c[_0x4b3c('0x13')](0x1f4,_0x151dc6['message']));});});};