Built motion from commit (unavailable).|2.5.12
[motion2.git] / server / api / whatsappMessage / whatsappMessage.controller.js
index b275fa1..3e21798 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 _0x1a85=['redis','defaults','localhost','socket.io-emitter','./whatsappMessage.socket','register','jayson/promise','http','request','then','info','WhatsappMessage,\x20%s,\x20%s','request\x20sent','WhatsappMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','reject','update','destroy','stack','name','send','index','map','fieldName','type','key','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','WhatsappMessage','include','findAll','rows','show','params','rawAttributes','includeAll','find','create','body','describe','whatsapp-interactions','accept','whatsapp','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','get','WhatsappInteraction','WhatsappInteractionId','isNil','interaction','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','user','role','null','acceptMessage','manual','interface','SIP/%s','event','EventManager','acceptmessage','agent','[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','channel','rejectmessage','WhatsappAccount','WhatsappAccountId','debug','received\x20delivery\x20report\x20from','inspect','twilio','MessageSid','messageId','MessageStatus','WhatsappAccount,\x20%s,\x20%s,\x20%s','rimraf','zip-dir','fast-json-patch','bluebird','mustache','util','sox','ejs','squel','crypto','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb'];(function(_0x2662f7,_0x2eaeb5){var _0x17bb1d=function(_0xb04865){while(--_0xb04865){_0x2662f7['push'](_0x2662f7['shift']());}};_0x17bb1d(++_0x2eaeb5);}(_0x1a85,0x178));var _0x51a8=function(_0x5b2865,_0x3b814b){_0x5b2865=_0x5b2865-0x0;var _0x3cb4c6=_0x1a85[_0x5b2865];return _0x3cb4c6;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x51a8('0x0'));var zipdir=require(_0x51a8('0x1'));var jsonpatch=require(_0x51a8('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x51a8('0x3'));var Mustache=require(_0x51a8('0x4'));var util=require(_0x51a8('0x5'));var path=require('path');var sox=require(_0x51a8('0x6'));var csv=require('to-csv');var ejs=require(_0x51a8('0x7'));var fs=require('fs');var _=require('lodash');var squel=require(_0x51a8('0x8'));var crypto=require(_0x51a8('0x9'));var jsforce=require('jsforce');var deskjs=require(_0x51a8('0xa'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x51a8('0xb'));var Redis=require(_0x51a8('0xc'));var authService=require(_0x51a8('0xd'));var qs=require(_0x51a8('0xe'));var as=require(_0x51a8('0xf'));var hardwareService=require(_0x51a8('0x10'));var logger=require(_0x51a8('0x11'))(_0x51a8('0x12'));var utils=require(_0x51a8('0x13'));var config=require(_0x51a8('0x14'));var licenseUtil=require(_0x51a8('0x15'));var db=require(_0x51a8('0x16'))['db'];config[_0x51a8('0x17')]=_[_0x51a8('0x18')](config[_0x51a8('0x17')],{'host':_0x51a8('0x19'),'port':0x18eb});var socket=require(_0x51a8('0x1a'))(new Redis(config['redis']));require(_0x51a8('0x1b'))[_0x51a8('0x1c')](socket);var jayson=require(_0x51a8('0x1d'));var client=jayson['client'][_0x51a8('0x1e')]({'port':0x232c});var client9002=jayson['client'][_0x51a8('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x2b8d37,_0x39cd45,_0x2b0521,_0x3fbd02){return new BPromise(function(_0x3e0603,_0x1f49ee){var _0x516abc=_0x3fbd02||client;return _0x516abc[_0x51a8('0x1f')](_0x2b8d37,_0x2b0521)[_0x51a8('0x20')](function(_0xd52230){logger[_0x51a8('0x21')](_0x51a8('0x22'),_0x39cd45,_0x51a8('0x23'));logger['debug'](_0x51a8('0x24'),_0x39cd45,_0x51a8('0x23'),JSON[_0x51a8('0x25')](_0xd52230));if(_0xd52230[_0x51a8('0x26')]){if(_0xd52230[_0x51a8('0x26')][_0x51a8('0x27')]===0x1f4){logger[_0x51a8('0x26')](_0x51a8('0x22'),_0x39cd45,_0xd52230['error'][_0x51a8('0x28')]);return _0x1f49ee(_0xd52230['error'][_0x51a8('0x28')]);}logger[_0x51a8('0x26')](_0x51a8('0x22'),_0x39cd45,_0xd52230[_0x51a8('0x26')]['message']);return _0x3e0603(_0xd52230[_0x51a8('0x26')]['message']);}else{logger['info'](_0x51a8('0x22'),_0x39cd45,'request\x20sent');_0x3e0603(_0xd52230[_0x51a8('0x29')][_0x51a8('0x28')]);}})[_0x51a8('0x2a')](function(_0x18e2f3){logger[_0x51a8('0x26')](_0x51a8('0x22'),_0x39cd45,_0x18e2f3);_0x1f49ee(_0x18e2f3);});});}function respondWithStatusCode(_0x291ed6,_0x1326a2){_0x1326a2=_0x1326a2||0xcc;return function(_0x5b3f49){if(_0x5b3f49){return _0x291ed6[_0x51a8('0x2b')](_0x1326a2);}return _0x291ed6[_0x51a8('0x2c')](_0x1326a2)[_0x51a8('0x2d')]();};}function respondWithResult(_0x3da187,_0x1c150d){_0x1c150d=_0x1c150d||0xc8;return function(_0x11aefc){if(_0x11aefc){return _0x3da187[_0x51a8('0x2c')](_0x1c150d)[_0x51a8('0x2e')](_0x11aefc);}};}function respondWithFilteredResult(_0xec08ae,_0x4b5cda){return function(_0x20c6b5){if(_0x20c6b5){var _0x347a02=_0x20c6b5[_0x51a8('0x2f')],_0x4a1548=_0x4b5cda[_0x51a8('0x30')],_0x2f9d53=_0x4b5cda[_0x51a8('0x30')]+_0x4b5cda[_0x51a8('0x31')],_0x58cba0;if(_0x2f9d53>=_0x347a02){_0x2f9d53=_0x347a02;_0x58cba0=0xc8;}else{_0x58cba0=0xce;}_0xec08ae[_0x51a8('0x2c')](_0x58cba0);return _0xec08ae['set'](_0x51a8('0x32'),_0x4a1548+'-'+_0x2f9d53+'/'+_0x347a02)['json'](_0x20c6b5);}return null;};}function patchUpdates(_0x41c4de){return function(_0x24b39a){try{jsonpatch[_0x51a8('0x33')](_0x24b39a,_0x41c4de,!![]);}catch(_0x4b19c8){return BPromise[_0x51a8('0x34')](_0x4b19c8);}return _0x24b39a['save']();};}function saveUpdates(_0x25a858,_0x192ac4){return function(_0x1ba6a7){if(_0x1ba6a7){return _0x1ba6a7[_0x51a8('0x35')](_0x25a858)[_0x51a8('0x20')](function(_0x50195b){return _0x50195b;});}return null;};}function removeEntity(_0x1167b8,_0x53b3b6){return function(_0x9f0e6){if(_0x9f0e6){return _0x9f0e6[_0x51a8('0x36')]()[_0x51a8('0x20')](function(){_0x1167b8['status'](0xcc)[_0x51a8('0x2d')]();});}};}function handleEntityNotFound(_0xdc6cc7,_0x2b7833){return function(_0x2429f8){if(!_0x2429f8){_0xdc6cc7[_0x51a8('0x2b')](0x194);}return _0x2429f8;};}function handleError(_0x49ab37,_0x4c2b3d){_0x4c2b3d=_0x4c2b3d||0x1f4;return function(_0x4d3114){logger[_0x51a8('0x26')](_0x4d3114[_0x51a8('0x37')]);if(_0x4d3114['name']){delete _0x4d3114[_0x51a8('0x38')];}_0x49ab37['status'](_0x4c2b3d)[_0x51a8('0x39')](_0x4d3114);};}exports[_0x51a8('0x3a')]=function(_0x433853,_0x1eef9d){var _0x256cda={},_0x1186a9={},_0x4e88cc={'count':0x0,'rows':[]};var _0x4e5566=_[_0x51a8('0x3b')](db['WhatsappMessage']['rawAttributes'],function(_0x5df144){return{'name':_0x5df144[_0x51a8('0x3c')],'type':_0x5df144[_0x51a8('0x3d')][_0x51a8('0x3e')]};});_0x1186a9['model']=_[_0x51a8('0x3b')](_0x4e5566,_0x51a8('0x38'));_0x1186a9[_0x51a8('0x3f')]=_[_0x51a8('0x40')](_0x433853['query']);_0x1186a9[_0x51a8('0x41')]=_[_0x51a8('0x42')](_0x1186a9[_0x51a8('0x43')],_0x1186a9['query']);_0x256cda[_0x51a8('0x44')]=_['intersection'](_0x1186a9[_0x51a8('0x43')],qs[_0x51a8('0x45')](_0x433853[_0x51a8('0x3f')][_0x51a8('0x45')]));_0x256cda['attributes']=_0x256cda[_0x51a8('0x44')][_0x51a8('0x46')]?_0x256cda[_0x51a8('0x44')]:_0x1186a9[_0x51a8('0x43')];if(!_0x433853[_0x51a8('0x3f')][_0x51a8('0x47')](_0x51a8('0x48'))){_0x256cda[_0x51a8('0x31')]=qs[_0x51a8('0x31')](_0x433853['query'][_0x51a8('0x31')]);_0x256cda[_0x51a8('0x30')]=qs['offset'](_0x433853['query'][_0x51a8('0x30')]);}_0x256cda[_0x51a8('0x49')]=qs[_0x51a8('0x4a')](_0x433853[_0x51a8('0x3f')][_0x51a8('0x4a')]);_0x256cda[_0x51a8('0x4b')]=qs[_0x51a8('0x41')](_[_0x51a8('0x4c')](_0x433853[_0x51a8('0x3f')],_0x1186a9[_0x51a8('0x41')]),_0x4e5566);if(_0x433853['query'][_0x51a8('0x4d')]){_0x256cda[_0x51a8('0x4b')]=_[_0x51a8('0x4e')](_0x256cda[_0x51a8('0x4b')],{'$or':_[_0x51a8('0x3b')](_0x4e5566,function(_0x22ff0e){if(_0x22ff0e['type']!==_0x51a8('0x4f')){var _0x4cc815={};_0x4cc815[_0x22ff0e[_0x51a8('0x38')]]={'$like':'%'+_0x433853[_0x51a8('0x3f')][_0x51a8('0x4d')]+'%'};return _0x4cc815;}})});}_0x256cda=_[_0x51a8('0x4e')]({},_0x256cda,_0x433853[_0x51a8('0x50')]);var _0x56d002={'where':_0x256cda['where']};return db[_0x51a8('0x51')][_0x51a8('0x2f')](_0x56d002)[_0x51a8('0x20')](function(_0x35e510){_0x4e88cc[_0x51a8('0x2f')]=_0x35e510;if(_0x433853['query']['includeAll']){_0x256cda[_0x51a8('0x52')]=[{'all':!![]}];}return db[_0x51a8('0x51')][_0x51a8('0x53')](_0x256cda);})[_0x51a8('0x20')](function(_0x40c97a){_0x4e88cc[_0x51a8('0x54')]=_0x40c97a;return _0x4e88cc;})[_0x51a8('0x20')](respondWithFilteredResult(_0x1eef9d,_0x256cda))[_0x51a8('0x2a')](handleError(_0x1eef9d,null));};exports[_0x51a8('0x55')]=function(_0x4d29ab,_0x5cb2cf){var _0x5db030={'raw':!![],'where':{'id':_0x4d29ab[_0x51a8('0x56')]['id']}},_0x3e2d6c={};_0x3e2d6c[_0x51a8('0x43')]=_['keys'](db[_0x51a8('0x51')][_0x51a8('0x57')]);_0x3e2d6c['query']=_[_0x51a8('0x40')](_0x4d29ab['query']);_0x3e2d6c['filters']=_[_0x51a8('0x42')](_0x3e2d6c[_0x51a8('0x43')],_0x3e2d6c[_0x51a8('0x3f')]);_0x5db030['attributes']=_['intersection'](_0x3e2d6c[_0x51a8('0x43')],qs['fields'](_0x4d29ab[_0x51a8('0x3f')][_0x51a8('0x45')]));_0x5db030[_0x51a8('0x44')]=_0x5db030[_0x51a8('0x44')][_0x51a8('0x46')]?_0x5db030[_0x51a8('0x44')]:_0x3e2d6c[_0x51a8('0x43')];if(_0x4d29ab[_0x51a8('0x3f')][_0x51a8('0x58')]){_0x5db030['include']=[{'all':!![]}];}_0x5db030=_[_0x51a8('0x4e')]({},_0x5db030,_0x4d29ab[_0x51a8('0x50')]);return db[_0x51a8('0x51')][_0x51a8('0x59')](_0x5db030)['then'](handleEntityNotFound(_0x5cb2cf,null))[_0x51a8('0x20')](respondWithResult(_0x5cb2cf,null))['catch'](handleError(_0x5cb2cf,null));};exports[_0x51a8('0x5a')]=function(_0x252c20,_0x5c66e8){return db['WhatsappMessage'][_0x51a8('0x5a')](_0x252c20[_0x51a8('0x5b')],{})[_0x51a8('0x20')](respondWithResult(_0x5c66e8,0xc9))[_0x51a8('0x2a')](handleError(_0x5c66e8,null));};exports[_0x51a8('0x35')]=function(_0x52f60f,_0x43b79a){if(_0x52f60f[_0x51a8('0x5b')]['id']){delete _0x52f60f[_0x51a8('0x5b')]['id'];}return db[_0x51a8('0x51')][_0x51a8('0x59')]({'where':{'id':_0x52f60f['params']['id']}})[_0x51a8('0x20')](handleEntityNotFound(_0x43b79a,null))[_0x51a8('0x20')](saveUpdates(_0x52f60f[_0x51a8('0x5b')],null))[_0x51a8('0x20')](respondWithResult(_0x43b79a,null))[_0x51a8('0x2a')](handleError(_0x43b79a,null));};exports[_0x51a8('0x36')]=function(_0x4d2699,_0x4cef4e){return db['WhatsappMessage']['find']({'where':{'id':_0x4d2699[_0x51a8('0x56')]['id']}})[_0x51a8('0x20')](handleEntityNotFound(_0x4cef4e,null))['then'](removeEntity(_0x4cef4e,null))[_0x51a8('0x2a')](handleError(_0x4cef4e,null));};exports['describe']=function(_0x41cc00,_0x54f626){return db[_0x51a8('0x51')][_0x51a8('0x5c')]()['then'](respondWithResult(_0x54f626,null))['catch'](handleError(_0x54f626,null));};var interaction_log=require('../../config/logger')(_0x51a8('0x5d'));exports[_0x51a8('0x5e')]=function(_0x283c8f,_0x143f77,_0x149047){var _0x21c8e0={'channel':_0x51a8('0x5f')};if(_0x283c8f[_0x51a8('0x5b')]['id']){delete _0x283c8f['body']['id'];}_0x283c8f[_0x51a8('0x5b')][_0x51a8('0x60')]=!![];_0x283c8f['body'][_0x51a8('0x61')]=moment()[_0x51a8('0x62')](_0x51a8('0x63'));_0x283c8f[_0x51a8('0x5b')][_0x51a8('0x64')]=_0x283c8f[_0x51a8('0x5b')]['UserId']||_0x283c8f['user']['id'];return db[_0x51a8('0x51')]['find']({'where':{'id':_0x283c8f['params']['id'],'UserId':null},'include':[{'model':db['CmContact'],'as':'Contact'}]})['then'](handleEntityNotFound(_0x143f77,null))[_0x51a8('0x20')](saveUpdates(_0x283c8f['body'],null))[_0x51a8('0x20')](function(_0x4772cd){if(_0x4772cd){_0x21c8e0[_0x51a8('0x28')]=_0x4772cd[_0x51a8('0x65')]({'plain':!![]});return db[_0x51a8('0x66')][_0x51a8('0x59')]({'where':{'id':_0x4772cd[_0x51a8('0x67')]}});}return null;})[_0x51a8('0x20')](handleEntityNotFound(_0x143f77,null))[_0x51a8('0x20')](function(_0x3d558d){if(_0x3d558d){return _0x3d558d['update']({'UserId':_0x283c8f[_0x51a8('0x5b')][_0x51a8('0x64')],'read1stAt':_[_0x51a8('0x68')](_0x3d558d['read1stAt'])?moment()['format']('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})[_0x51a8('0x20')](function(_0x32e1b9){if(_0x32e1b9){_0x21c8e0[_0x51a8('0x69')]=_0x32e1b9[_0x51a8('0x65')]({'plain':!![]});interaction_log[_0x51a8('0x21')](_0x51a8('0x6a'),_0x283c8f[_0x51a8('0x6b')]['id'],_0x283c8f[_0x51a8('0x6b')][_0x51a8('0x38')],_0x283c8f[_0x51a8('0x6b')][_0x51a8('0x6c')],_0x21c8e0[_0x51a8('0x69')]['id'],_0x283c8f[_0x51a8('0x5b')]?JSON['stringify'](_0x283c8f[_0x51a8('0x5b')]):_0x51a8('0x6d'));return respondWithRpcPromise('AcceptMessage',_0x51a8('0x6e'),_0x21c8e0);}return null;})['then'](function(_0x4ac62e){if(_0x4ac62e){if(_0x283c8f['body'][_0x51a8('0x6f')]){_0x21c8e0[_0x51a8('0x28')][_0x51a8('0x70')]=util[_0x51a8('0x62')](_0x51a8('0x71'),_0x283c8f[_0x51a8('0x6b')][_0x51a8('0x38')]);_0x21c8e0['message']['channel']=_0x21c8e0['channel'];_0x21c8e0[_0x51a8('0x28')][_0x51a8('0x72')]=_0x51a8('0x5e');return respondWithRpcPromise(_0x51a8('0x73'),_0x51a8('0x73'),{'event':_0x51a8('0x74'),'message':_0x21c8e0['message']},client9002)[_0x51a8('0x20')](function(){return _0x21c8e0;});}return _0x21c8e0;}return null;})['then'](respondWithResult(_0x143f77,null))[_0x51a8('0x2a')](handleError(_0x143f77,null));};var interaction_log=require(_0x51a8('0x11'))(_0x51a8('0x5d'));exports[_0x51a8('0x34')]=function(_0x149a40,_0x3aca4a,_0x895b42){var _0xc751c3={'agent':{},'channel':_0x51a8('0x5f')};if(_0x149a40[_0x51a8('0x5b')]['id']){delete _0x149a40[_0x51a8('0x5b')]['id'];}_0x149a40['body']['UserId']=_0x149a40[_0x51a8('0x5b')][_0x51a8('0x64')]||_0x149a40[_0x51a8('0x6b')]['id'];_0xc751c3[_0x51a8('0x75')]['id']=_0x149a40['body'][_0x51a8('0x64')];return db['WhatsappMessage'][_0x51a8('0x59')]({'where':{'id':_0x149a40[_0x51a8('0x56')]['id'],'UserId':null}})[_0x51a8('0x20')](handleEntityNotFound(_0x3aca4a,null))[_0x51a8('0x20')](function(_0x190632){if(_0x190632){_0xc751c3[_0x51a8('0x28')]=_0x190632[_0x51a8('0x65')]({'plain':!![]});return db[_0x51a8('0x66')][_0x51a8('0x59')]({'where':{'id':_0x190632['WhatsappInteractionId']}});}return null;})[_0x51a8('0x20')](handleEntityNotFound(_0x3aca4a,null))[_0x51a8('0x20')](function(_0x3e80db){if(_0x3e80db){_0xc751c3[_0x51a8('0x69')]=_0x3e80db['get']({'plain':!![]});interaction_log['info'](_0x51a8('0x76'),_0x149a40['user']['id'],_0x149a40['user']['name'],_0x149a40[_0x51a8('0x6b')]['role'],_0xc751c3['interaction']['id'],_0x149a40[_0x51a8('0x5b')]?JSON[_0x51a8('0x25')](_0x149a40[_0x51a8('0x5b')]):'null');return respondWithRpcPromise(_0x51a8('0x77'),_0x51a8('0x78'),_0xc751c3);}return null;})[_0x51a8('0x20')](function(_0x5f20f7){if(_0x5f20f7){_0x5f20f7[_0x51a8('0x28')][_0x51a8('0x70')]=util[_0x51a8('0x62')](_0x51a8('0x71'),_0x149a40[_0x51a8('0x6b')][_0x51a8('0x38')]);_0x5f20f7[_0x51a8('0x28')][_0x51a8('0x79')]=_0xc751c3[_0x51a8('0x79')];_0x5f20f7['message'][_0x51a8('0x72')]=_0x51a8('0x34');respondWithRpcPromise('EventManager',_0x51a8('0x73'),{'event':_0x51a8('0x7a'),'message':_0x5f20f7['message']},client9002);return _0xc751c3;}return null;})[_0x51a8('0x20')](respondWithResult(_0x3aca4a,null))[_0x51a8('0x2a')](handleError(_0x3aca4a,null));};exports[_0x51a8('0x2c')]=function(_0x17fd0a,_0x398fb2,_0x53cca9){if(_0x17fd0a[_0x51a8('0x5b')]['id']){delete _0x17fd0a[_0x51a8('0x5b')]['id'];}var _0x12d018;return db[_0x51a8('0x51')]['find']({'where':{'id':_0x17fd0a[_0x51a8('0x56')]['id']}})[_0x51a8('0x20')](handleEntityNotFound(_0x398fb2,null))[_0x51a8('0x20')](function(_0x37f253){if(_0x37f253){_0x12d018=_0x37f253;return db[_0x51a8('0x7b')][_0x51a8('0x59')]({'where':{'id':_0x37f253[_0x51a8('0x7c')]}});}})[_0x51a8('0x20')](handleEntityNotFound(_0x398fb2,null))['then'](function(_0x1d7794){if(_0x1d7794){logger[_0x51a8('0x7d')]('WhatsppMessage,\x20%s,\x20%s,\x20%s',_0x51a8('0x2c'),_0x51a8('0x7e'),_0x1d7794['type'],util[_0x51a8('0x7f')](_0x17fd0a['body'],{'showHidden':![],'depth':null}));switch(_0x1d7794['type']){case _0x51a8('0x80'):if(_0x17fd0a[_0x51a8('0x5b')][_0x51a8('0x81')]&&_0x17fd0a['body']['MessageSid']===_0x12d018[_0x51a8('0x82')]&&_0x17fd0a['body'][_0x51a8('0x83')]&&_0x17fd0a[_0x51a8('0x5b')][_0x51a8('0x83')]===_0x51a8('0x60')){return _0x12d018[_0x51a8('0x35')]({'read':!![]});}else{logger[_0x51a8('0x26')](_0x51a8('0x84'),_0x51a8('0x2c'),_0x51a8('0x80'),util[_0x51a8('0x7f')](_0x17fd0a[_0x51a8('0x5b')],{'showHidden':![],'depth':null}));}break;}return _0x12d018;}})[_0x51a8('0x20')](respondWithResult(_0x398fb2,null))[_0x51a8('0x2a')](handleError(_0x398fb2,null));};
\ No newline at end of file