Built motion from commit (unavailable).|2.5.29
[motion2.git] / server / api / whatsappMessage / whatsappMessage.controller.js
index cb11821..ad54c36 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 _0x0b52=['attributes','intersection','length','hasOwnProperty','nolimit','sort','where','filter','merge','VIRTUAL','options','includeAll','rows','show','model','find','create','body','update','describe','whatsapp-interactions','whatsapp','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','params','CmContact','Contact','get','WhatsappInteraction','WhatsappInteractionId','isNil','read1stAt','format','role','interaction','stringify','null','AcceptMessage','manual','channel','event','accept','EventManager','acceptmessage','RejectMessage','rejectMessage','interface','SIP/%s','rejectmessage','WhatsappAccount','WhatsappAccountId','WhatsppMessage,\x20%s,\x20%s,\x20%s','received\x20delivery\x20report\x20from','inspect','twilio','MessageSid','messageId','read','WhatsappAccount,\x20%s,\x20%s,\x20%s','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','util','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./whatsappMessage.socket','register','client','http','then','info','WhatsappMessage,\x20%s,\x20%s','request\x20sent','debug','error','code','message','result','catch','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','reject','save','destroy','stack','name','index','map','WhatsappMessage','rawAttributes','type','key','keys','query','filters'];(function(_0x55e08b,_0x421620){var _0xd1a7ff=function(_0x58c7ff){while(--_0x58c7ff){_0x55e08b['push'](_0x55e08b['shift']());}};_0xd1a7ff(++_0x421620);}(_0x0b52,0xb9));var _0x20b5=function(_0x405020,_0x743aac){_0x405020=_0x405020-0x0;var _0x33321c=_0x0b52[_0x405020];return _0x33321c;};'use strict';var emlformat=require(_0x20b5('0x0'));var rimraf=require(_0x20b5('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x20b5('0x2'));var rp=require(_0x20b5('0x3'));var moment=require(_0x20b5('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x20b5('0x5'));var util=require(_0x20b5('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0x20b5('0x7'));var ejs=require(_0x20b5('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x20b5('0x9'));var squel=require(_0x20b5('0xa'));var crypto=require(_0x20b5('0xb'));var jsforce=require(_0x20b5('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x20b5('0xd'));var Papa=require('papaparse');var Redis=require(_0x20b5('0xe'));var authService=require(_0x20b5('0xf'));var qs=require(_0x20b5('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x20b5('0x11'));var logger=require(_0x20b5('0x12'))('api');var utils=require('../../config/utils');var config=require(_0x20b5('0x13'));var licenseUtil=require(_0x20b5('0x14'));var db=require('../../mysqldb')['db'];config[_0x20b5('0x15')]=_[_0x20b5('0x16')](config[_0x20b5('0x15')],{'host':_0x20b5('0x17'),'port':0x18eb});var socket=require(_0x20b5('0x18'))(new Redis(config[_0x20b5('0x15')]));require(_0x20b5('0x19'))[_0x20b5('0x1a')](socket);var jayson=require('jayson/promise');var client=jayson[_0x20b5('0x1b')]['http']({'port':0x232c});var client9002=jayson[_0x20b5('0x1b')][_0x20b5('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x560695,_0x482ea8,_0x11ac85,_0xc9db91){return new BPromise(function(_0x5d46f8,_0x3c390b){var _0x1618e0=_0xc9db91||client;return _0x1618e0['request'](_0x560695,_0x11ac85)[_0x20b5('0x1d')](function(_0x4fbceb){logger[_0x20b5('0x1e')](_0x20b5('0x1f'),_0x482ea8,_0x20b5('0x20'));logger[_0x20b5('0x21')]('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0x482ea8,_0x20b5('0x20'),JSON['stringify'](_0x4fbceb));if(_0x4fbceb['error']){if(_0x4fbceb[_0x20b5('0x22')][_0x20b5('0x23')]===0x1f4){logger[_0x20b5('0x22')](_0x20b5('0x1f'),_0x482ea8,_0x4fbceb['error'][_0x20b5('0x24')]);return _0x3c390b(_0x4fbceb[_0x20b5('0x22')][_0x20b5('0x24')]);}logger[_0x20b5('0x22')]('WhatsappMessage,\x20%s,\x20%s',_0x482ea8,_0x4fbceb[_0x20b5('0x22')]['message']);return _0x5d46f8(_0x4fbceb[_0x20b5('0x22')][_0x20b5('0x24')]);}else{logger[_0x20b5('0x1e')](_0x20b5('0x1f'),_0x482ea8,'request\x20sent');_0x5d46f8(_0x4fbceb[_0x20b5('0x25')][_0x20b5('0x24')]);}})[_0x20b5('0x26')](function(_0x15ecc3){logger[_0x20b5('0x22')](_0x20b5('0x1f'),_0x482ea8,_0x15ecc3);_0x3c390b(_0x15ecc3);});});}function respondWithStatusCode(_0x43dee1,_0x94f2ea){_0x94f2ea=_0x94f2ea||0xcc;return function(_0x29b115){if(_0x29b115){return _0x43dee1['sendStatus'](_0x94f2ea);}return _0x43dee1[_0x20b5('0x27')](_0x94f2ea)[_0x20b5('0x28')]();};}function respondWithResult(_0x24a356,_0x37689d){_0x37689d=_0x37689d||0xc8;return function(_0x23f35f){if(_0x23f35f){return _0x24a356[_0x20b5('0x27')](_0x37689d)[_0x20b5('0x29')](_0x23f35f);}};}function respondWithFilteredResult(_0x143446,_0x1a8f5a){return function(_0x109eae){if(_0x109eae){var _0xa1f216=typeof _0x1a8f5a[_0x20b5('0x2a')]==='undefined'&&typeof _0x1a8f5a[_0x20b5('0x2b')]===_0x20b5('0x2c');var _0x3fe510=_0x109eae[_0x20b5('0x2d')];var _0x8a9719=_0xa1f216?0x0:_0x1a8f5a[_0x20b5('0x2a')];var _0x5b92f8=_0xa1f216?_0x109eae[_0x20b5('0x2d')]:_0x1a8f5a[_0x20b5('0x2a')]+_0x1a8f5a['limit'];var _0xa499ff;if(_0x5b92f8>=_0x3fe510){_0x5b92f8=_0x3fe510;_0xa499ff=0xc8;}else{_0xa499ff=0xce;}_0x143446[_0x20b5('0x27')](_0xa499ff);return _0x143446[_0x20b5('0x2e')](_0x20b5('0x2f'),_0x8a9719+'-'+_0x5b92f8+'/'+_0x3fe510)['json'](_0x109eae);}return null;};}function patchUpdates(_0xc369c2){return function(_0x29aa98){try{jsonpatch[_0x20b5('0x30')](_0x29aa98,_0xc369c2,!![]);}catch(_0x169474){return BPromise[_0x20b5('0x31')](_0x169474);}return _0x29aa98[_0x20b5('0x32')]();};}function saveUpdates(_0x2ea72f,_0x549e2a){return function(_0x561695){if(_0x561695){return _0x561695['update'](_0x2ea72f)[_0x20b5('0x1d')](function(_0x4bd34a){return _0x4bd34a;});}return null;};}function removeEntity(_0x31123d,_0x5d2475){return function(_0x1f2f11){if(_0x1f2f11){return _0x1f2f11[_0x20b5('0x33')]()[_0x20b5('0x1d')](function(){_0x31123d[_0x20b5('0x27')](0xcc)[_0x20b5('0x28')]();});}};}function handleEntityNotFound(_0x16b0c3,_0xb350f9){return function(_0x4fd125){if(!_0x4fd125){_0x16b0c3['sendStatus'](0x194);}return _0x4fd125;};}function handleError(_0x529ec3,_0x3147d9){_0x3147d9=_0x3147d9||0x1f4;return function(_0x1d59ff){logger[_0x20b5('0x22')](_0x1d59ff[_0x20b5('0x34')]);if(_0x1d59ff[_0x20b5('0x35')]){delete _0x1d59ff[_0x20b5('0x35')];}_0x529ec3[_0x20b5('0x27')](_0x3147d9)['send'](_0x1d59ff);};}exports[_0x20b5('0x36')]=function(_0x11000c,_0x4b17f1){var _0x38d49d={},_0x2ab536={},_0x4d1ad7={'count':0x0,'rows':[]};var _0x3b37cc=_[_0x20b5('0x37')](db[_0x20b5('0x38')][_0x20b5('0x39')],function(_0x10da49){return{'name':_0x10da49['fieldName'],'type':_0x10da49[_0x20b5('0x3a')][_0x20b5('0x3b')]};});_0x2ab536['model']=_['map'](_0x3b37cc,'name');_0x2ab536['query']=_[_0x20b5('0x3c')](_0x11000c[_0x20b5('0x3d')]);_0x2ab536[_0x20b5('0x3e')]=_['intersection'](_0x2ab536['model'],_0x2ab536['query']);_0x38d49d[_0x20b5('0x3f')]=_[_0x20b5('0x40')](_0x2ab536['model'],qs['fields'](_0x11000c[_0x20b5('0x3d')]['fields']));_0x38d49d[_0x20b5('0x3f')]=_0x38d49d[_0x20b5('0x3f')][_0x20b5('0x41')]?_0x38d49d[_0x20b5('0x3f')]:_0x2ab536['model'];if(!_0x11000c[_0x20b5('0x3d')][_0x20b5('0x42')](_0x20b5('0x43'))){_0x38d49d[_0x20b5('0x2b')]=qs[_0x20b5('0x2b')](_0x11000c[_0x20b5('0x3d')][_0x20b5('0x2b')]);_0x38d49d[_0x20b5('0x2a')]=qs[_0x20b5('0x2a')](_0x11000c['query'][_0x20b5('0x2a')]);}_0x38d49d['order']=qs[_0x20b5('0x44')](_0x11000c[_0x20b5('0x3d')][_0x20b5('0x44')]);_0x38d49d[_0x20b5('0x45')]=qs[_0x20b5('0x3e')](_['pick'](_0x11000c[_0x20b5('0x3d')],_0x2ab536['filters']),_0x3b37cc);if(_0x11000c[_0x20b5('0x3d')][_0x20b5('0x46')]){_0x38d49d[_0x20b5('0x45')]=_[_0x20b5('0x47')](_0x38d49d['where'],{'$or':_[_0x20b5('0x37')](_0x3b37cc,function(_0x5b3aaa){if(_0x5b3aaa['type']!==_0x20b5('0x48')){var _0x42664c={};_0x42664c[_0x5b3aaa[_0x20b5('0x35')]]={'$like':'%'+_0x11000c[_0x20b5('0x3d')]['filter']+'%'};return _0x42664c;}})});}_0x38d49d=_['merge']({},_0x38d49d,_0x11000c[_0x20b5('0x49')]);var _0x5b5eb8={'where':_0x38d49d[_0x20b5('0x45')]};return db[_0x20b5('0x38')]['count'](_0x5b5eb8)['then'](function(_0x3c3981){_0x4d1ad7[_0x20b5('0x2d')]=_0x3c3981;if(_0x11000c[_0x20b5('0x3d')][_0x20b5('0x4a')]){_0x38d49d['include']=[{'all':!![]}];}return db[_0x20b5('0x38')]['findAll'](_0x38d49d);})['then'](function(_0x1ed72d){_0x4d1ad7[_0x20b5('0x4b')]=_0x1ed72d;return _0x4d1ad7;})[_0x20b5('0x1d')](respondWithFilteredResult(_0x4b17f1,_0x38d49d))[_0x20b5('0x26')](handleError(_0x4b17f1,null));};exports[_0x20b5('0x4c')]=function(_0x4d631b,_0x2bca39){var _0x51e379={'raw':!![],'where':{'id':_0x4d631b['params']['id']}},_0x13d883={};_0x13d883[_0x20b5('0x4d')]=_[_0x20b5('0x3c')](db[_0x20b5('0x38')]['rawAttributes']);_0x13d883['query']=_[_0x20b5('0x3c')](_0x4d631b[_0x20b5('0x3d')]);_0x13d883[_0x20b5('0x3e')]=_['intersection'](_0x13d883[_0x20b5('0x4d')],_0x13d883[_0x20b5('0x3d')]);_0x51e379['attributes']=_[_0x20b5('0x40')](_0x13d883[_0x20b5('0x4d')],qs['fields'](_0x4d631b[_0x20b5('0x3d')]['fields']));_0x51e379[_0x20b5('0x3f')]=_0x51e379[_0x20b5('0x3f')][_0x20b5('0x41')]?_0x51e379[_0x20b5('0x3f')]:_0x13d883[_0x20b5('0x4d')];if(_0x4d631b[_0x20b5('0x3d')]['includeAll']){_0x51e379['include']=[{'all':!![]}];}_0x51e379=_[_0x20b5('0x47')]({},_0x51e379,_0x4d631b[_0x20b5('0x49')]);return db[_0x20b5('0x38')][_0x20b5('0x4e')](_0x51e379)[_0x20b5('0x1d')](handleEntityNotFound(_0x2bca39,null))[_0x20b5('0x1d')](respondWithResult(_0x2bca39,null))[_0x20b5('0x26')](handleError(_0x2bca39,null));};exports[_0x20b5('0x4f')]=function(_0x3bac12,_0xfbf414){return db[_0x20b5('0x38')]['create'](_0x3bac12[_0x20b5('0x50')],{})[_0x20b5('0x1d')](respondWithResult(_0xfbf414,0xc9))[_0x20b5('0x26')](handleError(_0xfbf414,null));};exports[_0x20b5('0x51')]=function(_0x5b8794,_0x3c74e1){if(_0x5b8794[_0x20b5('0x50')]['id']){delete _0x5b8794[_0x20b5('0x50')]['id'];}return db[_0x20b5('0x38')][_0x20b5('0x4e')]({'where':{'id':_0x5b8794['params']['id']}})[_0x20b5('0x1d')](handleEntityNotFound(_0x3c74e1,null))[_0x20b5('0x1d')](saveUpdates(_0x5b8794[_0x20b5('0x50')],null))['then'](respondWithResult(_0x3c74e1,null))[_0x20b5('0x26')](handleError(_0x3c74e1,null));};exports[_0x20b5('0x33')]=function(_0x516898,_0x58daaa){return db[_0x20b5('0x38')][_0x20b5('0x4e')]({'where':{'id':_0x516898['params']['id']}})[_0x20b5('0x1d')](handleEntityNotFound(_0x58daaa,null))[_0x20b5('0x1d')](removeEntity(_0x58daaa,null))[_0x20b5('0x26')](handleError(_0x58daaa,null));};exports[_0x20b5('0x52')]=function(_0x4a4e49,_0x618254){return db['WhatsappMessage'][_0x20b5('0x52')]()[_0x20b5('0x1d')](respondWithResult(_0x618254,null))[_0x20b5('0x26')](handleError(_0x618254,null));};var interaction_log=require('../../config/logger')(_0x20b5('0x53'));exports['accept']=function(_0x864196,_0x392cb0,_0xcb6a35){var _0x2b797e={'agent':{},'channel':_0x20b5('0x54')};if(_0x864196[_0x20b5('0x50')]['id']){delete _0x864196[_0x20b5('0x50')]['id'];}_0x864196[_0x20b5('0x50')]['read']=!![];_0x864196[_0x20b5('0x50')]['readAt']=moment()['format'](_0x20b5('0x55'));_0x864196['body'][_0x20b5('0x56')]=_0x864196[_0x20b5('0x50')][_0x20b5('0x56')]||_0x864196[_0x20b5('0x57')]['id'];_0x2b797e[_0x20b5('0x58')]['id']=_0x864196['body'][_0x20b5('0x56')];return db[_0x20b5('0x38')][_0x20b5('0x4e')]({'where':{'id':_0x864196[_0x20b5('0x59')]['id'],'UserId':null},'include':[{'model':db[_0x20b5('0x5a')],'as':_0x20b5('0x5b')}]})[_0x20b5('0x1d')](handleEntityNotFound(_0x392cb0,null))[_0x20b5('0x1d')](saveUpdates(_0x864196['body'],null))[_0x20b5('0x1d')](function(_0x366d74){if(_0x366d74){_0x2b797e[_0x20b5('0x24')]=_0x366d74[_0x20b5('0x5c')]({'plain':!![]});return db[_0x20b5('0x5d')][_0x20b5('0x4e')]({'where':{'id':_0x366d74[_0x20b5('0x5e')]}});}return null;})['then'](handleEntityNotFound(_0x392cb0,null))[_0x20b5('0x1d')](function(_0x1fe082){if(_0x1fe082){return _0x1fe082[_0x20b5('0x51')]({'UserId':_0x864196['body']['UserId'],'read1stAt':_[_0x20b5('0x5f')](_0x1fe082[_0x20b5('0x60')])?moment()[_0x20b5('0x61')](_0x20b5('0x55')):undefined});}return null;})[_0x20b5('0x1d')](function(_0x5a41d0){if(_0x5a41d0){_0x2b797e['interaction']=_0x5a41d0['get']({'plain':!![]});interaction_log[_0x20b5('0x1e')]('[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x864196[_0x20b5('0x57')]['id'],_0x864196[_0x20b5('0x57')][_0x20b5('0x35')],_0x864196[_0x20b5('0x57')][_0x20b5('0x62')],_0x2b797e[_0x20b5('0x63')]['id'],_0x864196[_0x20b5('0x50')]?JSON[_0x20b5('0x64')](_0x864196[_0x20b5('0x50')]):_0x20b5('0x65'));return respondWithRpcPromise(_0x20b5('0x66'),'acceptMessage',_0x2b797e);}return null;})[_0x20b5('0x1d')](function(_0x5916f6){if(_0x5916f6){if(_0x864196[_0x20b5('0x50')][_0x20b5('0x67')]){_0x2b797e[_0x20b5('0x24')]['interface']=util[_0x20b5('0x61')]('SIP/%s',_0x864196[_0x20b5('0x57')][_0x20b5('0x35')]);_0x2b797e[_0x20b5('0x24')][_0x20b5('0x68')]=_0x2b797e[_0x20b5('0x68')];_0x2b797e['message'][_0x20b5('0x69')]=_0x20b5('0x6a');return respondWithRpcPromise(_0x20b5('0x6b'),_0x20b5('0x6b'),{'event':_0x20b5('0x6c'),'message':_0x2b797e[_0x20b5('0x24')]},client9002)[_0x20b5('0x1d')](function(){return _0x2b797e;});}return _0x2b797e;}return null;})['then'](respondWithResult(_0x392cb0,null))['catch'](handleError(_0x392cb0,null));};var interaction_log=require(_0x20b5('0x12'))(_0x20b5('0x53'));exports[_0x20b5('0x31')]=function(_0x456255,_0x394c5f,_0x4a8d97){var _0x55be19={'agent':{},'channel':_0x20b5('0x54')};if(_0x456255['body']['id']){delete _0x456255[_0x20b5('0x50')]['id'];}_0x456255[_0x20b5('0x50')]['UserId']=_0x456255[_0x20b5('0x50')][_0x20b5('0x56')]||_0x456255[_0x20b5('0x57')]['id'];_0x55be19[_0x20b5('0x58')]['id']=_0x456255[_0x20b5('0x50')]['UserId'];return db[_0x20b5('0x38')][_0x20b5('0x4e')]({'where':{'id':_0x456255[_0x20b5('0x59')]['id'],'UserId':null}})[_0x20b5('0x1d')](handleEntityNotFound(_0x394c5f,null))[_0x20b5('0x1d')](function(_0x5a4b98){if(_0x5a4b98){_0x55be19[_0x20b5('0x24')]=_0x5a4b98['get']({'plain':!![]});return db[_0x20b5('0x5d')][_0x20b5('0x4e')]({'where':{'id':_0x5a4b98[_0x20b5('0x5e')]}});}return null;})['then'](handleEntityNotFound(_0x394c5f,null))[_0x20b5('0x1d')](function(_0x372ff1){if(_0x372ff1){_0x55be19[_0x20b5('0x63')]=_0x372ff1['get']({'plain':!![]});interaction_log['info']('[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x456255[_0x20b5('0x57')]['id'],_0x456255[_0x20b5('0x57')]['name'],_0x456255[_0x20b5('0x57')][_0x20b5('0x62')],_0x55be19[_0x20b5('0x63')]['id'],_0x456255[_0x20b5('0x50')]?JSON[_0x20b5('0x64')](_0x456255[_0x20b5('0x50')]):'null');return respondWithRpcPromise(_0x20b5('0x6d'),_0x20b5('0x6e'),_0x55be19);}return null;})[_0x20b5('0x1d')](function(_0x372bfe){if(_0x372bfe){_0x372bfe['message'][_0x20b5('0x6f')]=util['format'](_0x20b5('0x70'),_0x456255[_0x20b5('0x57')]['name']);_0x372bfe[_0x20b5('0x24')][_0x20b5('0x68')]=_0x55be19[_0x20b5('0x68')];_0x372bfe[_0x20b5('0x24')]['event']=_0x20b5('0x31');respondWithRpcPromise(_0x20b5('0x6b'),_0x20b5('0x6b'),{'event':_0x20b5('0x71'),'message':_0x372bfe[_0x20b5('0x24')]},client9002);return _0x55be19;}return null;})[_0x20b5('0x1d')](respondWithResult(_0x394c5f,null))[_0x20b5('0x26')](handleError(_0x394c5f,null));};exports[_0x20b5('0x27')]=function(_0x1a462e,_0x5f32e8,_0x3814fe){if(_0x1a462e[_0x20b5('0x50')]['id']){delete _0x1a462e[_0x20b5('0x50')]['id'];}var _0x40e0bb;return db[_0x20b5('0x38')][_0x20b5('0x4e')]({'where':{'id':_0x1a462e[_0x20b5('0x59')]['id']}})[_0x20b5('0x1d')](handleEntityNotFound(_0x5f32e8,null))['then'](function(_0x280f98){if(_0x280f98){_0x40e0bb=_0x280f98;return db[_0x20b5('0x72')][_0x20b5('0x4e')]({'where':{'id':_0x280f98[_0x20b5('0x73')]}});}})[_0x20b5('0x1d')](handleEntityNotFound(_0x5f32e8,null))[_0x20b5('0x1d')](function(_0x5c9a45){if(_0x5c9a45){logger[_0x20b5('0x21')](_0x20b5('0x74'),_0x20b5('0x27'),_0x20b5('0x75'),_0x5c9a45[_0x20b5('0x3a')],util[_0x20b5('0x76')](_0x1a462e[_0x20b5('0x50')],{'showHidden':![],'depth':null}));switch(_0x5c9a45['type']){case _0x20b5('0x77'):if(_0x1a462e[_0x20b5('0x50')][_0x20b5('0x78')]&&_0x1a462e[_0x20b5('0x50')][_0x20b5('0x78')]===_0x40e0bb[_0x20b5('0x79')]&&_0x1a462e[_0x20b5('0x50')]['MessageStatus']&&_0x1a462e[_0x20b5('0x50')]['MessageStatus']===_0x20b5('0x7a')){return _0x40e0bb[_0x20b5('0x51')]({'read':!![]});}else{logger[_0x20b5('0x22')](_0x20b5('0x7b'),_0x20b5('0x27'),_0x20b5('0x77'),util[_0x20b5('0x76')](_0x1a462e[_0x20b5('0x50')],{'showHidden':![],'depth':null}));}break;}return _0x40e0bb;}})[_0x20b5('0x1d')](respondWithResult(_0x5f32e8,null))['catch'](handleError(_0x5f32e8,null));};
\ No newline at end of file