37eb68b7db7a8941ef5ee3e62aa3755fb6a8d995
[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 _0x5f05=['keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','include','findAll','rows','show','params','find','create','body','update','destroy','describe','../../config/logger','whatsapp-interactions','accept','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','WhatsappInteraction','WhatsappInteractionId','isNil','read1stAt','interaction','get','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','user','role','null','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','Sequelize','SELECT','contact','User','agent','email','internal','manual','interface','SIP/%s','channel','motionChannel','EventManager','acceptmessage','[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','ContactId','QueryTypes','fullname','WhatsappAccountId','WhatsppMessage,\x20%s,\x20%s,\x20%s','received\x20delivery\x20report\x20from','inspect','twilio','MessageStatus','WhatsappAccount,\x20%s,\x20%s,\x20%s','eml-format','rimraf','zip-dir','fast-json-patch','mustache','util','sox','to-csv','lodash','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','jayson/promise','client','http','request','then','WhatsappMessage,\x20%s,\x20%s','debug','WhatsappMessage,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','message','info','catch','end','status','json','offset','undefined','count','limit','Content-Range','reject','sendStatus','name','send','map','WhatsappMessage','rawAttributes','fieldName','type','key','query'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x5f05,0x153));var _0x55f0=function(_0x1e9129,_0x507a58){_0x1e9129=_0x1e9129-0x0;var _0x2996f1=_0x5f05[_0x1e9129];return _0x2996f1;};'use strict';var emlformat=require(_0x55f0('0x0'));var rimraf=require(_0x55f0('0x1'));var zipdir=require(_0x55f0('0x2'));var jsonpatch=require(_0x55f0('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x55f0('0x4'));var util=require(_0x55f0('0x5'));var path=require('path');var sox=require(_0x55f0('0x6'));var csv=require(_0x55f0('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x55f0('0x8'));var squel=require(_0x55f0('0x9'));var crypto=require(_0x55f0('0xa'));var jsforce=require(_0x55f0('0xb'));var deskjs=require(_0x55f0('0xc'));var toCsv=require(_0x55f0('0x7'));var querystring=require(_0x55f0('0xd'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x55f0('0xe'));var qs=require('../../components/parsers/qs');var as=require(_0x55f0('0xf'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x55f0('0x10'));var utils=require(_0x55f0('0x11'));var config=require(_0x55f0('0x12'));var licenseUtil=require(_0x55f0('0x13'));var db=require(_0x55f0('0x14'))['db'];config[_0x55f0('0x15')]=_[_0x55f0('0x16')](config[_0x55f0('0x15')],{'host':'localhost','port':0x18eb});var socket=require(_0x55f0('0x17'))(new Redis(config[_0x55f0('0x15')]));require('./whatsappMessage.socket')['register'](socket);var jayson=require(_0x55f0('0x18'));var client=jayson[_0x55f0('0x19')][_0x55f0('0x1a')]({'port':0x232c});var client9002=jayson[_0x55f0('0x19')]['http']({'port':0x232a});function respondWithRpcPromise(_0x57cef1,_0x50f7d5,_0x1be688,_0x474776){return new BPromise(function(_0x10d0ac,_0x11d189){var _0x158702=_0x474776||client;return _0x158702[_0x55f0('0x1b')](_0x57cef1,_0x1be688)[_0x55f0('0x1c')](function(_0x371a57){logger['info'](_0x55f0('0x1d'),_0x50f7d5,'request\x20sent');logger[_0x55f0('0x1e')](_0x55f0('0x1f'),_0x50f7d5,_0x55f0('0x20'),JSON[_0x55f0('0x21')](_0x371a57));if(_0x371a57[_0x55f0('0x22')]){if(_0x371a57[_0x55f0('0x22')]['code']===0x1f4){logger[_0x55f0('0x22')]('WhatsappMessage,\x20%s,\x20%s',_0x50f7d5,_0x371a57[_0x55f0('0x22')][_0x55f0('0x23')]);return _0x11d189(_0x371a57[_0x55f0('0x22')][_0x55f0('0x23')]);}logger['error'](_0x55f0('0x1d'),_0x50f7d5,_0x371a57[_0x55f0('0x22')]['message']);return _0x10d0ac(_0x371a57[_0x55f0('0x22')][_0x55f0('0x23')]);}else{logger[_0x55f0('0x24')](_0x55f0('0x1d'),_0x50f7d5,_0x55f0('0x20'));_0x10d0ac(_0x371a57['result'][_0x55f0('0x23')]);}})[_0x55f0('0x25')](function(_0x347a95){logger[_0x55f0('0x22')]('WhatsappMessage,\x20%s,\x20%s',_0x50f7d5,_0x347a95);_0x11d189(_0x347a95);});});}function respondWithStatusCode(_0x3ad0ea,_0x5e3db7){_0x5e3db7=_0x5e3db7||0xcc;return function(_0x5b42e2){if(_0x5b42e2){return _0x3ad0ea['sendStatus'](_0x5e3db7);}return _0x3ad0ea['status'](_0x5e3db7)[_0x55f0('0x26')]();};}function respondWithResult(_0x352a0d,_0x50d116){_0x50d116=_0x50d116||0xc8;return function(_0x54099d){if(_0x54099d){return _0x352a0d[_0x55f0('0x27')](_0x50d116)[_0x55f0('0x28')](_0x54099d);}};}function respondWithFilteredResult(_0x59552f,_0x171912){return function(_0x5e2bed){if(_0x5e2bed){var _0x2edb94=typeof _0x171912[_0x55f0('0x29')]===_0x55f0('0x2a')&&typeof _0x171912['limit']===_0x55f0('0x2a');var _0x4cad02=_0x5e2bed['count'];var _0x21ebd2=_0x2edb94?0x0:_0x171912['offset'];var _0x219457=_0x2edb94?_0x5e2bed[_0x55f0('0x2b')]:_0x171912[_0x55f0('0x29')]+_0x171912[_0x55f0('0x2c')];var _0x33a666;if(_0x219457>=_0x4cad02){_0x219457=_0x4cad02;_0x33a666=0xc8;}else{_0x33a666=0xce;}_0x59552f[_0x55f0('0x27')](_0x33a666);return _0x59552f['set'](_0x55f0('0x2d'),_0x21ebd2+'-'+_0x219457+'/'+_0x4cad02)[_0x55f0('0x28')](_0x5e2bed);}return null;};}function patchUpdates(_0x97868c){return function(_0x1f8fc1){try{jsonpatch['apply'](_0x1f8fc1,_0x97868c,!![]);}catch(_0x38feb3){return BPromise[_0x55f0('0x2e')](_0x38feb3);}return _0x1f8fc1['save']();};}function saveUpdates(_0x1303b2,_0x22157d){return function(_0x56cdc5){if(_0x56cdc5){return _0x56cdc5['update'](_0x1303b2)['then'](function(_0x2f035c){return _0x2f035c;});}return null;};}function removeEntity(_0x3d68f2,_0x3193f5){return function(_0x1d02fd){if(_0x1d02fd){return _0x1d02fd['destroy']()[_0x55f0('0x1c')](function(){_0x3d68f2[_0x55f0('0x27')](0xcc)[_0x55f0('0x26')]();});}};}function handleEntityNotFound(_0xddba7c,_0x11fcd3){return function(_0x489133){if(!_0x489133){_0xddba7c[_0x55f0('0x2f')](0x194);}return _0x489133;};}function handleError(_0x5ee1a4,_0x1d0e32){_0x1d0e32=_0x1d0e32||0x1f4;return function(_0x1256d0){logger[_0x55f0('0x22')](_0x1256d0['stack']);if(_0x1256d0[_0x55f0('0x30')]){delete _0x1256d0[_0x55f0('0x30')];}_0x5ee1a4['status'](_0x1d0e32)[_0x55f0('0x31')](_0x1256d0);};}exports['index']=function(_0x4b4bc8,_0x1354d5){var _0xb84fd6={},_0x51fd22={},_0x4e4aef={'count':0x0,'rows':[]};var _0x2554cf=_[_0x55f0('0x32')](db[_0x55f0('0x33')][_0x55f0('0x34')],function(_0x70bdbf){return{'name':_0x70bdbf[_0x55f0('0x35')],'type':_0x70bdbf[_0x55f0('0x36')][_0x55f0('0x37')]};});_0x51fd22['model']=_['map'](_0x2554cf,_0x55f0('0x30'));_0x51fd22[_0x55f0('0x38')]=_[_0x55f0('0x39')](_0x4b4bc8[_0x55f0('0x38')]);_0x51fd22[_0x55f0('0x3a')]=_[_0x55f0('0x3b')](_0x51fd22[_0x55f0('0x3c')],_0x51fd22[_0x55f0('0x38')]);_0xb84fd6[_0x55f0('0x3d')]=_[_0x55f0('0x3b')](_0x51fd22[_0x55f0('0x3c')],qs['fields'](_0x4b4bc8['query'][_0x55f0('0x3e')]));_0xb84fd6['attributes']=_0xb84fd6['attributes'][_0x55f0('0x3f')]?_0xb84fd6[_0x55f0('0x3d')]:_0x51fd22['model'];if(!_0x4b4bc8[_0x55f0('0x38')][_0x55f0('0x40')](_0x55f0('0x41'))){_0xb84fd6[_0x55f0('0x2c')]=qs['limit'](_0x4b4bc8['query'][_0x55f0('0x2c')]);_0xb84fd6['offset']=qs['offset'](_0x4b4bc8[_0x55f0('0x38')][_0x55f0('0x29')]);}_0xb84fd6[_0x55f0('0x42')]=qs[_0x55f0('0x43')](_0x4b4bc8[_0x55f0('0x38')][_0x55f0('0x43')]);_0xb84fd6[_0x55f0('0x44')]=qs[_0x55f0('0x3a')](_[_0x55f0('0x45')](_0x4b4bc8[_0x55f0('0x38')],_0x51fd22[_0x55f0('0x3a')]),_0x2554cf);if(_0x4b4bc8[_0x55f0('0x38')][_0x55f0('0x46')]){_0xb84fd6[_0x55f0('0x44')]=_[_0x55f0('0x47')](_0xb84fd6[_0x55f0('0x44')],{'$or':_[_0x55f0('0x32')](_0x2554cf,function(_0xdda70d){if(_0xdda70d[_0x55f0('0x36')]!==_0x55f0('0x48')){var _0x49896f={};_0x49896f[_0xdda70d[_0x55f0('0x30')]]={'$like':'%'+_0x4b4bc8[_0x55f0('0x38')]['filter']+'%'};return _0x49896f;}})});}_0xb84fd6=_[_0x55f0('0x47')]({},_0xb84fd6,_0x4b4bc8[_0x55f0('0x49')]);var _0x20ab82={'where':_0xb84fd6['where']};return db[_0x55f0('0x33')][_0x55f0('0x2b')](_0x20ab82)[_0x55f0('0x1c')](function(_0x57d406){_0x4e4aef[_0x55f0('0x2b')]=_0x57d406;if(_0x4b4bc8['query']['includeAll']){_0xb84fd6[_0x55f0('0x4a')]=[{'all':!![]}];}return db[_0x55f0('0x33')][_0x55f0('0x4b')](_0xb84fd6);})['then'](function(_0x5690b8){_0x4e4aef[_0x55f0('0x4c')]=_0x5690b8;return _0x4e4aef;})[_0x55f0('0x1c')](respondWithFilteredResult(_0x1354d5,_0xb84fd6))[_0x55f0('0x25')](handleError(_0x1354d5,null));};exports[_0x55f0('0x4d')]=function(_0xd827ec,_0x5d4243){var _0x2c2ffe={'raw':!![],'where':{'id':_0xd827ec[_0x55f0('0x4e')]['id']}},_0x5c9329={};_0x5c9329[_0x55f0('0x3c')]=_['keys'](db[_0x55f0('0x33')]['rawAttributes']);_0x5c9329[_0x55f0('0x38')]=_[_0x55f0('0x39')](_0xd827ec[_0x55f0('0x38')]);_0x5c9329['filters']=_[_0x55f0('0x3b')](_0x5c9329['model'],_0x5c9329[_0x55f0('0x38')]);_0x2c2ffe[_0x55f0('0x3d')]=_[_0x55f0('0x3b')](_0x5c9329['model'],qs[_0x55f0('0x3e')](_0xd827ec['query'][_0x55f0('0x3e')]));_0x2c2ffe[_0x55f0('0x3d')]=_0x2c2ffe[_0x55f0('0x3d')][_0x55f0('0x3f')]?_0x2c2ffe[_0x55f0('0x3d')]:_0x5c9329['model'];if(_0xd827ec['query']['includeAll']){_0x2c2ffe[_0x55f0('0x4a')]=[{'all':!![]}];}_0x2c2ffe=_['merge']({},_0x2c2ffe,_0xd827ec[_0x55f0('0x49')]);return db[_0x55f0('0x33')][_0x55f0('0x4f')](_0x2c2ffe)[_0x55f0('0x1c')](handleEntityNotFound(_0x5d4243,null))['then'](respondWithResult(_0x5d4243,null))[_0x55f0('0x25')](handleError(_0x5d4243,null));};exports[_0x55f0('0x50')]=function(_0x495ba,_0x92acfd){return db[_0x55f0('0x33')][_0x55f0('0x50')](_0x495ba[_0x55f0('0x51')],{})[_0x55f0('0x1c')](respondWithResult(_0x92acfd,0xc9))[_0x55f0('0x25')](handleError(_0x92acfd,null));};exports[_0x55f0('0x52')]=function(_0x207064,_0x4914ce){if(_0x207064[_0x55f0('0x51')]['id']){delete _0x207064[_0x55f0('0x51')]['id'];}return db[_0x55f0('0x33')][_0x55f0('0x4f')]({'where':{'id':_0x207064['params']['id']}})[_0x55f0('0x1c')](handleEntityNotFound(_0x4914ce,null))['then'](saveUpdates(_0x207064[_0x55f0('0x51')],null))[_0x55f0('0x1c')](respondWithResult(_0x4914ce,null))[_0x55f0('0x25')](handleError(_0x4914ce,null));};exports[_0x55f0('0x53')]=function(_0x22e24b,_0x39b7f0){return db[_0x55f0('0x33')][_0x55f0('0x4f')]({'where':{'id':_0x22e24b[_0x55f0('0x4e')]['id']}})['then'](handleEntityNotFound(_0x39b7f0,null))[_0x55f0('0x1c')](removeEntity(_0x39b7f0,null))[_0x55f0('0x25')](handleError(_0x39b7f0,null));};exports[_0x55f0('0x54')]=function(_0x1a1afb,_0x3dd4a6){return db[_0x55f0('0x33')]['describe']()[_0x55f0('0x1c')](respondWithResult(_0x3dd4a6,null))[_0x55f0('0x25')](handleError(_0x3dd4a6,null));};var interaction_log=require(_0x55f0('0x55'))(_0x55f0('0x56'));exports[_0x55f0('0x57')]=function(_0x5bcd67,_0x19a309,_0x427f05){var _0x288ebe={'agent':{},'channel':'whatsapp'};if(_0x5bcd67[_0x55f0('0x51')]['id']){delete _0x5bcd67['body']['id'];}_0x5bcd67[_0x55f0('0x51')][_0x55f0('0x58')]=!![];_0x5bcd67[_0x55f0('0x51')][_0x55f0('0x59')]=moment()[_0x55f0('0x5a')](_0x55f0('0x5b'));_0x5bcd67[_0x55f0('0x51')][_0x55f0('0x5c')]=_0x5bcd67[_0x55f0('0x51')]['UserId']||_0x5bcd67['user']['id'];_0x288ebe['agent']['id']=_0x5bcd67[_0x55f0('0x51')][_0x55f0('0x5c')];return db[_0x55f0('0x33')][_0x55f0('0x4f')]({'where':{'id':_0x5bcd67[_0x55f0('0x4e')]['id'],'UserId':null}})[_0x55f0('0x1c')](handleEntityNotFound(_0x19a309,null))[_0x55f0('0x1c')](saveUpdates(_0x5bcd67['body'],null))[_0x55f0('0x1c')](function(_0x4a1ef0){if(_0x4a1ef0){_0x288ebe['message']=_0x4a1ef0['get']({'plain':!![]});return db[_0x55f0('0x5d')]['find']({'where':{'id':_0x4a1ef0[_0x55f0('0x5e')]}});}return null;})[_0x55f0('0x1c')](handleEntityNotFound(_0x19a309,null))[_0x55f0('0x1c')](function(_0x1b5784){if(_0x1b5784){return _0x1b5784[_0x55f0('0x52')]({'UserId':_0x5bcd67[_0x55f0('0x51')][_0x55f0('0x5c')],'read1stAt':_[_0x55f0('0x5f')](_0x1b5784[_0x55f0('0x60')])?moment()[_0x55f0('0x5a')]('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})[_0x55f0('0x1c')](function(_0x33ffae){if(_0x33ffae){_0x288ebe[_0x55f0('0x61')]=_0x33ffae[_0x55f0('0x62')]({'plain':!![]});interaction_log[_0x55f0('0x24')](_0x55f0('0x63'),_0x5bcd67[_0x55f0('0x64')]['id'],_0x5bcd67[_0x55f0('0x64')][_0x55f0('0x30')],_0x5bcd67[_0x55f0('0x64')][_0x55f0('0x65')],_0x288ebe[_0x55f0('0x61')]['id'],_0x5bcd67[_0x55f0('0x51')]?JSON['stringify'](_0x5bcd67[_0x55f0('0x51')]):_0x55f0('0x66'));return respondWithRpcPromise('AcceptMessage','acceptMessage',_0x288ebe);}return null;})['then'](function(_0x193940){var _0x57ee98=_0x55f0('0x67')+_0x193940[_0x55f0('0x23')]['ContactId'];return db[_0x55f0('0x68')][_0x55f0('0x38')](_0x57ee98,{'type':db[_0x55f0('0x69')]['QueryTypes'][_0x55f0('0x6a')],'raw':!![]})[_0x55f0('0x1c')](function(_0x4c8a8d){return _0x4c8a8d;});})[_0x55f0('0x1c')](function(_0x3045ab){if(_0x3045ab){_0x288ebe['message'][_0x55f0('0x6b')]=_0x3045ab[0x0];if(!_0x5bcd67[_0x55f0('0x51')][_0x55f0('0x5c')])return;return db[_0x55f0('0x6c')][_0x55f0('0x4f')]({'where':{'id':_0x5bcd67[_0x55f0('0x51')][_0x55f0('0x5c')],'role':_0x55f0('0x6d')},'attributes':['id',_0x55f0('0x30'),'fullname',_0x55f0('0x6e'),_0x55f0('0x6f')],'raw':!![]});}return null;})['then'](function(_0x1e9594){if(!_0x1e9594)return null;_0x288ebe['message']['agent']=_0x1e9594;return _0x288ebe;})['then'](function(_0xb4f6b8){if(_0xb4f6b8){if(_0x5bcd67['body'][_0x55f0('0x70')]){_0x288ebe[_0x55f0('0x23')][_0x55f0('0x71')]=util[_0x55f0('0x5a')](_0x55f0('0x72'),_0x5bcd67[_0x55f0('0x64')][_0x55f0('0x30')]);_0x288ebe['message'][_0x55f0('0x73')]=_0x288ebe[_0x55f0('0x73')];_0x288ebe[_0x55f0('0x23')][_0x55f0('0x74')]=_0x288ebe[_0x55f0('0x73')];_0x288ebe['message']['event']=_0x55f0('0x57');return respondWithRpcPromise(_0x55f0('0x75'),'EventManager',{'event':_0x55f0('0x76'),'message':_0x288ebe[_0x55f0('0x23')]},client9002)[_0x55f0('0x1c')](function(){return _0x288ebe;});}return _0x288ebe;}return null;})['then'](respondWithResult(_0x19a309,null))['catch'](handleError(_0x19a309,null));};var interaction_log=require(_0x55f0('0x55'))(_0x55f0('0x56'));exports[_0x55f0('0x2e')]=function(_0x2bcf07,_0x19fd06,_0x200872){var _0x25f084={'agent':{},'channel':'whatsapp'};if(_0x2bcf07[_0x55f0('0x51')]['id']){delete _0x2bcf07[_0x55f0('0x51')]['id'];}_0x2bcf07[_0x55f0('0x51')][_0x55f0('0x5c')]=_0x2bcf07[_0x55f0('0x51')][_0x55f0('0x5c')]||_0x2bcf07[_0x55f0('0x64')]['id'];_0x25f084[_0x55f0('0x6d')]['id']=_0x2bcf07[_0x55f0('0x51')][_0x55f0('0x5c')];return db[_0x55f0('0x33')][_0x55f0('0x4f')]({'where':{'id':_0x2bcf07['params']['id'],'UserId':null}})[_0x55f0('0x1c')](handleEntityNotFound(_0x19fd06,null))['then'](function(_0x187194){if(_0x187194){_0x25f084['message']=_0x187194[_0x55f0('0x62')]({'plain':!![]});return db[_0x55f0('0x5d')][_0x55f0('0x4f')]({'where':{'id':_0x187194[_0x55f0('0x5e')]}});}return null;})[_0x55f0('0x1c')](handleEntityNotFound(_0x19fd06,null))[_0x55f0('0x1c')](function(_0x388853){if(_0x388853){_0x25f084[_0x55f0('0x61')]=_0x388853[_0x55f0('0x62')]({'plain':!![]});interaction_log['info'](_0x55f0('0x77'),_0x2bcf07['user']['id'],_0x2bcf07[_0x55f0('0x64')][_0x55f0('0x30')],_0x2bcf07[_0x55f0('0x64')][_0x55f0('0x65')],_0x25f084[_0x55f0('0x61')]['id'],_0x2bcf07[_0x55f0('0x51')]?JSON[_0x55f0('0x21')](_0x2bcf07['body']):'null');return respondWithRpcPromise(_0x55f0('0x78'),_0x55f0('0x79'),_0x25f084);}return null;})[_0x55f0('0x1c')](function(_0x5e8da6){var _0x201725=_0x55f0('0x67')+_0x5e8da6[_0x55f0('0x23')][_0x55f0('0x7a')];return db[_0x55f0('0x68')][_0x55f0('0x38')](_0x201725,{'type':db[_0x55f0('0x69')][_0x55f0('0x7b')][_0x55f0('0x6a')],'raw':!![]})[_0x55f0('0x1c')](function(_0x3d080e){return _0x3d080e;});})[_0x55f0('0x1c')](function(_0x278ff3){if(_0x278ff3){_0x25f084[_0x55f0('0x23')][_0x55f0('0x6b')]=_0x278ff3[0x0];if(!_0x2bcf07[_0x55f0('0x51')][_0x55f0('0x5c')])return;return db['User'][_0x55f0('0x4f')]({'where':{'id':_0x2bcf07[_0x55f0('0x51')][_0x55f0('0x5c')],'role':_0x55f0('0x6d')},'attributes':['id',_0x55f0('0x30'),_0x55f0('0x7c'),_0x55f0('0x6e'),'internal'],'raw':!![]});}return null;})[_0x55f0('0x1c')](function(_0x1edbf8){if(!_0x1edbf8)return null;_0x25f084[_0x55f0('0x23')][_0x55f0('0x6d')]=_0x1edbf8;return _0x25f084;})[_0x55f0('0x1c')](function(_0xfd1198){if(_0xfd1198){_0xfd1198[_0x55f0('0x23')][_0x55f0('0x71')]=util[_0x55f0('0x5a')](_0x55f0('0x72'),_0x2bcf07[_0x55f0('0x64')][_0x55f0('0x30')]);_0xfd1198['message'][_0x55f0('0x73')]=_0x25f084['channel'];_0xfd1198[_0x55f0('0x23')][_0x55f0('0x74')]=_0x25f084[_0x55f0('0x73')];_0xfd1198[_0x55f0('0x23')]['event']=_0x55f0('0x2e');respondWithRpcPromise(_0x55f0('0x75'),_0x55f0('0x75'),{'event':'rejectmessage','message':_0xfd1198[_0x55f0('0x23')]},client9002);return _0x25f084;}return null;})['then'](respondWithResult(_0x19fd06,null))[_0x55f0('0x25')](handleError(_0x19fd06,null));};exports[_0x55f0('0x27')]=function(_0x2429b4,_0x9ecb3a,_0x258acb){if(_0x2429b4[_0x55f0('0x51')]['id']){delete _0x2429b4['body']['id'];}var _0x470e20;return db[_0x55f0('0x33')][_0x55f0('0x4f')]({'where':{'id':_0x2429b4[_0x55f0('0x4e')]['id']}})[_0x55f0('0x1c')](handleEntityNotFound(_0x9ecb3a,null))[_0x55f0('0x1c')](function(_0x37f190){if(_0x37f190){_0x470e20=_0x37f190;return db['WhatsappAccount'][_0x55f0('0x4f')]({'where':{'id':_0x37f190[_0x55f0('0x7d')]}});}})[_0x55f0('0x1c')](handleEntityNotFound(_0x9ecb3a,null))[_0x55f0('0x1c')](function(_0x12d2a4){if(_0x12d2a4){logger['debug'](_0x55f0('0x7e'),'status',_0x55f0('0x7f'),_0x12d2a4['type'],util[_0x55f0('0x80')](_0x2429b4[_0x55f0('0x51')],{'showHidden':![],'depth':null}));switch(_0x12d2a4['type']){case _0x55f0('0x81'):if(_0x2429b4[_0x55f0('0x51')]['MessageSid']&&_0x2429b4[_0x55f0('0x51')]['MessageSid']===_0x470e20['messageId']&&_0x2429b4[_0x55f0('0x51')][_0x55f0('0x82')]&&_0x2429b4[_0x55f0('0x51')][_0x55f0('0x82')]===_0x55f0('0x58')){return _0x470e20['update']({'read':!![]});}else{logger[_0x55f0('0x22')](_0x55f0('0x83'),_0x55f0('0x27'),_0x55f0('0x81'),util[_0x55f0('0x80')](_0x2429b4['body'],{'showHidden':![],'depth':null}));}break;}return _0x470e20;}})[_0x55f0('0x1c')](respondWithResult(_0x9ecb3a,null))[_0x55f0('0x25')](handleError(_0x9ecb3a,null));};