Built motion from commit fade34fd.|2.5.41
[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 _0x47cb=['jayson/promise','client','http','request','then','info','SmsMessage,\x20%s,\x20%s','request\x20sent','debug','SmsMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','json','offset','undefined','count','set','Content-Range','reject','update','destroy','end','name','send','map','SmsMessage','rawAttributes','fieldName','type','key','model','query','intersection','attributes','length','nolimit','limit','order','sort','where','pick','filters','filter','merge','VIRTUAL','options','includeAll','include','rows','show','keys','fields','find','create','body','params','describe','sms-interactions','accept','sms','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','get','SmsInteractionId','isNil','read1stAt','role','null','AcceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','SELECT','contact','User','internal','manual','interface','channel','motionChannel','event','EventManager','acceptmessage','SmsInteraction','interaction','[SMSMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','fullname','email','SIP/%s','rejectmessage','SmsAccount','SmsAccountId','inspect','MessageSid','messageId','SmsAccount,\x20%s,\x20%s,\x20%s','plivo','MessageUUID','indexOf','Status','plivio','infobip','DELIVERED','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsMessage.socket','register'];(function(_0x177c8d,_0x15a8af){var _0x2a771b=function(_0x3b2763){while(--_0x3b2763){_0x177c8d['push'](_0x177c8d['shift']());}};_0x2a771b(++_0x15a8af);}(_0x47cb,0x74));var _0xb47c=function(_0x14add3,_0x13ce8d){_0x14add3=_0x14add3-0x0;var _0x4a174f=_0x47cb[_0x14add3];return _0x4a174f;};'use strict';var emlformat=require(_0xb47c('0x0'));var rimraf=require(_0xb47c('0x1'));var zipdir=require(_0xb47c('0x2'));var jsonpatch=require(_0xb47c('0x3'));var rp=require(_0xb47c('0x4'));var moment=require(_0xb47c('0x5'));var BPromise=require(_0xb47c('0x6'));var Mustache=require(_0xb47c('0x7'));var util=require('util');var path=require(_0xb47c('0x8'));var sox=require(_0xb47c('0x9'));var csv=require(_0xb47c('0xa'));var ejs=require(_0xb47c('0xb'));var fs=require('fs');var fs_extra=require(_0xb47c('0xc'));var _=require(_0xb47c('0xd'));var squel=require(_0xb47c('0xe'));var crypto=require(_0xb47c('0xf'));var jsforce=require(_0xb47c('0x10'));var deskjs=require(_0xb47c('0x11'));var toCsv=require(_0xb47c('0xa'));var querystring=require(_0xb47c('0x12'));var Papa=require(_0xb47c('0x13'));var Redis=require(_0xb47c('0x14'));var authService=require(_0xb47c('0x15'));var qs=require('../../components/parsers/qs');var as=require(_0xb47c('0x16'));var hardwareService=require(_0xb47c('0x17'));var logger=require(_0xb47c('0x18'))('api');var utils=require(_0xb47c('0x19'));var config=require(_0xb47c('0x1a'));var licenseUtil=require('../../config/license/util');var db=require(_0xb47c('0x1b'))['db'];config[_0xb47c('0x1c')]=_[_0xb47c('0x1d')](config['redis'],{'host':_0xb47c('0x1e'),'port':0x18eb});var socket=require(_0xb47c('0x1f'))(new Redis(config[_0xb47c('0x1c')]));require(_0xb47c('0x20'))[_0xb47c('0x21')](socket);var jayson=require(_0xb47c('0x22'));var client=jayson[_0xb47c('0x23')][_0xb47c('0x24')]({'port':0x232c});var client9002=jayson[_0xb47c('0x23')][_0xb47c('0x24')]({'port':0x232a});function respondWithRpcPromise(_0x28ee54,_0x4a335e,_0x33dbe3,_0x1ef6d4){return new BPromise(function(_0xc8c2a8,_0x4b8f13){var _0x2c8a23=_0x1ef6d4||client;return _0x2c8a23[_0xb47c('0x25')](_0x28ee54,_0x33dbe3)[_0xb47c('0x26')](function(_0x2cbc14){logger[_0xb47c('0x27')](_0xb47c('0x28'),_0x4a335e,_0xb47c('0x29'));logger[_0xb47c('0x2a')](_0xb47c('0x2b'),_0x4a335e,_0xb47c('0x29'),JSON[_0xb47c('0x2c')](_0x2cbc14));if(_0x2cbc14[_0xb47c('0x2d')]){if(_0x2cbc14['error'][_0xb47c('0x2e')]===0x1f4){logger[_0xb47c('0x2d')](_0xb47c('0x28'),_0x4a335e,_0x2cbc14['error']['message']);return _0x4b8f13(_0x2cbc14['error'][_0xb47c('0x2f')]);}logger[_0xb47c('0x2d')](_0xb47c('0x28'),_0x4a335e,_0x2cbc14['error'][_0xb47c('0x2f')]);return _0xc8c2a8(_0x2cbc14['error'][_0xb47c('0x2f')]);}else{logger[_0xb47c('0x27')]('SmsMessage,\x20%s,\x20%s',_0x4a335e,'request\x20sent');_0xc8c2a8(_0x2cbc14[_0xb47c('0x30')][_0xb47c('0x2f')]);}})[_0xb47c('0x31')](function(_0x39d0ff){logger[_0xb47c('0x2d')](_0xb47c('0x28'),_0x4a335e,_0x39d0ff);_0x4b8f13(_0x39d0ff);});});}function respondWithStatusCode(_0x14a73e,_0x3c96de){_0x3c96de=_0x3c96de||0xcc;return function(_0x37f77d){if(_0x37f77d){return _0x14a73e[_0xb47c('0x32')](_0x3c96de);}return _0x14a73e[_0xb47c('0x33')](_0x3c96de)['end']();};}function respondWithResult(_0x30cbeb,_0x22ba70){_0x22ba70=_0x22ba70||0xc8;return function(_0x52803a){if(_0x52803a){return _0x30cbeb['status'](_0x22ba70)[_0xb47c('0x34')](_0x52803a);}};}function respondWithFilteredResult(_0x3722d4,_0x38c4df){return function(_0x28b8c2){if(_0x28b8c2){var _0x587835=typeof _0x38c4df[_0xb47c('0x35')]===_0xb47c('0x36')&&typeof _0x38c4df['limit']===_0xb47c('0x36');var _0x53295d=_0x28b8c2[_0xb47c('0x37')];var _0x43e1f5=_0x587835?0x0:_0x38c4df[_0xb47c('0x35')];var _0x146487=_0x587835?_0x28b8c2[_0xb47c('0x37')]:_0x38c4df['offset']+_0x38c4df['limit'];var _0x2c0e34;if(_0x146487>=_0x53295d){_0x146487=_0x53295d;_0x2c0e34=0xc8;}else{_0x2c0e34=0xce;}_0x3722d4['status'](_0x2c0e34);return _0x3722d4[_0xb47c('0x38')](_0xb47c('0x39'),_0x43e1f5+'-'+_0x146487+'/'+_0x53295d)['json'](_0x28b8c2);}return null;};}function patchUpdates(_0x5333cf){return function(_0x5ecfab){try{jsonpatch['apply'](_0x5ecfab,_0x5333cf,!![]);}catch(_0x1b1836){return BPromise[_0xb47c('0x3a')](_0x1b1836);}return _0x5ecfab['save']();};}function saveUpdates(_0x402f62,_0x48662a){return function(_0x206327){if(_0x206327){return _0x206327[_0xb47c('0x3b')](_0x402f62)[_0xb47c('0x26')](function(_0x18ef35){return _0x18ef35;});}return null;};}function removeEntity(_0x361a08,_0x301636){return function(_0x5d6243){if(_0x5d6243){return _0x5d6243[_0xb47c('0x3c')]()[_0xb47c('0x26')](function(){_0x361a08[_0xb47c('0x33')](0xcc)[_0xb47c('0x3d')]();});}};}function handleEntityNotFound(_0x42afff,_0x3e0ac0){return function(_0x5c5fd2){if(!_0x5c5fd2){_0x42afff[_0xb47c('0x32')](0x194);}return _0x5c5fd2;};}function handleError(_0x32fbad,_0x4e30c6){_0x4e30c6=_0x4e30c6||0x1f4;return function(_0x2751cc){logger[_0xb47c('0x2d')](_0x2751cc['stack']);if(_0x2751cc[_0xb47c('0x3e')]){delete _0x2751cc[_0xb47c('0x3e')];}_0x32fbad['status'](_0x4e30c6)[_0xb47c('0x3f')](_0x2751cc);};}exports['index']=function(_0x5e5caa,_0x26157e){var _0xa3847a={},_0x6438bc={},_0x418119={'count':0x0,'rows':[]};var _0x888a73=_[_0xb47c('0x40')](db[_0xb47c('0x41')][_0xb47c('0x42')],function(_0x188d2b){return{'name':_0x188d2b[_0xb47c('0x43')],'type':_0x188d2b[_0xb47c('0x44')][_0xb47c('0x45')]};});_0x6438bc[_0xb47c('0x46')]=_[_0xb47c('0x40')](_0x888a73,_0xb47c('0x3e'));_0x6438bc[_0xb47c('0x47')]=_['keys'](_0x5e5caa[_0xb47c('0x47')]);_0x6438bc['filters']=_[_0xb47c('0x48')](_0x6438bc[_0xb47c('0x46')],_0x6438bc['query']);_0xa3847a[_0xb47c('0x49')]=_[_0xb47c('0x48')](_0x6438bc[_0xb47c('0x46')],qs['fields'](_0x5e5caa[_0xb47c('0x47')]['fields']));_0xa3847a[_0xb47c('0x49')]=_0xa3847a['attributes'][_0xb47c('0x4a')]?_0xa3847a[_0xb47c('0x49')]:_0x6438bc['model'];if(!_0x5e5caa[_0xb47c('0x47')]['hasOwnProperty'](_0xb47c('0x4b'))){_0xa3847a['limit']=qs[_0xb47c('0x4c')](_0x5e5caa[_0xb47c('0x47')][_0xb47c('0x4c')]);_0xa3847a[_0xb47c('0x35')]=qs[_0xb47c('0x35')](_0x5e5caa[_0xb47c('0x47')][_0xb47c('0x35')]);}_0xa3847a[_0xb47c('0x4d')]=qs[_0xb47c('0x4e')](_0x5e5caa[_0xb47c('0x47')][_0xb47c('0x4e')]);_0xa3847a[_0xb47c('0x4f')]=qs['filters'](_[_0xb47c('0x50')](_0x5e5caa[_0xb47c('0x47')],_0x6438bc[_0xb47c('0x51')]),_0x888a73);if(_0x5e5caa[_0xb47c('0x47')][_0xb47c('0x52')]){_0xa3847a[_0xb47c('0x4f')]=_[_0xb47c('0x53')](_0xa3847a[_0xb47c('0x4f')],{'$or':_['map'](_0x888a73,function(_0x33c9a4){if(_0x33c9a4[_0xb47c('0x44')]!==_0xb47c('0x54')){var _0x35b8f7={};_0x35b8f7[_0x33c9a4[_0xb47c('0x3e')]]={'$like':'%'+_0x5e5caa[_0xb47c('0x47')]['filter']+'%'};return _0x35b8f7;}})});}_0xa3847a=_[_0xb47c('0x53')]({},_0xa3847a,_0x5e5caa[_0xb47c('0x55')]);var _0x356577={'where':_0xa3847a[_0xb47c('0x4f')]};return db['SmsMessage'][_0xb47c('0x37')](_0x356577)['then'](function(_0xc590b9){_0x418119['count']=_0xc590b9;if(_0x5e5caa['query'][_0xb47c('0x56')]){_0xa3847a[_0xb47c('0x57')]=[{'all':!![]}];}return db[_0xb47c('0x41')]['findAll'](_0xa3847a);})['then'](function(_0x574173){_0x418119[_0xb47c('0x58')]=_0x574173;return _0x418119;})[_0xb47c('0x26')](respondWithFilteredResult(_0x26157e,_0xa3847a))[_0xb47c('0x31')](handleError(_0x26157e,null));};exports[_0xb47c('0x59')]=function(_0x48e91f,_0x5a7e97){var _0x3b257c={'raw':!![],'where':{'id':_0x48e91f['params']['id']}},_0xfee8a8={};_0xfee8a8[_0xb47c('0x46')]=_[_0xb47c('0x5a')](db[_0xb47c('0x41')][_0xb47c('0x42')]);_0xfee8a8[_0xb47c('0x47')]=_['keys'](_0x48e91f[_0xb47c('0x47')]);_0xfee8a8[_0xb47c('0x51')]=_[_0xb47c('0x48')](_0xfee8a8['model'],_0xfee8a8['query']);_0x3b257c[_0xb47c('0x49')]=_[_0xb47c('0x48')](_0xfee8a8['model'],qs[_0xb47c('0x5b')](_0x48e91f[_0xb47c('0x47')]['fields']));_0x3b257c[_0xb47c('0x49')]=_0x3b257c[_0xb47c('0x49')][_0xb47c('0x4a')]?_0x3b257c['attributes']:_0xfee8a8['model'];if(_0x48e91f['query'][_0xb47c('0x56')]){_0x3b257c[_0xb47c('0x57')]=[{'all':!![]}];}_0x3b257c=_[_0xb47c('0x53')]({},_0x3b257c,_0x48e91f[_0xb47c('0x55')]);return db[_0xb47c('0x41')][_0xb47c('0x5c')](_0x3b257c)['then'](handleEntityNotFound(_0x5a7e97,null))['then'](respondWithResult(_0x5a7e97,null))[_0xb47c('0x31')](handleError(_0x5a7e97,null));};exports['create']=function(_0x24b714,_0x4792d8){return db[_0xb47c('0x41')][_0xb47c('0x5d')](_0x24b714[_0xb47c('0x5e')],{})[_0xb47c('0x26')](respondWithResult(_0x4792d8,0xc9))[_0xb47c('0x31')](handleError(_0x4792d8,null));};exports[_0xb47c('0x3b')]=function(_0x236c80,_0x341520){if(_0x236c80[_0xb47c('0x5e')]['id']){delete _0x236c80[_0xb47c('0x5e')]['id'];}return db['SmsMessage'][_0xb47c('0x5c')]({'where':{'id':_0x236c80[_0xb47c('0x5f')]['id']}})[_0xb47c('0x26')](handleEntityNotFound(_0x341520,null))[_0xb47c('0x26')](saveUpdates(_0x236c80['body'],null))[_0xb47c('0x26')](respondWithResult(_0x341520,null))[_0xb47c('0x31')](handleError(_0x341520,null));};exports[_0xb47c('0x3c')]=function(_0x1f8302,_0x2d389a){return db[_0xb47c('0x41')][_0xb47c('0x5c')]({'where':{'id':_0x1f8302[_0xb47c('0x5f')]['id']}})[_0xb47c('0x26')](handleEntityNotFound(_0x2d389a,null))[_0xb47c('0x26')](removeEntity(_0x2d389a,null))[_0xb47c('0x31')](handleError(_0x2d389a,null));};exports['describe']=function(_0x455fa6,_0x541546){return db[_0xb47c('0x41')][_0xb47c('0x60')]()[_0xb47c('0x26')](respondWithResult(_0x541546,null))[_0xb47c('0x31')](handleError(_0x541546,null));};var interaction_log=require(_0xb47c('0x18'))(_0xb47c('0x61'));exports[_0xb47c('0x62')]=function(_0x346a27,_0x4eb1bd,_0x2ee55c){var _0x20ad72={'agent':{},'channel':_0xb47c('0x63')};if(_0x346a27[_0xb47c('0x5e')]['id']){delete _0x346a27[_0xb47c('0x5e')]['id'];}_0x346a27[_0xb47c('0x5e')][_0xb47c('0x64')]=!![];_0x346a27[_0xb47c('0x5e')][_0xb47c('0x65')]=moment()[_0xb47c('0x66')](_0xb47c('0x67'));_0x346a27[_0xb47c('0x5e')]['UserId']=_0x346a27['body'][_0xb47c('0x68')]||_0x346a27[_0xb47c('0x69')]['id'];_0x20ad72[_0xb47c('0x6a')]['id']=_0x346a27[_0xb47c('0x5e')][_0xb47c('0x68')];return db['SmsMessage'][_0xb47c('0x5c')]({'where':{'id':_0x346a27[_0xb47c('0x5f')]['id'],'UserId':null}})[_0xb47c('0x26')](handleEntityNotFound(_0x4eb1bd,null))['then'](saveUpdates(_0x346a27[_0xb47c('0x5e')],null))[_0xb47c('0x26')](function(_0x6a044e){if(_0x6a044e){_0x20ad72[_0xb47c('0x2f')]=_0x6a044e[_0xb47c('0x6b')]({'plain':!![]});return db['SmsInteraction'][_0xb47c('0x5c')]({'where':{'id':_0x6a044e[_0xb47c('0x6c')]}});}return null;})[_0xb47c('0x26')](handleEntityNotFound(_0x4eb1bd,null))[_0xb47c('0x26')](function(_0x4c5b2a){if(_0x4c5b2a){return _0x4c5b2a[_0xb47c('0x3b')]({'UserId':_0x346a27[_0xb47c('0x5e')][_0xb47c('0x68')],'read1stAt':_[_0xb47c('0x6d')](_0x4c5b2a[_0xb47c('0x6e')])?moment()[_0xb47c('0x66')](_0xb47c('0x67')):undefined});}return null;})[_0xb47c('0x26')](function(_0x3be10e){if(_0x3be10e){_0x20ad72['interaction']=_0x3be10e[_0xb47c('0x6b')]({'plain':!![]});interaction_log['info']('[SMSMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x346a27[_0xb47c('0x69')]['id'],_0x346a27[_0xb47c('0x69')]['name'],_0x346a27['user'][_0xb47c('0x6f')],_0x20ad72['interaction']['id'],_0x346a27[_0xb47c('0x5e')]?JSON[_0xb47c('0x2c')](_0x346a27['body']):_0xb47c('0x70'));return respondWithRpcPromise(_0xb47c('0x71'),'acceptMessage',_0x20ad72);}return null;})[_0xb47c('0x26')](function(_0xb40038){var _0x237308=_0xb47c('0x72')+_0xb40038['message'][_0xb47c('0x73')];return db[_0xb47c('0x74')][_0xb47c('0x47')](_0x237308,{'type':db[_0xb47c('0x75')]['QueryTypes'][_0xb47c('0x76')],'raw':!![]})[_0xb47c('0x26')](function(_0x52eb94){return _0x52eb94;});})[_0xb47c('0x26')](function(_0x13345c){if(_0x13345c){_0x20ad72[_0xb47c('0x2f')][_0xb47c('0x77')]=_0x13345c[0x0];if(!_0x346a27[_0xb47c('0x5e')][_0xb47c('0x68')])return;return db[_0xb47c('0x78')][_0xb47c('0x5c')]({'where':{'id':_0x346a27[_0xb47c('0x5e')]['UserId'],'role':_0xb47c('0x6a')},'attributes':['id',_0xb47c('0x3e'),'fullname','email',_0xb47c('0x79')],'raw':!![]});}return null;})['then'](function(_0x194141){if(!_0x194141)return null;_0x20ad72['message'][_0xb47c('0x6a')]=_0x194141;return _0x20ad72;})[_0xb47c('0x26')](function(_0x48dd58){if(_0x48dd58){if(_0x346a27[_0xb47c('0x5e')][_0xb47c('0x7a')]){_0x20ad72[_0xb47c('0x2f')][_0xb47c('0x7b')]=util[_0xb47c('0x66')]('SIP/%s',_0x346a27[_0xb47c('0x69')][_0xb47c('0x3e')]);_0x20ad72[_0xb47c('0x2f')][_0xb47c('0x7c')]=_0x20ad72[_0xb47c('0x7c')];_0x20ad72[_0xb47c('0x2f')][_0xb47c('0x7d')]=_0x20ad72[_0xb47c('0x7c')];_0x20ad72['message'][_0xb47c('0x7e')]=_0xb47c('0x62');return respondWithRpcPromise('EventManager',_0xb47c('0x7f'),{'event':_0xb47c('0x80'),'message':_0x20ad72['message']},client9002)[_0xb47c('0x26')](function(){return _0x20ad72;});}return _0x20ad72;}return null;})[_0xb47c('0x26')](respondWithResult(_0x4eb1bd,null))[_0xb47c('0x31')](handleError(_0x4eb1bd,null));};var interaction_log=require(_0xb47c('0x18'))(_0xb47c('0x61'));exports[_0xb47c('0x3a')]=function(_0x153738,_0xce0aad,_0x36ae01){var _0x23f4c1={'agent':{},'channel':_0xb47c('0x63')};if(_0x153738[_0xb47c('0x5e')]['id']){delete _0x153738[_0xb47c('0x5e')]['id'];}_0x153738['body'][_0xb47c('0x68')]=_0x153738[_0xb47c('0x5e')]['UserId']||_0x153738['user']['id'];_0x23f4c1[_0xb47c('0x6a')]['id']=_0x153738[_0xb47c('0x5e')][_0xb47c('0x68')];return db[_0xb47c('0x41')][_0xb47c('0x5c')]({'where':{'id':_0x153738['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0xce0aad,null))[_0xb47c('0x26')](function(_0x4dfa3c){if(_0x4dfa3c){_0x23f4c1['message']=_0x4dfa3c[_0xb47c('0x6b')]({'plain':!![]});return db[_0xb47c('0x81')][_0xb47c('0x5c')]({'where':{'id':_0x4dfa3c['SmsInteractionId']}});}return null;})[_0xb47c('0x26')](handleEntityNotFound(_0xce0aad,null))[_0xb47c('0x26')](function(_0x283fe3){if(_0x283fe3){_0x23f4c1[_0xb47c('0x82')]=_0x283fe3['get']({'plain':!![]});interaction_log['info'](_0xb47c('0x83'),_0x153738[_0xb47c('0x69')]['id'],_0x153738[_0xb47c('0x69')][_0xb47c('0x3e')],_0x153738[_0xb47c('0x69')][_0xb47c('0x6f')],_0x23f4c1[_0xb47c('0x82')]['id'],_0x153738['body']?JSON[_0xb47c('0x2c')](_0x153738['body']):_0xb47c('0x70'));return respondWithRpcPromise(_0xb47c('0x84'),'rejectMessage',_0x23f4c1);}return null;})[_0xb47c('0x26')](function(_0x1d1cd6){var _0x135bb6=_0xb47c('0x72')+_0x1d1cd6[_0xb47c('0x2f')]['ContactId'];return db[_0xb47c('0x74')]['query'](_0x135bb6,{'type':db[_0xb47c('0x75')]['QueryTypes']['SELECT'],'raw':!![]})[_0xb47c('0x26')](function(_0x2f6512){return _0x2f6512;});})['then'](function(_0x52ace1){if(_0x52ace1){_0x23f4c1[_0xb47c('0x2f')][_0xb47c('0x77')]=_0x52ace1[0x0];if(!_0x153738['body'][_0xb47c('0x68')])return;return db['User']['find']({'where':{'id':_0x153738[_0xb47c('0x5e')][_0xb47c('0x68')],'role':_0xb47c('0x6a')},'attributes':['id',_0xb47c('0x3e'),_0xb47c('0x85'),_0xb47c('0x86'),_0xb47c('0x79')],'raw':!![]});}return null;})['then'](function(_0x4bd7ec){if(!_0x4bd7ec)return null;_0x23f4c1[_0xb47c('0x2f')][_0xb47c('0x6a')]=_0x4bd7ec;return _0x23f4c1;})[_0xb47c('0x26')](function(_0x8dce3d){if(_0x8dce3d){_0x8dce3d[_0xb47c('0x2f')][_0xb47c('0x7b')]=util[_0xb47c('0x66')](_0xb47c('0x87'),_0x153738['user']['name']);_0x8dce3d[_0xb47c('0x2f')][_0xb47c('0x7c')]=_0x23f4c1[_0xb47c('0x7c')];_0x8dce3d[_0xb47c('0x2f')][_0xb47c('0x7d')]=_0x23f4c1[_0xb47c('0x7c')];_0x8dce3d[_0xb47c('0x2f')][_0xb47c('0x7e')]=_0xb47c('0x3a');respondWithRpcPromise(_0xb47c('0x7f'),_0xb47c('0x7f'),{'event':_0xb47c('0x88'),'message':_0x8dce3d[_0xb47c('0x2f')]},client9002);return _0x23f4c1;}return null;})['then'](respondWithResult(_0xce0aad,null))[_0xb47c('0x31')](handleError(_0xce0aad,null));};exports[_0xb47c('0x33')]=function(_0xb898ec,_0x175b9b,_0x72f848){if(_0xb898ec[_0xb47c('0x5e')]['id']){delete _0xb898ec['body']['id'];}var _0x2b6e4d;return db[_0xb47c('0x41')][_0xb47c('0x5c')]({'where':{'id':_0xb898ec[_0xb47c('0x5f')]['id']}})[_0xb47c('0x26')](handleEntityNotFound(_0x175b9b,null))[_0xb47c('0x26')](function(_0x4e9b1d){if(_0x4e9b1d){_0x2b6e4d=_0x4e9b1d;return db[_0xb47c('0x89')][_0xb47c('0x5c')]({'where':{'id':_0x4e9b1d[_0xb47c('0x8a')]}});}})[_0xb47c('0x26')](handleEntityNotFound(_0x175b9b,null))[_0xb47c('0x26')](function(_0x27fe56){if(_0x27fe56){logger[_0xb47c('0x2a')]('SmsMessage,\x20%s,\x20%s,\x20%s','status','received\x20delivery\x20report\x20from',_0x27fe56['type'],util[_0xb47c('0x8b')](_0xb898ec[_0xb47c('0x5e')],{'showHidden':![],'depth':null}));switch(_0x27fe56[_0xb47c('0x44')]){case'twilio':if(_0xb898ec[_0xb47c('0x5e')][_0xb47c('0x8c')]&&_0xb898ec[_0xb47c('0x5e')]['MessageSid']===_0x2b6e4d[_0xb47c('0x8d')]){return _0x2b6e4d[_0xb47c('0x3b')]({'read':!![]});}else{logger[_0xb47c('0x2d')](_0xb47c('0x8e'),_0xb47c('0x33'),'twilio',util[_0xb47c('0x8b')](_0xb898ec['body'],{'showHidden':![],'depth':null}));}break;case _0xb47c('0x8f'):if(_0xb898ec[_0xb47c('0x5e')][_0xb47c('0x90')]&&_0xb898ec[_0xb47c('0x5e')][_0xb47c('0x90')]===_0x2b6e4d['messageId']&&_[_0xb47c('0x91')](['sent','delivered'],_0xb898ec[_0xb47c('0x5e')][_0xb47c('0x92')])>=0x0){return _0x2b6e4d[_0xb47c('0x3b')]({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0xb47c('0x33'),_0xb47c('0x93'),util[_0xb47c('0x8b')](_0xb898ec[_0xb47c('0x5e')],{'showHidden':![],'depth':null}));}break;case _0xb47c('0x94'):var _0x39b6dd=_0xb898ec[_0xb47c('0x5e')]['results'][0x0];if(_0x39b6dd[_0xb47c('0x33')]['groupName']===_0xb47c('0x95')){return _0x2b6e4d[_0xb47c('0x3b')]({'read':!![]});}else{logger[_0xb47c('0x2d')](_0xb47c('0x8e'),_0xb47c('0x33'),_0xb47c('0x94'),util[_0xb47c('0x8b')](_0xb898ec['body'],{'showHidden':![],'depth':null}));}break;}return _0x2b6e4d;}})[_0xb47c('0x26')](respondWithResult(_0x175b9b,null))[_0xb47c('0x31')](handleError(_0x175b9b,null));};