Built motion from commit da24aabd.|2.6.20
[motion2.git] / server / api / smsMessage / smsMessage.controller.js
index 2dc934d..8bdfce1 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x7d8a=['ContactId','sequelize','Sequelize','QueryTypes','SELECT','User','internal','agent','manual','interface','channel','event','EventManager','acceptmessage','reject','[SMSMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','contact','fullname','email','SIP/%s','motionChannel','rejectmessage','SmsAccount','received\x20delivery\x20report\x20from','twilio','MessageSid','messageId','SmsAccount,\x20%s,\x20%s,\x20%s','plivo','MessageUUID','sent','delivered','Status','inspect','results','groupName','DELIVERED','infobip','eml-format','rimraf','zip-dir','request-promise','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','squel','jsforce','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsMessage.socket','register','jayson/promise','http','client','request','debug','SmsMessage,\x20%s,\x20%s,\x20%s','request\x20sent','error','code','SmsMessage,\x20%s,\x20%s','message','info','result','catch','status','end','offset','undefined','limit','count','set','json','apply','save','then','sendStatus','name','index','map','SmsMessage','rawAttributes','fieldName','type','query','keys','filters','intersection','model','attributes','fields','hasOwnProperty','nolimit','order','sort','where','filter','merge','VIRTUAL','options','includeAll','include','rows','show','create','body','update','find','params','describe','sms-interactions','accept','sms','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','get','SmsInteraction','SmsInteractionId','isNil','read1stAt','[SMSMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','user','role','interaction','stringify','null','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'];(function(_0x47c52b,_0x45fd04){var _0x4c3e5a=function(_0x22986){while(--_0x22986){_0x47c52b['push'](_0x47c52b['shift']());}};_0x4c3e5a(++_0x45fd04);}(_0x7d8a,0xbf));var _0xa7d8=function(_0x334841,_0x2bbc4c){_0x334841=_0x334841-0x0;var _0x5beb4b=_0x7d8a[_0x334841];return _0x5beb4b;};'use strict';var emlformat=require(_0xa7d8('0x0'));var rimraf=require(_0xa7d8('0x1'));var zipdir=require(_0xa7d8('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xa7d8('0x3'));var moment=require('moment');var BPromise=require(_0xa7d8('0x4'));var Mustache=require(_0xa7d8('0x5'));var util=require(_0xa7d8('0x6'));var path=require(_0xa7d8('0x7'));var sox=require(_0xa7d8('0x8'));var csv=require('to-csv');var ejs=require(_0xa7d8('0x9'));var fs=require('fs');var fs_extra=require(_0xa7d8('0xa'));var _=require(_0xa7d8('0xb'));var squel=require(_0xa7d8('0xc'));var crypto=require('crypto');var jsforce=require(_0xa7d8('0xd'));var deskjs=require(_0xa7d8('0xe'));var toCsv=require(_0xa7d8('0xf'));var querystring=require('querystring');var Papa=require(_0xa7d8('0x10'));var Redis=require(_0xa7d8('0x11'));var authService=require(_0xa7d8('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0xa7d8('0x13'));var hardwareService=require(_0xa7d8('0x14'));var logger=require(_0xa7d8('0x15'))(_0xa7d8('0x16'));var utils=require(_0xa7d8('0x17'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xa7d8('0x18'))['db'];config[_0xa7d8('0x19')]=_[_0xa7d8('0x1a')](config[_0xa7d8('0x19')],{'host':_0xa7d8('0x1b'),'port':0x18eb});var socket=require(_0xa7d8('0x1c'))(new Redis(config[_0xa7d8('0x19')]));require(_0xa7d8('0x1d'))[_0xa7d8('0x1e')](socket);var jayson=require(_0xa7d8('0x1f'));var client=jayson['client'][_0xa7d8('0x20')]({'port':0x232c});var client9002=jayson[_0xa7d8('0x21')][_0xa7d8('0x20')]({'port':0x232a});function respondWithRpcPromise(_0x23f768,_0x31142f,_0x2fbb63,_0x3f43d2){return new BPromise(function(_0x5741e5,_0x174bb2){var _0x37db34=_0x3f43d2||client;return _0x37db34[_0xa7d8('0x22')](_0x23f768,_0x2fbb63)['then'](function(_0x343a06){logger['info']('SmsMessage,\x20%s,\x20%s',_0x31142f,'request\x20sent');logger[_0xa7d8('0x23')](_0xa7d8('0x24'),_0x31142f,_0xa7d8('0x25'),JSON['stringify'](_0x343a06));if(_0x343a06[_0xa7d8('0x26')]){if(_0x343a06['error'][_0xa7d8('0x27')]===0x1f4){logger[_0xa7d8('0x26')](_0xa7d8('0x28'),_0x31142f,_0x343a06[_0xa7d8('0x26')]['message']);return _0x174bb2(_0x343a06[_0xa7d8('0x26')][_0xa7d8('0x29')]);}logger[_0xa7d8('0x26')](_0xa7d8('0x28'),_0x31142f,_0x343a06[_0xa7d8('0x26')][_0xa7d8('0x29')]);return _0x5741e5(_0x343a06[_0xa7d8('0x26')][_0xa7d8('0x29')]);}else{logger[_0xa7d8('0x2a')](_0xa7d8('0x28'),_0x31142f,_0xa7d8('0x25'));_0x5741e5(_0x343a06[_0xa7d8('0x2b')][_0xa7d8('0x29')]);}})[_0xa7d8('0x2c')](function(_0x925452){logger['error']('SmsMessage,\x20%s,\x20%s',_0x31142f,_0x925452);_0x174bb2(_0x925452);});});}function respondWithStatusCode(_0x596873,_0xcf65d8){_0xcf65d8=_0xcf65d8||0xcc;return function(_0x4be29e){if(_0x4be29e){return _0x596873['sendStatus'](_0xcf65d8);}return _0x596873[_0xa7d8('0x2d')](_0xcf65d8)[_0xa7d8('0x2e')]();};}function respondWithResult(_0x164138,_0x21e63c){_0x21e63c=_0x21e63c||0xc8;return function(_0x21a398){if(_0x21a398){return _0x164138[_0xa7d8('0x2d')](_0x21e63c)['json'](_0x21a398);}};}function respondWithFilteredResult(_0x39f3e1,_0x1a4bab){return function(_0x2770c6){if(_0x2770c6){var _0x10411d=typeof _0x1a4bab[_0xa7d8('0x2f')]===_0xa7d8('0x30')&&typeof _0x1a4bab[_0xa7d8('0x31')]==='undefined';var _0x56d462=_0x2770c6[_0xa7d8('0x32')];var _0x3829fe=_0x10411d?0x0:_0x1a4bab[_0xa7d8('0x2f')];var _0x4fc5de=_0x10411d?_0x2770c6[_0xa7d8('0x32')]:_0x1a4bab[_0xa7d8('0x2f')]+_0x1a4bab['limit'];var _0x2f38d9;if(_0x4fc5de>=_0x56d462){_0x4fc5de=_0x56d462;_0x2f38d9=0xc8;}else{_0x2f38d9=0xce;}_0x39f3e1['status'](_0x2f38d9);return _0x39f3e1[_0xa7d8('0x33')]('Content-Range',_0x3829fe+'-'+_0x4fc5de+'/'+_0x56d462)[_0xa7d8('0x34')](_0x2770c6);}return null;};}function patchUpdates(_0x4cc87f){return function(_0x258594){try{jsonpatch[_0xa7d8('0x35')](_0x258594,_0x4cc87f,!![]);}catch(_0x1599ad){return BPromise['reject'](_0x1599ad);}return _0x258594[_0xa7d8('0x36')]();};}function saveUpdates(_0x5b72b4,_0x45067c){return function(_0x4ff75c){if(_0x4ff75c){return _0x4ff75c['update'](_0x5b72b4)[_0xa7d8('0x37')](function(_0x17be51){return _0x17be51;});}return null;};}function removeEntity(_0x23c8bb,_0x15af42){return function(_0x1022bc){if(_0x1022bc){return _0x1022bc['destroy']()['then'](function(){_0x23c8bb[_0xa7d8('0x2d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2d5cb1,_0x3431e5){return function(_0x478951){if(!_0x478951){_0x2d5cb1[_0xa7d8('0x38')](0x194);}return _0x478951;};}function handleError(_0x1c6632,_0x5550b6){_0x5550b6=_0x5550b6||0x1f4;return function(_0x27ae4c){logger['error'](_0x27ae4c['stack']);if(_0x27ae4c[_0xa7d8('0x39')]){delete _0x27ae4c['name'];}_0x1c6632['status'](_0x5550b6)['send'](_0x27ae4c);};}exports[_0xa7d8('0x3a')]=function(_0x1ac5cf,_0x20261c){var _0x586826={},_0x5856a0={},_0x385099={'count':0x0,'rows':[]};var _0x56b5a9=_[_0xa7d8('0x3b')](db[_0xa7d8('0x3c')][_0xa7d8('0x3d')],function(_0x5d3a79){return{'name':_0x5d3a79[_0xa7d8('0x3e')],'type':_0x5d3a79[_0xa7d8('0x3f')]['key']};});_0x5856a0['model']=_[_0xa7d8('0x3b')](_0x56b5a9,_0xa7d8('0x39'));_0x5856a0[_0xa7d8('0x40')]=_[_0xa7d8('0x41')](_0x1ac5cf[_0xa7d8('0x40')]);_0x5856a0[_0xa7d8('0x42')]=_[_0xa7d8('0x43')](_0x5856a0[_0xa7d8('0x44')],_0x5856a0[_0xa7d8('0x40')]);_0x586826[_0xa7d8('0x45')]=_[_0xa7d8('0x43')](_0x5856a0['model'],qs['fields'](_0x1ac5cf['query'][_0xa7d8('0x46')]));_0x586826['attributes']=_0x586826[_0xa7d8('0x45')]['length']?_0x586826['attributes']:_0x5856a0[_0xa7d8('0x44')];if(!_0x1ac5cf['query'][_0xa7d8('0x47')](_0xa7d8('0x48'))){_0x586826[_0xa7d8('0x31')]=qs[_0xa7d8('0x31')](_0x1ac5cf[_0xa7d8('0x40')][_0xa7d8('0x31')]);_0x586826['offset']=qs[_0xa7d8('0x2f')](_0x1ac5cf[_0xa7d8('0x40')][_0xa7d8('0x2f')]);}_0x586826[_0xa7d8('0x49')]=qs['sort'](_0x1ac5cf[_0xa7d8('0x40')][_0xa7d8('0x4a')]);_0x586826[_0xa7d8('0x4b')]=qs[_0xa7d8('0x42')](_['pick'](_0x1ac5cf['query'],_0x5856a0[_0xa7d8('0x42')]),_0x56b5a9);if(_0x1ac5cf[_0xa7d8('0x40')][_0xa7d8('0x4c')]){_0x586826[_0xa7d8('0x4b')]=_[_0xa7d8('0x4d')](_0x586826[_0xa7d8('0x4b')],{'$or':_['map'](_0x56b5a9,function(_0x577908){if(_0x577908[_0xa7d8('0x3f')]!==_0xa7d8('0x4e')){var _0x6b5abe={};_0x6b5abe[_0x577908[_0xa7d8('0x39')]]={'$like':'%'+_0x1ac5cf['query'][_0xa7d8('0x4c')]+'%'};return _0x6b5abe;}})});}_0x586826=_[_0xa7d8('0x4d')]({},_0x586826,_0x1ac5cf[_0xa7d8('0x4f')]);var _0x62cf2c={'where':_0x586826[_0xa7d8('0x4b')]};return db[_0xa7d8('0x3c')]['count'](_0x62cf2c)[_0xa7d8('0x37')](function(_0x2fd4bc){_0x385099[_0xa7d8('0x32')]=_0x2fd4bc;if(_0x1ac5cf[_0xa7d8('0x40')][_0xa7d8('0x50')]){_0x586826[_0xa7d8('0x51')]=[{'all':!![]}];}return db[_0xa7d8('0x3c')]['findAll'](_0x586826);})['then'](function(_0x3c93c0){_0x385099[_0xa7d8('0x52')]=_0x3c93c0;return _0x385099;})[_0xa7d8('0x37')](respondWithFilteredResult(_0x20261c,_0x586826))[_0xa7d8('0x2c')](handleError(_0x20261c,null));};exports[_0xa7d8('0x53')]=function(_0x472af2,_0x52e55e){var _0x4054c8={'raw':!![],'where':{'id':_0x472af2['params']['id']}},_0x54fa76={};_0x54fa76['model']=_['keys'](db[_0xa7d8('0x3c')][_0xa7d8('0x3d')]);_0x54fa76['query']=_[_0xa7d8('0x41')](_0x472af2['query']);_0x54fa76[_0xa7d8('0x42')]=_['intersection'](_0x54fa76[_0xa7d8('0x44')],_0x54fa76['query']);_0x4054c8[_0xa7d8('0x45')]=_[_0xa7d8('0x43')](_0x54fa76[_0xa7d8('0x44')],qs['fields'](_0x472af2[_0xa7d8('0x40')]['fields']));_0x4054c8[_0xa7d8('0x45')]=_0x4054c8['attributes']['length']?_0x4054c8[_0xa7d8('0x45')]:_0x54fa76['model'];if(_0x472af2[_0xa7d8('0x40')][_0xa7d8('0x50')]){_0x4054c8[_0xa7d8('0x51')]=[{'all':!![]}];}_0x4054c8=_[_0xa7d8('0x4d')]({},_0x4054c8,_0x472af2[_0xa7d8('0x4f')]);return db[_0xa7d8('0x3c')]['find'](_0x4054c8)[_0xa7d8('0x37')](handleEntityNotFound(_0x52e55e,null))[_0xa7d8('0x37')](respondWithResult(_0x52e55e,null))[_0xa7d8('0x2c')](handleError(_0x52e55e,null));};exports['create']=function(_0x118fc1,_0x3a5477){return db[_0xa7d8('0x3c')][_0xa7d8('0x54')](_0x118fc1[_0xa7d8('0x55')],{})[_0xa7d8('0x37')](respondWithResult(_0x3a5477,0xc9))[_0xa7d8('0x2c')](handleError(_0x3a5477,null));};exports[_0xa7d8('0x56')]=function(_0x5f55a6,_0x166602){if(_0x5f55a6[_0xa7d8('0x55')]['id']){delete _0x5f55a6[_0xa7d8('0x55')]['id'];}return db[_0xa7d8('0x3c')][_0xa7d8('0x57')]({'where':{'id':_0x5f55a6['params']['id']}})['then'](handleEntityNotFound(_0x166602,null))[_0xa7d8('0x37')](saveUpdates(_0x5f55a6['body'],null))[_0xa7d8('0x37')](respondWithResult(_0x166602,null))['catch'](handleError(_0x166602,null));};exports['destroy']=function(_0x2e8995,_0x39557f){return db[_0xa7d8('0x3c')]['find']({'where':{'id':_0x2e8995[_0xa7d8('0x58')]['id']}})[_0xa7d8('0x37')](handleEntityNotFound(_0x39557f,null))[_0xa7d8('0x37')](removeEntity(_0x39557f,null))[_0xa7d8('0x2c')](handleError(_0x39557f,null));};exports['describe']=function(_0x4cfa78,_0x441327){return db[_0xa7d8('0x3c')][_0xa7d8('0x59')]()['then'](respondWithResult(_0x441327,null))['catch'](handleError(_0x441327,null));};var interaction_log=require('../../config/logger')(_0xa7d8('0x5a'));exports[_0xa7d8('0x5b')]=function(_0x1c0bd4,_0x58b917,_0x431344){var _0x17843a={'agent':{},'channel':_0xa7d8('0x5c')};if(_0x1c0bd4[_0xa7d8('0x55')]['id']){delete _0x1c0bd4[_0xa7d8('0x55')]['id'];}_0x1c0bd4[_0xa7d8('0x55')][_0xa7d8('0x5d')]=!![];_0x1c0bd4[_0xa7d8('0x55')][_0xa7d8('0x5e')]=moment()[_0xa7d8('0x5f')](_0xa7d8('0x60'));_0x1c0bd4['body'][_0xa7d8('0x61')]=_0x1c0bd4[_0xa7d8('0x55')][_0xa7d8('0x61')]||_0x1c0bd4['user']['id'];_0x17843a['agent']['id']=_0x1c0bd4[_0xa7d8('0x55')][_0xa7d8('0x61')];return db['SmsMessage']['find']({'where':{'id':_0x1c0bd4[_0xa7d8('0x58')]['id'],'UserId':null}})[_0xa7d8('0x37')](handleEntityNotFound(_0x58b917,null))[_0xa7d8('0x37')](saveUpdates(_0x1c0bd4['body'],null))['then'](function(_0x204707){if(_0x204707){_0x17843a[_0xa7d8('0x29')]=_0x204707[_0xa7d8('0x62')]({'plain':!![]});return db[_0xa7d8('0x63')]['find']({'where':{'id':_0x204707[_0xa7d8('0x64')]}});}return null;})[_0xa7d8('0x37')](handleEntityNotFound(_0x58b917,null))['then'](function(_0x854dce){if(_0x854dce){return _0x854dce[_0xa7d8('0x56')]({'UserId':_0x1c0bd4[_0xa7d8('0x55')][_0xa7d8('0x61')],'read1stAt':_[_0xa7d8('0x65')](_0x854dce[_0xa7d8('0x66')])?moment()['format'](_0xa7d8('0x60')):undefined});}return null;})[_0xa7d8('0x37')](function(_0xb6225b){if(_0xb6225b){_0x17843a['interaction']=_0xb6225b[_0xa7d8('0x62')]({'plain':!![]});interaction_log[_0xa7d8('0x2a')](_0xa7d8('0x67'),_0x1c0bd4['user']['id'],_0x1c0bd4[_0xa7d8('0x68')]['name'],_0x1c0bd4['user'][_0xa7d8('0x69')],_0x17843a[_0xa7d8('0x6a')]['id'],_0x1c0bd4[_0xa7d8('0x55')]?JSON[_0xa7d8('0x6b')](_0x1c0bd4[_0xa7d8('0x55')]):_0xa7d8('0x6c'));return respondWithRpcPromise('AcceptMessage',_0xa7d8('0x6d'),_0x17843a);}return null;})[_0xa7d8('0x37')](function(_0x4ff71c){var _0x5ac11d=_0xa7d8('0x6e')+_0x4ff71c[_0xa7d8('0x29')][_0xa7d8('0x6f')];return db[_0xa7d8('0x70')][_0xa7d8('0x40')](_0x5ac11d,{'type':db[_0xa7d8('0x71')][_0xa7d8('0x72')][_0xa7d8('0x73')],'raw':!![]})[_0xa7d8('0x37')](function(_0x3a533){return _0x3a533;});})[_0xa7d8('0x37')](function(_0x2ee8b9){if(_0x2ee8b9){_0x17843a['message']['contact']=_0x2ee8b9[0x0];if(!_0x1c0bd4['body'][_0xa7d8('0x61')])return;return db[_0xa7d8('0x74')][_0xa7d8('0x57')]({'where':{'id':_0x1c0bd4['body'][_0xa7d8('0x61')],'role':'agent'},'attributes':['id','name','fullname','email',_0xa7d8('0x75')],'raw':!![]});}return null;})[_0xa7d8('0x37')](function(_0x597b59){if(!_0x597b59)return null;_0x17843a['message'][_0xa7d8('0x76')]=_0x597b59;return _0x17843a;})[_0xa7d8('0x37')](function(_0x5b9306){if(_0x5b9306){if(_0x1c0bd4[_0xa7d8('0x55')][_0xa7d8('0x77')]){_0x17843a[_0xa7d8('0x29')][_0xa7d8('0x78')]=util[_0xa7d8('0x5f')]('SIP/%s',_0x1c0bd4[_0xa7d8('0x68')][_0xa7d8('0x39')]);_0x17843a[_0xa7d8('0x29')]['channel']=_0x17843a[_0xa7d8('0x79')];_0x17843a['message']['motionChannel']=_0x17843a[_0xa7d8('0x79')];_0x17843a[_0xa7d8('0x29')][_0xa7d8('0x7a')]=_0xa7d8('0x5b');return respondWithRpcPromise('EventManager',_0xa7d8('0x7b'),{'event':_0xa7d8('0x7c'),'message':_0x17843a[_0xa7d8('0x29')]},client9002)[_0xa7d8('0x37')](function(){return _0x17843a;});}return _0x17843a;}return null;})[_0xa7d8('0x37')](respondWithResult(_0x58b917,null))[_0xa7d8('0x2c')](handleError(_0x58b917,null));};var interaction_log=require('../../config/logger')('sms-interactions');exports[_0xa7d8('0x7d')]=function(_0x621b35,_0x476a8e,_0x5c4d94){var _0x3b7923={'agent':{},'channel':_0xa7d8('0x5c')};if(_0x621b35['body']['id']){delete _0x621b35['body']['id'];}_0x621b35[_0xa7d8('0x55')]['UserId']=_0x621b35['body'][_0xa7d8('0x61')]||_0x621b35['user']['id'];_0x3b7923['agent']['id']=_0x621b35[_0xa7d8('0x55')][_0xa7d8('0x61')];return db[_0xa7d8('0x3c')][_0xa7d8('0x57')]({'where':{'id':_0x621b35[_0xa7d8('0x58')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x476a8e,null))[_0xa7d8('0x37')](function(_0x125eb2){if(_0x125eb2){_0x3b7923['message']=_0x125eb2[_0xa7d8('0x62')]({'plain':!![]});return db[_0xa7d8('0x63')][_0xa7d8('0x57')]({'where':{'id':_0x125eb2[_0xa7d8('0x64')]}});}return null;})[_0xa7d8('0x37')](handleEntityNotFound(_0x476a8e,null))[_0xa7d8('0x37')](function(_0x3259e3){if(_0x3259e3){_0x3b7923[_0xa7d8('0x6a')]=_0x3259e3[_0xa7d8('0x62')]({'plain':!![]});interaction_log[_0xa7d8('0x2a')](_0xa7d8('0x7e'),_0x621b35[_0xa7d8('0x68')]['id'],_0x621b35[_0xa7d8('0x68')]['name'],_0x621b35[_0xa7d8('0x68')][_0xa7d8('0x69')],_0x3b7923['interaction']['id'],_0x621b35[_0xa7d8('0x55')]?JSON[_0xa7d8('0x6b')](_0x621b35[_0xa7d8('0x55')]):_0xa7d8('0x6c'));return respondWithRpcPromise(_0xa7d8('0x7f'),_0xa7d8('0x80'),_0x3b7923);}return null;})[_0xa7d8('0x37')](function(_0x2dc4f9){var _0x363fe5='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x2dc4f9['message'][_0xa7d8('0x6f')];return db['sequelize'][_0xa7d8('0x40')](_0x363fe5,{'type':db[_0xa7d8('0x71')][_0xa7d8('0x72')][_0xa7d8('0x73')],'raw':!![]})[_0xa7d8('0x37')](function(_0x2cd24e){return _0x2cd24e;});})['then'](function(_0xa75638){if(_0xa75638){_0x3b7923['message'][_0xa7d8('0x81')]=_0xa75638[0x0];if(!_0x621b35[_0xa7d8('0x55')][_0xa7d8('0x61')])return;return db[_0xa7d8('0x74')][_0xa7d8('0x57')]({'where':{'id':_0x621b35[_0xa7d8('0x55')][_0xa7d8('0x61')],'role':_0xa7d8('0x76')},'attributes':['id',_0xa7d8('0x39'),_0xa7d8('0x82'),_0xa7d8('0x83'),'internal'],'raw':!![]});}return null;})[_0xa7d8('0x37')](function(_0x1e82ed){if(!_0x1e82ed)return null;_0x3b7923['message'][_0xa7d8('0x76')]=_0x1e82ed;return _0x3b7923;})['then'](function(_0x225a8c){if(_0x225a8c){_0x225a8c[_0xa7d8('0x29')][_0xa7d8('0x78')]=util['format'](_0xa7d8('0x84'),_0x621b35['user'][_0xa7d8('0x39')]);_0x225a8c[_0xa7d8('0x29')][_0xa7d8('0x79')]=_0x3b7923[_0xa7d8('0x79')];_0x225a8c['message'][_0xa7d8('0x85')]=_0x3b7923[_0xa7d8('0x79')];_0x225a8c[_0xa7d8('0x29')][_0xa7d8('0x7a')]=_0xa7d8('0x7d');respondWithRpcPromise(_0xa7d8('0x7b'),_0xa7d8('0x7b'),{'event':_0xa7d8('0x86'),'message':_0x225a8c[_0xa7d8('0x29')]},client9002);return _0x3b7923;}return null;})[_0xa7d8('0x37')](respondWithResult(_0x476a8e,null))[_0xa7d8('0x2c')](handleError(_0x476a8e,null));};exports[_0xa7d8('0x2d')]=function(_0x3d0d58,_0x5760c6,_0x1dc1b0){if(_0x3d0d58[_0xa7d8('0x55')]['id']){delete _0x3d0d58[_0xa7d8('0x55')]['id'];}var _0x487edd;return db[_0xa7d8('0x3c')][_0xa7d8('0x57')]({'where':{'id':_0x3d0d58[_0xa7d8('0x58')]['id']}})[_0xa7d8('0x37')](handleEntityNotFound(_0x5760c6,null))[_0xa7d8('0x37')](function(_0x159c34){if(_0x159c34){_0x487edd=_0x159c34;return db[_0xa7d8('0x87')][_0xa7d8('0x57')]({'where':{'id':_0x159c34['SmsAccountId']}});}})['then'](handleEntityNotFound(_0x5760c6,null))[_0xa7d8('0x37')](function(_0x33f808){if(_0x33f808){logger['debug']('SmsMessage,\x20%s,\x20%s,\x20%s',_0xa7d8('0x2d'),_0xa7d8('0x88'),_0x33f808[_0xa7d8('0x3f')],util['inspect'](_0x3d0d58[_0xa7d8('0x55')],{'showHidden':![],'depth':null}));switch(_0x33f808['type']){case _0xa7d8('0x89'):if(_0x3d0d58[_0xa7d8('0x55')][_0xa7d8('0x8a')]&&_0x3d0d58[_0xa7d8('0x55')][_0xa7d8('0x8a')]===_0x487edd[_0xa7d8('0x8b')]){return _0x487edd[_0xa7d8('0x56')]({'read':!![]});}else{logger[_0xa7d8('0x26')](_0xa7d8('0x8c'),_0xa7d8('0x2d'),_0xa7d8('0x89'),util['inspect'](_0x3d0d58[_0xa7d8('0x55')],{'showHidden':![],'depth':null}));}break;case _0xa7d8('0x8d'):if(_0x3d0d58[_0xa7d8('0x55')]['MessageUUID']&&_0x3d0d58[_0xa7d8('0x55')][_0xa7d8('0x8e')]===_0x487edd[_0xa7d8('0x8b')]&&_['indexOf']([_0xa7d8('0x8f'),_0xa7d8('0x90')],_0x3d0d58[_0xa7d8('0x55')][_0xa7d8('0x91')])>=0x0){return _0x487edd[_0xa7d8('0x56')]({'read':!![]});}else{logger[_0xa7d8('0x26')](_0xa7d8('0x8c'),_0xa7d8('0x2d'),'plivio',util[_0xa7d8('0x92')](_0x3d0d58['body'],{'showHidden':![],'depth':null}));}break;case'infobip':var _0x686f5=_0x3d0d58['body'][_0xa7d8('0x93')][0x0];if(_0x686f5[_0xa7d8('0x2d')][_0xa7d8('0x94')]===_0xa7d8('0x95')){return _0x487edd[_0xa7d8('0x56')]({'read':!![]});}else{logger[_0xa7d8('0x26')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xa7d8('0x2d'),_0xa7d8('0x96'),util[_0xa7d8('0x92')](_0x3d0d58[_0xa7d8('0x55')],{'showHidden':![],'depth':null}));}break;}return _0x487edd;}})[_0xa7d8('0x37')](respondWithResult(_0x5760c6,null))['catch'](handleError(_0x5760c6,null));};
\ No newline at end of file
+var _0xfc64=['groupName','DELIVERED','infobip','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','register','client','http','request','info','request\x20sent','debug','SmsMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','SmsMessage,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','json','offset','undefined','limit','count','Content-Range','apply','save','update','then','destroy','stack','name','index','SmsMessage','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','hasOwnProperty','nolimit','sort','where','merge','map','VIRTUAL','options','includeAll','include','findAll','rows','show','params','find','create','body','describe','sms-interactions','sms','read','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','get','SmsInteraction','SmsInteractionId','isNil','interaction','[SMSMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','Sequelize','QueryTypes','SELECT','contact','User','fullname','email','internal','manual','interface','SIP/%s','channel','motionChannel','event','EventManager','acceptmessage','reject','rejectMessage','ContactId','received\x20delivery\x20report\x20from','inspect','twilio','MessageSid','messageId','SmsAccount,\x20%s,\x20%s,\x20%s','plivo','MessageUUID','indexOf','sent','delivered','plivio'];(function(_0x17a3bf,_0x3fe868){var _0x1ff0e6=function(_0x22deb1){while(--_0x22deb1){_0x17a3bf['push'](_0x17a3bf['shift']());}};_0x1ff0e6(++_0x3fe868);}(_0xfc64,0x1b3));var _0x4fc6=function(_0x1ddedd,_0x485606){_0x1ddedd=_0x1ddedd-0x0;var _0xa3e1ac=_0xfc64[_0x1ddedd];return _0xa3e1ac;};'use strict';var emlformat=require(_0x4fc6('0x0'));var rimraf=require(_0x4fc6('0x1'));var zipdir=require(_0x4fc6('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x4fc6('0x3'));var moment=require(_0x4fc6('0x4'));var BPromise=require(_0x4fc6('0x5'));var Mustache=require(_0x4fc6('0x6'));var util=require(_0x4fc6('0x7'));var path=require('path');var sox=require(_0x4fc6('0x8'));var csv=require(_0x4fc6('0x9'));var ejs=require(_0x4fc6('0xa'));var fs=require('fs');var fs_extra=require(_0x4fc6('0xb'));var _=require(_0x4fc6('0xc'));var squel=require(_0x4fc6('0xd'));var crypto=require(_0x4fc6('0xe'));var jsforce=require('jsforce');var deskjs=require(_0x4fc6('0xf'));var toCsv=require(_0x4fc6('0x9'));var querystring=require(_0x4fc6('0x10'));var Papa=require(_0x4fc6('0x11'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x4fc6('0x12'));var as=require(_0x4fc6('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x4fc6('0x14'));var utils=require(_0x4fc6('0x15'));var config=require(_0x4fc6('0x16'));var licenseUtil=require(_0x4fc6('0x17'));var db=require(_0x4fc6('0x18'))['db'];config[_0x4fc6('0x19')]=_[_0x4fc6('0x1a')](config[_0x4fc6('0x19')],{'host':'localhost','port':0x18eb});var socket=require(_0x4fc6('0x1b'))(new Redis(config[_0x4fc6('0x19')]));require('./smsMessage.socket')[_0x4fc6('0x1c')](socket);var jayson=require('jayson/promise');var client=jayson['client']['http']({'port':0x232c});var client9002=jayson[_0x4fc6('0x1d')][_0x4fc6('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x4810e3,_0x55426f,_0x24a112,_0x53dfd6){return new BPromise(function(_0x40dc97,_0x27aec2){var _0x275f31=_0x53dfd6||client;return _0x275f31[_0x4fc6('0x1f')](_0x4810e3,_0x24a112)['then'](function(_0x3eef8e){logger[_0x4fc6('0x20')]('SmsMessage,\x20%s,\x20%s',_0x55426f,_0x4fc6('0x21'));logger[_0x4fc6('0x22')](_0x4fc6('0x23'),_0x55426f,_0x4fc6('0x21'),JSON[_0x4fc6('0x24')](_0x3eef8e));if(_0x3eef8e[_0x4fc6('0x25')]){if(_0x3eef8e[_0x4fc6('0x25')][_0x4fc6('0x26')]===0x1f4){logger[_0x4fc6('0x25')](_0x4fc6('0x27'),_0x55426f,_0x3eef8e[_0x4fc6('0x25')]['message']);return _0x27aec2(_0x3eef8e[_0x4fc6('0x25')][_0x4fc6('0x28')]);}logger[_0x4fc6('0x25')]('SmsMessage,\x20%s,\x20%s',_0x55426f,_0x3eef8e[_0x4fc6('0x25')][_0x4fc6('0x28')]);return _0x40dc97(_0x3eef8e[_0x4fc6('0x25')]['message']);}else{logger[_0x4fc6('0x20')]('SmsMessage,\x20%s,\x20%s',_0x55426f,_0x4fc6('0x21'));_0x40dc97(_0x3eef8e[_0x4fc6('0x29')][_0x4fc6('0x28')]);}})[_0x4fc6('0x2a')](function(_0x1a0596){logger[_0x4fc6('0x25')]('SmsMessage,\x20%s,\x20%s',_0x55426f,_0x1a0596);_0x27aec2(_0x1a0596);});});}function respondWithStatusCode(_0x16632c,_0x3f6e3e){_0x3f6e3e=_0x3f6e3e||0xcc;return function(_0x5c64b5){if(_0x5c64b5){return _0x16632c[_0x4fc6('0x2b')](_0x3f6e3e);}return _0x16632c[_0x4fc6('0x2c')](_0x3f6e3e)[_0x4fc6('0x2d')]();};}function respondWithResult(_0x40f240,_0x15e29b){_0x15e29b=_0x15e29b||0xc8;return function(_0x3b7e8d){if(_0x3b7e8d){return _0x40f240['status'](_0x15e29b)[_0x4fc6('0x2e')](_0x3b7e8d);}};}function respondWithFilteredResult(_0x48be65,_0x266d75){return function(_0x589bb1){if(_0x589bb1){var _0x1d0870=typeof _0x266d75[_0x4fc6('0x2f')]===_0x4fc6('0x30')&&typeof _0x266d75[_0x4fc6('0x31')]===_0x4fc6('0x30');var _0x37eac8=_0x589bb1[_0x4fc6('0x32')];var _0x467182=_0x1d0870?0x0:_0x266d75['offset'];var _0x218986=_0x1d0870?_0x589bb1[_0x4fc6('0x32')]:_0x266d75[_0x4fc6('0x2f')]+_0x266d75[_0x4fc6('0x31')];var _0x652420;if(_0x218986>=_0x37eac8){_0x218986=_0x37eac8;_0x652420=0xc8;}else{_0x652420=0xce;}_0x48be65['status'](_0x652420);return _0x48be65['set'](_0x4fc6('0x33'),_0x467182+'-'+_0x218986+'/'+_0x37eac8)[_0x4fc6('0x2e')](_0x589bb1);}return null;};}function patchUpdates(_0x2cebbf){return function(_0x2958d9){try{jsonpatch[_0x4fc6('0x34')](_0x2958d9,_0x2cebbf,!![]);}catch(_0x56dd81){return BPromise['reject'](_0x56dd81);}return _0x2958d9[_0x4fc6('0x35')]();};}function saveUpdates(_0x5d036f,_0x5c3add){return function(_0x1b45a8){if(_0x1b45a8){return _0x1b45a8[_0x4fc6('0x36')](_0x5d036f)[_0x4fc6('0x37')](function(_0xa076e7){return _0xa076e7;});}return null;};}function removeEntity(_0x3967dc,_0xe86b53){return function(_0x23b6f4){if(_0x23b6f4){return _0x23b6f4[_0x4fc6('0x38')]()[_0x4fc6('0x37')](function(){_0x3967dc[_0x4fc6('0x2c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4a7794,_0x386000){return function(_0x7e9c0a){if(!_0x7e9c0a){_0x4a7794[_0x4fc6('0x2b')](0x194);}return _0x7e9c0a;};}function handleError(_0x4b3b9e,_0x833e5){_0x833e5=_0x833e5||0x1f4;return function(_0x16d88d){logger['error'](_0x16d88d[_0x4fc6('0x39')]);if(_0x16d88d[_0x4fc6('0x3a')]){delete _0x16d88d['name'];}_0x4b3b9e[_0x4fc6('0x2c')](_0x833e5)['send'](_0x16d88d);};}exports[_0x4fc6('0x3b')]=function(_0x3f8f2d,_0x3a47ce){var _0x3c0b64={},_0x6bf8b8={},_0x54c8c2={'count':0x0,'rows':[]};var _0x2cc5a7=_['map'](db[_0x4fc6('0x3c')][_0x4fc6('0x3d')],function(_0x2cf18b){return{'name':_0x2cf18b[_0x4fc6('0x3e')],'type':_0x2cf18b[_0x4fc6('0x3f')][_0x4fc6('0x40')]};});_0x6bf8b8[_0x4fc6('0x41')]=_['map'](_0x2cc5a7,'name');_0x6bf8b8[_0x4fc6('0x42')]=_[_0x4fc6('0x43')](_0x3f8f2d[_0x4fc6('0x42')]);_0x6bf8b8[_0x4fc6('0x44')]=_[_0x4fc6('0x45')](_0x6bf8b8[_0x4fc6('0x41')],_0x6bf8b8[_0x4fc6('0x42')]);_0x3c0b64['attributes']=_[_0x4fc6('0x45')](_0x6bf8b8[_0x4fc6('0x41')],qs[_0x4fc6('0x46')](_0x3f8f2d[_0x4fc6('0x42')]['fields']));_0x3c0b64['attributes']=_0x3c0b64[_0x4fc6('0x47')]['length']?_0x3c0b64[_0x4fc6('0x47')]:_0x6bf8b8[_0x4fc6('0x41')];if(!_0x3f8f2d[_0x4fc6('0x42')][_0x4fc6('0x48')](_0x4fc6('0x49'))){_0x3c0b64[_0x4fc6('0x31')]=qs['limit'](_0x3f8f2d['query'][_0x4fc6('0x31')]);_0x3c0b64[_0x4fc6('0x2f')]=qs[_0x4fc6('0x2f')](_0x3f8f2d[_0x4fc6('0x42')]['offset']);}_0x3c0b64['order']=qs[_0x4fc6('0x4a')](_0x3f8f2d[_0x4fc6('0x42')][_0x4fc6('0x4a')]);_0x3c0b64[_0x4fc6('0x4b')]=qs[_0x4fc6('0x44')](_['pick'](_0x3f8f2d['query'],_0x6bf8b8[_0x4fc6('0x44')]),_0x2cc5a7);if(_0x3f8f2d['query']['filter']){_0x3c0b64['where']=_[_0x4fc6('0x4c')](_0x3c0b64[_0x4fc6('0x4b')],{'$or':_[_0x4fc6('0x4d')](_0x2cc5a7,function(_0x534555){if(_0x534555[_0x4fc6('0x3f')]!==_0x4fc6('0x4e')){var _0x2cec50={};_0x2cec50[_0x534555[_0x4fc6('0x3a')]]={'$like':'%'+_0x3f8f2d[_0x4fc6('0x42')]['filter']+'%'};return _0x2cec50;}})});}_0x3c0b64=_[_0x4fc6('0x4c')]({},_0x3c0b64,_0x3f8f2d[_0x4fc6('0x4f')]);var _0x313cd5={'where':_0x3c0b64[_0x4fc6('0x4b')]};return db[_0x4fc6('0x3c')][_0x4fc6('0x32')](_0x313cd5)[_0x4fc6('0x37')](function(_0x4647b1){_0x54c8c2['count']=_0x4647b1;if(_0x3f8f2d[_0x4fc6('0x42')][_0x4fc6('0x50')]){_0x3c0b64[_0x4fc6('0x51')]=[{'all':!![]}];}return db[_0x4fc6('0x3c')][_0x4fc6('0x52')](_0x3c0b64);})['then'](function(_0x458784){_0x54c8c2[_0x4fc6('0x53')]=_0x458784;return _0x54c8c2;})['then'](respondWithFilteredResult(_0x3a47ce,_0x3c0b64))[_0x4fc6('0x2a')](handleError(_0x3a47ce,null));};exports[_0x4fc6('0x54')]=function(_0x768994,_0x588e61){var _0x1be3fa={'raw':!![],'where':{'id':_0x768994[_0x4fc6('0x55')]['id']}},_0x1d1776={};_0x1d1776[_0x4fc6('0x41')]=_[_0x4fc6('0x43')](db['SmsMessage']['rawAttributes']);_0x1d1776[_0x4fc6('0x42')]=_[_0x4fc6('0x43')](_0x768994[_0x4fc6('0x42')]);_0x1d1776['filters']=_[_0x4fc6('0x45')](_0x1d1776[_0x4fc6('0x41')],_0x1d1776[_0x4fc6('0x42')]);_0x1be3fa['attributes']=_['intersection'](_0x1d1776['model'],qs[_0x4fc6('0x46')](_0x768994[_0x4fc6('0x42')][_0x4fc6('0x46')]));_0x1be3fa[_0x4fc6('0x47')]=_0x1be3fa[_0x4fc6('0x47')]['length']?_0x1be3fa['attributes']:_0x1d1776[_0x4fc6('0x41')];if(_0x768994[_0x4fc6('0x42')][_0x4fc6('0x50')]){_0x1be3fa[_0x4fc6('0x51')]=[{'all':!![]}];}_0x1be3fa=_['merge']({},_0x1be3fa,_0x768994[_0x4fc6('0x4f')]);return db[_0x4fc6('0x3c')][_0x4fc6('0x56')](_0x1be3fa)[_0x4fc6('0x37')](handleEntityNotFound(_0x588e61,null))[_0x4fc6('0x37')](respondWithResult(_0x588e61,null))[_0x4fc6('0x2a')](handleError(_0x588e61,null));};exports[_0x4fc6('0x57')]=function(_0x10efcd,_0x462a74){return db[_0x4fc6('0x3c')][_0x4fc6('0x57')](_0x10efcd['body'],{})[_0x4fc6('0x37')](respondWithResult(_0x462a74,0xc9))[_0x4fc6('0x2a')](handleError(_0x462a74,null));};exports[_0x4fc6('0x36')]=function(_0x13f5e6,_0x40b9b0){if(_0x13f5e6[_0x4fc6('0x58')]['id']){delete _0x13f5e6[_0x4fc6('0x58')]['id'];}return db[_0x4fc6('0x3c')][_0x4fc6('0x56')]({'where':{'id':_0x13f5e6['params']['id']}})['then'](handleEntityNotFound(_0x40b9b0,null))[_0x4fc6('0x37')](saveUpdates(_0x13f5e6[_0x4fc6('0x58')],null))[_0x4fc6('0x37')](respondWithResult(_0x40b9b0,null))[_0x4fc6('0x2a')](handleError(_0x40b9b0,null));};exports['destroy']=function(_0x532f4f,_0x56feff){return db[_0x4fc6('0x3c')][_0x4fc6('0x56')]({'where':{'id':_0x532f4f[_0x4fc6('0x55')]['id']}})['then'](handleEntityNotFound(_0x56feff,null))[_0x4fc6('0x37')](removeEntity(_0x56feff,null))[_0x4fc6('0x2a')](handleError(_0x56feff,null));};exports['describe']=function(_0x5484ce,_0x380430){return db[_0x4fc6('0x3c')][_0x4fc6('0x59')]()['then'](respondWithResult(_0x380430,null))[_0x4fc6('0x2a')](handleError(_0x380430,null));};var interaction_log=require('../../config/logger')(_0x4fc6('0x5a'));exports['accept']=function(_0x42ebf1,_0x16ed4a,_0x483709){var _0x208038={'agent':{},'channel':_0x4fc6('0x5b')};if(_0x42ebf1[_0x4fc6('0x58')]['id']){delete _0x42ebf1[_0x4fc6('0x58')]['id'];}_0x42ebf1[_0x4fc6('0x58')][_0x4fc6('0x5c')]=!![];_0x42ebf1[_0x4fc6('0x58')]['readAt']=moment()[_0x4fc6('0x5d')](_0x4fc6('0x5e'));_0x42ebf1['body'][_0x4fc6('0x5f')]=_0x42ebf1[_0x4fc6('0x58')][_0x4fc6('0x5f')]||_0x42ebf1[_0x4fc6('0x60')]['id'];_0x208038[_0x4fc6('0x61')]['id']=_0x42ebf1['body']['UserId'];return db[_0x4fc6('0x3c')]['find']({'where':{'id':_0x42ebf1['params']['id'],'UserId':null}})[_0x4fc6('0x37')](handleEntityNotFound(_0x16ed4a,null))['then'](saveUpdates(_0x42ebf1[_0x4fc6('0x58')],null))['then'](function(_0xcbfd73){if(_0xcbfd73){_0x208038[_0x4fc6('0x28')]=_0xcbfd73[_0x4fc6('0x62')]({'plain':!![]});return db[_0x4fc6('0x63')]['find']({'where':{'id':_0xcbfd73[_0x4fc6('0x64')]}});}return null;})['then'](handleEntityNotFound(_0x16ed4a,null))[_0x4fc6('0x37')](function(_0x1dfdf0){if(_0x1dfdf0){return _0x1dfdf0[_0x4fc6('0x36')]({'UserId':_0x42ebf1[_0x4fc6('0x58')]['UserId'],'read1stAt':_[_0x4fc6('0x65')](_0x1dfdf0['read1stAt'])?moment()['format'](_0x4fc6('0x5e')):undefined});}return null;})[_0x4fc6('0x37')](function(_0x4058d7){if(_0x4058d7){_0x208038[_0x4fc6('0x66')]=_0x4058d7[_0x4fc6('0x62')]({'plain':!![]});interaction_log['info'](_0x4fc6('0x67'),_0x42ebf1[_0x4fc6('0x60')]['id'],_0x42ebf1['user'][_0x4fc6('0x3a')],_0x42ebf1[_0x4fc6('0x60')][_0x4fc6('0x68')],_0x208038[_0x4fc6('0x66')]['id'],_0x42ebf1[_0x4fc6('0x58')]?JSON[_0x4fc6('0x24')](_0x42ebf1[_0x4fc6('0x58')]):_0x4fc6('0x69'));return respondWithRpcPromise(_0x4fc6('0x6a'),_0x4fc6('0x6b'),_0x208038);}return null;})[_0x4fc6('0x37')](function(_0x5c70b5){var _0x1a07af=_0x4fc6('0x6c')+_0x5c70b5[_0x4fc6('0x28')]['ContactId'];return db[_0x4fc6('0x6d')][_0x4fc6('0x42')](_0x1a07af,{'type':db[_0x4fc6('0x6e')][_0x4fc6('0x6f')][_0x4fc6('0x70')],'raw':!![]})['then'](function(_0x301e6e){return _0x301e6e;});})[_0x4fc6('0x37')](function(_0x233386){if(_0x233386){_0x208038[_0x4fc6('0x28')][_0x4fc6('0x71')]=_0x233386[0x0];if(!_0x42ebf1['body'][_0x4fc6('0x5f')])return;return db[_0x4fc6('0x72')][_0x4fc6('0x56')]({'where':{'id':_0x42ebf1[_0x4fc6('0x58')][_0x4fc6('0x5f')],'role':_0x4fc6('0x61')},'attributes':['id',_0x4fc6('0x3a'),_0x4fc6('0x73'),_0x4fc6('0x74'),_0x4fc6('0x75')],'raw':!![]});}return null;})['then'](function(_0x44ed6f){if(!_0x44ed6f)return null;_0x208038[_0x4fc6('0x28')][_0x4fc6('0x61')]=_0x44ed6f;return _0x208038;})['then'](function(_0x3c7613){if(_0x3c7613){if(_0x42ebf1[_0x4fc6('0x58')][_0x4fc6('0x76')]){_0x208038['message'][_0x4fc6('0x77')]=util['format'](_0x4fc6('0x78'),_0x42ebf1[_0x4fc6('0x60')][_0x4fc6('0x3a')]);_0x208038[_0x4fc6('0x28')][_0x4fc6('0x79')]=_0x208038[_0x4fc6('0x79')];_0x208038[_0x4fc6('0x28')][_0x4fc6('0x7a')]=_0x208038[_0x4fc6('0x79')];_0x208038[_0x4fc6('0x28')][_0x4fc6('0x7b')]='accept';return respondWithRpcPromise(_0x4fc6('0x7c'),_0x4fc6('0x7c'),{'event':_0x4fc6('0x7d'),'message':_0x208038[_0x4fc6('0x28')]},client9002)['then'](function(){return _0x208038;});}return _0x208038;}return null;})[_0x4fc6('0x37')](respondWithResult(_0x16ed4a,null))['catch'](handleError(_0x16ed4a,null));};var interaction_log=require('../../config/logger')('sms-interactions');exports[_0x4fc6('0x7e')]=function(_0x294f0d,_0x10158e,_0x39d308){var _0x5cfce5={'agent':{},'channel':_0x4fc6('0x5b')};if(_0x294f0d[_0x4fc6('0x58')]['id']){delete _0x294f0d[_0x4fc6('0x58')]['id'];}_0x294f0d['body'][_0x4fc6('0x5f')]=_0x294f0d[_0x4fc6('0x58')]['UserId']||_0x294f0d['user']['id'];_0x5cfce5[_0x4fc6('0x61')]['id']=_0x294f0d[_0x4fc6('0x58')][_0x4fc6('0x5f')];return db[_0x4fc6('0x3c')][_0x4fc6('0x56')]({'where':{'id':_0x294f0d[_0x4fc6('0x55')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x10158e,null))['then'](function(_0x691c5e){if(_0x691c5e){_0x5cfce5[_0x4fc6('0x28')]=_0x691c5e['get']({'plain':!![]});return db[_0x4fc6('0x63')][_0x4fc6('0x56')]({'where':{'id':_0x691c5e['SmsInteractionId']}});}return null;})['then'](handleEntityNotFound(_0x10158e,null))[_0x4fc6('0x37')](function(_0x59868c){if(_0x59868c){_0x5cfce5[_0x4fc6('0x66')]=_0x59868c[_0x4fc6('0x62')]({'plain':!![]});interaction_log['info']('[SMSMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x294f0d[_0x4fc6('0x60')]['id'],_0x294f0d[_0x4fc6('0x60')][_0x4fc6('0x3a')],_0x294f0d[_0x4fc6('0x60')][_0x4fc6('0x68')],_0x5cfce5['interaction']['id'],_0x294f0d['body']?JSON[_0x4fc6('0x24')](_0x294f0d['body']):_0x4fc6('0x69'));return respondWithRpcPromise('RejectMessage',_0x4fc6('0x7f'),_0x5cfce5);}return null;})[_0x4fc6('0x37')](function(_0x316043){var _0x2ecb26='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x316043['message'][_0x4fc6('0x80')];return db[_0x4fc6('0x6d')][_0x4fc6('0x42')](_0x2ecb26,{'type':db[_0x4fc6('0x6e')]['QueryTypes'][_0x4fc6('0x70')],'raw':!![]})[_0x4fc6('0x37')](function(_0x4077a9){return _0x4077a9;});})[_0x4fc6('0x37')](function(_0x1d5f08){if(_0x1d5f08){_0x5cfce5['message'][_0x4fc6('0x71')]=_0x1d5f08[0x0];if(!_0x294f0d[_0x4fc6('0x58')][_0x4fc6('0x5f')])return;return db[_0x4fc6('0x72')][_0x4fc6('0x56')]({'where':{'id':_0x294f0d[_0x4fc6('0x58')]['UserId'],'role':'agent'},'attributes':['id',_0x4fc6('0x3a'),_0x4fc6('0x73'),_0x4fc6('0x74'),'internal'],'raw':!![]});}return null;})[_0x4fc6('0x37')](function(_0x9d35c7){if(!_0x9d35c7)return null;_0x5cfce5[_0x4fc6('0x28')]['agent']=_0x9d35c7;return _0x5cfce5;})[_0x4fc6('0x37')](function(_0x3b9852){if(_0x3b9852){_0x3b9852[_0x4fc6('0x28')][_0x4fc6('0x77')]=util[_0x4fc6('0x5d')](_0x4fc6('0x78'),_0x294f0d['user'][_0x4fc6('0x3a')]);_0x3b9852[_0x4fc6('0x28')][_0x4fc6('0x79')]=_0x5cfce5['channel'];_0x3b9852[_0x4fc6('0x28')][_0x4fc6('0x7a')]=_0x5cfce5[_0x4fc6('0x79')];_0x3b9852[_0x4fc6('0x28')]['event']=_0x4fc6('0x7e');respondWithRpcPromise(_0x4fc6('0x7c'),'EventManager',{'event':'rejectmessage','message':_0x3b9852['message']},client9002);return _0x5cfce5;}return null;})['then'](respondWithResult(_0x10158e,null))[_0x4fc6('0x2a')](handleError(_0x10158e,null));};exports[_0x4fc6('0x2c')]=function(_0x4e2c6a,_0x15e533,_0x132da8){if(_0x4e2c6a[_0x4fc6('0x58')]['id']){delete _0x4e2c6a[_0x4fc6('0x58')]['id'];}var _0x3a8a9b;return db['SmsMessage']['find']({'where':{'id':_0x4e2c6a['params']['id']}})[_0x4fc6('0x37')](handleEntityNotFound(_0x15e533,null))['then'](function(_0xbbef33){if(_0xbbef33){_0x3a8a9b=_0xbbef33;return db['SmsAccount'][_0x4fc6('0x56')]({'where':{'id':_0xbbef33['SmsAccountId']}});}})[_0x4fc6('0x37')](handleEntityNotFound(_0x15e533,null))[_0x4fc6('0x37')](function(_0x592756){if(_0x592756){logger[_0x4fc6('0x22')](_0x4fc6('0x23'),'status',_0x4fc6('0x81'),_0x592756['type'],util[_0x4fc6('0x82')](_0x4e2c6a[_0x4fc6('0x58')],{'showHidden':![],'depth':null}));switch(_0x592756['type']){case _0x4fc6('0x83'):if(_0x4e2c6a[_0x4fc6('0x58')][_0x4fc6('0x84')]&&_0x4e2c6a[_0x4fc6('0x58')][_0x4fc6('0x84')]===_0x3a8a9b[_0x4fc6('0x85')]){return _0x3a8a9b[_0x4fc6('0x36')]({'read':!![]});}else{logger[_0x4fc6('0x25')](_0x4fc6('0x86'),'status',_0x4fc6('0x83'),util[_0x4fc6('0x82')](_0x4e2c6a[_0x4fc6('0x58')],{'showHidden':![],'depth':null}));}break;case _0x4fc6('0x87'):if(_0x4e2c6a['body']['MessageUUID']&&_0x4e2c6a[_0x4fc6('0x58')][_0x4fc6('0x88')]===_0x3a8a9b['messageId']&&_[_0x4fc6('0x89')]([_0x4fc6('0x8a'),_0x4fc6('0x8b')],_0x4e2c6a[_0x4fc6('0x58')]['Status'])>=0x0){return _0x3a8a9b[_0x4fc6('0x36')]({'read':!![]});}else{logger['error'](_0x4fc6('0x86'),'status',_0x4fc6('0x8c'),util[_0x4fc6('0x82')](_0x4e2c6a['body'],{'showHidden':![],'depth':null}));}break;case'infobip':var _0x1b26e5=_0x4e2c6a[_0x4fc6('0x58')]['results'][0x0];if(_0x1b26e5['status'][_0x4fc6('0x8d')]===_0x4fc6('0x8e')){return _0x3a8a9b['update']({'read':!![]});}else{logger[_0x4fc6('0x25')](_0x4fc6('0x86'),_0x4fc6('0x2c'),_0x4fc6('0x8f'),util[_0x4fc6('0x82')](_0x4e2c6a['body'],{'showHidden':![],'depth':null}));}break;}return _0x3a8a9b;}})[_0x4fc6('0x37')](respondWithResult(_0x15e533,null))['catch'](handleError(_0x15e533,null));};
\ No newline at end of file