8f38f0fe16582af7cd107da5989ea7a9c23232cd
[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 _0x3f71=['catch','CreateSquareMessage','SquareMessage','body','options','raw','stringify','lodash','util','moment','bluebird','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','client','http','then','info','SquareMessage,\x20%s,\x20%s','debug','request\x20sent','error','code','message','result'];(function(_0x1f511c,_0x5d4dc8){var _0x528093=function(_0x16134a){while(--_0x16134a){_0x1f511c['push'](_0x1f511c['shift']());}};_0x528093(++_0x5d4dc8);}(_0x3f71,0x181));var _0x13f7=function(_0x4d07cc,_0x587613){_0x4d07cc=_0x4d07cc-0x0;var _0x42de3b=_0x3f71[_0x4d07cc];return _0x42de3b;};'use strict';var _=require(_0x13f7('0x0'));var util=require(_0x13f7('0x1'));var moment=require(_0x13f7('0x2'));var BPromise=require(_0x13f7('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x13f7('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0x13f7('0x5'));var logger=require(_0x13f7('0x6'))(_0x13f7('0x7'));var config=require(_0x13f7('0x8'));var jayson=require('jayson/promise');var client=jayson[_0x13f7('0x9')][_0x13f7('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x3bbef9,_0x4ca762,_0x192ec0){return new BPromise(function(_0x3df86d,_0x54de13){return client['request'](_0x3bbef9,_0x192ec0)[_0x13f7('0xb')](function(_0x328b9d){logger[_0x13f7('0xc')](_0x13f7('0xd'),_0x4ca762,'request\x20sent');logger[_0x13f7('0xe')]('SquareMessage,\x20%s,\x20%s,\x20%s',_0x4ca762,_0x13f7('0xf'),JSON['stringify'](_0x328b9d));if(_0x328b9d['error']){if(_0x328b9d[_0x13f7('0x10')][_0x13f7('0x11')]===0x1f4){logger[_0x13f7('0x10')](_0x13f7('0xd'),_0x4ca762,_0x328b9d['error'][_0x13f7('0x12')]);return _0x54de13(_0x328b9d[_0x13f7('0x10')][_0x13f7('0x12')]);}logger[_0x13f7('0x10')](_0x13f7('0xd'),_0x4ca762,_0x328b9d['error'][_0x13f7('0x12')]);return _0x3df86d(_0x328b9d['error'][_0x13f7('0x12')]);}else{logger['info'](_0x13f7('0xd'),_0x4ca762,_0x13f7('0xf'));_0x3df86d(_0x328b9d[_0x13f7('0x13')][_0x13f7('0x12')]);}})[_0x13f7('0x14')](function(_0x14324c){logger[_0x13f7('0x10')]('SquareMessage,\x20%s,\x20%s',_0x4ca762,_0x14324c);_0x54de13(_0x14324c);});});}exports[_0x13f7('0x15')]=function(_0x18d078){var _0x3c94a8=this;return new Promise(function(_0xb8e6e8,_0x9da25c){return db[_0x13f7('0x16')]['create'](_0x18d078[_0x13f7('0x17')],{'raw':_0x18d078[_0x13f7('0x18')]?_0x18d078[_0x13f7('0x18')][_0x13f7('0x19')]===undefined?!![]:![]:!![]})['then'](function(_0x539c6d){logger['info'](_0x13f7('0x15'),_0x18d078);logger['debug'](_0x13f7('0x15'),_0x18d078,JSON[_0x13f7('0x1a')](_0x539c6d));_0xb8e6e8(_0x539c6d);})[_0x13f7('0x14')](function(_0x4da2f9){logger[_0x13f7('0x10')](_0x13f7('0x15'),_0x4da2f9[_0x13f7('0x12')],_0x18d078);_0x9da25c(_0x3c94a8[_0x13f7('0x10')](0x1f4,_0x4da2f9[_0x13f7('0x12')]));});});};