Built motion from commit (unavailable).|2.5.10
[motion2.git] / server / api / whatsappMessage / whatsappMessage.controller.js
index cb11821..078a08b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5f66=['get','WhatsappInteraction','WhatsappInteractionId','isNil','read1stAt','YYYY-MM-DD\x20HH:mm:ss','interaction','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','stringify','null','AcceptMessage','acceptMessage','interface','SIP/%s','channel','event','acceptmessage','agent','[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','EventManager','rejectmessage','WhatsappAccountId','WhatsppMessage,\x20%s,\x20%s,\x20%s','received\x20delivery\x20report\x20from','twilio','MessageSid','MessageStatus','read','WhatsappAccount,\x20%s,\x20%s,\x20%s','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','sox','to-csv','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/license/util','redis','localhost','socket.io-emitter','./whatsappMessage.socket','register','jayson/promise','client','http','request','then','info','debug','error','WhatsappMessage,\x20%s,\x20%s','message','request\x20sent','result','sendStatus','status','json','count','offset','limit','Content-Range','apply','reject','save','update','destroy','end','stack','name','send','index','map','WhatsappMessage','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','type','VIRTUAL','includeAll','include','findAll','catch','show','params','rawAttributes','options','find','create','body','describe','../../config/logger','whatsapp-interactions','accept','whatsapp','readAt','format','UserId','user','Contact'];(function(_0x3a3791,_0x127485){var _0x21960c=function(_0x230b4e){while(--_0x230b4e){_0x3a3791['push'](_0x3a3791['shift']());}};_0x21960c(++_0x127485);}(_0x5f66,0x1a0));var _0x65f6=function(_0x3947c9,_0x4d6c97){_0x3947c9=_0x3947c9-0x0;var _0x2e7871=_0x5f66[_0x3947c9];return _0x2e7871;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x65f6('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x65f6('0x1'));var jsonpatch=require(_0x65f6('0x2'));var rp=require(_0x65f6('0x3'));var moment=require(_0x65f6('0x4'));var BPromise=require(_0x65f6('0x5'));var Mustache=require('mustache');var util=require(_0x65f6('0x6'));var path=require('path');var sox=require(_0x65f6('0x7'));var csv=require(_0x65f6('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x65f6('0x9'));var crypto=require(_0x65f6('0xa'));var jsforce=require(_0x65f6('0xb'));var deskjs=require(_0x65f6('0xc'));var toCsv=require(_0x65f6('0x8'));var querystring=require(_0x65f6('0xd'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x65f6('0xe'));var qs=require(_0x65f6('0xf'));var as=require(_0x65f6('0x10'));var hardwareService=require(_0x65f6('0x11'));var logger=require('../../config/logger')(_0x65f6('0x12'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x65f6('0x13'));var db=require('../../mysqldb')['db'];config[_0x65f6('0x14')]=_['defaults'](config[_0x65f6('0x14')],{'host':_0x65f6('0x15'),'port':0x18eb});var socket=require(_0x65f6('0x16'))(new Redis(config[_0x65f6('0x14')]));require(_0x65f6('0x17'))[_0x65f6('0x18')](socket);var jayson=require(_0x65f6('0x19'));var client=jayson[_0x65f6('0x1a')][_0x65f6('0x1b')]({'port':0x232c});var client9002=jayson[_0x65f6('0x1a')]['http']({'port':0x232a});function respondWithRpcPromise(_0x19b9ff,_0x49a913,_0x5dd324,_0x1693e6){return new BPromise(function(_0x5c69f8,_0x37330d){var _0x1c955c=_0x1693e6||client;return _0x1c955c[_0x65f6('0x1c')](_0x19b9ff,_0x5dd324)[_0x65f6('0x1d')](function(_0xc8660c){logger[_0x65f6('0x1e')]('WhatsappMessage,\x20%s,\x20%s',_0x49a913,'request\x20sent');logger[_0x65f6('0x1f')]('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0x49a913,'request\x20sent',JSON['stringify'](_0xc8660c));if(_0xc8660c[_0x65f6('0x20')]){if(_0xc8660c[_0x65f6('0x20')]['code']===0x1f4){logger[_0x65f6('0x20')](_0x65f6('0x21'),_0x49a913,_0xc8660c[_0x65f6('0x20')][_0x65f6('0x22')]);return _0x37330d(_0xc8660c[_0x65f6('0x20')][_0x65f6('0x22')]);}logger['error'](_0x65f6('0x21'),_0x49a913,_0xc8660c['error']['message']);return _0x5c69f8(_0xc8660c[_0x65f6('0x20')][_0x65f6('0x22')]);}else{logger['info'](_0x65f6('0x21'),_0x49a913,_0x65f6('0x23'));_0x5c69f8(_0xc8660c[_0x65f6('0x24')][_0x65f6('0x22')]);}})['catch'](function(_0x9d7bb0){logger[_0x65f6('0x20')](_0x65f6('0x21'),_0x49a913,_0x9d7bb0);_0x37330d(_0x9d7bb0);});});}function respondWithStatusCode(_0x5963e0,_0x5cb131){_0x5cb131=_0x5cb131||0xcc;return function(_0x4fde2f){if(_0x4fde2f){return _0x5963e0[_0x65f6('0x25')](_0x5cb131);}return _0x5963e0[_0x65f6('0x26')](_0x5cb131)['end']();};}function respondWithResult(_0x296cd9,_0x28f710){_0x28f710=_0x28f710||0xc8;return function(_0x52277c){if(_0x52277c){return _0x296cd9[_0x65f6('0x26')](_0x28f710)[_0x65f6('0x27')](_0x52277c);}};}function respondWithFilteredResult(_0x28d0df,_0x559330){return function(_0x4ac04b){if(_0x4ac04b){var _0x488d36=_0x4ac04b[_0x65f6('0x28')],_0x266cfe=_0x559330[_0x65f6('0x29')],_0x3c032f=_0x559330[_0x65f6('0x29')]+_0x559330[_0x65f6('0x2a')],_0x4344b3;if(_0x3c032f>=_0x488d36){_0x3c032f=_0x488d36;_0x4344b3=0xc8;}else{_0x4344b3=0xce;}_0x28d0df['status'](_0x4344b3);return _0x28d0df['set'](_0x65f6('0x2b'),_0x266cfe+'-'+_0x3c032f+'/'+_0x488d36)[_0x65f6('0x27')](_0x4ac04b);}return null;};}function patchUpdates(_0x5878bc){return function(_0x4e50c0){try{jsonpatch[_0x65f6('0x2c')](_0x4e50c0,_0x5878bc,!![]);}catch(_0x1ce43c){return BPromise[_0x65f6('0x2d')](_0x1ce43c);}return _0x4e50c0[_0x65f6('0x2e')]();};}function saveUpdates(_0x1217fd,_0x2d32be){return function(_0x5792a0){if(_0x5792a0){return _0x5792a0[_0x65f6('0x2f')](_0x1217fd)[_0x65f6('0x1d')](function(_0x46f03c){return _0x46f03c;});}return null;};}function removeEntity(_0x4bc037,_0x217f35){return function(_0x2a7aa8){if(_0x2a7aa8){return _0x2a7aa8[_0x65f6('0x30')]()[_0x65f6('0x1d')](function(){_0x4bc037[_0x65f6('0x26')](0xcc)[_0x65f6('0x31')]();});}};}function handleEntityNotFound(_0x4d4d84,_0x3c7c58){return function(_0x1b24ea){if(!_0x1b24ea){_0x4d4d84['sendStatus'](0x194);}return _0x1b24ea;};}function handleError(_0x36dbf4,_0x5a740a){_0x5a740a=_0x5a740a||0x1f4;return function(_0x2b403b){logger['error'](_0x2b403b[_0x65f6('0x32')]);if(_0x2b403b[_0x65f6('0x33')]){delete _0x2b403b['name'];}_0x36dbf4[_0x65f6('0x26')](_0x5a740a)[_0x65f6('0x34')](_0x2b403b);};}exports[_0x65f6('0x35')]=function(_0x515648,_0x582c7e){var _0x30109d={},_0x4c0df4={},_0x26de30={'count':0x0,'rows':[]};var _0x4e6653=_[_0x65f6('0x36')](db[_0x65f6('0x37')]['rawAttributes'],function(_0x44b809){return{'name':_0x44b809['fieldName'],'type':_0x44b809['type'][_0x65f6('0x38')]};});_0x4c0df4[_0x65f6('0x39')]=_[_0x65f6('0x36')](_0x4e6653,_0x65f6('0x33'));_0x4c0df4[_0x65f6('0x3a')]=_[_0x65f6('0x3b')](_0x515648[_0x65f6('0x3a')]);_0x4c0df4[_0x65f6('0x3c')]=_['intersection'](_0x4c0df4[_0x65f6('0x39')],_0x4c0df4['query']);_0x30109d[_0x65f6('0x3d')]=_[_0x65f6('0x3e')](_0x4c0df4[_0x65f6('0x39')],qs[_0x65f6('0x3f')](_0x515648['query'][_0x65f6('0x3f')]));_0x30109d[_0x65f6('0x3d')]=_0x30109d[_0x65f6('0x3d')][_0x65f6('0x40')]?_0x30109d[_0x65f6('0x3d')]:_0x4c0df4[_0x65f6('0x39')];if(!_0x515648[_0x65f6('0x3a')][_0x65f6('0x41')](_0x65f6('0x42'))){_0x30109d['limit']=qs[_0x65f6('0x2a')](_0x515648[_0x65f6('0x3a')][_0x65f6('0x2a')]);_0x30109d[_0x65f6('0x29')]=qs[_0x65f6('0x29')](_0x515648[_0x65f6('0x3a')][_0x65f6('0x29')]);}_0x30109d[_0x65f6('0x43')]=qs[_0x65f6('0x44')](_0x515648[_0x65f6('0x3a')][_0x65f6('0x44')]);_0x30109d[_0x65f6('0x45')]=qs[_0x65f6('0x3c')](_[_0x65f6('0x46')](_0x515648[_0x65f6('0x3a')],_0x4c0df4[_0x65f6('0x3c')]),_0x4e6653);if(_0x515648['query'][_0x65f6('0x47')]){_0x30109d[_0x65f6('0x45')]=_[_0x65f6('0x48')](_0x30109d[_0x65f6('0x45')],{'$or':_['map'](_0x4e6653,function(_0x1bf5bf){if(_0x1bf5bf[_0x65f6('0x49')]!==_0x65f6('0x4a')){var _0x5e69b4={};_0x5e69b4[_0x1bf5bf[_0x65f6('0x33')]]={'$like':'%'+_0x515648[_0x65f6('0x3a')][_0x65f6('0x47')]+'%'};return _0x5e69b4;}})});}_0x30109d=_[_0x65f6('0x48')]({},_0x30109d,_0x515648['options']);var _0x2ec114={'where':_0x30109d['where']};return db[_0x65f6('0x37')][_0x65f6('0x28')](_0x2ec114)['then'](function(_0xf754ee){_0x26de30['count']=_0xf754ee;if(_0x515648[_0x65f6('0x3a')][_0x65f6('0x4b')]){_0x30109d[_0x65f6('0x4c')]=[{'all':!![]}];}return db[_0x65f6('0x37')][_0x65f6('0x4d')](_0x30109d);})[_0x65f6('0x1d')](function(_0x4d30c5){_0x26de30['rows']=_0x4d30c5;return _0x26de30;})[_0x65f6('0x1d')](respondWithFilteredResult(_0x582c7e,_0x30109d))[_0x65f6('0x4e')](handleError(_0x582c7e,null));};exports[_0x65f6('0x4f')]=function(_0x1e9e29,_0x3b907c){var _0x2d6ab9={'raw':!![],'where':{'id':_0x1e9e29[_0x65f6('0x50')]['id']}},_0x149c28={};_0x149c28[_0x65f6('0x39')]=_['keys'](db[_0x65f6('0x37')][_0x65f6('0x51')]);_0x149c28[_0x65f6('0x3a')]=_['keys'](_0x1e9e29[_0x65f6('0x3a')]);_0x149c28[_0x65f6('0x3c')]=_['intersection'](_0x149c28[_0x65f6('0x39')],_0x149c28[_0x65f6('0x3a')]);_0x2d6ab9['attributes']=_[_0x65f6('0x3e')](_0x149c28['model'],qs[_0x65f6('0x3f')](_0x1e9e29[_0x65f6('0x3a')][_0x65f6('0x3f')]));_0x2d6ab9['attributes']=_0x2d6ab9[_0x65f6('0x3d')][_0x65f6('0x40')]?_0x2d6ab9['attributes']:_0x149c28[_0x65f6('0x39')];if(_0x1e9e29[_0x65f6('0x3a')]['includeAll']){_0x2d6ab9[_0x65f6('0x4c')]=[{'all':!![]}];}_0x2d6ab9=_[_0x65f6('0x48')]({},_0x2d6ab9,_0x1e9e29[_0x65f6('0x52')]);return db[_0x65f6('0x37')][_0x65f6('0x53')](_0x2d6ab9)[_0x65f6('0x1d')](handleEntityNotFound(_0x3b907c,null))[_0x65f6('0x1d')](respondWithResult(_0x3b907c,null))[_0x65f6('0x4e')](handleError(_0x3b907c,null));};exports['create']=function(_0x52c5a4,_0x5ca62e){return db[_0x65f6('0x37')][_0x65f6('0x54')](_0x52c5a4[_0x65f6('0x55')],{})[_0x65f6('0x1d')](respondWithResult(_0x5ca62e,0xc9))['catch'](handleError(_0x5ca62e,null));};exports[_0x65f6('0x2f')]=function(_0x2032b9,_0x9ff849){if(_0x2032b9['body']['id']){delete _0x2032b9[_0x65f6('0x55')]['id'];}return db[_0x65f6('0x37')][_0x65f6('0x53')]({'where':{'id':_0x2032b9['params']['id']}})['then'](handleEntityNotFound(_0x9ff849,null))[_0x65f6('0x1d')](saveUpdates(_0x2032b9[_0x65f6('0x55')],null))[_0x65f6('0x1d')](respondWithResult(_0x9ff849,null))[_0x65f6('0x4e')](handleError(_0x9ff849,null));};exports[_0x65f6('0x30')]=function(_0x3cf5fe,_0x35d77f){return db[_0x65f6('0x37')][_0x65f6('0x53')]({'where':{'id':_0x3cf5fe[_0x65f6('0x50')]['id']}})[_0x65f6('0x1d')](handleEntityNotFound(_0x35d77f,null))[_0x65f6('0x1d')](removeEntity(_0x35d77f,null))[_0x65f6('0x4e')](handleError(_0x35d77f,null));};exports[_0x65f6('0x56')]=function(_0x5ba9c6,_0x47610a){return db[_0x65f6('0x37')][_0x65f6('0x56')]()['then'](respondWithResult(_0x47610a,null))[_0x65f6('0x4e')](handleError(_0x47610a,null));};var interaction_log=require(_0x65f6('0x57'))(_0x65f6('0x58'));exports[_0x65f6('0x59')]=function(_0x4ef333,_0x12a5c9,_0x4227f5){var _0xe5fc65={'channel':_0x65f6('0x5a')};if(_0x4ef333['body']['id']){delete _0x4ef333[_0x65f6('0x55')]['id'];}_0x4ef333[_0x65f6('0x55')]['read']=!![];_0x4ef333[_0x65f6('0x55')][_0x65f6('0x5b')]=moment()[_0x65f6('0x5c')]('YYYY-MM-DD\x20HH:mm:ss');_0x4ef333[_0x65f6('0x55')][_0x65f6('0x5d')]=_0x4ef333[_0x65f6('0x55')][_0x65f6('0x5d')]||_0x4ef333[_0x65f6('0x5e')]['id'];return db[_0x65f6('0x37')]['find']({'where':{'id':_0x4ef333['params']['id'],'UserId':null},'include':[{'model':db['CmContact'],'as':_0x65f6('0x5f')}]})[_0x65f6('0x1d')](handleEntityNotFound(_0x12a5c9,null))[_0x65f6('0x1d')](saveUpdates(_0x4ef333[_0x65f6('0x55')],null))[_0x65f6('0x1d')](function(_0x304cf9){if(_0x304cf9){_0xe5fc65['message']=_0x304cf9[_0x65f6('0x60')]({'plain':!![]});return db[_0x65f6('0x61')]['find']({'where':{'id':_0x304cf9[_0x65f6('0x62')]}});}return null;})[_0x65f6('0x1d')](handleEntityNotFound(_0x12a5c9,null))[_0x65f6('0x1d')](function(_0x4efa91){if(_0x4efa91){return _0x4efa91[_0x65f6('0x2f')]({'UserId':_0x4ef333[_0x65f6('0x55')]['UserId'],'read1stAt':_[_0x65f6('0x63')](_0x4efa91[_0x65f6('0x64')])?moment()[_0x65f6('0x5c')](_0x65f6('0x65')):undefined});}return null;})[_0x65f6('0x1d')](function(_0x2226bf){if(_0x2226bf){_0xe5fc65[_0x65f6('0x66')]=_0x2226bf['get']({'plain':!![]});interaction_log['info'](_0x65f6('0x67'),_0x4ef333[_0x65f6('0x5e')]['id'],_0x4ef333['user'][_0x65f6('0x33')],_0x4ef333['user'][_0x65f6('0x68')],_0xe5fc65['interaction']['id'],_0x4ef333[_0x65f6('0x55')]?JSON[_0x65f6('0x69')](_0x4ef333[_0x65f6('0x55')]):_0x65f6('0x6a'));return respondWithRpcPromise(_0x65f6('0x6b'),_0x65f6('0x6c'),_0xe5fc65);}return null;})[_0x65f6('0x1d')](function(_0x1cc66a){if(_0x1cc66a){if(_0x4ef333[_0x65f6('0x55')]['manual']){_0xe5fc65['message'][_0x65f6('0x6d')]=util[_0x65f6('0x5c')](_0x65f6('0x6e'),_0x4ef333['user']['name']);_0xe5fc65[_0x65f6('0x22')][_0x65f6('0x6f')]=_0xe5fc65[_0x65f6('0x6f')];_0xe5fc65[_0x65f6('0x22')][_0x65f6('0x70')]=_0x65f6('0x59');return respondWithRpcPromise('EventManager','EventManager',{'event':_0x65f6('0x71'),'message':_0xe5fc65[_0x65f6('0x22')]},client9002)['then'](function(){return _0xe5fc65;});}return _0xe5fc65;}return null;})[_0x65f6('0x1d')](respondWithResult(_0x12a5c9,null))['catch'](handleError(_0x12a5c9,null));};var interaction_log=require(_0x65f6('0x57'))(_0x65f6('0x58'));exports[_0x65f6('0x2d')]=function(_0x16726d,_0x558888,_0x34ab7b){var _0x351d43={'agent':{},'channel':_0x65f6('0x5a')};if(_0x16726d['body']['id']){delete _0x16726d['body']['id'];}_0x16726d[_0x65f6('0x55')]['UserId']=_0x16726d[_0x65f6('0x55')][_0x65f6('0x5d')]||_0x16726d[_0x65f6('0x5e')]['id'];_0x351d43[_0x65f6('0x72')]['id']=_0x16726d['body']['UserId'];return db['WhatsappMessage'][_0x65f6('0x53')]({'where':{'id':_0x16726d[_0x65f6('0x50')]['id'],'UserId':null}})[_0x65f6('0x1d')](handleEntityNotFound(_0x558888,null))['then'](function(_0x46cbde){if(_0x46cbde){_0x351d43[_0x65f6('0x22')]=_0x46cbde[_0x65f6('0x60')]({'plain':!![]});return db['WhatsappInteraction'][_0x65f6('0x53')]({'where':{'id':_0x46cbde[_0x65f6('0x62')]}});}return null;})['then'](handleEntityNotFound(_0x558888,null))[_0x65f6('0x1d')](function(_0x2f59f9){if(_0x2f59f9){_0x351d43['interaction']=_0x2f59f9[_0x65f6('0x60')]({'plain':!![]});interaction_log['info'](_0x65f6('0x73'),_0x16726d['user']['id'],_0x16726d[_0x65f6('0x5e')][_0x65f6('0x33')],_0x16726d['user'][_0x65f6('0x68')],_0x351d43[_0x65f6('0x66')]['id'],_0x16726d[_0x65f6('0x55')]?JSON[_0x65f6('0x69')](_0x16726d[_0x65f6('0x55')]):_0x65f6('0x6a'));return respondWithRpcPromise(_0x65f6('0x74'),_0x65f6('0x75'),_0x351d43);}return null;})[_0x65f6('0x1d')](function(_0x413e65){if(_0x413e65){_0x413e65[_0x65f6('0x22')]['interface']=util[_0x65f6('0x5c')](_0x65f6('0x6e'),_0x16726d[_0x65f6('0x5e')][_0x65f6('0x33')]);_0x413e65['message'][_0x65f6('0x6f')]=_0x351d43[_0x65f6('0x6f')];_0x413e65['message'][_0x65f6('0x70')]='reject';respondWithRpcPromise(_0x65f6('0x76'),'EventManager',{'event':_0x65f6('0x77'),'message':_0x413e65[_0x65f6('0x22')]},client9002);return _0x351d43;}return null;})['then'](respondWithResult(_0x558888,null))['catch'](handleError(_0x558888,null));};exports[_0x65f6('0x26')]=function(_0x413c21,_0x5158c9,_0x2d86c8){if(_0x413c21[_0x65f6('0x55')]['id']){delete _0x413c21[_0x65f6('0x55')]['id'];}var _0x4edba0;return db[_0x65f6('0x37')][_0x65f6('0x53')]({'where':{'id':_0x413c21['params']['id']}})[_0x65f6('0x1d')](handleEntityNotFound(_0x5158c9,null))['then'](function(_0x1e57b0){if(_0x1e57b0){_0x4edba0=_0x1e57b0;return db['WhatsappAccount']['find']({'where':{'id':_0x1e57b0[_0x65f6('0x78')]}});}})[_0x65f6('0x1d')](handleEntityNotFound(_0x5158c9,null))[_0x65f6('0x1d')](function(_0xc82d69){if(_0xc82d69){logger[_0x65f6('0x1f')](_0x65f6('0x79'),_0x65f6('0x26'),_0x65f6('0x7a'),_0xc82d69['type'],util['inspect'](_0x413c21[_0x65f6('0x55')],{'showHidden':![],'depth':null}));switch(_0xc82d69['type']){case _0x65f6('0x7b'):if(_0x413c21[_0x65f6('0x55')][_0x65f6('0x7c')]&&_0x413c21[_0x65f6('0x55')][_0x65f6('0x7c')]===_0x4edba0['messageId']&&_0x413c21[_0x65f6('0x55')][_0x65f6('0x7d')]&&_0x413c21[_0x65f6('0x55')]['MessageStatus']===_0x65f6('0x7e')){return _0x4edba0[_0x65f6('0x2f')]({'read':!![]});}else{logger[_0x65f6('0x20')](_0x65f6('0x7f'),_0x65f6('0x26'),_0x65f6('0x7b'),util['inspect'](_0x413c21['body'],{'showHidden':![],'depth':null}));}break;}return _0x4edba0;}})[_0x65f6('0x1d')](respondWithResult(_0x5158c9,null))[_0x65f6('0x4e')](handleError(_0x5158c9,null));};
\ No newline at end of file
+var _0x5f2f=['../../components/auth/service','../../components/parsers/advancedSearch','api','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','./whatsappMessage.socket','register','jayson/promise','client','http','request','then','info','WhatsappMessage,\x20%s,\x20%s','request\x20sent','debug','WhatsappMessage,\x20%s,\x20%s,\x20%s','stringify','error','message','catch','sendStatus','end','status','json','count','offset','limit','reject','save','update','destroy','stack','name','send','index','map','WhatsappMessage','fieldName','type','key','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','rows','show','params','rawAttributes','find','create','body','describe','../../config/logger','whatsapp-interactions','accept','whatsapp','readAt','YYYY-MM-DD\x20HH:mm:ss','UserId','user','CmContact','Contact','WhatsappInteraction','WhatsappInteractionId','isNil','format','interaction','get','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','acceptMessage','manual','interface','SIP/%s','channel','EventManager','acceptmessage','agent','[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','WhatsappAccount','WhatsappAccountId','WhatsppMessage,\x20%s,\x20%s,\x20%s','received\x20delivery\x20report\x20from','inspect','twilio','MessageSid','messageId','MessageStatus','read','WhatsappAccount,\x20%s,\x20%s,\x20%s','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','papaparse','ioredis'];(function(_0x349367,_0x1cede2){var _0x14179b=function(_0x38a191){while(--_0x38a191){_0x349367['push'](_0x349367['shift']());}};_0x14179b(++_0x1cede2);}(_0x5f2f,0x73));var _0xf5f2=function(_0x4ae668,_0x1b5fc8){_0x4ae668=_0x4ae668-0x0;var _0x4a4456=_0x5f2f[_0x4ae668];return _0x4a4456;};'use strict';var pdf=require(_0xf5f2('0x0'));var emlformat=require(_0xf5f2('0x1'));var rimraf=require(_0xf5f2('0x2'));var zipdir=require(_0xf5f2('0x3'));var jsonpatch=require(_0xf5f2('0x4'));var rp=require(_0xf5f2('0x5'));var moment=require(_0xf5f2('0x6'));var BPromise=require(_0xf5f2('0x7'));var Mustache=require('mustache');var util=require('util');var path=require(_0xf5f2('0x8'));var sox=require(_0xf5f2('0x9'));var csv=require(_0xf5f2('0xa'));var ejs=require(_0xf5f2('0xb'));var fs=require('fs');var _=require(_0xf5f2('0xc'));var squel=require(_0xf5f2('0xd'));var crypto=require('crypto');var jsforce=require(_0xf5f2('0xe'));var deskjs=require(_0xf5f2('0xf'));var toCsv=require(_0xf5f2('0xa'));var querystring=require('querystring');var Papa=require(_0xf5f2('0x10'));var Redis=require(_0xf5f2('0x11'));var authService=require(_0xf5f2('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0xf5f2('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xf5f2('0x14'));var utils=require(_0xf5f2('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xf5f2('0x16'));var db=require(_0xf5f2('0x17'))['db'];config[_0xf5f2('0x18')]=_[_0xf5f2('0x19')](config[_0xf5f2('0x18')],{'host':_0xf5f2('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xf5f2('0x18')]));require(_0xf5f2('0x1b'))[_0xf5f2('0x1c')](socket);var jayson=require(_0xf5f2('0x1d'));var client=jayson[_0xf5f2('0x1e')]['http']({'port':0x232c});var client9002=jayson[_0xf5f2('0x1e')][_0xf5f2('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x17d656,_0x1b6dd2,_0x23e23a,_0x3a9dbb){return new BPromise(function(_0xdb61b3,_0x395a5a){var _0x11f702=_0x3a9dbb||client;return _0x11f702[_0xf5f2('0x20')](_0x17d656,_0x23e23a)[_0xf5f2('0x21')](function(_0x28e097){logger[_0xf5f2('0x22')](_0xf5f2('0x23'),_0x1b6dd2,_0xf5f2('0x24'));logger[_0xf5f2('0x25')](_0xf5f2('0x26'),_0x1b6dd2,'request\x20sent',JSON[_0xf5f2('0x27')](_0x28e097));if(_0x28e097[_0xf5f2('0x28')]){if(_0x28e097['error']['code']===0x1f4){logger[_0xf5f2('0x28')](_0xf5f2('0x23'),_0x1b6dd2,_0x28e097['error'][_0xf5f2('0x29')]);return _0x395a5a(_0x28e097[_0xf5f2('0x28')][_0xf5f2('0x29')]);}logger[_0xf5f2('0x28')](_0xf5f2('0x23'),_0x1b6dd2,_0x28e097['error'][_0xf5f2('0x29')]);return _0xdb61b3(_0x28e097[_0xf5f2('0x28')][_0xf5f2('0x29')]);}else{logger[_0xf5f2('0x22')](_0xf5f2('0x23'),_0x1b6dd2,'request\x20sent');_0xdb61b3(_0x28e097['result'][_0xf5f2('0x29')]);}})[_0xf5f2('0x2a')](function(_0x13da6f){logger[_0xf5f2('0x28')](_0xf5f2('0x23'),_0x1b6dd2,_0x13da6f);_0x395a5a(_0x13da6f);});});}function respondWithStatusCode(_0x788a8d,_0x13a3be){_0x13a3be=_0x13a3be||0xcc;return function(_0x281ec8){if(_0x281ec8){return _0x788a8d[_0xf5f2('0x2b')](_0x13a3be);}return _0x788a8d['status'](_0x13a3be)[_0xf5f2('0x2c')]();};}function respondWithResult(_0x102449,_0x375ca8){_0x375ca8=_0x375ca8||0xc8;return function(_0x31bfcb){if(_0x31bfcb){return _0x102449[_0xf5f2('0x2d')](_0x375ca8)[_0xf5f2('0x2e')](_0x31bfcb);}};}function respondWithFilteredResult(_0x5b6672,_0x53cb96){return function(_0x22c826){if(_0x22c826){var _0x14c829=_0x22c826[_0xf5f2('0x2f')],_0x11c771=_0x53cb96[_0xf5f2('0x30')],_0x5027ab=_0x53cb96[_0xf5f2('0x30')]+_0x53cb96[_0xf5f2('0x31')],_0x5a2c7e;if(_0x5027ab>=_0x14c829){_0x5027ab=_0x14c829;_0x5a2c7e=0xc8;}else{_0x5a2c7e=0xce;}_0x5b6672[_0xf5f2('0x2d')](_0x5a2c7e);return _0x5b6672['set']('Content-Range',_0x11c771+'-'+_0x5027ab+'/'+_0x14c829)[_0xf5f2('0x2e')](_0x22c826);}return null;};}function patchUpdates(_0x4e19cb){return function(_0xb744b9){try{jsonpatch['apply'](_0xb744b9,_0x4e19cb,!![]);}catch(_0x45b643){return BPromise[_0xf5f2('0x32')](_0x45b643);}return _0xb744b9[_0xf5f2('0x33')]();};}function saveUpdates(_0x428770,_0x256bd9){return function(_0x277eee){if(_0x277eee){return _0x277eee[_0xf5f2('0x34')](_0x428770)[_0xf5f2('0x21')](function(_0x5ca917){return _0x5ca917;});}return null;};}function removeEntity(_0x4149e6,_0x43e4ff){return function(_0x4590ec){if(_0x4590ec){return _0x4590ec[_0xf5f2('0x35')]()[_0xf5f2('0x21')](function(){_0x4149e6[_0xf5f2('0x2d')](0xcc)[_0xf5f2('0x2c')]();});}};}function handleEntityNotFound(_0x48d64d,_0x144646){return function(_0xf503e8){if(!_0xf503e8){_0x48d64d['sendStatus'](0x194);}return _0xf503e8;};}function handleError(_0x3fc168,_0x4b8c42){_0x4b8c42=_0x4b8c42||0x1f4;return function(_0x18ae07){logger[_0xf5f2('0x28')](_0x18ae07[_0xf5f2('0x36')]);if(_0x18ae07[_0xf5f2('0x37')]){delete _0x18ae07['name'];}_0x3fc168['status'](_0x4b8c42)[_0xf5f2('0x38')](_0x18ae07);};}exports[_0xf5f2('0x39')]=function(_0x20eb74,_0x4ec8fb){var _0x41447f={},_0x4f7f80={},_0x9da533={'count':0x0,'rows':[]};var _0x566c47=_[_0xf5f2('0x3a')](db[_0xf5f2('0x3b')]['rawAttributes'],function(_0x29694f){return{'name':_0x29694f[_0xf5f2('0x3c')],'type':_0x29694f[_0xf5f2('0x3d')][_0xf5f2('0x3e')]};});_0x4f7f80['model']=_['map'](_0x566c47,_0xf5f2('0x37'));_0x4f7f80[_0xf5f2('0x3f')]=_[_0xf5f2('0x40')](_0x20eb74[_0xf5f2('0x3f')]);_0x4f7f80[_0xf5f2('0x41')]=_[_0xf5f2('0x42')](_0x4f7f80[_0xf5f2('0x43')],_0x4f7f80['query']);_0x41447f[_0xf5f2('0x44')]=_[_0xf5f2('0x42')](_0x4f7f80['model'],qs[_0xf5f2('0x45')](_0x20eb74[_0xf5f2('0x3f')][_0xf5f2('0x45')]));_0x41447f[_0xf5f2('0x44')]=_0x41447f[_0xf5f2('0x44')][_0xf5f2('0x46')]?_0x41447f[_0xf5f2('0x44')]:_0x4f7f80[_0xf5f2('0x43')];if(!_0x20eb74['query'][_0xf5f2('0x47')](_0xf5f2('0x48'))){_0x41447f[_0xf5f2('0x31')]=qs['limit'](_0x20eb74['query']['limit']);_0x41447f[_0xf5f2('0x30')]=qs[_0xf5f2('0x30')](_0x20eb74['query'][_0xf5f2('0x30')]);}_0x41447f[_0xf5f2('0x49')]=qs[_0xf5f2('0x4a')](_0x20eb74[_0xf5f2('0x3f')][_0xf5f2('0x4a')]);_0x41447f[_0xf5f2('0x4b')]=qs[_0xf5f2('0x41')](_[_0xf5f2('0x4c')](_0x20eb74[_0xf5f2('0x3f')],_0x4f7f80[_0xf5f2('0x41')]),_0x566c47);if(_0x20eb74[_0xf5f2('0x3f')][_0xf5f2('0x4d')]){_0x41447f[_0xf5f2('0x4b')]=_[_0xf5f2('0x4e')](_0x41447f['where'],{'$or':_[_0xf5f2('0x3a')](_0x566c47,function(_0x578c93){if(_0x578c93[_0xf5f2('0x3d')]!==_0xf5f2('0x4f')){var _0x218def={};_0x218def[_0x578c93[_0xf5f2('0x37')]]={'$like':'%'+_0x20eb74[_0xf5f2('0x3f')][_0xf5f2('0x4d')]+'%'};return _0x218def;}})});}_0x41447f=_['merge']({},_0x41447f,_0x20eb74[_0xf5f2('0x50')]);var _0x2e7193={'where':_0x41447f[_0xf5f2('0x4b')]};return db[_0xf5f2('0x3b')][_0xf5f2('0x2f')](_0x2e7193)[_0xf5f2('0x21')](function(_0xf638ff){_0x9da533[_0xf5f2('0x2f')]=_0xf638ff;if(_0x20eb74['query'][_0xf5f2('0x51')]){_0x41447f[_0xf5f2('0x52')]=[{'all':!![]}];}return db[_0xf5f2('0x3b')]['findAll'](_0x41447f);})[_0xf5f2('0x21')](function(_0xc91b64){_0x9da533[_0xf5f2('0x53')]=_0xc91b64;return _0x9da533;})['then'](respondWithFilteredResult(_0x4ec8fb,_0x41447f))['catch'](handleError(_0x4ec8fb,null));};exports[_0xf5f2('0x54')]=function(_0x27c472,_0x5db519){var _0x14aa81={'raw':!![],'where':{'id':_0x27c472[_0xf5f2('0x55')]['id']}},_0x533cca={};_0x533cca['model']=_[_0xf5f2('0x40')](db['WhatsappMessage'][_0xf5f2('0x56')]);_0x533cca[_0xf5f2('0x3f')]=_[_0xf5f2('0x40')](_0x27c472[_0xf5f2('0x3f')]);_0x533cca['filters']=_[_0xf5f2('0x42')](_0x533cca[_0xf5f2('0x43')],_0x533cca['query']);_0x14aa81['attributes']=_[_0xf5f2('0x42')](_0x533cca[_0xf5f2('0x43')],qs['fields'](_0x27c472[_0xf5f2('0x3f')][_0xf5f2('0x45')]));_0x14aa81[_0xf5f2('0x44')]=_0x14aa81[_0xf5f2('0x44')]['length']?_0x14aa81['attributes']:_0x533cca[_0xf5f2('0x43')];if(_0x27c472[_0xf5f2('0x3f')]['includeAll']){_0x14aa81[_0xf5f2('0x52')]=[{'all':!![]}];}_0x14aa81=_[_0xf5f2('0x4e')]({},_0x14aa81,_0x27c472[_0xf5f2('0x50')]);return db[_0xf5f2('0x3b')][_0xf5f2('0x57')](_0x14aa81)[_0xf5f2('0x21')](handleEntityNotFound(_0x5db519,null))[_0xf5f2('0x21')](respondWithResult(_0x5db519,null))['catch'](handleError(_0x5db519,null));};exports['create']=function(_0x330730,_0x27665d){return db[_0xf5f2('0x3b')][_0xf5f2('0x58')](_0x330730[_0xf5f2('0x59')],{})['then'](respondWithResult(_0x27665d,0xc9))[_0xf5f2('0x2a')](handleError(_0x27665d,null));};exports[_0xf5f2('0x34')]=function(_0x18b124,_0x519c24){if(_0x18b124[_0xf5f2('0x59')]['id']){delete _0x18b124['body']['id'];}return db[_0xf5f2('0x3b')][_0xf5f2('0x57')]({'where':{'id':_0x18b124[_0xf5f2('0x55')]['id']}})[_0xf5f2('0x21')](handleEntityNotFound(_0x519c24,null))['then'](saveUpdates(_0x18b124['body'],null))[_0xf5f2('0x21')](respondWithResult(_0x519c24,null))['catch'](handleError(_0x519c24,null));};exports[_0xf5f2('0x35')]=function(_0x1f1916,_0x572ec1){return db[_0xf5f2('0x3b')][_0xf5f2('0x57')]({'where':{'id':_0x1f1916[_0xf5f2('0x55')]['id']}})['then'](handleEntityNotFound(_0x572ec1,null))[_0xf5f2('0x21')](removeEntity(_0x572ec1,null))[_0xf5f2('0x2a')](handleError(_0x572ec1,null));};exports[_0xf5f2('0x5a')]=function(_0x4579f4,_0x51fa7e){return db[_0xf5f2('0x3b')]['describe']()[_0xf5f2('0x21')](respondWithResult(_0x51fa7e,null))[_0xf5f2('0x2a')](handleError(_0x51fa7e,null));};var interaction_log=require(_0xf5f2('0x5b'))(_0xf5f2('0x5c'));exports[_0xf5f2('0x5d')]=function(_0x5583c2,_0xda8dda,_0xacd80){var _0x3461e5={'channel':_0xf5f2('0x5e')};if(_0x5583c2[_0xf5f2('0x59')]['id']){delete _0x5583c2['body']['id'];}_0x5583c2[_0xf5f2('0x59')]['read']=!![];_0x5583c2['body'][_0xf5f2('0x5f')]=moment()['format'](_0xf5f2('0x60'));_0x5583c2[_0xf5f2('0x59')][_0xf5f2('0x61')]=_0x5583c2[_0xf5f2('0x59')]['UserId']||_0x5583c2[_0xf5f2('0x62')]['id'];return db[_0xf5f2('0x3b')][_0xf5f2('0x57')]({'where':{'id':_0x5583c2[_0xf5f2('0x55')]['id'],'UserId':null},'include':[{'model':db[_0xf5f2('0x63')],'as':_0xf5f2('0x64')}]})[_0xf5f2('0x21')](handleEntityNotFound(_0xda8dda,null))['then'](saveUpdates(_0x5583c2[_0xf5f2('0x59')],null))[_0xf5f2('0x21')](function(_0xb39a6e){if(_0xb39a6e){_0x3461e5[_0xf5f2('0x29')]=_0xb39a6e['get']({'plain':!![]});return db[_0xf5f2('0x65')]['find']({'where':{'id':_0xb39a6e[_0xf5f2('0x66')]}});}return null;})[_0xf5f2('0x21')](handleEntityNotFound(_0xda8dda,null))['then'](function(_0x363b34){if(_0x363b34){return _0x363b34[_0xf5f2('0x34')]({'UserId':_0x5583c2[_0xf5f2('0x59')][_0xf5f2('0x61')],'read1stAt':_[_0xf5f2('0x67')](_0x363b34['read1stAt'])?moment()[_0xf5f2('0x68')](_0xf5f2('0x60')):undefined});}return null;})[_0xf5f2('0x21')](function(_0xbf9f55){if(_0xbf9f55){_0x3461e5[_0xf5f2('0x69')]=_0xbf9f55[_0xf5f2('0x6a')]({'plain':!![]});interaction_log['info'](_0xf5f2('0x6b'),_0x5583c2[_0xf5f2('0x62')]['id'],_0x5583c2['user'][_0xf5f2('0x37')],_0x5583c2[_0xf5f2('0x62')][_0xf5f2('0x6c')],_0x3461e5['interaction']['id'],_0x5583c2['body']?JSON['stringify'](_0x5583c2[_0xf5f2('0x59')]):_0xf5f2('0x6d'));return respondWithRpcPromise(_0xf5f2('0x6e'),_0xf5f2('0x6f'),_0x3461e5);}return null;})[_0xf5f2('0x21')](function(_0x4d878e){if(_0x4d878e){if(_0x5583c2[_0xf5f2('0x59')][_0xf5f2('0x70')]){_0x3461e5[_0xf5f2('0x29')][_0xf5f2('0x71')]=util[_0xf5f2('0x68')](_0xf5f2('0x72'),_0x5583c2[_0xf5f2('0x62')][_0xf5f2('0x37')]);_0x3461e5[_0xf5f2('0x29')][_0xf5f2('0x73')]=_0x3461e5[_0xf5f2('0x73')];_0x3461e5['message']['event']='accept';return respondWithRpcPromise(_0xf5f2('0x74'),_0xf5f2('0x74'),{'event':_0xf5f2('0x75'),'message':_0x3461e5[_0xf5f2('0x29')]},client9002)[_0xf5f2('0x21')](function(){return _0x3461e5;});}return _0x3461e5;}return null;})['then'](respondWithResult(_0xda8dda,null))[_0xf5f2('0x2a')](handleError(_0xda8dda,null));};var interaction_log=require(_0xf5f2('0x5b'))(_0xf5f2('0x5c'));exports[_0xf5f2('0x32')]=function(_0x44d119,_0x55748d,_0x2986ed){var _0x1409b9={'agent':{},'channel':'whatsapp'};if(_0x44d119[_0xf5f2('0x59')]['id']){delete _0x44d119[_0xf5f2('0x59')]['id'];}_0x44d119[_0xf5f2('0x59')][_0xf5f2('0x61')]=_0x44d119['body'][_0xf5f2('0x61')]||_0x44d119[_0xf5f2('0x62')]['id'];_0x1409b9[_0xf5f2('0x76')]['id']=_0x44d119[_0xf5f2('0x59')][_0xf5f2('0x61')];return db['WhatsappMessage']['find']({'where':{'id':_0x44d119[_0xf5f2('0x55')]['id'],'UserId':null}})[_0xf5f2('0x21')](handleEntityNotFound(_0x55748d,null))[_0xf5f2('0x21')](function(_0xe3ea1e){if(_0xe3ea1e){_0x1409b9['message']=_0xe3ea1e['get']({'plain':!![]});return db[_0xf5f2('0x65')]['find']({'where':{'id':_0xe3ea1e['WhatsappInteractionId']}});}return null;})['then'](handleEntityNotFound(_0x55748d,null))['then'](function(_0xad4554){if(_0xad4554){_0x1409b9[_0xf5f2('0x69')]=_0xad4554[_0xf5f2('0x6a')]({'plain':!![]});interaction_log[_0xf5f2('0x22')](_0xf5f2('0x77'),_0x44d119[_0xf5f2('0x62')]['id'],_0x44d119[_0xf5f2('0x62')][_0xf5f2('0x37')],_0x44d119[_0xf5f2('0x62')][_0xf5f2('0x6c')],_0x1409b9[_0xf5f2('0x69')]['id'],_0x44d119[_0xf5f2('0x59')]?JSON[_0xf5f2('0x27')](_0x44d119[_0xf5f2('0x59')]):_0xf5f2('0x6d'));return respondWithRpcPromise(_0xf5f2('0x78'),_0xf5f2('0x79'),_0x1409b9);}return null;})[_0xf5f2('0x21')](function(_0x4a39c0){if(_0x4a39c0){_0x4a39c0[_0xf5f2('0x29')][_0xf5f2('0x71')]=util[_0xf5f2('0x68')](_0xf5f2('0x72'),_0x44d119[_0xf5f2('0x62')][_0xf5f2('0x37')]);_0x4a39c0[_0xf5f2('0x29')][_0xf5f2('0x73')]=_0x1409b9['channel'];_0x4a39c0[_0xf5f2('0x29')]['event']='reject';respondWithRpcPromise('EventManager','EventManager',{'event':'rejectmessage','message':_0x4a39c0['message']},client9002);return _0x1409b9;}return null;})[_0xf5f2('0x21')](respondWithResult(_0x55748d,null))[_0xf5f2('0x2a')](handleError(_0x55748d,null));};exports[_0xf5f2('0x2d')]=function(_0x375bc9,_0x145d4d,_0x3cf857){if(_0x375bc9['body']['id']){delete _0x375bc9['body']['id'];}var _0x2fb1a6;return db['WhatsappMessage'][_0xf5f2('0x57')]({'where':{'id':_0x375bc9[_0xf5f2('0x55')]['id']}})['then'](handleEntityNotFound(_0x145d4d,null))['then'](function(_0x9068a1){if(_0x9068a1){_0x2fb1a6=_0x9068a1;return db[_0xf5f2('0x7a')]['find']({'where':{'id':_0x9068a1[_0xf5f2('0x7b')]}});}})[_0xf5f2('0x21')](handleEntityNotFound(_0x145d4d,null))['then'](function(_0x1774ab){if(_0x1774ab){logger[_0xf5f2('0x25')](_0xf5f2('0x7c'),'status',_0xf5f2('0x7d'),_0x1774ab[_0xf5f2('0x3d')],util[_0xf5f2('0x7e')](_0x375bc9[_0xf5f2('0x59')],{'showHidden':![],'depth':null}));switch(_0x1774ab[_0xf5f2('0x3d')]){case _0xf5f2('0x7f'):if(_0x375bc9[_0xf5f2('0x59')][_0xf5f2('0x80')]&&_0x375bc9[_0xf5f2('0x59')][_0xf5f2('0x80')]===_0x2fb1a6[_0xf5f2('0x81')]&&_0x375bc9[_0xf5f2('0x59')][_0xf5f2('0x82')]&&_0x375bc9[_0xf5f2('0x59')][_0xf5f2('0x82')]===_0xf5f2('0x83')){return _0x2fb1a6[_0xf5f2('0x34')]({'read':!![]});}else{logger[_0xf5f2('0x28')](_0xf5f2('0x84'),_0xf5f2('0x2d'),_0xf5f2('0x7f'),util['inspect'](_0x375bc9[_0xf5f2('0x59')],{'showHidden':![],'depth':null}));}break;}return _0x2fb1a6;}})[_0xf5f2('0x21')](respondWithResult(_0x145d4d,null))['catch'](handleError(_0x145d4d,null));};
\ No newline at end of file