Built motion from commit b5413ace.|2.6.9
[motion2.git] / server / api / smsMessage / smsMessage.controller.js
index 1ed4b38..438daf5 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa533=['motionChannel','rejectmessage','SmsAccountId','type','inspect','MessageSid','twilio','plivo','MessageUUID','messageId','indexOf','delivered','Status','SmsAccount,\x20%s,\x20%s,\x20%s','plivio','results','groupName','DELIVERED','infobip','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','redis','defaults','socket.io-emitter','./smsMessage.socket','jayson/promise','client','http','then','info','SmsMessage,\x20%s,\x20%s','request\x20sent','debug','SmsMessage,\x20%s,\x20%s,\x20%s','stringify','code','error','message','result','catch','sendStatus','end','status','json','undefined','offset','count','limit','apply','update','stack','name','send','index','map','SmsMessage','rawAttributes','fieldName','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order','filter','where','merge','VIRTUAL','options','includeAll','include','findAll','show','params','create','body','find','destroy','describe','sms-interactions','accept','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','get','SmsInteraction','isNil','read1stAt','interaction','[SMSMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','QueryTypes','SELECT','contact','fullname','email','internal','manual','interface','SIP/%s','channel','EventManager','reject','SmsInteractionId','rejectMessage'];(function(_0x257e65,_0x3f4a68){var _0x3eef2f=function(_0x1c61e2){while(--_0x1c61e2){_0x257e65['push'](_0x257e65['shift']());}};_0x3eef2f(++_0x3f4a68);}(_0xa533,0x1c6));var _0x3a53=function(_0x264ec6,_0xe93945){_0x264ec6=_0x264ec6-0x0;var _0x425cde=_0xa533[_0x264ec6];return _0x425cde;};'use strict';var emlformat=require(_0x3a53('0x0'));var rimraf=require(_0x3a53('0x1'));var zipdir=require(_0x3a53('0x2'));var jsonpatch=require(_0x3a53('0x3'));var rp=require(_0x3a53('0x4'));var moment=require(_0x3a53('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x3a53('0x6'));var util=require(_0x3a53('0x7'));var path=require(_0x3a53('0x8'));var sox=require(_0x3a53('0x9'));var csv=require(_0x3a53('0xa'));var ejs=require(_0x3a53('0xb'));var fs=require('fs');var fs_extra=require(_0x3a53('0xc'));var _=require(_0x3a53('0xd'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x3a53('0xe'));var deskjs=require(_0x3a53('0xf'));var toCsv=require(_0x3a53('0xa'));var querystring=require(_0x3a53('0x10'));var Papa=require(_0x3a53('0x11'));var Redis=require(_0x3a53('0x12'));var authService=require('../../components/auth/service');var qs=require(_0x3a53('0x13'));var as=require(_0x3a53('0x14'));var hardwareService=require(_0x3a53('0x15'));var logger=require(_0x3a53('0x16'))(_0x3a53('0x17'));var utils=require(_0x3a53('0x18'));var config=require(_0x3a53('0x19'));var licenseUtil=require('../../config/license/util');var db=require(_0x3a53('0x1a'))['db'];config[_0x3a53('0x1b')]=_[_0x3a53('0x1c')](config[_0x3a53('0x1b')],{'host':'localhost','port':0x18eb});var socket=require(_0x3a53('0x1d'))(new Redis(config['redis']));require(_0x3a53('0x1e'))['register'](socket);var jayson=require(_0x3a53('0x1f'));var client=jayson[_0x3a53('0x20')][_0x3a53('0x21')]({'port':0x232c});var client9002=jayson['client'][_0x3a53('0x21')]({'port':0x232a});function respondWithRpcPromise(_0x13a8de,_0x438353,_0x59dabb,_0x5a059d){return new BPromise(function(_0x316873,_0x25393a){var _0x4e3edb=_0x5a059d||client;return _0x4e3edb['request'](_0x13a8de,_0x59dabb)[_0x3a53('0x22')](function(_0x1e1b03){logger[_0x3a53('0x23')](_0x3a53('0x24'),_0x438353,_0x3a53('0x25'));logger[_0x3a53('0x26')](_0x3a53('0x27'),_0x438353,_0x3a53('0x25'),JSON[_0x3a53('0x28')](_0x1e1b03));if(_0x1e1b03['error']){if(_0x1e1b03['error'][_0x3a53('0x29')]===0x1f4){logger['error']('SmsMessage,\x20%s,\x20%s',_0x438353,_0x1e1b03[_0x3a53('0x2a')][_0x3a53('0x2b')]);return _0x25393a(_0x1e1b03['error'][_0x3a53('0x2b')]);}logger[_0x3a53('0x2a')](_0x3a53('0x24'),_0x438353,_0x1e1b03['error']['message']);return _0x316873(_0x1e1b03[_0x3a53('0x2a')][_0x3a53('0x2b')]);}else{logger['info'](_0x3a53('0x24'),_0x438353,_0x3a53('0x25'));_0x316873(_0x1e1b03[_0x3a53('0x2c')][_0x3a53('0x2b')]);}})[_0x3a53('0x2d')](function(_0xb63d33){logger[_0x3a53('0x2a')](_0x3a53('0x24'),_0x438353,_0xb63d33);_0x25393a(_0xb63d33);});});}function respondWithStatusCode(_0x32963f,_0x415a16){_0x415a16=_0x415a16||0xcc;return function(_0x2666ac){if(_0x2666ac){return _0x32963f[_0x3a53('0x2e')](_0x415a16);}return _0x32963f['status'](_0x415a16)[_0x3a53('0x2f')]();};}function respondWithResult(_0x42f23a,_0x210a81){_0x210a81=_0x210a81||0xc8;return function(_0x460a2e){if(_0x460a2e){return _0x42f23a[_0x3a53('0x30')](_0x210a81)[_0x3a53('0x31')](_0x460a2e);}};}function respondWithFilteredResult(_0x2e3506,_0x5f3022){return function(_0x7402de){if(_0x7402de){var _0x905690=typeof _0x5f3022['offset']===_0x3a53('0x32')&&typeof _0x5f3022['limit']==='undefined';var _0x4204e3=_0x7402de['count'];var _0x3d4e2b=_0x905690?0x0:_0x5f3022[_0x3a53('0x33')];var _0x314e84=_0x905690?_0x7402de[_0x3a53('0x34')]:_0x5f3022[_0x3a53('0x33')]+_0x5f3022[_0x3a53('0x35')];var _0x459e10;if(_0x314e84>=_0x4204e3){_0x314e84=_0x4204e3;_0x459e10=0xc8;}else{_0x459e10=0xce;}_0x2e3506[_0x3a53('0x30')](_0x459e10);return _0x2e3506['set']('Content-Range',_0x3d4e2b+'-'+_0x314e84+'/'+_0x4204e3)[_0x3a53('0x31')](_0x7402de);}return null;};}function patchUpdates(_0x2ea4a7){return function(_0x2dd75b){try{jsonpatch[_0x3a53('0x36')](_0x2dd75b,_0x2ea4a7,!![]);}catch(_0x143c9e){return BPromise['reject'](_0x143c9e);}return _0x2dd75b['save']();};}function saveUpdates(_0x1fd27a,_0x3b8388){return function(_0x30723c){if(_0x30723c){return _0x30723c[_0x3a53('0x37')](_0x1fd27a)[_0x3a53('0x22')](function(_0x379155){return _0x379155;});}return null;};}function removeEntity(_0x4126d9,_0x487e91){return function(_0xcb63f9){if(_0xcb63f9){return _0xcb63f9['destroy']()[_0x3a53('0x22')](function(){_0x4126d9[_0x3a53('0x30')](0xcc)[_0x3a53('0x2f')]();});}};}function handleEntityNotFound(_0x1b3495,_0x175fb1){return function(_0x1255ac){if(!_0x1255ac){_0x1b3495[_0x3a53('0x2e')](0x194);}return _0x1255ac;};}function handleError(_0x53b92d,_0xf9328c){_0xf9328c=_0xf9328c||0x1f4;return function(_0x3c10e0){logger[_0x3a53('0x2a')](_0x3c10e0[_0x3a53('0x38')]);if(_0x3c10e0[_0x3a53('0x39')]){delete _0x3c10e0['name'];}_0x53b92d[_0x3a53('0x30')](_0xf9328c)[_0x3a53('0x3a')](_0x3c10e0);};}exports[_0x3a53('0x3b')]=function(_0x4839f8,_0x3c853b){var _0x589557={},_0x25ee74={},_0x5105fd={'count':0x0,'rows':[]};var _0x1b7cd4=_[_0x3a53('0x3c')](db[_0x3a53('0x3d')][_0x3a53('0x3e')],function(_0x142dee){return{'name':_0x142dee[_0x3a53('0x3f')],'type':_0x142dee['type'][_0x3a53('0x40')]};});_0x25ee74[_0x3a53('0x41')]=_[_0x3a53('0x3c')](_0x1b7cd4,_0x3a53('0x39'));_0x25ee74[_0x3a53('0x42')]=_[_0x3a53('0x43')](_0x4839f8[_0x3a53('0x42')]);_0x25ee74[_0x3a53('0x44')]=_[_0x3a53('0x45')](_0x25ee74['model'],_0x25ee74[_0x3a53('0x42')]);_0x589557[_0x3a53('0x46')]=_[_0x3a53('0x45')](_0x25ee74[_0x3a53('0x41')],qs[_0x3a53('0x47')](_0x4839f8['query'][_0x3a53('0x47')]));_0x589557[_0x3a53('0x46')]=_0x589557[_0x3a53('0x46')][_0x3a53('0x48')]?_0x589557[_0x3a53('0x46')]:_0x25ee74[_0x3a53('0x41')];if(!_0x4839f8[_0x3a53('0x42')][_0x3a53('0x49')]('nolimit')){_0x589557[_0x3a53('0x35')]=qs[_0x3a53('0x35')](_0x4839f8[_0x3a53('0x42')][_0x3a53('0x35')]);_0x589557[_0x3a53('0x33')]=qs['offset'](_0x4839f8[_0x3a53('0x42')][_0x3a53('0x33')]);}_0x589557[_0x3a53('0x4a')]=qs['sort'](_0x4839f8['query']['sort']);_0x589557['where']=qs[_0x3a53('0x44')](_['pick'](_0x4839f8[_0x3a53('0x42')],_0x25ee74[_0x3a53('0x44')]),_0x1b7cd4);if(_0x4839f8['query'][_0x3a53('0x4b')]){_0x589557[_0x3a53('0x4c')]=_[_0x3a53('0x4d')](_0x589557[_0x3a53('0x4c')],{'$or':_[_0x3a53('0x3c')](_0x1b7cd4,function(_0x17070d){if(_0x17070d['type']!==_0x3a53('0x4e')){var _0x55394d={};_0x55394d[_0x17070d[_0x3a53('0x39')]]={'$like':'%'+_0x4839f8['query'][_0x3a53('0x4b')]+'%'};return _0x55394d;}})});}_0x589557=_[_0x3a53('0x4d')]({},_0x589557,_0x4839f8[_0x3a53('0x4f')]);var _0x47b392={'where':_0x589557[_0x3a53('0x4c')]};return db[_0x3a53('0x3d')][_0x3a53('0x34')](_0x47b392)[_0x3a53('0x22')](function(_0x1e32e0){_0x5105fd[_0x3a53('0x34')]=_0x1e32e0;if(_0x4839f8['query'][_0x3a53('0x50')]){_0x589557[_0x3a53('0x51')]=[{'all':!![]}];}return db[_0x3a53('0x3d')][_0x3a53('0x52')](_0x589557);})['then'](function(_0x536aa2){_0x5105fd['rows']=_0x536aa2;return _0x5105fd;})[_0x3a53('0x22')](respondWithFilteredResult(_0x3c853b,_0x589557))[_0x3a53('0x2d')](handleError(_0x3c853b,null));};exports[_0x3a53('0x53')]=function(_0x230289,_0x4dac1a){var _0x44d671={'raw':!![],'where':{'id':_0x230289[_0x3a53('0x54')]['id']}},_0x1b58f7={};_0x1b58f7['model']=_[_0x3a53('0x43')](db['SmsMessage'][_0x3a53('0x3e')]);_0x1b58f7[_0x3a53('0x42')]=_[_0x3a53('0x43')](_0x230289[_0x3a53('0x42')]);_0x1b58f7[_0x3a53('0x44')]=_[_0x3a53('0x45')](_0x1b58f7[_0x3a53('0x41')],_0x1b58f7[_0x3a53('0x42')]);_0x44d671[_0x3a53('0x46')]=_[_0x3a53('0x45')](_0x1b58f7['model'],qs[_0x3a53('0x47')](_0x230289[_0x3a53('0x42')]['fields']));_0x44d671[_0x3a53('0x46')]=_0x44d671[_0x3a53('0x46')][_0x3a53('0x48')]?_0x44d671['attributes']:_0x1b58f7[_0x3a53('0x41')];if(_0x230289[_0x3a53('0x42')][_0x3a53('0x50')]){_0x44d671[_0x3a53('0x51')]=[{'all':!![]}];}_0x44d671=_['merge']({},_0x44d671,_0x230289[_0x3a53('0x4f')]);return db[_0x3a53('0x3d')]['find'](_0x44d671)[_0x3a53('0x22')](handleEntityNotFound(_0x4dac1a,null))[_0x3a53('0x22')](respondWithResult(_0x4dac1a,null))[_0x3a53('0x2d')](handleError(_0x4dac1a,null));};exports[_0x3a53('0x55')]=function(_0x2fc363,_0x5dde37){return db['SmsMessage'][_0x3a53('0x55')](_0x2fc363['body'],{})[_0x3a53('0x22')](respondWithResult(_0x5dde37,0xc9))[_0x3a53('0x2d')](handleError(_0x5dde37,null));};exports[_0x3a53('0x37')]=function(_0x484db5,_0x4c89bd){if(_0x484db5[_0x3a53('0x56')]['id']){delete _0x484db5[_0x3a53('0x56')]['id'];}return db[_0x3a53('0x3d')][_0x3a53('0x57')]({'where':{'id':_0x484db5[_0x3a53('0x54')]['id']}})[_0x3a53('0x22')](handleEntityNotFound(_0x4c89bd,null))[_0x3a53('0x22')](saveUpdates(_0x484db5[_0x3a53('0x56')],null))['then'](respondWithResult(_0x4c89bd,null))['catch'](handleError(_0x4c89bd,null));};exports[_0x3a53('0x58')]=function(_0x1e1145,_0x36960c){return db[_0x3a53('0x3d')][_0x3a53('0x57')]({'where':{'id':_0x1e1145[_0x3a53('0x54')]['id']}})[_0x3a53('0x22')](handleEntityNotFound(_0x36960c,null))[_0x3a53('0x22')](removeEntity(_0x36960c,null))[_0x3a53('0x2d')](handleError(_0x36960c,null));};exports['describe']=function(_0x3739e1,_0x209feb){return db[_0x3a53('0x3d')][_0x3a53('0x59')]()[_0x3a53('0x22')](respondWithResult(_0x209feb,null))['catch'](handleError(_0x209feb,null));};var interaction_log=require(_0x3a53('0x16'))(_0x3a53('0x5a'));exports[_0x3a53('0x5b')]=function(_0x11ec13,_0x5f5c41,_0x3b6333){var _0xba6e66={'agent':{},'channel':'sms'};if(_0x11ec13[_0x3a53('0x56')]['id']){delete _0x11ec13['body']['id'];}_0x11ec13[_0x3a53('0x56')][_0x3a53('0x5c')]=!![];_0x11ec13['body'][_0x3a53('0x5d')]=moment()[_0x3a53('0x5e')](_0x3a53('0x5f'));_0x11ec13['body']['UserId']=_0x11ec13[_0x3a53('0x56')][_0x3a53('0x60')]||_0x11ec13[_0x3a53('0x61')]['id'];_0xba6e66[_0x3a53('0x62')]['id']=_0x11ec13['body'][_0x3a53('0x60')];return db[_0x3a53('0x3d')][_0x3a53('0x57')]({'where':{'id':_0x11ec13['params']['id'],'UserId':null}})[_0x3a53('0x22')](handleEntityNotFound(_0x5f5c41,null))[_0x3a53('0x22')](saveUpdates(_0x11ec13[_0x3a53('0x56')],null))[_0x3a53('0x22')](function(_0x46bffd){if(_0x46bffd){_0xba6e66[_0x3a53('0x2b')]=_0x46bffd[_0x3a53('0x63')]({'plain':!![]});return db[_0x3a53('0x64')][_0x3a53('0x57')]({'where':{'id':_0x46bffd['SmsInteractionId']}});}return null;})['then'](handleEntityNotFound(_0x5f5c41,null))[_0x3a53('0x22')](function(_0x3b371c){if(_0x3b371c){return _0x3b371c[_0x3a53('0x37')]({'UserId':_0x11ec13['body'][_0x3a53('0x60')],'read1stAt':_[_0x3a53('0x65')](_0x3b371c[_0x3a53('0x66')])?moment()[_0x3a53('0x5e')]('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})['then'](function(_0x34d9e3){if(_0x34d9e3){_0xba6e66[_0x3a53('0x67')]=_0x34d9e3[_0x3a53('0x63')]({'plain':!![]});interaction_log[_0x3a53('0x23')](_0x3a53('0x68'),_0x11ec13['user']['id'],_0x11ec13[_0x3a53('0x61')]['name'],_0x11ec13[_0x3a53('0x61')][_0x3a53('0x69')],_0xba6e66[_0x3a53('0x67')]['id'],_0x11ec13[_0x3a53('0x56')]?JSON[_0x3a53('0x28')](_0x11ec13[_0x3a53('0x56')]):_0x3a53('0x6a'));return respondWithRpcPromise('AcceptMessage',_0x3a53('0x6b'),_0xba6e66);}return null;})[_0x3a53('0x22')](function(_0x3f4cb3){var _0x26d7b3=_0x3a53('0x6c')+_0x3f4cb3[_0x3a53('0x2b')][_0x3a53('0x6d')];return db[_0x3a53('0x6e')]['query'](_0x26d7b3,{'type':db[_0x3a53('0x6f')][_0x3a53('0x70')][_0x3a53('0x71')],'raw':!![]})[_0x3a53('0x22')](function(_0x48e379){return _0x48e379;});})['then'](function(_0x409717){if(_0x409717){_0xba6e66['message'][_0x3a53('0x72')]=_0x409717[0x0];if(!_0x11ec13[_0x3a53('0x56')][_0x3a53('0x60')])return;return db['User'][_0x3a53('0x57')]({'where':{'id':_0x11ec13[_0x3a53('0x56')]['UserId'],'role':'agent'},'attributes':['id','name',_0x3a53('0x73'),_0x3a53('0x74'),_0x3a53('0x75')],'raw':!![]});}return null;})[_0x3a53('0x22')](function(_0x46fe27){if(!_0x46fe27)return null;_0xba6e66['message']['agent']=_0x46fe27;return _0xba6e66;})[_0x3a53('0x22')](function(_0x1a51e1){if(_0x1a51e1){if(_0x11ec13[_0x3a53('0x56')][_0x3a53('0x76')]){_0xba6e66[_0x3a53('0x2b')][_0x3a53('0x77')]=util[_0x3a53('0x5e')](_0x3a53('0x78'),_0x11ec13[_0x3a53('0x61')][_0x3a53('0x39')]);_0xba6e66[_0x3a53('0x2b')][_0x3a53('0x79')]=_0xba6e66[_0x3a53('0x79')];_0xba6e66[_0x3a53('0x2b')]['motionChannel']=_0xba6e66[_0x3a53('0x79')];_0xba6e66[_0x3a53('0x2b')]['event']=_0x3a53('0x5b');return respondWithRpcPromise('EventManager',_0x3a53('0x7a'),{'event':'acceptmessage','message':_0xba6e66[_0x3a53('0x2b')]},client9002)['then'](function(){return _0xba6e66;});}return _0xba6e66;}return null;})[_0x3a53('0x22')](respondWithResult(_0x5f5c41,null))[_0x3a53('0x2d')](handleError(_0x5f5c41,null));};var interaction_log=require(_0x3a53('0x16'))(_0x3a53('0x5a'));exports[_0x3a53('0x7b')]=function(_0x173e64,_0x4b0499,_0x456fb7){var _0x4dbc1b={'agent':{},'channel':'sms'};if(_0x173e64[_0x3a53('0x56')]['id']){delete _0x173e64[_0x3a53('0x56')]['id'];}_0x173e64[_0x3a53('0x56')]['UserId']=_0x173e64[_0x3a53('0x56')][_0x3a53('0x60')]||_0x173e64[_0x3a53('0x61')]['id'];_0x4dbc1b[_0x3a53('0x62')]['id']=_0x173e64[_0x3a53('0x56')][_0x3a53('0x60')];return db[_0x3a53('0x3d')]['find']({'where':{'id':_0x173e64['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x4b0499,null))[_0x3a53('0x22')](function(_0x204a38){if(_0x204a38){_0x4dbc1b[_0x3a53('0x2b')]=_0x204a38['get']({'plain':!![]});return db['SmsInteraction']['find']({'where':{'id':_0x204a38[_0x3a53('0x7c')]}});}return null;})[_0x3a53('0x22')](handleEntityNotFound(_0x4b0499,null))['then'](function(_0x177b80){if(_0x177b80){_0x4dbc1b[_0x3a53('0x67')]=_0x177b80['get']({'plain':!![]});interaction_log['info']('[SMSMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x173e64[_0x3a53('0x61')]['id'],_0x173e64[_0x3a53('0x61')][_0x3a53('0x39')],_0x173e64[_0x3a53('0x61')][_0x3a53('0x69')],_0x4dbc1b[_0x3a53('0x67')]['id'],_0x173e64['body']?JSON['stringify'](_0x173e64[_0x3a53('0x56')]):'null');return respondWithRpcPromise('RejectMessage',_0x3a53('0x7d'),_0x4dbc1b);}return null;})[_0x3a53('0x22')](function(_0x5e8ce0){var _0x426365=_0x3a53('0x6c')+_0x5e8ce0['message'][_0x3a53('0x6d')];return db[_0x3a53('0x6e')][_0x3a53('0x42')](_0x426365,{'type':db[_0x3a53('0x6f')][_0x3a53('0x70')][_0x3a53('0x71')],'raw':!![]})[_0x3a53('0x22')](function(_0x41588d){return _0x41588d;});})['then'](function(_0x57479a){if(_0x57479a){_0x4dbc1b[_0x3a53('0x2b')]['contact']=_0x57479a[0x0];if(!_0x173e64[_0x3a53('0x56')]['UserId'])return;return db['User'][_0x3a53('0x57')]({'where':{'id':_0x173e64[_0x3a53('0x56')][_0x3a53('0x60')],'role':_0x3a53('0x62')},'attributes':['id',_0x3a53('0x39'),_0x3a53('0x73'),'email',_0x3a53('0x75')],'raw':!![]});}return null;})[_0x3a53('0x22')](function(_0x2751b3){if(!_0x2751b3)return null;_0x4dbc1b['message'][_0x3a53('0x62')]=_0x2751b3;return _0x4dbc1b;})[_0x3a53('0x22')](function(_0x20e266){if(_0x20e266){_0x20e266['message'][_0x3a53('0x77')]=util[_0x3a53('0x5e')](_0x3a53('0x78'),_0x173e64[_0x3a53('0x61')][_0x3a53('0x39')]);_0x20e266['message'][_0x3a53('0x79')]=_0x4dbc1b['channel'];_0x20e266[_0x3a53('0x2b')][_0x3a53('0x7e')]=_0x4dbc1b[_0x3a53('0x79')];_0x20e266[_0x3a53('0x2b')]['event']='reject';respondWithRpcPromise('EventManager',_0x3a53('0x7a'),{'event':_0x3a53('0x7f'),'message':_0x20e266[_0x3a53('0x2b')]},client9002);return _0x4dbc1b;}return null;})[_0x3a53('0x22')](respondWithResult(_0x4b0499,null))[_0x3a53('0x2d')](handleError(_0x4b0499,null));};exports[_0x3a53('0x30')]=function(_0x419dc1,_0x84d299,_0x48f463){if(_0x419dc1[_0x3a53('0x56')]['id']){delete _0x419dc1[_0x3a53('0x56')]['id'];}var _0x126a16;return db[_0x3a53('0x3d')][_0x3a53('0x57')]({'where':{'id':_0x419dc1[_0x3a53('0x54')]['id']}})['then'](handleEntityNotFound(_0x84d299,null))[_0x3a53('0x22')](function(_0x224e48){if(_0x224e48){_0x126a16=_0x224e48;return db['SmsAccount']['find']({'where':{'id':_0x224e48[_0x3a53('0x80')]}});}})['then'](handleEntityNotFound(_0x84d299,null))['then'](function(_0x31a7db){if(_0x31a7db){logger[_0x3a53('0x26')](_0x3a53('0x27'),_0x3a53('0x30'),'received\x20delivery\x20report\x20from',_0x31a7db[_0x3a53('0x81')],util[_0x3a53('0x82')](_0x419dc1[_0x3a53('0x56')],{'showHidden':![],'depth':null}));switch(_0x31a7db[_0x3a53('0x81')]){case'twilio':if(_0x419dc1[_0x3a53('0x56')]['MessageSid']&&_0x419dc1[_0x3a53('0x56')][_0x3a53('0x83')]===_0x126a16['messageId']){return _0x126a16[_0x3a53('0x37')]({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0x3a53('0x30'),_0x3a53('0x84'),util[_0x3a53('0x82')](_0x419dc1[_0x3a53('0x56')],{'showHidden':![],'depth':null}));}break;case _0x3a53('0x85'):if(_0x419dc1[_0x3a53('0x56')][_0x3a53('0x86')]&&_0x419dc1[_0x3a53('0x56')][_0x3a53('0x86')]===_0x126a16[_0x3a53('0x87')]&&_[_0x3a53('0x88')](['sent',_0x3a53('0x89')],_0x419dc1[_0x3a53('0x56')][_0x3a53('0x8a')])>=0x0){return _0x126a16[_0x3a53('0x37')]({'read':!![]});}else{logger[_0x3a53('0x2a')](_0x3a53('0x8b'),_0x3a53('0x30'),_0x3a53('0x8c'),util[_0x3a53('0x82')](_0x419dc1['body'],{'showHidden':![],'depth':null}));}break;case'infobip':var _0x219e68=_0x419dc1[_0x3a53('0x56')][_0x3a53('0x8d')][0x0];if(_0x219e68['status'][_0x3a53('0x8e')]===_0x3a53('0x8f')){return _0x126a16[_0x3a53('0x37')]({'read':!![]});}else{logger[_0x3a53('0x2a')](_0x3a53('0x8b'),_0x3a53('0x30'),_0x3a53('0x90'),util[_0x3a53('0x82')](_0x419dc1[_0x3a53('0x56')],{'showHidden':![],'depth':null}));}break;}return _0x126a16;}})[_0x3a53('0x22')](respondWithResult(_0x84d299,null))[_0x3a53('0x2d')](handleError(_0x84d299,null));};
\ No newline at end of file
+var _0xeb85=['model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','merge','VIRTUAL','filter','options','includeAll','include','findAll','show','params','find','create','body','describe','sms-interactions','accept','sms','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','get','SmsInteraction','SmsInteractionId','interaction','[SMSMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','QueryTypes','SELECT','internal','manual','interface','SIP/%s','channel','motionChannel','EventManager','RejectMessage','contact','User','fullname','event','SmsAccount','SmsAccountId','debug','received\x20delivery\x20report\x20from','inspect','twilio','MessageSid','messageId','MessageUUID','indexOf','sent','delivered','SmsAccount,\x20%s,\x20%s,\x20%s','plivio','groupName','DELIVERED','infobip','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','./smsMessage.socket','register','client','http','then','info','SmsMessage,\x20%s,\x20%s','request\x20sent','SmsMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','status','end','json','offset','undefined','count','limit','apply','reject','save','update','destroy','sendStatus','stack','name','send','index','map','SmsMessage','rawAttributes','type'];(function(_0x189cb4,_0x393c9b){var _0x5d4911=function(_0x35398e){while(--_0x35398e){_0x189cb4['push'](_0x189cb4['shift']());}};_0x5d4911(++_0x393c9b);}(_0xeb85,0x167));var _0x5eb8=function(_0x386dc7,_0x341e56){_0x386dc7=_0x386dc7-0x0;var _0x4cd426=_0xeb85[_0x386dc7];return _0x4cd426;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x5eb8('0x0'));var zipdir=require(_0x5eb8('0x1'));var jsonpatch=require(_0x5eb8('0x2'));var rp=require(_0x5eb8('0x3'));var moment=require(_0x5eb8('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x5eb8('0x5'));var util=require(_0x5eb8('0x6'));var path=require('path');var sox=require(_0x5eb8('0x7'));var csv=require(_0x5eb8('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x5eb8('0x9'));var _=require(_0x5eb8('0xa'));var squel=require(_0x5eb8('0xb'));var crypto=require('crypto');var jsforce=require(_0x5eb8('0xc'));var deskjs=require(_0x5eb8('0xd'));var toCsv=require(_0x5eb8('0x8'));var querystring=require(_0x5eb8('0xe'));var Papa=require(_0x5eb8('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x5eb8('0x10'));var logger=require(_0x5eb8('0x11'))(_0x5eb8('0x12'));var utils=require(_0x5eb8('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0x5eb8('0x14'));var db=require(_0x5eb8('0x15'))['db'];config[_0x5eb8('0x16')]=_[_0x5eb8('0x17')](config['redis'],{'host':_0x5eb8('0x18'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x5eb8('0x16')]));require(_0x5eb8('0x19'))[_0x5eb8('0x1a')](socket);var jayson=require('jayson/promise');var client=jayson['client']['http']({'port':0x232c});var client9002=jayson[_0x5eb8('0x1b')][_0x5eb8('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x21f0f1,_0x4a6556,_0xf8ee94,_0x164432){return new BPromise(function(_0x94b3ae,_0x3d2061){var _0x4ce450=_0x164432||client;return _0x4ce450['request'](_0x21f0f1,_0xf8ee94)[_0x5eb8('0x1d')](function(_0x3e9395){logger[_0x5eb8('0x1e')](_0x5eb8('0x1f'),_0x4a6556,_0x5eb8('0x20'));logger['debug'](_0x5eb8('0x21'),_0x4a6556,_0x5eb8('0x20'),JSON[_0x5eb8('0x22')](_0x3e9395));if(_0x3e9395[_0x5eb8('0x23')]){if(_0x3e9395[_0x5eb8('0x23')][_0x5eb8('0x24')]===0x1f4){logger['error'](_0x5eb8('0x1f'),_0x4a6556,_0x3e9395[_0x5eb8('0x23')][_0x5eb8('0x25')]);return _0x3d2061(_0x3e9395[_0x5eb8('0x23')][_0x5eb8('0x25')]);}logger[_0x5eb8('0x23')](_0x5eb8('0x1f'),_0x4a6556,_0x3e9395[_0x5eb8('0x23')][_0x5eb8('0x25')]);return _0x94b3ae(_0x3e9395['error']['message']);}else{logger[_0x5eb8('0x1e')](_0x5eb8('0x1f'),_0x4a6556,_0x5eb8('0x20'));_0x94b3ae(_0x3e9395[_0x5eb8('0x26')][_0x5eb8('0x25')]);}})[_0x5eb8('0x27')](function(_0x32b9e6){logger[_0x5eb8('0x23')](_0x5eb8('0x1f'),_0x4a6556,_0x32b9e6);_0x3d2061(_0x32b9e6);});});}function respondWithStatusCode(_0x340023,_0x5b41cb){_0x5b41cb=_0x5b41cb||0xcc;return function(_0xf10b3a){if(_0xf10b3a){return _0x340023['sendStatus'](_0x5b41cb);}return _0x340023[_0x5eb8('0x28')](_0x5b41cb)[_0x5eb8('0x29')]();};}function respondWithResult(_0xb5712f,_0x4f6134){_0x4f6134=_0x4f6134||0xc8;return function(_0x335cd1){if(_0x335cd1){return _0xb5712f[_0x5eb8('0x28')](_0x4f6134)[_0x5eb8('0x2a')](_0x335cd1);}};}function respondWithFilteredResult(_0x18eac3,_0x57443d){return function(_0x28da76){if(_0x28da76){var _0x15cc50=typeof _0x57443d[_0x5eb8('0x2b')]==='undefined'&&typeof _0x57443d['limit']===_0x5eb8('0x2c');var _0x1ebd5a=_0x28da76[_0x5eb8('0x2d')];var _0x310f4c=_0x15cc50?0x0:_0x57443d[_0x5eb8('0x2b')];var _0x7a62e6=_0x15cc50?_0x28da76[_0x5eb8('0x2d')]:_0x57443d[_0x5eb8('0x2b')]+_0x57443d[_0x5eb8('0x2e')];var _0x579b06;if(_0x7a62e6>=_0x1ebd5a){_0x7a62e6=_0x1ebd5a;_0x579b06=0xc8;}else{_0x579b06=0xce;}_0x18eac3[_0x5eb8('0x28')](_0x579b06);return _0x18eac3['set']('Content-Range',_0x310f4c+'-'+_0x7a62e6+'/'+_0x1ebd5a)[_0x5eb8('0x2a')](_0x28da76);}return null;};}function patchUpdates(_0xf30449){return function(_0x285d0d){try{jsonpatch[_0x5eb8('0x2f')](_0x285d0d,_0xf30449,!![]);}catch(_0x2c85a1){return BPromise[_0x5eb8('0x30')](_0x2c85a1);}return _0x285d0d[_0x5eb8('0x31')]();};}function saveUpdates(_0x3551d7,_0x2607a3){return function(_0x429d0e){if(_0x429d0e){return _0x429d0e[_0x5eb8('0x32')](_0x3551d7)[_0x5eb8('0x1d')](function(_0x37f08a){return _0x37f08a;});}return null;};}function removeEntity(_0x357c43,_0x2680de){return function(_0x1bbfe6){if(_0x1bbfe6){return _0x1bbfe6[_0x5eb8('0x33')]()['then'](function(){_0x357c43[_0x5eb8('0x28')](0xcc)[_0x5eb8('0x29')]();});}};}function handleEntityNotFound(_0x5cac0e,_0x42877e){return function(_0x257ce5){if(!_0x257ce5){_0x5cac0e[_0x5eb8('0x34')](0x194);}return _0x257ce5;};}function handleError(_0x2fcf7b,_0x5ed44d){_0x5ed44d=_0x5ed44d||0x1f4;return function(_0x44d320){logger[_0x5eb8('0x23')](_0x44d320[_0x5eb8('0x35')]);if(_0x44d320[_0x5eb8('0x36')]){delete _0x44d320['name'];}_0x2fcf7b[_0x5eb8('0x28')](_0x5ed44d)[_0x5eb8('0x37')](_0x44d320);};}exports[_0x5eb8('0x38')]=function(_0x16e0b3,_0x29367e){var _0x46fbea={},_0x56b3c6={},_0x4325b0={'count':0x0,'rows':[]};var _0x38b8b4=_[_0x5eb8('0x39')](db[_0x5eb8('0x3a')][_0x5eb8('0x3b')],function(_0x29d927){return{'name':_0x29d927['fieldName'],'type':_0x29d927[_0x5eb8('0x3c')]['key']};});_0x56b3c6[_0x5eb8('0x3d')]=_[_0x5eb8('0x39')](_0x38b8b4,_0x5eb8('0x36'));_0x56b3c6[_0x5eb8('0x3e')]=_[_0x5eb8('0x3f')](_0x16e0b3[_0x5eb8('0x3e')]);_0x56b3c6[_0x5eb8('0x40')]=_[_0x5eb8('0x41')](_0x56b3c6[_0x5eb8('0x3d')],_0x56b3c6['query']);_0x46fbea[_0x5eb8('0x42')]=_['intersection'](_0x56b3c6['model'],qs['fields'](_0x16e0b3[_0x5eb8('0x3e')][_0x5eb8('0x43')]));_0x46fbea[_0x5eb8('0x42')]=_0x46fbea['attributes'][_0x5eb8('0x44')]?_0x46fbea[_0x5eb8('0x42')]:_0x56b3c6[_0x5eb8('0x3d')];if(!_0x16e0b3['query'][_0x5eb8('0x45')](_0x5eb8('0x46'))){_0x46fbea['limit']=qs[_0x5eb8('0x2e')](_0x16e0b3[_0x5eb8('0x3e')][_0x5eb8('0x2e')]);_0x46fbea[_0x5eb8('0x2b')]=qs[_0x5eb8('0x2b')](_0x16e0b3[_0x5eb8('0x3e')][_0x5eb8('0x2b')]);}_0x46fbea['order']=qs['sort'](_0x16e0b3[_0x5eb8('0x3e')][_0x5eb8('0x47')]);_0x46fbea[_0x5eb8('0x48')]=qs['filters'](_[_0x5eb8('0x49')](_0x16e0b3[_0x5eb8('0x3e')],_0x56b3c6[_0x5eb8('0x40')]),_0x38b8b4);if(_0x16e0b3[_0x5eb8('0x3e')]['filter']){_0x46fbea[_0x5eb8('0x48')]=_[_0x5eb8('0x4a')](_0x46fbea[_0x5eb8('0x48')],{'$or':_['map'](_0x38b8b4,function(_0x564654){if(_0x564654[_0x5eb8('0x3c')]!==_0x5eb8('0x4b')){var _0x5a2c30={};_0x5a2c30[_0x564654[_0x5eb8('0x36')]]={'$like':'%'+_0x16e0b3[_0x5eb8('0x3e')][_0x5eb8('0x4c')]+'%'};return _0x5a2c30;}})});}_0x46fbea=_['merge']({},_0x46fbea,_0x16e0b3[_0x5eb8('0x4d')]);var _0x2bfdb8={'where':_0x46fbea[_0x5eb8('0x48')]};return db[_0x5eb8('0x3a')][_0x5eb8('0x2d')](_0x2bfdb8)[_0x5eb8('0x1d')](function(_0x45e8f8){_0x4325b0[_0x5eb8('0x2d')]=_0x45e8f8;if(_0x16e0b3['query'][_0x5eb8('0x4e')]){_0x46fbea[_0x5eb8('0x4f')]=[{'all':!![]}];}return db[_0x5eb8('0x3a')][_0x5eb8('0x50')](_0x46fbea);})[_0x5eb8('0x1d')](function(_0x4537b5){_0x4325b0['rows']=_0x4537b5;return _0x4325b0;})['then'](respondWithFilteredResult(_0x29367e,_0x46fbea))[_0x5eb8('0x27')](handleError(_0x29367e,null));};exports[_0x5eb8('0x51')]=function(_0x4d992b,_0xeb83d7){var _0x119989={'raw':!![],'where':{'id':_0x4d992b[_0x5eb8('0x52')]['id']}},_0x4f3984={};_0x4f3984[_0x5eb8('0x3d')]=_['keys'](db[_0x5eb8('0x3a')][_0x5eb8('0x3b')]);_0x4f3984[_0x5eb8('0x3e')]=_[_0x5eb8('0x3f')](_0x4d992b[_0x5eb8('0x3e')]);_0x4f3984[_0x5eb8('0x40')]=_['intersection'](_0x4f3984['model'],_0x4f3984['query']);_0x119989[_0x5eb8('0x42')]=_[_0x5eb8('0x41')](_0x4f3984[_0x5eb8('0x3d')],qs[_0x5eb8('0x43')](_0x4d992b[_0x5eb8('0x3e')][_0x5eb8('0x43')]));_0x119989[_0x5eb8('0x42')]=_0x119989[_0x5eb8('0x42')][_0x5eb8('0x44')]?_0x119989[_0x5eb8('0x42')]:_0x4f3984[_0x5eb8('0x3d')];if(_0x4d992b[_0x5eb8('0x3e')][_0x5eb8('0x4e')]){_0x119989['include']=[{'all':!![]}];}_0x119989=_[_0x5eb8('0x4a')]({},_0x119989,_0x4d992b[_0x5eb8('0x4d')]);return db[_0x5eb8('0x3a')][_0x5eb8('0x53')](_0x119989)['then'](handleEntityNotFound(_0xeb83d7,null))['then'](respondWithResult(_0xeb83d7,null))[_0x5eb8('0x27')](handleError(_0xeb83d7,null));};exports['create']=function(_0x5ca289,_0x5b7687){return db[_0x5eb8('0x3a')][_0x5eb8('0x54')](_0x5ca289['body'],{})[_0x5eb8('0x1d')](respondWithResult(_0x5b7687,0xc9))['catch'](handleError(_0x5b7687,null));};exports[_0x5eb8('0x32')]=function(_0x1dd43e,_0x60c83){if(_0x1dd43e[_0x5eb8('0x55')]['id']){delete _0x1dd43e[_0x5eb8('0x55')]['id'];}return db[_0x5eb8('0x3a')]['find']({'where':{'id':_0x1dd43e[_0x5eb8('0x52')]['id']}})[_0x5eb8('0x1d')](handleEntityNotFound(_0x60c83,null))[_0x5eb8('0x1d')](saveUpdates(_0x1dd43e[_0x5eb8('0x55')],null))[_0x5eb8('0x1d')](respondWithResult(_0x60c83,null))[_0x5eb8('0x27')](handleError(_0x60c83,null));};exports[_0x5eb8('0x33')]=function(_0x14d9b6,_0x4be44d){return db[_0x5eb8('0x3a')]['find']({'where':{'id':_0x14d9b6[_0x5eb8('0x52')]['id']}})[_0x5eb8('0x1d')](handleEntityNotFound(_0x4be44d,null))[_0x5eb8('0x1d')](removeEntity(_0x4be44d,null))[_0x5eb8('0x27')](handleError(_0x4be44d,null));};exports[_0x5eb8('0x56')]=function(_0x4948d1,_0x48522b){return db[_0x5eb8('0x3a')]['describe']()[_0x5eb8('0x1d')](respondWithResult(_0x48522b,null))[_0x5eb8('0x27')](handleError(_0x48522b,null));};var interaction_log=require(_0x5eb8('0x11'))(_0x5eb8('0x57'));exports[_0x5eb8('0x58')]=function(_0x593189,_0x296ff6,_0x593a24){var _0x58819a={'agent':{},'channel':_0x5eb8('0x59')};if(_0x593189[_0x5eb8('0x55')]['id']){delete _0x593189['body']['id'];}_0x593189[_0x5eb8('0x55')][_0x5eb8('0x5a')]=!![];_0x593189['body'][_0x5eb8('0x5b')]=moment()[_0x5eb8('0x5c')](_0x5eb8('0x5d'));_0x593189[_0x5eb8('0x55')][_0x5eb8('0x5e')]=_0x593189[_0x5eb8('0x55')]['UserId']||_0x593189[_0x5eb8('0x5f')]['id'];_0x58819a[_0x5eb8('0x60')]['id']=_0x593189['body'][_0x5eb8('0x5e')];return db[_0x5eb8('0x3a')][_0x5eb8('0x53')]({'where':{'id':_0x593189[_0x5eb8('0x52')]['id'],'UserId':null}})[_0x5eb8('0x1d')](handleEntityNotFound(_0x296ff6,null))[_0x5eb8('0x1d')](saveUpdates(_0x593189[_0x5eb8('0x55')],null))['then'](function(_0x2f40e0){if(_0x2f40e0){_0x58819a[_0x5eb8('0x25')]=_0x2f40e0[_0x5eb8('0x61')]({'plain':!![]});return db[_0x5eb8('0x62')]['find']({'where':{'id':_0x2f40e0[_0x5eb8('0x63')]}});}return null;})[_0x5eb8('0x1d')](handleEntityNotFound(_0x296ff6,null))['then'](function(_0x37fd15){if(_0x37fd15){return _0x37fd15[_0x5eb8('0x32')]({'UserId':_0x593189[_0x5eb8('0x55')][_0x5eb8('0x5e')],'read1stAt':_['isNil'](_0x37fd15['read1stAt'])?moment()[_0x5eb8('0x5c')]('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})[_0x5eb8('0x1d')](function(_0x2ab5c5){if(_0x2ab5c5){_0x58819a[_0x5eb8('0x64')]=_0x2ab5c5[_0x5eb8('0x61')]({'plain':!![]});interaction_log[_0x5eb8('0x1e')](_0x5eb8('0x65'),_0x593189[_0x5eb8('0x5f')]['id'],_0x593189[_0x5eb8('0x5f')]['name'],_0x593189[_0x5eb8('0x5f')][_0x5eb8('0x66')],_0x58819a['interaction']['id'],_0x593189['body']?JSON[_0x5eb8('0x22')](_0x593189[_0x5eb8('0x55')]):_0x5eb8('0x67'));return respondWithRpcPromise(_0x5eb8('0x68'),'acceptMessage',_0x58819a);}return null;})[_0x5eb8('0x1d')](function(_0x405fc2){var _0x2fdce8=_0x5eb8('0x69')+_0x405fc2[_0x5eb8('0x25')][_0x5eb8('0x6a')];return db[_0x5eb8('0x6b')]['query'](_0x2fdce8,{'type':db[_0x5eb8('0x6c')][_0x5eb8('0x6d')][_0x5eb8('0x6e')],'raw':!![]})[_0x5eb8('0x1d')](function(_0x29e281){return _0x29e281;});})[_0x5eb8('0x1d')](function(_0x514e96){if(_0x514e96){_0x58819a['message']['contact']=_0x514e96[0x0];if(!_0x593189['body'][_0x5eb8('0x5e')])return;return db['User'][_0x5eb8('0x53')]({'where':{'id':_0x593189['body'][_0x5eb8('0x5e')],'role':'agent'},'attributes':['id','name','fullname','email',_0x5eb8('0x6f')],'raw':!![]});}return null;})[_0x5eb8('0x1d')](function(_0x285068){if(!_0x285068)return null;_0x58819a[_0x5eb8('0x25')][_0x5eb8('0x60')]=_0x285068;return _0x58819a;})[_0x5eb8('0x1d')](function(_0x13b4ac){if(_0x13b4ac){if(_0x593189[_0x5eb8('0x55')][_0x5eb8('0x70')]){_0x58819a['message'][_0x5eb8('0x71')]=util[_0x5eb8('0x5c')](_0x5eb8('0x72'),_0x593189[_0x5eb8('0x5f')]['name']);_0x58819a['message'][_0x5eb8('0x73')]=_0x58819a[_0x5eb8('0x73')];_0x58819a[_0x5eb8('0x25')][_0x5eb8('0x74')]=_0x58819a[_0x5eb8('0x73')];_0x58819a[_0x5eb8('0x25')]['event']=_0x5eb8('0x58');return respondWithRpcPromise(_0x5eb8('0x75'),_0x5eb8('0x75'),{'event':'acceptmessage','message':_0x58819a[_0x5eb8('0x25')]},client9002)[_0x5eb8('0x1d')](function(){return _0x58819a;});}return _0x58819a;}return null;})[_0x5eb8('0x1d')](respondWithResult(_0x296ff6,null))['catch'](handleError(_0x296ff6,null));};var interaction_log=require(_0x5eb8('0x11'))(_0x5eb8('0x57'));exports[_0x5eb8('0x30')]=function(_0x17319c,_0x5edd7f,_0x564b79){var _0x1c0c0f={'agent':{},'channel':_0x5eb8('0x59')};if(_0x17319c[_0x5eb8('0x55')]['id']){delete _0x17319c[_0x5eb8('0x55')]['id'];}_0x17319c[_0x5eb8('0x55')][_0x5eb8('0x5e')]=_0x17319c[_0x5eb8('0x55')][_0x5eb8('0x5e')]||_0x17319c[_0x5eb8('0x5f')]['id'];_0x1c0c0f[_0x5eb8('0x60')]['id']=_0x17319c[_0x5eb8('0x55')][_0x5eb8('0x5e')];return db['SmsMessage'][_0x5eb8('0x53')]({'where':{'id':_0x17319c[_0x5eb8('0x52')]['id'],'UserId':null}})[_0x5eb8('0x1d')](handleEntityNotFound(_0x5edd7f,null))['then'](function(_0x18a01f){if(_0x18a01f){_0x1c0c0f[_0x5eb8('0x25')]=_0x18a01f[_0x5eb8('0x61')]({'plain':!![]});return db[_0x5eb8('0x62')]['find']({'where':{'id':_0x18a01f['SmsInteractionId']}});}return null;})[_0x5eb8('0x1d')](handleEntityNotFound(_0x5edd7f,null))['then'](function(_0x2dac5d){if(_0x2dac5d){_0x1c0c0f['interaction']=_0x2dac5d[_0x5eb8('0x61')]({'plain':!![]});interaction_log[_0x5eb8('0x1e')]('[SMSMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x17319c[_0x5eb8('0x5f')]['id'],_0x17319c[_0x5eb8('0x5f')]['name'],_0x17319c[_0x5eb8('0x5f')]['role'],_0x1c0c0f['interaction']['id'],_0x17319c[_0x5eb8('0x55')]?JSON[_0x5eb8('0x22')](_0x17319c[_0x5eb8('0x55')]):_0x5eb8('0x67'));return respondWithRpcPromise(_0x5eb8('0x76'),'rejectMessage',_0x1c0c0f);}return null;})[_0x5eb8('0x1d')](function(_0x577b2b){var _0x1a8367=_0x5eb8('0x69')+_0x577b2b['message']['ContactId'];return db['sequelize'][_0x5eb8('0x3e')](_0x1a8367,{'type':db[_0x5eb8('0x6c')][_0x5eb8('0x6d')][_0x5eb8('0x6e')],'raw':!![]})[_0x5eb8('0x1d')](function(_0x1b2d26){return _0x1b2d26;});})[_0x5eb8('0x1d')](function(_0x5a0ef2){if(_0x5a0ef2){_0x1c0c0f['message'][_0x5eb8('0x77')]=_0x5a0ef2[0x0];if(!_0x17319c[_0x5eb8('0x55')][_0x5eb8('0x5e')])return;return db[_0x5eb8('0x78')][_0x5eb8('0x53')]({'where':{'id':_0x17319c[_0x5eb8('0x55')][_0x5eb8('0x5e')],'role':_0x5eb8('0x60')},'attributes':['id',_0x5eb8('0x36'),_0x5eb8('0x79'),'email',_0x5eb8('0x6f')],'raw':!![]});}return null;})['then'](function(_0x50f964){if(!_0x50f964)return null;_0x1c0c0f[_0x5eb8('0x25')][_0x5eb8('0x60')]=_0x50f964;return _0x1c0c0f;})[_0x5eb8('0x1d')](function(_0xd69778){if(_0xd69778){_0xd69778['message'][_0x5eb8('0x71')]=util[_0x5eb8('0x5c')](_0x5eb8('0x72'),_0x17319c[_0x5eb8('0x5f')][_0x5eb8('0x36')]);_0xd69778[_0x5eb8('0x25')]['channel']=_0x1c0c0f[_0x5eb8('0x73')];_0xd69778[_0x5eb8('0x25')][_0x5eb8('0x74')]=_0x1c0c0f['channel'];_0xd69778[_0x5eb8('0x25')][_0x5eb8('0x7a')]=_0x5eb8('0x30');respondWithRpcPromise('EventManager',_0x5eb8('0x75'),{'event':'rejectmessage','message':_0xd69778['message']},client9002);return _0x1c0c0f;}return null;})[_0x5eb8('0x1d')](respondWithResult(_0x5edd7f,null))['catch'](handleError(_0x5edd7f,null));};exports[_0x5eb8('0x28')]=function(_0x33e25c,_0x3acc73,_0x584180){if(_0x33e25c[_0x5eb8('0x55')]['id']){delete _0x33e25c[_0x5eb8('0x55')]['id'];}var _0x325e82;return db[_0x5eb8('0x3a')][_0x5eb8('0x53')]({'where':{'id':_0x33e25c[_0x5eb8('0x52')]['id']}})['then'](handleEntityNotFound(_0x3acc73,null))['then'](function(_0x2d3c46){if(_0x2d3c46){_0x325e82=_0x2d3c46;return db[_0x5eb8('0x7b')]['find']({'where':{'id':_0x2d3c46[_0x5eb8('0x7c')]}});}})['then'](handleEntityNotFound(_0x3acc73,null))[_0x5eb8('0x1d')](function(_0x3f949a){if(_0x3f949a){logger[_0x5eb8('0x7d')](_0x5eb8('0x21'),_0x5eb8('0x28'),_0x5eb8('0x7e'),_0x3f949a[_0x5eb8('0x3c')],util[_0x5eb8('0x7f')](_0x33e25c[_0x5eb8('0x55')],{'showHidden':![],'depth':null}));switch(_0x3f949a['type']){case _0x5eb8('0x80'):if(_0x33e25c[_0x5eb8('0x55')][_0x5eb8('0x81')]&&_0x33e25c[_0x5eb8('0x55')]['MessageSid']===_0x325e82[_0x5eb8('0x82')]){return _0x325e82[_0x5eb8('0x32')]({'read':!![]});}else{logger[_0x5eb8('0x23')]('SmsAccount,\x20%s,\x20%s,\x20%s','status','twilio',util[_0x5eb8('0x7f')](_0x33e25c[_0x5eb8('0x55')],{'showHidden':![],'depth':null}));}break;case'plivo':if(_0x33e25c[_0x5eb8('0x55')][_0x5eb8('0x83')]&&_0x33e25c[_0x5eb8('0x55')][_0x5eb8('0x83')]===_0x325e82[_0x5eb8('0x82')]&&_[_0x5eb8('0x84')]([_0x5eb8('0x85'),_0x5eb8('0x86')],_0x33e25c[_0x5eb8('0x55')]['Status'])>=0x0){return _0x325e82[_0x5eb8('0x32')]({'read':!![]});}else{logger['error'](_0x5eb8('0x87'),'status',_0x5eb8('0x88'),util[_0x5eb8('0x7f')](_0x33e25c[_0x5eb8('0x55')],{'showHidden':![],'depth':null}));}break;case'infobip':var _0x2dddf6=_0x33e25c['body']['results'][0x0];if(_0x2dddf6[_0x5eb8('0x28')][_0x5eb8('0x89')]===_0x5eb8('0x8a')){return _0x325e82[_0x5eb8('0x32')]({'read':!![]});}else{logger['error'](_0x5eb8('0x87'),_0x5eb8('0x28'),_0x5eb8('0x8b'),util[_0x5eb8('0x7f')](_0x33e25c['body'],{'showHidden':![],'depth':null}));}break;}return _0x325e82;}})[_0x5eb8('0x1d')](respondWithResult(_0x3acc73,null))['catch'](handleError(_0x3acc73,null));};
\ No newline at end of file