Built motion from commit ab870f9e.|2.5.44
[motion2.git] / server / api / smsMessage / smsMessage.controller.js
index 15141d6..582774f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xe4b9=['acceptmessage','RejectMessage','rejectmessage','SmsAccount','SmsAccountId','received\x20delivery\x20report\x20from','inspect','MessageSid','SmsAccount,\x20%s,\x20%s,\x20%s','twilio','plivo','MessageUUID','messageId','indexOf','sent','Status','plivio','infobip','results','DELIVERED','html-pdf','zip-dir','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsMessage.socket','register','jayson/promise','client','http','request','then','info','SmsMessage,\x20%s,\x20%s','debug','SmsMessage,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','result','message','catch','sendStatus','status','end','offset','limit','set','Content-Range','apply','reject','update','destroy','stack','name','send','index','map','SmsMessage','rawAttributes','fieldName','model','query','filters','intersection','attributes','fields','hasOwnProperty','sort','where','pick','filter','type','VIRTUAL','merge','include','findAll','rows','params','keys','includeAll','options','find','create','body','describe','sms-interactions','accept','sms','read','readAt','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','Contact','SmsInteractionId','isNil','read1stAt','get','[SMSMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','interaction','null','AcceptMessage','acceptMessage','manual','interface','format','SIP/%s','channel','event','EventManager'];(function(_0x243643,_0x524240){var _0x2b2518=function(_0x25910d){while(--_0x25910d){_0x243643['push'](_0x243643['shift']());}};_0x2b2518(++_0x524240);}(_0xe4b9,0x9d));var _0x9e4b=function(_0x1d06a8,_0xb555ab){_0x1d06a8=_0x1d06a8-0x0;var _0x2db796=_0xe4b9[_0x1d06a8];return _0x2db796;};'use strict';var pdf=require(_0x9e4b('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x9e4b('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x9e4b('0x2'));var moment=require('moment');var BPromise=require(_0x9e4b('0x3'));var Mustache=require(_0x9e4b('0x4'));var util=require(_0x9e4b('0x5'));var path=require(_0x9e4b('0x6'));var sox=require(_0x9e4b('0x7'));var csv=require(_0x9e4b('0x8'));var ejs=require(_0x9e4b('0x9'));var fs=require('fs');var _=require(_0x9e4b('0xa'));var squel=require(_0x9e4b('0xb'));var crypto=require(_0x9e4b('0xc'));var jsforce=require(_0x9e4b('0xd'));var deskjs=require(_0x9e4b('0xe'));var toCsv=require(_0x9e4b('0x8'));var querystring=require(_0x9e4b('0xf'));var Papa=require(_0x9e4b('0x10'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x9e4b('0x11'));var hardwareService=require(_0x9e4b('0x12'));var logger=require(_0x9e4b('0x13'))(_0x9e4b('0x14'));var utils=require('../../config/utils');var config=require(_0x9e4b('0x15'));var licenseUtil=require(_0x9e4b('0x16'));var db=require(_0x9e4b('0x17'))['db'];config[_0x9e4b('0x18')]=_[_0x9e4b('0x19')](config[_0x9e4b('0x18')],{'host':_0x9e4b('0x1a'),'port':0x18eb});var socket=require(_0x9e4b('0x1b'))(new Redis(config[_0x9e4b('0x18')]));require(_0x9e4b('0x1c'))[_0x9e4b('0x1d')](socket);var jayson=require(_0x9e4b('0x1e'));var client=jayson[_0x9e4b('0x1f')][_0x9e4b('0x20')]({'port':0x232c});var client9002=jayson[_0x9e4b('0x1f')]['http']({'port':0x232a});function respondWithRpcPromise(_0x2e0aaa,_0x3f86af,_0x42810c,_0x43f223){return new BPromise(function(_0x1d3fc2,_0x3ef8c2){var _0x408979=_0x43f223||client;return _0x408979[_0x9e4b('0x21')](_0x2e0aaa,_0x42810c)[_0x9e4b('0x22')](function(_0x5904d0){logger[_0x9e4b('0x23')](_0x9e4b('0x24'),_0x3f86af,'request\x20sent');logger[_0x9e4b('0x25')](_0x9e4b('0x26'),_0x3f86af,_0x9e4b('0x27'),JSON[_0x9e4b('0x28')](_0x5904d0));if(_0x5904d0['error']){if(_0x5904d0[_0x9e4b('0x29')][_0x9e4b('0x2a')]===0x1f4){logger['error'](_0x9e4b('0x24'),_0x3f86af,_0x5904d0[_0x9e4b('0x29')]['message']);return _0x3ef8c2(_0x5904d0[_0x9e4b('0x29')]['message']);}logger[_0x9e4b('0x29')](_0x9e4b('0x24'),_0x3f86af,_0x5904d0[_0x9e4b('0x29')]['message']);return _0x1d3fc2(_0x5904d0[_0x9e4b('0x29')]['message']);}else{logger['info']('SmsMessage,\x20%s,\x20%s',_0x3f86af,_0x9e4b('0x27'));_0x1d3fc2(_0x5904d0[_0x9e4b('0x2b')][_0x9e4b('0x2c')]);}})[_0x9e4b('0x2d')](function(_0x48f638){logger[_0x9e4b('0x29')](_0x9e4b('0x24'),_0x3f86af,_0x48f638);_0x3ef8c2(_0x48f638);});});}function respondWithStatusCode(_0x37357e,_0x49f7dd){_0x49f7dd=_0x49f7dd||0xcc;return function(_0x38b72c){if(_0x38b72c){return _0x37357e[_0x9e4b('0x2e')](_0x49f7dd);}return _0x37357e[_0x9e4b('0x2f')](_0x49f7dd)[_0x9e4b('0x30')]();};}function respondWithResult(_0x443452,_0x45c513){_0x45c513=_0x45c513||0xc8;return function(_0x1e6a5c){if(_0x1e6a5c){return _0x443452[_0x9e4b('0x2f')](_0x45c513)['json'](_0x1e6a5c);}};}function respondWithFilteredResult(_0x12e92d,_0x42664b){return function(_0x20b4b2){if(_0x20b4b2){var _0x11ac53=_0x20b4b2['count'],_0x311b89=_0x42664b[_0x9e4b('0x31')],_0x43f0a8=_0x42664b[_0x9e4b('0x31')]+_0x42664b[_0x9e4b('0x32')],_0x558951;if(_0x43f0a8>=_0x11ac53){_0x43f0a8=_0x11ac53;_0x558951=0xc8;}else{_0x558951=0xce;}_0x12e92d[_0x9e4b('0x2f')](_0x558951);return _0x12e92d[_0x9e4b('0x33')](_0x9e4b('0x34'),_0x311b89+'-'+_0x43f0a8+'/'+_0x11ac53)['json'](_0x20b4b2);}return null;};}function patchUpdates(_0x1a3de4){return function(_0x834ab7){try{jsonpatch[_0x9e4b('0x35')](_0x834ab7,_0x1a3de4,!![]);}catch(_0x1a6eb6){return BPromise[_0x9e4b('0x36')](_0x1a6eb6);}return _0x834ab7['save']();};}function saveUpdates(_0x4b73cf,_0x1c9567){return function(_0x4f795a){if(_0x4f795a){return _0x4f795a[_0x9e4b('0x37')](_0x4b73cf)[_0x9e4b('0x22')](function(_0x53b541){return _0x53b541;});}return null;};}function removeEntity(_0x39bfc3,_0x44ad00){return function(_0x196496){if(_0x196496){return _0x196496[_0x9e4b('0x38')]()[_0x9e4b('0x22')](function(){_0x39bfc3[_0x9e4b('0x2f')](0xcc)[_0x9e4b('0x30')]();});}};}function handleEntityNotFound(_0x1b6b07,_0x2f3ab5){return function(_0x29cf54){if(!_0x29cf54){_0x1b6b07[_0x9e4b('0x2e')](0x194);}return _0x29cf54;};}function handleError(_0x31ae08,_0x4eac35){_0x4eac35=_0x4eac35||0x1f4;return function(_0x9b86e7){logger[_0x9e4b('0x29')](_0x9b86e7[_0x9e4b('0x39')]);if(_0x9b86e7[_0x9e4b('0x3a')]){delete _0x9b86e7[_0x9e4b('0x3a')];}_0x31ae08['status'](_0x4eac35)[_0x9e4b('0x3b')](_0x9b86e7);};}exports[_0x9e4b('0x3c')]=function(_0x3b62bb,_0x2ed282){var _0x323c6c={},_0xd6e006={},_0x2e4e1d={'count':0x0,'rows':[]};var _0x4677d7=_[_0x9e4b('0x3d')](db[_0x9e4b('0x3e')][_0x9e4b('0x3f')],function(_0x26348b){return{'name':_0x26348b[_0x9e4b('0x40')],'type':_0x26348b['type']['key']};});_0xd6e006[_0x9e4b('0x41')]=_['map'](_0x4677d7,'name');_0xd6e006[_0x9e4b('0x42')]=_['keys'](_0x3b62bb[_0x9e4b('0x42')]);_0xd6e006[_0x9e4b('0x43')]=_[_0x9e4b('0x44')](_0xd6e006[_0x9e4b('0x41')],_0xd6e006['query']);_0x323c6c[_0x9e4b('0x45')]=_['intersection'](_0xd6e006[_0x9e4b('0x41')],qs[_0x9e4b('0x46')](_0x3b62bb[_0x9e4b('0x42')][_0x9e4b('0x46')]));_0x323c6c[_0x9e4b('0x45')]=_0x323c6c['attributes']['length']?_0x323c6c[_0x9e4b('0x45')]:_0xd6e006[_0x9e4b('0x41')];if(!_0x3b62bb[_0x9e4b('0x42')][_0x9e4b('0x47')]('nolimit')){_0x323c6c['limit']=qs[_0x9e4b('0x32')](_0x3b62bb[_0x9e4b('0x42')][_0x9e4b('0x32')]);_0x323c6c[_0x9e4b('0x31')]=qs[_0x9e4b('0x31')](_0x3b62bb[_0x9e4b('0x42')][_0x9e4b('0x31')]);}_0x323c6c['order']=qs[_0x9e4b('0x48')](_0x3b62bb['query'][_0x9e4b('0x48')]);_0x323c6c[_0x9e4b('0x49')]=qs[_0x9e4b('0x43')](_[_0x9e4b('0x4a')](_0x3b62bb[_0x9e4b('0x42')],_0xd6e006[_0x9e4b('0x43')]),_0x4677d7);if(_0x3b62bb[_0x9e4b('0x42')][_0x9e4b('0x4b')]){_0x323c6c[_0x9e4b('0x49')]=_['merge'](_0x323c6c['where'],{'$or':_['map'](_0x4677d7,function(_0x9a1296){if(_0x9a1296[_0x9e4b('0x4c')]!==_0x9e4b('0x4d')){var _0x43947d={};_0x43947d[_0x9a1296[_0x9e4b('0x3a')]]={'$like':'%'+_0x3b62bb[_0x9e4b('0x42')]['filter']+'%'};return _0x43947d;}})});}_0x323c6c=_[_0x9e4b('0x4e')]({},_0x323c6c,_0x3b62bb['options']);var _0x1511e5={'where':_0x323c6c[_0x9e4b('0x49')]};return db[_0x9e4b('0x3e')]['count'](_0x1511e5)['then'](function(_0x5c355b){_0x2e4e1d['count']=_0x5c355b;if(_0x3b62bb[_0x9e4b('0x42')]['includeAll']){_0x323c6c[_0x9e4b('0x4f')]=[{'all':!![]}];}return db[_0x9e4b('0x3e')][_0x9e4b('0x50')](_0x323c6c);})['then'](function(_0x9b8cd1){_0x2e4e1d[_0x9e4b('0x51')]=_0x9b8cd1;return _0x2e4e1d;})[_0x9e4b('0x22')](respondWithFilteredResult(_0x2ed282,_0x323c6c))[_0x9e4b('0x2d')](handleError(_0x2ed282,null));};exports['show']=function(_0x3b4a05,_0x69d33d){var _0x464eb8={'raw':!![],'where':{'id':_0x3b4a05[_0x9e4b('0x52')]['id']}},_0x2b3d76={};_0x2b3d76[_0x9e4b('0x41')]=_[_0x9e4b('0x53')](db['SmsMessage'][_0x9e4b('0x3f')]);_0x2b3d76[_0x9e4b('0x42')]=_[_0x9e4b('0x53')](_0x3b4a05[_0x9e4b('0x42')]);_0x2b3d76['filters']=_[_0x9e4b('0x44')](_0x2b3d76[_0x9e4b('0x41')],_0x2b3d76[_0x9e4b('0x42')]);_0x464eb8[_0x9e4b('0x45')]=_[_0x9e4b('0x44')](_0x2b3d76[_0x9e4b('0x41')],qs[_0x9e4b('0x46')](_0x3b4a05[_0x9e4b('0x42')][_0x9e4b('0x46')]));_0x464eb8['attributes']=_0x464eb8['attributes']['length']?_0x464eb8[_0x9e4b('0x45')]:_0x2b3d76[_0x9e4b('0x41')];if(_0x3b4a05[_0x9e4b('0x42')][_0x9e4b('0x54')]){_0x464eb8['include']=[{'all':!![]}];}_0x464eb8=_['merge']({},_0x464eb8,_0x3b4a05[_0x9e4b('0x55')]);return db[_0x9e4b('0x3e')][_0x9e4b('0x56')](_0x464eb8)[_0x9e4b('0x22')](handleEntityNotFound(_0x69d33d,null))[_0x9e4b('0x22')](respondWithResult(_0x69d33d,null))[_0x9e4b('0x2d')](handleError(_0x69d33d,null));};exports[_0x9e4b('0x57')]=function(_0x57bb88,_0x38448e){return db[_0x9e4b('0x3e')][_0x9e4b('0x57')](_0x57bb88['body'],{})[_0x9e4b('0x22')](respondWithResult(_0x38448e,0xc9))[_0x9e4b('0x2d')](handleError(_0x38448e,null));};exports[_0x9e4b('0x37')]=function(_0x478ad6,_0x18d1ac){if(_0x478ad6['body']['id']){delete _0x478ad6[_0x9e4b('0x58')]['id'];}return db[_0x9e4b('0x3e')][_0x9e4b('0x56')]({'where':{'id':_0x478ad6[_0x9e4b('0x52')]['id']}})[_0x9e4b('0x22')](handleEntityNotFound(_0x18d1ac,null))[_0x9e4b('0x22')](saveUpdates(_0x478ad6[_0x9e4b('0x58')],null))['then'](respondWithResult(_0x18d1ac,null))['catch'](handleError(_0x18d1ac,null));};exports[_0x9e4b('0x38')]=function(_0x268cce,_0x26bb2d){return db[_0x9e4b('0x3e')]['find']({'where':{'id':_0x268cce[_0x9e4b('0x52')]['id']}})[_0x9e4b('0x22')](handleEntityNotFound(_0x26bb2d,null))[_0x9e4b('0x22')](removeEntity(_0x26bb2d,null))[_0x9e4b('0x2d')](handleError(_0x26bb2d,null));};exports['describe']=function(_0x247245,_0x111e3b){return db['SmsMessage'][_0x9e4b('0x59')]()['then'](respondWithResult(_0x111e3b,null))[_0x9e4b('0x2d')](handleError(_0x111e3b,null));};var interaction_log=require(_0x9e4b('0x13'))(_0x9e4b('0x5a'));exports[_0x9e4b('0x5b')]=function(_0x54a444,_0x48263e,_0x1b1a58){var _0x2f4c96={'agent':{},'channel':_0x9e4b('0x5c')};if(_0x54a444[_0x9e4b('0x58')]['id']){delete _0x54a444[_0x9e4b('0x58')]['id'];}_0x54a444[_0x9e4b('0x58')][_0x9e4b('0x5d')]=!![];_0x54a444[_0x9e4b('0x58')][_0x9e4b('0x5e')]=moment()['format'](_0x9e4b('0x5f'));_0x54a444['body'][_0x9e4b('0x60')]=_0x54a444['body'][_0x9e4b('0x60')]||_0x54a444[_0x9e4b('0x61')]['id'];_0x2f4c96[_0x9e4b('0x62')]['id']=_0x54a444[_0x9e4b('0x58')][_0x9e4b('0x60')];return db[_0x9e4b('0x3e')][_0x9e4b('0x56')]({'where':{'id':_0x54a444[_0x9e4b('0x52')]['id'],'UserId':null},'include':[{'model':db['CmContact'],'as':_0x9e4b('0x63')}]})['then'](handleEntityNotFound(_0x48263e,null))[_0x9e4b('0x22')](saveUpdates(_0x54a444[_0x9e4b('0x58')],null))[_0x9e4b('0x22')](function(_0x446042){if(_0x446042){_0x2f4c96['message']=_0x446042['get']({'plain':!![]});return db['SmsInteraction'][_0x9e4b('0x56')]({'where':{'id':_0x446042[_0x9e4b('0x64')]}});}return null;})['then'](handleEntityNotFound(_0x48263e,null))[_0x9e4b('0x22')](function(_0x3b38d8){if(_0x3b38d8){return _0x3b38d8[_0x9e4b('0x37')]({'UserId':_0x54a444[_0x9e4b('0x58')][_0x9e4b('0x60')],'read1stAt':_[_0x9e4b('0x65')](_0x3b38d8[_0x9e4b('0x66')])?moment()['format'](_0x9e4b('0x5f')):undefined});}return null;})[_0x9e4b('0x22')](function(_0x10775e){if(_0x10775e){_0x2f4c96['interaction']=_0x10775e[_0x9e4b('0x67')]({'plain':!![]});interaction_log['info'](_0x9e4b('0x68'),_0x54a444[_0x9e4b('0x61')]['id'],_0x54a444['user'][_0x9e4b('0x3a')],_0x54a444[_0x9e4b('0x61')][_0x9e4b('0x69')],_0x2f4c96[_0x9e4b('0x6a')]['id'],_0x54a444[_0x9e4b('0x58')]?JSON[_0x9e4b('0x28')](_0x54a444[_0x9e4b('0x58')]):_0x9e4b('0x6b'));return respondWithRpcPromise(_0x9e4b('0x6c'),_0x9e4b('0x6d'),_0x2f4c96);}return null;})[_0x9e4b('0x22')](function(_0x389e43){if(_0x389e43){if(_0x54a444['body'][_0x9e4b('0x6e')]){_0x2f4c96['message'][_0x9e4b('0x6f')]=util[_0x9e4b('0x70')](_0x9e4b('0x71'),_0x54a444[_0x9e4b('0x61')][_0x9e4b('0x3a')]);_0x2f4c96[_0x9e4b('0x2c')]['channel']=_0x2f4c96[_0x9e4b('0x72')];_0x2f4c96[_0x9e4b('0x2c')][_0x9e4b('0x73')]='accept';return respondWithRpcPromise('EventManager',_0x9e4b('0x74'),{'event':_0x9e4b('0x75'),'message':_0x2f4c96['message']},client9002)[_0x9e4b('0x22')](function(){return _0x2f4c96;});}return _0x2f4c96;}return null;})['then'](respondWithResult(_0x48263e,null))[_0x9e4b('0x2d')](handleError(_0x48263e,null));};var interaction_log=require(_0x9e4b('0x13'))(_0x9e4b('0x5a'));exports[_0x9e4b('0x36')]=function(_0x28dd8b,_0x548252,_0x1de7f0){var _0x12035c={'agent':{},'channel':'sms'};if(_0x28dd8b[_0x9e4b('0x58')]['id']){delete _0x28dd8b[_0x9e4b('0x58')]['id'];}_0x28dd8b[_0x9e4b('0x58')][_0x9e4b('0x60')]=_0x28dd8b[_0x9e4b('0x58')][_0x9e4b('0x60')]||_0x28dd8b[_0x9e4b('0x61')]['id'];_0x12035c[_0x9e4b('0x62')]['id']=_0x28dd8b[_0x9e4b('0x58')][_0x9e4b('0x60')];return db[_0x9e4b('0x3e')][_0x9e4b('0x56')]({'where':{'id':_0x28dd8b[_0x9e4b('0x52')]['id'],'UserId':null}})[_0x9e4b('0x22')](handleEntityNotFound(_0x548252,null))[_0x9e4b('0x22')](function(_0x3b03aa){if(_0x3b03aa){_0x12035c['message']=_0x3b03aa[_0x9e4b('0x67')]({'plain':!![]});return db['SmsInteraction'][_0x9e4b('0x56')]({'where':{'id':_0x3b03aa[_0x9e4b('0x64')]}});}return null;})[_0x9e4b('0x22')](handleEntityNotFound(_0x548252,null))[_0x9e4b('0x22')](function(_0x3d9d14){if(_0x3d9d14){_0x12035c[_0x9e4b('0x6a')]=_0x3d9d14[_0x9e4b('0x67')]({'plain':!![]});interaction_log['info']('[SMSMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x28dd8b[_0x9e4b('0x61')]['id'],_0x28dd8b['user'][_0x9e4b('0x3a')],_0x28dd8b['user']['role'],_0x12035c[_0x9e4b('0x6a')]['id'],_0x28dd8b[_0x9e4b('0x58')]?JSON[_0x9e4b('0x28')](_0x28dd8b[_0x9e4b('0x58')]):_0x9e4b('0x6b'));return respondWithRpcPromise(_0x9e4b('0x76'),'rejectMessage',_0x12035c);}return null;})['then'](function(_0x190fa3){if(_0x190fa3){_0x190fa3[_0x9e4b('0x2c')][_0x9e4b('0x6f')]=util['format']('SIP/%s',_0x28dd8b[_0x9e4b('0x61')]['name']);_0x190fa3[_0x9e4b('0x2c')][_0x9e4b('0x72')]=_0x12035c[_0x9e4b('0x72')];_0x190fa3[_0x9e4b('0x2c')]['event']=_0x9e4b('0x36');respondWithRpcPromise(_0x9e4b('0x74'),_0x9e4b('0x74'),{'event':_0x9e4b('0x77'),'message':_0x190fa3[_0x9e4b('0x2c')]},client9002);return _0x12035c;}return null;})[_0x9e4b('0x22')](respondWithResult(_0x548252,null))['catch'](handleError(_0x548252,null));};exports[_0x9e4b('0x2f')]=function(_0x2094c8,_0x3a1246,_0x222fd4){if(_0x2094c8[_0x9e4b('0x58')]['id']){delete _0x2094c8[_0x9e4b('0x58')]['id'];}var _0x536a76;return db['SmsMessage'][_0x9e4b('0x56')]({'where':{'id':_0x2094c8[_0x9e4b('0x52')]['id']}})[_0x9e4b('0x22')](handleEntityNotFound(_0x3a1246,null))[_0x9e4b('0x22')](function(_0x5f1053){if(_0x5f1053){_0x536a76=_0x5f1053;return db[_0x9e4b('0x78')][_0x9e4b('0x56')]({'where':{'id':_0x5f1053[_0x9e4b('0x79')]}});}})[_0x9e4b('0x22')](handleEntityNotFound(_0x3a1246,null))['then'](function(_0x32a796){if(_0x32a796){logger[_0x9e4b('0x25')](_0x9e4b('0x26'),_0x9e4b('0x2f'),_0x9e4b('0x7a'),_0x32a796['type'],util[_0x9e4b('0x7b')](_0x2094c8[_0x9e4b('0x58')],{'showHidden':![],'depth':null}));switch(_0x32a796[_0x9e4b('0x4c')]){case'twilio':if(_0x2094c8[_0x9e4b('0x58')][_0x9e4b('0x7c')]&&_0x2094c8[_0x9e4b('0x58')][_0x9e4b('0x7c')]===_0x536a76['messageId']){return _0x536a76['update']({'read':!![]});}else{logger[_0x9e4b('0x29')](_0x9e4b('0x7d'),'status',_0x9e4b('0x7e'),util[_0x9e4b('0x7b')](_0x2094c8['body'],{'showHidden':![],'depth':null}));}break;case _0x9e4b('0x7f'):if(_0x2094c8['body'][_0x9e4b('0x80')]&&_0x2094c8[_0x9e4b('0x58')][_0x9e4b('0x80')]===_0x536a76[_0x9e4b('0x81')]&&_[_0x9e4b('0x82')]([_0x9e4b('0x83'),'delivered'],_0x2094c8[_0x9e4b('0x58')][_0x9e4b('0x84')])>=0x0){return _0x536a76[_0x9e4b('0x37')]({'read':!![]});}else{logger['error'](_0x9e4b('0x7d'),_0x9e4b('0x2f'),_0x9e4b('0x85'),util[_0x9e4b('0x7b')](_0x2094c8['body'],{'showHidden':![],'depth':null}));}break;case _0x9e4b('0x86'):var _0x3721ad=_0x2094c8[_0x9e4b('0x58')][_0x9e4b('0x87')][0x0];if(_0x3721ad[_0x9e4b('0x2f')]['groupName']===_0x9e4b('0x88')){return _0x536a76['update']({'read':!![]});}else{logger[_0x9e4b('0x29')](_0x9e4b('0x7d'),_0x9e4b('0x2f'),_0x9e4b('0x86'),util[_0x9e4b('0x7b')](_0x2094c8['body'],{'showHidden':![],'depth':null}));}break;}return _0x536a76;}})['then'](respondWithResult(_0x3a1246,null))[_0x9e4b('0x2d')](handleError(_0x3a1246,null));};
\ No newline at end of file
+var _0xbc7a=['event','rejectmessage','SmsAccount','SmsAccountId','inspect','twilio','MessageSid','messageId','plivo','MessageUUID','indexOf','sent','delivered','Status','SmsAccount,\x20%s,\x20%s,\x20%s','plivio','infobip','results','groupName','DELIVERED','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','socket.io-emitter','register','client','http','then','SmsMessage,\x20%s,\x20%s','request\x20sent','SmsMessage,\x20%s,\x20%s,\x20%s','error','message','info','result','catch','sendStatus','end','offset','undefined','limit','count','status','apply','reject','save','update','stack','send','rawAttributes','fieldName','type','key','map','name','query','keys','filters','model','attributes','intersection','fields','length','nolimit','sort','where','pick','filter','merge','VIRTUAL','options','SmsMessage','include','findAll','rows','show','params','create','body','find','destroy','describe','sms-interactions','sms','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','get','SmsInteraction','isNil','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','User','fullname','email','internal','interface','SIP/%s','channel','motionChannel','accept','EventManager','acceptmessage','SmsInteractionId','stringify','RejectMessage','rejectMessage'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xbc7a,0xa4));var _0xabc7=function(_0x59b6c1,_0x33258b){_0x59b6c1=_0x59b6c1-0x0;var _0x329560=_0xbc7a[_0x59b6c1];return _0x329560;};'use strict';var emlformat=require(_0xabc7('0x0'));var rimraf=require(_0xabc7('0x1'));var zipdir=require(_0xabc7('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xabc7('0x3'));var moment=require(_0xabc7('0x4'));var BPromise=require(_0xabc7('0x5'));var Mustache=require(_0xabc7('0x6'));var util=require(_0xabc7('0x7'));var path=require(_0xabc7('0x8'));var sox=require('sox');var csv=require(_0xabc7('0x9'));var ejs=require(_0xabc7('0xa'));var fs=require('fs');var fs_extra=require(_0xabc7('0xb'));var _=require(_0xabc7('0xc'));var squel=require(_0xabc7('0xd'));var crypto=require(_0xabc7('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xabc7('0xf'));var toCsv=require('to-csv');var querystring=require(_0xabc7('0x10'));var Papa=require(_0xabc7('0x11'));var Redis=require(_0xabc7('0x12'));var authService=require(_0xabc7('0x13'));var qs=require(_0xabc7('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xabc7('0x15'))('api');var utils=require(_0xabc7('0x16'));var config=require(_0xabc7('0x17'));var licenseUtil=require(_0xabc7('0x18'));var db=require('../../mysqldb')['db'];config[_0xabc7('0x19')]=_[_0xabc7('0x1a')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xabc7('0x1b'))(new Redis(config[_0xabc7('0x19')]));require('./smsMessage.socket')[_0xabc7('0x1c')](socket);var jayson=require('jayson/promise');var client=jayson[_0xabc7('0x1d')][_0xabc7('0x1e')]({'port':0x232c});var client9002=jayson[_0xabc7('0x1d')][_0xabc7('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x4b3575,_0x50027a,_0x42f77a,_0xa23fd){return new BPromise(function(_0x4216a2,_0x2d1e4e){var _0x5a184e=_0xa23fd||client;return _0x5a184e['request'](_0x4b3575,_0x42f77a)[_0xabc7('0x1f')](function(_0x181dd6){logger['info'](_0xabc7('0x20'),_0x50027a,_0xabc7('0x21'));logger['debug'](_0xabc7('0x22'),_0x50027a,_0xabc7('0x21'),JSON['stringify'](_0x181dd6));if(_0x181dd6[_0xabc7('0x23')]){if(_0x181dd6['error']['code']===0x1f4){logger['error'](_0xabc7('0x20'),_0x50027a,_0x181dd6['error'][_0xabc7('0x24')]);return _0x2d1e4e(_0x181dd6['error']['message']);}logger[_0xabc7('0x23')](_0xabc7('0x20'),_0x50027a,_0x181dd6[_0xabc7('0x23')]['message']);return _0x4216a2(_0x181dd6[_0xabc7('0x23')][_0xabc7('0x24')]);}else{logger[_0xabc7('0x25')](_0xabc7('0x20'),_0x50027a,_0xabc7('0x21'));_0x4216a2(_0x181dd6[_0xabc7('0x26')][_0xabc7('0x24')]);}})[_0xabc7('0x27')](function(_0x924f1b){logger['error'](_0xabc7('0x20'),_0x50027a,_0x924f1b);_0x2d1e4e(_0x924f1b);});});}function respondWithStatusCode(_0x2c66d2,_0x10bb9e){_0x10bb9e=_0x10bb9e||0xcc;return function(_0x5b5a59){if(_0x5b5a59){return _0x2c66d2[_0xabc7('0x28')](_0x10bb9e);}return _0x2c66d2['status'](_0x10bb9e)[_0xabc7('0x29')]();};}function respondWithResult(_0x2a0d86,_0x305cdb){_0x305cdb=_0x305cdb||0xc8;return function(_0x429144){if(_0x429144){return _0x2a0d86['status'](_0x305cdb)['json'](_0x429144);}};}function respondWithFilteredResult(_0x3b0bdc,_0x5dd2a3){return function(_0x5a4c1d){if(_0x5a4c1d){var _0x1fdbea=typeof _0x5dd2a3[_0xabc7('0x2a')]===_0xabc7('0x2b')&&typeof _0x5dd2a3[_0xabc7('0x2c')]===_0xabc7('0x2b');var _0x22d34e=_0x5a4c1d[_0xabc7('0x2d')];var _0x43b4a9=_0x1fdbea?0x0:_0x5dd2a3[_0xabc7('0x2a')];var _0xdcb9aa=_0x1fdbea?_0x5a4c1d['count']:_0x5dd2a3['offset']+_0x5dd2a3[_0xabc7('0x2c')];var _0x249dc4;if(_0xdcb9aa>=_0x22d34e){_0xdcb9aa=_0x22d34e;_0x249dc4=0xc8;}else{_0x249dc4=0xce;}_0x3b0bdc[_0xabc7('0x2e')](_0x249dc4);return _0x3b0bdc['set']('Content-Range',_0x43b4a9+'-'+_0xdcb9aa+'/'+_0x22d34e)['json'](_0x5a4c1d);}return null;};}function patchUpdates(_0x3976d2){return function(_0x233bcb){try{jsonpatch[_0xabc7('0x2f')](_0x233bcb,_0x3976d2,!![]);}catch(_0x212648){return BPromise[_0xabc7('0x30')](_0x212648);}return _0x233bcb[_0xabc7('0x31')]();};}function saveUpdates(_0x3572f6,_0x1810ec){return function(_0x17e125){if(_0x17e125){return _0x17e125[_0xabc7('0x32')](_0x3572f6)[_0xabc7('0x1f')](function(_0xf77b21){return _0xf77b21;});}return null;};}function removeEntity(_0x1426cd,_0x219eb7){return function(_0x67dbd2){if(_0x67dbd2){return _0x67dbd2['destroy']()[_0xabc7('0x1f')](function(){_0x1426cd[_0xabc7('0x2e')](0xcc)[_0xabc7('0x29')]();});}};}function handleEntityNotFound(_0xe68b4e,_0x33c64e){return function(_0xe55703){if(!_0xe55703){_0xe68b4e['sendStatus'](0x194);}return _0xe55703;};}function handleError(_0x1a46d9,_0x271779){_0x271779=_0x271779||0x1f4;return function(_0x468f37){logger[_0xabc7('0x23')](_0x468f37[_0xabc7('0x33')]);if(_0x468f37['name']){delete _0x468f37['name'];}_0x1a46d9[_0xabc7('0x2e')](_0x271779)[_0xabc7('0x34')](_0x468f37);};}exports['index']=function(_0x1f3c8a,_0x389c39){var _0x4112b3={},_0x286b6f={},_0xbbf5ad={'count':0x0,'rows':[]};var _0xe798fa=_['map'](db['SmsMessage'][_0xabc7('0x35')],function(_0x3110ab){return{'name':_0x3110ab[_0xabc7('0x36')],'type':_0x3110ab[_0xabc7('0x37')][_0xabc7('0x38')]};});_0x286b6f['model']=_[_0xabc7('0x39')](_0xe798fa,_0xabc7('0x3a'));_0x286b6f[_0xabc7('0x3b')]=_[_0xabc7('0x3c')](_0x1f3c8a['query']);_0x286b6f[_0xabc7('0x3d')]=_['intersection'](_0x286b6f[_0xabc7('0x3e')],_0x286b6f[_0xabc7('0x3b')]);_0x4112b3[_0xabc7('0x3f')]=_[_0xabc7('0x40')](_0x286b6f['model'],qs['fields'](_0x1f3c8a[_0xabc7('0x3b')][_0xabc7('0x41')]));_0x4112b3['attributes']=_0x4112b3[_0xabc7('0x3f')][_0xabc7('0x42')]?_0x4112b3[_0xabc7('0x3f')]:_0x286b6f[_0xabc7('0x3e')];if(!_0x1f3c8a['query']['hasOwnProperty'](_0xabc7('0x43'))){_0x4112b3[_0xabc7('0x2c')]=qs['limit'](_0x1f3c8a[_0xabc7('0x3b')][_0xabc7('0x2c')]);_0x4112b3[_0xabc7('0x2a')]=qs[_0xabc7('0x2a')](_0x1f3c8a[_0xabc7('0x3b')]['offset']);}_0x4112b3['order']=qs[_0xabc7('0x44')](_0x1f3c8a[_0xabc7('0x3b')]['sort']);_0x4112b3[_0xabc7('0x45')]=qs[_0xabc7('0x3d')](_[_0xabc7('0x46')](_0x1f3c8a[_0xabc7('0x3b')],_0x286b6f['filters']),_0xe798fa);if(_0x1f3c8a['query'][_0xabc7('0x47')]){_0x4112b3[_0xabc7('0x45')]=_[_0xabc7('0x48')](_0x4112b3['where'],{'$or':_[_0xabc7('0x39')](_0xe798fa,function(_0x41cca1){if(_0x41cca1[_0xabc7('0x37')]!==_0xabc7('0x49')){var _0x5be7af={};_0x5be7af[_0x41cca1[_0xabc7('0x3a')]]={'$like':'%'+_0x1f3c8a[_0xabc7('0x3b')][_0xabc7('0x47')]+'%'};return _0x5be7af;}})});}_0x4112b3=_[_0xabc7('0x48')]({},_0x4112b3,_0x1f3c8a[_0xabc7('0x4a')]);var _0x227f9c={'where':_0x4112b3[_0xabc7('0x45')]};return db[_0xabc7('0x4b')][_0xabc7('0x2d')](_0x227f9c)[_0xabc7('0x1f')](function(_0x20112f){_0xbbf5ad[_0xabc7('0x2d')]=_0x20112f;if(_0x1f3c8a[_0xabc7('0x3b')]['includeAll']){_0x4112b3[_0xabc7('0x4c')]=[{'all':!![]}];}return db[_0xabc7('0x4b')][_0xabc7('0x4d')](_0x4112b3);})[_0xabc7('0x1f')](function(_0x20a31f){_0xbbf5ad[_0xabc7('0x4e')]=_0x20a31f;return _0xbbf5ad;})[_0xabc7('0x1f')](respondWithFilteredResult(_0x389c39,_0x4112b3))['catch'](handleError(_0x389c39,null));};exports[_0xabc7('0x4f')]=function(_0xfab427,_0x2a4d89){var _0x559b65={'raw':!![],'where':{'id':_0xfab427[_0xabc7('0x50')]['id']}},_0x464a68={};_0x464a68['model']=_[_0xabc7('0x3c')](db[_0xabc7('0x4b')][_0xabc7('0x35')]);_0x464a68[_0xabc7('0x3b')]=_[_0xabc7('0x3c')](_0xfab427[_0xabc7('0x3b')]);_0x464a68['filters']=_['intersection'](_0x464a68[_0xabc7('0x3e')],_0x464a68['query']);_0x559b65[_0xabc7('0x3f')]=_[_0xabc7('0x40')](_0x464a68[_0xabc7('0x3e')],qs[_0xabc7('0x41')](_0xfab427['query'][_0xabc7('0x41')]));_0x559b65[_0xabc7('0x3f')]=_0x559b65['attributes']['length']?_0x559b65['attributes']:_0x464a68[_0xabc7('0x3e')];if(_0xfab427[_0xabc7('0x3b')]['includeAll']){_0x559b65[_0xabc7('0x4c')]=[{'all':!![]}];}_0x559b65=_[_0xabc7('0x48')]({},_0x559b65,_0xfab427['options']);return db[_0xabc7('0x4b')]['find'](_0x559b65)[_0xabc7('0x1f')](handleEntityNotFound(_0x2a4d89,null))[_0xabc7('0x1f')](respondWithResult(_0x2a4d89,null))[_0xabc7('0x27')](handleError(_0x2a4d89,null));};exports[_0xabc7('0x51')]=function(_0x10280f,_0x3b58b6){return db[_0xabc7('0x4b')][_0xabc7('0x51')](_0x10280f[_0xabc7('0x52')],{})['then'](respondWithResult(_0x3b58b6,0xc9))[_0xabc7('0x27')](handleError(_0x3b58b6,null));};exports['update']=function(_0x4af394,_0x553418){if(_0x4af394[_0xabc7('0x52')]['id']){delete _0x4af394[_0xabc7('0x52')]['id'];}return db[_0xabc7('0x4b')][_0xabc7('0x53')]({'where':{'id':_0x4af394['params']['id']}})[_0xabc7('0x1f')](handleEntityNotFound(_0x553418,null))['then'](saveUpdates(_0x4af394[_0xabc7('0x52')],null))['then'](respondWithResult(_0x553418,null))[_0xabc7('0x27')](handleError(_0x553418,null));};exports[_0xabc7('0x54')]=function(_0x4d266b,_0x314740){return db[_0xabc7('0x4b')][_0xabc7('0x53')]({'where':{'id':_0x4d266b['params']['id']}})[_0xabc7('0x1f')](handleEntityNotFound(_0x314740,null))['then'](removeEntity(_0x314740,null))['catch'](handleError(_0x314740,null));};exports[_0xabc7('0x55')]=function(_0x3fcf5a,_0x3ef95f){return db['SmsMessage'][_0xabc7('0x55')]()[_0xabc7('0x1f')](respondWithResult(_0x3ef95f,null))[_0xabc7('0x27')](handleError(_0x3ef95f,null));};var interaction_log=require('../../config/logger')(_0xabc7('0x56'));exports['accept']=function(_0x44a86a,_0x430279,_0x2f963a){var _0x3615af={'agent':{},'channel':_0xabc7('0x57')};if(_0x44a86a[_0xabc7('0x52')]['id']){delete _0x44a86a['body']['id'];}_0x44a86a[_0xabc7('0x52')]['read']=!![];_0x44a86a['body'][_0xabc7('0x58')]=moment()[_0xabc7('0x59')](_0xabc7('0x5a'));_0x44a86a[_0xabc7('0x52')][_0xabc7('0x5b')]=_0x44a86a[_0xabc7('0x52')]['UserId']||_0x44a86a[_0xabc7('0x5c')]['id'];_0x3615af[_0xabc7('0x5d')]['id']=_0x44a86a[_0xabc7('0x52')][_0xabc7('0x5b')];return db[_0xabc7('0x4b')][_0xabc7('0x53')]({'where':{'id':_0x44a86a[_0xabc7('0x50')]['id'],'UserId':null}})[_0xabc7('0x1f')](handleEntityNotFound(_0x430279,null))[_0xabc7('0x1f')](saveUpdates(_0x44a86a[_0xabc7('0x52')],null))[_0xabc7('0x1f')](function(_0x345f84){if(_0x345f84){_0x3615af[_0xabc7('0x24')]=_0x345f84[_0xabc7('0x5e')]({'plain':!![]});return db[_0xabc7('0x5f')]['find']({'where':{'id':_0x345f84['SmsInteractionId']}});}return null;})[_0xabc7('0x1f')](handleEntityNotFound(_0x430279,null))['then'](function(_0xe52f1c){if(_0xe52f1c){return _0xe52f1c['update']({'UserId':_0x44a86a[_0xabc7('0x52')][_0xabc7('0x5b')],'read1stAt':_[_0xabc7('0x60')](_0xe52f1c['read1stAt'])?moment()[_0xabc7('0x59')](_0xabc7('0x5a')):undefined});}return null;})[_0xabc7('0x1f')](function(_0x5be9a6){if(_0x5be9a6){_0x3615af[_0xabc7('0x61')]=_0x5be9a6[_0xabc7('0x5e')]({'plain':!![]});interaction_log['info'](_0xabc7('0x62'),_0x44a86a[_0xabc7('0x5c')]['id'],_0x44a86a[_0xabc7('0x5c')][_0xabc7('0x3a')],_0x44a86a[_0xabc7('0x5c')][_0xabc7('0x63')],_0x3615af[_0xabc7('0x61')]['id'],_0x44a86a[_0xabc7('0x52')]?JSON['stringify'](_0x44a86a[_0xabc7('0x52')]):_0xabc7('0x64'));return respondWithRpcPromise('AcceptMessage',_0xabc7('0x65'),_0x3615af);}return null;})[_0xabc7('0x1f')](function(_0x38c3ab){var _0x31338c=_0xabc7('0x66')+_0x38c3ab[_0xabc7('0x24')][_0xabc7('0x67')];return db[_0xabc7('0x68')][_0xabc7('0x3b')](_0x31338c,{'type':db[_0xabc7('0x69')][_0xabc7('0x6a')][_0xabc7('0x6b')],'raw':!![]})[_0xabc7('0x1f')](function(_0x51b26f){return _0x51b26f;});})[_0xabc7('0x1f')](function(_0x5ef6d6){if(_0x5ef6d6){_0x3615af[_0xabc7('0x24')][_0xabc7('0x6c')]=_0x5ef6d6[0x0];if(!_0x44a86a[_0xabc7('0x52')][_0xabc7('0x5b')])return;return db[_0xabc7('0x6d')][_0xabc7('0x53')]({'where':{'id':_0x44a86a[_0xabc7('0x52')][_0xabc7('0x5b')],'role':'agent'},'attributes':['id',_0xabc7('0x3a'),_0xabc7('0x6e'),_0xabc7('0x6f'),_0xabc7('0x70')],'raw':!![]});}return null;})[_0xabc7('0x1f')](function(_0x457be5){if(!_0x457be5)return null;_0x3615af[_0xabc7('0x24')]['agent']=_0x457be5;return _0x3615af;})[_0xabc7('0x1f')](function(_0x23e80a){if(_0x23e80a){if(_0x44a86a[_0xabc7('0x52')]['manual']){_0x3615af['message'][_0xabc7('0x71')]=util[_0xabc7('0x59')](_0xabc7('0x72'),_0x44a86a[_0xabc7('0x5c')][_0xabc7('0x3a')]);_0x3615af[_0xabc7('0x24')][_0xabc7('0x73')]=_0x3615af[_0xabc7('0x73')];_0x3615af[_0xabc7('0x24')][_0xabc7('0x74')]=_0x3615af[_0xabc7('0x73')];_0x3615af[_0xabc7('0x24')]['event']=_0xabc7('0x75');return respondWithRpcPromise(_0xabc7('0x76'),_0xabc7('0x76'),{'event':_0xabc7('0x77'),'message':_0x3615af[_0xabc7('0x24')]},client9002)[_0xabc7('0x1f')](function(){return _0x3615af;});}return _0x3615af;}return null;})['then'](respondWithResult(_0x430279,null))[_0xabc7('0x27')](handleError(_0x430279,null));};var interaction_log=require('../../config/logger')(_0xabc7('0x56'));exports[_0xabc7('0x30')]=function(_0x295582,_0x323a77,_0x284f1b){var _0x8ae4c6={'agent':{},'channel':_0xabc7('0x57')};if(_0x295582[_0xabc7('0x52')]['id']){delete _0x295582['body']['id'];}_0x295582[_0xabc7('0x52')][_0xabc7('0x5b')]=_0x295582[_0xabc7('0x52')][_0xabc7('0x5b')]||_0x295582[_0xabc7('0x5c')]['id'];_0x8ae4c6[_0xabc7('0x5d')]['id']=_0x295582['body'][_0xabc7('0x5b')];return db['SmsMessage']['find']({'where':{'id':_0x295582[_0xabc7('0x50')]['id'],'UserId':null}})[_0xabc7('0x1f')](handleEntityNotFound(_0x323a77,null))[_0xabc7('0x1f')](function(_0x49f00d){if(_0x49f00d){_0x8ae4c6[_0xabc7('0x24')]=_0x49f00d[_0xabc7('0x5e')]({'plain':!![]});return db[_0xabc7('0x5f')][_0xabc7('0x53')]({'where':{'id':_0x49f00d[_0xabc7('0x78')]}});}return null;})[_0xabc7('0x1f')](handleEntityNotFound(_0x323a77,null))[_0xabc7('0x1f')](function(_0xc8a3d8){if(_0xc8a3d8){_0x8ae4c6[_0xabc7('0x61')]=_0xc8a3d8[_0xabc7('0x5e')]({'plain':!![]});interaction_log[_0xabc7('0x25')]('[SMSMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x295582[_0xabc7('0x5c')]['id'],_0x295582[_0xabc7('0x5c')]['name'],_0x295582[_0xabc7('0x5c')][_0xabc7('0x63')],_0x8ae4c6[_0xabc7('0x61')]['id'],_0x295582['body']?JSON[_0xabc7('0x79')](_0x295582['body']):'null');return respondWithRpcPromise(_0xabc7('0x7a'),_0xabc7('0x7b'),_0x8ae4c6);}return null;})[_0xabc7('0x1f')](function(_0x4785a4){var _0x3a0587=_0xabc7('0x66')+_0x4785a4[_0xabc7('0x24')][_0xabc7('0x67')];return db[_0xabc7('0x68')][_0xabc7('0x3b')](_0x3a0587,{'type':db[_0xabc7('0x69')][_0xabc7('0x6a')]['SELECT'],'raw':!![]})['then'](function(_0x26a799){return _0x26a799;});})[_0xabc7('0x1f')](function(_0x2e6d01){if(_0x2e6d01){_0x8ae4c6[_0xabc7('0x24')][_0xabc7('0x6c')]=_0x2e6d01[0x0];if(!_0x295582[_0xabc7('0x52')][_0xabc7('0x5b')])return;return db[_0xabc7('0x6d')][_0xabc7('0x53')]({'where':{'id':_0x295582[_0xabc7('0x52')][_0xabc7('0x5b')],'role':_0xabc7('0x5d')},'attributes':['id',_0xabc7('0x3a'),'fullname',_0xabc7('0x6f'),_0xabc7('0x70')],'raw':!![]});}return null;})[_0xabc7('0x1f')](function(_0x46f801){if(!_0x46f801)return null;_0x8ae4c6[_0xabc7('0x24')][_0xabc7('0x5d')]=_0x46f801;return _0x8ae4c6;})[_0xabc7('0x1f')](function(_0x4cf193){if(_0x4cf193){_0x4cf193['message']['interface']=util['format'](_0xabc7('0x72'),_0x295582[_0xabc7('0x5c')][_0xabc7('0x3a')]);_0x4cf193['message'][_0xabc7('0x73')]=_0x8ae4c6[_0xabc7('0x73')];_0x4cf193['message'][_0xabc7('0x74')]=_0x8ae4c6[_0xabc7('0x73')];_0x4cf193[_0xabc7('0x24')][_0xabc7('0x7c')]='reject';respondWithRpcPromise(_0xabc7('0x76'),'EventManager',{'event':_0xabc7('0x7d'),'message':_0x4cf193[_0xabc7('0x24')]},client9002);return _0x8ae4c6;}return null;})[_0xabc7('0x1f')](respondWithResult(_0x323a77,null))[_0xabc7('0x27')](handleError(_0x323a77,null));};exports[_0xabc7('0x2e')]=function(_0x145242,_0x4dfeea,_0x48e977){if(_0x145242['body']['id']){delete _0x145242[_0xabc7('0x52')]['id'];}var _0x4c1d32;return db[_0xabc7('0x4b')][_0xabc7('0x53')]({'where':{'id':_0x145242[_0xabc7('0x50')]['id']}})['then'](handleEntityNotFound(_0x4dfeea,null))[_0xabc7('0x1f')](function(_0x5b4a0c){if(_0x5b4a0c){_0x4c1d32=_0x5b4a0c;return db[_0xabc7('0x7e')]['find']({'where':{'id':_0x5b4a0c[_0xabc7('0x7f')]}});}})[_0xabc7('0x1f')](handleEntityNotFound(_0x4dfeea,null))[_0xabc7('0x1f')](function(_0x37803d){if(_0x37803d){logger['debug'](_0xabc7('0x22'),_0xabc7('0x2e'),'received\x20delivery\x20report\x20from',_0x37803d[_0xabc7('0x37')],util[_0xabc7('0x80')](_0x145242[_0xabc7('0x52')],{'showHidden':![],'depth':null}));switch(_0x37803d[_0xabc7('0x37')]){case _0xabc7('0x81'):if(_0x145242[_0xabc7('0x52')]['MessageSid']&&_0x145242['body'][_0xabc7('0x82')]===_0x4c1d32[_0xabc7('0x83')]){return _0x4c1d32[_0xabc7('0x32')]({'read':!![]});}else{logger[_0xabc7('0x23')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xabc7('0x2e'),_0xabc7('0x81'),util[_0xabc7('0x80')](_0x145242[_0xabc7('0x52')],{'showHidden':![],'depth':null}));}break;case _0xabc7('0x84'):if(_0x145242['body'][_0xabc7('0x85')]&&_0x145242[_0xabc7('0x52')]['MessageUUID']===_0x4c1d32['messageId']&&_[_0xabc7('0x86')]([_0xabc7('0x87'),_0xabc7('0x88')],_0x145242['body'][_0xabc7('0x89')])>=0x0){return _0x4c1d32[_0xabc7('0x32')]({'read':!![]});}else{logger[_0xabc7('0x23')](_0xabc7('0x8a'),_0xabc7('0x2e'),_0xabc7('0x8b'),util[_0xabc7('0x80')](_0x145242[_0xabc7('0x52')],{'showHidden':![],'depth':null}));}break;case _0xabc7('0x8c'):var _0x2a8c63=_0x145242[_0xabc7('0x52')][_0xabc7('0x8d')][0x0];if(_0x2a8c63[_0xabc7('0x2e')][_0xabc7('0x8e')]===_0xabc7('0x8f')){return _0x4c1d32[_0xabc7('0x32')]({'read':!![]});}else{logger[_0xabc7('0x23')](_0xabc7('0x8a'),_0xabc7('0x2e'),_0xabc7('0x8c'),util[_0xabc7('0x80')](_0x145242[_0xabc7('0x52')],{'showHidden':![],'depth':null}));}break;}return _0x4c1d32;}})['then'](respondWithResult(_0x4dfeea,null))[_0xabc7('0x27')](handleError(_0x4dfeea,null));};
\ No newline at end of file