Built motion from commit (unavailable).|2.5.29
[motion2.git] / server / api / whatsappMessage / whatsappMessage.controller.js
index 09c735a..ad54c36 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf34f=['localhost','socket.io-emitter','./whatsappMessage.socket','register','jayson/promise','client','http','then','info','WhatsappMessage,\x20%s,\x20%s','WhatsappMessage,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','catch','sendStatus','end','status','json','offset','limit','set','Content-Range','reject','update','name','send','index','map','WhatsappMessage','rawAttributes','fieldName','type','key','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','count','include','findAll','rows','show','keys','find','create','body','params','describe','whatsapp-interactions','accept','format','YYYY-MM-DD\x20HH:mm:ss','UserId','CmContact','Contact','get','WhatsappInteraction','WhatsappInteractionId','read1stAt','interaction','user','null','acceptMessage','manual','SIP/%s','channel','EventManager','acceptmessage','whatsapp','agent','[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','rejectMessage','event','rejectmessage','WhatsappAccount','WhatsappAccountId','debug','inspect','twilio','MessageSid','messageId','MessageStatus','read','WhatsappAccount,\x20%s,\x20%s,\x20%s','html-pdf','rimraf','fast-json-patch','moment','bluebird','mustache','path','to-csv','lodash','crypto','jsforce','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults'];(function(_0xdca4a6,_0x4965f6){var _0x5c5b95=function(_0x2c8fe7){while(--_0x2c8fe7){_0xdca4a6['push'](_0xdca4a6['shift']());}};_0x5c5b95(++_0x4965f6);}(_0xf34f,0x64));var _0xff34=function(_0x44f29a,_0x4546e2){_0x44f29a=_0x44f29a-0x0;var _0x22075c=_0xf34f[_0x44f29a];return _0x22075c;};'use strict';var pdf=require(_0xff34('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xff34('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xff34('0x2'));var rp=require('request-promise');var moment=require(_0xff34('0x3'));var BPromise=require(_0xff34('0x4'));var Mustache=require(_0xff34('0x5'));var util=require('util');var path=require(_0xff34('0x6'));var sox=require('sox');var csv=require(_0xff34('0x7'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xff34('0x8'));var squel=require('squel');var crypto=require(_0xff34('0x9'));var jsforce=require(_0xff34('0xa'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xff34('0xb'));var Papa=require(_0xff34('0xc'));var Redis=require(_0xff34('0xd'));var authService=require('../../components/auth/service');var qs=require(_0xff34('0xe'));var as=require(_0xff34('0xf'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xff34('0x10'))(_0xff34('0x11'));var utils=require(_0xff34('0x12'));var config=require('../../config/environment');var licenseUtil=require(_0xff34('0x13'));var db=require(_0xff34('0x14'))['db'];config[_0xff34('0x15')]=_[_0xff34('0x16')](config[_0xff34('0x15')],{'host':_0xff34('0x17'),'port':0x18eb});var socket=require(_0xff34('0x18'))(new Redis(config[_0xff34('0x15')]));require(_0xff34('0x19'))[_0xff34('0x1a')](socket);var jayson=require(_0xff34('0x1b'));var client=jayson[_0xff34('0x1c')][_0xff34('0x1d')]({'port':0x232c});var client9002=jayson[_0xff34('0x1c')][_0xff34('0x1d')]({'port':0x232a});function respondWithRpcPromise(_0x11aac2,_0x23023f,_0x3b7af5,_0x31fdfd){return new BPromise(function(_0xf5e0ec,_0x5be354){var _0x95a2b0=_0x31fdfd||client;return _0x95a2b0['request'](_0x11aac2,_0x3b7af5)[_0xff34('0x1e')](function(_0x50bfa5){logger[_0xff34('0x1f')](_0xff34('0x20'),_0x23023f,'request\x20sent');logger['debug'](_0xff34('0x21'),_0x23023f,_0xff34('0x22'),JSON[_0xff34('0x23')](_0x50bfa5));if(_0x50bfa5[_0xff34('0x24')]){if(_0x50bfa5[_0xff34('0x24')][_0xff34('0x25')]===0x1f4){logger[_0xff34('0x24')](_0xff34('0x20'),_0x23023f,_0x50bfa5[_0xff34('0x24')][_0xff34('0x26')]);return _0x5be354(_0x50bfa5[_0xff34('0x24')][_0xff34('0x26')]);}logger[_0xff34('0x24')](_0xff34('0x20'),_0x23023f,_0x50bfa5[_0xff34('0x24')][_0xff34('0x26')]);return _0xf5e0ec(_0x50bfa5[_0xff34('0x24')][_0xff34('0x26')]);}else{logger[_0xff34('0x1f')](_0xff34('0x20'),_0x23023f,_0xff34('0x22'));_0xf5e0ec(_0x50bfa5['result'][_0xff34('0x26')]);}})[_0xff34('0x27')](function(_0x66df01){logger[_0xff34('0x24')](_0xff34('0x20'),_0x23023f,_0x66df01);_0x5be354(_0x66df01);});});}function respondWithStatusCode(_0x5dd28d,_0x4ee376){_0x4ee376=_0x4ee376||0xcc;return function(_0x293170){if(_0x293170){return _0x5dd28d[_0xff34('0x28')](_0x4ee376);}return _0x5dd28d['status'](_0x4ee376)[_0xff34('0x29')]();};}function respondWithResult(_0x119c88,_0x206dc3){_0x206dc3=_0x206dc3||0xc8;return function(_0x4c2c42){if(_0x4c2c42){return _0x119c88[_0xff34('0x2a')](_0x206dc3)[_0xff34('0x2b')](_0x4c2c42);}};}function respondWithFilteredResult(_0x3939fa,_0x2b28f8){return function(_0x1038bc){if(_0x1038bc){var _0x5c1e72=_0x1038bc['count'],_0x3ddd8a=_0x2b28f8[_0xff34('0x2c')],_0xd18630=_0x2b28f8[_0xff34('0x2c')]+_0x2b28f8[_0xff34('0x2d')],_0x19b2c3;if(_0xd18630>=_0x5c1e72){_0xd18630=_0x5c1e72;_0x19b2c3=0xc8;}else{_0x19b2c3=0xce;}_0x3939fa[_0xff34('0x2a')](_0x19b2c3);return _0x3939fa[_0xff34('0x2e')](_0xff34('0x2f'),_0x3ddd8a+'-'+_0xd18630+'/'+_0x5c1e72)['json'](_0x1038bc);}return null;};}function patchUpdates(_0x4a04bf){return function(_0x215b70){try{jsonpatch['apply'](_0x215b70,_0x4a04bf,!![]);}catch(_0x137d47){return BPromise[_0xff34('0x30')](_0x137d47);}return _0x215b70['save']();};}function saveUpdates(_0x4d2f87,_0x3eed88){return function(_0x3b3381){if(_0x3b3381){return _0x3b3381[_0xff34('0x31')](_0x4d2f87)[_0xff34('0x1e')](function(_0x32b445){return _0x32b445;});}return null;};}function removeEntity(_0xe431e1,_0x4634f4){return function(_0x283087){if(_0x283087){return _0x283087['destroy']()[_0xff34('0x1e')](function(){_0xe431e1['status'](0xcc)[_0xff34('0x29')]();});}};}function handleEntityNotFound(_0x34f9ae,_0x4ff1c1){return function(_0x4f9eab){if(!_0x4f9eab){_0x34f9ae[_0xff34('0x28')](0x194);}return _0x4f9eab;};}function handleError(_0x258b7a,_0x13abaa){_0x13abaa=_0x13abaa||0x1f4;return function(_0x333a05){logger[_0xff34('0x24')](_0x333a05['stack']);if(_0x333a05[_0xff34('0x32')]){delete _0x333a05[_0xff34('0x32')];}_0x258b7a['status'](_0x13abaa)[_0xff34('0x33')](_0x333a05);};}exports[_0xff34('0x34')]=function(_0x54907b,_0x45bf6d){var _0x5eec0d={},_0x1c0df9={},_0x1bf3ed={'count':0x0,'rows':[]};var _0x574787=_[_0xff34('0x35')](db[_0xff34('0x36')][_0xff34('0x37')],function(_0x1c1f69){return{'name':_0x1c1f69[_0xff34('0x38')],'type':_0x1c1f69[_0xff34('0x39')][_0xff34('0x3a')]};});_0x1c0df9['model']=_['map'](_0x574787,_0xff34('0x32'));_0x1c0df9[_0xff34('0x3b')]=_['keys'](_0x54907b[_0xff34('0x3b')]);_0x1c0df9[_0xff34('0x3c')]=_[_0xff34('0x3d')](_0x1c0df9[_0xff34('0x3e')],_0x1c0df9[_0xff34('0x3b')]);_0x5eec0d[_0xff34('0x3f')]=_[_0xff34('0x3d')](_0x1c0df9[_0xff34('0x3e')],qs[_0xff34('0x40')](_0x54907b[_0xff34('0x3b')][_0xff34('0x40')]));_0x5eec0d[_0xff34('0x3f')]=_0x5eec0d[_0xff34('0x3f')][_0xff34('0x41')]?_0x5eec0d[_0xff34('0x3f')]:_0x1c0df9[_0xff34('0x3e')];if(!_0x54907b['query'][_0xff34('0x42')](_0xff34('0x43'))){_0x5eec0d['limit']=qs[_0xff34('0x2d')](_0x54907b[_0xff34('0x3b')][_0xff34('0x2d')]);_0x5eec0d[_0xff34('0x2c')]=qs[_0xff34('0x2c')](_0x54907b['query']['offset']);}_0x5eec0d[_0xff34('0x44')]=qs[_0xff34('0x45')](_0x54907b['query'][_0xff34('0x45')]);_0x5eec0d[_0xff34('0x46')]=qs[_0xff34('0x3c')](_[_0xff34('0x47')](_0x54907b[_0xff34('0x3b')],_0x1c0df9['filters']),_0x574787);if(_0x54907b['query'][_0xff34('0x48')]){_0x5eec0d['where']=_[_0xff34('0x49')](_0x5eec0d['where'],{'$or':_[_0xff34('0x35')](_0x574787,function(_0x5696e8){if(_0x5696e8[_0xff34('0x39')]!=='VIRTUAL'){var _0x1078da={};_0x1078da[_0x5696e8[_0xff34('0x32')]]={'$like':'%'+_0x54907b['query'][_0xff34('0x48')]+'%'};return _0x1078da;}})});}_0x5eec0d=_[_0xff34('0x49')]({},_0x5eec0d,_0x54907b[_0xff34('0x4a')]);var _0x391058={'where':_0x5eec0d[_0xff34('0x46')]};return db[_0xff34('0x36')][_0xff34('0x4b')](_0x391058)['then'](function(_0x326498){_0x1bf3ed['count']=_0x326498;if(_0x54907b['query']['includeAll']){_0x5eec0d[_0xff34('0x4c')]=[{'all':!![]}];}return db['WhatsappMessage'][_0xff34('0x4d')](_0x5eec0d);})[_0xff34('0x1e')](function(_0x3c4fa6){_0x1bf3ed[_0xff34('0x4e')]=_0x3c4fa6;return _0x1bf3ed;})['then'](respondWithFilteredResult(_0x45bf6d,_0x5eec0d))['catch'](handleError(_0x45bf6d,null));};exports[_0xff34('0x4f')]=function(_0x492a60,_0x14d5ae){var _0x5d6d21={'raw':!![],'where':{'id':_0x492a60['params']['id']}},_0x4e77d9={};_0x4e77d9[_0xff34('0x3e')]=_[_0xff34('0x50')](db[_0xff34('0x36')]['rawAttributes']);_0x4e77d9[_0xff34('0x3b')]=_['keys'](_0x492a60[_0xff34('0x3b')]);_0x4e77d9['filters']=_[_0xff34('0x3d')](_0x4e77d9[_0xff34('0x3e')],_0x4e77d9[_0xff34('0x3b')]);_0x5d6d21['attributes']=_[_0xff34('0x3d')](_0x4e77d9['model'],qs[_0xff34('0x40')](_0x492a60[_0xff34('0x3b')]['fields']));_0x5d6d21[_0xff34('0x3f')]=_0x5d6d21[_0xff34('0x3f')][_0xff34('0x41')]?_0x5d6d21['attributes']:_0x4e77d9[_0xff34('0x3e')];if(_0x492a60[_0xff34('0x3b')]['includeAll']){_0x5d6d21[_0xff34('0x4c')]=[{'all':!![]}];}_0x5d6d21=_[_0xff34('0x49')]({},_0x5d6d21,_0x492a60[_0xff34('0x4a')]);return db['WhatsappMessage'][_0xff34('0x51')](_0x5d6d21)['then'](handleEntityNotFound(_0x14d5ae,null))[_0xff34('0x1e')](respondWithResult(_0x14d5ae,null))[_0xff34('0x27')](handleError(_0x14d5ae,null));};exports[_0xff34('0x52')]=function(_0x23f474,_0x56872f){return db[_0xff34('0x36')][_0xff34('0x52')](_0x23f474[_0xff34('0x53')],{})[_0xff34('0x1e')](respondWithResult(_0x56872f,0xc9))['catch'](handleError(_0x56872f,null));};exports[_0xff34('0x31')]=function(_0x1e3e1e,_0x2e65e2){if(_0x1e3e1e['body']['id']){delete _0x1e3e1e['body']['id'];}return db['WhatsappMessage'][_0xff34('0x51')]({'where':{'id':_0x1e3e1e['params']['id']}})['then'](handleEntityNotFound(_0x2e65e2,null))[_0xff34('0x1e')](saveUpdates(_0x1e3e1e[_0xff34('0x53')],null))[_0xff34('0x1e')](respondWithResult(_0x2e65e2,null))[_0xff34('0x27')](handleError(_0x2e65e2,null));};exports['destroy']=function(_0x3267a6,_0x301843){return db['WhatsappMessage'][_0xff34('0x51')]({'where':{'id':_0x3267a6[_0xff34('0x54')]['id']}})[_0xff34('0x1e')](handleEntityNotFound(_0x301843,null))[_0xff34('0x1e')](removeEntity(_0x301843,null))[_0xff34('0x27')](handleError(_0x301843,null));};exports[_0xff34('0x55')]=function(_0x1cf8f9,_0xc8231b){return db[_0xff34('0x36')][_0xff34('0x55')]()[_0xff34('0x1e')](respondWithResult(_0xc8231b,null))[_0xff34('0x27')](handleError(_0xc8231b,null));};var interaction_log=require(_0xff34('0x10'))(_0xff34('0x56'));exports[_0xff34('0x57')]=function(_0x134dd3,_0x3d782a,_0x562f88){var _0x7a92db={'agent':{},'channel':'whatsapp'};if(_0x134dd3['body']['id']){delete _0x134dd3[_0xff34('0x53')]['id'];}_0x134dd3[_0xff34('0x53')]['read']=!![];_0x134dd3['body']['readAt']=moment()[_0xff34('0x58')](_0xff34('0x59'));_0x134dd3[_0xff34('0x53')][_0xff34('0x5a')]=_0x134dd3['body'][_0xff34('0x5a')]||_0x134dd3['user']['id'];_0x7a92db['agent']['id']=_0x134dd3['body'][_0xff34('0x5a')];return db['WhatsappMessage'][_0xff34('0x51')]({'where':{'id':_0x134dd3[_0xff34('0x54')]['id'],'UserId':null},'include':[{'model':db[_0xff34('0x5b')],'as':_0xff34('0x5c')}]})[_0xff34('0x1e')](handleEntityNotFound(_0x3d782a,null))[_0xff34('0x1e')](saveUpdates(_0x134dd3['body'],null))[_0xff34('0x1e')](function(_0x3aa696){if(_0x3aa696){_0x7a92db[_0xff34('0x26')]=_0x3aa696[_0xff34('0x5d')]({'plain':!![]});return db[_0xff34('0x5e')]['find']({'where':{'id':_0x3aa696[_0xff34('0x5f')]}});}return null;})[_0xff34('0x1e')](handleEntityNotFound(_0x3d782a,null))[_0xff34('0x1e')](function(_0x50b11f){if(_0x50b11f){return _0x50b11f[_0xff34('0x31')]({'UserId':_0x134dd3[_0xff34('0x53')][_0xff34('0x5a')],'read1stAt':_['isNil'](_0x50b11f[_0xff34('0x60')])?moment()[_0xff34('0x58')](_0xff34('0x59')):undefined});}return null;})[_0xff34('0x1e')](function(_0x55217c){if(_0x55217c){_0x7a92db[_0xff34('0x61')]=_0x55217c[_0xff34('0x5d')]({'plain':!![]});interaction_log[_0xff34('0x1f')]('[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x134dd3[_0xff34('0x62')]['id'],_0x134dd3[_0xff34('0x62')][_0xff34('0x32')],_0x134dd3[_0xff34('0x62')]['role'],_0x7a92db[_0xff34('0x61')]['id'],_0x134dd3[_0xff34('0x53')]?JSON[_0xff34('0x23')](_0x134dd3['body']):_0xff34('0x63'));return respondWithRpcPromise('AcceptMessage',_0xff34('0x64'),_0x7a92db);}return null;})[_0xff34('0x1e')](function(_0x598900){if(_0x598900){if(_0x134dd3[_0xff34('0x53')][_0xff34('0x65')]){_0x7a92db[_0xff34('0x26')]['interface']=util[_0xff34('0x58')](_0xff34('0x66'),_0x134dd3[_0xff34('0x62')][_0xff34('0x32')]);_0x7a92db[_0xff34('0x26')][_0xff34('0x67')]=_0x7a92db[_0xff34('0x67')];_0x7a92db['message']['event']=_0xff34('0x57');return respondWithRpcPromise(_0xff34('0x68'),_0xff34('0x68'),{'event':_0xff34('0x69'),'message':_0x7a92db[_0xff34('0x26')]},client9002)[_0xff34('0x1e')](function(){return _0x7a92db;});}return _0x7a92db;}return null;})[_0xff34('0x1e')](respondWithResult(_0x3d782a,null))[_0xff34('0x27')](handleError(_0x3d782a,null));};var interaction_log=require(_0xff34('0x10'))('whatsapp-interactions');exports[_0xff34('0x30')]=function(_0x245676,_0x1d89dd,_0x3755f7){var _0x25aab9={'agent':{},'channel':_0xff34('0x6a')};if(_0x245676[_0xff34('0x53')]['id']){delete _0x245676[_0xff34('0x53')]['id'];}_0x245676[_0xff34('0x53')]['UserId']=_0x245676[_0xff34('0x53')][_0xff34('0x5a')]||_0x245676['user']['id'];_0x25aab9[_0xff34('0x6b')]['id']=_0x245676[_0xff34('0x53')][_0xff34('0x5a')];return db[_0xff34('0x36')]['find']({'where':{'id':_0x245676[_0xff34('0x54')]['id'],'UserId':null}})[_0xff34('0x1e')](handleEntityNotFound(_0x1d89dd,null))['then'](function(_0x575165){if(_0x575165){_0x25aab9[_0xff34('0x26')]=_0x575165[_0xff34('0x5d')]({'plain':!![]});return db['WhatsappInteraction']['find']({'where':{'id':_0x575165[_0xff34('0x5f')]}});}return null;})['then'](handleEntityNotFound(_0x1d89dd,null))[_0xff34('0x1e')](function(_0x49faa3){if(_0x49faa3){_0x25aab9[_0xff34('0x61')]=_0x49faa3['get']({'plain':!![]});interaction_log[_0xff34('0x1f')](_0xff34('0x6c'),_0x245676[_0xff34('0x62')]['id'],_0x245676['user'][_0xff34('0x32')],_0x245676[_0xff34('0x62')][_0xff34('0x6d')],_0x25aab9[_0xff34('0x61')]['id'],_0x245676[_0xff34('0x53')]?JSON['stringify'](_0x245676[_0xff34('0x53')]):_0xff34('0x63'));return respondWithRpcPromise('RejectMessage',_0xff34('0x6e'),_0x25aab9);}return null;})[_0xff34('0x1e')](function(_0x3ebcbf){if(_0x3ebcbf){_0x3ebcbf[_0xff34('0x26')]['interface']=util['format'](_0xff34('0x66'),_0x245676[_0xff34('0x62')][_0xff34('0x32')]);_0x3ebcbf[_0xff34('0x26')][_0xff34('0x67')]=_0x25aab9[_0xff34('0x67')];_0x3ebcbf['message'][_0xff34('0x6f')]=_0xff34('0x30');respondWithRpcPromise(_0xff34('0x68'),_0xff34('0x68'),{'event':_0xff34('0x70'),'message':_0x3ebcbf['message']},client9002);return _0x25aab9;}return null;})[_0xff34('0x1e')](respondWithResult(_0x1d89dd,null))[_0xff34('0x27')](handleError(_0x1d89dd,null));};exports[_0xff34('0x2a')]=function(_0x4aadc8,_0x593a77,_0x405c95){if(_0x4aadc8[_0xff34('0x53')]['id']){delete _0x4aadc8[_0xff34('0x53')]['id'];}var _0x484c52;return db[_0xff34('0x36')]['find']({'where':{'id':_0x4aadc8[_0xff34('0x54')]['id']}})['then'](handleEntityNotFound(_0x593a77,null))['then'](function(_0x3de81b){if(_0x3de81b){_0x484c52=_0x3de81b;return db[_0xff34('0x71')][_0xff34('0x51')]({'where':{'id':_0x3de81b[_0xff34('0x72')]}});}})[_0xff34('0x1e')](handleEntityNotFound(_0x593a77,null))[_0xff34('0x1e')](function(_0x2f6701){if(_0x2f6701){logger[_0xff34('0x73')]('WhatsppMessage,\x20%s,\x20%s,\x20%s',_0xff34('0x2a'),'received\x20delivery\x20report\x20from',_0x2f6701[_0xff34('0x39')],util[_0xff34('0x74')](_0x4aadc8[_0xff34('0x53')],{'showHidden':![],'depth':null}));switch(_0x2f6701[_0xff34('0x39')]){case _0xff34('0x75'):if(_0x4aadc8['body'][_0xff34('0x76')]&&_0x4aadc8[_0xff34('0x53')][_0xff34('0x76')]===_0x484c52[_0xff34('0x77')]&&_0x4aadc8[_0xff34('0x53')][_0xff34('0x78')]&&_0x4aadc8['body'][_0xff34('0x78')]===_0xff34('0x79')){return _0x484c52[_0xff34('0x31')]({'read':!![]});}else{logger[_0xff34('0x24')](_0xff34('0x7a'),_0xff34('0x2a'),_0xff34('0x75'),util[_0xff34('0x74')](_0x4aadc8[_0xff34('0x53')],{'showHidden':![],'depth':null}));}break;}return _0x484c52;}})[_0xff34('0x1e')](respondWithResult(_0x593a77,null))[_0xff34('0x27')](handleError(_0x593a77,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