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