Built motion from commit 092f8824.|2.5.49
[motion2.git] / server / api / whatsappMessage / whatsappMessage.controller.js
index 89b6a71..83b028d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xdcab=['fieldName','type','key','model','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','sort','pick','where','merge','VIRTUAL','filter','options','includeAll','include','findAll','show','params','find','create','body','describe','whatsapp-interactions','accept','whatsapp','read','readAt','format','UserId','user','agent','get','WhatsappInteraction','WhatsappInteractionId','YYYY-MM-DD\x20HH:mm:ss','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','interaction','null','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','Sequelize','QueryTypes','SELECT','contact','User','fullname','email','internal','interface','SIP/%s','channel','event','EventManager','acceptmessage','[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','ContactId','motionChannel','WhatsappAccount','WhatsappAccountId','WhatsppMessage,\x20%s,\x20%s,\x20%s','twilio','MessageSid','messageId','MessageStatus','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','socket.io-emitter','./whatsappMessage.socket','client','http','then','info','WhatsappMessage,\x20%s,\x20%s','debug','WhatsappMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','request\x20sent','result','catch','end','status','json','offset','limit','undefined','count','set','apply','reject','save','update','stack','name','send','index','WhatsappMessage','rawAttributes'];(function(_0x2e4093,_0x5486b4){var _0x316bb4=function(_0x463b18){while(--_0x463b18){_0x2e4093['push'](_0x2e4093['shift']());}};_0x316bb4(++_0x5486b4);}(_0xdcab,0x1e9));var _0xbdca=function(_0x420464,_0x4cc611){_0x420464=_0x420464-0x0;var _0x2473a6=_0xdcab[_0x420464];return _0x2473a6;};'use strict';var emlformat=require(_0xbdca('0x0'));var rimraf=require(_0xbdca('0x1'));var zipdir=require(_0xbdca('0x2'));var jsonpatch=require(_0xbdca('0x3'));var rp=require(_0xbdca('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xbdca('0x5'));var util=require(_0xbdca('0x6'));var path=require(_0xbdca('0x7'));var sox=require(_0xbdca('0x8'));var csv=require(_0xbdca('0x9'));var ejs=require(_0xbdca('0xa'));var fs=require('fs');var fs_extra=require(_0xbdca('0xb'));var _=require(_0xbdca('0xc'));var squel=require(_0xbdca('0xd'));var crypto=require(_0xbdca('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xbdca('0xf'));var toCsv=require('to-csv');var querystring=require(_0xbdca('0x10'));var Papa=require(_0xbdca('0x11'));var Redis=require(_0xbdca('0x12'));var authService=require(_0xbdca('0x13'));var qs=require(_0xbdca('0x14'));var as=require(_0xbdca('0x15'));var hardwareService=require(_0xbdca('0x16'));var logger=require(_0xbdca('0x17'))(_0xbdca('0x18'));var utils=require('../../config/utils');var config=require(_0xbdca('0x19'));var licenseUtil=require(_0xbdca('0x1a'));var db=require(_0xbdca('0x1b'))['db'];config[_0xbdca('0x1c')]=_['defaults'](config[_0xbdca('0x1c')],{'host':'localhost','port':0x18eb});var socket=require(_0xbdca('0x1d'))(new Redis(config[_0xbdca('0x1c')]));require(_0xbdca('0x1e'))['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0xbdca('0x1f')][_0xbdca('0x20')]({'port':0x232c});var client9002=jayson[_0xbdca('0x1f')][_0xbdca('0x20')]({'port':0x232a});function respondWithRpcPromise(_0x2a24f0,_0x133d8d,_0x5f54f5,_0x113a82){return new BPromise(function(_0x69ecf6,_0x244b41){var _0x3272ac=_0x113a82||client;return _0x3272ac['request'](_0x2a24f0,_0x5f54f5)[_0xbdca('0x21')](function(_0x90d3d){logger[_0xbdca('0x22')](_0xbdca('0x23'),_0x133d8d,'request\x20sent');logger[_0xbdca('0x24')](_0xbdca('0x25'),_0x133d8d,'request\x20sent',JSON[_0xbdca('0x26')](_0x90d3d));if(_0x90d3d[_0xbdca('0x27')]){if(_0x90d3d['error'][_0xbdca('0x28')]===0x1f4){logger[_0xbdca('0x27')](_0xbdca('0x23'),_0x133d8d,_0x90d3d[_0xbdca('0x27')][_0xbdca('0x29')]);return _0x244b41(_0x90d3d[_0xbdca('0x27')]['message']);}logger[_0xbdca('0x27')](_0xbdca('0x23'),_0x133d8d,_0x90d3d['error']['message']);return _0x69ecf6(_0x90d3d[_0xbdca('0x27')][_0xbdca('0x29')]);}else{logger[_0xbdca('0x22')](_0xbdca('0x23'),_0x133d8d,_0xbdca('0x2a'));_0x69ecf6(_0x90d3d[_0xbdca('0x2b')][_0xbdca('0x29')]);}})[_0xbdca('0x2c')](function(_0x3b260c){logger[_0xbdca('0x27')](_0xbdca('0x23'),_0x133d8d,_0x3b260c);_0x244b41(_0x3b260c);});});}function respondWithStatusCode(_0x5b3a00,_0x5ebea6){_0x5ebea6=_0x5ebea6||0xcc;return function(_0x4eecc1){if(_0x4eecc1){return _0x5b3a00['sendStatus'](_0x5ebea6);}return _0x5b3a00['status'](_0x5ebea6)[_0xbdca('0x2d')]();};}function respondWithResult(_0xe10981,_0x45113b){_0x45113b=_0x45113b||0xc8;return function(_0x267506){if(_0x267506){return _0xe10981[_0xbdca('0x2e')](_0x45113b)[_0xbdca('0x2f')](_0x267506);}};}function respondWithFilteredResult(_0x4c495e,_0x356bc7){return function(_0x170948){if(_0x170948){var _0x4cc9c6=typeof _0x356bc7[_0xbdca('0x30')]==='undefined'&&typeof _0x356bc7[_0xbdca('0x31')]===_0xbdca('0x32');var _0x22f403=_0x170948[_0xbdca('0x33')];var _0x47dbd2=_0x4cc9c6?0x0:_0x356bc7[_0xbdca('0x30')];var _0x1998d8=_0x4cc9c6?_0x170948[_0xbdca('0x33')]:_0x356bc7[_0xbdca('0x30')]+_0x356bc7[_0xbdca('0x31')];var _0x1b88b4;if(_0x1998d8>=_0x22f403){_0x1998d8=_0x22f403;_0x1b88b4=0xc8;}else{_0x1b88b4=0xce;}_0x4c495e['status'](_0x1b88b4);return _0x4c495e[_0xbdca('0x34')]('Content-Range',_0x47dbd2+'-'+_0x1998d8+'/'+_0x22f403)[_0xbdca('0x2f')](_0x170948);}return null;};}function patchUpdates(_0x1accc4){return function(_0x41a482){try{jsonpatch[_0xbdca('0x35')](_0x41a482,_0x1accc4,!![]);}catch(_0x34d66c){return BPromise[_0xbdca('0x36')](_0x34d66c);}return _0x41a482[_0xbdca('0x37')]();};}function saveUpdates(_0x4c50f9,_0x593447){return function(_0x55fa52){if(_0x55fa52){return _0x55fa52[_0xbdca('0x38')](_0x4c50f9)[_0xbdca('0x21')](function(_0x3adccb){return _0x3adccb;});}return null;};}function removeEntity(_0x57940a,_0x1a5f5f){return function(_0x41372c){if(_0x41372c){return _0x41372c['destroy']()['then'](function(){_0x57940a[_0xbdca('0x2e')](0xcc)[_0xbdca('0x2d')]();});}};}function handleEntityNotFound(_0x54d34e,_0x17c265){return function(_0x2fe862){if(!_0x2fe862){_0x54d34e['sendStatus'](0x194);}return _0x2fe862;};}function handleError(_0x1f54ec,_0x220ffc){_0x220ffc=_0x220ffc||0x1f4;return function(_0x11a714){logger[_0xbdca('0x27')](_0x11a714[_0xbdca('0x39')]);if(_0x11a714[_0xbdca('0x3a')]){delete _0x11a714['name'];}_0x1f54ec[_0xbdca('0x2e')](_0x220ffc)[_0xbdca('0x3b')](_0x11a714);};}exports[_0xbdca('0x3c')]=function(_0x3bf4d6,_0x3d2f2d){var _0x5240d6={},_0x3b5685={},_0x25594d={'count':0x0,'rows':[]};var _0xd01c7e=_['map'](db[_0xbdca('0x3d')][_0xbdca('0x3e')],function(_0x42a159){return{'name':_0x42a159[_0xbdca('0x3f')],'type':_0x42a159[_0xbdca('0x40')][_0xbdca('0x41')]};});_0x3b5685[_0xbdca('0x42')]=_[_0xbdca('0x43')](_0xd01c7e,_0xbdca('0x3a'));_0x3b5685[_0xbdca('0x44')]=_[_0xbdca('0x45')](_0x3bf4d6['query']);_0x3b5685[_0xbdca('0x46')]=_[_0xbdca('0x47')](_0x3b5685[_0xbdca('0x42')],_0x3b5685[_0xbdca('0x44')]);_0x5240d6[_0xbdca('0x48')]=_[_0xbdca('0x47')](_0x3b5685[_0xbdca('0x42')],qs[_0xbdca('0x49')](_0x3bf4d6[_0xbdca('0x44')][_0xbdca('0x49')]));_0x5240d6[_0xbdca('0x48')]=_0x5240d6[_0xbdca('0x48')][_0xbdca('0x4a')]?_0x5240d6[_0xbdca('0x48')]:_0x3b5685[_0xbdca('0x42')];if(!_0x3bf4d6[_0xbdca('0x44')][_0xbdca('0x4b')]('nolimit')){_0x5240d6[_0xbdca('0x31')]=qs['limit'](_0x3bf4d6[_0xbdca('0x44')][_0xbdca('0x31')]);_0x5240d6[_0xbdca('0x30')]=qs[_0xbdca('0x30')](_0x3bf4d6['query']['offset']);}_0x5240d6['order']=qs[_0xbdca('0x4c')](_0x3bf4d6[_0xbdca('0x44')]['sort']);_0x5240d6['where']=qs[_0xbdca('0x46')](_[_0xbdca('0x4d')](_0x3bf4d6[_0xbdca('0x44')],_0x3b5685[_0xbdca('0x46')]),_0xd01c7e);if(_0x3bf4d6[_0xbdca('0x44')]['filter']){_0x5240d6[_0xbdca('0x4e')]=_[_0xbdca('0x4f')](_0x5240d6[_0xbdca('0x4e')],{'$or':_[_0xbdca('0x43')](_0xd01c7e,function(_0x24caf2){if(_0x24caf2[_0xbdca('0x40')]!==_0xbdca('0x50')){var _0x128aa4={};_0x128aa4[_0x24caf2[_0xbdca('0x3a')]]={'$like':'%'+_0x3bf4d6[_0xbdca('0x44')][_0xbdca('0x51')]+'%'};return _0x128aa4;}})});}_0x5240d6=_[_0xbdca('0x4f')]({},_0x5240d6,_0x3bf4d6[_0xbdca('0x52')]);var _0x284c35={'where':_0x5240d6[_0xbdca('0x4e')]};return db[_0xbdca('0x3d')][_0xbdca('0x33')](_0x284c35)[_0xbdca('0x21')](function(_0x2139ff){_0x25594d[_0xbdca('0x33')]=_0x2139ff;if(_0x3bf4d6[_0xbdca('0x44')][_0xbdca('0x53')]){_0x5240d6[_0xbdca('0x54')]=[{'all':!![]}];}return db[_0xbdca('0x3d')][_0xbdca('0x55')](_0x5240d6);})[_0xbdca('0x21')](function(_0x5a0081){_0x25594d['rows']=_0x5a0081;return _0x25594d;})[_0xbdca('0x21')](respondWithFilteredResult(_0x3d2f2d,_0x5240d6))[_0xbdca('0x2c')](handleError(_0x3d2f2d,null));};exports[_0xbdca('0x56')]=function(_0x225796,_0x257c43){var _0x2df640={'raw':!![],'where':{'id':_0x225796[_0xbdca('0x57')]['id']}},_0x22fe0e={};_0x22fe0e[_0xbdca('0x42')]=_[_0xbdca('0x45')](db[_0xbdca('0x3d')][_0xbdca('0x3e')]);_0x22fe0e[_0xbdca('0x44')]=_[_0xbdca('0x45')](_0x225796[_0xbdca('0x44')]);_0x22fe0e[_0xbdca('0x46')]=_[_0xbdca('0x47')](_0x22fe0e[_0xbdca('0x42')],_0x22fe0e['query']);_0x2df640['attributes']=_[_0xbdca('0x47')](_0x22fe0e[_0xbdca('0x42')],qs[_0xbdca('0x49')](_0x225796[_0xbdca('0x44')][_0xbdca('0x49')]));_0x2df640[_0xbdca('0x48')]=_0x2df640[_0xbdca('0x48')]['length']?_0x2df640[_0xbdca('0x48')]:_0x22fe0e[_0xbdca('0x42')];if(_0x225796[_0xbdca('0x44')][_0xbdca('0x53')]){_0x2df640[_0xbdca('0x54')]=[{'all':!![]}];}_0x2df640=_[_0xbdca('0x4f')]({},_0x2df640,_0x225796['options']);return db[_0xbdca('0x3d')][_0xbdca('0x58')](_0x2df640)[_0xbdca('0x21')](handleEntityNotFound(_0x257c43,null))['then'](respondWithResult(_0x257c43,null))[_0xbdca('0x2c')](handleError(_0x257c43,null));};exports['create']=function(_0x2aa4ec,_0x25ca32){return db[_0xbdca('0x3d')][_0xbdca('0x59')](_0x2aa4ec[_0xbdca('0x5a')],{})[_0xbdca('0x21')](respondWithResult(_0x25ca32,0xc9))[_0xbdca('0x2c')](handleError(_0x25ca32,null));};exports['update']=function(_0x25bba4,_0x1a0bd5){if(_0x25bba4[_0xbdca('0x5a')]['id']){delete _0x25bba4[_0xbdca('0x5a')]['id'];}return db[_0xbdca('0x3d')][_0xbdca('0x58')]({'where':{'id':_0x25bba4[_0xbdca('0x57')]['id']}})['then'](handleEntityNotFound(_0x1a0bd5,null))['then'](saveUpdates(_0x25bba4[_0xbdca('0x5a')],null))[_0xbdca('0x21')](respondWithResult(_0x1a0bd5,null))[_0xbdca('0x2c')](handleError(_0x1a0bd5,null));};exports['destroy']=function(_0x2d1a1e,_0x479144){return db[_0xbdca('0x3d')][_0xbdca('0x58')]({'where':{'id':_0x2d1a1e['params']['id']}})[_0xbdca('0x21')](handleEntityNotFound(_0x479144,null))[_0xbdca('0x21')](removeEntity(_0x479144,null))[_0xbdca('0x2c')](handleError(_0x479144,null));};exports[_0xbdca('0x5b')]=function(_0x189d7a,_0x338755){return db[_0xbdca('0x3d')]['describe']()[_0xbdca('0x21')](respondWithResult(_0x338755,null))[_0xbdca('0x2c')](handleError(_0x338755,null));};var interaction_log=require(_0xbdca('0x17'))(_0xbdca('0x5c'));exports[_0xbdca('0x5d')]=function(_0x11d326,_0x279abb,_0x53f330){var _0xe56b25={'agent':{},'channel':_0xbdca('0x5e')};if(_0x11d326['body']['id']){delete _0x11d326['body']['id'];}_0x11d326['body'][_0xbdca('0x5f')]=!![];_0x11d326[_0xbdca('0x5a')][_0xbdca('0x60')]=moment()[_0xbdca('0x61')]('YYYY-MM-DD\x20HH:mm:ss');_0x11d326[_0xbdca('0x5a')][_0xbdca('0x62')]=_0x11d326[_0xbdca('0x5a')][_0xbdca('0x62')]||_0x11d326[_0xbdca('0x63')]['id'];_0xe56b25[_0xbdca('0x64')]['id']=_0x11d326[_0xbdca('0x5a')][_0xbdca('0x62')];return db[_0xbdca('0x3d')][_0xbdca('0x58')]({'where':{'id':_0x11d326[_0xbdca('0x57')]['id'],'UserId':null}})[_0xbdca('0x21')](handleEntityNotFound(_0x279abb,null))['then'](saveUpdates(_0x11d326[_0xbdca('0x5a')],null))[_0xbdca('0x21')](function(_0x5ed8ca){if(_0x5ed8ca){_0xe56b25[_0xbdca('0x29')]=_0x5ed8ca[_0xbdca('0x65')]({'plain':!![]});return db[_0xbdca('0x66')][_0xbdca('0x58')]({'where':{'id':_0x5ed8ca[_0xbdca('0x67')]}});}return null;})[_0xbdca('0x21')](handleEntityNotFound(_0x279abb,null))[_0xbdca('0x21')](function(_0x60c1e9){if(_0x60c1e9){return _0x60c1e9[_0xbdca('0x38')]({'UserId':_0x11d326[_0xbdca('0x5a')]['UserId'],'read1stAt':_['isNil'](_0x60c1e9['read1stAt'])?moment()[_0xbdca('0x61')](_0xbdca('0x68')):undefined});}return null;})[_0xbdca('0x21')](function(_0x389dd5){if(_0x389dd5){_0xe56b25['interaction']=_0x389dd5[_0xbdca('0x65')]({'plain':!![]});interaction_log['info'](_0xbdca('0x69'),_0x11d326[_0xbdca('0x63')]['id'],_0x11d326[_0xbdca('0x63')][_0xbdca('0x3a')],_0x11d326['user'][_0xbdca('0x6a')],_0xe56b25[_0xbdca('0x6b')]['id'],_0x11d326[_0xbdca('0x5a')]?JSON[_0xbdca('0x26')](_0x11d326[_0xbdca('0x5a')]):_0xbdca('0x6c'));return respondWithRpcPromise('AcceptMessage',_0xbdca('0x6d'),_0xe56b25);}return null;})[_0xbdca('0x21')](function(_0x2b1767){var _0x59f53b=_0xbdca('0x6e')+_0x2b1767[_0xbdca('0x29')]['ContactId'];return db[_0xbdca('0x6f')][_0xbdca('0x44')](_0x59f53b,{'type':db[_0xbdca('0x70')][_0xbdca('0x71')][_0xbdca('0x72')],'raw':!![]})[_0xbdca('0x21')](function(_0x1319a8){return _0x1319a8;});})[_0xbdca('0x21')](function(_0x3f47f6){if(_0x3f47f6){_0xe56b25[_0xbdca('0x29')][_0xbdca('0x73')]=_0x3f47f6[0x0];if(!_0x11d326['body'][_0xbdca('0x62')])return;return db[_0xbdca('0x74')]['find']({'where':{'id':_0x11d326[_0xbdca('0x5a')]['UserId'],'role':'agent'},'attributes':['id',_0xbdca('0x3a'),_0xbdca('0x75'),_0xbdca('0x76'),_0xbdca('0x77')],'raw':!![]});}return null;})['then'](function(_0x3ba499){if(!_0x3ba499)return null;_0xe56b25['message'][_0xbdca('0x64')]=_0x3ba499;return _0xe56b25;})[_0xbdca('0x21')](function(_0x55b889){if(_0x55b889){if(_0x11d326[_0xbdca('0x5a')]['manual']){_0xe56b25[_0xbdca('0x29')][_0xbdca('0x78')]=util[_0xbdca('0x61')](_0xbdca('0x79'),_0x11d326['user'][_0xbdca('0x3a')]);_0xe56b25[_0xbdca('0x29')][_0xbdca('0x7a')]=_0xe56b25[_0xbdca('0x7a')];_0xe56b25[_0xbdca('0x29')]['motionChannel']=_0xe56b25[_0xbdca('0x7a')];_0xe56b25[_0xbdca('0x29')][_0xbdca('0x7b')]=_0xbdca('0x5d');return respondWithRpcPromise(_0xbdca('0x7c'),'EventManager',{'event':_0xbdca('0x7d'),'message':_0xe56b25[_0xbdca('0x29')]},client9002)['then'](function(){return _0xe56b25;});}return _0xe56b25;}return null;})['then'](respondWithResult(_0x279abb,null))[_0xbdca('0x2c')](handleError(_0x279abb,null));};var interaction_log=require(_0xbdca('0x17'))(_0xbdca('0x5c'));exports['reject']=function(_0x343cbb,_0x1bf02d,_0x19bf4a){var _0x266360={'agent':{},'channel':_0xbdca('0x5e')};if(_0x343cbb[_0xbdca('0x5a')]['id']){delete _0x343cbb[_0xbdca('0x5a')]['id'];}_0x343cbb[_0xbdca('0x5a')][_0xbdca('0x62')]=_0x343cbb[_0xbdca('0x5a')][_0xbdca('0x62')]||_0x343cbb[_0xbdca('0x63')]['id'];_0x266360[_0xbdca('0x64')]['id']=_0x343cbb[_0xbdca('0x5a')][_0xbdca('0x62')];return db['WhatsappMessage'][_0xbdca('0x58')]({'where':{'id':_0x343cbb[_0xbdca('0x57')]['id'],'UserId':null}})[_0xbdca('0x21')](handleEntityNotFound(_0x1bf02d,null))[_0xbdca('0x21')](function(_0x3a16dd){if(_0x3a16dd){_0x266360[_0xbdca('0x29')]=_0x3a16dd['get']({'plain':!![]});return db[_0xbdca('0x66')][_0xbdca('0x58')]({'where':{'id':_0x3a16dd[_0xbdca('0x67')]}});}return null;})['then'](handleEntityNotFound(_0x1bf02d,null))[_0xbdca('0x21')](function(_0x29353c){if(_0x29353c){_0x266360[_0xbdca('0x6b')]=_0x29353c['get']({'plain':!![]});interaction_log['info'](_0xbdca('0x7e'),_0x343cbb[_0xbdca('0x63')]['id'],_0x343cbb[_0xbdca('0x63')]['name'],_0x343cbb[_0xbdca('0x63')][_0xbdca('0x6a')],_0x266360['interaction']['id'],_0x343cbb[_0xbdca('0x5a')]?JSON[_0xbdca('0x26')](_0x343cbb[_0xbdca('0x5a')]):_0xbdca('0x6c'));return respondWithRpcPromise(_0xbdca('0x7f'),_0xbdca('0x80'),_0x266360);}return null;})[_0xbdca('0x21')](function(_0x28a6dc){var _0x1c9cb7=_0xbdca('0x6e')+_0x28a6dc[_0xbdca('0x29')][_0xbdca('0x81')];return db['sequelize'][_0xbdca('0x44')](_0x1c9cb7,{'type':db['Sequelize'][_0xbdca('0x71')][_0xbdca('0x72')],'raw':!![]})[_0xbdca('0x21')](function(_0x30b7ca){return _0x30b7ca;});})['then'](function(_0x4aaee6){if(_0x4aaee6){_0x266360[_0xbdca('0x29')][_0xbdca('0x73')]=_0x4aaee6[0x0];if(!_0x343cbb[_0xbdca('0x5a')][_0xbdca('0x62')])return;return db[_0xbdca('0x74')][_0xbdca('0x58')]({'where':{'id':_0x343cbb[_0xbdca('0x5a')][_0xbdca('0x62')],'role':_0xbdca('0x64')},'attributes':['id',_0xbdca('0x3a'),_0xbdca('0x75'),_0xbdca('0x76'),_0xbdca('0x77')],'raw':!![]});}return null;})['then'](function(_0x3f4a15){if(!_0x3f4a15)return null;_0x266360[_0xbdca('0x29')]['agent']=_0x3f4a15;return _0x266360;})[_0xbdca('0x21')](function(_0xc9ff01){if(_0xc9ff01){_0xc9ff01[_0xbdca('0x29')][_0xbdca('0x78')]=util[_0xbdca('0x61')]('SIP/%s',_0x343cbb[_0xbdca('0x63')][_0xbdca('0x3a')]);_0xc9ff01['message'][_0xbdca('0x7a')]=_0x266360[_0xbdca('0x7a')];_0xc9ff01[_0xbdca('0x29')][_0xbdca('0x82')]=_0x266360[_0xbdca('0x7a')];_0xc9ff01['message'][_0xbdca('0x7b')]=_0xbdca('0x36');respondWithRpcPromise(_0xbdca('0x7c'),_0xbdca('0x7c'),{'event':'rejectmessage','message':_0xc9ff01[_0xbdca('0x29')]},client9002);return _0x266360;}return null;})[_0xbdca('0x21')](respondWithResult(_0x1bf02d,null))[_0xbdca('0x2c')](handleError(_0x1bf02d,null));};exports[_0xbdca('0x2e')]=function(_0x4eb5ff,_0x3ddbd7,_0xc4b49f){if(_0x4eb5ff[_0xbdca('0x5a')]['id']){delete _0x4eb5ff[_0xbdca('0x5a')]['id'];}var _0x5658b5;return db[_0xbdca('0x3d')][_0xbdca('0x58')]({'where':{'id':_0x4eb5ff['params']['id']}})[_0xbdca('0x21')](handleEntityNotFound(_0x3ddbd7,null))[_0xbdca('0x21')](function(_0x505127){if(_0x505127){_0x5658b5=_0x505127;return db[_0xbdca('0x83')][_0xbdca('0x58')]({'where':{'id':_0x505127[_0xbdca('0x84')]}});}})[_0xbdca('0x21')](handleEntityNotFound(_0x3ddbd7,null))['then'](function(_0x7f8428){if(_0x7f8428){logger[_0xbdca('0x24')](_0xbdca('0x85'),'status','received\x20delivery\x20report\x20from',_0x7f8428[_0xbdca('0x40')],util['inspect'](_0x4eb5ff[_0xbdca('0x5a')],{'showHidden':![],'depth':null}));switch(_0x7f8428[_0xbdca('0x40')]){case _0xbdca('0x86'):if(_0x4eb5ff['body'][_0xbdca('0x87')]&&_0x4eb5ff[_0xbdca('0x5a')][_0xbdca('0x87')]===_0x5658b5[_0xbdca('0x88')]&&_0x4eb5ff[_0xbdca('0x5a')][_0xbdca('0x89')]&&_0x4eb5ff['body'][_0xbdca('0x89')]==='read'){return _0x5658b5[_0xbdca('0x38')]({'read':!![]});}else{logger[_0xbdca('0x27')]('WhatsappAccount,\x20%s,\x20%s,\x20%s',_0xbdca('0x2e'),'twilio',util['inspect'](_0x4eb5ff[_0xbdca('0x5a')],{'showHidden':![],'depth':null}));}break;}return _0x5658b5;}})[_0xbdca('0x21')](respondWithResult(_0x3ddbd7,null))['catch'](handleError(_0x3ddbd7,null));};
\ No newline at end of file
+var _0x0c2e=['map','WhatsappMessage','rawAttributes','type','key','model','query','keys','filters','intersection','attributes','length','hasOwnProperty','nolimit','sort','pick','filter','where','merge','VIRTUAL','include','findAll','rows','params','fields','includeAll','options','find','body','describe','whatsapp-interactions','whatsapp','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','get','WhatsappInteraction','WhatsappInteractionId','isNil','interaction','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','user','role','null','AcceptMessage','acceptMessage','ContactId','sequelize','Sequelize','QueryTypes','SELECT','contact','email','agent','manual','interface','SIP/%s','channel','motionChannel','accept','EventManager','acceptmessage','[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','stringify','rejectMessage','User','fullname','rejectmessage','WhatsappAccountId','WhatsppMessage,\x20%s,\x20%s,\x20%s','received\x20delivery\x20report\x20from','MessageSid','messageId','MessageStatus','twilio','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','ejs','lodash','squel','crypto','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/license/util','defaults','redis','localhost','socket.io-emitter','./whatsappMessage.socket','register','http','client','request','info','WhatsappMessage,\x20%s,\x20%s','request\x20sent','debug','WhatsappMessage,\x20%s,\x20%s,\x20%s','error','code','message','result','catch','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','name','send','index'];(function(_0x1caf48,_0x5663a2){var _0x4d2fe3=function(_0x567700){while(--_0x567700){_0x1caf48['push'](_0x1caf48['shift']());}};_0x4d2fe3(++_0x5663a2);}(_0x0c2e,0x1ee));var _0xe0c2=function(_0x149ffc,_0x46ad7a){_0x149ffc=_0x149ffc-0x0;var _0x31eb53=_0x0c2e[_0x149ffc];return _0x31eb53;};'use strict';var emlformat=require(_0xe0c2('0x0'));var rimraf=require(_0xe0c2('0x1'));var zipdir=require(_0xe0c2('0x2'));var jsonpatch=require(_0xe0c2('0x3'));var rp=require(_0xe0c2('0x4'));var moment=require(_0xe0c2('0x5'));var BPromise=require(_0xe0c2('0x6'));var Mustache=require(_0xe0c2('0x7'));var util=require(_0xe0c2('0x8'));var path=require('path');var sox=require(_0xe0c2('0x9'));var csv=require('to-csv');var ejs=require(_0xe0c2('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xe0c2('0xb'));var squel=require(_0xe0c2('0xc'));var crypto=require(_0xe0c2('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xe0c2('0xe'));var querystring=require('querystring');var Papa=require(_0xe0c2('0xf'));var Redis=require(_0xe0c2('0x10'));var authService=require(_0xe0c2('0x11'));var qs=require(_0xe0c2('0x12'));var as=require(_0xe0c2('0x13'));var hardwareService=require(_0xe0c2('0x14'));var logger=require(_0xe0c2('0x15'))(_0xe0c2('0x16'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xe0c2('0x17'));var db=require('../../mysqldb')['db'];config['redis']=_[_0xe0c2('0x18')](config[_0xe0c2('0x19')],{'host':_0xe0c2('0x1a'),'port':0x18eb});var socket=require(_0xe0c2('0x1b'))(new Redis(config[_0xe0c2('0x19')]));require(_0xe0c2('0x1c'))[_0xe0c2('0x1d')](socket);var jayson=require('jayson/promise');var client=jayson['client'][_0xe0c2('0x1e')]({'port':0x232c});var client9002=jayson[_0xe0c2('0x1f')][_0xe0c2('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x4e5549,_0x20c59d,_0x2f1033,_0x5405ab){return new BPromise(function(_0x2d09ea,_0x47cecd){var _0x15473c=_0x5405ab||client;return _0x15473c[_0xe0c2('0x20')](_0x4e5549,_0x2f1033)['then'](function(_0x1a9e41){logger[_0xe0c2('0x21')](_0xe0c2('0x22'),_0x20c59d,_0xe0c2('0x23'));logger[_0xe0c2('0x24')](_0xe0c2('0x25'),_0x20c59d,'request\x20sent',JSON['stringify'](_0x1a9e41));if(_0x1a9e41[_0xe0c2('0x26')]){if(_0x1a9e41[_0xe0c2('0x26')][_0xe0c2('0x27')]===0x1f4){logger['error'](_0xe0c2('0x22'),_0x20c59d,_0x1a9e41[_0xe0c2('0x26')][_0xe0c2('0x28')]);return _0x47cecd(_0x1a9e41['error'][_0xe0c2('0x28')]);}logger['error']('WhatsappMessage,\x20%s,\x20%s',_0x20c59d,_0x1a9e41[_0xe0c2('0x26')]['message']);return _0x2d09ea(_0x1a9e41['error'][_0xe0c2('0x28')]);}else{logger[_0xe0c2('0x21')](_0xe0c2('0x22'),_0x20c59d,_0xe0c2('0x23'));_0x2d09ea(_0x1a9e41[_0xe0c2('0x29')]['message']);}})[_0xe0c2('0x2a')](function(_0x5b18f0){logger[_0xe0c2('0x26')](_0xe0c2('0x22'),_0x20c59d,_0x5b18f0);_0x47cecd(_0x5b18f0);});});}function respondWithStatusCode(_0x3ade78,_0x44b457){_0x44b457=_0x44b457||0xcc;return function(_0x34c2f5){if(_0x34c2f5){return _0x3ade78[_0xe0c2('0x2b')](_0x44b457);}return _0x3ade78[_0xe0c2('0x2c')](_0x44b457)[_0xe0c2('0x2d')]();};}function respondWithResult(_0x57901b,_0x4b4d6a){_0x4b4d6a=_0x4b4d6a||0xc8;return function(_0x333dc3){if(_0x333dc3){return _0x57901b[_0xe0c2('0x2c')](_0x4b4d6a)[_0xe0c2('0x2e')](_0x333dc3);}};}function respondWithFilteredResult(_0x322be9,_0x265854){return function(_0x34e73a){if(_0x34e73a){var _0x19950b=typeof _0x265854[_0xe0c2('0x2f')]===_0xe0c2('0x30')&&typeof _0x265854[_0xe0c2('0x31')]===_0xe0c2('0x30');var _0x16a869=_0x34e73a[_0xe0c2('0x32')];var _0x48833e=_0x19950b?0x0:_0x265854[_0xe0c2('0x2f')];var _0x1b4595=_0x19950b?_0x34e73a[_0xe0c2('0x32')]:_0x265854[_0xe0c2('0x2f')]+_0x265854[_0xe0c2('0x31')];var _0xc15835;if(_0x1b4595>=_0x16a869){_0x1b4595=_0x16a869;_0xc15835=0xc8;}else{_0xc15835=0xce;}_0x322be9[_0xe0c2('0x2c')](_0xc15835);return _0x322be9[_0xe0c2('0x33')](_0xe0c2('0x34'),_0x48833e+'-'+_0x1b4595+'/'+_0x16a869)[_0xe0c2('0x2e')](_0x34e73a);}return null;};}function patchUpdates(_0xb9070c){return function(_0x257ab4){try{jsonpatch[_0xe0c2('0x35')](_0x257ab4,_0xb9070c,!![]);}catch(_0x2c6c2a){return BPromise[_0xe0c2('0x36')](_0x2c6c2a);}return _0x257ab4[_0xe0c2('0x37')]();};}function saveUpdates(_0x2a96db,_0x2f86d7){return function(_0x2a36ad){if(_0x2a36ad){return _0x2a36ad[_0xe0c2('0x38')](_0x2a96db)[_0xe0c2('0x39')](function(_0xea0983){return _0xea0983;});}return null;};}function removeEntity(_0x3697dd,_0x901844){return function(_0x1e92ff){if(_0x1e92ff){return _0x1e92ff[_0xe0c2('0x3a')]()[_0xe0c2('0x39')](function(){_0x3697dd[_0xe0c2('0x2c')](0xcc)[_0xe0c2('0x2d')]();});}};}function handleEntityNotFound(_0x1abb5f,_0x3e0eed){return function(_0x5bf95b){if(!_0x5bf95b){_0x1abb5f[_0xe0c2('0x2b')](0x194);}return _0x5bf95b;};}function handleError(_0x3d15fa,_0x3155d9){_0x3155d9=_0x3155d9||0x1f4;return function(_0x2134d7){logger[_0xe0c2('0x26')](_0x2134d7['stack']);if(_0x2134d7[_0xe0c2('0x3b')]){delete _0x2134d7[_0xe0c2('0x3b')];}_0x3d15fa[_0xe0c2('0x2c')](_0x3155d9)[_0xe0c2('0x3c')](_0x2134d7);};}exports[_0xe0c2('0x3d')]=function(_0x305887,_0xfa8ffe){var _0x462e6a={},_0x19bc7b={},_0x4a700e={'count':0x0,'rows':[]};var _0x7d3125=_[_0xe0c2('0x3e')](db[_0xe0c2('0x3f')][_0xe0c2('0x40')],function(_0x5c1392){return{'name':_0x5c1392['fieldName'],'type':_0x5c1392[_0xe0c2('0x41')][_0xe0c2('0x42')]};});_0x19bc7b[_0xe0c2('0x43')]=_['map'](_0x7d3125,_0xe0c2('0x3b'));_0x19bc7b[_0xe0c2('0x44')]=_[_0xe0c2('0x45')](_0x305887['query']);_0x19bc7b[_0xe0c2('0x46')]=_[_0xe0c2('0x47')](_0x19bc7b['model'],_0x19bc7b[_0xe0c2('0x44')]);_0x462e6a[_0xe0c2('0x48')]=_[_0xe0c2('0x47')](_0x19bc7b[_0xe0c2('0x43')],qs['fields'](_0x305887[_0xe0c2('0x44')]['fields']));_0x462e6a['attributes']=_0x462e6a[_0xe0c2('0x48')][_0xe0c2('0x49')]?_0x462e6a['attributes']:_0x19bc7b[_0xe0c2('0x43')];if(!_0x305887['query'][_0xe0c2('0x4a')](_0xe0c2('0x4b'))){_0x462e6a[_0xe0c2('0x31')]=qs[_0xe0c2('0x31')](_0x305887[_0xe0c2('0x44')]['limit']);_0x462e6a[_0xe0c2('0x2f')]=qs['offset'](_0x305887[_0xe0c2('0x44')][_0xe0c2('0x2f')]);}_0x462e6a['order']=qs[_0xe0c2('0x4c')](_0x305887[_0xe0c2('0x44')]['sort']);_0x462e6a['where']=qs[_0xe0c2('0x46')](_[_0xe0c2('0x4d')](_0x305887[_0xe0c2('0x44')],_0x19bc7b[_0xe0c2('0x46')]),_0x7d3125);if(_0x305887[_0xe0c2('0x44')][_0xe0c2('0x4e')]){_0x462e6a[_0xe0c2('0x4f')]=_[_0xe0c2('0x50')](_0x462e6a['where'],{'$or':_[_0xe0c2('0x3e')](_0x7d3125,function(_0x4eeeba){if(_0x4eeeba[_0xe0c2('0x41')]!==_0xe0c2('0x51')){var _0x5e16d2={};_0x5e16d2[_0x4eeeba[_0xe0c2('0x3b')]]={'$like':'%'+_0x305887[_0xe0c2('0x44')]['filter']+'%'};return _0x5e16d2;}})});}_0x462e6a=_[_0xe0c2('0x50')]({},_0x462e6a,_0x305887['options']);var _0x3415fc={'where':_0x462e6a[_0xe0c2('0x4f')]};return db[_0xe0c2('0x3f')][_0xe0c2('0x32')](_0x3415fc)[_0xe0c2('0x39')](function(_0x38a795){_0x4a700e[_0xe0c2('0x32')]=_0x38a795;if(_0x305887[_0xe0c2('0x44')]['includeAll']){_0x462e6a[_0xe0c2('0x52')]=[{'all':!![]}];}return db['WhatsappMessage'][_0xe0c2('0x53')](_0x462e6a);})[_0xe0c2('0x39')](function(_0x9491e7){_0x4a700e[_0xe0c2('0x54')]=_0x9491e7;return _0x4a700e;})[_0xe0c2('0x39')](respondWithFilteredResult(_0xfa8ffe,_0x462e6a))['catch'](handleError(_0xfa8ffe,null));};exports['show']=function(_0x12907a,_0x272047){var _0x6d3cab={'raw':!![],'where':{'id':_0x12907a[_0xe0c2('0x55')]['id']}},_0x16b873={};_0x16b873[_0xe0c2('0x43')]=_['keys'](db[_0xe0c2('0x3f')][_0xe0c2('0x40')]);_0x16b873[_0xe0c2('0x44')]=_[_0xe0c2('0x45')](_0x12907a[_0xe0c2('0x44')]);_0x16b873['filters']=_[_0xe0c2('0x47')](_0x16b873['model'],_0x16b873[_0xe0c2('0x44')]);_0x6d3cab['attributes']=_[_0xe0c2('0x47')](_0x16b873[_0xe0c2('0x43')],qs['fields'](_0x12907a[_0xe0c2('0x44')][_0xe0c2('0x56')]));_0x6d3cab[_0xe0c2('0x48')]=_0x6d3cab['attributes'][_0xe0c2('0x49')]?_0x6d3cab[_0xe0c2('0x48')]:_0x16b873[_0xe0c2('0x43')];if(_0x12907a[_0xe0c2('0x44')][_0xe0c2('0x57')]){_0x6d3cab[_0xe0c2('0x52')]=[{'all':!![]}];}_0x6d3cab=_['merge']({},_0x6d3cab,_0x12907a[_0xe0c2('0x58')]);return db[_0xe0c2('0x3f')][_0xe0c2('0x59')](_0x6d3cab)[_0xe0c2('0x39')](handleEntityNotFound(_0x272047,null))[_0xe0c2('0x39')](respondWithResult(_0x272047,null))[_0xe0c2('0x2a')](handleError(_0x272047,null));};exports['create']=function(_0x830c1b,_0x1af0d5){return db[_0xe0c2('0x3f')]['create'](_0x830c1b[_0xe0c2('0x5a')],{})['then'](respondWithResult(_0x1af0d5,0xc9))[_0xe0c2('0x2a')](handleError(_0x1af0d5,null));};exports[_0xe0c2('0x38')]=function(_0x388c44,_0x579984){if(_0x388c44[_0xe0c2('0x5a')]['id']){delete _0x388c44[_0xe0c2('0x5a')]['id'];}return db[_0xe0c2('0x3f')][_0xe0c2('0x59')]({'where':{'id':_0x388c44['params']['id']}})['then'](handleEntityNotFound(_0x579984,null))[_0xe0c2('0x39')](saveUpdates(_0x388c44[_0xe0c2('0x5a')],null))['then'](respondWithResult(_0x579984,null))[_0xe0c2('0x2a')](handleError(_0x579984,null));};exports[_0xe0c2('0x3a')]=function(_0x41862d,_0x34c0ba){return db[_0xe0c2('0x3f')][_0xe0c2('0x59')]({'where':{'id':_0x41862d['params']['id']}})[_0xe0c2('0x39')](handleEntityNotFound(_0x34c0ba,null))[_0xe0c2('0x39')](removeEntity(_0x34c0ba,null))[_0xe0c2('0x2a')](handleError(_0x34c0ba,null));};exports[_0xe0c2('0x5b')]=function(_0x319cbc,_0x33e372){return db[_0xe0c2('0x3f')][_0xe0c2('0x5b')]()[_0xe0c2('0x39')](respondWithResult(_0x33e372,null))[_0xe0c2('0x2a')](handleError(_0x33e372,null));};var interaction_log=require(_0xe0c2('0x15'))(_0xe0c2('0x5c'));exports['accept']=function(_0x2c413e,_0x1d5035,_0x27c019){var _0x54cbf6={'agent':{},'channel':_0xe0c2('0x5d')};if(_0x2c413e[_0xe0c2('0x5a')]['id']){delete _0x2c413e['body']['id'];}_0x2c413e['body'][_0xe0c2('0x5e')]=!![];_0x2c413e['body'][_0xe0c2('0x5f')]=moment()[_0xe0c2('0x60')](_0xe0c2('0x61'));_0x2c413e[_0xe0c2('0x5a')][_0xe0c2('0x62')]=_0x2c413e[_0xe0c2('0x5a')][_0xe0c2('0x62')]||_0x2c413e['user']['id'];_0x54cbf6['agent']['id']=_0x2c413e[_0xe0c2('0x5a')]['UserId'];return db[_0xe0c2('0x3f')][_0xe0c2('0x59')]({'where':{'id':_0x2c413e[_0xe0c2('0x55')]['id'],'UserId':null}})[_0xe0c2('0x39')](handleEntityNotFound(_0x1d5035,null))[_0xe0c2('0x39')](saveUpdates(_0x2c413e[_0xe0c2('0x5a')],null))[_0xe0c2('0x39')](function(_0x467427){if(_0x467427){_0x54cbf6[_0xe0c2('0x28')]=_0x467427[_0xe0c2('0x63')]({'plain':!![]});return db[_0xe0c2('0x64')][_0xe0c2('0x59')]({'where':{'id':_0x467427[_0xe0c2('0x65')]}});}return null;})[_0xe0c2('0x39')](handleEntityNotFound(_0x1d5035,null))[_0xe0c2('0x39')](function(_0x5cab7c){if(_0x5cab7c){return _0x5cab7c[_0xe0c2('0x38')]({'UserId':_0x2c413e[_0xe0c2('0x5a')][_0xe0c2('0x62')],'read1stAt':_[_0xe0c2('0x66')](_0x5cab7c['read1stAt'])?moment()['format'](_0xe0c2('0x61')):undefined});}return null;})[_0xe0c2('0x39')](function(_0x4ce0f6){if(_0x4ce0f6){_0x54cbf6[_0xe0c2('0x67')]=_0x4ce0f6['get']({'plain':!![]});interaction_log['info'](_0xe0c2('0x68'),_0x2c413e[_0xe0c2('0x69')]['id'],_0x2c413e[_0xe0c2('0x69')][_0xe0c2('0x3b')],_0x2c413e[_0xe0c2('0x69')][_0xe0c2('0x6a')],_0x54cbf6[_0xe0c2('0x67')]['id'],_0x2c413e[_0xe0c2('0x5a')]?JSON['stringify'](_0x2c413e[_0xe0c2('0x5a')]):_0xe0c2('0x6b'));return respondWithRpcPromise(_0xe0c2('0x6c'),_0xe0c2('0x6d'),_0x54cbf6);}return null;})[_0xe0c2('0x39')](function(_0x22a54c){var _0x360e75='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x22a54c[_0xe0c2('0x28')][_0xe0c2('0x6e')];return db[_0xe0c2('0x6f')][_0xe0c2('0x44')](_0x360e75,{'type':db[_0xe0c2('0x70')][_0xe0c2('0x71')][_0xe0c2('0x72')],'raw':!![]})[_0xe0c2('0x39')](function(_0x4c99a8){return _0x4c99a8;});})['then'](function(_0x216ee5){if(_0x216ee5){_0x54cbf6[_0xe0c2('0x28')][_0xe0c2('0x73')]=_0x216ee5[0x0];if(!_0x2c413e[_0xe0c2('0x5a')][_0xe0c2('0x62')])return;return db['User'][_0xe0c2('0x59')]({'where':{'id':_0x2c413e[_0xe0c2('0x5a')]['UserId'],'role':'agent'},'attributes':['id',_0xe0c2('0x3b'),'fullname',_0xe0c2('0x74'),'internal'],'raw':!![]});}return null;})[_0xe0c2('0x39')](function(_0x497520){if(!_0x497520)return null;_0x54cbf6[_0xe0c2('0x28')][_0xe0c2('0x75')]=_0x497520;return _0x54cbf6;})['then'](function(_0x517a98){if(_0x517a98){if(_0x2c413e[_0xe0c2('0x5a')][_0xe0c2('0x76')]){_0x54cbf6['message'][_0xe0c2('0x77')]=util[_0xe0c2('0x60')](_0xe0c2('0x78'),_0x2c413e[_0xe0c2('0x69')]['name']);_0x54cbf6[_0xe0c2('0x28')]['channel']=_0x54cbf6[_0xe0c2('0x79')];_0x54cbf6['message'][_0xe0c2('0x7a')]=_0x54cbf6[_0xe0c2('0x79')];_0x54cbf6['message']['event']=_0xe0c2('0x7b');return respondWithRpcPromise('EventManager',_0xe0c2('0x7c'),{'event':_0xe0c2('0x7d'),'message':_0x54cbf6['message']},client9002)[_0xe0c2('0x39')](function(){return _0x54cbf6;});}return _0x54cbf6;}return null;})[_0xe0c2('0x39')](respondWithResult(_0x1d5035,null))[_0xe0c2('0x2a')](handleError(_0x1d5035,null));};var interaction_log=require(_0xe0c2('0x15'))(_0xe0c2('0x5c'));exports[_0xe0c2('0x36')]=function(_0x1ea972,_0x285b99,_0x3190ea){var _0x149b40={'agent':{},'channel':_0xe0c2('0x5d')};if(_0x1ea972[_0xe0c2('0x5a')]['id']){delete _0x1ea972[_0xe0c2('0x5a')]['id'];}_0x1ea972['body']['UserId']=_0x1ea972[_0xe0c2('0x5a')][_0xe0c2('0x62')]||_0x1ea972[_0xe0c2('0x69')]['id'];_0x149b40[_0xe0c2('0x75')]['id']=_0x1ea972['body']['UserId'];return db['WhatsappMessage'][_0xe0c2('0x59')]({'where':{'id':_0x1ea972[_0xe0c2('0x55')]['id'],'UserId':null}})[_0xe0c2('0x39')](handleEntityNotFound(_0x285b99,null))[_0xe0c2('0x39')](function(_0x1f1202){if(_0x1f1202){_0x149b40['message']=_0x1f1202['get']({'plain':!![]});return db[_0xe0c2('0x64')][_0xe0c2('0x59')]({'where':{'id':_0x1f1202['WhatsappInteractionId']}});}return null;})[_0xe0c2('0x39')](handleEntityNotFound(_0x285b99,null))[_0xe0c2('0x39')](function(_0x35201e){if(_0x35201e){_0x149b40['interaction']=_0x35201e['get']({'plain':!![]});interaction_log[_0xe0c2('0x21')](_0xe0c2('0x7e'),_0x1ea972[_0xe0c2('0x69')]['id'],_0x1ea972[_0xe0c2('0x69')][_0xe0c2('0x3b')],_0x1ea972[_0xe0c2('0x69')][_0xe0c2('0x6a')],_0x149b40['interaction']['id'],_0x1ea972[_0xe0c2('0x5a')]?JSON[_0xe0c2('0x7f')](_0x1ea972['body']):'null');return respondWithRpcPromise('RejectMessage',_0xe0c2('0x80'),_0x149b40);}return null;})['then'](function(_0x5784d4){var _0x276d8c='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x5784d4[_0xe0c2('0x28')][_0xe0c2('0x6e')];return db['sequelize'][_0xe0c2('0x44')](_0x276d8c,{'type':db[_0xe0c2('0x70')][_0xe0c2('0x71')][_0xe0c2('0x72')],'raw':!![]})[_0xe0c2('0x39')](function(_0x33727d){return _0x33727d;});})['then'](function(_0x43432c){if(_0x43432c){_0x149b40[_0xe0c2('0x28')][_0xe0c2('0x73')]=_0x43432c[0x0];if(!_0x1ea972['body'][_0xe0c2('0x62')])return;return db[_0xe0c2('0x81')]['find']({'where':{'id':_0x1ea972[_0xe0c2('0x5a')][_0xe0c2('0x62')],'role':_0xe0c2('0x75')},'attributes':['id',_0xe0c2('0x3b'),_0xe0c2('0x82'),'email','internal'],'raw':!![]});}return null;})[_0xe0c2('0x39')](function(_0x1d92c7){if(!_0x1d92c7)return null;_0x149b40[_0xe0c2('0x28')]['agent']=_0x1d92c7;return _0x149b40;})[_0xe0c2('0x39')](function(_0xdbe979){if(_0xdbe979){_0xdbe979[_0xe0c2('0x28')]['interface']=util[_0xe0c2('0x60')](_0xe0c2('0x78'),_0x1ea972['user']['name']);_0xdbe979[_0xe0c2('0x28')]['channel']=_0x149b40[_0xe0c2('0x79')];_0xdbe979['message'][_0xe0c2('0x7a')]=_0x149b40['channel'];_0xdbe979[_0xe0c2('0x28')]['event']=_0xe0c2('0x36');respondWithRpcPromise(_0xe0c2('0x7c'),_0xe0c2('0x7c'),{'event':_0xe0c2('0x83'),'message':_0xdbe979[_0xe0c2('0x28')]},client9002);return _0x149b40;}return null;})[_0xe0c2('0x39')](respondWithResult(_0x285b99,null))[_0xe0c2('0x2a')](handleError(_0x285b99,null));};exports['status']=function(_0x4abf59,_0x539279,_0x591a5d){if(_0x4abf59[_0xe0c2('0x5a')]['id']){delete _0x4abf59[_0xe0c2('0x5a')]['id'];}var _0x30f377;return db['WhatsappMessage']['find']({'where':{'id':_0x4abf59['params']['id']}})[_0xe0c2('0x39')](handleEntityNotFound(_0x539279,null))[_0xe0c2('0x39')](function(_0x1119b0){if(_0x1119b0){_0x30f377=_0x1119b0;return db['WhatsappAccount']['find']({'where':{'id':_0x1119b0[_0xe0c2('0x84')]}});}})[_0xe0c2('0x39')](handleEntityNotFound(_0x539279,null))[_0xe0c2('0x39')](function(_0x2de29d){if(_0x2de29d){logger[_0xe0c2('0x24')](_0xe0c2('0x85'),_0xe0c2('0x2c'),_0xe0c2('0x86'),_0x2de29d[_0xe0c2('0x41')],util['inspect'](_0x4abf59[_0xe0c2('0x5a')],{'showHidden':![],'depth':null}));switch(_0x2de29d[_0xe0c2('0x41')]){case'twilio':if(_0x4abf59['body'][_0xe0c2('0x87')]&&_0x4abf59[_0xe0c2('0x5a')][_0xe0c2('0x87')]===_0x30f377[_0xe0c2('0x88')]&&_0x4abf59[_0xe0c2('0x5a')]['MessageStatus']&&_0x4abf59['body'][_0xe0c2('0x89')]===_0xe0c2('0x5e')){return _0x30f377[_0xe0c2('0x38')]({'read':!![]});}else{logger[_0xe0c2('0x26')]('WhatsappAccount,\x20%s,\x20%s,\x20%s',_0xe0c2('0x2c'),_0xe0c2('0x8a'),util['inspect'](_0x4abf59[_0xe0c2('0x5a')],{'showHidden':![],'depth':null}));}break;}return _0x30f377;}})[_0xe0c2('0x39')](respondWithResult(_0x539279,null))['catch'](handleError(_0x539279,null));};
\ No newline at end of file