Built motion from commit 14588770.|2.5.38
[motion2.git] / server / api / smsMessage / smsMessage.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x26b0=['rejectmessage','SmsAccount','SmsAccountId','debug','SmsMessage,\x20%s,\x20%s,\x20%s','twilio','MessageSid','SmsAccount,\x20%s,\x20%s,\x20%s','inspect','plivo','MessageUUID','messageId','indexOf','sent','delivered','Status','plivio','infobip','results','groupName','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','fs-extra','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsMessage.socket','jayson/promise','client','http','SmsMessage,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','info','result','end','status','undefined','limit','count','offset','set','Content-Range','json','reject','save','update','then','destroy','sendStatus','name','index','map','SmsMessage','rawAttributes','type','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','sort','filters','pick','filter','where','VIRTUAL','merge','options','includeAll','include','findAll','rows','catch','params','find','create','body','sms-interactions','accept','sms','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','SmsInteraction','SmsInteractionId','isNil','interaction','get','[SMSMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','SELECT','User','fullname','internal','interface','SIP/%s','channel','motionChannel','event','EventManager','acceptmessage','[SMSMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','RejectMessage','rejectMessage','QueryTypes','contact','email'];(function(_0x303c30,_0x16edcb){var _0x43161b=function(_0x3330ff){while(--_0x3330ff){_0x303c30['push'](_0x303c30['shift']());}};_0x43161b(++_0x16edcb);}(_0x26b0,0x138));var _0x026b=function(_0x5d845a,_0x3d3db0){_0x5d845a=_0x5d845a-0x0;var _0x111a7b=_0x26b0[_0x5d845a];return _0x111a7b;};'use strict';var emlformat=require(_0x026b('0x0'));var rimraf=require(_0x026b('0x1'));var zipdir=require(_0x026b('0x2'));var jsonpatch=require(_0x026b('0x3'));var rp=require(_0x026b('0x4'));var moment=require(_0x026b('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x026b('0x6'));var util=require(_0x026b('0x7'));var path=require(_0x026b('0x8'));var sox=require(_0x026b('0x9'));var csv=require(_0x026b('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x026b('0xb'));var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x026b('0xc'));var deskjs=require(_0x026b('0xd'));var toCsv=require(_0x026b('0xa'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x026b('0xe'));var authService=require(_0x026b('0xf'));var qs=require(_0x026b('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x026b('0x11'));var logger=require(_0x026b('0x12'))(_0x026b('0x13'));var utils=require(_0x026b('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0x026b('0x15'));var db=require(_0x026b('0x16'))['db'];config[_0x026b('0x17')]=_[_0x026b('0x18')](config[_0x026b('0x17')],{'host':_0x026b('0x19'),'port':0x18eb});var socket=require(_0x026b('0x1a'))(new Redis(config['redis']));require(_0x026b('0x1b'))['register'](socket);var jayson=require(_0x026b('0x1c'));var client=jayson[_0x026b('0x1d')][_0x026b('0x1e')]({'port':0x232c});var client9002=jayson[_0x026b('0x1d')]['http']({'port':0x232a});function respondWithRpcPromise(_0x250697,_0x1956a4,_0xe8d12,_0x4c0fca){return new BPromise(function(_0x5117f3,_0x4bd1ff){var _0x43b1a8=_0x4c0fca||client;return _0x43b1a8['request'](_0x250697,_0xe8d12)['then'](function(_0xbb0e24){logger['info'](_0x026b('0x1f'),_0x1956a4,_0x026b('0x20'));logger['debug']('SmsMessage,\x20%s,\x20%s,\x20%s',_0x1956a4,_0x026b('0x20'),JSON[_0x026b('0x21')](_0xbb0e24));if(_0xbb0e24[_0x026b('0x22')]){if(_0xbb0e24[_0x026b('0x22')][_0x026b('0x23')]===0x1f4){logger['error'](_0x026b('0x1f'),_0x1956a4,_0xbb0e24[_0x026b('0x22')][_0x026b('0x24')]);return _0x4bd1ff(_0xbb0e24['error'][_0x026b('0x24')]);}logger[_0x026b('0x22')](_0x026b('0x1f'),_0x1956a4,_0xbb0e24[_0x026b('0x22')][_0x026b('0x24')]);return _0x5117f3(_0xbb0e24['error'][_0x026b('0x24')]);}else{logger[_0x026b('0x25')](_0x026b('0x1f'),_0x1956a4,_0x026b('0x20'));_0x5117f3(_0xbb0e24[_0x026b('0x26')][_0x026b('0x24')]);}})['catch'](function(_0x4b42b9){logger[_0x026b('0x22')]('SmsMessage,\x20%s,\x20%s',_0x1956a4,_0x4b42b9);_0x4bd1ff(_0x4b42b9);});});}function respondWithStatusCode(_0x27cb59,_0x19b1dc){_0x19b1dc=_0x19b1dc||0xcc;return function(_0x39f344){if(_0x39f344){return _0x27cb59['sendStatus'](_0x19b1dc);}return _0x27cb59['status'](_0x19b1dc)[_0x026b('0x27')]();};}function respondWithResult(_0x3f3999,_0x472191){_0x472191=_0x472191||0xc8;return function(_0x382e51){if(_0x382e51){return _0x3f3999[_0x026b('0x28')](_0x472191)['json'](_0x382e51);}};}function respondWithFilteredResult(_0x2ab365,_0x335463){return function(_0x464667){if(_0x464667){var _0x2bb89f=typeof _0x335463['offset']===_0x026b('0x29')&&typeof _0x335463[_0x026b('0x2a')]==='undefined';var _0x59e9b2=_0x464667[_0x026b('0x2b')];var _0x34fbba=_0x2bb89f?0x0:_0x335463['offset'];var _0x5b9edf=_0x2bb89f?_0x464667['count']:_0x335463[_0x026b('0x2c')]+_0x335463['limit'];var _0x33590f;if(_0x5b9edf>=_0x59e9b2){_0x5b9edf=_0x59e9b2;_0x33590f=0xc8;}else{_0x33590f=0xce;}_0x2ab365[_0x026b('0x28')](_0x33590f);return _0x2ab365[_0x026b('0x2d')](_0x026b('0x2e'),_0x34fbba+'-'+_0x5b9edf+'/'+_0x59e9b2)[_0x026b('0x2f')](_0x464667);}return null;};}function patchUpdates(_0x17bc65){return function(_0x421f43){try{jsonpatch['apply'](_0x421f43,_0x17bc65,!![]);}catch(_0x2d8002){return BPromise[_0x026b('0x30')](_0x2d8002);}return _0x421f43[_0x026b('0x31')]();};}function saveUpdates(_0x5a3781,_0x54df5a){return function(_0x283a18){if(_0x283a18){return _0x283a18[_0x026b('0x32')](_0x5a3781)[_0x026b('0x33')](function(_0x25e02c){return _0x25e02c;});}return null;};}function removeEntity(_0x48fe1c,_0x22d5c6){return function(_0x3ee3dd){if(_0x3ee3dd){return _0x3ee3dd[_0x026b('0x34')]()[_0x026b('0x33')](function(){_0x48fe1c['status'](0xcc)[_0x026b('0x27')]();});}};}function handleEntityNotFound(_0xa3adae,_0x685abe){return function(_0x163dff){if(!_0x163dff){_0xa3adae[_0x026b('0x35')](0x194);}return _0x163dff;};}function handleError(_0xab6df2,_0x862d33){_0x862d33=_0x862d33||0x1f4;return function(_0x339b59){logger[_0x026b('0x22')](_0x339b59['stack']);if(_0x339b59[_0x026b('0x36')]){delete _0x339b59[_0x026b('0x36')];}_0xab6df2[_0x026b('0x28')](_0x862d33)['send'](_0x339b59);};}exports[_0x026b('0x37')]=function(_0x1105cf,_0x3c8d55){var _0x30e072={},_0x27e29d={},_0x400c6f={'count':0x0,'rows':[]};var _0x5bb124=_[_0x026b('0x38')](db[_0x026b('0x39')][_0x026b('0x3a')],function(_0x5811e7){return{'name':_0x5811e7['fieldName'],'type':_0x5811e7[_0x026b('0x3b')]['key']};});_0x27e29d[_0x026b('0x3c')]=_['map'](_0x5bb124,_0x026b('0x36'));_0x27e29d[_0x026b('0x3d')]=_[_0x026b('0x3e')](_0x1105cf[_0x026b('0x3d')]);_0x27e29d['filters']=_[_0x026b('0x3f')](_0x27e29d[_0x026b('0x3c')],_0x27e29d[_0x026b('0x3d')]);_0x30e072[_0x026b('0x40')]=_['intersection'](_0x27e29d[_0x026b('0x3c')],qs[_0x026b('0x41')](_0x1105cf[_0x026b('0x3d')]['fields']));_0x30e072[_0x026b('0x40')]=_0x30e072[_0x026b('0x40')][_0x026b('0x42')]?_0x30e072[_0x026b('0x40')]:_0x27e29d[_0x026b('0x3c')];if(!_0x1105cf[_0x026b('0x3d')][_0x026b('0x43')]('nolimit')){_0x30e072[_0x026b('0x2a')]=qs[_0x026b('0x2a')](_0x1105cf[_0x026b('0x3d')][_0x026b('0x2a')]);_0x30e072[_0x026b('0x2c')]=qs[_0x026b('0x2c')](_0x1105cf[_0x026b('0x3d')]['offset']);}_0x30e072['order']=qs[_0x026b('0x44')](_0x1105cf['query'][_0x026b('0x44')]);_0x30e072['where']=qs[_0x026b('0x45')](_[_0x026b('0x46')](_0x1105cf[_0x026b('0x3d')],_0x27e29d[_0x026b('0x45')]),_0x5bb124);if(_0x1105cf[_0x026b('0x3d')][_0x026b('0x47')]){_0x30e072['where']=_['merge'](_0x30e072[_0x026b('0x48')],{'$or':_[_0x026b('0x38')](_0x5bb124,function(_0x300660){if(_0x300660[_0x026b('0x3b')]!==_0x026b('0x49')){var _0x197847={};_0x197847[_0x300660['name']]={'$like':'%'+_0x1105cf[_0x026b('0x3d')][_0x026b('0x47')]+'%'};return _0x197847;}})});}_0x30e072=_[_0x026b('0x4a')]({},_0x30e072,_0x1105cf[_0x026b('0x4b')]);var _0x4eb458={'where':_0x30e072[_0x026b('0x48')]};return db[_0x026b('0x39')]['count'](_0x4eb458)[_0x026b('0x33')](function(_0x1773eb){_0x400c6f[_0x026b('0x2b')]=_0x1773eb;if(_0x1105cf['query'][_0x026b('0x4c')]){_0x30e072[_0x026b('0x4d')]=[{'all':!![]}];}return db[_0x026b('0x39')][_0x026b('0x4e')](_0x30e072);})[_0x026b('0x33')](function(_0x50ef6f){_0x400c6f[_0x026b('0x4f')]=_0x50ef6f;return _0x400c6f;})[_0x026b('0x33')](respondWithFilteredResult(_0x3c8d55,_0x30e072))[_0x026b('0x50')](handleError(_0x3c8d55,null));};exports['show']=function(_0x43b296,_0x4a3028){var _0x40d424={'raw':!![],'where':{'id':_0x43b296[_0x026b('0x51')]['id']}},_0x2ccc79={};_0x2ccc79[_0x026b('0x3c')]=_[_0x026b('0x3e')](db[_0x026b('0x39')][_0x026b('0x3a')]);_0x2ccc79[_0x026b('0x3d')]=_[_0x026b('0x3e')](_0x43b296[_0x026b('0x3d')]);_0x2ccc79['filters']=_[_0x026b('0x3f')](_0x2ccc79[_0x026b('0x3c')],_0x2ccc79[_0x026b('0x3d')]);_0x40d424['attributes']=_[_0x026b('0x3f')](_0x2ccc79[_0x026b('0x3c')],qs[_0x026b('0x41')](_0x43b296[_0x026b('0x3d')][_0x026b('0x41')]));_0x40d424['attributes']=_0x40d424[_0x026b('0x40')][_0x026b('0x42')]?_0x40d424[_0x026b('0x40')]:_0x2ccc79[_0x026b('0x3c')];if(_0x43b296[_0x026b('0x3d')][_0x026b('0x4c')]){_0x40d424[_0x026b('0x4d')]=[{'all':!![]}];}_0x40d424=_[_0x026b('0x4a')]({},_0x40d424,_0x43b296[_0x026b('0x4b')]);return db[_0x026b('0x39')][_0x026b('0x52')](_0x40d424)['then'](handleEntityNotFound(_0x4a3028,null))[_0x026b('0x33')](respondWithResult(_0x4a3028,null))[_0x026b('0x50')](handleError(_0x4a3028,null));};exports[_0x026b('0x53')]=function(_0x5bb329,_0x495425){return db[_0x026b('0x39')][_0x026b('0x53')](_0x5bb329[_0x026b('0x54')],{})['then'](respondWithResult(_0x495425,0xc9))['catch'](handleError(_0x495425,null));};exports[_0x026b('0x32')]=function(_0x3f8b13,_0xc3bcd0){if(_0x3f8b13[_0x026b('0x54')]['id']){delete _0x3f8b13['body']['id'];}return db[_0x026b('0x39')][_0x026b('0x52')]({'where':{'id':_0x3f8b13['params']['id']}})[_0x026b('0x33')](handleEntityNotFound(_0xc3bcd0,null))[_0x026b('0x33')](saveUpdates(_0x3f8b13[_0x026b('0x54')],null))['then'](respondWithResult(_0xc3bcd0,null))[_0x026b('0x50')](handleError(_0xc3bcd0,null));};exports['destroy']=function(_0x3334e6,_0x416475){return db['SmsMessage'][_0x026b('0x52')]({'where':{'id':_0x3334e6[_0x026b('0x51')]['id']}})['then'](handleEntityNotFound(_0x416475,null))[_0x026b('0x33')](removeEntity(_0x416475,null))[_0x026b('0x50')](handleError(_0x416475,null));};exports['describe']=function(_0x422e38,_0x813477){return db[_0x026b('0x39')]['describe']()[_0x026b('0x33')](respondWithResult(_0x813477,null))[_0x026b('0x50')](handleError(_0x813477,null));};var interaction_log=require(_0x026b('0x12'))(_0x026b('0x55'));exports[_0x026b('0x56')]=function(_0x45b74f,_0x424588,_0x2b64ce){var _0x30a887={'agent':{},'channel':_0x026b('0x57')};if(_0x45b74f[_0x026b('0x54')]['id']){delete _0x45b74f[_0x026b('0x54')]['id'];}_0x45b74f[_0x026b('0x54')][_0x026b('0x58')]=!![];_0x45b74f[_0x026b('0x54')][_0x026b('0x59')]=moment()[_0x026b('0x5a')](_0x026b('0x5b'));_0x45b74f['body']['UserId']=_0x45b74f[_0x026b('0x54')][_0x026b('0x5c')]||_0x45b74f[_0x026b('0x5d')]['id'];_0x30a887[_0x026b('0x5e')]['id']=_0x45b74f[_0x026b('0x54')][_0x026b('0x5c')];return db[_0x026b('0x39')][_0x026b('0x52')]({'where':{'id':_0x45b74f[_0x026b('0x51')]['id'],'UserId':null}})[_0x026b('0x33')](handleEntityNotFound(_0x424588,null))[_0x026b('0x33')](saveUpdates(_0x45b74f['body'],null))[_0x026b('0x33')](function(_0x5e32a1){if(_0x5e32a1){_0x30a887[_0x026b('0x24')]=_0x5e32a1['get']({'plain':!![]});return db[_0x026b('0x5f')][_0x026b('0x52')]({'where':{'id':_0x5e32a1[_0x026b('0x60')]}});}return null;})[_0x026b('0x33')](handleEntityNotFound(_0x424588,null))[_0x026b('0x33')](function(_0x2e8e42){if(_0x2e8e42){return _0x2e8e42[_0x026b('0x32')]({'UserId':_0x45b74f[_0x026b('0x54')][_0x026b('0x5c')],'read1stAt':_[_0x026b('0x61')](_0x2e8e42['read1stAt'])?moment()[_0x026b('0x5a')](_0x026b('0x5b')):undefined});}return null;})['then'](function(_0x391a69){if(_0x391a69){_0x30a887[_0x026b('0x62')]=_0x391a69[_0x026b('0x63')]({'plain':!![]});interaction_log[_0x026b('0x25')](_0x026b('0x64'),_0x45b74f['user']['id'],_0x45b74f[_0x026b('0x5d')]['name'],_0x45b74f[_0x026b('0x5d')]['role'],_0x30a887[_0x026b('0x62')]['id'],_0x45b74f[_0x026b('0x54')]?JSON['stringify'](_0x45b74f[_0x026b('0x54')]):'null');return respondWithRpcPromise(_0x026b('0x65'),_0x026b('0x66'),_0x30a887);}return null;})[_0x026b('0x33')](function(_0x453445){var _0x5c5023=_0x026b('0x67')+_0x453445[_0x026b('0x24')][_0x026b('0x68')];return db[_0x026b('0x69')][_0x026b('0x3d')](_0x5c5023,{'type':db[_0x026b('0x6a')]['QueryTypes'][_0x026b('0x6b')],'raw':!![]})[_0x026b('0x33')](function(_0x119483){return _0x119483;});})[_0x026b('0x33')](function(_0x35baf2){if(_0x35baf2){_0x30a887[_0x026b('0x24')]['contact']=_0x35baf2[0x0];if(!_0x45b74f[_0x026b('0x54')]['UserId'])return;return db[_0x026b('0x6c')][_0x026b('0x52')]({'where':{'id':_0x45b74f['body']['UserId'],'role':_0x026b('0x5e')},'attributes':['id',_0x026b('0x36'),_0x026b('0x6d'),'email',_0x026b('0x6e')],'raw':!![]});}return null;})['then'](function(_0x5b5875){if(!_0x5b5875)return null;_0x30a887['message'][_0x026b('0x5e')]=_0x5b5875;return _0x30a887;})[_0x026b('0x33')](function(_0xd798ac){if(_0xd798ac){if(_0x45b74f[_0x026b('0x54')]['manual']){_0x30a887[_0x026b('0x24')][_0x026b('0x6f')]=util[_0x026b('0x5a')](_0x026b('0x70'),_0x45b74f[_0x026b('0x5d')][_0x026b('0x36')]);_0x30a887['message']['channel']=_0x30a887[_0x026b('0x71')];_0x30a887[_0x026b('0x24')][_0x026b('0x72')]=_0x30a887[_0x026b('0x71')];_0x30a887['message'][_0x026b('0x73')]=_0x026b('0x56');return respondWithRpcPromise(_0x026b('0x74'),_0x026b('0x74'),{'event':_0x026b('0x75'),'message':_0x30a887[_0x026b('0x24')]},client9002)[_0x026b('0x33')](function(){return _0x30a887;});}return _0x30a887;}return null;})[_0x026b('0x33')](respondWithResult(_0x424588,null))[_0x026b('0x50')](handleError(_0x424588,null));};var interaction_log=require('../../config/logger')(_0x026b('0x55'));exports[_0x026b('0x30')]=function(_0x525ea8,_0x52cb12,_0x30d002){var _0x5a5ee3={'agent':{},'channel':'sms'};if(_0x525ea8[_0x026b('0x54')]['id']){delete _0x525ea8[_0x026b('0x54')]['id'];}_0x525ea8[_0x026b('0x54')][_0x026b('0x5c')]=_0x525ea8[_0x026b('0x54')]['UserId']||_0x525ea8['user']['id'];_0x5a5ee3[_0x026b('0x5e')]['id']=_0x525ea8[_0x026b('0x54')]['UserId'];return db[_0x026b('0x39')][_0x026b('0x52')]({'where':{'id':_0x525ea8[_0x026b('0x51')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x52cb12,null))[_0x026b('0x33')](function(_0x1c61f2){if(_0x1c61f2){_0x5a5ee3['message']=_0x1c61f2[_0x026b('0x63')]({'plain':!![]});return db[_0x026b('0x5f')][_0x026b('0x52')]({'where':{'id':_0x1c61f2[_0x026b('0x60')]}});}return null;})[_0x026b('0x33')](handleEntityNotFound(_0x52cb12,null))['then'](function(_0x5ec571){if(_0x5ec571){_0x5a5ee3[_0x026b('0x62')]=_0x5ec571[_0x026b('0x63')]({'plain':!![]});interaction_log[_0x026b('0x25')](_0x026b('0x76'),_0x525ea8[_0x026b('0x5d')]['id'],_0x525ea8['user']['name'],_0x525ea8[_0x026b('0x5d')][_0x026b('0x77')],_0x5a5ee3['interaction']['id'],_0x525ea8[_0x026b('0x54')]?JSON['stringify'](_0x525ea8[_0x026b('0x54')]):_0x026b('0x78'));return respondWithRpcPromise(_0x026b('0x79'),_0x026b('0x7a'),_0x5a5ee3);}return null;})[_0x026b('0x33')](function(_0x13883a){var _0x349ff8=_0x026b('0x67')+_0x13883a[_0x026b('0x24')][_0x026b('0x68')];return db[_0x026b('0x69')][_0x026b('0x3d')](_0x349ff8,{'type':db[_0x026b('0x6a')][_0x026b('0x7b')][_0x026b('0x6b')],'raw':!![]})[_0x026b('0x33')](function(_0x14272a){return _0x14272a;});})['then'](function(_0x31a8e8){if(_0x31a8e8){_0x5a5ee3[_0x026b('0x24')][_0x026b('0x7c')]=_0x31a8e8[0x0];if(!_0x525ea8[_0x026b('0x54')][_0x026b('0x5c')])return;return db['User']['find']({'where':{'id':_0x525ea8['body']['UserId'],'role':_0x026b('0x5e')},'attributes':['id',_0x026b('0x36'),_0x026b('0x6d'),_0x026b('0x7d'),_0x026b('0x6e')],'raw':!![]});}return null;})[_0x026b('0x33')](function(_0x31f6f3){if(!_0x31f6f3)return null;_0x5a5ee3[_0x026b('0x24')]['agent']=_0x31f6f3;return _0x5a5ee3;})[_0x026b('0x33')](function(_0x287e03){if(_0x287e03){_0x287e03['message'][_0x026b('0x6f')]=util[_0x026b('0x5a')](_0x026b('0x70'),_0x525ea8['user'][_0x026b('0x36')]);_0x287e03[_0x026b('0x24')][_0x026b('0x71')]=_0x5a5ee3[_0x026b('0x71')];_0x287e03[_0x026b('0x24')][_0x026b('0x72')]=_0x5a5ee3['channel'];_0x287e03[_0x026b('0x24')][_0x026b('0x73')]=_0x026b('0x30');respondWithRpcPromise(_0x026b('0x74'),_0x026b('0x74'),{'event':_0x026b('0x7e'),'message':_0x287e03[_0x026b('0x24')]},client9002);return _0x5a5ee3;}return null;})[_0x026b('0x33')](respondWithResult(_0x52cb12,null))[_0x026b('0x50')](handleError(_0x52cb12,null));};exports[_0x026b('0x28')]=function(_0x578af5,_0x32f151,_0x5a779e){if(_0x578af5[_0x026b('0x54')]['id']){delete _0x578af5[_0x026b('0x54')]['id'];}var _0x269f9c;return db[_0x026b('0x39')][_0x026b('0x52')]({'where':{'id':_0x578af5[_0x026b('0x51')]['id']}})[_0x026b('0x33')](handleEntityNotFound(_0x32f151,null))[_0x026b('0x33')](function(_0x4928eb){if(_0x4928eb){_0x269f9c=_0x4928eb;return db[_0x026b('0x7f')][_0x026b('0x52')]({'where':{'id':_0x4928eb[_0x026b('0x80')]}});}})[_0x026b('0x33')](handleEntityNotFound(_0x32f151,null))[_0x026b('0x33')](function(_0x41722c){if(_0x41722c){logger[_0x026b('0x81')](_0x026b('0x82'),_0x026b('0x28'),'received\x20delivery\x20report\x20from',_0x41722c[_0x026b('0x3b')],util['inspect'](_0x578af5[_0x026b('0x54')],{'showHidden':![],'depth':null}));switch(_0x41722c[_0x026b('0x3b')]){case _0x026b('0x83'):if(_0x578af5['body'][_0x026b('0x84')]&&_0x578af5[_0x026b('0x54')]['MessageSid']===_0x269f9c['messageId']){return _0x269f9c['update']({'read':!![]});}else{logger['error'](_0x026b('0x85'),_0x026b('0x28'),'twilio',util[_0x026b('0x86')](_0x578af5[_0x026b('0x54')],{'showHidden':![],'depth':null}));}break;case _0x026b('0x87'):if(_0x578af5[_0x026b('0x54')][_0x026b('0x88')]&&_0x578af5[_0x026b('0x54')][_0x026b('0x88')]===_0x269f9c[_0x026b('0x89')]&&_[_0x026b('0x8a')]([_0x026b('0x8b'),_0x026b('0x8c')],_0x578af5[_0x026b('0x54')][_0x026b('0x8d')])>=0x0){return _0x269f9c[_0x026b('0x32')]({'read':!![]});}else{logger['error'](_0x026b('0x85'),_0x026b('0x28'),_0x026b('0x8e'),util[_0x026b('0x86')](_0x578af5['body'],{'showHidden':![],'depth':null}));}break;case _0x026b('0x8f'):var _0x6d4d2a=_0x578af5[_0x026b('0x54')][_0x026b('0x90')][0x0];if(_0x6d4d2a[_0x026b('0x28')][_0x026b('0x91')]==='DELIVERED'){return _0x269f9c[_0x026b('0x32')]({'read':!![]});}else{logger[_0x026b('0x22')](_0x026b('0x85'),_0x026b('0x28'),_0x026b('0x8f'),util[_0x026b('0x86')](_0x578af5[_0x026b('0x54')],{'showHidden':![],'depth':null}));}break;}return _0x269f9c;}})['then'](respondWithResult(_0x32f151,null))[_0x026b('0x50')](handleError(_0x32f151,null));};