Built motion from commit c116dc8b.|2.6.30
[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 _0xbc48=['api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','jayson/promise','client','http','request','info','request\x20sent','SmsMessage,\x20%s,\x20%s,\x20%s','error','code','SmsMessage,\x20%s,\x20%s','message','catch','sendStatus','status','end','offset','undefined','limit','count','Content-Range','apply','update','destroy','stack','name','send','index','map','SmsMessage','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','nolimit','sort','where','pick','filter','merge','options','then','includeAll','include','findAll','rows','params','keys','create','body','find','describe','sms-interactions','accept','sms','readAt','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','SmsInteractionId','isNil','read1stAt','format','role','interaction','stringify','null','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','User','fullname','email','manual','interface','SIP/%s','channel','motionChannel','event','EventManager','acceptmessage','reject','get','SmsInteraction','[SMSMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','Sequelize','QueryTypes','SELECT','internal','rejectmessage','SmsAccount','SmsAccountId','debug','received\x20delivery\x20report\x20from','inspect','MessageSid','messageId','SmsAccount,\x20%s,\x20%s,\x20%s','twilio','plivo','MessageUUID','indexOf','sent','delivered','Status','groupName','DELIVERED','infobip','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','sox','lodash','jsforce','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger'];(function(_0x564d81,_0x50d5f6){var _0x4ca859=function(_0x5c087e){while(--_0x5c087e){_0x564d81['push'](_0x564d81['shift']());}};_0x4ca859(++_0x50d5f6);}(_0xbc48,0x111));var _0x8bc4=function(_0x203416,_0x1de974){_0x203416=_0x203416-0x0;var _0x5008c9=_0xbc48[_0x203416];return _0x5008c9;};'use strict';var emlformat=require(_0x8bc4('0x0'));var rimraf=require(_0x8bc4('0x1'));var zipdir=require(_0x8bc4('0x2'));var jsonpatch=require(_0x8bc4('0x3'));var rp=require('request-promise');var moment=require(_0x8bc4('0x4'));var BPromise=require(_0x8bc4('0x5'));var Mustache=require(_0x8bc4('0x6'));var util=require(_0x8bc4('0x7'));var path=require('path');var sox=require(_0x8bc4('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x8bc4('0x9'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x8bc4('0xa'));var deskjs=require('desk.js');var toCsv=require(_0x8bc4('0xb'));var querystring=require(_0x8bc4('0xc'));var Papa=require(_0x8bc4('0xd'));var Redis=require(_0x8bc4('0xe'));var authService=require('../../components/auth/service');var qs=require(_0x8bc4('0xf'));var as=require(_0x8bc4('0x10'));var hardwareService=require(_0x8bc4('0x11'));var logger=require(_0x8bc4('0x12'))(_0x8bc4('0x13'));var utils=require(_0x8bc4('0x14'));var config=require(_0x8bc4('0x15'));var licenseUtil=require(_0x8bc4('0x16'));var db=require(_0x8bc4('0x17'))['db'];config[_0x8bc4('0x18')]=_[_0x8bc4('0x19')](config[_0x8bc4('0x18')],{'host':_0x8bc4('0x1a'),'port':0x18eb});var socket=require(_0x8bc4('0x1b'))(new Redis(config[_0x8bc4('0x18')]));require('./smsMessage.socket')[_0x8bc4('0x1c')](socket);var jayson=require(_0x8bc4('0x1d'));var client=jayson[_0x8bc4('0x1e')][_0x8bc4('0x1f')]({'port':0x232c});var client9002=jayson[_0x8bc4('0x1e')][_0x8bc4('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x5cd8f7,_0x4d2530,_0x50e59b,_0x36714f){return new BPromise(function(_0x556cef,_0x2033df){var _0x45244b=_0x36714f||client;return _0x45244b[_0x8bc4('0x20')](_0x5cd8f7,_0x50e59b)['then'](function(_0x13348c){logger[_0x8bc4('0x21')]('SmsMessage,\x20%s,\x20%s',_0x4d2530,_0x8bc4('0x22'));logger['debug'](_0x8bc4('0x23'),_0x4d2530,'request\x20sent',JSON['stringify'](_0x13348c));if(_0x13348c[_0x8bc4('0x24')]){if(_0x13348c[_0x8bc4('0x24')][_0x8bc4('0x25')]===0x1f4){logger[_0x8bc4('0x24')](_0x8bc4('0x26'),_0x4d2530,_0x13348c[_0x8bc4('0x24')][_0x8bc4('0x27')]);return _0x2033df(_0x13348c[_0x8bc4('0x24')][_0x8bc4('0x27')]);}logger[_0x8bc4('0x24')](_0x8bc4('0x26'),_0x4d2530,_0x13348c['error'][_0x8bc4('0x27')]);return _0x556cef(_0x13348c[_0x8bc4('0x24')][_0x8bc4('0x27')]);}else{logger['info'](_0x8bc4('0x26'),_0x4d2530,_0x8bc4('0x22'));_0x556cef(_0x13348c['result'][_0x8bc4('0x27')]);}})[_0x8bc4('0x28')](function(_0x45118c){logger['error'](_0x8bc4('0x26'),_0x4d2530,_0x45118c);_0x2033df(_0x45118c);});});}function respondWithStatusCode(_0x5e80f7,_0x57b437){_0x57b437=_0x57b437||0xcc;return function(_0xb44005){if(_0xb44005){return _0x5e80f7[_0x8bc4('0x29')](_0x57b437);}return _0x5e80f7[_0x8bc4('0x2a')](_0x57b437)[_0x8bc4('0x2b')]();};}function respondWithResult(_0x16c2a8,_0x14c7ec){_0x14c7ec=_0x14c7ec||0xc8;return function(_0x26133e){if(_0x26133e){return _0x16c2a8[_0x8bc4('0x2a')](_0x14c7ec)['json'](_0x26133e);}};}function respondWithFilteredResult(_0x56f462,_0x2f9cf4){return function(_0x39f657){if(_0x39f657){var _0x3bada3=typeof _0x2f9cf4[_0x8bc4('0x2c')]===_0x8bc4('0x2d')&&typeof _0x2f9cf4[_0x8bc4('0x2e')]==='undefined';var _0xf57c8a=_0x39f657[_0x8bc4('0x2f')];var _0xb006b8=_0x3bada3?0x0:_0x2f9cf4[_0x8bc4('0x2c')];var _0x5b1504=_0x3bada3?_0x39f657[_0x8bc4('0x2f')]:_0x2f9cf4[_0x8bc4('0x2c')]+_0x2f9cf4[_0x8bc4('0x2e')];var _0x3af06f;if(_0x5b1504>=_0xf57c8a){_0x5b1504=_0xf57c8a;_0x3af06f=0xc8;}else{_0x3af06f=0xce;}_0x56f462[_0x8bc4('0x2a')](_0x3af06f);return _0x56f462['set'](_0x8bc4('0x30'),_0xb006b8+'-'+_0x5b1504+'/'+_0xf57c8a)['json'](_0x39f657);}return null;};}function patchUpdates(_0x8780fa){return function(_0x231c3b){try{jsonpatch[_0x8bc4('0x31')](_0x231c3b,_0x8780fa,!![]);}catch(_0x27d91c){return BPromise['reject'](_0x27d91c);}return _0x231c3b['save']();};}function saveUpdates(_0x137f51,_0x39f9d2){return function(_0x88d673){if(_0x88d673){return _0x88d673[_0x8bc4('0x32')](_0x137f51)['then'](function(_0x4dbbc5){return _0x4dbbc5;});}return null;};}function removeEntity(_0x592820,_0x3f1cf8){return function(_0x8ee9c5){if(_0x8ee9c5){return _0x8ee9c5[_0x8bc4('0x33')]()['then'](function(){_0x592820['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x599632,_0x4c4d8d){return function(_0x38dff7){if(!_0x38dff7){_0x599632[_0x8bc4('0x29')](0x194);}return _0x38dff7;};}function handleError(_0x42597a,_0x4e0558){_0x4e0558=_0x4e0558||0x1f4;return function(_0x37885c){logger[_0x8bc4('0x24')](_0x37885c[_0x8bc4('0x34')]);if(_0x37885c['name']){delete _0x37885c[_0x8bc4('0x35')];}_0x42597a[_0x8bc4('0x2a')](_0x4e0558)[_0x8bc4('0x36')](_0x37885c);};}exports[_0x8bc4('0x37')]=function(_0x409989,_0x527d79){var _0x462133={},_0x2332c3={},_0x45d23f={'count':0x0,'rows':[]};var _0x5a4134=_[_0x8bc4('0x38')](db[_0x8bc4('0x39')][_0x8bc4('0x3a')],function(_0x14a511){return{'name':_0x14a511[_0x8bc4('0x3b')],'type':_0x14a511[_0x8bc4('0x3c')][_0x8bc4('0x3d')]};});_0x2332c3[_0x8bc4('0x3e')]=_[_0x8bc4('0x38')](_0x5a4134,_0x8bc4('0x35'));_0x2332c3[_0x8bc4('0x3f')]=_['keys'](_0x409989['query']);_0x2332c3[_0x8bc4('0x40')]=_[_0x8bc4('0x41')](_0x2332c3['model'],_0x2332c3[_0x8bc4('0x3f')]);_0x462133[_0x8bc4('0x42')]=_[_0x8bc4('0x41')](_0x2332c3['model'],qs['fields'](_0x409989[_0x8bc4('0x3f')][_0x8bc4('0x43')]));_0x462133[_0x8bc4('0x42')]=_0x462133[_0x8bc4('0x42')][_0x8bc4('0x44')]?_0x462133[_0x8bc4('0x42')]:_0x2332c3[_0x8bc4('0x3e')];if(!_0x409989['query']['hasOwnProperty'](_0x8bc4('0x45'))){_0x462133['limit']=qs['limit'](_0x409989[_0x8bc4('0x3f')][_0x8bc4('0x2e')]);_0x462133[_0x8bc4('0x2c')]=qs[_0x8bc4('0x2c')](_0x409989[_0x8bc4('0x3f')][_0x8bc4('0x2c')]);}_0x462133['order']=qs[_0x8bc4('0x46')](_0x409989[_0x8bc4('0x3f')]['sort']);_0x462133[_0x8bc4('0x47')]=qs['filters'](_[_0x8bc4('0x48')](_0x409989['query'],_0x2332c3[_0x8bc4('0x40')]),_0x5a4134);if(_0x409989[_0x8bc4('0x3f')][_0x8bc4('0x49')]){_0x462133['where']=_[_0x8bc4('0x4a')](_0x462133[_0x8bc4('0x47')],{'$or':_[_0x8bc4('0x38')](_0x5a4134,function(_0x6e7110){if(_0x6e7110['type']!=='VIRTUAL'){var _0x3a7984={};_0x3a7984[_0x6e7110[_0x8bc4('0x35')]]={'$like':'%'+_0x409989[_0x8bc4('0x3f')]['filter']+'%'};return _0x3a7984;}})});}_0x462133=_['merge']({},_0x462133,_0x409989[_0x8bc4('0x4b')]);var _0x546553={'where':_0x462133[_0x8bc4('0x47')]};return db[_0x8bc4('0x39')][_0x8bc4('0x2f')](_0x546553)[_0x8bc4('0x4c')](function(_0x66bb1d){_0x45d23f[_0x8bc4('0x2f')]=_0x66bb1d;if(_0x409989[_0x8bc4('0x3f')][_0x8bc4('0x4d')]){_0x462133[_0x8bc4('0x4e')]=[{'all':!![]}];}return db[_0x8bc4('0x39')][_0x8bc4('0x4f')](_0x462133);})[_0x8bc4('0x4c')](function(_0x7007f4){_0x45d23f[_0x8bc4('0x50')]=_0x7007f4;return _0x45d23f;})[_0x8bc4('0x4c')](respondWithFilteredResult(_0x527d79,_0x462133))[_0x8bc4('0x28')](handleError(_0x527d79,null));};exports['show']=function(_0x1b89c3,_0x1ec8bb){var _0xa8f0c6={'raw':!![],'where':{'id':_0x1b89c3[_0x8bc4('0x51')]['id']}},_0x1a4253={};_0x1a4253[_0x8bc4('0x3e')]=_[_0x8bc4('0x52')](db[_0x8bc4('0x39')]['rawAttributes']);_0x1a4253[_0x8bc4('0x3f')]=_[_0x8bc4('0x52')](_0x1b89c3[_0x8bc4('0x3f')]);_0x1a4253[_0x8bc4('0x40')]=_['intersection'](_0x1a4253[_0x8bc4('0x3e')],_0x1a4253['query']);_0xa8f0c6[_0x8bc4('0x42')]=_['intersection'](_0x1a4253[_0x8bc4('0x3e')],qs[_0x8bc4('0x43')](_0x1b89c3[_0x8bc4('0x3f')]['fields']));_0xa8f0c6[_0x8bc4('0x42')]=_0xa8f0c6[_0x8bc4('0x42')]['length']?_0xa8f0c6['attributes']:_0x1a4253[_0x8bc4('0x3e')];if(_0x1b89c3['query'][_0x8bc4('0x4d')]){_0xa8f0c6[_0x8bc4('0x4e')]=[{'all':!![]}];}_0xa8f0c6=_[_0x8bc4('0x4a')]({},_0xa8f0c6,_0x1b89c3['options']);return db[_0x8bc4('0x39')]['find'](_0xa8f0c6)[_0x8bc4('0x4c')](handleEntityNotFound(_0x1ec8bb,null))[_0x8bc4('0x4c')](respondWithResult(_0x1ec8bb,null))[_0x8bc4('0x28')](handleError(_0x1ec8bb,null));};exports['create']=function(_0x341646,_0x3751be){return db['SmsMessage'][_0x8bc4('0x53')](_0x341646['body'],{})[_0x8bc4('0x4c')](respondWithResult(_0x3751be,0xc9))[_0x8bc4('0x28')](handleError(_0x3751be,null));};exports[_0x8bc4('0x32')]=function(_0x194697,_0x27561f){if(_0x194697['body']['id']){delete _0x194697[_0x8bc4('0x54')]['id'];}return db['SmsMessage'][_0x8bc4('0x55')]({'where':{'id':_0x194697['params']['id']}})[_0x8bc4('0x4c')](handleEntityNotFound(_0x27561f,null))['then'](saveUpdates(_0x194697[_0x8bc4('0x54')],null))['then'](respondWithResult(_0x27561f,null))[_0x8bc4('0x28')](handleError(_0x27561f,null));};exports['destroy']=function(_0x579c0e,_0x2086aa){return db[_0x8bc4('0x39')]['find']({'where':{'id':_0x579c0e[_0x8bc4('0x51')]['id']}})[_0x8bc4('0x4c')](handleEntityNotFound(_0x2086aa,null))[_0x8bc4('0x4c')](removeEntity(_0x2086aa,null))['catch'](handleError(_0x2086aa,null));};exports[_0x8bc4('0x56')]=function(_0xdbb0e1,_0x2c6396){return db[_0x8bc4('0x39')][_0x8bc4('0x56')]()[_0x8bc4('0x4c')](respondWithResult(_0x2c6396,null))[_0x8bc4('0x28')](handleError(_0x2c6396,null));};var interaction_log=require(_0x8bc4('0x12'))(_0x8bc4('0x57'));exports[_0x8bc4('0x58')]=function(_0x4d6976,_0x17b3ea,_0x4faa32){var _0x72cb62={'agent':{},'channel':_0x8bc4('0x59')};if(_0x4d6976[_0x8bc4('0x54')]['id']){delete _0x4d6976[_0x8bc4('0x54')]['id'];}_0x4d6976[_0x8bc4('0x54')]['read']=!![];_0x4d6976['body'][_0x8bc4('0x5a')]=moment()['format'](_0x8bc4('0x5b'));_0x4d6976[_0x8bc4('0x54')][_0x8bc4('0x5c')]=_0x4d6976['body'][_0x8bc4('0x5c')]||_0x4d6976[_0x8bc4('0x5d')]['id'];_0x72cb62[_0x8bc4('0x5e')]['id']=_0x4d6976[_0x8bc4('0x54')]['UserId'];return db[_0x8bc4('0x39')][_0x8bc4('0x55')]({'where':{'id':_0x4d6976['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x17b3ea,null))[_0x8bc4('0x4c')](saveUpdates(_0x4d6976[_0x8bc4('0x54')],null))[_0x8bc4('0x4c')](function(_0x4a425f){if(_0x4a425f){_0x72cb62[_0x8bc4('0x27')]=_0x4a425f['get']({'plain':!![]});return db['SmsInteraction'][_0x8bc4('0x55')]({'where':{'id':_0x4a425f[_0x8bc4('0x5f')]}});}return null;})[_0x8bc4('0x4c')](handleEntityNotFound(_0x17b3ea,null))[_0x8bc4('0x4c')](function(_0x47b3f8){if(_0x47b3f8){return _0x47b3f8[_0x8bc4('0x32')]({'UserId':_0x4d6976['body'][_0x8bc4('0x5c')],'read1stAt':_[_0x8bc4('0x60')](_0x47b3f8[_0x8bc4('0x61')])?moment()[_0x8bc4('0x62')](_0x8bc4('0x5b')):undefined});}return null;})['then'](function(_0x430513){if(_0x430513){_0x72cb62['interaction']=_0x430513['get']({'plain':!![]});interaction_log[_0x8bc4('0x21')]('[SMSMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x4d6976['user']['id'],_0x4d6976[_0x8bc4('0x5d')][_0x8bc4('0x35')],_0x4d6976[_0x8bc4('0x5d')][_0x8bc4('0x63')],_0x72cb62[_0x8bc4('0x64')]['id'],_0x4d6976[_0x8bc4('0x54')]?JSON[_0x8bc4('0x65')](_0x4d6976[_0x8bc4('0x54')]):_0x8bc4('0x66'));return respondWithRpcPromise('AcceptMessage',_0x8bc4('0x67'),_0x72cb62);}return null;})[_0x8bc4('0x4c')](function(_0x173e5a){var _0x1eac6f=_0x8bc4('0x68')+_0x173e5a[_0x8bc4('0x27')]['ContactId'];return db[_0x8bc4('0x69')][_0x8bc4('0x3f')](_0x1eac6f,{'type':db['Sequelize']['QueryTypes']['SELECT'],'raw':!![]})['then'](function(_0x193732){return _0x193732;});})[_0x8bc4('0x4c')](function(_0x172540){if(_0x172540){_0x72cb62['message']['contact']=_0x172540[0x0];if(!_0x4d6976[_0x8bc4('0x54')][_0x8bc4('0x5c')])return;return db[_0x8bc4('0x6a')][_0x8bc4('0x55')]({'where':{'id':_0x4d6976[_0x8bc4('0x54')][_0x8bc4('0x5c')],'role':_0x8bc4('0x5e')},'attributes':['id',_0x8bc4('0x35'),_0x8bc4('0x6b'),_0x8bc4('0x6c'),'internal'],'raw':!![]});}return null;})[_0x8bc4('0x4c')](function(_0x16ea04){if(!_0x16ea04)return null;_0x72cb62[_0x8bc4('0x27')][_0x8bc4('0x5e')]=_0x16ea04;return _0x72cb62;})['then'](function(_0x54123e){if(_0x54123e){if(_0x4d6976[_0x8bc4('0x54')][_0x8bc4('0x6d')]){_0x72cb62[_0x8bc4('0x27')][_0x8bc4('0x6e')]=util[_0x8bc4('0x62')](_0x8bc4('0x6f'),_0x4d6976[_0x8bc4('0x5d')][_0x8bc4('0x35')]);_0x72cb62[_0x8bc4('0x27')]['channel']=_0x72cb62[_0x8bc4('0x70')];_0x72cb62[_0x8bc4('0x27')][_0x8bc4('0x71')]=_0x72cb62[_0x8bc4('0x70')];_0x72cb62['message'][_0x8bc4('0x72')]=_0x8bc4('0x58');return respondWithRpcPromise(_0x8bc4('0x73'),'EventManager',{'event':_0x8bc4('0x74'),'message':_0x72cb62[_0x8bc4('0x27')]},client9002)['then'](function(){return _0x72cb62;});}return _0x72cb62;}return null;})[_0x8bc4('0x4c')](respondWithResult(_0x17b3ea,null))[_0x8bc4('0x28')](handleError(_0x17b3ea,null));};var interaction_log=require(_0x8bc4('0x12'))(_0x8bc4('0x57'));exports[_0x8bc4('0x75')]=function(_0x462020,_0x13d34f,_0x51428e){var _0x41e301={'agent':{},'channel':'sms'};if(_0x462020[_0x8bc4('0x54')]['id']){delete _0x462020[_0x8bc4('0x54')]['id'];}_0x462020[_0x8bc4('0x54')][_0x8bc4('0x5c')]=_0x462020[_0x8bc4('0x54')]['UserId']||_0x462020[_0x8bc4('0x5d')]['id'];_0x41e301[_0x8bc4('0x5e')]['id']=_0x462020['body']['UserId'];return db['SmsMessage'][_0x8bc4('0x55')]({'where':{'id':_0x462020[_0x8bc4('0x51')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x13d34f,null))['then'](function(_0x1cd458){if(_0x1cd458){_0x41e301['message']=_0x1cd458[_0x8bc4('0x76')]({'plain':!![]});return db[_0x8bc4('0x77')][_0x8bc4('0x55')]({'where':{'id':_0x1cd458[_0x8bc4('0x5f')]}});}return null;})[_0x8bc4('0x4c')](handleEntityNotFound(_0x13d34f,null))[_0x8bc4('0x4c')](function(_0xd701b6){if(_0xd701b6){_0x41e301[_0x8bc4('0x64')]=_0xd701b6['get']({'plain':!![]});interaction_log['info'](_0x8bc4('0x78'),_0x462020[_0x8bc4('0x5d')]['id'],_0x462020[_0x8bc4('0x5d')][_0x8bc4('0x35')],_0x462020['user'][_0x8bc4('0x63')],_0x41e301[_0x8bc4('0x64')]['id'],_0x462020['body']?JSON[_0x8bc4('0x65')](_0x462020['body']):'null');return respondWithRpcPromise(_0x8bc4('0x79'),_0x8bc4('0x7a'),_0x41e301);}return null;})[_0x8bc4('0x4c')](function(_0x5c1090){var _0x264944='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x5c1090[_0x8bc4('0x27')]['ContactId'];return db[_0x8bc4('0x69')][_0x8bc4('0x3f')](_0x264944,{'type':db[_0x8bc4('0x7b')][_0x8bc4('0x7c')][_0x8bc4('0x7d')],'raw':!![]})[_0x8bc4('0x4c')](function(_0x409e04){return _0x409e04;});})['then'](function(_0x260a11){if(_0x260a11){_0x41e301[_0x8bc4('0x27')]['contact']=_0x260a11[0x0];if(!_0x462020[_0x8bc4('0x54')][_0x8bc4('0x5c')])return;return db['User'][_0x8bc4('0x55')]({'where':{'id':_0x462020[_0x8bc4('0x54')][_0x8bc4('0x5c')],'role':_0x8bc4('0x5e')},'attributes':['id',_0x8bc4('0x35'),'fullname',_0x8bc4('0x6c'),_0x8bc4('0x7e')],'raw':!![]});}return null;})[_0x8bc4('0x4c')](function(_0x46e48a){if(!_0x46e48a)return null;_0x41e301[_0x8bc4('0x27')][_0x8bc4('0x5e')]=_0x46e48a;return _0x41e301;})[_0x8bc4('0x4c')](function(_0x2bc9b9){if(_0x2bc9b9){_0x2bc9b9[_0x8bc4('0x27')]['interface']=util[_0x8bc4('0x62')](_0x8bc4('0x6f'),_0x462020[_0x8bc4('0x5d')]['name']);_0x2bc9b9[_0x8bc4('0x27')][_0x8bc4('0x70')]=_0x41e301[_0x8bc4('0x70')];_0x2bc9b9['message'][_0x8bc4('0x71')]=_0x41e301['channel'];_0x2bc9b9[_0x8bc4('0x27')][_0x8bc4('0x72')]=_0x8bc4('0x75');respondWithRpcPromise(_0x8bc4('0x73'),_0x8bc4('0x73'),{'event':_0x8bc4('0x7f'),'message':_0x2bc9b9['message']},client9002);return _0x41e301;}return null;})['then'](respondWithResult(_0x13d34f,null))[_0x8bc4('0x28')](handleError(_0x13d34f,null));};exports[_0x8bc4('0x2a')]=function(_0x10caa6,_0x6e8442,_0x33deda){if(_0x10caa6['body']['id']){delete _0x10caa6[_0x8bc4('0x54')]['id'];}var _0x2ef62e;return db['SmsMessage'][_0x8bc4('0x55')]({'where':{'id':_0x10caa6[_0x8bc4('0x51')]['id']}})['then'](handleEntityNotFound(_0x6e8442,null))[_0x8bc4('0x4c')](function(_0x1f23be){if(_0x1f23be){_0x2ef62e=_0x1f23be;return db[_0x8bc4('0x80')][_0x8bc4('0x55')]({'where':{'id':_0x1f23be[_0x8bc4('0x81')]}});}})[_0x8bc4('0x4c')](handleEntityNotFound(_0x6e8442,null))[_0x8bc4('0x4c')](function(_0x929ed8){if(_0x929ed8){logger[_0x8bc4('0x82')](_0x8bc4('0x23'),'status',_0x8bc4('0x83'),_0x929ed8[_0x8bc4('0x3c')],util[_0x8bc4('0x84')](_0x10caa6[_0x8bc4('0x54')],{'showHidden':![],'depth':null}));switch(_0x929ed8[_0x8bc4('0x3c')]){case'twilio':if(_0x10caa6[_0x8bc4('0x54')][_0x8bc4('0x85')]&&_0x10caa6[_0x8bc4('0x54')][_0x8bc4('0x85')]===_0x2ef62e[_0x8bc4('0x86')]){return _0x2ef62e[_0x8bc4('0x32')]({'read':!![]});}else{logger[_0x8bc4('0x24')](_0x8bc4('0x87'),_0x8bc4('0x2a'),_0x8bc4('0x88'),util['inspect'](_0x10caa6[_0x8bc4('0x54')],{'showHidden':![],'depth':null}));}break;case _0x8bc4('0x89'):if(_0x10caa6[_0x8bc4('0x54')][_0x8bc4('0x8a')]&&_0x10caa6['body'][_0x8bc4('0x8a')]===_0x2ef62e[_0x8bc4('0x86')]&&_[_0x8bc4('0x8b')]([_0x8bc4('0x8c'),_0x8bc4('0x8d')],_0x10caa6[_0x8bc4('0x54')][_0x8bc4('0x8e')])>=0x0){return _0x2ef62e[_0x8bc4('0x32')]({'read':!![]});}else{logger[_0x8bc4('0x24')](_0x8bc4('0x87'),_0x8bc4('0x2a'),'plivio',util['inspect'](_0x10caa6['body'],{'showHidden':![],'depth':null}));}break;case'infobip':var _0x5ddbf4=_0x10caa6[_0x8bc4('0x54')]['results'][0x0];if(_0x5ddbf4[_0x8bc4('0x2a')][_0x8bc4('0x8f')]===_0x8bc4('0x90')){return _0x2ef62e[_0x8bc4('0x32')]({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0x8bc4('0x2a'),_0x8bc4('0x91'),util[_0x8bc4('0x84')](_0x10caa6[_0x8bc4('0x54')],{'showHidden':![],'depth':null}));}break;}return _0x2ef62e;}})[_0x8bc4('0x4c')](respondWithResult(_0x6e8442,null))[_0x8bc4('0x28')](handleError(_0x6e8442,null));};