Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / whatsappMessage / whatsappMessage.controller.js
index a367df2..b608380 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa9ea=['inspect','messageId','MessageStatus','WhatsappAccount,\x20%s,\x20%s,\x20%s','twilio','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','to-csv','ejs','fs-extra','lodash','squel','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','defaults','localhost','redis','./whatsappMessage.socket','jayson/promise','client','http','request','then','request\x20sent','WhatsappMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','WhatsappMessage,\x20%s,\x20%s','info','result','sendStatus','status','end','json','offset','undefined','count','set','Content-Range','reject','destroy','stack','name','send','map','WhatsappMessage','rawAttributes','type','key','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','merge','filter','includeAll','include','findAll','rows','show','params','options','find','create','body','catch','update','describe','whatsapp-interactions','accept','whatsapp','read','UserId','user','agent','get','WhatsappInteraction','WhatsappInteractionId','isNil','read1stAt','format','YYYY-MM-DD\x20HH:mm:ss','interaction','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','Sequelize','QueryTypes','SELECT','contact','User','fullname','email','internal','manual','interface','SIP/%s','channel','motionChannel','event','EventManager','acceptmessage','[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','rejectmessage','WhatsappAccount','WhatsppMessage,\x20%s,\x20%s,\x20%s','received\x20delivery\x20report\x20from'];(function(_0x13ce0c,_0x3f2a0d){var _0x4388fb=function(_0x27db4b){while(--_0x27db4b){_0x13ce0c['push'](_0x13ce0c['shift']());}};_0x4388fb(++_0x3f2a0d);}(_0xa9ea,0x11d));var _0xaa9e=function(_0x2bf1d6,_0x410efd){_0x2bf1d6=_0x2bf1d6-0x0;var _0x1be08a=_0xa9ea[_0x2bf1d6];return _0x1be08a;};'use strict';var emlformat=require(_0xaa9e('0x0'));var rimraf=require(_0xaa9e('0x1'));var zipdir=require(_0xaa9e('0x2'));var jsonpatch=require(_0xaa9e('0x3'));var rp=require(_0xaa9e('0x4'));var moment=require(_0xaa9e('0x5'));var BPromise=require(_0xaa9e('0x6'));var Mustache=require('mustache');var util=require(_0xaa9e('0x7'));var path=require(_0xaa9e('0x8'));var sox=require('sox');var csv=require(_0xaa9e('0x9'));var ejs=require(_0xaa9e('0xa'));var fs=require('fs');var fs_extra=require(_0xaa9e('0xb'));var _=require(_0xaa9e('0xc'));var squel=require(_0xaa9e('0xd'));var crypto=require('crypto');var jsforce=require(_0xaa9e('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xaa9e('0x9'));var querystring=require(_0xaa9e('0xf'));var Papa=require('papaparse');var Redis=require(_0xaa9e('0x10'));var authService=require(_0xaa9e('0x11'));var qs=require(_0xaa9e('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xaa9e('0x13'));var logger=require(_0xaa9e('0x14'))(_0xaa9e('0x15'));var utils=require('../../config/utils');var config=require(_0xaa9e('0x16'));var licenseUtil=require(_0xaa9e('0x17'));var db=require('../../mysqldb')['db'];config['redis']=_[_0xaa9e('0x18')](config['redis'],{'host':_0xaa9e('0x19'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xaa9e('0x1a')]));require(_0xaa9e('0x1b'))['register'](socket);var jayson=require(_0xaa9e('0x1c'));var client=jayson[_0xaa9e('0x1d')][_0xaa9e('0x1e')]({'port':0x232c});var client9002=jayson['client'][_0xaa9e('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x569e94,_0xf1dbcf,_0x5abaad,_0xe08489){return new BPromise(function(_0x3f8993,_0x15a551){var _0x21023f=_0xe08489||client;return _0x21023f[_0xaa9e('0x1f')](_0x569e94,_0x5abaad)[_0xaa9e('0x20')](function(_0x272a8b){logger['info']('WhatsappMessage,\x20%s,\x20%s',_0xf1dbcf,_0xaa9e('0x21'));logger['debug'](_0xaa9e('0x22'),_0xf1dbcf,_0xaa9e('0x21'),JSON[_0xaa9e('0x23')](_0x272a8b));if(_0x272a8b[_0xaa9e('0x24')]){if(_0x272a8b[_0xaa9e('0x24')][_0xaa9e('0x25')]===0x1f4){logger['error']('WhatsappMessage,\x20%s,\x20%s',_0xf1dbcf,_0x272a8b[_0xaa9e('0x24')][_0xaa9e('0x26')]);return _0x15a551(_0x272a8b[_0xaa9e('0x24')][_0xaa9e('0x26')]);}logger[_0xaa9e('0x24')](_0xaa9e('0x27'),_0xf1dbcf,_0x272a8b[_0xaa9e('0x24')][_0xaa9e('0x26')]);return _0x3f8993(_0x272a8b[_0xaa9e('0x24')][_0xaa9e('0x26')]);}else{logger[_0xaa9e('0x28')]('WhatsappMessage,\x20%s,\x20%s',_0xf1dbcf,_0xaa9e('0x21'));_0x3f8993(_0x272a8b[_0xaa9e('0x29')]['message']);}})['catch'](function(_0x572611){logger[_0xaa9e('0x24')](_0xaa9e('0x27'),_0xf1dbcf,_0x572611);_0x15a551(_0x572611);});});}function respondWithStatusCode(_0x2a844f,_0x12081f){_0x12081f=_0x12081f||0xcc;return function(_0x3a09e2){if(_0x3a09e2){return _0x2a844f[_0xaa9e('0x2a')](_0x12081f);}return _0x2a844f[_0xaa9e('0x2b')](_0x12081f)[_0xaa9e('0x2c')]();};}function respondWithResult(_0xabddc6,_0x56ec9e){_0x56ec9e=_0x56ec9e||0xc8;return function(_0x50c092){if(_0x50c092){return _0xabddc6[_0xaa9e('0x2b')](_0x56ec9e)[_0xaa9e('0x2d')](_0x50c092);}};}function respondWithFilteredResult(_0x13f822,_0x1005c6){return function(_0x2b2734){if(_0x2b2734){var _0x52c090=typeof _0x1005c6[_0xaa9e('0x2e')]===_0xaa9e('0x2f')&&typeof _0x1005c6['limit']==='undefined';var _0x2ef292=_0x2b2734[_0xaa9e('0x30')];var _0x3829a1=_0x52c090?0x0:_0x1005c6[_0xaa9e('0x2e')];var _0x460ef0=_0x52c090?_0x2b2734['count']:_0x1005c6[_0xaa9e('0x2e')]+_0x1005c6['limit'];var _0x5a9163;if(_0x460ef0>=_0x2ef292){_0x460ef0=_0x2ef292;_0x5a9163=0xc8;}else{_0x5a9163=0xce;}_0x13f822[_0xaa9e('0x2b')](_0x5a9163);return _0x13f822[_0xaa9e('0x31')](_0xaa9e('0x32'),_0x3829a1+'-'+_0x460ef0+'/'+_0x2ef292)[_0xaa9e('0x2d')](_0x2b2734);}return null;};}function patchUpdates(_0x347208){return function(_0x16f77a){try{jsonpatch['apply'](_0x16f77a,_0x347208,!![]);}catch(_0x339540){return BPromise[_0xaa9e('0x33')](_0x339540);}return _0x16f77a['save']();};}function saveUpdates(_0x52c386,_0xa0aab8){return function(_0x437e27){if(_0x437e27){return _0x437e27['update'](_0x52c386)['then'](function(_0x465d97){return _0x465d97;});}return null;};}function removeEntity(_0x36f5ea,_0x491f17){return function(_0x9e4468){if(_0x9e4468){return _0x9e4468[_0xaa9e('0x34')]()['then'](function(){_0x36f5ea[_0xaa9e('0x2b')](0xcc)[_0xaa9e('0x2c')]();});}};}function handleEntityNotFound(_0x256a52,_0x186e8a){return function(_0x392a2d){if(!_0x392a2d){_0x256a52['sendStatus'](0x194);}return _0x392a2d;};}function handleError(_0x54a2f0,_0x35b408){_0x35b408=_0x35b408||0x1f4;return function(_0x37eac1){logger[_0xaa9e('0x24')](_0x37eac1[_0xaa9e('0x35')]);if(_0x37eac1[_0xaa9e('0x36')]){delete _0x37eac1[_0xaa9e('0x36')];}_0x54a2f0['status'](_0x35b408)[_0xaa9e('0x37')](_0x37eac1);};}exports['index']=function(_0xd22e51,_0x1d0d0a){var _0x51fe70={},_0x438f1d={},_0x4fead6={'count':0x0,'rows':[]};var _0x318e68=_[_0xaa9e('0x38')](db[_0xaa9e('0x39')][_0xaa9e('0x3a')],function(_0x3c3117){return{'name':_0x3c3117['fieldName'],'type':_0x3c3117[_0xaa9e('0x3b')][_0xaa9e('0x3c')]};});_0x438f1d[_0xaa9e('0x3d')]=_['map'](_0x318e68,_0xaa9e('0x36'));_0x438f1d['query']=_[_0xaa9e('0x3e')](_0xd22e51[_0xaa9e('0x3f')]);_0x438f1d[_0xaa9e('0x40')]=_[_0xaa9e('0x41')](_0x438f1d[_0xaa9e('0x3d')],_0x438f1d[_0xaa9e('0x3f')]);_0x51fe70[_0xaa9e('0x42')]=_[_0xaa9e('0x41')](_0x438f1d[_0xaa9e('0x3d')],qs[_0xaa9e('0x43')](_0xd22e51[_0xaa9e('0x3f')][_0xaa9e('0x43')]));_0x51fe70[_0xaa9e('0x42')]=_0x51fe70[_0xaa9e('0x42')][_0xaa9e('0x44')]?_0x51fe70[_0xaa9e('0x42')]:_0x438f1d[_0xaa9e('0x3d')];if(!_0xd22e51[_0xaa9e('0x3f')][_0xaa9e('0x45')](_0xaa9e('0x46'))){_0x51fe70[_0xaa9e('0x47')]=qs['limit'](_0xd22e51['query'][_0xaa9e('0x47')]);_0x51fe70[_0xaa9e('0x2e')]=qs[_0xaa9e('0x2e')](_0xd22e51[_0xaa9e('0x3f')][_0xaa9e('0x2e')]);}_0x51fe70[_0xaa9e('0x48')]=qs[_0xaa9e('0x49')](_0xd22e51[_0xaa9e('0x3f')][_0xaa9e('0x49')]);_0x51fe70[_0xaa9e('0x4a')]=qs[_0xaa9e('0x40')](_[_0xaa9e('0x4b')](_0xd22e51[_0xaa9e('0x3f')],_0x438f1d[_0xaa9e('0x40')]),_0x318e68);if(_0xd22e51[_0xaa9e('0x3f')]['filter']){_0x51fe70['where']=_[_0xaa9e('0x4c')](_0x51fe70[_0xaa9e('0x4a')],{'$or':_['map'](_0x318e68,function(_0x4a85a6){if(_0x4a85a6[_0xaa9e('0x3b')]!=='VIRTUAL'){var _0xd8a154={};_0xd8a154[_0x4a85a6[_0xaa9e('0x36')]]={'$like':'%'+_0xd22e51['query'][_0xaa9e('0x4d')]+'%'};return _0xd8a154;}})});}_0x51fe70=_['merge']({},_0x51fe70,_0xd22e51['options']);var _0x4e50f6={'where':_0x51fe70[_0xaa9e('0x4a')]};return db['WhatsappMessage'][_0xaa9e('0x30')](_0x4e50f6)[_0xaa9e('0x20')](function(_0x4728ca){_0x4fead6[_0xaa9e('0x30')]=_0x4728ca;if(_0xd22e51[_0xaa9e('0x3f')][_0xaa9e('0x4e')]){_0x51fe70[_0xaa9e('0x4f')]=[{'all':!![]}];}return db[_0xaa9e('0x39')][_0xaa9e('0x50')](_0x51fe70);})['then'](function(_0x34e7c2){_0x4fead6[_0xaa9e('0x51')]=_0x34e7c2;return _0x4fead6;})['then'](respondWithFilteredResult(_0x1d0d0a,_0x51fe70))['catch'](handleError(_0x1d0d0a,null));};exports[_0xaa9e('0x52')]=function(_0x729ea6,_0xd972c4){var _0x535155={'raw':!![],'where':{'id':_0x729ea6[_0xaa9e('0x53')]['id']}},_0x2ddcac={};_0x2ddcac[_0xaa9e('0x3d')]=_[_0xaa9e('0x3e')](db[_0xaa9e('0x39')][_0xaa9e('0x3a')]);_0x2ddcac[_0xaa9e('0x3f')]=_[_0xaa9e('0x3e')](_0x729ea6[_0xaa9e('0x3f')]);_0x2ddcac[_0xaa9e('0x40')]=_[_0xaa9e('0x41')](_0x2ddcac['model'],_0x2ddcac[_0xaa9e('0x3f')]);_0x535155[_0xaa9e('0x42')]=_['intersection'](_0x2ddcac[_0xaa9e('0x3d')],qs[_0xaa9e('0x43')](_0x729ea6['query']['fields']));_0x535155[_0xaa9e('0x42')]=_0x535155[_0xaa9e('0x42')][_0xaa9e('0x44')]?_0x535155[_0xaa9e('0x42')]:_0x2ddcac[_0xaa9e('0x3d')];if(_0x729ea6['query']['includeAll']){_0x535155[_0xaa9e('0x4f')]=[{'all':!![]}];}_0x535155=_[_0xaa9e('0x4c')]({},_0x535155,_0x729ea6[_0xaa9e('0x54')]);return db['WhatsappMessage'][_0xaa9e('0x55')](_0x535155)[_0xaa9e('0x20')](handleEntityNotFound(_0xd972c4,null))['then'](respondWithResult(_0xd972c4,null))['catch'](handleError(_0xd972c4,null));};exports['create']=function(_0x319bd6,_0x2511cb){return db[_0xaa9e('0x39')][_0xaa9e('0x56')](_0x319bd6[_0xaa9e('0x57')],{})[_0xaa9e('0x20')](respondWithResult(_0x2511cb,0xc9))[_0xaa9e('0x58')](handleError(_0x2511cb,null));};exports[_0xaa9e('0x59')]=function(_0x869317,_0x4cd16f){if(_0x869317[_0xaa9e('0x57')]['id']){delete _0x869317[_0xaa9e('0x57')]['id'];}return db[_0xaa9e('0x39')]['find']({'where':{'id':_0x869317[_0xaa9e('0x53')]['id']}})[_0xaa9e('0x20')](handleEntityNotFound(_0x4cd16f,null))['then'](saveUpdates(_0x869317[_0xaa9e('0x57')],null))[_0xaa9e('0x20')](respondWithResult(_0x4cd16f,null))[_0xaa9e('0x58')](handleError(_0x4cd16f,null));};exports['destroy']=function(_0x10be17,_0x3cb457){return db[_0xaa9e('0x39')][_0xaa9e('0x55')]({'where':{'id':_0x10be17[_0xaa9e('0x53')]['id']}})['then'](handleEntityNotFound(_0x3cb457,null))['then'](removeEntity(_0x3cb457,null))[_0xaa9e('0x58')](handleError(_0x3cb457,null));};exports[_0xaa9e('0x5a')]=function(_0x9d48c8,_0x11cab9){return db[_0xaa9e('0x39')][_0xaa9e('0x5a')]()[_0xaa9e('0x20')](respondWithResult(_0x11cab9,null))[_0xaa9e('0x58')](handleError(_0x11cab9,null));};var interaction_log=require(_0xaa9e('0x14'))(_0xaa9e('0x5b'));exports[_0xaa9e('0x5c')]=function(_0x28d57a,_0x550631,_0x4d54ad){var _0x31e02e={'agent':{},'channel':_0xaa9e('0x5d')};if(_0x28d57a[_0xaa9e('0x57')]['id']){delete _0x28d57a[_0xaa9e('0x57')]['id'];}_0x28d57a[_0xaa9e('0x57')][_0xaa9e('0x5e')]=!![];_0x28d57a[_0xaa9e('0x57')]['readAt']=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');_0x28d57a[_0xaa9e('0x57')][_0xaa9e('0x5f')]=_0x28d57a[_0xaa9e('0x57')][_0xaa9e('0x5f')]||_0x28d57a[_0xaa9e('0x60')]['id'];_0x31e02e[_0xaa9e('0x61')]['id']=_0x28d57a[_0xaa9e('0x57')][_0xaa9e('0x5f')];return db['WhatsappMessage']['find']({'where':{'id':_0x28d57a[_0xaa9e('0x53')]['id'],'UserId':null}})[_0xaa9e('0x20')](handleEntityNotFound(_0x550631,null))[_0xaa9e('0x20')](saveUpdates(_0x28d57a[_0xaa9e('0x57')],null))[_0xaa9e('0x20')](function(_0x113248){if(_0x113248){_0x31e02e[_0xaa9e('0x26')]=_0x113248[_0xaa9e('0x62')]({'plain':!![]});return db[_0xaa9e('0x63')][_0xaa9e('0x55')]({'where':{'id':_0x113248[_0xaa9e('0x64')]}});}return null;})[_0xaa9e('0x20')](handleEntityNotFound(_0x550631,null))['then'](function(_0x238790){if(_0x238790){return _0x238790[_0xaa9e('0x59')]({'UserId':_0x28d57a['body'][_0xaa9e('0x5f')],'read1stAt':_[_0xaa9e('0x65')](_0x238790[_0xaa9e('0x66')])?moment()[_0xaa9e('0x67')](_0xaa9e('0x68')):undefined});}return null;})[_0xaa9e('0x20')](function(_0x414dd9){if(_0x414dd9){_0x31e02e[_0xaa9e('0x69')]=_0x414dd9[_0xaa9e('0x62')]({'plain':!![]});interaction_log['info'](_0xaa9e('0x6a'),_0x28d57a[_0xaa9e('0x60')]['id'],_0x28d57a[_0xaa9e('0x60')]['name'],_0x28d57a[_0xaa9e('0x60')]['role'],_0x31e02e[_0xaa9e('0x69')]['id'],_0x28d57a[_0xaa9e('0x57')]?JSON[_0xaa9e('0x23')](_0x28d57a[_0xaa9e('0x57')]):_0xaa9e('0x6b'));return respondWithRpcPromise(_0xaa9e('0x6c'),_0xaa9e('0x6d'),_0x31e02e);}return null;})[_0xaa9e('0x20')](function(_0x4f5f4e){var _0x1a187d=_0xaa9e('0x6e')+_0x4f5f4e[_0xaa9e('0x26')][_0xaa9e('0x6f')];return db['sequelize'][_0xaa9e('0x3f')](_0x1a187d,{'type':db[_0xaa9e('0x70')][_0xaa9e('0x71')][_0xaa9e('0x72')],'raw':!![]})[_0xaa9e('0x20')](function(_0x3ba60c){return _0x3ba60c;});})['then'](function(_0x1a092b){if(_0x1a092b){_0x31e02e['message'][_0xaa9e('0x73')]=_0x1a092b[0x0];if(!_0x28d57a[_0xaa9e('0x57')][_0xaa9e('0x5f')])return;return db[_0xaa9e('0x74')][_0xaa9e('0x55')]({'where':{'id':_0x28d57a['body'][_0xaa9e('0x5f')],'role':_0xaa9e('0x61')},'attributes':['id','name',_0xaa9e('0x75'),_0xaa9e('0x76'),_0xaa9e('0x77')],'raw':!![]});}return null;})[_0xaa9e('0x20')](function(_0x297b88){if(!_0x297b88)return null;_0x31e02e[_0xaa9e('0x26')][_0xaa9e('0x61')]=_0x297b88;return _0x31e02e;})[_0xaa9e('0x20')](function(_0x3267f2){if(_0x3267f2){if(_0x28d57a[_0xaa9e('0x57')][_0xaa9e('0x78')]){_0x31e02e['message'][_0xaa9e('0x79')]=util[_0xaa9e('0x67')](_0xaa9e('0x7a'),_0x28d57a['user'][_0xaa9e('0x36')]);_0x31e02e[_0xaa9e('0x26')][_0xaa9e('0x7b')]=_0x31e02e[_0xaa9e('0x7b')];_0x31e02e['message'][_0xaa9e('0x7c')]=_0x31e02e[_0xaa9e('0x7b')];_0x31e02e[_0xaa9e('0x26')][_0xaa9e('0x7d')]=_0xaa9e('0x5c');return respondWithRpcPromise(_0xaa9e('0x7e'),_0xaa9e('0x7e'),{'event':_0xaa9e('0x7f'),'message':_0x31e02e[_0xaa9e('0x26')]},client9002)[_0xaa9e('0x20')](function(){return _0x31e02e;});}return _0x31e02e;}return null;})[_0xaa9e('0x20')](respondWithResult(_0x550631,null))[_0xaa9e('0x58')](handleError(_0x550631,null));};var interaction_log=require(_0xaa9e('0x14'))(_0xaa9e('0x5b'));exports['reject']=function(_0x3b68f4,_0x1296ad,_0x325ebb){var _0x4f85b1={'agent':{},'channel':'whatsapp'};if(_0x3b68f4[_0xaa9e('0x57')]['id']){delete _0x3b68f4[_0xaa9e('0x57')]['id'];}_0x3b68f4[_0xaa9e('0x57')]['UserId']=_0x3b68f4[_0xaa9e('0x57')][_0xaa9e('0x5f')]||_0x3b68f4[_0xaa9e('0x60')]['id'];_0x4f85b1[_0xaa9e('0x61')]['id']=_0x3b68f4[_0xaa9e('0x57')][_0xaa9e('0x5f')];return db['WhatsappMessage']['find']({'where':{'id':_0x3b68f4[_0xaa9e('0x53')]['id'],'UserId':null}})[_0xaa9e('0x20')](handleEntityNotFound(_0x1296ad,null))[_0xaa9e('0x20')](function(_0x103ddc){if(_0x103ddc){_0x4f85b1[_0xaa9e('0x26')]=_0x103ddc['get']({'plain':!![]});return db[_0xaa9e('0x63')][_0xaa9e('0x55')]({'where':{'id':_0x103ddc[_0xaa9e('0x64')]}});}return null;})['then'](handleEntityNotFound(_0x1296ad,null))[_0xaa9e('0x20')](function(_0x5cb410){if(_0x5cb410){_0x4f85b1[_0xaa9e('0x69')]=_0x5cb410[_0xaa9e('0x62')]({'plain':!![]});interaction_log[_0xaa9e('0x28')](_0xaa9e('0x80'),_0x3b68f4[_0xaa9e('0x60')]['id'],_0x3b68f4[_0xaa9e('0x60')][_0xaa9e('0x36')],_0x3b68f4[_0xaa9e('0x60')]['role'],_0x4f85b1[_0xaa9e('0x69')]['id'],_0x3b68f4['body']?JSON[_0xaa9e('0x23')](_0x3b68f4[_0xaa9e('0x57')]):_0xaa9e('0x6b'));return respondWithRpcPromise(_0xaa9e('0x81'),_0xaa9e('0x82'),_0x4f85b1);}return null;})['then'](function(_0x54b888){var _0xf75305='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x54b888[_0xaa9e('0x26')][_0xaa9e('0x6f')];return db['sequelize'][_0xaa9e('0x3f')](_0xf75305,{'type':db['Sequelize']['QueryTypes'][_0xaa9e('0x72')],'raw':!![]})[_0xaa9e('0x20')](function(_0x2df63b){return _0x2df63b;});})[_0xaa9e('0x20')](function(_0x11a7cb){if(_0x11a7cb){_0x4f85b1['message'][_0xaa9e('0x73')]=_0x11a7cb[0x0];if(!_0x3b68f4['body']['UserId'])return;return db[_0xaa9e('0x74')][_0xaa9e('0x55')]({'where':{'id':_0x3b68f4[_0xaa9e('0x57')][_0xaa9e('0x5f')],'role':_0xaa9e('0x61')},'attributes':['id','name','fullname',_0xaa9e('0x76'),_0xaa9e('0x77')],'raw':!![]});}return null;})[_0xaa9e('0x20')](function(_0x15865b){if(!_0x15865b)return null;_0x4f85b1['message'][_0xaa9e('0x61')]=_0x15865b;return _0x4f85b1;})[_0xaa9e('0x20')](function(_0x273265){if(_0x273265){_0x273265[_0xaa9e('0x26')][_0xaa9e('0x79')]=util['format']('SIP/%s',_0x3b68f4[_0xaa9e('0x60')]['name']);_0x273265[_0xaa9e('0x26')][_0xaa9e('0x7b')]=_0x4f85b1[_0xaa9e('0x7b')];_0x273265['message'][_0xaa9e('0x7c')]=_0x4f85b1['channel'];_0x273265[_0xaa9e('0x26')]['event']=_0xaa9e('0x33');respondWithRpcPromise(_0xaa9e('0x7e'),_0xaa9e('0x7e'),{'event':_0xaa9e('0x83'),'message':_0x273265[_0xaa9e('0x26')]},client9002);return _0x4f85b1;}return null;})[_0xaa9e('0x20')](respondWithResult(_0x1296ad,null))[_0xaa9e('0x58')](handleError(_0x1296ad,null));};exports['status']=function(_0x4e0dd3,_0x46c2e5,_0x25dd11){if(_0x4e0dd3[_0xaa9e('0x57')]['id']){delete _0x4e0dd3['body']['id'];}var _0x4835dd;return db[_0xaa9e('0x39')][_0xaa9e('0x55')]({'where':{'id':_0x4e0dd3[_0xaa9e('0x53')]['id']}})['then'](handleEntityNotFound(_0x46c2e5,null))['then'](function(_0x187b35){if(_0x187b35){_0x4835dd=_0x187b35;return db[_0xaa9e('0x84')][_0xaa9e('0x55')]({'where':{'id':_0x187b35['WhatsappAccountId']}});}})[_0xaa9e('0x20')](handleEntityNotFound(_0x46c2e5,null))[_0xaa9e('0x20')](function(_0x51e0e7){if(_0x51e0e7){logger['debug'](_0xaa9e('0x85'),_0xaa9e('0x2b'),_0xaa9e('0x86'),_0x51e0e7[_0xaa9e('0x3b')],util[_0xaa9e('0x87')](_0x4e0dd3[_0xaa9e('0x57')],{'showHidden':![],'depth':null}));switch(_0x51e0e7[_0xaa9e('0x3b')]){case'twilio':if(_0x4e0dd3['body']['MessageSid']&&_0x4e0dd3['body']['MessageSid']===_0x4835dd[_0xaa9e('0x88')]&&_0x4e0dd3[_0xaa9e('0x57')][_0xaa9e('0x89')]&&_0x4e0dd3[_0xaa9e('0x57')]['MessageStatus']==='read'){return _0x4835dd['update']({'read':!![]});}else{logger[_0xaa9e('0x24')](_0xaa9e('0x8a'),_0xaa9e('0x2b'),_0xaa9e('0x8b'),util[_0xaa9e('0x87')](_0x4e0dd3[_0xaa9e('0x57')],{'showHidden':![],'depth':null}));}break;}return _0x4835dd;}})[_0xaa9e('0x20')](respondWithResult(_0x46c2e5,null))[_0xaa9e('0x58')](handleError(_0x46c2e5,null));};
\ No newline at end of file
+var _0x534f=['QueryTypes','fullname','internal','rejectmessage','WhatsappAccountId','received\x20delivery\x20report\x20from','twilio','MessageSid','messageId','MessageStatus','read','WhatsappAccount,\x20%s,\x20%s,\x20%s','inspect','eml-format','rimraf','zip-dir','fast-json-patch','moment','mustache','util','sox','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./whatsappMessage.socket','client','http','request','then','info','WhatsappMessage,\x20%s,\x20%s','request\x20sent','debug','WhatsappMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','status','end','undefined','limit','count','Content-Range','json','apply','reject','save','update','destroy','sendStatus','name','send','index','map','rawAttributes','fieldName','model','keys','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','offset','order','sort','where','pick','filter','type','VIRTUAL','merge','options','WhatsappMessage','findAll','rows','show','params','length','includeAll','include','find','create','body','describe','whatsapp-interactions','accept','whatsapp','readAt','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','WhatsappInteraction','WhatsappInteractionId','format','get','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','interaction','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','SELECT','contact','User','email','manual','interface','channel','motionChannel','event','EventManager','acceptmessage','RejectMessage','rejectMessage','Sequelize'];(function(_0x1b6fa1,_0x439d73){var _0x13982d=function(_0x129fde){while(--_0x129fde){_0x1b6fa1['push'](_0x1b6fa1['shift']());}};_0x13982d(++_0x439d73);}(_0x534f,0x1b1));var _0xf534=function(_0xfc0e65,_0x4404de){_0xfc0e65=_0xfc0e65-0x0;var _0x464396=_0x534f[_0xfc0e65];return _0x464396;};'use strict';var emlformat=require(_0xf534('0x0'));var rimraf=require(_0xf534('0x1'));var zipdir=require(_0xf534('0x2'));var jsonpatch=require(_0xf534('0x3'));var rp=require('request-promise');var moment=require(_0xf534('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xf534('0x5'));var util=require(_0xf534('0x6'));var path=require('path');var sox=require(_0xf534('0x7'));var csv=require(_0xf534('0x8'));var ejs=require(_0xf534('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0xf534('0xa'));var crypto=require(_0xf534('0xb'));var jsforce=require(_0xf534('0xc'));var deskjs=require(_0xf534('0xd'));var toCsv=require(_0xf534('0x8'));var querystring=require(_0xf534('0xe'));var Papa=require(_0xf534('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xf534('0x10'));var as=require(_0xf534('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf534('0x12'))('api');var utils=require(_0xf534('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0xf534('0x14'));var db=require(_0xf534('0x15'))['db'];config[_0xf534('0x16')]=_[_0xf534('0x17')](config[_0xf534('0x16')],{'host':_0xf534('0x18'),'port':0x18eb});var socket=require(_0xf534('0x19'))(new Redis(config[_0xf534('0x16')]));require(_0xf534('0x1a'))['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0xf534('0x1b')]['http']({'port':0x232c});var client9002=jayson['client'][_0xf534('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x8cd0a0,_0x4b0f6d,_0x3501eb,_0x5298be){return new BPromise(function(_0x31e418,_0x32528a){var _0x1bb623=_0x5298be||client;return _0x1bb623[_0xf534('0x1d')](_0x8cd0a0,_0x3501eb)[_0xf534('0x1e')](function(_0xed9a45){logger[_0xf534('0x1f')](_0xf534('0x20'),_0x4b0f6d,_0xf534('0x21'));logger[_0xf534('0x22')](_0xf534('0x23'),_0x4b0f6d,_0xf534('0x21'),JSON[_0xf534('0x24')](_0xed9a45));if(_0xed9a45[_0xf534('0x25')]){if(_0xed9a45[_0xf534('0x25')][_0xf534('0x26')]===0x1f4){logger[_0xf534('0x25')]('WhatsappMessage,\x20%s,\x20%s',_0x4b0f6d,_0xed9a45['error'][_0xf534('0x27')]);return _0x32528a(_0xed9a45[_0xf534('0x25')]['message']);}logger['error']('WhatsappMessage,\x20%s,\x20%s',_0x4b0f6d,_0xed9a45[_0xf534('0x25')]['message']);return _0x31e418(_0xed9a45[_0xf534('0x25')][_0xf534('0x27')]);}else{logger[_0xf534('0x1f')](_0xf534('0x20'),_0x4b0f6d,_0xf534('0x21'));_0x31e418(_0xed9a45[_0xf534('0x28')][_0xf534('0x27')]);}})[_0xf534('0x29')](function(_0xbd376a){logger[_0xf534('0x25')](_0xf534('0x20'),_0x4b0f6d,_0xbd376a);_0x32528a(_0xbd376a);});});}function respondWithStatusCode(_0xa6524c,_0x13d179){_0x13d179=_0x13d179||0xcc;return function(_0xd78843){if(_0xd78843){return _0xa6524c['sendStatus'](_0x13d179);}return _0xa6524c[_0xf534('0x2a')](_0x13d179)[_0xf534('0x2b')]();};}function respondWithResult(_0x436f18,_0x1ec53a){_0x1ec53a=_0x1ec53a||0xc8;return function(_0x55da72){if(_0x55da72){return _0x436f18[_0xf534('0x2a')](_0x1ec53a)['json'](_0x55da72);}};}function respondWithFilteredResult(_0x1b311c,_0x47b2c2){return function(_0x1b66b0){if(_0x1b66b0){var _0x1320c4=typeof _0x47b2c2['offset']===_0xf534('0x2c')&&typeof _0x47b2c2[_0xf534('0x2d')]===_0xf534('0x2c');var _0x276729=_0x1b66b0[_0xf534('0x2e')];var _0x27bd2b=_0x1320c4?0x0:_0x47b2c2['offset'];var _0x32ea4a=_0x1320c4?_0x1b66b0[_0xf534('0x2e')]:_0x47b2c2['offset']+_0x47b2c2['limit'];var _0x1a4931;if(_0x32ea4a>=_0x276729){_0x32ea4a=_0x276729;_0x1a4931=0xc8;}else{_0x1a4931=0xce;}_0x1b311c[_0xf534('0x2a')](_0x1a4931);return _0x1b311c['set'](_0xf534('0x2f'),_0x27bd2b+'-'+_0x32ea4a+'/'+_0x276729)[_0xf534('0x30')](_0x1b66b0);}return null;};}function patchUpdates(_0x57b3b8){return function(_0x2cf65e){try{jsonpatch[_0xf534('0x31')](_0x2cf65e,_0x57b3b8,!![]);}catch(_0x5f2f6b){return BPromise[_0xf534('0x32')](_0x5f2f6b);}return _0x2cf65e[_0xf534('0x33')]();};}function saveUpdates(_0x303079,_0xba6d16){return function(_0x27e0fc){if(_0x27e0fc){return _0x27e0fc[_0xf534('0x34')](_0x303079)['then'](function(_0xe965c9){return _0xe965c9;});}return null;};}function removeEntity(_0x41308b,_0x4fd636){return function(_0x109cf3){if(_0x109cf3){return _0x109cf3[_0xf534('0x35')]()['then'](function(){_0x41308b[_0xf534('0x2a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x579ffb,_0x2e277d){return function(_0x319a0d){if(!_0x319a0d){_0x579ffb[_0xf534('0x36')](0x194);}return _0x319a0d;};}function handleError(_0x59776b,_0x1aca48){_0x1aca48=_0x1aca48||0x1f4;return function(_0x1e179e){logger['error'](_0x1e179e['stack']);if(_0x1e179e['name']){delete _0x1e179e[_0xf534('0x37')];}_0x59776b[_0xf534('0x2a')](_0x1aca48)[_0xf534('0x38')](_0x1e179e);};}exports[_0xf534('0x39')]=function(_0x55a5f4,_0x59b259){var _0x5a57e8={},_0x414385={},_0x38aed3={'count':0x0,'rows':[]};var _0x19a3e8=_[_0xf534('0x3a')](db['WhatsappMessage'][_0xf534('0x3b')],function(_0x349759){return{'name':_0x349759[_0xf534('0x3c')],'type':_0x349759['type']['key']};});_0x414385[_0xf534('0x3d')]=_['map'](_0x19a3e8,_0xf534('0x37'));_0x414385['query']=_[_0xf534('0x3e')](_0x55a5f4[_0xf534('0x3f')]);_0x414385[_0xf534('0x40')]=_[_0xf534('0x41')](_0x414385[_0xf534('0x3d')],_0x414385[_0xf534('0x3f')]);_0x5a57e8[_0xf534('0x42')]=_[_0xf534('0x41')](_0x414385[_0xf534('0x3d')],qs[_0xf534('0x43')](_0x55a5f4[_0xf534('0x3f')][_0xf534('0x43')]));_0x5a57e8[_0xf534('0x42')]=_0x5a57e8[_0xf534('0x42')]['length']?_0x5a57e8[_0xf534('0x42')]:_0x414385['model'];if(!_0x55a5f4[_0xf534('0x3f')][_0xf534('0x44')](_0xf534('0x45'))){_0x5a57e8[_0xf534('0x2d')]=qs[_0xf534('0x2d')](_0x55a5f4[_0xf534('0x3f')][_0xf534('0x2d')]);_0x5a57e8[_0xf534('0x46')]=qs[_0xf534('0x46')](_0x55a5f4[_0xf534('0x3f')][_0xf534('0x46')]);}_0x5a57e8[_0xf534('0x47')]=qs[_0xf534('0x48')](_0x55a5f4[_0xf534('0x3f')]['sort']);_0x5a57e8[_0xf534('0x49')]=qs['filters'](_[_0xf534('0x4a')](_0x55a5f4[_0xf534('0x3f')],_0x414385[_0xf534('0x40')]),_0x19a3e8);if(_0x55a5f4[_0xf534('0x3f')][_0xf534('0x4b')]){_0x5a57e8[_0xf534('0x49')]=_['merge'](_0x5a57e8['where'],{'$or':_[_0xf534('0x3a')](_0x19a3e8,function(_0x1ba227){if(_0x1ba227[_0xf534('0x4c')]!==_0xf534('0x4d')){var _0x5811e5={};_0x5811e5[_0x1ba227['name']]={'$like':'%'+_0x55a5f4[_0xf534('0x3f')][_0xf534('0x4b')]+'%'};return _0x5811e5;}})});}_0x5a57e8=_[_0xf534('0x4e')]({},_0x5a57e8,_0x55a5f4[_0xf534('0x4f')]);var _0x3b12b7={'where':_0x5a57e8[_0xf534('0x49')]};return db[_0xf534('0x50')][_0xf534('0x2e')](_0x3b12b7)[_0xf534('0x1e')](function(_0x412457){_0x38aed3['count']=_0x412457;if(_0x55a5f4[_0xf534('0x3f')]['includeAll']){_0x5a57e8['include']=[{'all':!![]}];}return db['WhatsappMessage'][_0xf534('0x51')](_0x5a57e8);})[_0xf534('0x1e')](function(_0x245a5c){_0x38aed3[_0xf534('0x52')]=_0x245a5c;return _0x38aed3;})[_0xf534('0x1e')](respondWithFilteredResult(_0x59b259,_0x5a57e8))['catch'](handleError(_0x59b259,null));};exports[_0xf534('0x53')]=function(_0x4f884b,_0x4047f8){var _0xa67fb7={'raw':!![],'where':{'id':_0x4f884b[_0xf534('0x54')]['id']}},_0x2ad9f8={};_0x2ad9f8[_0xf534('0x3d')]=_[_0xf534('0x3e')](db[_0xf534('0x50')][_0xf534('0x3b')]);_0x2ad9f8['query']=_[_0xf534('0x3e')](_0x4f884b[_0xf534('0x3f')]);_0x2ad9f8[_0xf534('0x40')]=_[_0xf534('0x41')](_0x2ad9f8[_0xf534('0x3d')],_0x2ad9f8[_0xf534('0x3f')]);_0xa67fb7[_0xf534('0x42')]=_[_0xf534('0x41')](_0x2ad9f8[_0xf534('0x3d')],qs[_0xf534('0x43')](_0x4f884b[_0xf534('0x3f')][_0xf534('0x43')]));_0xa67fb7['attributes']=_0xa67fb7[_0xf534('0x42')][_0xf534('0x55')]?_0xa67fb7['attributes']:_0x2ad9f8[_0xf534('0x3d')];if(_0x4f884b['query'][_0xf534('0x56')]){_0xa67fb7[_0xf534('0x57')]=[{'all':!![]}];}_0xa67fb7=_[_0xf534('0x4e')]({},_0xa67fb7,_0x4f884b[_0xf534('0x4f')]);return db[_0xf534('0x50')][_0xf534('0x58')](_0xa67fb7)['then'](handleEntityNotFound(_0x4047f8,null))['then'](respondWithResult(_0x4047f8,null))[_0xf534('0x29')](handleError(_0x4047f8,null));};exports[_0xf534('0x59')]=function(_0x2044c7,_0x22d649){return db[_0xf534('0x50')][_0xf534('0x59')](_0x2044c7[_0xf534('0x5a')],{})[_0xf534('0x1e')](respondWithResult(_0x22d649,0xc9))[_0xf534('0x29')](handleError(_0x22d649,null));};exports['update']=function(_0xb7fe10,_0x2163d7){if(_0xb7fe10[_0xf534('0x5a')]['id']){delete _0xb7fe10[_0xf534('0x5a')]['id'];}return db[_0xf534('0x50')][_0xf534('0x58')]({'where':{'id':_0xb7fe10[_0xf534('0x54')]['id']}})[_0xf534('0x1e')](handleEntityNotFound(_0x2163d7,null))[_0xf534('0x1e')](saveUpdates(_0xb7fe10['body'],null))[_0xf534('0x1e')](respondWithResult(_0x2163d7,null))[_0xf534('0x29')](handleError(_0x2163d7,null));};exports[_0xf534('0x35')]=function(_0x229b6a,_0x3b5c24){return db[_0xf534('0x50')][_0xf534('0x58')]({'where':{'id':_0x229b6a[_0xf534('0x54')]['id']}})[_0xf534('0x1e')](handleEntityNotFound(_0x3b5c24,null))[_0xf534('0x1e')](removeEntity(_0x3b5c24,null))['catch'](handleError(_0x3b5c24,null));};exports[_0xf534('0x5b')]=function(_0xa96b83,_0x5ab844){return db['WhatsappMessage'][_0xf534('0x5b')]()['then'](respondWithResult(_0x5ab844,null))[_0xf534('0x29')](handleError(_0x5ab844,null));};var interaction_log=require(_0xf534('0x12'))(_0xf534('0x5c'));exports[_0xf534('0x5d')]=function(_0xa3a839,_0x476ae7,_0x58b439){var _0x183734={'agent':{},'channel':_0xf534('0x5e')};if(_0xa3a839[_0xf534('0x5a')]['id']){delete _0xa3a839[_0xf534('0x5a')]['id'];}_0xa3a839[_0xf534('0x5a')]['read']=!![];_0xa3a839[_0xf534('0x5a')][_0xf534('0x5f')]=moment()['format'](_0xf534('0x60'));_0xa3a839[_0xf534('0x5a')][_0xf534('0x61')]=_0xa3a839[_0xf534('0x5a')][_0xf534('0x61')]||_0xa3a839[_0xf534('0x62')]['id'];_0x183734[_0xf534('0x63')]['id']=_0xa3a839['body']['UserId'];return db[_0xf534('0x50')][_0xf534('0x58')]({'where':{'id':_0xa3a839[_0xf534('0x54')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x476ae7,null))[_0xf534('0x1e')](saveUpdates(_0xa3a839['body'],null))[_0xf534('0x1e')](function(_0x4a6e19){if(_0x4a6e19){_0x183734['message']=_0x4a6e19['get']({'plain':!![]});return db[_0xf534('0x64')][_0xf534('0x58')]({'where':{'id':_0x4a6e19[_0xf534('0x65')]}});}return null;})[_0xf534('0x1e')](handleEntityNotFound(_0x476ae7,null))[_0xf534('0x1e')](function(_0xad09ff){if(_0xad09ff){return _0xad09ff[_0xf534('0x34')]({'UserId':_0xa3a839[_0xf534('0x5a')]['UserId'],'read1stAt':_['isNil'](_0xad09ff['read1stAt'])?moment()[_0xf534('0x66')](_0xf534('0x60')):undefined});}return null;})[_0xf534('0x1e')](function(_0x292f25){if(_0x292f25){_0x183734['interaction']=_0x292f25[_0xf534('0x67')]({'plain':!![]});interaction_log[_0xf534('0x1f')](_0xf534('0x68'),_0xa3a839[_0xf534('0x62')]['id'],_0xa3a839['user'][_0xf534('0x37')],_0xa3a839[_0xf534('0x62')][_0xf534('0x69')],_0x183734[_0xf534('0x6a')]['id'],_0xa3a839['body']?JSON[_0xf534('0x24')](_0xa3a839['body']):_0xf534('0x6b'));return respondWithRpcPromise(_0xf534('0x6c'),_0xf534('0x6d'),_0x183734);}return null;})[_0xf534('0x1e')](function(_0x34323d){var _0x2014d4=_0xf534('0x6e')+_0x34323d['message'][_0xf534('0x6f')];return db[_0xf534('0x70')][_0xf534('0x3f')](_0x2014d4,{'type':db['Sequelize']['QueryTypes'][_0xf534('0x71')],'raw':!![]})['then'](function(_0x32da27){return _0x32da27;});})[_0xf534('0x1e')](function(_0x1f26c0){if(_0x1f26c0){_0x183734[_0xf534('0x27')][_0xf534('0x72')]=_0x1f26c0[0x0];if(!_0xa3a839[_0xf534('0x5a')]['UserId'])return;return db[_0xf534('0x73')][_0xf534('0x58')]({'where':{'id':_0xa3a839[_0xf534('0x5a')][_0xf534('0x61')],'role':_0xf534('0x63')},'attributes':['id','name','fullname',_0xf534('0x74'),'internal'],'raw':!![]});}return null;})['then'](function(_0xa2bfec){if(!_0xa2bfec)return null;_0x183734[_0xf534('0x27')][_0xf534('0x63')]=_0xa2bfec;return _0x183734;})[_0xf534('0x1e')](function(_0x1dec1e){if(_0x1dec1e){if(_0xa3a839[_0xf534('0x5a')][_0xf534('0x75')]){_0x183734[_0xf534('0x27')][_0xf534('0x76')]=util['format']('SIP/%s',_0xa3a839['user'][_0xf534('0x37')]);_0x183734[_0xf534('0x27')]['channel']=_0x183734[_0xf534('0x77')];_0x183734['message'][_0xf534('0x78')]=_0x183734[_0xf534('0x77')];_0x183734[_0xf534('0x27')][_0xf534('0x79')]=_0xf534('0x5d');return respondWithRpcPromise('EventManager',_0xf534('0x7a'),{'event':_0xf534('0x7b'),'message':_0x183734['message']},client9002)[_0xf534('0x1e')](function(){return _0x183734;});}return _0x183734;}return null;})[_0xf534('0x1e')](respondWithResult(_0x476ae7,null))[_0xf534('0x29')](handleError(_0x476ae7,null));};var interaction_log=require(_0xf534('0x12'))('whatsapp-interactions');exports['reject']=function(_0x16034c,_0x1e8410,_0x3dd28e){var _0x19942d={'agent':{},'channel':_0xf534('0x5e')};if(_0x16034c[_0xf534('0x5a')]['id']){delete _0x16034c[_0xf534('0x5a')]['id'];}_0x16034c['body'][_0xf534('0x61')]=_0x16034c['body'][_0xf534('0x61')]||_0x16034c['user']['id'];_0x19942d[_0xf534('0x63')]['id']=_0x16034c[_0xf534('0x5a')][_0xf534('0x61')];return db[_0xf534('0x50')][_0xf534('0x58')]({'where':{'id':_0x16034c[_0xf534('0x54')]['id'],'UserId':null}})[_0xf534('0x1e')](handleEntityNotFound(_0x1e8410,null))[_0xf534('0x1e')](function(_0x5a4bd9){if(_0x5a4bd9){_0x19942d[_0xf534('0x27')]=_0x5a4bd9[_0xf534('0x67')]({'plain':!![]});return db[_0xf534('0x64')][_0xf534('0x58')]({'where':{'id':_0x5a4bd9[_0xf534('0x65')]}});}return null;})[_0xf534('0x1e')](handleEntityNotFound(_0x1e8410,null))['then'](function(_0x3cf350){if(_0x3cf350){_0x19942d[_0xf534('0x6a')]=_0x3cf350['get']({'plain':!![]});interaction_log[_0xf534('0x1f')]('[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x16034c[_0xf534('0x62')]['id'],_0x16034c[_0xf534('0x62')][_0xf534('0x37')],_0x16034c['user'][_0xf534('0x69')],_0x19942d[_0xf534('0x6a')]['id'],_0x16034c[_0xf534('0x5a')]?JSON[_0xf534('0x24')](_0x16034c[_0xf534('0x5a')]):'null');return respondWithRpcPromise(_0xf534('0x7c'),_0xf534('0x7d'),_0x19942d);}return null;})[_0xf534('0x1e')](function(_0x39d4e4){var _0x5f2e96=_0xf534('0x6e')+_0x39d4e4[_0xf534('0x27')]['ContactId'];return db[_0xf534('0x70')][_0xf534('0x3f')](_0x5f2e96,{'type':db[_0xf534('0x7e')][_0xf534('0x7f')]['SELECT'],'raw':!![]})['then'](function(_0x235a89){return _0x235a89;});})['then'](function(_0x1da66c){if(_0x1da66c){_0x19942d[_0xf534('0x27')][_0xf534('0x72')]=_0x1da66c[0x0];if(!_0x16034c[_0xf534('0x5a')][_0xf534('0x61')])return;return db[_0xf534('0x73')][_0xf534('0x58')]({'where':{'id':_0x16034c[_0xf534('0x5a')][_0xf534('0x61')],'role':'agent'},'attributes':['id',_0xf534('0x37'),_0xf534('0x80'),_0xf534('0x74'),_0xf534('0x81')],'raw':!![]});}return null;})[_0xf534('0x1e')](function(_0x564676){if(!_0x564676)return null;_0x19942d[_0xf534('0x27')]['agent']=_0x564676;return _0x19942d;})[_0xf534('0x1e')](function(_0x8a4b9c){if(_0x8a4b9c){_0x8a4b9c[_0xf534('0x27')][_0xf534('0x76')]=util[_0xf534('0x66')]('SIP/%s',_0x16034c[_0xf534('0x62')]['name']);_0x8a4b9c[_0xf534('0x27')]['channel']=_0x19942d['channel'];_0x8a4b9c[_0xf534('0x27')][_0xf534('0x78')]=_0x19942d[_0xf534('0x77')];_0x8a4b9c['message'][_0xf534('0x79')]=_0xf534('0x32');respondWithRpcPromise(_0xf534('0x7a'),_0xf534('0x7a'),{'event':_0xf534('0x82'),'message':_0x8a4b9c['message']},client9002);return _0x19942d;}return null;})[_0xf534('0x1e')](respondWithResult(_0x1e8410,null))['catch'](handleError(_0x1e8410,null));};exports[_0xf534('0x2a')]=function(_0x47ffbf,_0x5271b3,_0x192dca){if(_0x47ffbf[_0xf534('0x5a')]['id']){delete _0x47ffbf[_0xf534('0x5a')]['id'];}var _0xe4d904;return db[_0xf534('0x50')][_0xf534('0x58')]({'where':{'id':_0x47ffbf[_0xf534('0x54')]['id']}})[_0xf534('0x1e')](handleEntityNotFound(_0x5271b3,null))[_0xf534('0x1e')](function(_0x480842){if(_0x480842){_0xe4d904=_0x480842;return db['WhatsappAccount'][_0xf534('0x58')]({'where':{'id':_0x480842[_0xf534('0x83')]}});}})[_0xf534('0x1e')](handleEntityNotFound(_0x5271b3,null))['then'](function(_0x5d1a27){if(_0x5d1a27){logger[_0xf534('0x22')]('WhatsppMessage,\x20%s,\x20%s,\x20%s',_0xf534('0x2a'),_0xf534('0x84'),_0x5d1a27[_0xf534('0x4c')],util['inspect'](_0x47ffbf[_0xf534('0x5a')],{'showHidden':![],'depth':null}));switch(_0x5d1a27[_0xf534('0x4c')]){case _0xf534('0x85'):if(_0x47ffbf['body'][_0xf534('0x86')]&&_0x47ffbf[_0xf534('0x5a')][_0xf534('0x86')]===_0xe4d904[_0xf534('0x87')]&&_0x47ffbf['body']['MessageStatus']&&_0x47ffbf[_0xf534('0x5a')][_0xf534('0x88')]===_0xf534('0x89')){return _0xe4d904[_0xf534('0x34')]({'read':!![]});}else{logger[_0xf534('0x25')](_0xf534('0x8a'),_0xf534('0x2a'),_0xf534('0x85'),util[_0xf534('0x8b')](_0x47ffbf[_0xf534('0x5a')],{'showHidden':![],'depth':null}));}break;}return _0xe4d904;}})[_0xf534('0x1e')](respondWithResult(_0x5271b3,null))[_0xf534('0x29')](handleError(_0x5271b3,null));};
\ No newline at end of file