06d4109c630d5ddffcedfcd18a8f75c7271b6111
[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 _0xcc6d=['SmsAccount,\x20%s,\x20%s,\x20%s','plivo','MessageUUID','indexOf','delivered','Status','plivio','infobip','results','groupName','DELIVERED','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','path','to-csv','squel','jsforce','desk.js','querystring','papaparse','../../components/auth/service','api','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsMessage.socket','register','http','request','then','info','SmsMessage,\x20%s,\x20%s','request\x20sent','debug','SmsMessage,\x20%s,\x20%s,\x20%s','error','message','result','catch','sendStatus','status','end','offset','undefined','limit','json','apply','reject','save','update','destroy','stack','name','index','map','SmsMessage','type','key','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','count','include','rows','params','keys','includeAll','options','find','create','body','sms-interactions','accept','sms','read','readAt','format','UserId','user','get','SmsInteractionId','isNil','YYYY-MM-DD\x20HH:mm:ss','interaction','role','stringify','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','QueryTypes','SELECT','contact','User','fullname','email','internal','manual','interface','channel','motionChannel','event','EventManager','acceptmessage','../../config/logger','agent','SmsInteraction','RejectMessage','rejectMessage','Sequelize','SIP/%s','rejectmessage','SmsAccount','SmsAccountId','inspect','twilio'];(function(_0x96f74c,_0xfc30a4){var _0x379222=function(_0x1bbde9){while(--_0x1bbde9){_0x96f74c['push'](_0x96f74c['shift']());}};_0x379222(++_0xfc30a4);}(_0xcc6d,0x1a9));var _0xdcc6=function(_0x5823d9,_0x190f4f){_0x5823d9=_0x5823d9-0x0;var _0x7c69b5=_0xcc6d[_0x5823d9];return _0x7c69b5;};'use strict';var emlformat=require(_0xdcc6('0x0'));var rimraf=require(_0xdcc6('0x1'));var zipdir=require(_0xdcc6('0x2'));var jsonpatch=require(_0xdcc6('0x3'));var rp=require(_0xdcc6('0x4'));var moment=require('moment');var BPromise=require(_0xdcc6('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0xdcc6('0x6'));var sox=require('sox');var csv=require(_0xdcc6('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0xdcc6('0x8'));var crypto=require('crypto');var jsforce=require(_0xdcc6('0x9'));var deskjs=require(_0xdcc6('0xa'));var toCsv=require(_0xdcc6('0x7'));var querystring=require(_0xdcc6('0xb'));var Papa=require(_0xdcc6('0xc'));var Redis=require('ioredis');var authService=require(_0xdcc6('0xd'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xdcc6('0xe'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xdcc6('0xf'));var db=require(_0xdcc6('0x10'))['db'];config[_0xdcc6('0x11')]=_[_0xdcc6('0x12')](config[_0xdcc6('0x11')],{'host':_0xdcc6('0x13'),'port':0x18eb});var socket=require(_0xdcc6('0x14'))(new Redis(config[_0xdcc6('0x11')]));require(_0xdcc6('0x15'))[_0xdcc6('0x16')](socket);var jayson=require('jayson/promise');var client=jayson['client'][_0xdcc6('0x17')]({'port':0x232c});var client9002=jayson['client'][_0xdcc6('0x17')]({'port':0x232a});function respondWithRpcPromise(_0x472308,_0x18bf22,_0x403eef,_0x57b2aa){return new BPromise(function(_0x36a485,_0x5af6e7){var _0xf21a04=_0x57b2aa||client;return _0xf21a04[_0xdcc6('0x18')](_0x472308,_0x403eef)[_0xdcc6('0x19')](function(_0x5d2858){logger[_0xdcc6('0x1a')](_0xdcc6('0x1b'),_0x18bf22,_0xdcc6('0x1c'));logger[_0xdcc6('0x1d')](_0xdcc6('0x1e'),_0x18bf22,'request\x20sent',JSON['stringify'](_0x5d2858));if(_0x5d2858[_0xdcc6('0x1f')]){if(_0x5d2858[_0xdcc6('0x1f')]['code']===0x1f4){logger['error']('SmsMessage,\x20%s,\x20%s',_0x18bf22,_0x5d2858[_0xdcc6('0x1f')][_0xdcc6('0x20')]);return _0x5af6e7(_0x5d2858[_0xdcc6('0x1f')][_0xdcc6('0x20')]);}logger['error'](_0xdcc6('0x1b'),_0x18bf22,_0x5d2858[_0xdcc6('0x1f')][_0xdcc6('0x20')]);return _0x36a485(_0x5d2858[_0xdcc6('0x1f')]['message']);}else{logger['info']('SmsMessage,\x20%s,\x20%s',_0x18bf22,_0xdcc6('0x1c'));_0x36a485(_0x5d2858[_0xdcc6('0x21')]['message']);}})[_0xdcc6('0x22')](function(_0x126df5){logger['error']('SmsMessage,\x20%s,\x20%s',_0x18bf22,_0x126df5);_0x5af6e7(_0x126df5);});});}function respondWithStatusCode(_0x449a78,_0x1eafea){_0x1eafea=_0x1eafea||0xcc;return function(_0x1b5e0e){if(_0x1b5e0e){return _0x449a78[_0xdcc6('0x23')](_0x1eafea);}return _0x449a78[_0xdcc6('0x24')](_0x1eafea)[_0xdcc6('0x25')]();};}function respondWithResult(_0x8a7262,_0xe07e99){_0xe07e99=_0xe07e99||0xc8;return function(_0x3dcfa1){if(_0x3dcfa1){return _0x8a7262['status'](_0xe07e99)['json'](_0x3dcfa1);}};}function respondWithFilteredResult(_0x3e9033,_0x22d77f){return function(_0x6aa6f9){if(_0x6aa6f9){var _0xfd50e1=typeof _0x22d77f[_0xdcc6('0x26')]===_0xdcc6('0x27')&&typeof _0x22d77f[_0xdcc6('0x28')]===_0xdcc6('0x27');var _0x32dec7=_0x6aa6f9['count'];var _0x17040d=_0xfd50e1?0x0:_0x22d77f['offset'];var _0x22e343=_0xfd50e1?_0x6aa6f9['count']:_0x22d77f[_0xdcc6('0x26')]+_0x22d77f[_0xdcc6('0x28')];var _0x57adf2;if(_0x22e343>=_0x32dec7){_0x22e343=_0x32dec7;_0x57adf2=0xc8;}else{_0x57adf2=0xce;}_0x3e9033[_0xdcc6('0x24')](_0x57adf2);return _0x3e9033['set']('Content-Range',_0x17040d+'-'+_0x22e343+'/'+_0x32dec7)[_0xdcc6('0x29')](_0x6aa6f9);}return null;};}function patchUpdates(_0x152f41){return function(_0x47e8ac){try{jsonpatch[_0xdcc6('0x2a')](_0x47e8ac,_0x152f41,!![]);}catch(_0x1ae321){return BPromise[_0xdcc6('0x2b')](_0x1ae321);}return _0x47e8ac[_0xdcc6('0x2c')]();};}function saveUpdates(_0x2817cf,_0x4214ee){return function(_0x12839b){if(_0x12839b){return _0x12839b[_0xdcc6('0x2d')](_0x2817cf)[_0xdcc6('0x19')](function(_0x4de338){return _0x4de338;});}return null;};}function removeEntity(_0x36e6a3,_0x2de6f7){return function(_0x46f97d){if(_0x46f97d){return _0x46f97d[_0xdcc6('0x2e')]()['then'](function(){_0x36e6a3['status'](0xcc)[_0xdcc6('0x25')]();});}};}function handleEntityNotFound(_0x3ffe5a,_0x442a01){return function(_0x536a95){if(!_0x536a95){_0x3ffe5a[_0xdcc6('0x23')](0x194);}return _0x536a95;};}function handleError(_0x152af1,_0x32bca8){_0x32bca8=_0x32bca8||0x1f4;return function(_0x5d6f84){logger[_0xdcc6('0x1f')](_0x5d6f84[_0xdcc6('0x2f')]);if(_0x5d6f84['name']){delete _0x5d6f84[_0xdcc6('0x30')];}_0x152af1['status'](_0x32bca8)['send'](_0x5d6f84);};}exports[_0xdcc6('0x31')]=function(_0x5327e2,_0x35e1a2){var _0x4e80b2={},_0x3946bc={},_0x3bf0c0={'count':0x0,'rows':[]};var _0x2144b5=_[_0xdcc6('0x32')](db[_0xdcc6('0x33')]['rawAttributes'],function(_0x1c71d4){return{'name':_0x1c71d4['fieldName'],'type':_0x1c71d4[_0xdcc6('0x34')][_0xdcc6('0x35')]};});_0x3946bc['model']=_[_0xdcc6('0x32')](_0x2144b5,_0xdcc6('0x30'));_0x3946bc[_0xdcc6('0x36')]=_['keys'](_0x5327e2[_0xdcc6('0x36')]);_0x3946bc[_0xdcc6('0x37')]=_[_0xdcc6('0x38')](_0x3946bc[_0xdcc6('0x39')],_0x3946bc[_0xdcc6('0x36')]);_0x4e80b2[_0xdcc6('0x3a')]=_[_0xdcc6('0x38')](_0x3946bc['model'],qs[_0xdcc6('0x3b')](_0x5327e2['query'][_0xdcc6('0x3b')]));_0x4e80b2['attributes']=_0x4e80b2['attributes'][_0xdcc6('0x3c')]?_0x4e80b2['attributes']:_0x3946bc['model'];if(!_0x5327e2['query'][_0xdcc6('0x3d')](_0xdcc6('0x3e'))){_0x4e80b2[_0xdcc6('0x28')]=qs[_0xdcc6('0x28')](_0x5327e2['query'][_0xdcc6('0x28')]);_0x4e80b2[_0xdcc6('0x26')]=qs[_0xdcc6('0x26')](_0x5327e2[_0xdcc6('0x36')]['offset']);}_0x4e80b2[_0xdcc6('0x3f')]=qs[_0xdcc6('0x40')](_0x5327e2[_0xdcc6('0x36')][_0xdcc6('0x40')]);_0x4e80b2[_0xdcc6('0x41')]=qs[_0xdcc6('0x37')](_[_0xdcc6('0x42')](_0x5327e2[_0xdcc6('0x36')],_0x3946bc['filters']),_0x2144b5);if(_0x5327e2[_0xdcc6('0x36')][_0xdcc6('0x43')]){_0x4e80b2['where']=_[_0xdcc6('0x44')](_0x4e80b2[_0xdcc6('0x41')],{'$or':_[_0xdcc6('0x32')](_0x2144b5,function(_0x1f0138){if(_0x1f0138[_0xdcc6('0x34')]!==_0xdcc6('0x45')){var _0x39b2fb={};_0x39b2fb[_0x1f0138[_0xdcc6('0x30')]]={'$like':'%'+_0x5327e2[_0xdcc6('0x36')][_0xdcc6('0x43')]+'%'};return _0x39b2fb;}})});}_0x4e80b2=_[_0xdcc6('0x44')]({},_0x4e80b2,_0x5327e2['options']);var _0x24cab8={'where':_0x4e80b2[_0xdcc6('0x41')]};return db[_0xdcc6('0x33')][_0xdcc6('0x46')](_0x24cab8)['then'](function(_0x18bd6f){_0x3bf0c0[_0xdcc6('0x46')]=_0x18bd6f;if(_0x5327e2[_0xdcc6('0x36')]['includeAll']){_0x4e80b2[_0xdcc6('0x47')]=[{'all':!![]}];}return db[_0xdcc6('0x33')]['findAll'](_0x4e80b2);})['then'](function(_0x133751){_0x3bf0c0[_0xdcc6('0x48')]=_0x133751;return _0x3bf0c0;})[_0xdcc6('0x19')](respondWithFilteredResult(_0x35e1a2,_0x4e80b2))[_0xdcc6('0x22')](handleError(_0x35e1a2,null));};exports['show']=function(_0x154d8c,_0x35300f){var _0x3bacb9={'raw':!![],'where':{'id':_0x154d8c[_0xdcc6('0x49')]['id']}},_0x451e00={};_0x451e00[_0xdcc6('0x39')]=_['keys'](db[_0xdcc6('0x33')]['rawAttributes']);_0x451e00[_0xdcc6('0x36')]=_[_0xdcc6('0x4a')](_0x154d8c[_0xdcc6('0x36')]);_0x451e00[_0xdcc6('0x37')]=_[_0xdcc6('0x38')](_0x451e00['model'],_0x451e00[_0xdcc6('0x36')]);_0x3bacb9[_0xdcc6('0x3a')]=_[_0xdcc6('0x38')](_0x451e00[_0xdcc6('0x39')],qs[_0xdcc6('0x3b')](_0x154d8c[_0xdcc6('0x36')][_0xdcc6('0x3b')]));_0x3bacb9['attributes']=_0x3bacb9[_0xdcc6('0x3a')][_0xdcc6('0x3c')]?_0x3bacb9[_0xdcc6('0x3a')]:_0x451e00['model'];if(_0x154d8c[_0xdcc6('0x36')][_0xdcc6('0x4b')]){_0x3bacb9['include']=[{'all':!![]}];}_0x3bacb9=_[_0xdcc6('0x44')]({},_0x3bacb9,_0x154d8c[_0xdcc6('0x4c')]);return db[_0xdcc6('0x33')][_0xdcc6('0x4d')](_0x3bacb9)[_0xdcc6('0x19')](handleEntityNotFound(_0x35300f,null))[_0xdcc6('0x19')](respondWithResult(_0x35300f,null))[_0xdcc6('0x22')](handleError(_0x35300f,null));};exports[_0xdcc6('0x4e')]=function(_0x50b3ca,_0x3abaca){return db[_0xdcc6('0x33')][_0xdcc6('0x4e')](_0x50b3ca[_0xdcc6('0x4f')],{})['then'](respondWithResult(_0x3abaca,0xc9))['catch'](handleError(_0x3abaca,null));};exports[_0xdcc6('0x2d')]=function(_0x2c7db7,_0xd8624c){if(_0x2c7db7[_0xdcc6('0x4f')]['id']){delete _0x2c7db7[_0xdcc6('0x4f')]['id'];}return db[_0xdcc6('0x33')]['find']({'where':{'id':_0x2c7db7[_0xdcc6('0x49')]['id']}})[_0xdcc6('0x19')](handleEntityNotFound(_0xd8624c,null))['then'](saveUpdates(_0x2c7db7[_0xdcc6('0x4f')],null))[_0xdcc6('0x19')](respondWithResult(_0xd8624c,null))[_0xdcc6('0x22')](handleError(_0xd8624c,null));};exports['destroy']=function(_0x25de54,_0x229b94){return db[_0xdcc6('0x33')][_0xdcc6('0x4d')]({'where':{'id':_0x25de54[_0xdcc6('0x49')]['id']}})[_0xdcc6('0x19')](handleEntityNotFound(_0x229b94,null))[_0xdcc6('0x19')](removeEntity(_0x229b94,null))['catch'](handleError(_0x229b94,null));};exports['describe']=function(_0x2d4657,_0x8f1034){return db[_0xdcc6('0x33')]['describe']()[_0xdcc6('0x19')](respondWithResult(_0x8f1034,null))[_0xdcc6('0x22')](handleError(_0x8f1034,null));};var interaction_log=require('../../config/logger')(_0xdcc6('0x50'));exports[_0xdcc6('0x51')]=function(_0x391c35,_0x3a4e4e,_0x5768e2){var _0x41cf6e={'agent':{},'channel':_0xdcc6('0x52')};if(_0x391c35[_0xdcc6('0x4f')]['id']){delete _0x391c35['body']['id'];}_0x391c35[_0xdcc6('0x4f')][_0xdcc6('0x53')]=!![];_0x391c35[_0xdcc6('0x4f')][_0xdcc6('0x54')]=moment()[_0xdcc6('0x55')]('YYYY-MM-DD\x20HH:mm:ss');_0x391c35['body'][_0xdcc6('0x56')]=_0x391c35[_0xdcc6('0x4f')][_0xdcc6('0x56')]||_0x391c35[_0xdcc6('0x57')]['id'];_0x41cf6e['agent']['id']=_0x391c35[_0xdcc6('0x4f')][_0xdcc6('0x56')];return db[_0xdcc6('0x33')][_0xdcc6('0x4d')]({'where':{'id':_0x391c35[_0xdcc6('0x49')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x3a4e4e,null))[_0xdcc6('0x19')](saveUpdates(_0x391c35['body'],null))[_0xdcc6('0x19')](function(_0x403ea2){if(_0x403ea2){_0x41cf6e[_0xdcc6('0x20')]=_0x403ea2[_0xdcc6('0x58')]({'plain':!![]});return db['SmsInteraction'][_0xdcc6('0x4d')]({'where':{'id':_0x403ea2[_0xdcc6('0x59')]}});}return null;})[_0xdcc6('0x19')](handleEntityNotFound(_0x3a4e4e,null))['then'](function(_0x36a6c6){if(_0x36a6c6){return _0x36a6c6[_0xdcc6('0x2d')]({'UserId':_0x391c35['body'][_0xdcc6('0x56')],'read1stAt':_[_0xdcc6('0x5a')](_0x36a6c6['read1stAt'])?moment()[_0xdcc6('0x55')](_0xdcc6('0x5b')):undefined});}return null;})['then'](function(_0x1f87c6){if(_0x1f87c6){_0x41cf6e[_0xdcc6('0x5c')]=_0x1f87c6['get']({'plain':!![]});interaction_log[_0xdcc6('0x1a')]('[SMSMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x391c35[_0xdcc6('0x57')]['id'],_0x391c35[_0xdcc6('0x57')]['name'],_0x391c35[_0xdcc6('0x57')][_0xdcc6('0x5d')],_0x41cf6e[_0xdcc6('0x5c')]['id'],_0x391c35[_0xdcc6('0x4f')]?JSON[_0xdcc6('0x5e')](_0x391c35[_0xdcc6('0x4f')]):_0xdcc6('0x5f'));return respondWithRpcPromise(_0xdcc6('0x60'),_0xdcc6('0x61'),_0x41cf6e);}return null;})[_0xdcc6('0x19')](function(_0x11d03c){var _0x452f48=_0xdcc6('0x62')+_0x11d03c[_0xdcc6('0x20')][_0xdcc6('0x63')];return db[_0xdcc6('0x64')]['query'](_0x452f48,{'type':db['Sequelize'][_0xdcc6('0x65')][_0xdcc6('0x66')],'raw':!![]})[_0xdcc6('0x19')](function(_0x1b3f2b){return _0x1b3f2b;});})[_0xdcc6('0x19')](function(_0x5e46aa){if(_0x5e46aa){_0x41cf6e[_0xdcc6('0x20')][_0xdcc6('0x67')]=_0x5e46aa[0x0];if(!_0x391c35['body'][_0xdcc6('0x56')])return;return db[_0xdcc6('0x68')]['find']({'where':{'id':_0x391c35[_0xdcc6('0x4f')]['UserId'],'role':'agent'},'attributes':['id',_0xdcc6('0x30'),_0xdcc6('0x69'),_0xdcc6('0x6a'),_0xdcc6('0x6b')],'raw':!![]});}return null;})['then'](function(_0x4a0145){if(!_0x4a0145)return null;_0x41cf6e[_0xdcc6('0x20')]['agent']=_0x4a0145;return _0x41cf6e;})[_0xdcc6('0x19')](function(_0x5cdb36){if(_0x5cdb36){if(_0x391c35[_0xdcc6('0x4f')][_0xdcc6('0x6c')]){_0x41cf6e[_0xdcc6('0x20')][_0xdcc6('0x6d')]=util[_0xdcc6('0x55')]('SIP/%s',_0x391c35[_0xdcc6('0x57')][_0xdcc6('0x30')]);_0x41cf6e[_0xdcc6('0x20')][_0xdcc6('0x6e')]=_0x41cf6e[_0xdcc6('0x6e')];_0x41cf6e[_0xdcc6('0x20')][_0xdcc6('0x6f')]=_0x41cf6e[_0xdcc6('0x6e')];_0x41cf6e[_0xdcc6('0x20')][_0xdcc6('0x70')]='accept';return respondWithRpcPromise(_0xdcc6('0x71'),'EventManager',{'event':_0xdcc6('0x72'),'message':_0x41cf6e[_0xdcc6('0x20')]},client9002)[_0xdcc6('0x19')](function(){return _0x41cf6e;});}return _0x41cf6e;}return null;})[_0xdcc6('0x19')](respondWithResult(_0x3a4e4e,null))[_0xdcc6('0x22')](handleError(_0x3a4e4e,null));};var interaction_log=require(_0xdcc6('0x73'))(_0xdcc6('0x50'));exports[_0xdcc6('0x2b')]=function(_0x1d43fe,_0x4dd2e6,_0x37d024){var _0x44a213={'agent':{},'channel':_0xdcc6('0x52')};if(_0x1d43fe['body']['id']){delete _0x1d43fe[_0xdcc6('0x4f')]['id'];}_0x1d43fe['body'][_0xdcc6('0x56')]=_0x1d43fe[_0xdcc6('0x4f')]['UserId']||_0x1d43fe[_0xdcc6('0x57')]['id'];_0x44a213[_0xdcc6('0x74')]['id']=_0x1d43fe[_0xdcc6('0x4f')][_0xdcc6('0x56')];return db['SmsMessage'][_0xdcc6('0x4d')]({'where':{'id':_0x1d43fe[_0xdcc6('0x49')]['id'],'UserId':null}})[_0xdcc6('0x19')](handleEntityNotFound(_0x4dd2e6,null))[_0xdcc6('0x19')](function(_0x35988d){if(_0x35988d){_0x44a213['message']=_0x35988d[_0xdcc6('0x58')]({'plain':!![]});return db[_0xdcc6('0x75')][_0xdcc6('0x4d')]({'where':{'id':_0x35988d[_0xdcc6('0x59')]}});}return null;})[_0xdcc6('0x19')](handleEntityNotFound(_0x4dd2e6,null))[_0xdcc6('0x19')](function(_0x20b337){if(_0x20b337){_0x44a213[_0xdcc6('0x5c')]=_0x20b337[_0xdcc6('0x58')]({'plain':!![]});interaction_log['info']('[SMSMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x1d43fe[_0xdcc6('0x57')]['id'],_0x1d43fe[_0xdcc6('0x57')][_0xdcc6('0x30')],_0x1d43fe[_0xdcc6('0x57')]['role'],_0x44a213[_0xdcc6('0x5c')]['id'],_0x1d43fe[_0xdcc6('0x4f')]?JSON[_0xdcc6('0x5e')](_0x1d43fe[_0xdcc6('0x4f')]):_0xdcc6('0x5f'));return respondWithRpcPromise(_0xdcc6('0x76'),_0xdcc6('0x77'),_0x44a213);}return null;})[_0xdcc6('0x19')](function(_0x197926){var _0x2881e8=_0xdcc6('0x62')+_0x197926[_0xdcc6('0x20')][_0xdcc6('0x63')];return db[_0xdcc6('0x64')][_0xdcc6('0x36')](_0x2881e8,{'type':db[_0xdcc6('0x78')]['QueryTypes']['SELECT'],'raw':!![]})[_0xdcc6('0x19')](function(_0x99478e){return _0x99478e;});})[_0xdcc6('0x19')](function(_0x3005a8){if(_0x3005a8){_0x44a213[_0xdcc6('0x20')][_0xdcc6('0x67')]=_0x3005a8[0x0];if(!_0x1d43fe[_0xdcc6('0x4f')][_0xdcc6('0x56')])return;return db[_0xdcc6('0x68')]['find']({'where':{'id':_0x1d43fe[_0xdcc6('0x4f')][_0xdcc6('0x56')],'role':_0xdcc6('0x74')},'attributes':['id',_0xdcc6('0x30'),'fullname',_0xdcc6('0x6a'),_0xdcc6('0x6b')],'raw':!![]});}return null;})['then'](function(_0x521f04){if(!_0x521f04)return null;_0x44a213[_0xdcc6('0x20')][_0xdcc6('0x74')]=_0x521f04;return _0x44a213;})[_0xdcc6('0x19')](function(_0x34a491){if(_0x34a491){_0x34a491[_0xdcc6('0x20')][_0xdcc6('0x6d')]=util[_0xdcc6('0x55')](_0xdcc6('0x79'),_0x1d43fe['user']['name']);_0x34a491[_0xdcc6('0x20')][_0xdcc6('0x6e')]=_0x44a213[_0xdcc6('0x6e')];_0x34a491[_0xdcc6('0x20')][_0xdcc6('0x6f')]=_0x44a213[_0xdcc6('0x6e')];_0x34a491['message'][_0xdcc6('0x70')]=_0xdcc6('0x2b');respondWithRpcPromise(_0xdcc6('0x71'),'EventManager',{'event':_0xdcc6('0x7a'),'message':_0x34a491[_0xdcc6('0x20')]},client9002);return _0x44a213;}return null;})['then'](respondWithResult(_0x4dd2e6,null))[_0xdcc6('0x22')](handleError(_0x4dd2e6,null));};exports[_0xdcc6('0x24')]=function(_0x5abfd1,_0x327753,_0x28cfbc){if(_0x5abfd1[_0xdcc6('0x4f')]['id']){delete _0x5abfd1[_0xdcc6('0x4f')]['id'];}var _0x318c4c;return db[_0xdcc6('0x33')][_0xdcc6('0x4d')]({'where':{'id':_0x5abfd1[_0xdcc6('0x49')]['id']}})[_0xdcc6('0x19')](handleEntityNotFound(_0x327753,null))['then'](function(_0x55aec4){if(_0x55aec4){_0x318c4c=_0x55aec4;return db[_0xdcc6('0x7b')][_0xdcc6('0x4d')]({'where':{'id':_0x55aec4[_0xdcc6('0x7c')]}});}})[_0xdcc6('0x19')](handleEntityNotFound(_0x327753,null))[_0xdcc6('0x19')](function(_0x5c1e7f){if(_0x5c1e7f){logger[_0xdcc6('0x1d')](_0xdcc6('0x1e'),_0xdcc6('0x24'),'received\x20delivery\x20report\x20from',_0x5c1e7f[_0xdcc6('0x34')],util[_0xdcc6('0x7d')](_0x5abfd1[_0xdcc6('0x4f')],{'showHidden':![],'depth':null}));switch(_0x5c1e7f[_0xdcc6('0x34')]){case _0xdcc6('0x7e'):if(_0x5abfd1[_0xdcc6('0x4f')]['MessageSid']&&_0x5abfd1[_0xdcc6('0x4f')]['MessageSid']===_0x318c4c['messageId']){return _0x318c4c['update']({'read':!![]});}else{logger[_0xdcc6('0x1f')](_0xdcc6('0x7f'),_0xdcc6('0x24'),'twilio',util['inspect'](_0x5abfd1[_0xdcc6('0x4f')],{'showHidden':![],'depth':null}));}break;case _0xdcc6('0x80'):if(_0x5abfd1[_0xdcc6('0x4f')][_0xdcc6('0x81')]&&_0x5abfd1[_0xdcc6('0x4f')][_0xdcc6('0x81')]===_0x318c4c['messageId']&&_[_0xdcc6('0x82')](['sent',_0xdcc6('0x83')],_0x5abfd1[_0xdcc6('0x4f')][_0xdcc6('0x84')])>=0x0){return _0x318c4c[_0xdcc6('0x2d')]({'read':!![]});}else{logger[_0xdcc6('0x1f')](_0xdcc6('0x7f'),_0xdcc6('0x24'),_0xdcc6('0x85'),util[_0xdcc6('0x7d')](_0x5abfd1[_0xdcc6('0x4f')],{'showHidden':![],'depth':null}));}break;case _0xdcc6('0x86'):var _0xba3ad2=_0x5abfd1['body'][_0xdcc6('0x87')][0x0];if(_0xba3ad2['status'][_0xdcc6('0x88')]===_0xdcc6('0x89')){return _0x318c4c[_0xdcc6('0x2d')]({'read':!![]});}else{logger[_0xdcc6('0x1f')](_0xdcc6('0x7f'),_0xdcc6('0x24'),_0xdcc6('0x86'),util[_0xdcc6('0x7d')](_0x5abfd1['body'],{'showHidden':![],'depth':null}));}break;}return _0x318c4c;}})[_0xdcc6('0x19')](respondWithResult(_0x327753,null))['catch'](handleError(_0x327753,null));};