3fa470f495b6e92ffe259d8954f2b9dcb4b65ae5
[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 _0x3fce=['bluebird','mustache','ejs','fs-extra','squel','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','./smsMessage.socket','jayson/promise','client','http','then','info','SmsMessage,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','sendStatus','status','json','offset','undefined','limit','count','Content-Range','apply','reject','save','update','destroy','end','stack','name','send','index','map','SmsMessage','rawAttributes','fieldName','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','pick','filter','where','type','VIRTUAL','merge','options','includeAll','include','findAll','show','params','find','catch','create','body','describe','sms-interactions','accept','sms','read','readAt','format','UserId','user','get','SmsInteraction','SmsInteractionId','isNil','read1stAt','YYYY-MM-DD\x20HH:mm:ss','interaction','role','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','QueryTypes','SELECT','contact','agent','fullname','email','internal','manual','interface','channel','motionChannel','EventManager','acceptmessage','rejectMessage','User','SIP/%s','event','rejectmessage','SmsAccount','SmsAccountId','debug','SmsMessage,\x20%s,\x20%s,\x20%s','received\x20delivery\x20report\x20from','inspect','MessageSid','SmsAccount,\x20%s,\x20%s,\x20%s','twilio','plivo','MessageUUID','messageId','indexOf','Status','plivio','infobip','results','groupName','DELIVERED','rimraf','zip-dir','fast-json-patch','request-promise','moment'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x3fce,0x121));var _0xe3fc=function(_0x9cbfe0,_0x56aada){_0x9cbfe0=_0x9cbfe0-0x0;var _0x1f1534=_0x3fce[_0x9cbfe0];return _0x1f1534;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xe3fc('0x0'));var zipdir=require(_0xe3fc('0x1'));var jsonpatch=require(_0xe3fc('0x2'));var rp=require(_0xe3fc('0x3'));var moment=require(_0xe3fc('0x4'));var BPromise=require(_0xe3fc('0x5'));var Mustache=require(_0xe3fc('0x6'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xe3fc('0x7'));var fs=require('fs');var fs_extra=require(_0xe3fc('0x8'));var _=require('lodash');var squel=require(_0xe3fc('0x9'));var crypto=require('crypto');var jsforce=require(_0xe3fc('0xa'));var deskjs=require('desk.js');var toCsv=require(_0xe3fc('0xb'));var querystring=require(_0xe3fc('0xc'));var Papa=require(_0xe3fc('0xd'));var Redis=require(_0xe3fc('0xe'));var authService=require(_0xe3fc('0xf'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xe3fc('0x10'));var logger=require(_0xe3fc('0x11'))(_0xe3fc('0x12'));var utils=require('../../config/utils');var config=require(_0xe3fc('0x13'));var licenseUtil=require(_0xe3fc('0x14'));var db=require(_0xe3fc('0x15'))['db'];config[_0xe3fc('0x16')]=_[_0xe3fc('0x17')](config[_0xe3fc('0x16')],{'host':_0xe3fc('0x18'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xe3fc('0x16')]));require(_0xe3fc('0x19'))['register'](socket);var jayson=require(_0xe3fc('0x1a'));var client=jayson[_0xe3fc('0x1b')]['http']({'port':0x232c});var client9002=jayson[_0xe3fc('0x1b')][_0xe3fc('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x4b6256,_0x4fa4d4,_0x5953ac,_0x27b618){return new BPromise(function(_0x4283be,_0x2f8cc9){var _0x59a6db=_0x27b618||client;return _0x59a6db['request'](_0x4b6256,_0x5953ac)[_0xe3fc('0x1d')](function(_0x5a4d98){logger[_0xe3fc('0x1e')](_0xe3fc('0x1f'),_0x4fa4d4,_0xe3fc('0x20'));logger['debug']('SmsMessage,\x20%s,\x20%s,\x20%s',_0x4fa4d4,_0xe3fc('0x20'),JSON[_0xe3fc('0x21')](_0x5a4d98));if(_0x5a4d98[_0xe3fc('0x22')]){if(_0x5a4d98['error'][_0xe3fc('0x23')]===0x1f4){logger[_0xe3fc('0x22')]('SmsMessage,\x20%s,\x20%s',_0x4fa4d4,_0x5a4d98[_0xe3fc('0x22')][_0xe3fc('0x24')]);return _0x2f8cc9(_0x5a4d98['error'][_0xe3fc('0x24')]);}logger[_0xe3fc('0x22')](_0xe3fc('0x1f'),_0x4fa4d4,_0x5a4d98['error']['message']);return _0x4283be(_0x5a4d98[_0xe3fc('0x22')][_0xe3fc('0x24')]);}else{logger['info'](_0xe3fc('0x1f'),_0x4fa4d4,_0xe3fc('0x20'));_0x4283be(_0x5a4d98[_0xe3fc('0x25')][_0xe3fc('0x24')]);}})['catch'](function(_0x24043a){logger['error']('SmsMessage,\x20%s,\x20%s',_0x4fa4d4,_0x24043a);_0x2f8cc9(_0x24043a);});});}function respondWithStatusCode(_0x5abdb3,_0x58adb8){_0x58adb8=_0x58adb8||0xcc;return function(_0x51dc35){if(_0x51dc35){return _0x5abdb3[_0xe3fc('0x26')](_0x58adb8);}return _0x5abdb3[_0xe3fc('0x27')](_0x58adb8)['end']();};}function respondWithResult(_0x60e9b8,_0x188ca2){_0x188ca2=_0x188ca2||0xc8;return function(_0x5be1d6){if(_0x5be1d6){return _0x60e9b8[_0xe3fc('0x27')](_0x188ca2)[_0xe3fc('0x28')](_0x5be1d6);}};}function respondWithFilteredResult(_0x1ecb86,_0x3bc101){return function(_0x3d173e){if(_0x3d173e){var _0x21ccdd=typeof _0x3bc101[_0xe3fc('0x29')]===_0xe3fc('0x2a')&&typeof _0x3bc101[_0xe3fc('0x2b')]===_0xe3fc('0x2a');var _0x30a897=_0x3d173e[_0xe3fc('0x2c')];var _0x25a0af=_0x21ccdd?0x0:_0x3bc101[_0xe3fc('0x29')];var _0x38ab54=_0x21ccdd?_0x3d173e[_0xe3fc('0x2c')]:_0x3bc101['offset']+_0x3bc101[_0xe3fc('0x2b')];var _0x2f910e;if(_0x38ab54>=_0x30a897){_0x38ab54=_0x30a897;_0x2f910e=0xc8;}else{_0x2f910e=0xce;}_0x1ecb86[_0xe3fc('0x27')](_0x2f910e);return _0x1ecb86['set'](_0xe3fc('0x2d'),_0x25a0af+'-'+_0x38ab54+'/'+_0x30a897)[_0xe3fc('0x28')](_0x3d173e);}return null;};}function patchUpdates(_0x3527ac){return function(_0x4a6202){try{jsonpatch[_0xe3fc('0x2e')](_0x4a6202,_0x3527ac,!![]);}catch(_0x30c178){return BPromise[_0xe3fc('0x2f')](_0x30c178);}return _0x4a6202[_0xe3fc('0x30')]();};}function saveUpdates(_0x3ebd5d,_0x161434){return function(_0x56cadd){if(_0x56cadd){return _0x56cadd[_0xe3fc('0x31')](_0x3ebd5d)[_0xe3fc('0x1d')](function(_0x9baaec){return _0x9baaec;});}return null;};}function removeEntity(_0x36701e,_0x1f441d){return function(_0x437e4e){if(_0x437e4e){return _0x437e4e[_0xe3fc('0x32')]()[_0xe3fc('0x1d')](function(){_0x36701e[_0xe3fc('0x27')](0xcc)[_0xe3fc('0x33')]();});}};}function handleEntityNotFound(_0x794f2,_0x25edfd){return function(_0x24dae1){if(!_0x24dae1){_0x794f2['sendStatus'](0x194);}return _0x24dae1;};}function handleError(_0x580cba,_0x4ced3a){_0x4ced3a=_0x4ced3a||0x1f4;return function(_0x2348b3){logger[_0xe3fc('0x22')](_0x2348b3[_0xe3fc('0x34')]);if(_0x2348b3[_0xe3fc('0x35')]){delete _0x2348b3[_0xe3fc('0x35')];}_0x580cba[_0xe3fc('0x27')](_0x4ced3a)[_0xe3fc('0x36')](_0x2348b3);};}exports[_0xe3fc('0x37')]=function(_0x4a5ba9,_0x4b4d2b){var _0x1b0d87={},_0x48a626={},_0x38b7b7={'count':0x0,'rows':[]};var _0x35a970=_[_0xe3fc('0x38')](db[_0xe3fc('0x39')][_0xe3fc('0x3a')],function(_0x5047f1){return{'name':_0x5047f1[_0xe3fc('0x3b')],'type':_0x5047f1['type']['key']};});_0x48a626[_0xe3fc('0x3c')]=_[_0xe3fc('0x38')](_0x35a970,'name');_0x48a626[_0xe3fc('0x3d')]=_[_0xe3fc('0x3e')](_0x4a5ba9[_0xe3fc('0x3d')]);_0x48a626[_0xe3fc('0x3f')]=_[_0xe3fc('0x40')](_0x48a626[_0xe3fc('0x3c')],_0x48a626['query']);_0x1b0d87[_0xe3fc('0x41')]=_[_0xe3fc('0x40')](_0x48a626[_0xe3fc('0x3c')],qs[_0xe3fc('0x42')](_0x4a5ba9[_0xe3fc('0x3d')]['fields']));_0x1b0d87[_0xe3fc('0x41')]=_0x1b0d87[_0xe3fc('0x41')][_0xe3fc('0x43')]?_0x1b0d87['attributes']:_0x48a626[_0xe3fc('0x3c')];if(!_0x4a5ba9['query'][_0xe3fc('0x44')](_0xe3fc('0x45'))){_0x1b0d87[_0xe3fc('0x2b')]=qs[_0xe3fc('0x2b')](_0x4a5ba9[_0xe3fc('0x3d')]['limit']);_0x1b0d87[_0xe3fc('0x29')]=qs[_0xe3fc('0x29')](_0x4a5ba9[_0xe3fc('0x3d')][_0xe3fc('0x29')]);}_0x1b0d87[_0xe3fc('0x46')]=qs['sort'](_0x4a5ba9[_0xe3fc('0x3d')]['sort']);_0x1b0d87['where']=qs['filters'](_[_0xe3fc('0x47')](_0x4a5ba9[_0xe3fc('0x3d')],_0x48a626[_0xe3fc('0x3f')]),_0x35a970);if(_0x4a5ba9[_0xe3fc('0x3d')][_0xe3fc('0x48')]){_0x1b0d87[_0xe3fc('0x49')]=_['merge'](_0x1b0d87[_0xe3fc('0x49')],{'$or':_['map'](_0x35a970,function(_0x352efb){if(_0x352efb[_0xe3fc('0x4a')]!==_0xe3fc('0x4b')){var _0x2c1350={};_0x2c1350[_0x352efb['name']]={'$like':'%'+_0x4a5ba9[_0xe3fc('0x3d')][_0xe3fc('0x48')]+'%'};return _0x2c1350;}})});}_0x1b0d87=_[_0xe3fc('0x4c')]({},_0x1b0d87,_0x4a5ba9[_0xe3fc('0x4d')]);var _0xde6752={'where':_0x1b0d87[_0xe3fc('0x49')]};return db['SmsMessage']['count'](_0xde6752)[_0xe3fc('0x1d')](function(_0x43bf0c){_0x38b7b7[_0xe3fc('0x2c')]=_0x43bf0c;if(_0x4a5ba9[_0xe3fc('0x3d')][_0xe3fc('0x4e')]){_0x1b0d87[_0xe3fc('0x4f')]=[{'all':!![]}];}return db['SmsMessage'][_0xe3fc('0x50')](_0x1b0d87);})['then'](function(_0x1a17e2){_0x38b7b7['rows']=_0x1a17e2;return _0x38b7b7;})['then'](respondWithFilteredResult(_0x4b4d2b,_0x1b0d87))['catch'](handleError(_0x4b4d2b,null));};exports[_0xe3fc('0x51')]=function(_0x33a62b,_0x577b14){var _0x2100f6={'raw':!![],'where':{'id':_0x33a62b[_0xe3fc('0x52')]['id']}},_0x5338c4={};_0x5338c4[_0xe3fc('0x3c')]=_[_0xe3fc('0x3e')](db[_0xe3fc('0x39')][_0xe3fc('0x3a')]);_0x5338c4[_0xe3fc('0x3d')]=_['keys'](_0x33a62b['query']);_0x5338c4[_0xe3fc('0x3f')]=_[_0xe3fc('0x40')](_0x5338c4[_0xe3fc('0x3c')],_0x5338c4[_0xe3fc('0x3d')]);_0x2100f6[_0xe3fc('0x41')]=_[_0xe3fc('0x40')](_0x5338c4[_0xe3fc('0x3c')],qs['fields'](_0x33a62b[_0xe3fc('0x3d')][_0xe3fc('0x42')]));_0x2100f6[_0xe3fc('0x41')]=_0x2100f6[_0xe3fc('0x41')]['length']?_0x2100f6['attributes']:_0x5338c4['model'];if(_0x33a62b[_0xe3fc('0x3d')][_0xe3fc('0x4e')]){_0x2100f6[_0xe3fc('0x4f')]=[{'all':!![]}];}_0x2100f6=_[_0xe3fc('0x4c')]({},_0x2100f6,_0x33a62b[_0xe3fc('0x4d')]);return db[_0xe3fc('0x39')][_0xe3fc('0x53')](_0x2100f6)[_0xe3fc('0x1d')](handleEntityNotFound(_0x577b14,null))[_0xe3fc('0x1d')](respondWithResult(_0x577b14,null))[_0xe3fc('0x54')](handleError(_0x577b14,null));};exports[_0xe3fc('0x55')]=function(_0x3a9d46,_0x2a95a5){return db['SmsMessage']['create'](_0x3a9d46['body'],{})[_0xe3fc('0x1d')](respondWithResult(_0x2a95a5,0xc9))[_0xe3fc('0x54')](handleError(_0x2a95a5,null));};exports[_0xe3fc('0x31')]=function(_0x4e5eb8,_0x4b06cf){if(_0x4e5eb8[_0xe3fc('0x56')]['id']){delete _0x4e5eb8[_0xe3fc('0x56')]['id'];}return db[_0xe3fc('0x39')]['find']({'where':{'id':_0x4e5eb8['params']['id']}})['then'](handleEntityNotFound(_0x4b06cf,null))[_0xe3fc('0x1d')](saveUpdates(_0x4e5eb8['body'],null))['then'](respondWithResult(_0x4b06cf,null))[_0xe3fc('0x54')](handleError(_0x4b06cf,null));};exports['destroy']=function(_0x4b5e5d,_0x5ed9be){return db[_0xe3fc('0x39')][_0xe3fc('0x53')]({'where':{'id':_0x4b5e5d[_0xe3fc('0x52')]['id']}})[_0xe3fc('0x1d')](handleEntityNotFound(_0x5ed9be,null))[_0xe3fc('0x1d')](removeEntity(_0x5ed9be,null))['catch'](handleError(_0x5ed9be,null));};exports[_0xe3fc('0x57')]=function(_0x34585a,_0x5bd77d){return db[_0xe3fc('0x39')][_0xe3fc('0x57')]()[_0xe3fc('0x1d')](respondWithResult(_0x5bd77d,null))[_0xe3fc('0x54')](handleError(_0x5bd77d,null));};var interaction_log=require(_0xe3fc('0x11'))(_0xe3fc('0x58'));exports[_0xe3fc('0x59')]=function(_0x4dd1ea,_0x3dbf21,_0x1dbffe){var _0x8d1312={'agent':{},'channel':_0xe3fc('0x5a')};if(_0x4dd1ea[_0xe3fc('0x56')]['id']){delete _0x4dd1ea[_0xe3fc('0x56')]['id'];}_0x4dd1ea[_0xe3fc('0x56')][_0xe3fc('0x5b')]=!![];_0x4dd1ea[_0xe3fc('0x56')][_0xe3fc('0x5c')]=moment()[_0xe3fc('0x5d')]('YYYY-MM-DD\x20HH:mm:ss');_0x4dd1ea[_0xe3fc('0x56')][_0xe3fc('0x5e')]=_0x4dd1ea[_0xe3fc('0x56')]['UserId']||_0x4dd1ea[_0xe3fc('0x5f')]['id'];_0x8d1312['agent']['id']=_0x4dd1ea[_0xe3fc('0x56')]['UserId'];return db['SmsMessage'][_0xe3fc('0x53')]({'where':{'id':_0x4dd1ea[_0xe3fc('0x52')]['id'],'UserId':null}})[_0xe3fc('0x1d')](handleEntityNotFound(_0x3dbf21,null))[_0xe3fc('0x1d')](saveUpdates(_0x4dd1ea['body'],null))[_0xe3fc('0x1d')](function(_0x348e0c){if(_0x348e0c){_0x8d1312[_0xe3fc('0x24')]=_0x348e0c[_0xe3fc('0x60')]({'plain':!![]});return db[_0xe3fc('0x61')][_0xe3fc('0x53')]({'where':{'id':_0x348e0c[_0xe3fc('0x62')]}});}return null;})['then'](handleEntityNotFound(_0x3dbf21,null))[_0xe3fc('0x1d')](function(_0x4f8ab3){if(_0x4f8ab3){return _0x4f8ab3[_0xe3fc('0x31')]({'UserId':_0x4dd1ea[_0xe3fc('0x56')][_0xe3fc('0x5e')],'read1stAt':_[_0xe3fc('0x63')](_0x4f8ab3[_0xe3fc('0x64')])?moment()['format'](_0xe3fc('0x65')):undefined});}return null;})[_0xe3fc('0x1d')](function(_0x1ea8b5){if(_0x1ea8b5){_0x8d1312[_0xe3fc('0x66')]=_0x1ea8b5[_0xe3fc('0x60')]({'plain':!![]});interaction_log[_0xe3fc('0x1e')]('[SMSMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x4dd1ea[_0xe3fc('0x5f')]['id'],_0x4dd1ea[_0xe3fc('0x5f')][_0xe3fc('0x35')],_0x4dd1ea[_0xe3fc('0x5f')][_0xe3fc('0x67')],_0x8d1312['interaction']['id'],_0x4dd1ea[_0xe3fc('0x56')]?JSON[_0xe3fc('0x21')](_0x4dd1ea[_0xe3fc('0x56')]):'null');return respondWithRpcPromise(_0xe3fc('0x68'),_0xe3fc('0x69'),_0x8d1312);}return null;})['then'](function(_0x44529b){var _0x3b5a52=_0xe3fc('0x6a')+_0x44529b['message'][_0xe3fc('0x6b')];return db[_0xe3fc('0x6c')]['query'](_0x3b5a52,{'type':db[_0xe3fc('0x6d')][_0xe3fc('0x6e')][_0xe3fc('0x6f')],'raw':!![]})[_0xe3fc('0x1d')](function(_0x11e0d2){return _0x11e0d2;});})['then'](function(_0x579391){if(_0x579391){_0x8d1312[_0xe3fc('0x24')][_0xe3fc('0x70')]=_0x579391[0x0];if(!_0x4dd1ea[_0xe3fc('0x56')]['UserId'])return;return db['User'][_0xe3fc('0x53')]({'where':{'id':_0x4dd1ea[_0xe3fc('0x56')][_0xe3fc('0x5e')],'role':_0xe3fc('0x71')},'attributes':['id',_0xe3fc('0x35'),_0xe3fc('0x72'),_0xe3fc('0x73'),_0xe3fc('0x74')],'raw':!![]});}return null;})[_0xe3fc('0x1d')](function(_0x44ee45){if(!_0x44ee45)return null;_0x8d1312[_0xe3fc('0x24')]['agent']=_0x44ee45;return _0x8d1312;})[_0xe3fc('0x1d')](function(_0x376bd2){if(_0x376bd2){if(_0x4dd1ea[_0xe3fc('0x56')][_0xe3fc('0x75')]){_0x8d1312[_0xe3fc('0x24')][_0xe3fc('0x76')]=util[_0xe3fc('0x5d')]('SIP/%s',_0x4dd1ea['user'][_0xe3fc('0x35')]);_0x8d1312[_0xe3fc('0x24')][_0xe3fc('0x77')]=_0x8d1312['channel'];_0x8d1312[_0xe3fc('0x24')][_0xe3fc('0x78')]=_0x8d1312[_0xe3fc('0x77')];_0x8d1312[_0xe3fc('0x24')]['event']='accept';return respondWithRpcPromise(_0xe3fc('0x79'),_0xe3fc('0x79'),{'event':_0xe3fc('0x7a'),'message':_0x8d1312[_0xe3fc('0x24')]},client9002)[_0xe3fc('0x1d')](function(){return _0x8d1312;});}return _0x8d1312;}return null;})['then'](respondWithResult(_0x3dbf21,null))[_0xe3fc('0x54')](handleError(_0x3dbf21,null));};var interaction_log=require(_0xe3fc('0x11'))('sms-interactions');exports[_0xe3fc('0x2f')]=function(_0x130f78,_0x3b0b0f,_0x1c3c7c){var _0x2d8ff5={'agent':{},'channel':_0xe3fc('0x5a')};if(_0x130f78[_0xe3fc('0x56')]['id']){delete _0x130f78[_0xe3fc('0x56')]['id'];}_0x130f78['body'][_0xe3fc('0x5e')]=_0x130f78[_0xe3fc('0x56')][_0xe3fc('0x5e')]||_0x130f78[_0xe3fc('0x5f')]['id'];_0x2d8ff5[_0xe3fc('0x71')]['id']=_0x130f78[_0xe3fc('0x56')][_0xe3fc('0x5e')];return db['SmsMessage'][_0xe3fc('0x53')]({'where':{'id':_0x130f78['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x3b0b0f,null))[_0xe3fc('0x1d')](function(_0xc67375){if(_0xc67375){_0x2d8ff5['message']=_0xc67375[_0xe3fc('0x60')]({'plain':!![]});return db['SmsInteraction'][_0xe3fc('0x53')]({'where':{'id':_0xc67375[_0xe3fc('0x62')]}});}return null;})[_0xe3fc('0x1d')](handleEntityNotFound(_0x3b0b0f,null))[_0xe3fc('0x1d')](function(_0x749800){if(_0x749800){_0x2d8ff5[_0xe3fc('0x66')]=_0x749800['get']({'plain':!![]});interaction_log['info']('[SMSMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x130f78[_0xe3fc('0x5f')]['id'],_0x130f78['user'][_0xe3fc('0x35')],_0x130f78['user'][_0xe3fc('0x67')],_0x2d8ff5[_0xe3fc('0x66')]['id'],_0x130f78[_0xe3fc('0x56')]?JSON[_0xe3fc('0x21')](_0x130f78['body']):'null');return respondWithRpcPromise('RejectMessage',_0xe3fc('0x7b'),_0x2d8ff5);}return null;})[_0xe3fc('0x1d')](function(_0x30f8e0){var _0x26b853=_0xe3fc('0x6a')+_0x30f8e0[_0xe3fc('0x24')][_0xe3fc('0x6b')];return db['sequelize'][_0xe3fc('0x3d')](_0x26b853,{'type':db[_0xe3fc('0x6d')][_0xe3fc('0x6e')][_0xe3fc('0x6f')],'raw':!![]})[_0xe3fc('0x1d')](function(_0x114185){return _0x114185;});})['then'](function(_0xdc176d){if(_0xdc176d){_0x2d8ff5['message']['contact']=_0xdc176d[0x0];if(!_0x130f78[_0xe3fc('0x56')][_0xe3fc('0x5e')])return;return db[_0xe3fc('0x7c')][_0xe3fc('0x53')]({'where':{'id':_0x130f78[_0xe3fc('0x56')][_0xe3fc('0x5e')],'role':'agent'},'attributes':['id',_0xe3fc('0x35'),_0xe3fc('0x72'),_0xe3fc('0x73'),_0xe3fc('0x74')],'raw':!![]});}return null;})[_0xe3fc('0x1d')](function(_0x173841){if(!_0x173841)return null;_0x2d8ff5[_0xe3fc('0x24')][_0xe3fc('0x71')]=_0x173841;return _0x2d8ff5;})[_0xe3fc('0x1d')](function(_0x70aede){if(_0x70aede){_0x70aede[_0xe3fc('0x24')][_0xe3fc('0x76')]=util[_0xe3fc('0x5d')](_0xe3fc('0x7d'),_0x130f78[_0xe3fc('0x5f')][_0xe3fc('0x35')]);_0x70aede['message'][_0xe3fc('0x77')]=_0x2d8ff5[_0xe3fc('0x77')];_0x70aede['message'][_0xe3fc('0x78')]=_0x2d8ff5[_0xe3fc('0x77')];_0x70aede['message'][_0xe3fc('0x7e')]=_0xe3fc('0x2f');respondWithRpcPromise(_0xe3fc('0x79'),_0xe3fc('0x79'),{'event':_0xe3fc('0x7f'),'message':_0x70aede[_0xe3fc('0x24')]},client9002);return _0x2d8ff5;}return null;})[_0xe3fc('0x1d')](respondWithResult(_0x3b0b0f,null))[_0xe3fc('0x54')](handleError(_0x3b0b0f,null));};exports[_0xe3fc('0x27')]=function(_0xff3647,_0x5387c6,_0x1f252b){if(_0xff3647[_0xe3fc('0x56')]['id']){delete _0xff3647['body']['id'];}var _0x1a4551;return db[_0xe3fc('0x39')][_0xe3fc('0x53')]({'where':{'id':_0xff3647['params']['id']}})[_0xe3fc('0x1d')](handleEntityNotFound(_0x5387c6,null))[_0xe3fc('0x1d')](function(_0x315bce){if(_0x315bce){_0x1a4551=_0x315bce;return db[_0xe3fc('0x80')][_0xe3fc('0x53')]({'where':{'id':_0x315bce[_0xe3fc('0x81')]}});}})[_0xe3fc('0x1d')](handleEntityNotFound(_0x5387c6,null))[_0xe3fc('0x1d')](function(_0x52c222){if(_0x52c222){logger[_0xe3fc('0x82')](_0xe3fc('0x83'),_0xe3fc('0x27'),_0xe3fc('0x84'),_0x52c222[_0xe3fc('0x4a')],util[_0xe3fc('0x85')](_0xff3647[_0xe3fc('0x56')],{'showHidden':![],'depth':null}));switch(_0x52c222['type']){case'twilio':if(_0xff3647[_0xe3fc('0x56')][_0xe3fc('0x86')]&&_0xff3647[_0xe3fc('0x56')]['MessageSid']===_0x1a4551['messageId']){return _0x1a4551[_0xe3fc('0x31')]({'read':!![]});}else{logger[_0xe3fc('0x22')](_0xe3fc('0x87'),_0xe3fc('0x27'),_0xe3fc('0x88'),util['inspect'](_0xff3647[_0xe3fc('0x56')],{'showHidden':![],'depth':null}));}break;case _0xe3fc('0x89'):if(_0xff3647[_0xe3fc('0x56')][_0xe3fc('0x8a')]&&_0xff3647[_0xe3fc('0x56')][_0xe3fc('0x8a')]===_0x1a4551[_0xe3fc('0x8b')]&&_[_0xe3fc('0x8c')](['sent','delivered'],_0xff3647[_0xe3fc('0x56')][_0xe3fc('0x8d')])>=0x0){return _0x1a4551[_0xe3fc('0x31')]({'read':!![]});}else{logger[_0xe3fc('0x22')](_0xe3fc('0x87'),'status',_0xe3fc('0x8e'),util[_0xe3fc('0x85')](_0xff3647[_0xe3fc('0x56')],{'showHidden':![],'depth':null}));}break;case _0xe3fc('0x8f'):var _0x28d479=_0xff3647[_0xe3fc('0x56')][_0xe3fc('0x90')][0x0];if(_0x28d479[_0xe3fc('0x27')][_0xe3fc('0x91')]===_0xe3fc('0x92')){return _0x1a4551[_0xe3fc('0x31')]({'read':!![]});}else{logger['error'](_0xe3fc('0x87'),_0xe3fc('0x27'),_0xe3fc('0x8f'),util[_0xe3fc('0x85')](_0xff3647[_0xe3fc('0x56')],{'showHidden':![],'depth':null}));}break;}return _0x1a4551;}})['then'](respondWithResult(_0x5387c6,null))[_0xe3fc('0x54')](handleError(_0x5387c6,null));};