Built motion from commit b5413ace.|2.6.9
[motion2.git] / server / api / whatsappMessage / whatsappMessage.controller.js
index 6fd1881..b00ace3 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x164f=['get','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','Sequelize','QueryTypes','SELECT','contact','User','fullname','email','SIP/%s','channel','event','EventManager','acceptmessage','[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','sequelize','internal','interface','motionChannel','WhatsappAccount','received\x20delivery\x20report\x20from','twilio','MessageSid','messageId','MessageStatus','WhatsappAccount,\x20%s,\x20%s,\x20%s','inspect','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','./whatsappMessage.socket','register','jayson/promise','http','client','request','then','WhatsappMessage,\x20%s,\x20%s','request\x20sent','debug','WhatsappMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','catch','status','end','json','offset','limit','undefined','count','apply','reject','save','update','destroy','sendStatus','stack','name','send','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','WhatsappMessage','findAll','rows','show','params','length','find','create','body','describe','whatsapp-interactions','accept','whatsapp','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','WhatsappInteraction','WhatsappInteractionId','isNil','read1stAt','interaction'];(function(_0x64c079,_0x2f867e){var _0x187078=function(_0x2f13f0){while(--_0x2f13f0){_0x64c079['push'](_0x64c079['shift']());}};_0x187078(++_0x2f867e);}(_0x164f,0x1d0));var _0xf164=function(_0x23a21d,_0x2f4730){_0x23a21d=_0x23a21d-0x0;var _0x3178f9=_0x164f[_0x23a21d];return _0x3178f9;};'use strict';var emlformat=require(_0xf164('0x0'));var rimraf=require(_0xf164('0x1'));var zipdir=require(_0xf164('0x2'));var jsonpatch=require(_0xf164('0x3'));var rp=require(_0xf164('0x4'));var moment=require('moment');var BPromise=require(_0xf164('0x5'));var Mustache=require(_0xf164('0x6'));var util=require(_0xf164('0x7'));var path=require(_0xf164('0x8'));var sox=require('sox');var csv=require(_0xf164('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf164('0xa'));var _=require(_0xf164('0xb'));var squel=require(_0xf164('0xc'));var crypto=require(_0xf164('0xd'));var jsforce=require(_0xf164('0xe'));var deskjs=require(_0xf164('0xf'));var toCsv=require(_0xf164('0x9'));var querystring=require(_0xf164('0x10'));var Papa=require('papaparse');var Redis=require(_0xf164('0x11'));var authService=require(_0xf164('0x12'));var qs=require(_0xf164('0x13'));var as=require(_0xf164('0x14'));var hardwareService=require(_0xf164('0x15'));var logger=require(_0xf164('0x16'))(_0xf164('0x17'));var utils=require(_0xf164('0x18'));var config=require(_0xf164('0x19'));var licenseUtil=require(_0xf164('0x1a'));var db=require(_0xf164('0x1b'))['db'];config[_0xf164('0x1c')]=_[_0xf164('0x1d')](config['redis'],{'host':_0xf164('0x1e'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0xf164('0x1f'))[_0xf164('0x20')](socket);var jayson=require(_0xf164('0x21'));var client=jayson['client'][_0xf164('0x22')]({'port':0x232c});var client9002=jayson[_0xf164('0x23')]['http']({'port':0x232a});function respondWithRpcPromise(_0x9bb76a,_0x42c73d,_0x26be92,_0x17a70a){return new BPromise(function(_0x34dd6b,_0x402d57){var _0x57127f=_0x17a70a||client;return _0x57127f[_0xf164('0x24')](_0x9bb76a,_0x26be92)[_0xf164('0x25')](function(_0x35e8f9){logger['info'](_0xf164('0x26'),_0x42c73d,_0xf164('0x27'));logger[_0xf164('0x28')](_0xf164('0x29'),_0x42c73d,_0xf164('0x27'),JSON[_0xf164('0x2a')](_0x35e8f9));if(_0x35e8f9['error']){if(_0x35e8f9[_0xf164('0x2b')][_0xf164('0x2c')]===0x1f4){logger['error'](_0xf164('0x26'),_0x42c73d,_0x35e8f9[_0xf164('0x2b')][_0xf164('0x2d')]);return _0x402d57(_0x35e8f9[_0xf164('0x2b')][_0xf164('0x2d')]);}logger[_0xf164('0x2b')]('WhatsappMessage,\x20%s,\x20%s',_0x42c73d,_0x35e8f9['error'][_0xf164('0x2d')]);return _0x34dd6b(_0x35e8f9[_0xf164('0x2b')][_0xf164('0x2d')]);}else{logger[_0xf164('0x2e')](_0xf164('0x26'),_0x42c73d,_0xf164('0x27'));_0x34dd6b(_0x35e8f9['result']['message']);}})[_0xf164('0x2f')](function(_0x350ba5){logger[_0xf164('0x2b')](_0xf164('0x26'),_0x42c73d,_0x350ba5);_0x402d57(_0x350ba5);});});}function respondWithStatusCode(_0x56a3f0,_0x4e2943){_0x4e2943=_0x4e2943||0xcc;return function(_0x443917){if(_0x443917){return _0x56a3f0['sendStatus'](_0x4e2943);}return _0x56a3f0[_0xf164('0x30')](_0x4e2943)[_0xf164('0x31')]();};}function respondWithResult(_0x1d275b,_0x41c2dc){_0x41c2dc=_0x41c2dc||0xc8;return function(_0x3b6f9b){if(_0x3b6f9b){return _0x1d275b[_0xf164('0x30')](_0x41c2dc)[_0xf164('0x32')](_0x3b6f9b);}};}function respondWithFilteredResult(_0x2486b9,_0x42965e){return function(_0x2fc2be){if(_0x2fc2be){var _0x19c5bf=typeof _0x42965e[_0xf164('0x33')]==='undefined'&&typeof _0x42965e[_0xf164('0x34')]===_0xf164('0x35');var _0x22d945=_0x2fc2be[_0xf164('0x36')];var _0x2d9f19=_0x19c5bf?0x0:_0x42965e[_0xf164('0x33')];var _0x514145=_0x19c5bf?_0x2fc2be[_0xf164('0x36')]:_0x42965e[_0xf164('0x33')]+_0x42965e[_0xf164('0x34')];var _0x2596f8;if(_0x514145>=_0x22d945){_0x514145=_0x22d945;_0x2596f8=0xc8;}else{_0x2596f8=0xce;}_0x2486b9[_0xf164('0x30')](_0x2596f8);return _0x2486b9['set']('Content-Range',_0x2d9f19+'-'+_0x514145+'/'+_0x22d945)[_0xf164('0x32')](_0x2fc2be);}return null;};}function patchUpdates(_0x5b7889){return function(_0x5b43bd){try{jsonpatch[_0xf164('0x37')](_0x5b43bd,_0x5b7889,!![]);}catch(_0xde85fd){return BPromise[_0xf164('0x38')](_0xde85fd);}return _0x5b43bd[_0xf164('0x39')]();};}function saveUpdates(_0xd1489c,_0x2f99b4){return function(_0x57fc63){if(_0x57fc63){return _0x57fc63[_0xf164('0x3a')](_0xd1489c)[_0xf164('0x25')](function(_0x577ac8){return _0x577ac8;});}return null;};}function removeEntity(_0x37905b,_0x44ba1a){return function(_0x5bf302){if(_0x5bf302){return _0x5bf302[_0xf164('0x3b')]()['then'](function(){_0x37905b[_0xf164('0x30')](0xcc)[_0xf164('0x31')]();});}};}function handleEntityNotFound(_0x237a33,_0x8dfbe5){return function(_0x27b581){if(!_0x27b581){_0x237a33[_0xf164('0x3c')](0x194);}return _0x27b581;};}function handleError(_0x272691,_0x232fe8){_0x232fe8=_0x232fe8||0x1f4;return function(_0x341867){logger[_0xf164('0x2b')](_0x341867[_0xf164('0x3d')]);if(_0x341867[_0xf164('0x3e')]){delete _0x341867[_0xf164('0x3e')];}_0x272691[_0xf164('0x30')](_0x232fe8)[_0xf164('0x3f')](_0x341867);};}exports[_0xf164('0x40')]=function(_0x34b75e,_0x45326d){var _0x45a2db={},_0x58133d={},_0x8996e5={'count':0x0,'rows':[]};var _0x4f8ef8=_[_0xf164('0x41')](db['WhatsappMessage'][_0xf164('0x42')],function(_0x1f3591){return{'name':_0x1f3591[_0xf164('0x43')],'type':_0x1f3591[_0xf164('0x44')][_0xf164('0x45')]};});_0x58133d[_0xf164('0x46')]=_[_0xf164('0x41')](_0x4f8ef8,'name');_0x58133d[_0xf164('0x47')]=_[_0xf164('0x48')](_0x34b75e[_0xf164('0x47')]);_0x58133d[_0xf164('0x49')]=_['intersection'](_0x58133d[_0xf164('0x46')],_0x58133d[_0xf164('0x47')]);_0x45a2db[_0xf164('0x4a')]=_[_0xf164('0x4b')](_0x58133d[_0xf164('0x46')],qs['fields'](_0x34b75e['query'][_0xf164('0x4c')]));_0x45a2db['attributes']=_0x45a2db[_0xf164('0x4a')]['length']?_0x45a2db['attributes']:_0x58133d[_0xf164('0x46')];if(!_0x34b75e[_0xf164('0x47')][_0xf164('0x4d')](_0xf164('0x4e'))){_0x45a2db['limit']=qs[_0xf164('0x34')](_0x34b75e[_0xf164('0x47')]['limit']);_0x45a2db[_0xf164('0x33')]=qs['offset'](_0x34b75e[_0xf164('0x47')][_0xf164('0x33')]);}_0x45a2db[_0xf164('0x4f')]=qs[_0xf164('0x50')](_0x34b75e[_0xf164('0x47')][_0xf164('0x50')]);_0x45a2db[_0xf164('0x51')]=qs['filters'](_[_0xf164('0x52')](_0x34b75e['query'],_0x58133d[_0xf164('0x49')]),_0x4f8ef8);if(_0x34b75e['query'][_0xf164('0x53')]){_0x45a2db[_0xf164('0x51')]=_[_0xf164('0x54')](_0x45a2db[_0xf164('0x51')],{'$or':_[_0xf164('0x41')](_0x4f8ef8,function(_0xf2dbfe){if(_0xf2dbfe[_0xf164('0x44')]!==_0xf164('0x55')){var _0x43d431={};_0x43d431[_0xf2dbfe[_0xf164('0x3e')]]={'$like':'%'+_0x34b75e['query'][_0xf164('0x53')]+'%'};return _0x43d431;}})});}_0x45a2db=_[_0xf164('0x54')]({},_0x45a2db,_0x34b75e[_0xf164('0x56')]);var _0x2321b7={'where':_0x45a2db['where']};return db['WhatsappMessage'][_0xf164('0x36')](_0x2321b7)[_0xf164('0x25')](function(_0x3d77b4){_0x8996e5[_0xf164('0x36')]=_0x3d77b4;if(_0x34b75e[_0xf164('0x47')]['includeAll']){_0x45a2db['include']=[{'all':!![]}];}return db[_0xf164('0x57')][_0xf164('0x58')](_0x45a2db);})[_0xf164('0x25')](function(_0x50af47){_0x8996e5[_0xf164('0x59')]=_0x50af47;return _0x8996e5;})[_0xf164('0x25')](respondWithFilteredResult(_0x45326d,_0x45a2db))[_0xf164('0x2f')](handleError(_0x45326d,null));};exports[_0xf164('0x5a')]=function(_0x176f7f,_0x571f0e){var _0x33288c={'raw':!![],'where':{'id':_0x176f7f[_0xf164('0x5b')]['id']}},_0x36aa0f={};_0x36aa0f[_0xf164('0x46')]=_['keys'](db['WhatsappMessage'][_0xf164('0x42')]);_0x36aa0f['query']=_[_0xf164('0x48')](_0x176f7f['query']);_0x36aa0f[_0xf164('0x49')]=_[_0xf164('0x4b')](_0x36aa0f['model'],_0x36aa0f[_0xf164('0x47')]);_0x33288c[_0xf164('0x4a')]=_['intersection'](_0x36aa0f['model'],qs[_0xf164('0x4c')](_0x176f7f[_0xf164('0x47')][_0xf164('0x4c')]));_0x33288c['attributes']=_0x33288c[_0xf164('0x4a')][_0xf164('0x5c')]?_0x33288c['attributes']:_0x36aa0f[_0xf164('0x46')];if(_0x176f7f[_0xf164('0x47')]['includeAll']){_0x33288c['include']=[{'all':!![]}];}_0x33288c=_[_0xf164('0x54')]({},_0x33288c,_0x176f7f[_0xf164('0x56')]);return db[_0xf164('0x57')][_0xf164('0x5d')](_0x33288c)[_0xf164('0x25')](handleEntityNotFound(_0x571f0e,null))['then'](respondWithResult(_0x571f0e,null))[_0xf164('0x2f')](handleError(_0x571f0e,null));};exports[_0xf164('0x5e')]=function(_0x500c20,_0x54098e){return db['WhatsappMessage'][_0xf164('0x5e')](_0x500c20['body'],{})[_0xf164('0x25')](respondWithResult(_0x54098e,0xc9))[_0xf164('0x2f')](handleError(_0x54098e,null));};exports['update']=function(_0x1254af,_0x4fdb86){if(_0x1254af['body']['id']){delete _0x1254af[_0xf164('0x5f')]['id'];}return db[_0xf164('0x57')]['find']({'where':{'id':_0x1254af[_0xf164('0x5b')]['id']}})[_0xf164('0x25')](handleEntityNotFound(_0x4fdb86,null))[_0xf164('0x25')](saveUpdates(_0x1254af[_0xf164('0x5f')],null))[_0xf164('0x25')](respondWithResult(_0x4fdb86,null))[_0xf164('0x2f')](handleError(_0x4fdb86,null));};exports[_0xf164('0x3b')]=function(_0x58882c,_0x36026e){return db[_0xf164('0x57')][_0xf164('0x5d')]({'where':{'id':_0x58882c[_0xf164('0x5b')]['id']}})[_0xf164('0x25')](handleEntityNotFound(_0x36026e,null))[_0xf164('0x25')](removeEntity(_0x36026e,null))[_0xf164('0x2f')](handleError(_0x36026e,null));};exports[_0xf164('0x60')]=function(_0x2e4541,_0x199d14){return db[_0xf164('0x57')][_0xf164('0x60')]()[_0xf164('0x25')](respondWithResult(_0x199d14,null))['catch'](handleError(_0x199d14,null));};var interaction_log=require('../../config/logger')(_0xf164('0x61'));exports[_0xf164('0x62')]=function(_0x5c107f,_0x673dee,_0x374098){var _0x13cb70={'agent':{},'channel':_0xf164('0x63')};if(_0x5c107f[_0xf164('0x5f')]['id']){delete _0x5c107f[_0xf164('0x5f')]['id'];}_0x5c107f[_0xf164('0x5f')][_0xf164('0x64')]=!![];_0x5c107f['body'][_0xf164('0x65')]=moment()[_0xf164('0x66')](_0xf164('0x67'));_0x5c107f[_0xf164('0x5f')]['UserId']=_0x5c107f[_0xf164('0x5f')][_0xf164('0x68')]||_0x5c107f[_0xf164('0x69')]['id'];_0x13cb70[_0xf164('0x6a')]['id']=_0x5c107f['body'][_0xf164('0x68')];return db[_0xf164('0x57')][_0xf164('0x5d')]({'where':{'id':_0x5c107f[_0xf164('0x5b')]['id'],'UserId':null}})[_0xf164('0x25')](handleEntityNotFound(_0x673dee,null))['then'](saveUpdates(_0x5c107f[_0xf164('0x5f')],null))[_0xf164('0x25')](function(_0x2c4858){if(_0x2c4858){_0x13cb70[_0xf164('0x2d')]=_0x2c4858['get']({'plain':!![]});return db[_0xf164('0x6b')][_0xf164('0x5d')]({'where':{'id':_0x2c4858[_0xf164('0x6c')]}});}return null;})[_0xf164('0x25')](handleEntityNotFound(_0x673dee,null))['then'](function(_0x4c0a85){if(_0x4c0a85){return _0x4c0a85[_0xf164('0x3a')]({'UserId':_0x5c107f[_0xf164('0x5f')][_0xf164('0x68')],'read1stAt':_[_0xf164('0x6d')](_0x4c0a85[_0xf164('0x6e')])?moment()[_0xf164('0x66')](_0xf164('0x67')):undefined});}return null;})[_0xf164('0x25')](function(_0x5452ea){if(_0x5452ea){_0x13cb70[_0xf164('0x6f')]=_0x5452ea[_0xf164('0x70')]({'plain':!![]});interaction_log[_0xf164('0x2e')](_0xf164('0x71'),_0x5c107f['user']['id'],_0x5c107f[_0xf164('0x69')][_0xf164('0x3e')],_0x5c107f[_0xf164('0x69')][_0xf164('0x72')],_0x13cb70[_0xf164('0x6f')]['id'],_0x5c107f['body']?JSON[_0xf164('0x2a')](_0x5c107f['body']):_0xf164('0x73'));return respondWithRpcPromise('AcceptMessage',_0xf164('0x74'),_0x13cb70);}return null;})[_0xf164('0x25')](function(_0x32edc9){var _0x2fa82c=_0xf164('0x75')+_0x32edc9[_0xf164('0x2d')][_0xf164('0x76')];return db['sequelize'][_0xf164('0x47')](_0x2fa82c,{'type':db[_0xf164('0x77')][_0xf164('0x78')][_0xf164('0x79')],'raw':!![]})[_0xf164('0x25')](function(_0x3b4d84){return _0x3b4d84;});})[_0xf164('0x25')](function(_0x181400){if(_0x181400){_0x13cb70['message'][_0xf164('0x7a')]=_0x181400[0x0];if(!_0x5c107f[_0xf164('0x5f')]['UserId'])return;return db[_0xf164('0x7b')][_0xf164('0x5d')]({'where':{'id':_0x5c107f['body'][_0xf164('0x68')],'role':_0xf164('0x6a')},'attributes':['id',_0xf164('0x3e'),_0xf164('0x7c'),_0xf164('0x7d'),'internal'],'raw':!![]});}return null;})[_0xf164('0x25')](function(_0x2ad146){if(!_0x2ad146)return null;_0x13cb70[_0xf164('0x2d')][_0xf164('0x6a')]=_0x2ad146;return _0x13cb70;})['then'](function(_0x515f4c){if(_0x515f4c){if(_0x5c107f[_0xf164('0x5f')]['manual']){_0x13cb70[_0xf164('0x2d')]['interface']=util[_0xf164('0x66')](_0xf164('0x7e'),_0x5c107f[_0xf164('0x69')][_0xf164('0x3e')]);_0x13cb70[_0xf164('0x2d')][_0xf164('0x7f')]=_0x13cb70[_0xf164('0x7f')];_0x13cb70[_0xf164('0x2d')]['motionChannel']=_0x13cb70[_0xf164('0x7f')];_0x13cb70['message'][_0xf164('0x80')]=_0xf164('0x62');return respondWithRpcPromise(_0xf164('0x81'),_0xf164('0x81'),{'event':_0xf164('0x82'),'message':_0x13cb70['message']},client9002)[_0xf164('0x25')](function(){return _0x13cb70;});}return _0x13cb70;}return null;})[_0xf164('0x25')](respondWithResult(_0x673dee,null))[_0xf164('0x2f')](handleError(_0x673dee,null));};var interaction_log=require(_0xf164('0x16'))(_0xf164('0x61'));exports[_0xf164('0x38')]=function(_0x4cda22,_0x2d9f56,_0x920c7d){var _0x17d271={'agent':{},'channel':'whatsapp'};if(_0x4cda22[_0xf164('0x5f')]['id']){delete _0x4cda22[_0xf164('0x5f')]['id'];}_0x4cda22[_0xf164('0x5f')][_0xf164('0x68')]=_0x4cda22['body'][_0xf164('0x68')]||_0x4cda22[_0xf164('0x69')]['id'];_0x17d271[_0xf164('0x6a')]['id']=_0x4cda22[_0xf164('0x5f')]['UserId'];return db[_0xf164('0x57')][_0xf164('0x5d')]({'where':{'id':_0x4cda22[_0xf164('0x5b')]['id'],'UserId':null}})[_0xf164('0x25')](handleEntityNotFound(_0x2d9f56,null))['then'](function(_0x4aed0a){if(_0x4aed0a){_0x17d271[_0xf164('0x2d')]=_0x4aed0a[_0xf164('0x70')]({'plain':!![]});return db[_0xf164('0x6b')]['find']({'where':{'id':_0x4aed0a[_0xf164('0x6c')]}});}return null;})[_0xf164('0x25')](handleEntityNotFound(_0x2d9f56,null))[_0xf164('0x25')](function(_0x1d28d6){if(_0x1d28d6){_0x17d271[_0xf164('0x6f')]=_0x1d28d6['get']({'plain':!![]});interaction_log['info'](_0xf164('0x83'),_0x4cda22[_0xf164('0x69')]['id'],_0x4cda22[_0xf164('0x69')]['name'],_0x4cda22[_0xf164('0x69')]['role'],_0x17d271['interaction']['id'],_0x4cda22[_0xf164('0x5f')]?JSON[_0xf164('0x2a')](_0x4cda22[_0xf164('0x5f')]):_0xf164('0x73'));return respondWithRpcPromise('RejectMessage','rejectMessage',_0x17d271);}return null;})['then'](function(_0x2e51f7){var _0x71e055=_0xf164('0x75')+_0x2e51f7[_0xf164('0x2d')][_0xf164('0x76')];return db[_0xf164('0x84')][_0xf164('0x47')](_0x71e055,{'type':db[_0xf164('0x77')][_0xf164('0x78')]['SELECT'],'raw':!![]})[_0xf164('0x25')](function(_0x1afec1){return _0x1afec1;});})[_0xf164('0x25')](function(_0x16d1e5){if(_0x16d1e5){_0x17d271[_0xf164('0x2d')][_0xf164('0x7a')]=_0x16d1e5[0x0];if(!_0x4cda22[_0xf164('0x5f')]['UserId'])return;return db[_0xf164('0x7b')][_0xf164('0x5d')]({'where':{'id':_0x4cda22['body'][_0xf164('0x68')],'role':_0xf164('0x6a')},'attributes':['id',_0xf164('0x3e'),_0xf164('0x7c'),_0xf164('0x7d'),_0xf164('0x85')],'raw':!![]});}return null;})[_0xf164('0x25')](function(_0x333efd){if(!_0x333efd)return null;_0x17d271[_0xf164('0x2d')][_0xf164('0x6a')]=_0x333efd;return _0x17d271;})[_0xf164('0x25')](function(_0x315eb6){if(_0x315eb6){_0x315eb6['message'][_0xf164('0x86')]=util[_0xf164('0x66')](_0xf164('0x7e'),_0x4cda22[_0xf164('0x69')][_0xf164('0x3e')]);_0x315eb6[_0xf164('0x2d')]['channel']=_0x17d271['channel'];_0x315eb6[_0xf164('0x2d')][_0xf164('0x87')]=_0x17d271['channel'];_0x315eb6[_0xf164('0x2d')]['event']=_0xf164('0x38');respondWithRpcPromise('EventManager',_0xf164('0x81'),{'event':'rejectmessage','message':_0x315eb6['message']},client9002);return _0x17d271;}return null;})[_0xf164('0x25')](respondWithResult(_0x2d9f56,null))[_0xf164('0x2f')](handleError(_0x2d9f56,null));};exports[_0xf164('0x30')]=function(_0x2785dc,_0x538410,_0x749bdf){if(_0x2785dc[_0xf164('0x5f')]['id']){delete _0x2785dc[_0xf164('0x5f')]['id'];}var _0x1f25ca;return db[_0xf164('0x57')][_0xf164('0x5d')]({'where':{'id':_0x2785dc['params']['id']}})[_0xf164('0x25')](handleEntityNotFound(_0x538410,null))[_0xf164('0x25')](function(_0x33d401){if(_0x33d401){_0x1f25ca=_0x33d401;return db[_0xf164('0x88')][_0xf164('0x5d')]({'where':{'id':_0x33d401['WhatsappAccountId']}});}})[_0xf164('0x25')](handleEntityNotFound(_0x538410,null))[_0xf164('0x25')](function(_0x532edd){if(_0x532edd){logger[_0xf164('0x28')]('WhatsppMessage,\x20%s,\x20%s,\x20%s','status',_0xf164('0x89'),_0x532edd['type'],util['inspect'](_0x2785dc[_0xf164('0x5f')],{'showHidden':![],'depth':null}));switch(_0x532edd[_0xf164('0x44')]){case _0xf164('0x8a'):if(_0x2785dc[_0xf164('0x5f')][_0xf164('0x8b')]&&_0x2785dc['body'][_0xf164('0x8b')]===_0x1f25ca[_0xf164('0x8c')]&&_0x2785dc[_0xf164('0x5f')][_0xf164('0x8d')]&&_0x2785dc[_0xf164('0x5f')]['MessageStatus']==='read'){return _0x1f25ca['update']({'read':!![]});}else{logger['error'](_0xf164('0x8e'),'status',_0xf164('0x8a'),util[_0xf164('0x8f')](_0x2785dc[_0xf164('0x5f')],{'showHidden':![],'depth':null}));}break;}return _0x1f25ca;}})[_0xf164('0x25')](respondWithResult(_0x538410,null))[_0xf164('0x2f')](handleError(_0x538410,null));};
\ No newline at end of file
+var _0xd708=['../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./whatsappMessage.socket','jayson/promise','client','http','request','then','WhatsappMessage,\x20%s,\x20%s','request\x20sent','debug','WhatsappMessage,\x20%s,\x20%s,\x20%s','error','code','message','info','result','catch','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','json','reject','save','update','destroy','name','index','map','WhatsappMessage','fieldName','type','key','filters','intersection','model','query','fields','attributes','sort','where','filter','VIRTUAL','merge','include','show','params','keys','length','includeAll','options','create','body','describe','whatsapp-interactions','whatsapp','readAt','format','UserId','user','agent','find','get','isNil','read1stAt','YYYY-MM-DD\x20HH:mm:ss','interaction','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','stringify','null','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','QueryTypes','contact','email','internal','manual','SIP/%s','channel','motionChannel','event','accept','EventManager','acceptmessage','WhatsappInteraction','WhatsappInteractionId','[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','RejectMessage','rejectMessage','SELECT','User','fullname','interface','rejectmessage','WhatsappAccount','WhatsppMessage,\x20%s,\x20%s,\x20%s','inspect','twilio','MessageSid','messageId','MessageStatus','read','WhatsappAccount,\x20%s,\x20%s,\x20%s','eml-format','rimraf','fast-json-patch','request-promise','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','querystring','papaparse','ioredis','../../components/parsers/qs'];(function(_0x141dc0,_0x2b04d8){var _0x22b224=function(_0x42d58f){while(--_0x42d58f){_0x141dc0['push'](_0x141dc0['shift']());}};_0x22b224(++_0x2b04d8);}(_0xd708,0x18a));var _0x8d70=function(_0x47d89d,_0x1c1bd7){_0x47d89d=_0x47d89d-0x0;var _0x28fc0f=_0xd708[_0x47d89d];return _0x28fc0f;};'use strict';var emlformat=require(_0x8d70('0x0'));var rimraf=require(_0x8d70('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x8d70('0x2'));var rp=require(_0x8d70('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x8d70('0x4'));var path=require(_0x8d70('0x5'));var sox=require(_0x8d70('0x6'));var csv=require(_0x8d70('0x7'));var ejs=require(_0x8d70('0x8'));var fs=require('fs');var fs_extra=require(_0x8d70('0x9'));var _=require(_0x8d70('0xa'));var squel=require(_0x8d70('0xb'));var crypto=require('crypto');var jsforce=require(_0x8d70('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x8d70('0x7'));var querystring=require(_0x8d70('0xd'));var Papa=require(_0x8d70('0xe'));var Redis=require(_0x8d70('0xf'));var authService=require('../../components/auth/service');var qs=require(_0x8d70('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x8d70('0x11'))(_0x8d70('0x12'));var utils=require(_0x8d70('0x13'));var config=require(_0x8d70('0x14'));var licenseUtil=require(_0x8d70('0x15'));var db=require(_0x8d70('0x16'))['db'];config[_0x8d70('0x17')]=_['defaults'](config['redis'],{'host':_0x8d70('0x18'),'port':0x18eb});var socket=require(_0x8d70('0x19'))(new Redis(config[_0x8d70('0x17')]));require(_0x8d70('0x1a'))['register'](socket);var jayson=require(_0x8d70('0x1b'));var client=jayson[_0x8d70('0x1c')][_0x8d70('0x1d')]({'port':0x232c});var client9002=jayson[_0x8d70('0x1c')][_0x8d70('0x1d')]({'port':0x232a});function respondWithRpcPromise(_0x1ab5fc,_0x2e37e7,_0x33554c,_0x5051b5){return new BPromise(function(_0x40430c,_0x3cd217){var _0x55e6e3=_0x5051b5||client;return _0x55e6e3[_0x8d70('0x1e')](_0x1ab5fc,_0x33554c)[_0x8d70('0x1f')](function(_0x4efed0){logger['info'](_0x8d70('0x20'),_0x2e37e7,_0x8d70('0x21'));logger[_0x8d70('0x22')](_0x8d70('0x23'),_0x2e37e7,_0x8d70('0x21'),JSON['stringify'](_0x4efed0));if(_0x4efed0['error']){if(_0x4efed0[_0x8d70('0x24')][_0x8d70('0x25')]===0x1f4){logger[_0x8d70('0x24')](_0x8d70('0x20'),_0x2e37e7,_0x4efed0['error'][_0x8d70('0x26')]);return _0x3cd217(_0x4efed0[_0x8d70('0x24')][_0x8d70('0x26')]);}logger[_0x8d70('0x24')](_0x8d70('0x20'),_0x2e37e7,_0x4efed0[_0x8d70('0x24')][_0x8d70('0x26')]);return _0x40430c(_0x4efed0[_0x8d70('0x24')][_0x8d70('0x26')]);}else{logger[_0x8d70('0x27')]('WhatsappMessage,\x20%s,\x20%s',_0x2e37e7,'request\x20sent');_0x40430c(_0x4efed0[_0x8d70('0x28')][_0x8d70('0x26')]);}})[_0x8d70('0x29')](function(_0x1d997d){logger[_0x8d70('0x24')](_0x8d70('0x20'),_0x2e37e7,_0x1d997d);_0x3cd217(_0x1d997d);});});}function respondWithStatusCode(_0x5167f7,_0x38b9ee){_0x38b9ee=_0x38b9ee||0xcc;return function(_0x51a627){if(_0x51a627){return _0x5167f7[_0x8d70('0x2a')](_0x38b9ee);}return _0x5167f7[_0x8d70('0x2b')](_0x38b9ee)[_0x8d70('0x2c')]();};}function respondWithResult(_0x162316,_0xf9e53a){_0xf9e53a=_0xf9e53a||0xc8;return function(_0x5980b6){if(_0x5980b6){return _0x162316[_0x8d70('0x2b')](_0xf9e53a)['json'](_0x5980b6);}};}function respondWithFilteredResult(_0x405784,_0x25ceae){return function(_0x30f419){if(_0x30f419){var _0xd8f88e=typeof _0x25ceae[_0x8d70('0x2d')]===_0x8d70('0x2e')&&typeof _0x25ceae[_0x8d70('0x2f')]==='undefined';var _0x25d173=_0x30f419[_0x8d70('0x30')];var _0xfafe7c=_0xd8f88e?0x0:_0x25ceae[_0x8d70('0x2d')];var _0x1d3ccd=_0xd8f88e?_0x30f419[_0x8d70('0x30')]:_0x25ceae[_0x8d70('0x2d')]+_0x25ceae['limit'];var _0x4cb64c;if(_0x1d3ccd>=_0x25d173){_0x1d3ccd=_0x25d173;_0x4cb64c=0xc8;}else{_0x4cb64c=0xce;}_0x405784[_0x8d70('0x2b')](_0x4cb64c);return _0x405784[_0x8d70('0x31')](_0x8d70('0x32'),_0xfafe7c+'-'+_0x1d3ccd+'/'+_0x25d173)[_0x8d70('0x33')](_0x30f419);}return null;};}function patchUpdates(_0xb97647){return function(_0x27aedc){try{jsonpatch['apply'](_0x27aedc,_0xb97647,!![]);}catch(_0x316c3d){return BPromise[_0x8d70('0x34')](_0x316c3d);}return _0x27aedc[_0x8d70('0x35')]();};}function saveUpdates(_0x3d0f64,_0x433e60){return function(_0x5aa389){if(_0x5aa389){return _0x5aa389[_0x8d70('0x36')](_0x3d0f64)[_0x8d70('0x1f')](function(_0x23d291){return _0x23d291;});}return null;};}function removeEntity(_0x4bab74,_0x48aade){return function(_0x22a6eb){if(_0x22a6eb){return _0x22a6eb[_0x8d70('0x37')]()[_0x8d70('0x1f')](function(){_0x4bab74[_0x8d70('0x2b')](0xcc)[_0x8d70('0x2c')]();});}};}function handleEntityNotFound(_0x1ac49c,_0x17ecff){return function(_0x55806e){if(!_0x55806e){_0x1ac49c['sendStatus'](0x194);}return _0x55806e;};}function handleError(_0x5a759a,_0x3f302f){_0x3f302f=_0x3f302f||0x1f4;return function(_0x2d2fab){logger[_0x8d70('0x24')](_0x2d2fab['stack']);if(_0x2d2fab[_0x8d70('0x38')]){delete _0x2d2fab[_0x8d70('0x38')];}_0x5a759a['status'](_0x3f302f)['send'](_0x2d2fab);};}exports[_0x8d70('0x39')]=function(_0x348b75,_0x4efdfd){var _0x2fcc73={},_0x5caba3={},_0x324420={'count':0x0,'rows':[]};var _0x1bb6ea=_[_0x8d70('0x3a')](db[_0x8d70('0x3b')]['rawAttributes'],function(_0x225e5a){return{'name':_0x225e5a[_0x8d70('0x3c')],'type':_0x225e5a[_0x8d70('0x3d')][_0x8d70('0x3e')]};});_0x5caba3['model']=_[_0x8d70('0x3a')](_0x1bb6ea,'name');_0x5caba3['query']=_['keys'](_0x348b75['query']);_0x5caba3[_0x8d70('0x3f')]=_[_0x8d70('0x40')](_0x5caba3[_0x8d70('0x41')],_0x5caba3[_0x8d70('0x42')]);_0x2fcc73['attributes']=_[_0x8d70('0x40')](_0x5caba3[_0x8d70('0x41')],qs['fields'](_0x348b75['query'][_0x8d70('0x43')]));_0x2fcc73[_0x8d70('0x44')]=_0x2fcc73[_0x8d70('0x44')]['length']?_0x2fcc73[_0x8d70('0x44')]:_0x5caba3[_0x8d70('0x41')];if(!_0x348b75[_0x8d70('0x42')]['hasOwnProperty']('nolimit')){_0x2fcc73['limit']=qs[_0x8d70('0x2f')](_0x348b75[_0x8d70('0x42')][_0x8d70('0x2f')]);_0x2fcc73[_0x8d70('0x2d')]=qs[_0x8d70('0x2d')](_0x348b75[_0x8d70('0x42')][_0x8d70('0x2d')]);}_0x2fcc73['order']=qs[_0x8d70('0x45')](_0x348b75[_0x8d70('0x42')]['sort']);_0x2fcc73[_0x8d70('0x46')]=qs[_0x8d70('0x3f')](_['pick'](_0x348b75['query'],_0x5caba3['filters']),_0x1bb6ea);if(_0x348b75[_0x8d70('0x42')][_0x8d70('0x47')]){_0x2fcc73[_0x8d70('0x46')]=_['merge'](_0x2fcc73[_0x8d70('0x46')],{'$or':_[_0x8d70('0x3a')](_0x1bb6ea,function(_0x18d11a){if(_0x18d11a[_0x8d70('0x3d')]!==_0x8d70('0x48')){var _0x55737c={};_0x55737c[_0x18d11a['name']]={'$like':'%'+_0x348b75[_0x8d70('0x42')]['filter']+'%'};return _0x55737c;}})});}_0x2fcc73=_[_0x8d70('0x49')]({},_0x2fcc73,_0x348b75['options']);var _0x1b6c4e={'where':_0x2fcc73[_0x8d70('0x46')]};return db[_0x8d70('0x3b')]['count'](_0x1b6c4e)['then'](function(_0xeab4b5){_0x324420[_0x8d70('0x30')]=_0xeab4b5;if(_0x348b75['query']['includeAll']){_0x2fcc73[_0x8d70('0x4a')]=[{'all':!![]}];}return db[_0x8d70('0x3b')]['findAll'](_0x2fcc73);})[_0x8d70('0x1f')](function(_0x493c20){_0x324420['rows']=_0x493c20;return _0x324420;})[_0x8d70('0x1f')](respondWithFilteredResult(_0x4efdfd,_0x2fcc73))['catch'](handleError(_0x4efdfd,null));};exports[_0x8d70('0x4b')]=function(_0x27523f,_0x536d71){var _0x2345b1={'raw':!![],'where':{'id':_0x27523f[_0x8d70('0x4c')]['id']}},_0x49de88={};_0x49de88[_0x8d70('0x41')]=_[_0x8d70('0x4d')](db[_0x8d70('0x3b')]['rawAttributes']);_0x49de88['query']=_[_0x8d70('0x4d')](_0x27523f['query']);_0x49de88[_0x8d70('0x3f')]=_[_0x8d70('0x40')](_0x49de88[_0x8d70('0x41')],_0x49de88[_0x8d70('0x42')]);_0x2345b1[_0x8d70('0x44')]=_[_0x8d70('0x40')](_0x49de88['model'],qs[_0x8d70('0x43')](_0x27523f[_0x8d70('0x42')][_0x8d70('0x43')]));_0x2345b1[_0x8d70('0x44')]=_0x2345b1['attributes'][_0x8d70('0x4e')]?_0x2345b1['attributes']:_0x49de88[_0x8d70('0x41')];if(_0x27523f[_0x8d70('0x42')][_0x8d70('0x4f')]){_0x2345b1[_0x8d70('0x4a')]=[{'all':!![]}];}_0x2345b1=_['merge']({},_0x2345b1,_0x27523f[_0x8d70('0x50')]);return db[_0x8d70('0x3b')]['find'](_0x2345b1)['then'](handleEntityNotFound(_0x536d71,null))[_0x8d70('0x1f')](respondWithResult(_0x536d71,null))[_0x8d70('0x29')](handleError(_0x536d71,null));};exports[_0x8d70('0x51')]=function(_0xc92339,_0x477970){return db[_0x8d70('0x3b')][_0x8d70('0x51')](_0xc92339[_0x8d70('0x52')],{})[_0x8d70('0x1f')](respondWithResult(_0x477970,0xc9))['catch'](handleError(_0x477970,null));};exports[_0x8d70('0x36')]=function(_0x50edce,_0x42acac){if(_0x50edce[_0x8d70('0x52')]['id']){delete _0x50edce[_0x8d70('0x52')]['id'];}return db[_0x8d70('0x3b')]['find']({'where':{'id':_0x50edce[_0x8d70('0x4c')]['id']}})[_0x8d70('0x1f')](handleEntityNotFound(_0x42acac,null))['then'](saveUpdates(_0x50edce[_0x8d70('0x52')],null))[_0x8d70('0x1f')](respondWithResult(_0x42acac,null))[_0x8d70('0x29')](handleError(_0x42acac,null));};exports['destroy']=function(_0x142cc8,_0x13520f){return db['WhatsappMessage']['find']({'where':{'id':_0x142cc8[_0x8d70('0x4c')]['id']}})[_0x8d70('0x1f')](handleEntityNotFound(_0x13520f,null))[_0x8d70('0x1f')](removeEntity(_0x13520f,null))[_0x8d70('0x29')](handleError(_0x13520f,null));};exports[_0x8d70('0x53')]=function(_0x256797,_0x139aa3){return db['WhatsappMessage'][_0x8d70('0x53')]()['then'](respondWithResult(_0x139aa3,null))['catch'](handleError(_0x139aa3,null));};var interaction_log=require(_0x8d70('0x11'))(_0x8d70('0x54'));exports['accept']=function(_0x23acda,_0x32ccb2,_0x27db8){var _0x48a711={'agent':{},'channel':_0x8d70('0x55')};if(_0x23acda[_0x8d70('0x52')]['id']){delete _0x23acda[_0x8d70('0x52')]['id'];}_0x23acda[_0x8d70('0x52')]['read']=!![];_0x23acda['body'][_0x8d70('0x56')]=moment()[_0x8d70('0x57')]('YYYY-MM-DD\x20HH:mm:ss');_0x23acda[_0x8d70('0x52')][_0x8d70('0x58')]=_0x23acda[_0x8d70('0x52')][_0x8d70('0x58')]||_0x23acda[_0x8d70('0x59')]['id'];_0x48a711[_0x8d70('0x5a')]['id']=_0x23acda['body'][_0x8d70('0x58')];return db[_0x8d70('0x3b')][_0x8d70('0x5b')]({'where':{'id':_0x23acda[_0x8d70('0x4c')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x32ccb2,null))['then'](saveUpdates(_0x23acda[_0x8d70('0x52')],null))['then'](function(_0x2875c5){if(_0x2875c5){_0x48a711[_0x8d70('0x26')]=_0x2875c5[_0x8d70('0x5c')]({'plain':!![]});return db['WhatsappInteraction'][_0x8d70('0x5b')]({'where':{'id':_0x2875c5['WhatsappInteractionId']}});}return null;})[_0x8d70('0x1f')](handleEntityNotFound(_0x32ccb2,null))['then'](function(_0x2a5198){if(_0x2a5198){return _0x2a5198[_0x8d70('0x36')]({'UserId':_0x23acda[_0x8d70('0x52')][_0x8d70('0x58')],'read1stAt':_[_0x8d70('0x5d')](_0x2a5198[_0x8d70('0x5e')])?moment()[_0x8d70('0x57')](_0x8d70('0x5f')):undefined});}return null;})[_0x8d70('0x1f')](function(_0x2b53a0){if(_0x2b53a0){_0x48a711[_0x8d70('0x60')]=_0x2b53a0[_0x8d70('0x5c')]({'plain':!![]});interaction_log[_0x8d70('0x27')](_0x8d70('0x61'),_0x23acda[_0x8d70('0x59')]['id'],_0x23acda[_0x8d70('0x59')]['name'],_0x23acda[_0x8d70('0x59')]['role'],_0x48a711[_0x8d70('0x60')]['id'],_0x23acda[_0x8d70('0x52')]?JSON[_0x8d70('0x62')](_0x23acda[_0x8d70('0x52')]):_0x8d70('0x63'));return respondWithRpcPromise('AcceptMessage',_0x8d70('0x64'),_0x48a711);}return null;})[_0x8d70('0x1f')](function(_0x495b4d){var _0x254d44=_0x8d70('0x65')+_0x495b4d[_0x8d70('0x26')][_0x8d70('0x66')];return db[_0x8d70('0x67')]['query'](_0x254d44,{'type':db[_0x8d70('0x68')][_0x8d70('0x69')]['SELECT'],'raw':!![]})[_0x8d70('0x1f')](function(_0x2ab460){return _0x2ab460;});})[_0x8d70('0x1f')](function(_0x2f6ad5){if(_0x2f6ad5){_0x48a711['message'][_0x8d70('0x6a')]=_0x2f6ad5[0x0];if(!_0x23acda['body'][_0x8d70('0x58')])return;return db['User'][_0x8d70('0x5b')]({'where':{'id':_0x23acda[_0x8d70('0x52')][_0x8d70('0x58')],'role':_0x8d70('0x5a')},'attributes':['id','name','fullname',_0x8d70('0x6b'),_0x8d70('0x6c')],'raw':!![]});}return null;})['then'](function(_0x4345bc){if(!_0x4345bc)return null;_0x48a711['message'][_0x8d70('0x5a')]=_0x4345bc;return _0x48a711;})[_0x8d70('0x1f')](function(_0x597543){if(_0x597543){if(_0x23acda[_0x8d70('0x52')][_0x8d70('0x6d')]){_0x48a711[_0x8d70('0x26')]['interface']=util['format'](_0x8d70('0x6e'),_0x23acda[_0x8d70('0x59')][_0x8d70('0x38')]);_0x48a711['message'][_0x8d70('0x6f')]=_0x48a711['channel'];_0x48a711[_0x8d70('0x26')][_0x8d70('0x70')]=_0x48a711[_0x8d70('0x6f')];_0x48a711[_0x8d70('0x26')][_0x8d70('0x71')]=_0x8d70('0x72');return respondWithRpcPromise('EventManager',_0x8d70('0x73'),{'event':_0x8d70('0x74'),'message':_0x48a711[_0x8d70('0x26')]},client9002)['then'](function(){return _0x48a711;});}return _0x48a711;}return null;})['then'](respondWithResult(_0x32ccb2,null))[_0x8d70('0x29')](handleError(_0x32ccb2,null));};var interaction_log=require(_0x8d70('0x11'))('whatsapp-interactions');exports[_0x8d70('0x34')]=function(_0x22691a,_0x22ec10,_0x1bf2de){var _0x1b7c6b={'agent':{},'channel':_0x8d70('0x55')};if(_0x22691a[_0x8d70('0x52')]['id']){delete _0x22691a['body']['id'];}_0x22691a[_0x8d70('0x52')][_0x8d70('0x58')]=_0x22691a[_0x8d70('0x52')][_0x8d70('0x58')]||_0x22691a['user']['id'];_0x1b7c6b[_0x8d70('0x5a')]['id']=_0x22691a[_0x8d70('0x52')][_0x8d70('0x58')];return db[_0x8d70('0x3b')][_0x8d70('0x5b')]({'where':{'id':_0x22691a['params']['id'],'UserId':null}})[_0x8d70('0x1f')](handleEntityNotFound(_0x22ec10,null))[_0x8d70('0x1f')](function(_0x43752e){if(_0x43752e){_0x1b7c6b[_0x8d70('0x26')]=_0x43752e[_0x8d70('0x5c')]({'plain':!![]});return db[_0x8d70('0x75')][_0x8d70('0x5b')]({'where':{'id':_0x43752e[_0x8d70('0x76')]}});}return null;})[_0x8d70('0x1f')](handleEntityNotFound(_0x22ec10,null))[_0x8d70('0x1f')](function(_0x265175){if(_0x265175){_0x1b7c6b[_0x8d70('0x60')]=_0x265175['get']({'plain':!![]});interaction_log[_0x8d70('0x27')](_0x8d70('0x77'),_0x22691a[_0x8d70('0x59')]['id'],_0x22691a[_0x8d70('0x59')][_0x8d70('0x38')],_0x22691a[_0x8d70('0x59')][_0x8d70('0x78')],_0x1b7c6b[_0x8d70('0x60')]['id'],_0x22691a[_0x8d70('0x52')]?JSON[_0x8d70('0x62')](_0x22691a[_0x8d70('0x52')]):_0x8d70('0x63'));return respondWithRpcPromise(_0x8d70('0x79'),_0x8d70('0x7a'),_0x1b7c6b);}return null;})[_0x8d70('0x1f')](function(_0x16e08b){var _0x527d40='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x16e08b[_0x8d70('0x26')][_0x8d70('0x66')];return db[_0x8d70('0x67')][_0x8d70('0x42')](_0x527d40,{'type':db[_0x8d70('0x68')][_0x8d70('0x69')][_0x8d70('0x7b')],'raw':!![]})[_0x8d70('0x1f')](function(_0x31cd21){return _0x31cd21;});})[_0x8d70('0x1f')](function(_0x163111){if(_0x163111){_0x1b7c6b[_0x8d70('0x26')][_0x8d70('0x6a')]=_0x163111[0x0];if(!_0x22691a[_0x8d70('0x52')]['UserId'])return;return db[_0x8d70('0x7c')][_0x8d70('0x5b')]({'where':{'id':_0x22691a[_0x8d70('0x52')][_0x8d70('0x58')],'role':_0x8d70('0x5a')},'attributes':['id','name',_0x8d70('0x7d'),_0x8d70('0x6b'),_0x8d70('0x6c')],'raw':!![]});}return null;})[_0x8d70('0x1f')](function(_0x361958){if(!_0x361958)return null;_0x1b7c6b[_0x8d70('0x26')][_0x8d70('0x5a')]=_0x361958;return _0x1b7c6b;})['then'](function(_0x2d7f09){if(_0x2d7f09){_0x2d7f09['message'][_0x8d70('0x7e')]=util['format']('SIP/%s',_0x22691a[_0x8d70('0x59')][_0x8d70('0x38')]);_0x2d7f09[_0x8d70('0x26')][_0x8d70('0x6f')]=_0x1b7c6b[_0x8d70('0x6f')];_0x2d7f09[_0x8d70('0x26')]['motionChannel']=_0x1b7c6b[_0x8d70('0x6f')];_0x2d7f09['message'][_0x8d70('0x71')]=_0x8d70('0x34');respondWithRpcPromise(_0x8d70('0x73'),_0x8d70('0x73'),{'event':_0x8d70('0x7f'),'message':_0x2d7f09[_0x8d70('0x26')]},client9002);return _0x1b7c6b;}return null;})[_0x8d70('0x1f')](respondWithResult(_0x22ec10,null))[_0x8d70('0x29')](handleError(_0x22ec10,null));};exports[_0x8d70('0x2b')]=function(_0xb884f3,_0x411147,_0x111365){if(_0xb884f3['body']['id']){delete _0xb884f3[_0x8d70('0x52')]['id'];}var _0x2b4704;return db[_0x8d70('0x3b')][_0x8d70('0x5b')]({'where':{'id':_0xb884f3[_0x8d70('0x4c')]['id']}})[_0x8d70('0x1f')](handleEntityNotFound(_0x411147,null))[_0x8d70('0x1f')](function(_0x47f9d3){if(_0x47f9d3){_0x2b4704=_0x47f9d3;return db[_0x8d70('0x80')][_0x8d70('0x5b')]({'where':{'id':_0x47f9d3['WhatsappAccountId']}});}})[_0x8d70('0x1f')](handleEntityNotFound(_0x411147,null))['then'](function(_0x54da47){if(_0x54da47){logger[_0x8d70('0x22')](_0x8d70('0x81'),_0x8d70('0x2b'),'received\x20delivery\x20report\x20from',_0x54da47[_0x8d70('0x3d')],util[_0x8d70('0x82')](_0xb884f3['body'],{'showHidden':![],'depth':null}));switch(_0x54da47['type']){case _0x8d70('0x83'):if(_0xb884f3[_0x8d70('0x52')][_0x8d70('0x84')]&&_0xb884f3[_0x8d70('0x52')][_0x8d70('0x84')]===_0x2b4704[_0x8d70('0x85')]&&_0xb884f3[_0x8d70('0x52')][_0x8d70('0x86')]&&_0xb884f3[_0x8d70('0x52')][_0x8d70('0x86')]===_0x8d70('0x87')){return _0x2b4704[_0x8d70('0x36')]({'read':!![]});}else{logger['error'](_0x8d70('0x88'),_0x8d70('0x2b'),_0x8d70('0x83'),util['inspect'](_0xb884f3[_0x8d70('0x52')],{'showHidden':![],'depth':null}));}break;}return _0x2b4704;}})['then'](respondWithResult(_0x411147,null))['catch'](handleError(_0x411147,null));};
\ No newline at end of file