Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / api / whatsappMessage / whatsappMessage.controller.js
index b275fa1..1aa7930 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf219=['jayson/promise','client','test','Sequelize','ValidationError','request','then','info','WhatsappMessage,\x20%s,\x20%s','request\x20sent','debug','WhatsappMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','status','end','json','count','offset','set','save','update','destroy','sendStatus','stack','name','send','index','map','WhatsappMessage','fieldName','type','query','keys','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','filters','pick','where','merge','VIRTUAL','filter','options','includeAll','include','findAll','show','params','rawAttributes','find','create','body','describe','whatsapp-interactions','whatsapp','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','CmContact','WhatsappInteraction','WhatsappInteractionId','isNil','interaction','get','role','acceptMessage','manual','interface','channel','event','EventManager','acceptmessage','reject','agent','null','RejectMessage','rejectMessage','rejectmessage','WhatsappAccount','WhatsppMessage,\x20%s,\x20%s,\x20%s','received\x20delivery\x20report\x20from','inspect','twilio','MessageSid','MessageStatus','WhatsappAccount,\x20%s,\x20%s,\x20%s','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','to-csv','ejs','lodash','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','defaults','redis','localhost'];(function(_0x5d90b8,_0x528b3a){var _0x5712b3=function(_0x478049){while(--_0x478049){_0x5d90b8['push'](_0x5d90b8['shift']());}};_0x5712b3(++_0x528b3a);}(_0xf219,0x65));var _0x9f21=function(_0xfc36d8,_0x233b0b){_0xfc36d8=_0xfc36d8-0x0;var _0x234f42=_0xf219[_0xfc36d8];return _0x234f42;};'use strict';var pdf=require(_0x9f21('0x0'));var emlformat=require(_0x9f21('0x1'));var rimraf=require(_0x9f21('0x2'));var zipdir=require(_0x9f21('0x3'));var jsonpatch=require(_0x9f21('0x4'));var rp=require(_0x9f21('0x5'));var moment=require(_0x9f21('0x6'));var BPromise=require('bluebird');var Mustache=require(_0x9f21('0x7'));var util=require(_0x9f21('0x8'));var path=require(_0x9f21('0x9'));var sox=require('sox');var csv=require(_0x9f21('0xa'));var ejs=require(_0x9f21('0xb'));var fs=require('fs');var _=require(_0x9f21('0xc'));var squel=require('squel');var crypto=require(_0x9f21('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x9f21('0xe'));var toCsv=require(_0x9f21('0xa'));var querystring=require(_0x9f21('0xf'));var Papa=require('papaparse');var Redis=require(_0x9f21('0x10'));var authService=require(_0x9f21('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x9f21('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x9f21('0x13'))(_0x9f21('0x14'));var utils=require(_0x9f21('0x15'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];config['redis']=_[_0x9f21('0x16')](config[_0x9f21('0x17')],{'host':_0x9f21('0x18'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x9f21('0x17')]));require('./whatsappMessage.socket')['register'](socket);var jayson=require(_0x9f21('0x19'));var client=jayson[_0x9f21('0x1a')]['http']({'port':0x232c});var client9002=jayson['client']['http']({'port':0x232a});function checkPasswordPattern(_0x3a5f4c,_0x50562b,_0x516447){if(_0x516447){var _0x696b=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x696b[_0x9f21('0x1b')](_0x50562b)){return _0x3a5f4c;}else{throw new db[(_0x9f21('0x1c'))][(_0x9f21('0x1d'))]('The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.');}}else{return _0x3a5f4c;}}function respondWithRpcPromise(_0x389450,_0x1543a4,_0x33cd90,_0x26ed27){return new BPromise(function(_0x37fdaf,_0x22c40e){var _0x19311e=_0x26ed27||client;return _0x19311e[_0x9f21('0x1e')](_0x389450,_0x33cd90)[_0x9f21('0x1f')](function(_0x3a3fc4){logger[_0x9f21('0x20')](_0x9f21('0x21'),_0x1543a4,_0x9f21('0x22'));logger[_0x9f21('0x23')](_0x9f21('0x24'),_0x1543a4,_0x9f21('0x22'),JSON[_0x9f21('0x25')](_0x3a3fc4));if(_0x3a3fc4[_0x9f21('0x26')]){if(_0x3a3fc4[_0x9f21('0x26')][_0x9f21('0x27')]===0x1f4){logger['error'](_0x9f21('0x21'),_0x1543a4,_0x3a3fc4[_0x9f21('0x26')][_0x9f21('0x28')]);return _0x22c40e(_0x3a3fc4['error'][_0x9f21('0x28')]);}logger['error'](_0x9f21('0x21'),_0x1543a4,_0x3a3fc4['error']['message']);return _0x37fdaf(_0x3a3fc4[_0x9f21('0x26')][_0x9f21('0x28')]);}else{logger[_0x9f21('0x20')](_0x9f21('0x21'),_0x1543a4,_0x9f21('0x22'));_0x37fdaf(_0x3a3fc4[_0x9f21('0x29')][_0x9f21('0x28')]);}})[_0x9f21('0x2a')](function(_0x1e98d8){logger['error']('WhatsappMessage,\x20%s,\x20%s',_0x1543a4,_0x1e98d8);_0x22c40e(_0x1e98d8);});});}function respondWithStatusCode(_0x28d4fd,_0x5a21bb){_0x5a21bb=_0x5a21bb||0xcc;return function(_0x4c862c){if(_0x4c862c){return _0x28d4fd['sendStatus'](_0x5a21bb);}return _0x28d4fd[_0x9f21('0x2b')](_0x5a21bb)[_0x9f21('0x2c')]();};}function respondWithResult(_0x1c6cda,_0x2513b2){_0x2513b2=_0x2513b2||0xc8;return function(_0x359676){if(_0x359676){return _0x1c6cda[_0x9f21('0x2b')](_0x2513b2)[_0x9f21('0x2d')](_0x359676);}};}function respondWithFilteredResult(_0x29a7af,_0x5264e7){return function(_0x416383){if(_0x416383){var _0x5a2838=_0x416383[_0x9f21('0x2e')],_0xe82c6d=_0x5264e7[_0x9f21('0x2f')],_0x16a8de=_0x5264e7[_0x9f21('0x2f')]+_0x5264e7['limit'],_0x5c5d75;if(_0x16a8de>=_0x5a2838){_0x16a8de=_0x5a2838;_0x5c5d75=0xc8;}else{_0x5c5d75=0xce;}_0x29a7af[_0x9f21('0x2b')](_0x5c5d75);return _0x29a7af[_0x9f21('0x30')]('Content-Range',_0xe82c6d+'-'+_0x16a8de+'/'+_0x5a2838)[_0x9f21('0x2d')](_0x416383);}return null;};}function patchUpdates(_0x356d68){return function(_0x3bd2b6){try{jsonpatch['apply'](_0x3bd2b6,_0x356d68,!![]);}catch(_0x583808){return BPromise['reject'](_0x583808);}return _0x3bd2b6[_0x9f21('0x31')]();};}function saveUpdates(_0x34add9,_0x22e32f){return function(_0x14e704){if(_0x14e704){return _0x14e704[_0x9f21('0x32')](_0x34add9)[_0x9f21('0x1f')](function(_0x20d3d3){return _0x20d3d3;});}return null;};}function removeEntity(_0x5bd101,_0x3c7db7){return function(_0xb36de9){if(_0xb36de9){return _0xb36de9[_0x9f21('0x33')]()[_0x9f21('0x1f')](function(){_0x5bd101[_0x9f21('0x2b')](0xcc)[_0x9f21('0x2c')]();});}};}function handleEntityNotFound(_0x5ec834,_0x250eb9){return function(_0x28d7c2){if(!_0x28d7c2){_0x5ec834[_0x9f21('0x34')](0x194);}return _0x28d7c2;};}function handleError(_0x24af3c,_0xd0aa09){_0xd0aa09=_0xd0aa09||0x1f4;return function(_0x437f7b){logger[_0x9f21('0x26')](_0x437f7b[_0x9f21('0x35')]);if(_0x437f7b[_0x9f21('0x36')]){delete _0x437f7b['name'];}_0x24af3c['status'](_0xd0aa09)[_0x9f21('0x37')](_0x437f7b);};}exports[_0x9f21('0x38')]=function(_0x389304,_0x1d5ea2){var _0x14aeab={},_0x46feec={},_0x4d2405={'count':0x0,'rows':[]};var _0x537cbb=_[_0x9f21('0x39')](db[_0x9f21('0x3a')]['rawAttributes'],function(_0x116a82){return{'name':_0x116a82[_0x9f21('0x3b')],'type':_0x116a82[_0x9f21('0x3c')]['key']};});_0x46feec['model']=_[_0x9f21('0x39')](_0x537cbb,_0x9f21('0x36'));_0x46feec[_0x9f21('0x3d')]=_[_0x9f21('0x3e')](_0x389304[_0x9f21('0x3d')]);_0x46feec['filters']=_[_0x9f21('0x3f')](_0x46feec[_0x9f21('0x40')],_0x46feec[_0x9f21('0x3d')]);_0x14aeab[_0x9f21('0x41')]=_[_0x9f21('0x3f')](_0x46feec['model'],qs[_0x9f21('0x42')](_0x389304[_0x9f21('0x3d')]['fields']));_0x14aeab['attributes']=_0x14aeab['attributes'][_0x9f21('0x43')]?_0x14aeab[_0x9f21('0x41')]:_0x46feec['model'];if(!_0x389304[_0x9f21('0x3d')][_0x9f21('0x44')](_0x9f21('0x45'))){_0x14aeab[_0x9f21('0x46')]=qs[_0x9f21('0x46')](_0x389304['query'][_0x9f21('0x46')]);_0x14aeab['offset']=qs[_0x9f21('0x2f')](_0x389304[_0x9f21('0x3d')][_0x9f21('0x2f')]);}_0x14aeab[_0x9f21('0x47')]=qs[_0x9f21('0x48')](_0x389304[_0x9f21('0x3d')][_0x9f21('0x48')]);_0x14aeab['where']=qs[_0x9f21('0x49')](_[_0x9f21('0x4a')](_0x389304['query'],_0x46feec[_0x9f21('0x49')]),_0x537cbb);if(_0x389304['query']['filter']){_0x14aeab[_0x9f21('0x4b')]=_[_0x9f21('0x4c')](_0x14aeab[_0x9f21('0x4b')],{'$or':_['map'](_0x537cbb,function(_0x493c41){if(_0x493c41[_0x9f21('0x3c')]!==_0x9f21('0x4d')){var _0x89fa60={};_0x89fa60[_0x493c41[_0x9f21('0x36')]]={'$like':'%'+_0x389304[_0x9f21('0x3d')][_0x9f21('0x4e')]+'%'};return _0x89fa60;}})});}_0x14aeab=_[_0x9f21('0x4c')]({},_0x14aeab,_0x389304[_0x9f21('0x4f')]);var _0x1f31e6={'where':_0x14aeab[_0x9f21('0x4b')]};return db[_0x9f21('0x3a')]['count'](_0x1f31e6)['then'](function(_0x47484b){_0x4d2405[_0x9f21('0x2e')]=_0x47484b;if(_0x389304[_0x9f21('0x3d')][_0x9f21('0x50')]){_0x14aeab[_0x9f21('0x51')]=[{'all':!![]}];}return db[_0x9f21('0x3a')][_0x9f21('0x52')](_0x14aeab);})[_0x9f21('0x1f')](function(_0x4401a6){_0x4d2405['rows']=_0x4401a6;return _0x4d2405;})['then'](respondWithFilteredResult(_0x1d5ea2,_0x14aeab))[_0x9f21('0x2a')](handleError(_0x1d5ea2,null));};exports[_0x9f21('0x53')]=function(_0x4e6ecc,_0x16d4af){var _0x2e85a={'raw':!![],'where':{'id':_0x4e6ecc[_0x9f21('0x54')]['id']}},_0x1f75e1={};_0x1f75e1[_0x9f21('0x40')]=_[_0x9f21('0x3e')](db[_0x9f21('0x3a')][_0x9f21('0x55')]);_0x1f75e1[_0x9f21('0x3d')]=_[_0x9f21('0x3e')](_0x4e6ecc[_0x9f21('0x3d')]);_0x1f75e1[_0x9f21('0x49')]=_['intersection'](_0x1f75e1[_0x9f21('0x40')],_0x1f75e1[_0x9f21('0x3d')]);_0x2e85a['attributes']=_[_0x9f21('0x3f')](_0x1f75e1[_0x9f21('0x40')],qs['fields'](_0x4e6ecc['query'][_0x9f21('0x42')]));_0x2e85a[_0x9f21('0x41')]=_0x2e85a[_0x9f21('0x41')][_0x9f21('0x43')]?_0x2e85a[_0x9f21('0x41')]:_0x1f75e1[_0x9f21('0x40')];if(_0x4e6ecc[_0x9f21('0x3d')][_0x9f21('0x50')]){_0x2e85a['include']=[{'all':!![]}];}_0x2e85a=_[_0x9f21('0x4c')]({},_0x2e85a,_0x4e6ecc[_0x9f21('0x4f')]);return db[_0x9f21('0x3a')][_0x9f21('0x56')](_0x2e85a)[_0x9f21('0x1f')](handleEntityNotFound(_0x16d4af,null))['then'](respondWithResult(_0x16d4af,null))['catch'](handleError(_0x16d4af,null));};exports['create']=function(_0x2331bc,_0x40adc6){return db[_0x9f21('0x3a')][_0x9f21('0x57')](_0x2331bc['body'],{})[_0x9f21('0x1f')](respondWithResult(_0x40adc6,0xc9))[_0x9f21('0x2a')](handleError(_0x40adc6,null));};exports[_0x9f21('0x32')]=function(_0x203253,_0xce8fe9){if(_0x203253[_0x9f21('0x58')]['id']){delete _0x203253[_0x9f21('0x58')]['id'];}return db['WhatsappMessage'][_0x9f21('0x56')]({'where':{'id':_0x203253[_0x9f21('0x54')]['id']}})[_0x9f21('0x1f')](handleEntityNotFound(_0xce8fe9,null))[_0x9f21('0x1f')](saveUpdates(_0x203253[_0x9f21('0x58')],null))['then'](respondWithResult(_0xce8fe9,null))[_0x9f21('0x2a')](handleError(_0xce8fe9,null));};exports[_0x9f21('0x33')]=function(_0x394852,_0x579d2e){return db[_0x9f21('0x3a')][_0x9f21('0x56')]({'where':{'id':_0x394852[_0x9f21('0x54')]['id']}})['then'](handleEntityNotFound(_0x579d2e,null))['then'](removeEntity(_0x579d2e,null))[_0x9f21('0x2a')](handleError(_0x579d2e,null));};exports[_0x9f21('0x59')]=function(_0x2b90da,_0xa4df57){return db[_0x9f21('0x3a')][_0x9f21('0x59')]()['then'](respondWithResult(_0xa4df57,null))['catch'](handleError(_0xa4df57,null));};var interaction_log=require(_0x9f21('0x13'))(_0x9f21('0x5a'));exports['accept']=function(_0x1eed8b,_0x2b6c06,_0x630b86){var _0x52a61f={'channel':_0x9f21('0x5b')};if(_0x1eed8b[_0x9f21('0x58')]['id']){delete _0x1eed8b[_0x9f21('0x58')]['id'];}_0x1eed8b[_0x9f21('0x58')][_0x9f21('0x5c')]=!![];_0x1eed8b[_0x9f21('0x58')][_0x9f21('0x5d')]=moment()[_0x9f21('0x5e')](_0x9f21('0x5f'));_0x1eed8b[_0x9f21('0x58')][_0x9f21('0x60')]=_0x1eed8b[_0x9f21('0x58')][_0x9f21('0x60')]||_0x1eed8b[_0x9f21('0x61')]['id'];return db['WhatsappMessage'][_0x9f21('0x56')]({'where':{'id':_0x1eed8b['params']['id'],'UserId':null},'include':[{'model':db[_0x9f21('0x62')],'as':'Contact'}]})['then'](handleEntityNotFound(_0x2b6c06,null))[_0x9f21('0x1f')](saveUpdates(_0x1eed8b[_0x9f21('0x58')],null))[_0x9f21('0x1f')](function(_0x570876){if(_0x570876){_0x52a61f[_0x9f21('0x28')]=_0x570876['get']({'plain':!![]});return db[_0x9f21('0x63')][_0x9f21('0x56')]({'where':{'id':_0x570876[_0x9f21('0x64')]}});}return null;})[_0x9f21('0x1f')](handleEntityNotFound(_0x2b6c06,null))[_0x9f21('0x1f')](function(_0x159f3f){if(_0x159f3f){return _0x159f3f['update']({'UserId':_0x1eed8b[_0x9f21('0x58')][_0x9f21('0x60')],'read1stAt':_[_0x9f21('0x65')](_0x159f3f['read1stAt'])?moment()[_0x9f21('0x5e')](_0x9f21('0x5f')):undefined});}return null;})[_0x9f21('0x1f')](function(_0x4cf0a3){if(_0x4cf0a3){_0x52a61f[_0x9f21('0x66')]=_0x4cf0a3[_0x9f21('0x67')]({'plain':!![]});interaction_log[_0x9f21('0x20')]('[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x1eed8b['user']['id'],_0x1eed8b['user'][_0x9f21('0x36')],_0x1eed8b['user'][_0x9f21('0x68')],_0x52a61f[_0x9f21('0x66')]['id'],_0x1eed8b['body']?JSON[_0x9f21('0x25')](_0x1eed8b['body']):'null');return respondWithRpcPromise('AcceptMessage',_0x9f21('0x69'),_0x52a61f);}return null;})[_0x9f21('0x1f')](function(_0x5aa32c){if(_0x5aa32c){if(_0x1eed8b[_0x9f21('0x58')][_0x9f21('0x6a')]){_0x52a61f['message'][_0x9f21('0x6b')]=util['format']('SIP/%s',_0x1eed8b[_0x9f21('0x61')]['name']);_0x52a61f[_0x9f21('0x28')][_0x9f21('0x6c')]=_0x52a61f[_0x9f21('0x6c')];_0x52a61f[_0x9f21('0x28')][_0x9f21('0x6d')]='accept';return respondWithRpcPromise(_0x9f21('0x6e'),_0x9f21('0x6e'),{'event':_0x9f21('0x6f'),'message':_0x52a61f['message']},client9002)[_0x9f21('0x1f')](function(){return _0x52a61f;});}return _0x52a61f;}return null;})[_0x9f21('0x1f')](respondWithResult(_0x2b6c06,null))[_0x9f21('0x2a')](handleError(_0x2b6c06,null));};var interaction_log=require(_0x9f21('0x13'))(_0x9f21('0x5a'));exports[_0x9f21('0x70')]=function(_0x5445d6,_0x77a419,_0x44696b){var _0x4e53fa={'agent':{},'channel':_0x9f21('0x5b')};if(_0x5445d6[_0x9f21('0x58')]['id']){delete _0x5445d6[_0x9f21('0x58')]['id'];}_0x5445d6[_0x9f21('0x58')]['UserId']=_0x5445d6[_0x9f21('0x58')][_0x9f21('0x60')]||_0x5445d6['user']['id'];_0x4e53fa[_0x9f21('0x71')]['id']=_0x5445d6['body'][_0x9f21('0x60')];return db[_0x9f21('0x3a')][_0x9f21('0x56')]({'where':{'id':_0x5445d6['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x77a419,null))[_0x9f21('0x1f')](function(_0x30c677){if(_0x30c677){_0x4e53fa[_0x9f21('0x28')]=_0x30c677[_0x9f21('0x67')]({'plain':!![]});return db[_0x9f21('0x63')][_0x9f21('0x56')]({'where':{'id':_0x30c677['WhatsappInteractionId']}});}return null;})[_0x9f21('0x1f')](handleEntityNotFound(_0x77a419,null))['then'](function(_0x50d8a4){if(_0x50d8a4){_0x4e53fa['interaction']=_0x50d8a4[_0x9f21('0x67')]({'plain':!![]});interaction_log[_0x9f21('0x20')]('[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x5445d6[_0x9f21('0x61')]['id'],_0x5445d6[_0x9f21('0x61')][_0x9f21('0x36')],_0x5445d6['user']['role'],_0x4e53fa['interaction']['id'],_0x5445d6['body']?JSON[_0x9f21('0x25')](_0x5445d6['body']):_0x9f21('0x72'));return respondWithRpcPromise(_0x9f21('0x73'),_0x9f21('0x74'),_0x4e53fa);}return null;})['then'](function(_0x110f56){if(_0x110f56){_0x110f56[_0x9f21('0x28')][_0x9f21('0x6b')]=util[_0x9f21('0x5e')]('SIP/%s',_0x5445d6[_0x9f21('0x61')][_0x9f21('0x36')]);_0x110f56[_0x9f21('0x28')][_0x9f21('0x6c')]=_0x4e53fa[_0x9f21('0x6c')];_0x110f56['message'][_0x9f21('0x6d')]=_0x9f21('0x70');respondWithRpcPromise(_0x9f21('0x6e'),_0x9f21('0x6e'),{'event':_0x9f21('0x75'),'message':_0x110f56['message']},client9002);return _0x4e53fa;}return null;})[_0x9f21('0x1f')](respondWithResult(_0x77a419,null))[_0x9f21('0x2a')](handleError(_0x77a419,null));};exports[_0x9f21('0x2b')]=function(_0x144371,_0x21d4ad,_0x24d177){if(_0x144371[_0x9f21('0x58')]['id']){delete _0x144371[_0x9f21('0x58')]['id'];}var _0x5cea1e;return db[_0x9f21('0x3a')][_0x9f21('0x56')]({'where':{'id':_0x144371['params']['id']}})[_0x9f21('0x1f')](handleEntityNotFound(_0x21d4ad,null))[_0x9f21('0x1f')](function(_0x27171a){if(_0x27171a){_0x5cea1e=_0x27171a;return db[_0x9f21('0x76')][_0x9f21('0x56')]({'where':{'id':_0x27171a['WhatsappAccountId']}});}})['then'](handleEntityNotFound(_0x21d4ad,null))[_0x9f21('0x1f')](function(_0x59a0de){if(_0x59a0de){logger['debug'](_0x9f21('0x77'),_0x9f21('0x2b'),_0x9f21('0x78'),_0x59a0de[_0x9f21('0x3c')],util[_0x9f21('0x79')](_0x144371[_0x9f21('0x58')],{'showHidden':![],'depth':null}));switch(_0x59a0de['type']){case _0x9f21('0x7a'):if(_0x144371[_0x9f21('0x58')][_0x9f21('0x7b')]&&_0x144371[_0x9f21('0x58')][_0x9f21('0x7b')]===_0x5cea1e['messageId']&&_0x144371['body'][_0x9f21('0x7c')]&&_0x144371[_0x9f21('0x58')][_0x9f21('0x7c')]===_0x9f21('0x5c')){return _0x5cea1e[_0x9f21('0x32')]({'read':!![]});}else{logger[_0x9f21('0x26')](_0x9f21('0x7d'),_0x9f21('0x2b'),_0x9f21('0x7a'),util['inspect'](_0x144371[_0x9f21('0x58')],{'showHidden':![],'depth':null}));}break;}return _0x5cea1e;}})[_0x9f21('0x1f')](respondWithResult(_0x21d4ad,null))[_0x9f21('0x2a')](handleError(_0x21d4ad,null));};
\ No newline at end of file
+var _0x1751=['fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','redis','defaults','localhost','socket.io-emitter','register','jayson/promise','client','info','WhatsappMessage,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','status','end','limit','undefined','offset','set','Content-Range','apply','save','update','then','name','map','WhatsappMessage','rawAttributes','fieldName','type','key','model','query','keys','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filters','merge','VIRTUAL','filter','options','count','include','findAll','rows','show','params','find','create','describe','accept','whatsapp','body','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','CmContact','get','WhatsappInteraction','isNil','interaction','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','AcceptMessage','acceptMessage','manual','interface','SIP/%s','channel','event','EventManager','acceptmessage','reject','[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','null','RejectMessage','rejectMessage','WhatsappAccount','WhatsappAccountId','received\x20delivery\x20report\x20from','inspect','twilio','MessageSid','messageId','MessageStatus','WhatsappAccount,\x20%s,\x20%s,\x20%s','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs'];(function(_0x2fc1ce,_0x250865){var _0x2cf1ab=function(_0x5eaef4){while(--_0x5eaef4){_0x2fc1ce['push'](_0x2fc1ce['shift']());}};_0x2cf1ab(++_0x250865);}(_0x1751,0x76));var _0x1175=function(_0xae79bd,_0x53f201){_0xae79bd=_0xae79bd-0x0;var _0x1ba1b4=_0x1751[_0xae79bd];return _0x1ba1b4;};'use strict';var emlformat=require(_0x1175('0x0'));var rimraf=require(_0x1175('0x1'));var zipdir=require(_0x1175('0x2'));var jsonpatch=require(_0x1175('0x3'));var rp=require('request-promise');var moment=require(_0x1175('0x4'));var BPromise=require(_0x1175('0x5'));var Mustache=require(_0x1175('0x6'));var util=require(_0x1175('0x7'));var path=require(_0x1175('0x8'));var sox=require(_0x1175('0x9'));var csv=require(_0x1175('0xa'));var ejs=require(_0x1175('0xb'));var fs=require('fs');var fs_extra=require(_0x1175('0xc'));var _=require(_0x1175('0xd'));var squel=require(_0x1175('0xe'));var crypto=require(_0x1175('0xf'));var jsforce=require(_0x1175('0x10'));var deskjs=require(_0x1175('0x11'));var toCsv=require(_0x1175('0xa'));var querystring=require(_0x1175('0x12'));var Papa=require(_0x1175('0x13'));var Redis=require(_0x1175('0x14'));var authService=require(_0x1175('0x15'));var qs=require(_0x1175('0x16'));var as=require(_0x1175('0x17'));var hardwareService=require(_0x1175('0x18'));var logger=require(_0x1175('0x19'))(_0x1175('0x1a'));var utils=require(_0x1175('0x1b'));var config=require(_0x1175('0x1c'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0x1175('0x1d')]=_[_0x1175('0x1e')](config['redis'],{'host':_0x1175('0x1f'),'port':0x18eb});var socket=require(_0x1175('0x20'))(new Redis(config[_0x1175('0x1d')]));require('./whatsappMessage.socket')[_0x1175('0x21')](socket);var jayson=require(_0x1175('0x22'));var client=jayson[_0x1175('0x23')]['http']({'port':0x232c});var client9002=jayson[_0x1175('0x23')]['http']({'port':0x232a});function respondWithRpcPromise(_0x14be3c,_0x43b6b1,_0x2a9bc4,_0x2585be){return new BPromise(function(_0x5c1a14,_0x18119f){var _0xaa45d=_0x2585be||client;return _0xaa45d['request'](_0x14be3c,_0x2a9bc4)['then'](function(_0x40b685){logger[_0x1175('0x24')](_0x1175('0x25'),_0x43b6b1,_0x1175('0x26'));logger[_0x1175('0x27')]('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0x43b6b1,_0x1175('0x26'),JSON[_0x1175('0x28')](_0x40b685));if(_0x40b685[_0x1175('0x29')]){if(_0x40b685[_0x1175('0x29')][_0x1175('0x2a')]===0x1f4){logger[_0x1175('0x29')]('WhatsappMessage,\x20%s,\x20%s',_0x43b6b1,_0x40b685['error'][_0x1175('0x2b')]);return _0x18119f(_0x40b685[_0x1175('0x29')][_0x1175('0x2b')]);}logger[_0x1175('0x29')](_0x1175('0x25'),_0x43b6b1,_0x40b685[_0x1175('0x29')][_0x1175('0x2b')]);return _0x5c1a14(_0x40b685['error'][_0x1175('0x2b')]);}else{logger[_0x1175('0x24')](_0x1175('0x25'),_0x43b6b1,_0x1175('0x26'));_0x5c1a14(_0x40b685[_0x1175('0x2c')][_0x1175('0x2b')]);}})[_0x1175('0x2d')](function(_0x5a3dc9){logger[_0x1175('0x29')](_0x1175('0x25'),_0x43b6b1,_0x5a3dc9);_0x18119f(_0x5a3dc9);});});}function respondWithStatusCode(_0x38cf17,_0x5ad9b5){_0x5ad9b5=_0x5ad9b5||0xcc;return function(_0x491901){if(_0x491901){return _0x38cf17['sendStatus'](_0x5ad9b5);}return _0x38cf17[_0x1175('0x2e')](_0x5ad9b5)[_0x1175('0x2f')]();};}function respondWithResult(_0x3fd476,_0x5e4ac6){_0x5e4ac6=_0x5e4ac6||0xc8;return function(_0x5884a3){if(_0x5884a3){return _0x3fd476['status'](_0x5e4ac6)['json'](_0x5884a3);}};}function respondWithFilteredResult(_0x3abc9c,_0x3db0f7){return function(_0x1fabfb){if(_0x1fabfb){var _0x1e29d0=typeof _0x3db0f7['offset']==='undefined'&&typeof _0x3db0f7[_0x1175('0x30')]===_0x1175('0x31');var _0x57f7a8=_0x1fabfb['count'];var _0x5b6bfb=_0x1e29d0?0x0:_0x3db0f7[_0x1175('0x32')];var _0x305939=_0x1e29d0?_0x1fabfb['count']:_0x3db0f7[_0x1175('0x32')]+_0x3db0f7[_0x1175('0x30')];var _0x135d1b;if(_0x305939>=_0x57f7a8){_0x305939=_0x57f7a8;_0x135d1b=0xc8;}else{_0x135d1b=0xce;}_0x3abc9c[_0x1175('0x2e')](_0x135d1b);return _0x3abc9c[_0x1175('0x33')](_0x1175('0x34'),_0x5b6bfb+'-'+_0x305939+'/'+_0x57f7a8)['json'](_0x1fabfb);}return null;};}function patchUpdates(_0x3a32ec){return function(_0x399f53){try{jsonpatch[_0x1175('0x35')](_0x399f53,_0x3a32ec,!![]);}catch(_0x35929e){return BPromise['reject'](_0x35929e);}return _0x399f53[_0x1175('0x36')]();};}function saveUpdates(_0x5c0b9f,_0x476822){return function(_0x115e62){if(_0x115e62){return _0x115e62[_0x1175('0x37')](_0x5c0b9f)[_0x1175('0x38')](function(_0x6ec44b){return _0x6ec44b;});}return null;};}function removeEntity(_0x28bbb7,_0x574d77){return function(_0x49ed96){if(_0x49ed96){return _0x49ed96['destroy']()[_0x1175('0x38')](function(){_0x28bbb7[_0x1175('0x2e')](0xcc)[_0x1175('0x2f')]();});}};}function handleEntityNotFound(_0x40d809,_0x1661ae){return function(_0x2beda3){if(!_0x2beda3){_0x40d809['sendStatus'](0x194);}return _0x2beda3;};}function handleError(_0x4a10cd,_0x3862f4){_0x3862f4=_0x3862f4||0x1f4;return function(_0x325cb7){logger[_0x1175('0x29')](_0x325cb7['stack']);if(_0x325cb7[_0x1175('0x39')]){delete _0x325cb7[_0x1175('0x39')];}_0x4a10cd[_0x1175('0x2e')](_0x3862f4)['send'](_0x325cb7);};}exports['index']=function(_0x57650d,_0x177715){var _0x561023={},_0x20e9b1={},_0x23c0fc={'count':0x0,'rows':[]};var _0x43bb01=_[_0x1175('0x3a')](db[_0x1175('0x3b')][_0x1175('0x3c')],function(_0x2240d2){return{'name':_0x2240d2[_0x1175('0x3d')],'type':_0x2240d2[_0x1175('0x3e')][_0x1175('0x3f')]};});_0x20e9b1[_0x1175('0x40')]=_[_0x1175('0x3a')](_0x43bb01,_0x1175('0x39'));_0x20e9b1[_0x1175('0x41')]=_[_0x1175('0x42')](_0x57650d[_0x1175('0x41')]);_0x20e9b1['filters']=_[_0x1175('0x43')](_0x20e9b1[_0x1175('0x40')],_0x20e9b1[_0x1175('0x41')]);_0x561023['attributes']=_[_0x1175('0x43')](_0x20e9b1[_0x1175('0x40')],qs[_0x1175('0x44')](_0x57650d[_0x1175('0x41')][_0x1175('0x44')]));_0x561023['attributes']=_0x561023[_0x1175('0x45')][_0x1175('0x46')]?_0x561023[_0x1175('0x45')]:_0x20e9b1[_0x1175('0x40')];if(!_0x57650d['query'][_0x1175('0x47')](_0x1175('0x48'))){_0x561023[_0x1175('0x30')]=qs['limit'](_0x57650d[_0x1175('0x41')]['limit']);_0x561023[_0x1175('0x32')]=qs[_0x1175('0x32')](_0x57650d[_0x1175('0x41')][_0x1175('0x32')]);}_0x561023[_0x1175('0x49')]=qs[_0x1175('0x4a')](_0x57650d[_0x1175('0x41')][_0x1175('0x4a')]);_0x561023[_0x1175('0x4b')]=qs[_0x1175('0x4c')](_['pick'](_0x57650d['query'],_0x20e9b1[_0x1175('0x4c')]),_0x43bb01);if(_0x57650d[_0x1175('0x41')]['filter']){_0x561023[_0x1175('0x4b')]=_[_0x1175('0x4d')](_0x561023['where'],{'$or':_[_0x1175('0x3a')](_0x43bb01,function(_0x1ed96f){if(_0x1ed96f[_0x1175('0x3e')]!==_0x1175('0x4e')){var _0x18e8d5={};_0x18e8d5[_0x1ed96f[_0x1175('0x39')]]={'$like':'%'+_0x57650d[_0x1175('0x41')][_0x1175('0x4f')]+'%'};return _0x18e8d5;}})});}_0x561023=_[_0x1175('0x4d')]({},_0x561023,_0x57650d[_0x1175('0x50')]);var _0x2e49d9={'where':_0x561023[_0x1175('0x4b')]};return db[_0x1175('0x3b')][_0x1175('0x51')](_0x2e49d9)[_0x1175('0x38')](function(_0x33f2c1){_0x23c0fc[_0x1175('0x51')]=_0x33f2c1;if(_0x57650d['query']['includeAll']){_0x561023[_0x1175('0x52')]=[{'all':!![]}];}return db[_0x1175('0x3b')][_0x1175('0x53')](_0x561023);})['then'](function(_0x2f69f5){_0x23c0fc[_0x1175('0x54')]=_0x2f69f5;return _0x23c0fc;})[_0x1175('0x38')](respondWithFilteredResult(_0x177715,_0x561023))[_0x1175('0x2d')](handleError(_0x177715,null));};exports[_0x1175('0x55')]=function(_0x92cca9,_0x49b6c6){var _0x71c6bc={'raw':!![],'where':{'id':_0x92cca9[_0x1175('0x56')]['id']}},_0x3a44a6={};_0x3a44a6[_0x1175('0x40')]=_[_0x1175('0x42')](db[_0x1175('0x3b')][_0x1175('0x3c')]);_0x3a44a6[_0x1175('0x41')]=_[_0x1175('0x42')](_0x92cca9['query']);_0x3a44a6['filters']=_[_0x1175('0x43')](_0x3a44a6[_0x1175('0x40')],_0x3a44a6[_0x1175('0x41')]);_0x71c6bc[_0x1175('0x45')]=_['intersection'](_0x3a44a6[_0x1175('0x40')],qs['fields'](_0x92cca9['query'][_0x1175('0x44')]));_0x71c6bc[_0x1175('0x45')]=_0x71c6bc[_0x1175('0x45')]['length']?_0x71c6bc[_0x1175('0x45')]:_0x3a44a6[_0x1175('0x40')];if(_0x92cca9[_0x1175('0x41')]['includeAll']){_0x71c6bc['include']=[{'all':!![]}];}_0x71c6bc=_[_0x1175('0x4d')]({},_0x71c6bc,_0x92cca9[_0x1175('0x50')]);return db[_0x1175('0x3b')][_0x1175('0x57')](_0x71c6bc)[_0x1175('0x38')](handleEntityNotFound(_0x49b6c6,null))[_0x1175('0x38')](respondWithResult(_0x49b6c6,null))[_0x1175('0x2d')](handleError(_0x49b6c6,null));};exports[_0x1175('0x58')]=function(_0x213b7c,_0x191b44){return db[_0x1175('0x3b')][_0x1175('0x58')](_0x213b7c['body'],{})['then'](respondWithResult(_0x191b44,0xc9))[_0x1175('0x2d')](handleError(_0x191b44,null));};exports[_0x1175('0x37')]=function(_0x527c58,_0x306160){if(_0x527c58['body']['id']){delete _0x527c58['body']['id'];}return db[_0x1175('0x3b')][_0x1175('0x57')]({'where':{'id':_0x527c58[_0x1175('0x56')]['id']}})[_0x1175('0x38')](handleEntityNotFound(_0x306160,null))[_0x1175('0x38')](saveUpdates(_0x527c58['body'],null))['then'](respondWithResult(_0x306160,null))['catch'](handleError(_0x306160,null));};exports['destroy']=function(_0x3070b7,_0x2e2654){return db['WhatsappMessage'][_0x1175('0x57')]({'where':{'id':_0x3070b7[_0x1175('0x56')]['id']}})[_0x1175('0x38')](handleEntityNotFound(_0x2e2654,null))[_0x1175('0x38')](removeEntity(_0x2e2654,null))[_0x1175('0x2d')](handleError(_0x2e2654,null));};exports[_0x1175('0x59')]=function(_0x12d02d,_0x23316e){return db[_0x1175('0x3b')][_0x1175('0x59')]()['then'](respondWithResult(_0x23316e,null))[_0x1175('0x2d')](handleError(_0x23316e,null));};var interaction_log=require(_0x1175('0x19'))('whatsapp-interactions');exports[_0x1175('0x5a')]=function(_0x2e03be,_0x4606c8,_0xcab9c4){var _0x470f8b={'agent':{},'channel':_0x1175('0x5b')};if(_0x2e03be[_0x1175('0x5c')]['id']){delete _0x2e03be['body']['id'];}_0x2e03be[_0x1175('0x5c')][_0x1175('0x5d')]=!![];_0x2e03be['body'][_0x1175('0x5e')]=moment()[_0x1175('0x5f')](_0x1175('0x60'));_0x2e03be[_0x1175('0x5c')][_0x1175('0x61')]=_0x2e03be['body']['UserId']||_0x2e03be[_0x1175('0x62')]['id'];_0x470f8b[_0x1175('0x63')]['id']=_0x2e03be['body'][_0x1175('0x61')];return db['WhatsappMessage']['find']({'where':{'id':_0x2e03be[_0x1175('0x56')]['id'],'UserId':null},'include':[{'model':db[_0x1175('0x64')],'as':'Contact'}]})[_0x1175('0x38')](handleEntityNotFound(_0x4606c8,null))[_0x1175('0x38')](saveUpdates(_0x2e03be[_0x1175('0x5c')],null))[_0x1175('0x38')](function(_0x3f3a7){if(_0x3f3a7){_0x470f8b[_0x1175('0x2b')]=_0x3f3a7[_0x1175('0x65')]({'plain':!![]});return db[_0x1175('0x66')]['find']({'where':{'id':_0x3f3a7['WhatsappInteractionId']}});}return null;})[_0x1175('0x38')](handleEntityNotFound(_0x4606c8,null))['then'](function(_0x1ab407){if(_0x1ab407){return _0x1ab407[_0x1175('0x37')]({'UserId':_0x2e03be[_0x1175('0x5c')]['UserId'],'read1stAt':_[_0x1175('0x67')](_0x1ab407['read1stAt'])?moment()['format'](_0x1175('0x60')):undefined});}return null;})[_0x1175('0x38')](function(_0x319adb){if(_0x319adb){_0x470f8b[_0x1175('0x68')]=_0x319adb['get']({'plain':!![]});interaction_log['info'](_0x1175('0x69'),_0x2e03be[_0x1175('0x62')]['id'],_0x2e03be['user'][_0x1175('0x39')],_0x2e03be['user'][_0x1175('0x6a')],_0x470f8b[_0x1175('0x68')]['id'],_0x2e03be['body']?JSON['stringify'](_0x2e03be[_0x1175('0x5c')]):'null');return respondWithRpcPromise(_0x1175('0x6b'),_0x1175('0x6c'),_0x470f8b);}return null;})[_0x1175('0x38')](function(_0x2a4926){if(_0x2a4926){if(_0x2e03be[_0x1175('0x5c')][_0x1175('0x6d')]){_0x470f8b[_0x1175('0x2b')][_0x1175('0x6e')]=util[_0x1175('0x5f')](_0x1175('0x6f'),_0x2e03be[_0x1175('0x62')][_0x1175('0x39')]);_0x470f8b['message']['channel']=_0x470f8b[_0x1175('0x70')];_0x470f8b['message'][_0x1175('0x71')]='accept';return respondWithRpcPromise(_0x1175('0x72'),_0x1175('0x72'),{'event':_0x1175('0x73'),'message':_0x470f8b[_0x1175('0x2b')]},client9002)[_0x1175('0x38')](function(){return _0x470f8b;});}return _0x470f8b;}return null;})[_0x1175('0x38')](respondWithResult(_0x4606c8,null))[_0x1175('0x2d')](handleError(_0x4606c8,null));};var interaction_log=require(_0x1175('0x19'))('whatsapp-interactions');exports[_0x1175('0x74')]=function(_0x32f145,_0x56b312,_0x1a4241){var _0xbeb3fc={'agent':{},'channel':'whatsapp'};if(_0x32f145[_0x1175('0x5c')]['id']){delete _0x32f145[_0x1175('0x5c')]['id'];}_0x32f145[_0x1175('0x5c')][_0x1175('0x61')]=_0x32f145[_0x1175('0x5c')][_0x1175('0x61')]||_0x32f145[_0x1175('0x62')]['id'];_0xbeb3fc[_0x1175('0x63')]['id']=_0x32f145['body']['UserId'];return db[_0x1175('0x3b')][_0x1175('0x57')]({'where':{'id':_0x32f145[_0x1175('0x56')]['id'],'UserId':null}})[_0x1175('0x38')](handleEntityNotFound(_0x56b312,null))[_0x1175('0x38')](function(_0x233053){if(_0x233053){_0xbeb3fc[_0x1175('0x2b')]=_0x233053[_0x1175('0x65')]({'plain':!![]});return db[_0x1175('0x66')]['find']({'where':{'id':_0x233053['WhatsappInteractionId']}});}return null;})[_0x1175('0x38')](handleEntityNotFound(_0x56b312,null))[_0x1175('0x38')](function(_0x56fc3f){if(_0x56fc3f){_0xbeb3fc[_0x1175('0x68')]=_0x56fc3f[_0x1175('0x65')]({'plain':!![]});interaction_log[_0x1175('0x24')](_0x1175('0x75'),_0x32f145[_0x1175('0x62')]['id'],_0x32f145['user'][_0x1175('0x39')],_0x32f145[_0x1175('0x62')][_0x1175('0x6a')],_0xbeb3fc[_0x1175('0x68')]['id'],_0x32f145[_0x1175('0x5c')]?JSON[_0x1175('0x28')](_0x32f145[_0x1175('0x5c')]):_0x1175('0x76'));return respondWithRpcPromise(_0x1175('0x77'),_0x1175('0x78'),_0xbeb3fc);}return null;})['then'](function(_0x56dcdb){if(_0x56dcdb){_0x56dcdb['message'][_0x1175('0x6e')]=util[_0x1175('0x5f')](_0x1175('0x6f'),_0x32f145['user'][_0x1175('0x39')]);_0x56dcdb[_0x1175('0x2b')][_0x1175('0x70')]=_0xbeb3fc[_0x1175('0x70')];_0x56dcdb['message'][_0x1175('0x71')]=_0x1175('0x74');respondWithRpcPromise(_0x1175('0x72'),_0x1175('0x72'),{'event':'rejectmessage','message':_0x56dcdb[_0x1175('0x2b')]},client9002);return _0xbeb3fc;}return null;})[_0x1175('0x38')](respondWithResult(_0x56b312,null))['catch'](handleError(_0x56b312,null));};exports['status']=function(_0x58ec1f,_0x3a0a71,_0x30b1f3){if(_0x58ec1f['body']['id']){delete _0x58ec1f['body']['id'];}var _0x53288a;return db[_0x1175('0x3b')]['find']({'where':{'id':_0x58ec1f['params']['id']}})['then'](handleEntityNotFound(_0x3a0a71,null))[_0x1175('0x38')](function(_0x4c2cb2){if(_0x4c2cb2){_0x53288a=_0x4c2cb2;return db[_0x1175('0x79')][_0x1175('0x57')]({'where':{'id':_0x4c2cb2[_0x1175('0x7a')]}});}})[_0x1175('0x38')](handleEntityNotFound(_0x3a0a71,null))[_0x1175('0x38')](function(_0x3c7cd0){if(_0x3c7cd0){logger[_0x1175('0x27')]('WhatsppMessage,\x20%s,\x20%s,\x20%s','status',_0x1175('0x7b'),_0x3c7cd0['type'],util[_0x1175('0x7c')](_0x58ec1f[_0x1175('0x5c')],{'showHidden':![],'depth':null}));switch(_0x3c7cd0[_0x1175('0x3e')]){case _0x1175('0x7d'):if(_0x58ec1f['body'][_0x1175('0x7e')]&&_0x58ec1f[_0x1175('0x5c')]['MessageSid']===_0x53288a[_0x1175('0x7f')]&&_0x58ec1f['body'][_0x1175('0x80')]&&_0x58ec1f[_0x1175('0x5c')]['MessageStatus']===_0x1175('0x5d')){return _0x53288a[_0x1175('0x37')]({'read':!![]});}else{logger[_0x1175('0x29')](_0x1175('0x81'),_0x1175('0x2e'),_0x1175('0x7d'),util[_0x1175('0x7c')](_0x58ec1f['body'],{'showHidden':![],'depth':null}));}break;}return _0x53288a;}})[_0x1175('0x38')](respondWithResult(_0x3a0a71,null))[_0x1175('0x2d')](handleError(_0x3a0a71,null));};
\ No newline at end of file