Built motion from commit 85328c08.|2.5.50
[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 _0x97b2=['plivio','infobip','groupName','DELIVERED','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','squel','crypto','desk.js','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsMessage.socket','jayson/promise','client','http','request','info','request\x20sent','debug','SmsMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','SmsMessage,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','json','reject','save','then','stack','name','send','map','SmsMessage','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','includeAll','include','findAll','rows','show','params','find','create','body','sms-interactions','accept','sms','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','get','SmsInteraction','update','isNil','read1stAt','interaction','role','null','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','QueryTypes','SELECT','User','fullname','internal','manual','interface','SIP/%s','channel','motionChannel','event','EventManager','acceptmessage','SmsInteractionId','rejectMessage','email','rejectmessage','SmsAccount','received\x20delivery\x20report\x20from','inspect','twilio','MessageSid','messageId','SmsAccount,\x20%s,\x20%s,\x20%s','plivo','indexOf','sent','delivered','Status'];(function(_0x501f78,_0xc08722){var _0xca5be5=function(_0x4e49e1){while(--_0x4e49e1){_0x501f78['push'](_0x501f78['shift']());}};_0xca5be5(++_0xc08722);}(_0x97b2,0x1b7));var _0x297b=function(_0x9df060,_0x253d33){_0x9df060=_0x9df060-0x0;var _0x338dfe=_0x97b2[_0x9df060];return _0x338dfe;};'use strict';var emlformat=require(_0x297b('0x0'));var rimraf=require(_0x297b('0x1'));var zipdir=require(_0x297b('0x2'));var jsonpatch=require(_0x297b('0x3'));var rp=require(_0x297b('0x4'));var moment=require(_0x297b('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x297b('0x6'));var util=require(_0x297b('0x7'));var path=require('path');var sox=require(_0x297b('0x8'));var csv=require(_0x297b('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x297b('0xa'));var crypto=require(_0x297b('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x297b('0xc'));var toCsv=require(_0x297b('0x9'));var querystring=require('querystring');var Papa=require(_0x297b('0xd'));var Redis=require('ioredis');var authService=require(_0x297b('0xe'));var qs=require('../../components/parsers/qs');var as=require(_0x297b('0xf'));var hardwareService=require(_0x297b('0x10'));var logger=require(_0x297b('0x11'))(_0x297b('0x12'));var utils=require(_0x297b('0x13'));var config=require(_0x297b('0x14'));var licenseUtil=require(_0x297b('0x15'));var db=require(_0x297b('0x16'))['db'];config[_0x297b('0x17')]=_[_0x297b('0x18')](config[_0x297b('0x17')],{'host':_0x297b('0x19'),'port':0x18eb});var socket=require(_0x297b('0x1a'))(new Redis(config[_0x297b('0x17')]));require(_0x297b('0x1b'))['register'](socket);var jayson=require(_0x297b('0x1c'));var client=jayson[_0x297b('0x1d')]['http']({'port':0x232c});var client9002=jayson[_0x297b('0x1d')][_0x297b('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x4455f3,_0x241ff6,_0x11469e,_0x2b0e25){return new BPromise(function(_0x4882a4,_0x3a583b){var _0x34854d=_0x2b0e25||client;return _0x34854d[_0x297b('0x1f')](_0x4455f3,_0x11469e)['then'](function(_0x5bc19c){logger[_0x297b('0x20')]('SmsMessage,\x20%s,\x20%s',_0x241ff6,_0x297b('0x21'));logger[_0x297b('0x22')](_0x297b('0x23'),_0x241ff6,_0x297b('0x21'),JSON[_0x297b('0x24')](_0x5bc19c));if(_0x5bc19c['error']){if(_0x5bc19c[_0x297b('0x25')][_0x297b('0x26')]===0x1f4){logger['error'](_0x297b('0x27'),_0x241ff6,_0x5bc19c[_0x297b('0x25')][_0x297b('0x28')]);return _0x3a583b(_0x5bc19c[_0x297b('0x25')][_0x297b('0x28')]);}logger[_0x297b('0x25')](_0x297b('0x27'),_0x241ff6,_0x5bc19c['error'][_0x297b('0x28')]);return _0x4882a4(_0x5bc19c[_0x297b('0x25')][_0x297b('0x28')]);}else{logger['info'](_0x297b('0x27'),_0x241ff6,_0x297b('0x21'));_0x4882a4(_0x5bc19c[_0x297b('0x29')][_0x297b('0x28')]);}})[_0x297b('0x2a')](function(_0x4e995f){logger['error'](_0x297b('0x27'),_0x241ff6,_0x4e995f);_0x3a583b(_0x4e995f);});});}function respondWithStatusCode(_0x3af713,_0x46c23d){_0x46c23d=_0x46c23d||0xcc;return function(_0x2894b0){if(_0x2894b0){return _0x3af713[_0x297b('0x2b')](_0x46c23d);}return _0x3af713[_0x297b('0x2c')](_0x46c23d)[_0x297b('0x2d')]();};}function respondWithResult(_0x52bb5c,_0x4ab68b){_0x4ab68b=_0x4ab68b||0xc8;return function(_0x4c7d77){if(_0x4c7d77){return _0x52bb5c[_0x297b('0x2c')](_0x4ab68b)['json'](_0x4c7d77);}};}function respondWithFilteredResult(_0x5c2c26,_0x861618){return function(_0x323c47){if(_0x323c47){var _0x2d64a=typeof _0x861618[_0x297b('0x2e')]===_0x297b('0x2f')&&typeof _0x861618[_0x297b('0x30')]==='undefined';var _0x3a7105=_0x323c47['count'];var _0xf59317=_0x2d64a?0x0:_0x861618[_0x297b('0x2e')];var _0x4544ee=_0x2d64a?_0x323c47[_0x297b('0x31')]:_0x861618[_0x297b('0x2e')]+_0x861618[_0x297b('0x30')];var _0x1e22b3;if(_0x4544ee>=_0x3a7105){_0x4544ee=_0x3a7105;_0x1e22b3=0xc8;}else{_0x1e22b3=0xce;}_0x5c2c26[_0x297b('0x2c')](_0x1e22b3);return _0x5c2c26[_0x297b('0x32')](_0x297b('0x33'),_0xf59317+'-'+_0x4544ee+'/'+_0x3a7105)[_0x297b('0x34')](_0x323c47);}return null;};}function patchUpdates(_0x25165b){return function(_0x516b23){try{jsonpatch['apply'](_0x516b23,_0x25165b,!![]);}catch(_0x45b4c5){return BPromise[_0x297b('0x35')](_0x45b4c5);}return _0x516b23[_0x297b('0x36')]();};}function saveUpdates(_0x2f0b43,_0x576fcb){return function(_0x176790){if(_0x176790){return _0x176790['update'](_0x2f0b43)['then'](function(_0x400882){return _0x400882;});}return null;};}function removeEntity(_0x37cea8,_0x742e0b){return function(_0x2816f2){if(_0x2816f2){return _0x2816f2['destroy']()[_0x297b('0x37')](function(){_0x37cea8['status'](0xcc)[_0x297b('0x2d')]();});}};}function handleEntityNotFound(_0x6b96c0,_0x51c16b){return function(_0x472595){if(!_0x472595){_0x6b96c0[_0x297b('0x2b')](0x194);}return _0x472595;};}function handleError(_0x47cdf9,_0x51fac5){_0x51fac5=_0x51fac5||0x1f4;return function(_0x8e1844){logger[_0x297b('0x25')](_0x8e1844[_0x297b('0x38')]);if(_0x8e1844['name']){delete _0x8e1844[_0x297b('0x39')];}_0x47cdf9['status'](_0x51fac5)[_0x297b('0x3a')](_0x8e1844);};}exports['index']=function(_0x3d94ed,_0x46503d){var _0x2baa3e={},_0x18d861={},_0xc102da={'count':0x0,'rows':[]};var _0x4fade6=_[_0x297b('0x3b')](db[_0x297b('0x3c')][_0x297b('0x3d')],function(_0x581897){return{'name':_0x581897[_0x297b('0x3e')],'type':_0x581897[_0x297b('0x3f')][_0x297b('0x40')]};});_0x18d861[_0x297b('0x41')]=_[_0x297b('0x3b')](_0x4fade6,_0x297b('0x39'));_0x18d861[_0x297b('0x42')]=_[_0x297b('0x43')](_0x3d94ed[_0x297b('0x42')]);_0x18d861[_0x297b('0x44')]=_['intersection'](_0x18d861['model'],_0x18d861[_0x297b('0x42')]);_0x2baa3e[_0x297b('0x45')]=_[_0x297b('0x46')](_0x18d861[_0x297b('0x41')],qs[_0x297b('0x47')](_0x3d94ed[_0x297b('0x42')]['fields']));_0x2baa3e[_0x297b('0x45')]=_0x2baa3e[_0x297b('0x45')][_0x297b('0x48')]?_0x2baa3e[_0x297b('0x45')]:_0x18d861[_0x297b('0x41')];if(!_0x3d94ed[_0x297b('0x42')][_0x297b('0x49')](_0x297b('0x4a'))){_0x2baa3e['limit']=qs[_0x297b('0x30')](_0x3d94ed['query'][_0x297b('0x30')]);_0x2baa3e[_0x297b('0x2e')]=qs[_0x297b('0x2e')](_0x3d94ed[_0x297b('0x42')][_0x297b('0x2e')]);}_0x2baa3e[_0x297b('0x4b')]=qs[_0x297b('0x4c')](_0x3d94ed['query'][_0x297b('0x4c')]);_0x2baa3e[_0x297b('0x4d')]=qs['filters'](_[_0x297b('0x4e')](_0x3d94ed[_0x297b('0x42')],_0x18d861[_0x297b('0x44')]),_0x4fade6);if(_0x3d94ed['query'][_0x297b('0x4f')]){_0x2baa3e[_0x297b('0x4d')]=_[_0x297b('0x50')](_0x2baa3e['where'],{'$or':_[_0x297b('0x3b')](_0x4fade6,function(_0x2deb62){if(_0x2deb62[_0x297b('0x3f')]!=='VIRTUAL'){var _0x1e0a80={};_0x1e0a80[_0x2deb62[_0x297b('0x39')]]={'$like':'%'+_0x3d94ed[_0x297b('0x42')][_0x297b('0x4f')]+'%'};return _0x1e0a80;}})});}_0x2baa3e=_[_0x297b('0x50')]({},_0x2baa3e,_0x3d94ed['options']);var _0x375975={'where':_0x2baa3e[_0x297b('0x4d')]};return db['SmsMessage'][_0x297b('0x31')](_0x375975)[_0x297b('0x37')](function(_0x3cd8f8){_0xc102da[_0x297b('0x31')]=_0x3cd8f8;if(_0x3d94ed[_0x297b('0x42')][_0x297b('0x51')]){_0x2baa3e[_0x297b('0x52')]=[{'all':!![]}];}return db['SmsMessage'][_0x297b('0x53')](_0x2baa3e);})[_0x297b('0x37')](function(_0x113cf0){_0xc102da[_0x297b('0x54')]=_0x113cf0;return _0xc102da;})['then'](respondWithFilteredResult(_0x46503d,_0x2baa3e))[_0x297b('0x2a')](handleError(_0x46503d,null));};exports[_0x297b('0x55')]=function(_0x15c105,_0x4a15e1){var _0x11a6e6={'raw':!![],'where':{'id':_0x15c105[_0x297b('0x56')]['id']}},_0x3984d1={};_0x3984d1[_0x297b('0x41')]=_['keys'](db['SmsMessage'][_0x297b('0x3d')]);_0x3984d1[_0x297b('0x42')]=_[_0x297b('0x43')](_0x15c105['query']);_0x3984d1[_0x297b('0x44')]=_[_0x297b('0x46')](_0x3984d1[_0x297b('0x41')],_0x3984d1['query']);_0x11a6e6[_0x297b('0x45')]=_['intersection'](_0x3984d1[_0x297b('0x41')],qs[_0x297b('0x47')](_0x15c105['query'][_0x297b('0x47')]));_0x11a6e6[_0x297b('0x45')]=_0x11a6e6[_0x297b('0x45')]['length']?_0x11a6e6['attributes']:_0x3984d1['model'];if(_0x15c105[_0x297b('0x42')][_0x297b('0x51')]){_0x11a6e6['include']=[{'all':!![]}];}_0x11a6e6=_['merge']({},_0x11a6e6,_0x15c105['options']);return db['SmsMessage'][_0x297b('0x57')](_0x11a6e6)[_0x297b('0x37')](handleEntityNotFound(_0x4a15e1,null))[_0x297b('0x37')](respondWithResult(_0x4a15e1,null))[_0x297b('0x2a')](handleError(_0x4a15e1,null));};exports[_0x297b('0x58')]=function(_0x1665a2,_0x144fd4){return db[_0x297b('0x3c')][_0x297b('0x58')](_0x1665a2[_0x297b('0x59')],{})[_0x297b('0x37')](respondWithResult(_0x144fd4,0xc9))[_0x297b('0x2a')](handleError(_0x144fd4,null));};exports['update']=function(_0x33e218,_0x952533){if(_0x33e218[_0x297b('0x59')]['id']){delete _0x33e218[_0x297b('0x59')]['id'];}return db[_0x297b('0x3c')][_0x297b('0x57')]({'where':{'id':_0x33e218[_0x297b('0x56')]['id']}})[_0x297b('0x37')](handleEntityNotFound(_0x952533,null))['then'](saveUpdates(_0x33e218['body'],null))['then'](respondWithResult(_0x952533,null))[_0x297b('0x2a')](handleError(_0x952533,null));};exports['destroy']=function(_0x42487b,_0x14177d){return db[_0x297b('0x3c')][_0x297b('0x57')]({'where':{'id':_0x42487b['params']['id']}})[_0x297b('0x37')](handleEntityNotFound(_0x14177d,null))[_0x297b('0x37')](removeEntity(_0x14177d,null))['catch'](handleError(_0x14177d,null));};exports['describe']=function(_0xab1740,_0x1ed582){return db[_0x297b('0x3c')]['describe']()[_0x297b('0x37')](respondWithResult(_0x1ed582,null))[_0x297b('0x2a')](handleError(_0x1ed582,null));};var interaction_log=require(_0x297b('0x11'))(_0x297b('0x5a'));exports[_0x297b('0x5b')]=function(_0x2f2735,_0x22d463,_0x3be4f5){var _0x5590a1={'agent':{},'channel':_0x297b('0x5c')};if(_0x2f2735[_0x297b('0x59')]['id']){delete _0x2f2735['body']['id'];}_0x2f2735[_0x297b('0x59')][_0x297b('0x5d')]=!![];_0x2f2735[_0x297b('0x59')][_0x297b('0x5e')]=moment()[_0x297b('0x5f')](_0x297b('0x60'));_0x2f2735['body'][_0x297b('0x61')]=_0x2f2735[_0x297b('0x59')][_0x297b('0x61')]||_0x2f2735[_0x297b('0x62')]['id'];_0x5590a1[_0x297b('0x63')]['id']=_0x2f2735[_0x297b('0x59')][_0x297b('0x61')];return db['SmsMessage'][_0x297b('0x57')]({'where':{'id':_0x2f2735['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x22d463,null))[_0x297b('0x37')](saveUpdates(_0x2f2735[_0x297b('0x59')],null))[_0x297b('0x37')](function(_0x127642){if(_0x127642){_0x5590a1['message']=_0x127642[_0x297b('0x64')]({'plain':!![]});return db[_0x297b('0x65')]['find']({'where':{'id':_0x127642['SmsInteractionId']}});}return null;})[_0x297b('0x37')](handleEntityNotFound(_0x22d463,null))[_0x297b('0x37')](function(_0x2bf2f5){if(_0x2bf2f5){return _0x2bf2f5[_0x297b('0x66')]({'UserId':_0x2f2735[_0x297b('0x59')]['UserId'],'read1stAt':_[_0x297b('0x67')](_0x2bf2f5[_0x297b('0x68')])?moment()['format'](_0x297b('0x60')):undefined});}return null;})[_0x297b('0x37')](function(_0x4d1d32){if(_0x4d1d32){_0x5590a1[_0x297b('0x69')]=_0x4d1d32[_0x297b('0x64')]({'plain':!![]});interaction_log['info']('[SMSMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x2f2735[_0x297b('0x62')]['id'],_0x2f2735[_0x297b('0x62')]['name'],_0x2f2735[_0x297b('0x62')][_0x297b('0x6a')],_0x5590a1[_0x297b('0x69')]['id'],_0x2f2735['body']?JSON[_0x297b('0x24')](_0x2f2735[_0x297b('0x59')]):_0x297b('0x6b'));return respondWithRpcPromise('AcceptMessage','acceptMessage',_0x5590a1);}return null;})[_0x297b('0x37')](function(_0x58cfb3){var _0x172b08=_0x297b('0x6c')+_0x58cfb3[_0x297b('0x28')][_0x297b('0x6d')];return db[_0x297b('0x6e')][_0x297b('0x42')](_0x172b08,{'type':db[_0x297b('0x6f')][_0x297b('0x70')][_0x297b('0x71')],'raw':!![]})['then'](function(_0x47ad74){return _0x47ad74;});})[_0x297b('0x37')](function(_0x483791){if(_0x483791){_0x5590a1['message']['contact']=_0x483791[0x0];if(!_0x2f2735[_0x297b('0x59')][_0x297b('0x61')])return;return db[_0x297b('0x72')][_0x297b('0x57')]({'where':{'id':_0x2f2735[_0x297b('0x59')][_0x297b('0x61')],'role':_0x297b('0x63')},'attributes':['id',_0x297b('0x39'),_0x297b('0x73'),'email',_0x297b('0x74')],'raw':!![]});}return null;})['then'](function(_0x25e230){if(!_0x25e230)return null;_0x5590a1[_0x297b('0x28')][_0x297b('0x63')]=_0x25e230;return _0x5590a1;})[_0x297b('0x37')](function(_0x55f606){if(_0x55f606){if(_0x2f2735[_0x297b('0x59')][_0x297b('0x75')]){_0x5590a1['message'][_0x297b('0x76')]=util[_0x297b('0x5f')](_0x297b('0x77'),_0x2f2735[_0x297b('0x62')]['name']);_0x5590a1[_0x297b('0x28')][_0x297b('0x78')]=_0x5590a1[_0x297b('0x78')];_0x5590a1[_0x297b('0x28')][_0x297b('0x79')]=_0x5590a1[_0x297b('0x78')];_0x5590a1[_0x297b('0x28')][_0x297b('0x7a')]=_0x297b('0x5b');return respondWithRpcPromise('EventManager',_0x297b('0x7b'),{'event':_0x297b('0x7c'),'message':_0x5590a1[_0x297b('0x28')]},client9002)[_0x297b('0x37')](function(){return _0x5590a1;});}return _0x5590a1;}return null;})[_0x297b('0x37')](respondWithResult(_0x22d463,null))[_0x297b('0x2a')](handleError(_0x22d463,null));};var interaction_log=require(_0x297b('0x11'))(_0x297b('0x5a'));exports[_0x297b('0x35')]=function(_0x11bbd2,_0x45f47b,_0x2026e0){var _0x587349={'agent':{},'channel':_0x297b('0x5c')};if(_0x11bbd2['body']['id']){delete _0x11bbd2[_0x297b('0x59')]['id'];}_0x11bbd2['body'][_0x297b('0x61')]=_0x11bbd2['body'][_0x297b('0x61')]||_0x11bbd2[_0x297b('0x62')]['id'];_0x587349['agent']['id']=_0x11bbd2[_0x297b('0x59')][_0x297b('0x61')];return db[_0x297b('0x3c')]['find']({'where':{'id':_0x11bbd2[_0x297b('0x56')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x45f47b,null))['then'](function(_0x1408cc){if(_0x1408cc){_0x587349['message']=_0x1408cc[_0x297b('0x64')]({'plain':!![]});return db['SmsInteraction'][_0x297b('0x57')]({'where':{'id':_0x1408cc[_0x297b('0x7d')]}});}return null;})[_0x297b('0x37')](handleEntityNotFound(_0x45f47b,null))['then'](function(_0x993109){if(_0x993109){_0x587349[_0x297b('0x69')]=_0x993109[_0x297b('0x64')]({'plain':!![]});interaction_log[_0x297b('0x20')]('[SMSMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x11bbd2[_0x297b('0x62')]['id'],_0x11bbd2[_0x297b('0x62')][_0x297b('0x39')],_0x11bbd2['user'][_0x297b('0x6a')],_0x587349[_0x297b('0x69')]['id'],_0x11bbd2[_0x297b('0x59')]?JSON['stringify'](_0x11bbd2['body']):_0x297b('0x6b'));return respondWithRpcPromise('RejectMessage',_0x297b('0x7e'),_0x587349);}return null;})[_0x297b('0x37')](function(_0x141aa7){var _0x2cdcaf=_0x297b('0x6c')+_0x141aa7[_0x297b('0x28')][_0x297b('0x6d')];return db[_0x297b('0x6e')][_0x297b('0x42')](_0x2cdcaf,{'type':db[_0x297b('0x6f')][_0x297b('0x70')][_0x297b('0x71')],'raw':!![]})[_0x297b('0x37')](function(_0x41ea30){return _0x41ea30;});})['then'](function(_0x44dc7e){if(_0x44dc7e){_0x587349['message']['contact']=_0x44dc7e[0x0];if(!_0x11bbd2[_0x297b('0x59')][_0x297b('0x61')])return;return db[_0x297b('0x72')][_0x297b('0x57')]({'where':{'id':_0x11bbd2[_0x297b('0x59')][_0x297b('0x61')],'role':_0x297b('0x63')},'attributes':['id','name',_0x297b('0x73'),_0x297b('0x7f'),_0x297b('0x74')],'raw':!![]});}return null;})['then'](function(_0x367492){if(!_0x367492)return null;_0x587349['message'][_0x297b('0x63')]=_0x367492;return _0x587349;})[_0x297b('0x37')](function(_0x392871){if(_0x392871){_0x392871[_0x297b('0x28')]['interface']=util[_0x297b('0x5f')](_0x297b('0x77'),_0x11bbd2[_0x297b('0x62')][_0x297b('0x39')]);_0x392871[_0x297b('0x28')][_0x297b('0x78')]=_0x587349[_0x297b('0x78')];_0x392871[_0x297b('0x28')][_0x297b('0x79')]=_0x587349[_0x297b('0x78')];_0x392871['message']['event']='reject';respondWithRpcPromise(_0x297b('0x7b'),_0x297b('0x7b'),{'event':_0x297b('0x80'),'message':_0x392871['message']},client9002);return _0x587349;}return null;})['then'](respondWithResult(_0x45f47b,null))['catch'](handleError(_0x45f47b,null));};exports['status']=function(_0x5950b6,_0x131acb,_0x20d61b){if(_0x5950b6['body']['id']){delete _0x5950b6[_0x297b('0x59')]['id'];}var _0x18667a;return db[_0x297b('0x3c')]['find']({'where':{'id':_0x5950b6[_0x297b('0x56')]['id']}})[_0x297b('0x37')](handleEntityNotFound(_0x131acb,null))[_0x297b('0x37')](function(_0x17f387){if(_0x17f387){_0x18667a=_0x17f387;return db[_0x297b('0x81')][_0x297b('0x57')]({'where':{'id':_0x17f387['SmsAccountId']}});}})[_0x297b('0x37')](handleEntityNotFound(_0x131acb,null))[_0x297b('0x37')](function(_0x50c996){if(_0x50c996){logger[_0x297b('0x22')]('SmsMessage,\x20%s,\x20%s,\x20%s',_0x297b('0x2c'),_0x297b('0x82'),_0x50c996[_0x297b('0x3f')],util[_0x297b('0x83')](_0x5950b6[_0x297b('0x59')],{'showHidden':![],'depth':null}));switch(_0x50c996[_0x297b('0x3f')]){case _0x297b('0x84'):if(_0x5950b6[_0x297b('0x59')][_0x297b('0x85')]&&_0x5950b6[_0x297b('0x59')][_0x297b('0x85')]===_0x18667a[_0x297b('0x86')]){return _0x18667a[_0x297b('0x66')]({'read':!![]});}else{logger[_0x297b('0x25')](_0x297b('0x87'),_0x297b('0x2c'),_0x297b('0x84'),util[_0x297b('0x83')](_0x5950b6['body'],{'showHidden':![],'depth':null}));}break;case _0x297b('0x88'):if(_0x5950b6[_0x297b('0x59')]['MessageUUID']&&_0x5950b6[_0x297b('0x59')]['MessageUUID']===_0x18667a['messageId']&&_[_0x297b('0x89')]([_0x297b('0x8a'),_0x297b('0x8b')],_0x5950b6['body'][_0x297b('0x8c')])>=0x0){return _0x18667a['update']({'read':!![]});}else{logger[_0x297b('0x25')](_0x297b('0x87'),'status',_0x297b('0x8d'),util[_0x297b('0x83')](_0x5950b6[_0x297b('0x59')],{'showHidden':![],'depth':null}));}break;case _0x297b('0x8e'):var _0x563891=_0x5950b6[_0x297b('0x59')]['results'][0x0];if(_0x563891['status'][_0x297b('0x8f')]===_0x297b('0x90')){return _0x18667a[_0x297b('0x66')]({'read':!![]});}else{logger['error'](_0x297b('0x87'),'status','infobip',util[_0x297b('0x83')](_0x5950b6[_0x297b('0x59')],{'showHidden':![],'depth':null}));}break;}return _0x18667a;}})[_0x297b('0x37')](respondWithResult(_0x131acb,null))[_0x297b('0x2a')](handleError(_0x131acb,null));};