Built motion from commit 994c64e1.|2.6.1
[motion2.git] / server / api / whatsappMessage / whatsappMessage.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 _0x2afd=['User','internal','manual','format','SIP/%s','channel','motionChannel','event','accept','EventManager','acceptmessage','WhatsappInteraction','WhatsappInteractionId','role','RejectMessage','rejectMessage','contact','email','rejectmessage','WhatsappAccountId','received\x20delivery\x20report\x20from','inspect','messageId','MessageStatus','read','WhatsappAccount,\x20%s,\x20%s,\x20%s','twilio','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','path','sox','ejs','fs-extra','lodash','squel','jsforce','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./whatsappMessage.socket','jayson/promise','client','http','request','info','WhatsappMessage,\x20%s,\x20%s','debug','request\x20sent','stringify','error','code','message','result','catch','sendStatus','status','end','json','offset','undefined','count','set','reject','save','then','destroy','stack','name','send','index','map','WhatsappMessage','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','length','nolimit','limit','order','sort','where','pick','filter','VIRTUAL','merge','options','include','findAll','params','includeAll','find','create','body','update','describe','whatsapp-interactions','whatsapp','YYYY-MM-DD\x20HH:mm:ss','UserId','agent','get','isNil','read1stAt','interaction','user','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','QueryTypes','SELECT'];(function(_0x51942a,_0x3bd294){var _0x2ad705=function(_0x111eaf){while(--_0x111eaf){_0x51942a['push'](_0x51942a['shift']());}};_0x2ad705(++_0x3bd294);}(_0x2afd,0x1b0));var _0xd2af=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0x2afd[_0x321bb2];return _0x9c12ed;};'use strict';var emlformat=require(_0xd2af('0x0'));var rimraf=require(_0xd2af('0x1'));var zipdir=require(_0xd2af('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xd2af('0x3'));var moment=require(_0xd2af('0x4'));var BPromise=require(_0xd2af('0x5'));var Mustache=require(_0xd2af('0x6'));var util=require('util');var path=require(_0xd2af('0x7'));var sox=require(_0xd2af('0x8'));var csv=require('to-csv');var ejs=require(_0xd2af('0x9'));var fs=require('fs');var fs_extra=require(_0xd2af('0xa'));var _=require(_0xd2af('0xb'));var squel=require(_0xd2af('0xc'));var crypto=require('crypto');var jsforce=require(_0xd2af('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xd2af('0xe'));var querystring=require(_0xd2af('0xf'));var Papa=require(_0xd2af('0x10'));var Redis=require('ioredis');var authService=require(_0xd2af('0x11'));var qs=require(_0xd2af('0x12'));var as=require(_0xd2af('0x13'));var hardwareService=require(_0xd2af('0x14'));var logger=require(_0xd2af('0x15'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xd2af('0x16'));var db=require(_0xd2af('0x17'))['db'];config[_0xd2af('0x18')]=_[_0xd2af('0x19')](config['redis'],{'host':_0xd2af('0x1a'),'port':0x18eb});var socket=require(_0xd2af('0x1b'))(new Redis(config[_0xd2af('0x18')]));require(_0xd2af('0x1c'))['register'](socket);var jayson=require(_0xd2af('0x1d'));var client=jayson[_0xd2af('0x1e')][_0xd2af('0x1f')]({'port':0x232c});var client9002=jayson['client'][_0xd2af('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x52736b,_0xafeb48,_0x2534a2,_0x1fe129){return new BPromise(function(_0x33b704,_0x37d169){var _0x2da686=_0x1fe129||client;return _0x2da686[_0xd2af('0x20')](_0x52736b,_0x2534a2)['then'](function(_0x3df999){logger[_0xd2af('0x21')](_0xd2af('0x22'),_0xafeb48,'request\x20sent');logger[_0xd2af('0x23')]('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0xafeb48,_0xd2af('0x24'),JSON[_0xd2af('0x25')](_0x3df999));if(_0x3df999[_0xd2af('0x26')]){if(_0x3df999[_0xd2af('0x26')][_0xd2af('0x27')]===0x1f4){logger[_0xd2af('0x26')](_0xd2af('0x22'),_0xafeb48,_0x3df999[_0xd2af('0x26')][_0xd2af('0x28')]);return _0x37d169(_0x3df999[_0xd2af('0x26')][_0xd2af('0x28')]);}logger['error'](_0xd2af('0x22'),_0xafeb48,_0x3df999[_0xd2af('0x26')][_0xd2af('0x28')]);return _0x33b704(_0x3df999[_0xd2af('0x26')]['message']);}else{logger[_0xd2af('0x21')](_0xd2af('0x22'),_0xafeb48,_0xd2af('0x24'));_0x33b704(_0x3df999[_0xd2af('0x29')][_0xd2af('0x28')]);}})[_0xd2af('0x2a')](function(_0x3e9d53){logger[_0xd2af('0x26')](_0xd2af('0x22'),_0xafeb48,_0x3e9d53);_0x37d169(_0x3e9d53);});});}function respondWithStatusCode(_0x26cba0,_0x279489){_0x279489=_0x279489||0xcc;return function(_0x22000e){if(_0x22000e){return _0x26cba0[_0xd2af('0x2b')](_0x279489);}return _0x26cba0[_0xd2af('0x2c')](_0x279489)[_0xd2af('0x2d')]();};}function respondWithResult(_0x4a3d3e,_0x3272bb){_0x3272bb=_0x3272bb||0xc8;return function(_0x2e902b){if(_0x2e902b){return _0x4a3d3e[_0xd2af('0x2c')](_0x3272bb)[_0xd2af('0x2e')](_0x2e902b);}};}function respondWithFilteredResult(_0x3da948,_0x4fc81a){return function(_0x15ec8c){if(_0x15ec8c){var _0x386c92=typeof _0x4fc81a[_0xd2af('0x2f')]==='undefined'&&typeof _0x4fc81a['limit']===_0xd2af('0x30');var _0x1fe348=_0x15ec8c[_0xd2af('0x31')];var _0x3b7357=_0x386c92?0x0:_0x4fc81a['offset'];var _0x58a221=_0x386c92?_0x15ec8c[_0xd2af('0x31')]:_0x4fc81a[_0xd2af('0x2f')]+_0x4fc81a['limit'];var _0x3e2234;if(_0x58a221>=_0x1fe348){_0x58a221=_0x1fe348;_0x3e2234=0xc8;}else{_0x3e2234=0xce;}_0x3da948[_0xd2af('0x2c')](_0x3e2234);return _0x3da948[_0xd2af('0x32')]('Content-Range',_0x3b7357+'-'+_0x58a221+'/'+_0x1fe348)[_0xd2af('0x2e')](_0x15ec8c);}return null;};}function patchUpdates(_0xb6c582){return function(_0x389ae1){try{jsonpatch['apply'](_0x389ae1,_0xb6c582,!![]);}catch(_0x209467){return BPromise[_0xd2af('0x33')](_0x209467);}return _0x389ae1[_0xd2af('0x34')]();};}function saveUpdates(_0x2dda40,_0x1167ac){return function(_0x4661b8){if(_0x4661b8){return _0x4661b8['update'](_0x2dda40)[_0xd2af('0x35')](function(_0xa5cd36){return _0xa5cd36;});}return null;};}function removeEntity(_0x3c567e,_0x2a155f){return function(_0x2217c2){if(_0x2217c2){return _0x2217c2[_0xd2af('0x36')]()[_0xd2af('0x35')](function(){_0x3c567e['status'](0xcc)[_0xd2af('0x2d')]();});}};}function handleEntityNotFound(_0x512944,_0x2a5541){return function(_0x81c3e0){if(!_0x81c3e0){_0x512944['sendStatus'](0x194);}return _0x81c3e0;};}function handleError(_0x47a804,_0x3488a5){_0x3488a5=_0x3488a5||0x1f4;return function(_0x135e52){logger[_0xd2af('0x26')](_0x135e52[_0xd2af('0x37')]);if(_0x135e52[_0xd2af('0x38')]){delete _0x135e52['name'];}_0x47a804['status'](_0x3488a5)[_0xd2af('0x39')](_0x135e52);};}exports[_0xd2af('0x3a')]=function(_0xc267b1,_0x243d30){var _0x37a7e0={},_0x138025={},_0x3e4a74={'count':0x0,'rows':[]};var _0x4bd08d=_[_0xd2af('0x3b')](db[_0xd2af('0x3c')][_0xd2af('0x3d')],function(_0x1b968c){return{'name':_0x1b968c[_0xd2af('0x3e')],'type':_0x1b968c[_0xd2af('0x3f')][_0xd2af('0x40')]};});_0x138025[_0xd2af('0x41')]=_[_0xd2af('0x3b')](_0x4bd08d,_0xd2af('0x38'));_0x138025['query']=_[_0xd2af('0x42')](_0xc267b1[_0xd2af('0x43')]);_0x138025[_0xd2af('0x44')]=_[_0xd2af('0x45')](_0x138025[_0xd2af('0x41')],_0x138025['query']);_0x37a7e0[_0xd2af('0x46')]=_[_0xd2af('0x45')](_0x138025[_0xd2af('0x41')],qs[_0xd2af('0x47')](_0xc267b1[_0xd2af('0x43')][_0xd2af('0x47')]));_0x37a7e0[_0xd2af('0x46')]=_0x37a7e0[_0xd2af('0x46')][_0xd2af('0x48')]?_0x37a7e0[_0xd2af('0x46')]:_0x138025['model'];if(!_0xc267b1[_0xd2af('0x43')]['hasOwnProperty'](_0xd2af('0x49'))){_0x37a7e0[_0xd2af('0x4a')]=qs[_0xd2af('0x4a')](_0xc267b1[_0xd2af('0x43')][_0xd2af('0x4a')]);_0x37a7e0[_0xd2af('0x2f')]=qs['offset'](_0xc267b1[_0xd2af('0x43')]['offset']);}_0x37a7e0[_0xd2af('0x4b')]=qs[_0xd2af('0x4c')](_0xc267b1[_0xd2af('0x43')][_0xd2af('0x4c')]);_0x37a7e0[_0xd2af('0x4d')]=qs[_0xd2af('0x44')](_[_0xd2af('0x4e')](_0xc267b1[_0xd2af('0x43')],_0x138025[_0xd2af('0x44')]),_0x4bd08d);if(_0xc267b1['query'][_0xd2af('0x4f')]){_0x37a7e0[_0xd2af('0x4d')]=_['merge'](_0x37a7e0['where'],{'$or':_[_0xd2af('0x3b')](_0x4bd08d,function(_0x8ca56c){if(_0x8ca56c[_0xd2af('0x3f')]!==_0xd2af('0x50')){var _0x19301e={};_0x19301e[_0x8ca56c[_0xd2af('0x38')]]={'$like':'%'+_0xc267b1[_0xd2af('0x43')][_0xd2af('0x4f')]+'%'};return _0x19301e;}})});}_0x37a7e0=_[_0xd2af('0x51')]({},_0x37a7e0,_0xc267b1[_0xd2af('0x52')]);var _0x4ef28e={'where':_0x37a7e0[_0xd2af('0x4d')]};return db[_0xd2af('0x3c')]['count'](_0x4ef28e)['then'](function(_0x463556){_0x3e4a74[_0xd2af('0x31')]=_0x463556;if(_0xc267b1[_0xd2af('0x43')]['includeAll']){_0x37a7e0[_0xd2af('0x53')]=[{'all':!![]}];}return db[_0xd2af('0x3c')][_0xd2af('0x54')](_0x37a7e0);})[_0xd2af('0x35')](function(_0x50b173){_0x3e4a74['rows']=_0x50b173;return _0x3e4a74;})[_0xd2af('0x35')](respondWithFilteredResult(_0x243d30,_0x37a7e0))[_0xd2af('0x2a')](handleError(_0x243d30,null));};exports['show']=function(_0x4416e9,_0x258cc8){var _0xd7e145={'raw':!![],'where':{'id':_0x4416e9[_0xd2af('0x55')]['id']}},_0xb1a38e={};_0xb1a38e['model']=_[_0xd2af('0x42')](db[_0xd2af('0x3c')]['rawAttributes']);_0xb1a38e[_0xd2af('0x43')]=_[_0xd2af('0x42')](_0x4416e9[_0xd2af('0x43')]);_0xb1a38e[_0xd2af('0x44')]=_[_0xd2af('0x45')](_0xb1a38e['model'],_0xb1a38e[_0xd2af('0x43')]);_0xd7e145[_0xd2af('0x46')]=_[_0xd2af('0x45')](_0xb1a38e['model'],qs[_0xd2af('0x47')](_0x4416e9[_0xd2af('0x43')][_0xd2af('0x47')]));_0xd7e145[_0xd2af('0x46')]=_0xd7e145[_0xd2af('0x46')][_0xd2af('0x48')]?_0xd7e145['attributes']:_0xb1a38e[_0xd2af('0x41')];if(_0x4416e9[_0xd2af('0x43')][_0xd2af('0x56')]){_0xd7e145[_0xd2af('0x53')]=[{'all':!![]}];}_0xd7e145=_['merge']({},_0xd7e145,_0x4416e9['options']);return db[_0xd2af('0x3c')][_0xd2af('0x57')](_0xd7e145)[_0xd2af('0x35')](handleEntityNotFound(_0x258cc8,null))['then'](respondWithResult(_0x258cc8,null))[_0xd2af('0x2a')](handleError(_0x258cc8,null));};exports[_0xd2af('0x58')]=function(_0x582875,_0x282c69){return db[_0xd2af('0x3c')]['create'](_0x582875[_0xd2af('0x59')],{})[_0xd2af('0x35')](respondWithResult(_0x282c69,0xc9))[_0xd2af('0x2a')](handleError(_0x282c69,null));};exports[_0xd2af('0x5a')]=function(_0x3bd2fa,_0x2651f2){if(_0x3bd2fa['body']['id']){delete _0x3bd2fa['body']['id'];}return db['WhatsappMessage']['find']({'where':{'id':_0x3bd2fa[_0xd2af('0x55')]['id']}})[_0xd2af('0x35')](handleEntityNotFound(_0x2651f2,null))[_0xd2af('0x35')](saveUpdates(_0x3bd2fa['body'],null))[_0xd2af('0x35')](respondWithResult(_0x2651f2,null))['catch'](handleError(_0x2651f2,null));};exports[_0xd2af('0x36')]=function(_0x351aa1,_0x51d67a){return db[_0xd2af('0x3c')][_0xd2af('0x57')]({'where':{'id':_0x351aa1[_0xd2af('0x55')]['id']}})[_0xd2af('0x35')](handleEntityNotFound(_0x51d67a,null))[_0xd2af('0x35')](removeEntity(_0x51d67a,null))['catch'](handleError(_0x51d67a,null));};exports['describe']=function(_0x4de8bb,_0x2780bc){return db[_0xd2af('0x3c')][_0xd2af('0x5b')]()[_0xd2af('0x35')](respondWithResult(_0x2780bc,null))[_0xd2af('0x2a')](handleError(_0x2780bc,null));};var interaction_log=require(_0xd2af('0x15'))(_0xd2af('0x5c'));exports['accept']=function(_0x300d0f,_0x5f031f,_0x3994c3){var _0x761384={'agent':{},'channel':_0xd2af('0x5d')};if(_0x300d0f[_0xd2af('0x59')]['id']){delete _0x300d0f[_0xd2af('0x59')]['id'];}_0x300d0f[_0xd2af('0x59')]['read']=!![];_0x300d0f['body']['readAt']=moment()['format'](_0xd2af('0x5e'));_0x300d0f[_0xd2af('0x59')][_0xd2af('0x5f')]=_0x300d0f[_0xd2af('0x59')]['UserId']||_0x300d0f['user']['id'];_0x761384[_0xd2af('0x60')]['id']=_0x300d0f['body'][_0xd2af('0x5f')];return db[_0xd2af('0x3c')][_0xd2af('0x57')]({'where':{'id':_0x300d0f['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x5f031f,null))['then'](saveUpdates(_0x300d0f[_0xd2af('0x59')],null))['then'](function(_0x5b5b42){if(_0x5b5b42){_0x761384[_0xd2af('0x28')]=_0x5b5b42[_0xd2af('0x61')]({'plain':!![]});return db['WhatsappInteraction'][_0xd2af('0x57')]({'where':{'id':_0x5b5b42['WhatsappInteractionId']}});}return null;})[_0xd2af('0x35')](handleEntityNotFound(_0x5f031f,null))['then'](function(_0x1f6474){if(_0x1f6474){return _0x1f6474[_0xd2af('0x5a')]({'UserId':_0x300d0f[_0xd2af('0x59')][_0xd2af('0x5f')],'read1stAt':_[_0xd2af('0x62')](_0x1f6474[_0xd2af('0x63')])?moment()['format'](_0xd2af('0x5e')):undefined});}return null;})[_0xd2af('0x35')](function(_0x3fa72e){if(_0x3fa72e){_0x761384[_0xd2af('0x64')]=_0x3fa72e[_0xd2af('0x61')]({'plain':!![]});interaction_log[_0xd2af('0x21')]('[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x300d0f[_0xd2af('0x65')]['id'],_0x300d0f[_0xd2af('0x65')][_0xd2af('0x38')],_0x300d0f[_0xd2af('0x65')]['role'],_0x761384[_0xd2af('0x64')]['id'],_0x300d0f[_0xd2af('0x59')]?JSON[_0xd2af('0x25')](_0x300d0f[_0xd2af('0x59')]):'null');return respondWithRpcPromise('AcceptMessage','acceptMessage',_0x761384);}return null;})[_0xd2af('0x35')](function(_0x4a6e35){var _0x19b6c4=_0xd2af('0x66')+_0x4a6e35[_0xd2af('0x28')][_0xd2af('0x67')];return db[_0xd2af('0x68')][_0xd2af('0x43')](_0x19b6c4,{'type':db[_0xd2af('0x69')][_0xd2af('0x6a')][_0xd2af('0x6b')],'raw':!![]})[_0xd2af('0x35')](function(_0x4cf802){return _0x4cf802;});})[_0xd2af('0x35')](function(_0x4a0034){if(_0x4a0034){_0x761384[_0xd2af('0x28')]['contact']=_0x4a0034[0x0];if(!_0x300d0f[_0xd2af('0x59')][_0xd2af('0x5f')])return;return db[_0xd2af('0x6c')]['find']({'where':{'id':_0x300d0f['body'][_0xd2af('0x5f')],'role':_0xd2af('0x60')},'attributes':['id',_0xd2af('0x38'),'fullname','email',_0xd2af('0x6d')],'raw':!![]});}return null;})[_0xd2af('0x35')](function(_0x43923b){if(!_0x43923b)return null;_0x761384['message'][_0xd2af('0x60')]=_0x43923b;return _0x761384;})['then'](function(_0xde09b6){if(_0xde09b6){if(_0x300d0f[_0xd2af('0x59')][_0xd2af('0x6e')]){_0x761384[_0xd2af('0x28')]['interface']=util[_0xd2af('0x6f')](_0xd2af('0x70'),_0x300d0f['user'][_0xd2af('0x38')]);_0x761384[_0xd2af('0x28')]['channel']=_0x761384[_0xd2af('0x71')];_0x761384[_0xd2af('0x28')][_0xd2af('0x72')]=_0x761384[_0xd2af('0x71')];_0x761384['message'][_0xd2af('0x73')]=_0xd2af('0x74');return respondWithRpcPromise(_0xd2af('0x75'),_0xd2af('0x75'),{'event':_0xd2af('0x76'),'message':_0x761384[_0xd2af('0x28')]},client9002)[_0xd2af('0x35')](function(){return _0x761384;});}return _0x761384;}return null;})[_0xd2af('0x35')](respondWithResult(_0x5f031f,null))[_0xd2af('0x2a')](handleError(_0x5f031f,null));};var interaction_log=require('../../config/logger')(_0xd2af('0x5c'));exports[_0xd2af('0x33')]=function(_0x4766b5,_0xcd8473,_0x2260ca){var _0x2d36ce={'agent':{},'channel':_0xd2af('0x5d')};if(_0x4766b5[_0xd2af('0x59')]['id']){delete _0x4766b5[_0xd2af('0x59')]['id'];}_0x4766b5[_0xd2af('0x59')][_0xd2af('0x5f')]=_0x4766b5['body'][_0xd2af('0x5f')]||_0x4766b5['user']['id'];_0x2d36ce[_0xd2af('0x60')]['id']=_0x4766b5['body']['UserId'];return db[_0xd2af('0x3c')][_0xd2af('0x57')]({'where':{'id':_0x4766b5[_0xd2af('0x55')]['id'],'UserId':null}})[_0xd2af('0x35')](handleEntityNotFound(_0xcd8473,null))[_0xd2af('0x35')](function(_0xf2d4af){if(_0xf2d4af){_0x2d36ce['message']=_0xf2d4af[_0xd2af('0x61')]({'plain':!![]});return db[_0xd2af('0x77')]['find']({'where':{'id':_0xf2d4af[_0xd2af('0x78')]}});}return null;})['then'](handleEntityNotFound(_0xcd8473,null))[_0xd2af('0x35')](function(_0x1b79d4){if(_0x1b79d4){_0x2d36ce[_0xd2af('0x64')]=_0x1b79d4[_0xd2af('0x61')]({'plain':!![]});interaction_log['info']('[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x4766b5[_0xd2af('0x65')]['id'],_0x4766b5[_0xd2af('0x65')][_0xd2af('0x38')],_0x4766b5[_0xd2af('0x65')][_0xd2af('0x79')],_0x2d36ce[_0xd2af('0x64')]['id'],_0x4766b5[_0xd2af('0x59')]?JSON[_0xd2af('0x25')](_0x4766b5[_0xd2af('0x59')]):'null');return respondWithRpcPromise(_0xd2af('0x7a'),_0xd2af('0x7b'),_0x2d36ce);}return null;})['then'](function(_0x3d9a61){var _0x2cd1d4=_0xd2af('0x66')+_0x3d9a61[_0xd2af('0x28')][_0xd2af('0x67')];return db[_0xd2af('0x68')][_0xd2af('0x43')](_0x2cd1d4,{'type':db[_0xd2af('0x69')][_0xd2af('0x6a')][_0xd2af('0x6b')],'raw':!![]})['then'](function(_0x548557){return _0x548557;});})['then'](function(_0x182d7d){if(_0x182d7d){_0x2d36ce[_0xd2af('0x28')][_0xd2af('0x7c')]=_0x182d7d[0x0];if(!_0x4766b5[_0xd2af('0x59')][_0xd2af('0x5f')])return;return db[_0xd2af('0x6c')][_0xd2af('0x57')]({'where':{'id':_0x4766b5['body'][_0xd2af('0x5f')],'role':'agent'},'attributes':['id',_0xd2af('0x38'),'fullname',_0xd2af('0x7d'),_0xd2af('0x6d')],'raw':!![]});}return null;})[_0xd2af('0x35')](function(_0x2dcc59){if(!_0x2dcc59)return null;_0x2d36ce[_0xd2af('0x28')][_0xd2af('0x60')]=_0x2dcc59;return _0x2d36ce;})[_0xd2af('0x35')](function(_0x7d2486){if(_0x7d2486){_0x7d2486[_0xd2af('0x28')]['interface']=util['format']('SIP/%s',_0x4766b5[_0xd2af('0x65')][_0xd2af('0x38')]);_0x7d2486[_0xd2af('0x28')]['channel']=_0x2d36ce[_0xd2af('0x71')];_0x7d2486[_0xd2af('0x28')]['motionChannel']=_0x2d36ce[_0xd2af('0x71')];_0x7d2486[_0xd2af('0x28')][_0xd2af('0x73')]=_0xd2af('0x33');respondWithRpcPromise(_0xd2af('0x75'),_0xd2af('0x75'),{'event':_0xd2af('0x7e'),'message':_0x7d2486[_0xd2af('0x28')]},client9002);return _0x2d36ce;}return null;})[_0xd2af('0x35')](respondWithResult(_0xcd8473,null))[_0xd2af('0x2a')](handleError(_0xcd8473,null));};exports['status']=function(_0x591f13,_0x14ec3f,_0x4b28a0){if(_0x591f13['body']['id']){delete _0x591f13[_0xd2af('0x59')]['id'];}var _0x2d1c5d;return db['WhatsappMessage'][_0xd2af('0x57')]({'where':{'id':_0x591f13['params']['id']}})[_0xd2af('0x35')](handleEntityNotFound(_0x14ec3f,null))['then'](function(_0xb6a2cf){if(_0xb6a2cf){_0x2d1c5d=_0xb6a2cf;return db['WhatsappAccount'][_0xd2af('0x57')]({'where':{'id':_0xb6a2cf[_0xd2af('0x7f')]}});}})[_0xd2af('0x35')](handleEntityNotFound(_0x14ec3f,null))['then'](function(_0x11c9a8){if(_0x11c9a8){logger[_0xd2af('0x23')]('WhatsppMessage,\x20%s,\x20%s,\x20%s',_0xd2af('0x2c'),_0xd2af('0x80'),_0x11c9a8[_0xd2af('0x3f')],util[_0xd2af('0x81')](_0x591f13[_0xd2af('0x59')],{'showHidden':![],'depth':null}));switch(_0x11c9a8[_0xd2af('0x3f')]){case'twilio':if(_0x591f13[_0xd2af('0x59')]['MessageSid']&&_0x591f13[_0xd2af('0x59')]['MessageSid']===_0x2d1c5d[_0xd2af('0x82')]&&_0x591f13[_0xd2af('0x59')]['MessageStatus']&&_0x591f13[_0xd2af('0x59')][_0xd2af('0x83')]===_0xd2af('0x84')){return _0x2d1c5d[_0xd2af('0x5a')]({'read':!![]});}else{logger[_0xd2af('0x26')](_0xd2af('0x85'),_0xd2af('0x2c'),_0xd2af('0x86'),util[_0xd2af('0x81')](_0x591f13['body'],{'showHidden':![],'depth':null}));}break;}return _0x2d1c5d;}})[_0xd2af('0x35')](respondWithResult(_0x14ec3f,null))[_0xd2af('0x2a')](handleError(_0x14ec3f,null));};