Built motion from commit 994c64e1.|2.6.1
[motion2.git] / server / api / whatsappAccount / whatsappAccount.controller.js
index a00ce02..bc5c616 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xedf8=['options','count','includeAll','rows','show','include','find','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','autoAssociation','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','addDisposition','WhatsappAccountId','Disposition','order','removeDispositions','ids','addAnswer','getAnswers','findOne','CannedAnswer','findAll','removeAnswers','addAgents','spread','emit','userWhatsappAccount:save','removeAgents','isArray','userWhatsappAccount:remove','getAgents','addApplications','sequelize','WhatsappApplication','bulkCreate','priority','getApplications','whatsapp','Applications','account','applications','orderBy','asc','CmContact','Sequelize','ValidationError','difference','createdAt','updatedAt','CompanyId','ListId','mobile','twilio','from','From','replace','whatsapp:','Body','messageId','isNil','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','CmList','Contacts','DESC','list','omit','WhatsappInteraction','interaction','autoclose','push','close','created','WhatsappMessage','ContactId','AttachmentId','UserId','unshift','agent','waitForTheAssignedAgent','Start','startRouting','receiveMessage','entity\x20found','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','to\x20is\x20mandatory','List','user','out','dataValues','Messages','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','./whatsappAccount.socket','register','jayson/promise','client','request','WhatsappAccount,\x20%s,\x20%s','request\x20sent','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','catch','end','status','offset','limit','set','Content-Range','json','apply','update','then','destroy','get','WhatsappAccounts','UserProfileResource','sendStatus','stack','name','send','index','Pause','mandatoryDispositionPause','map','WhatsappAccount','rawAttributes','type','model','keys','filters','intersection','query','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge'];(function(_0x57f77b,_0x58d894){var _0x13fa8c=function(_0x2d6439){while(--_0x2d6439){_0x57f77b['push'](_0x57f77b['shift']());}};_0x13fa8c(++_0x58d894);}(_0xedf8,0x121));var _0x8edf=function(_0x1c18e8,_0x5124ef){_0x1c18e8=_0x1c18e8-0x0;var _0x83edae=_0xedf8[_0x1c18e8];return _0x83edae;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x8edf('0x0'));var rimraf=require(_0x8edf('0x1'));var zipdir=require(_0x8edf('0x2'));var jsonpatch=require(_0x8edf('0x3'));var rp=require(_0x8edf('0x4'));var moment=require(_0x8edf('0x5'));var BPromise=require(_0x8edf('0x6'));var Mustache=require(_0x8edf('0x7'));var util=require(_0x8edf('0x8'));var path=require('path');var sox=require(_0x8edf('0x9'));var csv=require(_0x8edf('0xa'));var ejs=require(_0x8edf('0xb'));var fs=require('fs');var _=require(_0x8edf('0xc'));var squel=require(_0x8edf('0xd'));var crypto=require(_0x8edf('0xe'));var jsforce=require(_0x8edf('0xf'));var deskjs=require(_0x8edf('0x10'));var toCsv=require(_0x8edf('0xa'));var querystring=require(_0x8edf('0x11'));var Papa=require(_0x8edf('0x12'));var Redis=require(_0x8edf('0x13'));var authService=require(_0x8edf('0x14'));var qs=require('../../components/parsers/qs');var as=require(_0x8edf('0x15'));var hardwareService=require(_0x8edf('0x16'));var logger=require(_0x8edf('0x17'))(_0x8edf('0x18'));var utils=require(_0x8edf('0x19'));var config=require(_0x8edf('0x1a'));var licenseUtil=require(_0x8edf('0x1b'));var db=require(_0x8edf('0x1c'))['db'];config[_0x8edf('0x1d')]=_[_0x8edf('0x1e')](config[_0x8edf('0x1d')],{'host':_0x8edf('0x1f'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x8edf('0x1d')]));require(_0x8edf('0x20'))[_0x8edf('0x21')](socket);var jayson=require(_0x8edf('0x22'));var client=jayson[_0x8edf('0x23')]['http']({'port':0x232c});function respondWithRpcPromise(_0x506b4a,_0x8cb633,_0x46dee9,_0x551170){return new BPromise(function(_0x48c2a4,_0x3689a8){var _0x41a2ef=_0x551170||client;return _0x41a2ef[_0x8edf('0x24')](_0x506b4a,_0x46dee9)['then'](function(_0x182485){logger['info'](_0x8edf('0x25'),_0x8cb633,_0x8edf('0x26'));logger['debug'](_0x8edf('0x27'),_0x8cb633,_0x8edf('0x26'),JSON[_0x8edf('0x28')](_0x182485));if(_0x182485[_0x8edf('0x29')]){if(_0x182485[_0x8edf('0x29')][_0x8edf('0x2a')]===0x1f4){logger[_0x8edf('0x29')](_0x8edf('0x25'),_0x8cb633,_0x182485[_0x8edf('0x29')][_0x8edf('0x2b')]);return _0x3689a8(_0x182485['error'][_0x8edf('0x2b')]);}logger['error'](_0x8edf('0x25'),_0x8cb633,_0x182485[_0x8edf('0x29')][_0x8edf('0x2b')]);return _0x48c2a4(_0x182485[_0x8edf('0x29')]['message']);}else{logger[_0x8edf('0x2c')](_0x8edf('0x25'),_0x8cb633,'request\x20sent');_0x48c2a4(_0x182485[_0x8edf('0x2d')][_0x8edf('0x2b')]);}})[_0x8edf('0x2e')](function(_0x450ad7){logger[_0x8edf('0x29')](_0x8edf('0x25'),_0x8cb633,_0x450ad7);_0x3689a8(_0x450ad7);});});}function respondWithStatusCode(_0x302dad,_0x446cff){_0x446cff=_0x446cff||0xcc;return function(_0xb8e9d4){if(_0xb8e9d4){return _0x302dad['sendStatus'](_0x446cff);}return _0x302dad['status'](_0x446cff)[_0x8edf('0x2f')]();};}function respondWithResult(_0x526f56,_0x131762){_0x131762=_0x131762||0xc8;return function(_0x2d736b){if(_0x2d736b){return _0x526f56[_0x8edf('0x30')](_0x131762)['json'](_0x2d736b);}};}function respondWithFilteredResult(_0x1c04ed,_0x2b5b4d){return function(_0x62adab){if(_0x62adab){var _0x483ab9=_0x62adab['count'],_0x11f4cd=_0x2b5b4d[_0x8edf('0x31')],_0x21a1d6=_0x2b5b4d[_0x8edf('0x31')]+_0x2b5b4d[_0x8edf('0x32')],_0x2f0939;if(_0x21a1d6>=_0x483ab9){_0x21a1d6=_0x483ab9;_0x2f0939=0xc8;}else{_0x2f0939=0xce;}_0x1c04ed[_0x8edf('0x30')](_0x2f0939);return _0x1c04ed[_0x8edf('0x33')](_0x8edf('0x34'),_0x11f4cd+'-'+_0x21a1d6+'/'+_0x483ab9)[_0x8edf('0x35')](_0x62adab);}return null;};}function patchUpdates(_0x3d6cb5){return function(_0x56ff75){try{jsonpatch[_0x8edf('0x36')](_0x56ff75,_0x3d6cb5,!![]);}catch(_0x43e59e){return BPromise['reject'](_0x43e59e);}return _0x56ff75['save']();};}function saveUpdates(_0x307147,_0x503cc){return function(_0x844d06){if(_0x844d06){return _0x844d06[_0x8edf('0x37')](_0x307147)[_0x8edf('0x38')](function(_0x18c23e){return _0x18c23e;});}return null;};}function removeEntity(_0x1a55b7,_0x5e97bb){return function(_0x22bff6){if(_0x22bff6){return _0x22bff6[_0x8edf('0x39')]()[_0x8edf('0x38')](function(){var _0x4ab98a=_0x22bff6[_0x8edf('0x3a')]({'plain':!![]});var _0x36d3ca=_0x8edf('0x3b');return db[_0x8edf('0x3c')]['destroy']({'where':{'type':_0x36d3ca,'resourceId':_0x4ab98a['id']}})['then'](function(){return _0x22bff6;});})[_0x8edf('0x38')](function(){_0x1a55b7[_0x8edf('0x30')](0xcc)[_0x8edf('0x2f')]();});}};}function handleEntityNotFound(_0x364eac,_0x2df8e4){return function(_0x256b48){if(!_0x256b48){_0x364eac[_0x8edf('0x3d')](0x194);}return _0x256b48;};}function handleError(_0x479d7d,_0x3e2641){_0x3e2641=_0x3e2641||0x1f4;return function(_0x355e94){logger[_0x8edf('0x29')](_0x355e94[_0x8edf('0x3e')]);if(_0x355e94[_0x8edf('0x3f')]){delete _0x355e94['name'];}_0x479d7d['status'](_0x3e2641)[_0x8edf('0x40')](_0x355e94);};}exports[_0x8edf('0x41')]=function(_0x185752,_0x3aa7a7){var _0x381833={'include':[{'model':db[_0x8edf('0x42')],'as':_0x8edf('0x43')}]},_0xfec929={},_0x2f1035={'count':0x0,'rows':[]};var _0x4f0565=_[_0x8edf('0x44')](db[_0x8edf('0x45')][_0x8edf('0x46')],function(_0x50671e){return{'name':_0x50671e['fieldName'],'type':_0x50671e[_0x8edf('0x47')]['key']};});_0xfec929[_0x8edf('0x48')]=_['map'](_0x4f0565,'name');_0xfec929['query']=_[_0x8edf('0x49')](_0x185752['query']);_0xfec929[_0x8edf('0x4a')]=_[_0x8edf('0x4b')](_0xfec929['model'],_0xfec929[_0x8edf('0x4c')]);_0x381833[_0x8edf('0x4d')]=_[_0x8edf('0x4b')](_0xfec929[_0x8edf('0x48')],qs[_0x8edf('0x4e')](_0x185752['query'][_0x8edf('0x4e')]));_0x381833[_0x8edf('0x4d')]=_0x381833['attributes'][_0x8edf('0x4f')]?_0x381833['attributes']:_0xfec929[_0x8edf('0x48')];if(!_0x185752['query'][_0x8edf('0x50')](_0x8edf('0x51'))){_0x381833['limit']=qs[_0x8edf('0x32')](_0x185752[_0x8edf('0x4c')][_0x8edf('0x32')]);_0x381833['offset']=qs[_0x8edf('0x31')](_0x185752[_0x8edf('0x4c')][_0x8edf('0x31')]);}_0x381833['order']=qs[_0x8edf('0x52')](_0x185752[_0x8edf('0x4c')][_0x8edf('0x52')]);_0x381833[_0x8edf('0x53')]=qs[_0x8edf('0x4a')](_[_0x8edf('0x54')](_0x185752[_0x8edf('0x4c')],_0xfec929['filters']),_0x4f0565);if(_0x185752[_0x8edf('0x4c')][_0x8edf('0x55')]){_0x381833['where']=_[_0x8edf('0x56')](_0x381833[_0x8edf('0x53')],{'$or':_[_0x8edf('0x44')](_0x4f0565,function(_0x225e2e){if(_0x225e2e[_0x8edf('0x47')]!=='VIRTUAL'){var _0x1e2d04={};_0x1e2d04[_0x225e2e['name']]={'$like':'%'+_0x185752[_0x8edf('0x4c')][_0x8edf('0x55')]+'%'};return _0x1e2d04;}})});}_0x381833=_['merge']({},_0x381833,_0x185752[_0x8edf('0x57')]);var _0x5f5aff={'where':_0x381833['where']};return db[_0x8edf('0x45')][_0x8edf('0x58')](_0x5f5aff)[_0x8edf('0x38')](function(_0x2943d0){_0x2f1035[_0x8edf('0x58')]=_0x2943d0;if(_0x185752[_0x8edf('0x4c')][_0x8edf('0x59')]){_0x381833['include']=[{'all':!![]}];}return db['WhatsappAccount']['findAll'](_0x381833);})[_0x8edf('0x38')](function(_0x456c0d){_0x2f1035[_0x8edf('0x5a')]=_0x456c0d;return _0x2f1035;})[_0x8edf('0x38')](respondWithFilteredResult(_0x3aa7a7,_0x381833))[_0x8edf('0x2e')](handleError(_0x3aa7a7,null));};exports[_0x8edf('0x5b')]=function(_0x91f395,_0x1d2d23){var _0x3e4abd={'raw':![],'where':{'id':_0x91f395['params']['id']},'include':[{'model':db['Pause'],'as':_0x8edf('0x43')}]},_0x3f5c4={};_0x3f5c4[_0x8edf('0x48')]=_[_0x8edf('0x49')](db[_0x8edf('0x45')]['rawAttributes']);_0x3f5c4[_0x8edf('0x4c')]=_[_0x8edf('0x49')](_0x91f395['query']);_0x3f5c4[_0x8edf('0x4a')]=_[_0x8edf('0x4b')](_0x3f5c4[_0x8edf('0x48')],_0x3f5c4[_0x8edf('0x4c')]);_0x3e4abd['attributes']=_[_0x8edf('0x4b')](_0x3f5c4['model'],qs[_0x8edf('0x4e')](_0x91f395[_0x8edf('0x4c')][_0x8edf('0x4e')]));_0x3e4abd[_0x8edf('0x4d')]=_0x3e4abd[_0x8edf('0x4d')][_0x8edf('0x4f')]?_0x3e4abd[_0x8edf('0x4d')]:_0x3f5c4[_0x8edf('0x48')];if(_0x91f395[_0x8edf('0x4c')][_0x8edf('0x59')]){_0x3e4abd[_0x8edf('0x5c')]=[{'all':!![]}];}_0x3e4abd=_[_0x8edf('0x56')]({},_0x3e4abd,_0x91f395[_0x8edf('0x57')]);return db['WhatsappAccount'][_0x8edf('0x5d')](_0x3e4abd)['then'](handleEntityNotFound(_0x1d2d23,null))[_0x8edf('0x38')](respondWithResult(_0x1d2d23,null))[_0x8edf('0x2e')](handleError(_0x1d2d23,null));};exports['create']=function(_0x9ba9e7,_0x46b063){return db['WhatsappAccount']['create'](_0x9ba9e7[_0x8edf('0x5e')],{})[_0x8edf('0x38')](function(_0x3784e0){var _0x1709cf=_0x9ba9e7['user'][_0x8edf('0x3a')]({'plain':!![]});if(!_0x1709cf)throw new Error(_0x8edf('0x5f'));if(_0x1709cf['role']==='user'){var _0x4f42eb=_0x3784e0[_0x8edf('0x3a')]({'plain':!![]});var _0x513fd0='WhatsappAccounts';return db[_0x8edf('0x60')][_0x8edf('0x5d')]({'where':{'name':_0x513fd0,'userProfileId':_0x1709cf[_0x8edf('0x61')]},'raw':!![]})[_0x8edf('0x38')](function(_0x358ae7){if(_0x358ae7&&_0x358ae7[_0x8edf('0x62')]===0x0){return db[_0x8edf('0x3c')][_0x8edf('0x63')]({'name':_0x4f42eb[_0x8edf('0x3f')],'resourceId':_0x4f42eb['id'],'type':_0x358ae7[_0x8edf('0x3f')],'sectionId':_0x358ae7['id']},{})[_0x8edf('0x38')](function(){return _0x3784e0;});}else{return _0x3784e0;}})[_0x8edf('0x2e')](function(_0x5d165d){logger[_0x8edf('0x29')](_0x8edf('0x64'),_0x5d165d);throw _0x5d165d;});}return _0x3784e0;})[_0x8edf('0x38')](respondWithResult(_0x46b063,0xc9))[_0x8edf('0x2e')](handleError(_0x46b063,null));};exports['update']=function(_0x275060,_0x2faf1e){if(_0x275060['body']['id']){delete _0x275060[_0x8edf('0x5e')]['id'];}return db[_0x8edf('0x45')][_0x8edf('0x5d')]({'where':{'id':_0x275060['params']['id']},'include':[{'model':db['Pause'],'as':_0x8edf('0x43')}]})[_0x8edf('0x38')](handleEntityNotFound(_0x2faf1e,null))[_0x8edf('0x38')](saveUpdates(_0x275060['body'],null))[_0x8edf('0x38')](respondWithResult(_0x2faf1e,null))[_0x8edf('0x2e')](handleError(_0x2faf1e,null));};exports[_0x8edf('0x39')]=function(_0x20a700,_0x1ec5c2){return db[_0x8edf('0x45')][_0x8edf('0x5d')]({'where':{'id':_0x20a700[_0x8edf('0x65')]['id']}})[_0x8edf('0x38')](handleEntityNotFound(_0x1ec5c2,null))[_0x8edf('0x38')](removeEntity(_0x1ec5c2,null))[_0x8edf('0x2e')](handleError(_0x1ec5c2,null));};exports[_0x8edf('0x66')]=function(_0x2dbd8b,_0x151e3c){return db[_0x8edf('0x45')][_0x8edf('0x66')]()[_0x8edf('0x38')](respondWithResult(_0x151e3c,null))[_0x8edf('0x2e')](handleError(_0x151e3c,null));};exports[_0x8edf('0x67')]=function(_0x3ac716,_0x46751b,_0x4f2b99){if(_0x3ac716[_0x8edf('0x5e')]['id']){delete _0x3ac716[_0x8edf('0x5e')]['id'];}return db[_0x8edf('0x45')]['find']({'where':{'id':_0x3ac716[_0x8edf('0x65')]['id']}})['then'](handleEntityNotFound(_0x46751b,null))[_0x8edf('0x38')](function(_0x51ea9d){if(_0x51ea9d){_0x3ac716['body'][_0x8edf('0x68')]=_0x51ea9d['id'];return db[_0x8edf('0x69')][_0x8edf('0x63')](_0x3ac716[_0x8edf('0x5e')]);}})[_0x8edf('0x38')](respondWithResult(_0x46751b,null))[_0x8edf('0x2e')](handleError(_0x46751b,null));};exports['getDispositions']=function(_0x2694ed,_0x4cd5ba,_0x180efa){var _0x1cc955={'raw':![],'where':{}};var _0x221509={};var _0x4d1e2d={'count':0x0,'rows':[]};return db[_0x8edf('0x45')]['findOne']({'where':{'id':_0x2694ed['params']['id']}})[_0x8edf('0x38')](handleEntityNotFound(_0x4cd5ba,null))[_0x8edf('0x38')](function(_0x4ce646){if(_0x4ce646){_0x221509['model']=_['keys'](db[_0x8edf('0x69')][_0x8edf('0x46')]);_0x221509[_0x8edf('0x4c')]=_[_0x8edf('0x49')](_0x2694ed[_0x8edf('0x4c')]);_0x221509[_0x8edf('0x4a')]=_['intersection'](_0x221509['model'],_0x221509[_0x8edf('0x4c')]);_0x1cc955[_0x8edf('0x4d')]=_['intersection'](_0x221509[_0x8edf('0x48')],qs['fields'](_0x2694ed[_0x8edf('0x4c')][_0x8edf('0x4e')]));_0x1cc955[_0x8edf('0x4d')]=_0x1cc955[_0x8edf('0x4d')][_0x8edf('0x4f')]?_0x1cc955[_0x8edf('0x4d')]:_0x221509['model'];if(!_0x2694ed[_0x8edf('0x4c')][_0x8edf('0x50')](_0x8edf('0x51'))){_0x1cc955[_0x8edf('0x32')]=qs[_0x8edf('0x32')](_0x2694ed[_0x8edf('0x4c')][_0x8edf('0x32')]);_0x1cc955[_0x8edf('0x31')]=qs[_0x8edf('0x31')](_0x2694ed['query'][_0x8edf('0x31')]);}_0x1cc955[_0x8edf('0x6a')]=qs['sort'](_0x2694ed[_0x8edf('0x4c')][_0x8edf('0x52')]);_0x1cc955[_0x8edf('0x53')]=qs[_0x8edf('0x4a')](_[_0x8edf('0x54')](_0x2694ed[_0x8edf('0x4c')],_0x221509[_0x8edf('0x4a')]));_0x1cc955['where']['WhatsappAccountId']=_0x4ce646['id'];if(_0x2694ed[_0x8edf('0x4c')][_0x8edf('0x55')]){_0x1cc955['where']=_[_0x8edf('0x56')](_0x1cc955[_0x8edf('0x53')],{'$or':_[_0x8edf('0x44')](_0x1cc955[_0x8edf('0x4d')],function(_0x482593){var _0x5a872d={};_0x5a872d[_0x482593]={'$like':'%'+_0x2694ed['query'][_0x8edf('0x55')]+'%'};return _0x5a872d;})});}_0x1cc955=_[_0x8edf('0x56')]({},_0x1cc955,_0x2694ed[_0x8edf('0x57')]);return db[_0x8edf('0x69')]['count']({'where':_0x1cc955['where']})['then'](function(_0x1e2025){_0x4d1e2d[_0x8edf('0x58')]=_0x1e2025;if(_0x2694ed['query'][_0x8edf('0x59')]){_0x1cc955[_0x8edf('0x5c')]=[{'all':!![]}];}return db[_0x8edf('0x69')]['findAll'](_0x1cc955);})[_0x8edf('0x38')](function(_0x1fa310){_0x4d1e2d[_0x8edf('0x5a')]=_0x1fa310;return _0x4d1e2d;});}})[_0x8edf('0x38')](respondWithFilteredResult(_0x4cd5ba,_0x1cc955))[_0x8edf('0x2e')](handleError(_0x4cd5ba,null));};exports['removeDispositions']=function(_0x125a38,_0x4f3892,_0x2d32df){return db[_0x8edf('0x45')]['find']({'where':{'id':_0x125a38[_0x8edf('0x65')]['id']}})[_0x8edf('0x38')](handleEntityNotFound(_0x4f3892,null))[_0x8edf('0x38')](function(_0x3aef31){if(_0x3aef31){return _0x3aef31[_0x8edf('0x6b')](_0x125a38[_0x8edf('0x4c')][_0x8edf('0x6c')]);}})[_0x8edf('0x38')](respondWithStatusCode(_0x4f3892,null))[_0x8edf('0x2e')](handleError(_0x4f3892,null));};exports[_0x8edf('0x6d')]=function(_0x222b05,_0x9114ff,_0x38f23e){if(_0x222b05['body']['id']){delete _0x222b05[_0x8edf('0x5e')]['id'];}return db[_0x8edf('0x45')][_0x8edf('0x5d')]({'where':{'id':_0x222b05[_0x8edf('0x65')]['id']}})[_0x8edf('0x38')](handleEntityNotFound(_0x9114ff,null))[_0x8edf('0x38')](function(_0x37da89){if(_0x37da89){_0x222b05[_0x8edf('0x5e')][_0x8edf('0x68')]=_0x37da89['id'];return db['CannedAnswer'][_0x8edf('0x63')](_0x222b05['body']);}})[_0x8edf('0x38')](respondWithResult(_0x9114ff,null))[_0x8edf('0x2e')](handleError(_0x9114ff,null));};exports[_0x8edf('0x6e')]=function(_0x2c9dc4,_0xb29df2,_0x5e563a){var _0x528760={'raw':![],'where':{}};var _0x530c4b={};var _0x9f98dc={'count':0x0,'rows':[]};return db['WhatsappAccount'][_0x8edf('0x6f')]({'where':{'id':_0x2c9dc4['params']['id']}})[_0x8edf('0x38')](handleEntityNotFound(_0xb29df2,null))[_0x8edf('0x38')](function(_0x1466d1){if(_0x1466d1){_0x530c4b[_0x8edf('0x48')]=_[_0x8edf('0x49')](db[_0x8edf('0x70')][_0x8edf('0x46')]);_0x530c4b[_0x8edf('0x4c')]=_[_0x8edf('0x49')](_0x2c9dc4[_0x8edf('0x4c')]);_0x530c4b[_0x8edf('0x4a')]=_[_0x8edf('0x4b')](_0x530c4b[_0x8edf('0x48')],_0x530c4b[_0x8edf('0x4c')]);_0x528760[_0x8edf('0x4d')]=_[_0x8edf('0x4b')](_0x530c4b[_0x8edf('0x48')],qs['fields'](_0x2c9dc4[_0x8edf('0x4c')]['fields']));_0x528760['attributes']=_0x528760[_0x8edf('0x4d')][_0x8edf('0x4f')]?_0x528760[_0x8edf('0x4d')]:_0x530c4b[_0x8edf('0x48')];if(!_0x2c9dc4['query'][_0x8edf('0x50')](_0x8edf('0x51'))){_0x528760[_0x8edf('0x32')]=qs[_0x8edf('0x32')](_0x2c9dc4[_0x8edf('0x4c')]['limit']);_0x528760[_0x8edf('0x31')]=qs['offset'](_0x2c9dc4['query'][_0x8edf('0x31')]);}_0x528760[_0x8edf('0x6a')]=qs[_0x8edf('0x52')](_0x2c9dc4[_0x8edf('0x4c')][_0x8edf('0x52')]);_0x528760[_0x8edf('0x53')]=qs['filters'](_['pick'](_0x2c9dc4['query'],_0x530c4b[_0x8edf('0x4a')]));_0x528760['where'][_0x8edf('0x68')]=_0x1466d1['id'];if(_0x2c9dc4[_0x8edf('0x4c')][_0x8edf('0x55')]){_0x528760[_0x8edf('0x53')]=_[_0x8edf('0x56')](_0x528760[_0x8edf('0x53')],{'$or':_[_0x8edf('0x44')](_0x528760[_0x8edf('0x4d')],function(_0x2da960){var _0x14e10c={};_0x14e10c[_0x2da960]={'$like':'%'+_0x2c9dc4[_0x8edf('0x4c')][_0x8edf('0x55')]+'%'};return _0x14e10c;})});}_0x528760=_[_0x8edf('0x56')]({},_0x528760,_0x2c9dc4[_0x8edf('0x57')]);return db[_0x8edf('0x70')][_0x8edf('0x58')]({'where':_0x528760[_0x8edf('0x53')]})[_0x8edf('0x38')](function(_0x1f9261){_0x9f98dc['count']=_0x1f9261;if(_0x2c9dc4[_0x8edf('0x4c')][_0x8edf('0x59')]){_0x528760['include']=[{'all':!![]}];}return db['CannedAnswer'][_0x8edf('0x71')](_0x528760);})[_0x8edf('0x38')](function(_0x4f0e36){_0x9f98dc['rows']=_0x4f0e36;return _0x9f98dc;});}})[_0x8edf('0x38')](respondWithFilteredResult(_0xb29df2,_0x528760))[_0x8edf('0x2e')](handleError(_0xb29df2,null));};exports[_0x8edf('0x72')]=function(_0x51d879,_0x4a1f1e,_0x26d95a){return db[_0x8edf('0x45')][_0x8edf('0x5d')]({'where':{'id':_0x51d879['params']['id']}})[_0x8edf('0x38')](handleEntityNotFound(_0x4a1f1e,null))[_0x8edf('0x38')](function(_0x2d8f11){if(_0x2d8f11){return _0x2d8f11[_0x8edf('0x72')](_0x51d879['query'][_0x8edf('0x6c')]);}})[_0x8edf('0x38')](respondWithStatusCode(_0x4a1f1e,null))['catch'](handleError(_0x4a1f1e,null));};exports[_0x8edf('0x73')]=function(_0x35030a,_0x217aef,_0x482e3e){return db[_0x8edf('0x45')][_0x8edf('0x5d')]({'where':{'id':_0x35030a[_0x8edf('0x65')]['id']}})[_0x8edf('0x38')](handleEntityNotFound(_0x217aef,null))[_0x8edf('0x38')](function(_0x1b6d8e){if(_0x1b6d8e){return _0x1b6d8e[_0x8edf('0x73')](_0x35030a[_0x8edf('0x5e')]['ids'],_['omit'](_0x35030a[_0x8edf('0x5e')],['ids','id'])||{})[_0x8edf('0x74')](function(_0x379448){for(var _0xfe2829=0x0;_0xfe2829<_0x35030a[_0x8edf('0x5e')][_0x8edf('0x6c')][_0x8edf('0x4f')];_0xfe2829+=0x1){socket[_0x8edf('0x75')](_0x8edf('0x76'),{'UserId':_0x35030a['body'][_0x8edf('0x6c')][_0xfe2829],'WhatsappAccountId':_0x35030a[_0x8edf('0x65')]['id']});}return _0x379448;});}})['then'](respondWithResult(_0x217aef,null))[_0x8edf('0x2e')](handleError(_0x217aef,null));};exports[_0x8edf('0x77')]=function(_0x56a6db,_0x2f5f69,_0x14554d){return db[_0x8edf('0x45')][_0x8edf('0x5d')]({'where':{'id':_0x56a6db[_0x8edf('0x65')]['id']}})[_0x8edf('0x38')](handleEntityNotFound(_0x2f5f69,null))[_0x8edf('0x38')](function(_0x57558b){if(_0x57558b){return _0x57558b[_0x8edf('0x77')](_0x56a6db[_0x8edf('0x4c')][_0x8edf('0x6c')])['then'](function(){if(_[_0x8edf('0x78')](_0x56a6db[_0x8edf('0x4c')][_0x8edf('0x6c')])){for(var _0x58ed7b=0x0;_0x58ed7b<_0x56a6db[_0x8edf('0x4c')][_0x8edf('0x6c')]['length'];_0x58ed7b+=0x1){socket[_0x8edf('0x75')](_0x8edf('0x79'),{'UserId':Number(_0x56a6db['query'][_0x8edf('0x6c')][_0x58ed7b]),'WhatsappAccountId':Number(_0x56a6db['params']['id'])});}}else{socket['emit'](_0x8edf('0x79'),{'UserId':Number(_0x56a6db['query']['ids']),'WhatsappAccountId':Number(_0x56a6db[_0x8edf('0x65')]['id'])});}});}})[_0x8edf('0x38')](respondWithStatusCode(_0x2f5f69,null))[_0x8edf('0x2e')](handleError(_0x2f5f69,null));};exports[_0x8edf('0x7a')]=function(_0x2db93a,_0x14c580,_0x5449fe){var _0x3ed7f2={};var _0x25602b={};var _0x33af8e;var _0x63a7ad;return db[_0x8edf('0x45')][_0x8edf('0x6f')]({'where':{'id':_0x2db93a['params']['id']}})[_0x8edf('0x38')](handleEntityNotFound(_0x14c580,null))['then'](function(_0x41baca){if(_0x41baca){_0x33af8e=_0x41baca;_0x25602b[_0x8edf('0x48')]=_[_0x8edf('0x49')](db['User']['rawAttributes']);_0x25602b['query']=_[_0x8edf('0x49')](_0x2db93a[_0x8edf('0x4c')]);_0x25602b[_0x8edf('0x4a')]=_[_0x8edf('0x4b')](_0x25602b[_0x8edf('0x48')],_0x25602b['query']);_0x3ed7f2[_0x8edf('0x4d')]=_['intersection'](_0x25602b['model'],qs['fields'](_0x2db93a[_0x8edf('0x4c')]['fields']));_0x3ed7f2[_0x8edf('0x4d')]=_0x3ed7f2[_0x8edf('0x4d')][_0x8edf('0x4f')]?_0x3ed7f2[_0x8edf('0x4d')]:_0x25602b[_0x8edf('0x48')];_0x3ed7f2['order']=qs['sort'](_0x2db93a[_0x8edf('0x4c')][_0x8edf('0x52')]);_0x3ed7f2[_0x8edf('0x53')]=qs['filters'](_['pick'](_0x2db93a[_0x8edf('0x4c')],_0x25602b[_0x8edf('0x4a')]));if(_0x2db93a[_0x8edf('0x4c')]['filter']){_0x3ed7f2[_0x8edf('0x53')]=_['merge'](_0x3ed7f2[_0x8edf('0x53')],{'$or':_[_0x8edf('0x44')](_0x3ed7f2[_0x8edf('0x4d')],function(_0x22b7f4){var _0x2b8977={};_0x2b8977[_0x22b7f4]={'$like':'%'+_0x2db93a['query'][_0x8edf('0x55')]+'%'};return _0x2b8977;})});}_0x3ed7f2=_[_0x8edf('0x56')]({},_0x3ed7f2,_0x2db93a['options']);return _0x33af8e['getAgents'](_0x3ed7f2);}})[_0x8edf('0x38')](function(_0x3b0d12){if(_0x3b0d12){_0x63a7ad=_0x3b0d12[_0x8edf('0x4f')];if(!_0x2db93a[_0x8edf('0x4c')][_0x8edf('0x50')](_0x8edf('0x51'))){_0x3ed7f2[_0x8edf('0x32')]=qs['limit'](_0x2db93a[_0x8edf('0x4c')][_0x8edf('0x32')]);_0x3ed7f2[_0x8edf('0x31')]=qs[_0x8edf('0x31')](_0x2db93a['query'][_0x8edf('0x31')]);}return _0x33af8e[_0x8edf('0x7a')](_0x3ed7f2);}})[_0x8edf('0x38')](function(_0x21aaf5){if(_0x21aaf5){return _0x21aaf5?{'count':_0x63a7ad,'rows':_0x21aaf5}:null;}})['then'](respondWithResult(_0x14c580,null))[_0x8edf('0x2e')](handleError(_0x14c580,null));};exports[_0x8edf('0x7b')]=function(_0x5de716,_0x4012f7,_0x56d7de){return db[_0x8edf('0x45')][_0x8edf('0x6f')]({'where':{'id':_0x5de716[_0x8edf('0x65')]['id']}})[_0x8edf('0x38')](handleEntityNotFound(_0x4012f7,null))[_0x8edf('0x38')](function(_0x3ab38b){if(_0x3ab38b){return db[_0x8edf('0x7c')]['transaction'](function(_0x72402e){return db[_0x8edf('0x7d')]['destroy']({'where':{'WhatsappAccountId':_0x5de716[_0x8edf('0x65')]['id']},'transaction':_0x72402e})[_0x8edf('0x38')](function(_0x2e023d){var _0x21245d=_['map'](_0x5de716[_0x8edf('0x5e')],function(_0x41d8ab){_0x41d8ab[_0x8edf('0x68')]=_0x5de716[_0x8edf('0x65')]['id'];return _0x41d8ab;});return db[_0x8edf('0x7d')][_0x8edf('0x7e')](_0x21245d,{'transaction':_0x72402e});});})[_0x8edf('0x38')](function(){return db[_0x8edf('0x7d')]['findAndCountAll']({'where':{'WhatsappAccountId':_0x5de716[_0x8edf('0x65')]['id']},'order':_0x8edf('0x7f')});});}})[_0x8edf('0x38')](respondWithResult(_0x4012f7,null))[_0x8edf('0x2e')](handleError(_0x4012f7,null));};exports[_0x8edf('0x80')]=function(_0x39a2a5,_0x5642a2,_0x1b5227){var _0x208832={};var _0x26df2a={};var _0x3b827d;var _0x579242;return db[_0x8edf('0x45')]['findOne']({'where':{'id':_0x39a2a5[_0x8edf('0x65')]['id']}})['then'](handleEntityNotFound(_0x5642a2,null))[_0x8edf('0x38')](function(_0x1719f3){if(_0x1719f3){_0x3b827d=_0x1719f3;_0x26df2a[_0x8edf('0x48')]=_[_0x8edf('0x49')](db[_0x8edf('0x7d')][_0x8edf('0x46')]);_0x26df2a['query']=_[_0x8edf('0x49')](_0x39a2a5['query']);_0x26df2a[_0x8edf('0x4a')]=_[_0x8edf('0x4b')](_0x26df2a['model'],_0x26df2a[_0x8edf('0x4c')]);_0x208832[_0x8edf('0x4d')]=_[_0x8edf('0x4b')](_0x26df2a[_0x8edf('0x48')],qs[_0x8edf('0x4e')](_0x39a2a5[_0x8edf('0x4c')]['fields']));_0x208832[_0x8edf('0x4d')]=_0x208832['attributes'][_0x8edf('0x4f')]?_0x208832['attributes']:_0x26df2a[_0x8edf('0x48')];_0x208832['order']=qs[_0x8edf('0x52')](_0x39a2a5[_0x8edf('0x4c')]['sort']);_0x208832[_0x8edf('0x53')]=qs[_0x8edf('0x4a')](_[_0x8edf('0x54')](_0x39a2a5['query'],_0x26df2a['filters']));if(_0x39a2a5[_0x8edf('0x4c')]['filter']){_0x208832['where']=_[_0x8edf('0x56')](_0x208832[_0x8edf('0x53')],{'$or':_[_0x8edf('0x44')](_0x208832[_0x8edf('0x4d')],function(_0x1e9a01){var _0x4a590f={};_0x4a590f[_0x1e9a01]={'$like':'%'+_0x39a2a5[_0x8edf('0x4c')][_0x8edf('0x55')]+'%'};return _0x4a590f;})});}_0x208832=_[_0x8edf('0x56')]({},_0x208832,_0x39a2a5[_0x8edf('0x57')]);return _0x3b827d[_0x8edf('0x80')](_0x208832);}})[_0x8edf('0x38')](function(_0x43b3bf){if(_0x43b3bf){_0x579242=_0x43b3bf[_0x8edf('0x4f')];if(!_0x39a2a5[_0x8edf('0x4c')][_0x8edf('0x50')](_0x8edf('0x51'))){_0x208832[_0x8edf('0x32')]=qs[_0x8edf('0x32')](_0x39a2a5[_0x8edf('0x4c')][_0x8edf('0x32')]);_0x208832[_0x8edf('0x31')]=qs['offset'](_0x39a2a5[_0x8edf('0x4c')][_0x8edf('0x31')]);}return _0x3b827d[_0x8edf('0x80')](_0x208832);}})[_0x8edf('0x38')](function(_0x1f6a84){if(_0x1f6a84){return _0x1f6a84?{'count':_0x579242,'rows':_0x1f6a84}:null;}})[_0x8edf('0x38')](respondWithResult(_0x5642a2,null))[_0x8edf('0x2e')](handleError(_0x5642a2,null));};exports['notify']=function(_0x4bb467,_0x57c117,_0x11c023){var _0x36f201={'channel':_0x8edf('0x81')};var _0x30e9cb=[];var _0x2148b4=[];var _0x1e49b2={};return db[_0x8edf('0x45')][_0x8edf('0x5d')]({'where':{'id':_0x4bb467['params']['id']},'include':[{'model':db[_0x8edf('0x7d')],'as':_0x8edf('0x82')}]})['then'](handleEntityNotFound(_0x57c117,null))[_0x8edf('0x38')](function(_0x14623e){_0x36f201[_0x8edf('0x83')]=_0x14623e;_0x36f201[_0x8edf('0x84')]=_[_0x8edf('0x85')](_0x14623e[_0x8edf('0x82')],[_0x8edf('0x7f')],[_0x8edf('0x86')]);if(_0x36f201[_0x8edf('0x83')]['Applications']){delete _0x36f201[_0x8edf('0x83')][_0x8edf('0x82')];}return db[_0x8edf('0x87')]['describe']();})[_0x8edf('0x38')](function(_0x12e89f){if(!_0x12e89f){throw new db[(_0x8edf('0x88'))][(_0x8edf('0x89'))]('no\x20available\x20attributes');}_0x30e9cb=_[_0x8edf('0x8a')](_['keys'](_0x12e89f),[_0x8edf('0x8b'),'updatedAt']);_0x2148b4=_[_0x8edf('0x8a')](_['keys'](_0x12e89f),[_0x8edf('0x8b'),_0x8edf('0x8c'),_0x8edf('0x8d'),_0x8edf('0x8e')]);_0x36f201[_0x8edf('0x5e')]={'mapKey':_0x8edf('0x8f')};if(_0x36f201[_0x8edf('0x83')]['type']&&_0x36f201[_0x8edf('0x83')][_0x8edf('0x47')]===_0x8edf('0x90')){_0x36f201['body'][_0x8edf('0x91')]=_0x4bb467[_0x8edf('0x5e')][_0x8edf('0x92')][_0x8edf('0x93')](_0x8edf('0x94'),'');_0x36f201[_0x8edf('0x5e')][_0x8edf('0x5e')]=_0x4bb467['body'][_0x8edf('0x95')];_0x36f201[_0x8edf('0x5e')][_0x8edf('0x96')]=_0x4bb467['body']['MessageSid'];}if(_0x36f201[_0x8edf('0x5e')]['id']){delete _0x36f201['body']['id'];}if(_[_0x8edf('0x97')](_0x36f201['body'][_0x8edf('0x91')])){throw new db[(_0x8edf('0x88'))][(_0x8edf('0x89'))](_0x8edf('0x98'));}if(_[_0x8edf('0x97')](_0x36f201[_0x8edf('0x5e')][_0x8edf('0x5e')])||_0x36f201[_0x8edf('0x5e')][_0x8edf('0x5e')]===''){throw new db['Sequelize']['ValidationError'](_0x8edf('0x99'));}if(_[_0x8edf('0x97')](_0x36f201[_0x8edf('0x5e')][_0x8edf('0x9a')])){throw new db[(_0x8edf('0x88'))]['ValidationError'](_0x8edf('0x9b')+_0x2148b4);}if(!_[_0x8edf('0x9c')](_0x2148b4,_0x36f201['body'][_0x8edf('0x9a')])){throw new db[(_0x8edf('0x88'))][(_0x8edf('0x89'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x2148b4);}_0x1e49b2[_0x36f201['body'][_0x8edf('0x9a')]]=_0x36f201[_0x8edf('0x5e')][_0x8edf('0x91')];return db[_0x8edf('0x9d')][_0x8edf('0x5d')]({'where':{'id':_0x36f201[_0x8edf('0x83')]['ListId']},'include':[{'model':db[_0x8edf('0x87')],'as':_0x8edf('0x9e'),'where':_0x1e49b2,'limit':0x1,'order':[[_0x8edf('0x8c'),_0x8edf('0x9f')]]}]});})[_0x8edf('0x38')](handleEntityNotFound(_0x57c117,null))[_0x8edf('0x38')](function(_0x55a0d3){if(_0x55a0d3){_0x36f201[_0x8edf('0xa0')]=_[_0x8edf('0xa1')](_0x55a0d3,[_0x8edf('0x9e')]);if(_0x55a0d3[_0x8edf('0x9e')]['length']){return _0x55a0d3[_0x8edf('0x9e')][0x0];}var _0x401c9f=_[_0x8edf('0x1e')](_0x36f201[_0x8edf('0x5e')],{'firstName':_0x36f201[_0x8edf('0x5e')][_0x8edf('0x91')],'ListId':_0x55a0d3['id']});_0x401c9f[_0x36f201['body']['mapKey']]=_0x36f201[_0x8edf('0x5e')][_0x8edf('0x91')];return db[_0x8edf('0x87')][_0x8edf('0x63')](_0x401c9f,{'fields':_0x30e9cb,'raw':!![]});}})[_0x8edf('0x38')](handleEntityNotFound(_0x57c117,null))[_0x8edf('0x38')](function(_0x507352){if(_0x507352){_0x36f201['contact']=_0x507352;var _0x2e7a4d={'ContactId':_0x507352['id'],'phone':_0x36f201[_0x8edf('0x5e')][_0x8edf('0x91')],'WhatsappAccountId':_0x4bb467['params']['id']};var _0x4e92e5={'ContactId':_0x507352['id'],'WhatsappAccountId':_0x4bb467[_0x8edf('0x65')]['id'],'closed':![]};return db[_0x8edf('0xa2')][_0x8edf('0x5d')]({'where':_0x4e92e5})[_0x8edf('0x38')](function(_0x1968c0){if(_0x1968c0){return[_0x1968c0,![]];}return db['WhatsappInteraction'][_0x8edf('0x63')](_0x2e7a4d)[_0x8edf('0x38')](function(_0x33fad9){return[_0x33fad9,!![]];});});}})[_0x8edf('0x74')](function(_0x2cdfe8,_0x1a01fb){_0x36f201[_0x8edf('0xa3')]=_0x2cdfe8[_0x8edf('0x3a')]({'plain':!![]});_0x36f201[_0x8edf('0xa3')]['created']=![];if(_0x1a01fb){if(_0x36f201[_0x8edf('0x83')][_0x8edf('0xa4')]){_0x36f201[_0x8edf('0x84')][_0x8edf('0xa5')]({'id':0x0,'priority':_0x36f201[_0x8edf('0x84')][_0x8edf('0x4f')]+0x1,'app':_0x8edf('0xa6'),'appdata':'unmanaged','interval':'*,*,*,*'});}_0x36f201[_0x8edf('0xa3')][_0x8edf('0xa7')]=!![];}return db[_0x8edf('0xa8')]['create']({'phone':_0x36f201[_0x8edf('0x5e')][_0x8edf('0x91')],'messageId':_0x36f201['body']['messageId'],'body':_0x36f201[_0x8edf('0x5e')][_0x8edf('0x5e')],'WhatsappAccountId':_0x4bb467[_0x8edf('0x65')]['id'],'WhatsappInteractionId':_0x2cdfe8['id'],'direction':'in','ContactId':_0x2cdfe8[_0x8edf('0xa9')],'AttachmentId':_0x36f201['body'][_0x8edf('0xaa')]});})[_0x8edf('0x38')](function(_0xbfacb9){_0x36f201[_0x8edf('0x2b')]=_0xbfacb9;if(_0x36f201[_0x8edf('0xa3')]['UserId']){return db['User'][_0x8edf('0x5d')]({'attributes':['id',_0x8edf('0x3f')],'where':{'id':_0x36f201[_0x8edf('0xa3')][_0x8edf('0xab')]}})['then'](function(_0x316440){if(_0x316440){_0x36f201['applications'][_0x8edf('0xac')]({'id':0x0,'priority':0x0,'app':_0x8edf('0xad'),'appdata':_0x316440[_0x8edf('0x3f')]+','+(_0x36f201[_0x8edf('0x83')][_0x8edf('0xae')]||0xa),'interval':'*,*,*,*'});}return respondWithRpcPromise('Start','startRouting',_0x36f201);});}return respondWithRpcPromise(_0x8edf('0xaf'),_0x8edf('0xb0'),_0x36f201);})['then'](function(_0x4dce92){if(_0x4dce92){var _0x41138b=0xc8;var _0x530317=_0x8edf('0xb1');logger[_0x8edf('0x2c')](_0x8edf('0x27'),_0x530317,_0x41138b,_0x8edf('0xb2'));logger[_0x8edf('0xb3')](_0x8edf('0xb4'),_0x530317,_0x41138b,_0x8edf('0xb2'),JSON['stringify'](_0x4dce92));if(_0x36f201[_0x8edf('0x83')]['type']===_0x8edf('0x90')){return _0x57c117[_0x8edf('0x30')](_0x41138b)[_0x8edf('0x33')]('Content-Type','text/xml')['send'](_0x8edf('0xb5'));}else{return _0x57c117[_0x8edf('0x30')](_0x41138b)[_0x8edf('0x35')](_0x4dce92);}}})[_0x8edf('0x2e')](handleError(_0x57c117,null));};exports['send']=function(_0x5006cf,_0x931704,_0x2b87b7){var _0x5253a0,_0x26aa0a,_0x7895a3;if(_['isNil'](_0x5006cf[_0x8edf('0x5e')][_0x8edf('0x5e')])||_0x5006cf[_0x8edf('0x5e')]['body']===''){throw new db[(_0x8edf('0x88'))][(_0x8edf('0x89'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x8edf('0x97')](_0x5006cf[_0x8edf('0x5e')]['to'])){throw new db[(_0x8edf('0x88'))][(_0x8edf('0x89'))](_0x8edf('0xb6'));}_0x5253a0=_0x5006cf[_0x8edf('0x5e')]['to'];return db[_0x8edf('0x45')][_0x8edf('0x5d')]({'where':{'id':_0x5006cf[_0x8edf('0x65')]['id']},'include':[{'model':db[_0x8edf('0x9d')],'as':_0x8edf('0xb7'),'include':[{'model':db[_0x8edf('0x87')],'as':_0x8edf('0x9e'),'where':{'mobile':_0x5253a0},'limit':0x1,'order':[['updatedAt',_0x8edf('0x9f')]]}]}]})['then'](handleEntityNotFound(_0x931704,null))['then'](function(_0xb884fa){if(_0xb884fa&&_0xb884fa[_0x8edf('0xb7')]){_0x26aa0a=_0xb884fa[_0x8edf('0x3a')]({'plain':!![]});if(_0x26aa0a[_0x8edf('0xb7')]&&_0x26aa0a[_0x8edf('0xb7')][_0x8edf('0x9e')][_0x8edf('0x4f')]){return _0x26aa0a['List'][_0x8edf('0x9e')][0x0];}return db[_0x8edf('0x87')][_0x8edf('0x63')](_[_0x8edf('0x1e')](_0x5006cf[_0x8edf('0x5e')],{'firstName':_0x5253a0,'mobile':_0x5253a0,'phone':_0x5253a0,'ListId':_0x26aa0a[_0x8edf('0x8e')]}));}})['then'](handleEntityNotFound(_0x931704,null))[_0x8edf('0x38')](function(_0x1c4939){if(_0x1c4939){_0x7895a3=_0x1c4939;return db[_0x8edf('0xa2')][_0x8edf('0x5d')]({'where':{'ContactId':_0x7895a3['id'],'closed':![],'WhatsappAccountId':_0x26aa0a['id']}})[_0x8edf('0x38')](function(_0x2c3bdd){if(_0x2c3bdd){return[_0x2c3bdd,![]];}return db['WhatsappInteraction'][_0x8edf('0x63')]({'UserId':_0x5006cf[_0x8edf('0xb8')]['id'],'ContactId':_0x7895a3['id'],'WhatsappAccountId':_0x26aa0a['id'],'phone':_0x5253a0,'firstMsgDirection':_0x8edf('0xb9'),'Messages':[_['merge'](_0x5006cf[_0x8edf('0x5e')],{'read':![],'body':_0x5006cf['body'][_0x8edf('0x5e')],'phone':_0x5253a0,'WhatsappAccountId':_0x26aa0a['id'],'UserId':_0x5006cf['user']['id'],'ContactId':_0x7895a3['id']})]},{'include':[{'model':db[_0x8edf('0xa8')],'as':'Messages'}]})[_0x8edf('0x38')](function(_0x429f29){return[_0x429f29,!![]];});});}})[_0x8edf('0x74')](function(_0x501cb2,_0x509b9c){if(_0x509b9c){return _0x501cb2;}return db[_0x8edf('0xa8')][_0x8edf('0x63')](_[_0x8edf('0x56')](_0x5006cf[_0x8edf('0x5e')],{'read':![],'body':_0x5006cf[_0x8edf('0x5e')][_0x8edf('0x5e')],'phone':_0x5253a0,'WhatsappAccountId':_0x26aa0a['id'],'WhatsappInteractionId':_0x501cb2['id'],'UserId':_0x5006cf[_0x8edf('0xb8')]['id'],'ContactId':_0x7895a3['id']}))['then'](function(_0x290e67){_0x501cb2[_0x8edf('0xba')][_0x8edf('0xbb')]=[];_0x501cb2[_0x8edf('0xba')][_0x8edf('0xbb')][_0x8edf('0xa5')](_0x290e67[_0x8edf('0xba')]);return _0x501cb2;});})[_0x8edf('0x38')](respondWithResult(_0x931704,null))['catch'](handleError(_0x931704,null));};
\ No newline at end of file
+var _0xeedf=['request-promise','moment','bluebird','mustache','sox','fs-extra','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./whatsappAccount.socket','register','http','then','info','WhatsappAccount,\x20%s,\x20%s','request\x20sent','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','sendStatus','status','end','json','offset','limit','count','set','Content-Range','save','destroy','get','WhatsappAccounts','UserProfileResource','name','send','index','Pause','mandatoryDispositionPause','map','WhatsappAccount','fieldName','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','pick','type','filter','options','includeAll','include','findAll','rows','catch','show','rawAttributes','merge','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','params','describe','addDisposition','WhatsappAccountId','Disposition','getDispositions','keys','order','removeDispositions','ids','addAnswer','CannedAnswer','findOne','removeAnswers','addAgents','omit','spread','emit','userWhatsappAccount:save','removeAgents','isArray','userWhatsappAccount:remove','getAgents','sequelize','transaction','READ_COMMITTED','WhatsappApplication','bulkCreate','findAndCountAll','priority','finally','getApplications','whatsapp','Applications','account','sinch','statuses','state','read','WhatsappMessage','message_id','applications','orderBy','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','ListId','mobile','twilio','from','whatsapp:','messageId','notifications','isNil','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','Contacts','DESC','defaults','contact','WhatsappInteraction','interaction','created','push','close','unmanaged','*,*,*,*','ContactId','AttachmentId','UserId','User','unshift','agent','waitForTheAssignedAgent','Start','receiveMessage','entity\x20found','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s','Content-Type','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','to\x20is\x20mandatory','List','out','Messages','dataValues','fast-json-patch'];(function(_0x5f76c3,_0x1a0793){var _0x1d2edb=function(_0x4bd7ee){while(--_0x4bd7ee){_0x5f76c3['push'](_0x5f76c3['shift']());}};_0x1d2edb(++_0x1a0793);}(_0xeedf,0x173));var _0xfeed=function(_0x385a41,_0x4b6141){_0x385a41=_0x385a41-0x0;var _0x5c4b65=_0xeedf[_0x385a41];return _0x5c4b65;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xfeed('0x0'));var rp=require(_0xfeed('0x1'));var moment=require(_0xfeed('0x2'));var BPromise=require(_0xfeed('0x3'));var Mustache=require(_0xfeed('0x4'));var util=require('util');var path=require('path');var sox=require(_0xfeed('0x5'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xfeed('0x6'));var _=require('lodash');var squel=require(_0xfeed('0x7'));var crypto=require('crypto');var jsforce=require(_0xfeed('0x8'));var deskjs=require(_0xfeed('0x9'));var toCsv=require('to-csv');var querystring=require(_0xfeed('0xa'));var Papa=require(_0xfeed('0xb'));var Redis=require(_0xfeed('0xc'));var authService=require(_0xfeed('0xd'));var qs=require('../../components/parsers/qs');var as=require(_0xfeed('0xe'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xfeed('0xf'));var utils=require(_0xfeed('0x10'));var config=require(_0xfeed('0x11'));var licenseUtil=require(_0xfeed('0x12'));var db=require(_0xfeed('0x13'))['db'];config[_0xfeed('0x14')]=_['defaults'](config[_0xfeed('0x14')],{'host':_0xfeed('0x15'),'port':0x18eb});var socket=require(_0xfeed('0x16'))(new Redis(config[_0xfeed('0x14')]));require(_0xfeed('0x17'))[_0xfeed('0x18')](socket);var jayson=require('jayson/promise');var client=jayson['client'][_0xfeed('0x19')]({'port':0x232c});function respondWithRpcPromise(_0x53433b,_0x183274,_0x142b5b,_0x3dbff4){return new BPromise(function(_0x14afd9,_0x49cc14){var _0x376488=_0x3dbff4||client;return _0x376488['request'](_0x53433b,_0x142b5b)[_0xfeed('0x1a')](function(_0x4f9aa4){logger[_0xfeed('0x1b')](_0xfeed('0x1c'),_0x183274,_0xfeed('0x1d'));logger['debug'](_0xfeed('0x1e'),_0x183274,'request\x20sent',JSON[_0xfeed('0x1f')](_0x4f9aa4));if(_0x4f9aa4[_0xfeed('0x20')]){if(_0x4f9aa4[_0xfeed('0x20')]['code']===0x1f4){logger['error'](_0xfeed('0x1c'),_0x183274,_0x4f9aa4[_0xfeed('0x20')][_0xfeed('0x21')]);return _0x49cc14(_0x4f9aa4[_0xfeed('0x20')][_0xfeed('0x21')]);}logger[_0xfeed('0x20')](_0xfeed('0x1c'),_0x183274,_0x4f9aa4['error'][_0xfeed('0x21')]);return _0x14afd9(_0x4f9aa4[_0xfeed('0x20')][_0xfeed('0x21')]);}else{logger[_0xfeed('0x1b')]('WhatsappAccount,\x20%s,\x20%s',_0x183274,'request\x20sent');_0x14afd9(_0x4f9aa4['result'][_0xfeed('0x21')]);}})['catch'](function(_0x55399d){logger[_0xfeed('0x20')]('WhatsappAccount,\x20%s,\x20%s',_0x183274,_0x55399d);_0x49cc14(_0x55399d);});});}function respondWithStatusCode(_0x1114fd,_0x3e6fdc){_0x3e6fdc=_0x3e6fdc||0xcc;return function(_0x2bb147){if(_0x2bb147){return _0x1114fd[_0xfeed('0x22')](_0x3e6fdc);}return _0x1114fd[_0xfeed('0x23')](_0x3e6fdc)[_0xfeed('0x24')]();};}function respondWithResult(_0x56255a,_0x41c23f){_0x41c23f=_0x41c23f||0xc8;return function(_0x5c7688){if(_0x5c7688){return _0x56255a[_0xfeed('0x23')](_0x41c23f)[_0xfeed('0x25')](_0x5c7688);}};}function respondWithFilteredResult(_0x4a7d4f,_0x3a4131){return function(_0x5cc61b){if(_0x5cc61b){var _0xeca37b=typeof _0x3a4131[_0xfeed('0x26')]==='undefined'&&typeof _0x3a4131[_0xfeed('0x27')]==='undefined';var _0x56d3d2=_0x5cc61b['count'];var _0x334766=_0xeca37b?0x0:_0x3a4131['offset'];var _0x35cb3c=_0xeca37b?_0x5cc61b[_0xfeed('0x28')]:_0x3a4131[_0xfeed('0x26')]+_0x3a4131['limit'];var _0x167f4a;if(_0x35cb3c>=_0x56d3d2){_0x35cb3c=_0x56d3d2;_0x167f4a=0xc8;}else{_0x167f4a=0xce;}_0x4a7d4f[_0xfeed('0x23')](_0x167f4a);return _0x4a7d4f[_0xfeed('0x29')](_0xfeed('0x2a'),_0x334766+'-'+_0x35cb3c+'/'+_0x56d3d2)[_0xfeed('0x25')](_0x5cc61b);}return null;};}function patchUpdates(_0x3be44c){return function(_0x2e652c){try{jsonpatch['apply'](_0x2e652c,_0x3be44c,!![]);}catch(_0x485786){return BPromise['reject'](_0x485786);}return _0x2e652c[_0xfeed('0x2b')]();};}function saveUpdates(_0x10d6aa,_0x39fecb){return function(_0x4711ea){if(_0x4711ea){return _0x4711ea['update'](_0x10d6aa)[_0xfeed('0x1a')](function(_0x5013d4){return _0x5013d4;});}return null;};}function removeEntity(_0x1e57aa,_0x32d7cb){return function(_0x3f7214){if(_0x3f7214){return _0x3f7214[_0xfeed('0x2c')]()[_0xfeed('0x1a')](function(){var _0x329990=_0x3f7214[_0xfeed('0x2d')]({'plain':!![]});var _0x5db0c5=_0xfeed('0x2e');return db[_0xfeed('0x2f')]['destroy']({'where':{'type':_0x5db0c5,'resourceId':_0x329990['id']}})[_0xfeed('0x1a')](function(){return _0x3f7214;});})['then'](function(){_0x1e57aa[_0xfeed('0x23')](0xcc)[_0xfeed('0x24')]();});}};}function handleEntityNotFound(_0x3e9b6a,_0xc1bc7){return function(_0x3b458e){if(!_0x3b458e){_0x3e9b6a[_0xfeed('0x22')](0x194);}return _0x3b458e;};}function handleError(_0x1442c3,_0x529fb6){_0x529fb6=_0x529fb6||0x1f4;return function(_0x43d369){logger[_0xfeed('0x20')](_0x43d369['stack']);if(_0x43d369[_0xfeed('0x30')]){delete _0x43d369['name'];}_0x1442c3[_0xfeed('0x23')](_0x529fb6)[_0xfeed('0x31')](_0x43d369);};}exports[_0xfeed('0x32')]=function(_0x4de573,_0x439fbc){var _0x25c86d={'include':[{'model':db[_0xfeed('0x33')],'as':_0xfeed('0x34')}]},_0x4082a7={},_0x1e8a81={'count':0x0,'rows':[]};var _0xd937fa=_[_0xfeed('0x35')](db[_0xfeed('0x36')]['rawAttributes'],function(_0x5864e9){return{'name':_0x5864e9[_0xfeed('0x37')],'type':_0x5864e9['type'][_0xfeed('0x38')]};});_0x4082a7[_0xfeed('0x39')]=_[_0xfeed('0x35')](_0xd937fa,'name');_0x4082a7[_0xfeed('0x3a')]=_['keys'](_0x4de573['query']);_0x4082a7[_0xfeed('0x3b')]=_[_0xfeed('0x3c')](_0x4082a7[_0xfeed('0x39')],_0x4082a7[_0xfeed('0x3a')]);_0x25c86d['attributes']=_[_0xfeed('0x3c')](_0x4082a7[_0xfeed('0x39')],qs[_0xfeed('0x3d')](_0x4de573[_0xfeed('0x3a')][_0xfeed('0x3d')]));_0x25c86d[_0xfeed('0x3e')]=_0x25c86d[_0xfeed('0x3e')][_0xfeed('0x3f')]?_0x25c86d[_0xfeed('0x3e')]:_0x4082a7['model'];if(!_0x4de573[_0xfeed('0x3a')][_0xfeed('0x40')](_0xfeed('0x41'))){_0x25c86d[_0xfeed('0x27')]=qs[_0xfeed('0x27')](_0x4de573['query']['limit']);_0x25c86d['offset']=qs['offset'](_0x4de573['query']['offset']);}_0x25c86d['order']=qs['sort'](_0x4de573['query'][_0xfeed('0x42')]);_0x25c86d[_0xfeed('0x43')]=qs[_0xfeed('0x3b')](_[_0xfeed('0x44')](_0x4de573[_0xfeed('0x3a')],_0x4082a7[_0xfeed('0x3b')]),_0xd937fa);if(_0x4de573[_0xfeed('0x3a')]['filter']){_0x25c86d[_0xfeed('0x43')]=_['merge'](_0x25c86d['where'],{'$or':_[_0xfeed('0x35')](_0xd937fa,function(_0x181f07){if(_0x181f07[_0xfeed('0x45')]!=='VIRTUAL'){var _0x894aec={};_0x894aec[_0x181f07['name']]={'$like':'%'+_0x4de573['query'][_0xfeed('0x46')]+'%'};return _0x894aec;}})});}_0x25c86d=_['merge']({},_0x25c86d,_0x4de573[_0xfeed('0x47')]);var _0x4b86c5={'where':_0x25c86d['where']};return db[_0xfeed('0x36')]['count'](_0x4b86c5)[_0xfeed('0x1a')](function(_0x36e431){_0x1e8a81[_0xfeed('0x28')]=_0x36e431;if(_0x4de573[_0xfeed('0x3a')][_0xfeed('0x48')]){_0x25c86d[_0xfeed('0x49')]=[{'all':!![]}];}return db[_0xfeed('0x36')][_0xfeed('0x4a')](_0x25c86d);})[_0xfeed('0x1a')](function(_0x1fcffa){_0x1e8a81[_0xfeed('0x4b')]=_0x1fcffa;return _0x1e8a81;})[_0xfeed('0x1a')](respondWithFilteredResult(_0x439fbc,_0x25c86d))[_0xfeed('0x4c')](handleError(_0x439fbc,null));};exports[_0xfeed('0x4d')]=function(_0x5f1764,_0x16f833){var _0x1bf91c={'raw':![],'where':{'id':_0x5f1764['params']['id']},'include':[{'model':db['Pause'],'as':_0xfeed('0x34')}]},_0x484381={};_0x484381[_0xfeed('0x39')]=_['keys'](db['WhatsappAccount'][_0xfeed('0x4e')]);_0x484381[_0xfeed('0x3a')]=_['keys'](_0x5f1764[_0xfeed('0x3a')]);_0x484381['filters']=_[_0xfeed('0x3c')](_0x484381[_0xfeed('0x39')],_0x484381[_0xfeed('0x3a')]);_0x1bf91c[_0xfeed('0x3e')]=_[_0xfeed('0x3c')](_0x484381[_0xfeed('0x39')],qs['fields'](_0x5f1764[_0xfeed('0x3a')][_0xfeed('0x3d')]));_0x1bf91c[_0xfeed('0x3e')]=_0x1bf91c[_0xfeed('0x3e')][_0xfeed('0x3f')]?_0x1bf91c[_0xfeed('0x3e')]:_0x484381[_0xfeed('0x39')];if(_0x5f1764['query'][_0xfeed('0x48')]){_0x1bf91c[_0xfeed('0x49')]=[{'all':!![]}];}_0x1bf91c=_[_0xfeed('0x4f')]({},_0x1bf91c,_0x5f1764[_0xfeed('0x47')]);return db[_0xfeed('0x36')][_0xfeed('0x50')](_0x1bf91c)[_0xfeed('0x1a')](handleEntityNotFound(_0x16f833,null))[_0xfeed('0x1a')](respondWithResult(_0x16f833,null))[_0xfeed('0x4c')](handleError(_0x16f833,null));};exports['create']=function(_0x2bee40,_0x52b737){return db[_0xfeed('0x36')][_0xfeed('0x51')](_0x2bee40[_0xfeed('0x52')],{})[_0xfeed('0x1a')](function(_0x5bda66){var _0x398547=_0x2bee40[_0xfeed('0x53')]['get']({'plain':!![]});if(!_0x398547)throw new Error(_0xfeed('0x54'));if(_0x398547['role']===_0xfeed('0x53')){var _0xa56001=_0x5bda66['get']({'plain':!![]});var _0x879901=_0xfeed('0x2e');return db[_0xfeed('0x55')][_0xfeed('0x50')]({'where':{'name':_0x879901,'userProfileId':_0x398547[_0xfeed('0x56')]},'raw':!![]})[_0xfeed('0x1a')](function(_0x25372b){if(_0x25372b&&_0x25372b[_0xfeed('0x57')]===0x0){return db[_0xfeed('0x2f')]['create']({'name':_0xa56001[_0xfeed('0x30')],'resourceId':_0xa56001['id'],'type':_0x25372b['name'],'sectionId':_0x25372b['id']},{})[_0xfeed('0x1a')](function(){return _0x5bda66;});}else{return _0x5bda66;}})['catch'](function(_0x3ef6ac){logger[_0xfeed('0x20')](_0xfeed('0x58'),_0x3ef6ac);throw _0x3ef6ac;});}return _0x5bda66;})[_0xfeed('0x1a')](respondWithResult(_0x52b737,0xc9))[_0xfeed('0x4c')](handleError(_0x52b737,null));};exports[_0xfeed('0x59')]=function(_0x45ce83,_0xeac8de){if(_0x45ce83[_0xfeed('0x52')]['id']){delete _0x45ce83['body']['id'];}return db[_0xfeed('0x36')][_0xfeed('0x50')]({'where':{'id':_0x45ce83[_0xfeed('0x5a')]['id']},'include':[{'model':db[_0xfeed('0x33')],'as':_0xfeed('0x34')}]})[_0xfeed('0x1a')](handleEntityNotFound(_0xeac8de,null))[_0xfeed('0x1a')](saveUpdates(_0x45ce83['body'],null))[_0xfeed('0x1a')](respondWithResult(_0xeac8de,null))[_0xfeed('0x4c')](handleError(_0xeac8de,null));};exports['destroy']=function(_0x5a7e79,_0x1249e7){return db[_0xfeed('0x36')][_0xfeed('0x50')]({'where':{'id':_0x5a7e79[_0xfeed('0x5a')]['id']}})[_0xfeed('0x1a')](handleEntityNotFound(_0x1249e7,null))[_0xfeed('0x1a')](removeEntity(_0x1249e7,null))[_0xfeed('0x4c')](handleError(_0x1249e7,null));};exports[_0xfeed('0x5b')]=function(_0x14241f,_0x25dca5){return db['WhatsappAccount']['describe']()[_0xfeed('0x1a')](respondWithResult(_0x25dca5,null))[_0xfeed('0x4c')](handleError(_0x25dca5,null));};exports[_0xfeed('0x5c')]=function(_0x6d9d74,_0x53fbc6,_0x29853a){if(_0x6d9d74[_0xfeed('0x52')]['id']){delete _0x6d9d74[_0xfeed('0x52')]['id'];}return db[_0xfeed('0x36')][_0xfeed('0x50')]({'where':{'id':_0x6d9d74[_0xfeed('0x5a')]['id']}})[_0xfeed('0x1a')](handleEntityNotFound(_0x53fbc6,null))['then'](function(_0x15ced2){if(_0x15ced2){_0x6d9d74[_0xfeed('0x52')][_0xfeed('0x5d')]=_0x15ced2['id'];return db[_0xfeed('0x5e')]['create'](_0x6d9d74[_0xfeed('0x52')]);}})[_0xfeed('0x1a')](respondWithResult(_0x53fbc6,null))[_0xfeed('0x4c')](handleError(_0x53fbc6,null));};exports[_0xfeed('0x5f')]=function(_0x3864d3,_0x3a5170,_0x363e29){var _0xcf8b32={'raw':![],'where':{}};var _0x34fc74={};var _0x594232={'count':0x0,'rows':[]};return db[_0xfeed('0x36')]['findOne']({'where':{'id':_0x3864d3[_0xfeed('0x5a')]['id']}})[_0xfeed('0x1a')](handleEntityNotFound(_0x3a5170,null))[_0xfeed('0x1a')](function(_0x469591){if(_0x469591){_0x34fc74[_0xfeed('0x39')]=_['keys'](db[_0xfeed('0x5e')][_0xfeed('0x4e')]);_0x34fc74[_0xfeed('0x3a')]=_[_0xfeed('0x60')](_0x3864d3[_0xfeed('0x3a')]);_0x34fc74['filters']=_['intersection'](_0x34fc74[_0xfeed('0x39')],_0x34fc74['query']);_0xcf8b32[_0xfeed('0x3e')]=_[_0xfeed('0x3c')](_0x34fc74[_0xfeed('0x39')],qs[_0xfeed('0x3d')](_0x3864d3[_0xfeed('0x3a')][_0xfeed('0x3d')]));_0xcf8b32[_0xfeed('0x3e')]=_0xcf8b32[_0xfeed('0x3e')][_0xfeed('0x3f')]?_0xcf8b32['attributes']:_0x34fc74[_0xfeed('0x39')];if(!_0x3864d3['query']['hasOwnProperty'](_0xfeed('0x41'))){_0xcf8b32[_0xfeed('0x27')]=qs[_0xfeed('0x27')](_0x3864d3[_0xfeed('0x3a')][_0xfeed('0x27')]);_0xcf8b32['offset']=qs[_0xfeed('0x26')](_0x3864d3[_0xfeed('0x3a')]['offset']);}_0xcf8b32[_0xfeed('0x61')]=qs['sort'](_0x3864d3[_0xfeed('0x3a')][_0xfeed('0x42')]);_0xcf8b32[_0xfeed('0x43')]=qs[_0xfeed('0x3b')](_[_0xfeed('0x44')](_0x3864d3[_0xfeed('0x3a')],_0x34fc74[_0xfeed('0x3b')]));_0xcf8b32[_0xfeed('0x43')][_0xfeed('0x5d')]=_0x469591['id'];if(_0x3864d3[_0xfeed('0x3a')][_0xfeed('0x46')]){_0xcf8b32['where']=_[_0xfeed('0x4f')](_0xcf8b32[_0xfeed('0x43')],{'$or':_[_0xfeed('0x35')](_0xcf8b32[_0xfeed('0x3e')],function(_0xb532cf){var _0x3d828c={};_0x3d828c[_0xb532cf]={'$like':'%'+_0x3864d3[_0xfeed('0x3a')][_0xfeed('0x46')]+'%'};return _0x3d828c;})});}_0xcf8b32=_[_0xfeed('0x4f')]({},_0xcf8b32,_0x3864d3[_0xfeed('0x47')]);return db['Disposition'][_0xfeed('0x28')]({'where':_0xcf8b32['where']})[_0xfeed('0x1a')](function(_0x54456a){_0x594232[_0xfeed('0x28')]=_0x54456a;if(_0x3864d3[_0xfeed('0x3a')]['includeAll']){_0xcf8b32['include']=[{'all':!![]}];}return db['Disposition'][_0xfeed('0x4a')](_0xcf8b32);})[_0xfeed('0x1a')](function(_0x21ba78){_0x594232['rows']=_0x21ba78;return _0x594232;});}})[_0xfeed('0x1a')](respondWithFilteredResult(_0x3a5170,_0xcf8b32))[_0xfeed('0x4c')](handleError(_0x3a5170,null));};exports[_0xfeed('0x62')]=function(_0x54e960,_0x3291e3,_0x209432){return db[_0xfeed('0x36')][_0xfeed('0x50')]({'where':{'id':_0x54e960[_0xfeed('0x5a')]['id']}})[_0xfeed('0x1a')](handleEntityNotFound(_0x3291e3,null))[_0xfeed('0x1a')](function(_0x3e942b){if(_0x3e942b){return _0x3e942b[_0xfeed('0x62')](_0x54e960[_0xfeed('0x3a')][_0xfeed('0x63')]);}})[_0xfeed('0x1a')](respondWithStatusCode(_0x3291e3,null))[_0xfeed('0x4c')](handleError(_0x3291e3,null));};exports[_0xfeed('0x64')]=function(_0x15b54b,_0x2d3c1b,_0x11754d){if(_0x15b54b[_0xfeed('0x52')]['id']){delete _0x15b54b[_0xfeed('0x52')]['id'];}return db[_0xfeed('0x36')][_0xfeed('0x50')]({'where':{'id':_0x15b54b[_0xfeed('0x5a')]['id']}})[_0xfeed('0x1a')](handleEntityNotFound(_0x2d3c1b,null))[_0xfeed('0x1a')](function(_0x236c6a){if(_0x236c6a){_0x15b54b[_0xfeed('0x52')][_0xfeed('0x5d')]=_0x236c6a['id'];return db[_0xfeed('0x65')][_0xfeed('0x51')](_0x15b54b['body']);}})['then'](respondWithResult(_0x2d3c1b,null))[_0xfeed('0x4c')](handleError(_0x2d3c1b,null));};exports['getAnswers']=function(_0x2dc6d9,_0x5124d4,_0x46f9d9){var _0x171d80={'raw':![],'where':{}};var _0x42decd={};var _0x10f478={'count':0x0,'rows':[]};return db[_0xfeed('0x36')][_0xfeed('0x66')]({'where':{'id':_0x2dc6d9['params']['id']}})[_0xfeed('0x1a')](handleEntityNotFound(_0x5124d4,null))['then'](function(_0x2fac08){if(_0x2fac08){_0x42decd['model']=_[_0xfeed('0x60')](db[_0xfeed('0x65')][_0xfeed('0x4e')]);_0x42decd[_0xfeed('0x3a')]=_[_0xfeed('0x60')](_0x2dc6d9[_0xfeed('0x3a')]);_0x42decd[_0xfeed('0x3b')]=_[_0xfeed('0x3c')](_0x42decd[_0xfeed('0x39')],_0x42decd[_0xfeed('0x3a')]);_0x171d80[_0xfeed('0x3e')]=_[_0xfeed('0x3c')](_0x42decd[_0xfeed('0x39')],qs['fields'](_0x2dc6d9[_0xfeed('0x3a')][_0xfeed('0x3d')]));_0x171d80[_0xfeed('0x3e')]=_0x171d80[_0xfeed('0x3e')]['length']?_0x171d80[_0xfeed('0x3e')]:_0x42decd[_0xfeed('0x39')];if(!_0x2dc6d9[_0xfeed('0x3a')]['hasOwnProperty'](_0xfeed('0x41'))){_0x171d80['limit']=qs['limit'](_0x2dc6d9[_0xfeed('0x3a')][_0xfeed('0x27')]);_0x171d80[_0xfeed('0x26')]=qs[_0xfeed('0x26')](_0x2dc6d9[_0xfeed('0x3a')][_0xfeed('0x26')]);}_0x171d80['order']=qs[_0xfeed('0x42')](_0x2dc6d9[_0xfeed('0x3a')][_0xfeed('0x42')]);_0x171d80[_0xfeed('0x43')]=qs['filters'](_['pick'](_0x2dc6d9[_0xfeed('0x3a')],_0x42decd[_0xfeed('0x3b')]));_0x171d80[_0xfeed('0x43')][_0xfeed('0x5d')]=_0x2fac08['id'];if(_0x2dc6d9[_0xfeed('0x3a')][_0xfeed('0x46')]){_0x171d80['where']=_[_0xfeed('0x4f')](_0x171d80[_0xfeed('0x43')],{'$or':_['map'](_0x171d80[_0xfeed('0x3e')],function(_0x365367){var _0x2eefac={};_0x2eefac[_0x365367]={'$like':'%'+_0x2dc6d9['query'][_0xfeed('0x46')]+'%'};return _0x2eefac;})});}_0x171d80=_[_0xfeed('0x4f')]({},_0x171d80,_0x2dc6d9[_0xfeed('0x47')]);return db[_0xfeed('0x65')]['count']({'where':_0x171d80[_0xfeed('0x43')]})[_0xfeed('0x1a')](function(_0x13a445){_0x10f478[_0xfeed('0x28')]=_0x13a445;if(_0x2dc6d9[_0xfeed('0x3a')][_0xfeed('0x48')]){_0x171d80['include']=[{'all':!![]}];}return db['CannedAnswer'][_0xfeed('0x4a')](_0x171d80);})[_0xfeed('0x1a')](function(_0x3fbfe8){_0x10f478[_0xfeed('0x4b')]=_0x3fbfe8;return _0x10f478;});}})['then'](respondWithFilteredResult(_0x5124d4,_0x171d80))[_0xfeed('0x4c')](handleError(_0x5124d4,null));};exports['removeAnswers']=function(_0x4e24ac,_0x19a651,_0x377eac){return db[_0xfeed('0x36')]['find']({'where':{'id':_0x4e24ac[_0xfeed('0x5a')]['id']}})[_0xfeed('0x1a')](handleEntityNotFound(_0x19a651,null))[_0xfeed('0x1a')](function(_0x429353){if(_0x429353){return _0x429353[_0xfeed('0x67')](_0x4e24ac[_0xfeed('0x3a')]['ids']);}})[_0xfeed('0x1a')](respondWithStatusCode(_0x19a651,null))[_0xfeed('0x4c')](handleError(_0x19a651,null));};exports[_0xfeed('0x68')]=function(_0x3c4b2d,_0x20f6b4,_0x53f99f){return db[_0xfeed('0x36')][_0xfeed('0x50')]({'where':{'id':_0x3c4b2d[_0xfeed('0x5a')]['id']}})[_0xfeed('0x1a')](handleEntityNotFound(_0x20f6b4,null))['then'](function(_0x4998fc){if(_0x4998fc){return _0x4998fc['addAgents'](_0x3c4b2d['body'][_0xfeed('0x63')],_[_0xfeed('0x69')](_0x3c4b2d['body'],[_0xfeed('0x63'),'id'])||{})[_0xfeed('0x6a')](function(_0x650841){for(var _0x1fb617=0x0;_0x1fb617<_0x3c4b2d[_0xfeed('0x52')][_0xfeed('0x63')][_0xfeed('0x3f')];_0x1fb617+=0x1){socket[_0xfeed('0x6b')](_0xfeed('0x6c'),{'UserId':Number(_0x3c4b2d[_0xfeed('0x52')][_0xfeed('0x63')][_0x1fb617]),'WhatsappAccountId':Number(_0x3c4b2d[_0xfeed('0x5a')]['id'])});}return _0x650841;});}})[_0xfeed('0x1a')](respondWithResult(_0x20f6b4,null))[_0xfeed('0x4c')](handleError(_0x20f6b4,null));};exports['removeAgents']=function(_0x3d608b,_0x34719c,_0x1b798c){return db[_0xfeed('0x36')][_0xfeed('0x50')]({'where':{'id':_0x3d608b[_0xfeed('0x5a')]['id']}})['then'](handleEntityNotFound(_0x34719c,null))[_0xfeed('0x1a')](function(_0x1ef320){if(_0x1ef320){return _0x1ef320[_0xfeed('0x6d')](_0x3d608b[_0xfeed('0x3a')][_0xfeed('0x63')])['then'](function(){if(_[_0xfeed('0x6e')](_0x3d608b[_0xfeed('0x3a')]['ids'])){for(var _0x48a0d7=0x0;_0x48a0d7<_0x3d608b['query'][_0xfeed('0x63')]['length'];_0x48a0d7+=0x1){socket[_0xfeed('0x6b')]('userWhatsappAccount:remove',{'UserId':Number(_0x3d608b[_0xfeed('0x3a')][_0xfeed('0x63')][_0x48a0d7]),'WhatsappAccountId':Number(_0x3d608b[_0xfeed('0x5a')]['id'])});}}else{socket[_0xfeed('0x6b')](_0xfeed('0x6f'),{'UserId':Number(_0x3d608b['query'][_0xfeed('0x63')]),'WhatsappAccountId':Number(_0x3d608b[_0xfeed('0x5a')]['id'])});}});}})[_0xfeed('0x1a')](respondWithStatusCode(_0x34719c,null))['catch'](handleError(_0x34719c,null));};exports['getAgents']=function(_0x1a447c,_0x56bd8b,_0x489904){var _0x4c1cdc={};var _0x183251={};var _0x116496;var _0x2dc9df;return db[_0xfeed('0x36')][_0xfeed('0x66')]({'where':{'id':_0x1a447c[_0xfeed('0x5a')]['id']}})[_0xfeed('0x1a')](handleEntityNotFound(_0x56bd8b,null))[_0xfeed('0x1a')](function(_0x146c78){if(_0x146c78){_0x116496=_0x146c78;_0x183251[_0xfeed('0x39')]=_['keys'](db['User']['rawAttributes']);_0x183251[_0xfeed('0x3a')]=_[_0xfeed('0x60')](_0x1a447c[_0xfeed('0x3a')]);_0x183251[_0xfeed('0x3b')]=_[_0xfeed('0x3c')](_0x183251[_0xfeed('0x39')],_0x183251[_0xfeed('0x3a')]);_0x4c1cdc[_0xfeed('0x3e')]=_[_0xfeed('0x3c')](_0x183251[_0xfeed('0x39')],qs[_0xfeed('0x3d')](_0x1a447c[_0xfeed('0x3a')][_0xfeed('0x3d')]));_0x4c1cdc[_0xfeed('0x3e')]=_0x4c1cdc[_0xfeed('0x3e')][_0xfeed('0x3f')]?_0x4c1cdc['attributes']:_0x183251[_0xfeed('0x39')];_0x4c1cdc[_0xfeed('0x61')]=qs[_0xfeed('0x42')](_0x1a447c[_0xfeed('0x3a')]['sort']);_0x4c1cdc[_0xfeed('0x43')]=qs[_0xfeed('0x3b')](_[_0xfeed('0x44')](_0x1a447c[_0xfeed('0x3a')],_0x183251['filters']));if(_0x1a447c[_0xfeed('0x3a')]['filter']){_0x4c1cdc[_0xfeed('0x43')]=_[_0xfeed('0x4f')](_0x4c1cdc['where'],{'$or':_['map'](_0x4c1cdc['attributes'],function(_0x47981d){var _0x286ac1={};_0x286ac1[_0x47981d]={'$like':'%'+_0x1a447c[_0xfeed('0x3a')][_0xfeed('0x46')]+'%'};return _0x286ac1;})});}_0x4c1cdc=_['merge']({},_0x4c1cdc,_0x1a447c[_0xfeed('0x47')]);return _0x116496[_0xfeed('0x70')](_0x4c1cdc);}})[_0xfeed('0x1a')](function(_0x3b719e){if(_0x3b719e){_0x2dc9df=_0x3b719e[_0xfeed('0x3f')];if(!_0x1a447c['query']['hasOwnProperty'](_0xfeed('0x41'))){_0x4c1cdc['limit']=qs[_0xfeed('0x27')](_0x1a447c['query'][_0xfeed('0x27')]);_0x4c1cdc['offset']=qs[_0xfeed('0x26')](_0x1a447c[_0xfeed('0x3a')][_0xfeed('0x26')]);}return _0x116496[_0xfeed('0x70')](_0x4c1cdc);}})['then'](function(_0x49997f){if(_0x49997f){return _0x49997f?{'count':_0x2dc9df,'rows':_0x49997f}:null;}})[_0xfeed('0x1a')](respondWithResult(_0x56bd8b,null))[_0xfeed('0x4c')](handleError(_0x56bd8b,null));};exports['addApplications']=function(_0x1e45a9,_0x2503ea){var _0x1e24c0=_0x1e45a9[_0xfeed('0x5a')]['id'];var _0x24122c=_0x1e45a9['body'];var _0x415066=0xc8;var _0x223796=null;return db[_0xfeed('0x71')][_0xfeed('0x72')]({'isolationLevel':db['sequelize']['Transaction']['ISOLATION_LEVELS'][_0xfeed('0x73')]},function(_0x280514){return db[_0xfeed('0x36')][_0xfeed('0x66')]({'where':{'id':_0x1e24c0},'transaction':_0x280514})[_0xfeed('0x1a')](function(_0x59d24d){if(_0x59d24d){return db[_0xfeed('0x74')][_0xfeed('0x2c')]({'where':{'WhatsappAccountId':_0x1e24c0},'transaction':_0x280514})[_0xfeed('0x1a')](function(){var _0x45c094=_[_0xfeed('0x35')](_0x24122c,function(_0xd5500e){_0xd5500e['WhatsappAccountId']=_0x1e24c0;return _0xd5500e;});return db[_0xfeed('0x74')][_0xfeed('0x75')](_0x45c094,{'transaction':_0x280514});});}else{_0x415066=0x194;_0x223796=[];}});})['then'](function(){if(_0x415066!==0x194){return db[_0xfeed('0x74')][_0xfeed('0x76')]({'where':{'WhatsappAccountId':_0x1e24c0},'order':_0xfeed('0x77')})[_0xfeed('0x1a')](function(_0x73ebb3){_0x223796=_0x73ebb3;});}})[_0xfeed('0x4c')](function(_0x46a3d5){_0x415066=0x1f4;logger[_0xfeed('0x20')](_0x46a3d5['stack']);if(_0x46a3d5[_0xfeed('0x30')]){delete _0x46a3d5[_0xfeed('0x30')];}_0x223796=_0x46a3d5;})[_0xfeed('0x78')](function(){if(_0x223796===null){_0x2503ea['sendStatus'](_0x415066);}else{if(_0x415066===0x1f4){_0x2503ea['status'](_0x415066)[_0xfeed('0x31')](_0x223796);}else{_0x2503ea[_0xfeed('0x23')](_0x415066)['json'](_0x223796);}}});};exports['getApplications']=function(_0x3534a3,_0x4c0e20,_0x5e2a06){var _0x40d252={};var _0x1b847c={};var _0x434981;var _0x20f518;return db[_0xfeed('0x36')]['findOne']({'where':{'id':_0x3534a3['params']['id']}})[_0xfeed('0x1a')](handleEntityNotFound(_0x4c0e20,null))[_0xfeed('0x1a')](function(_0x240d59){if(_0x240d59){_0x434981=_0x240d59;_0x1b847c[_0xfeed('0x39')]=_[_0xfeed('0x60')](db[_0xfeed('0x74')][_0xfeed('0x4e')]);_0x1b847c[_0xfeed('0x3a')]=_[_0xfeed('0x60')](_0x3534a3[_0xfeed('0x3a')]);_0x1b847c[_0xfeed('0x3b')]=_[_0xfeed('0x3c')](_0x1b847c[_0xfeed('0x39')],_0x1b847c[_0xfeed('0x3a')]);_0x40d252['attributes']=_[_0xfeed('0x3c')](_0x1b847c['model'],qs[_0xfeed('0x3d')](_0x3534a3['query']['fields']));_0x40d252['attributes']=_0x40d252[_0xfeed('0x3e')][_0xfeed('0x3f')]?_0x40d252[_0xfeed('0x3e')]:_0x1b847c[_0xfeed('0x39')];_0x40d252[_0xfeed('0x61')]=qs['sort'](_0x3534a3[_0xfeed('0x3a')][_0xfeed('0x42')]);_0x40d252[_0xfeed('0x43')]=qs[_0xfeed('0x3b')](_[_0xfeed('0x44')](_0x3534a3[_0xfeed('0x3a')],_0x1b847c[_0xfeed('0x3b')]));if(_0x3534a3[_0xfeed('0x3a')][_0xfeed('0x46')]){_0x40d252[_0xfeed('0x43')]=_[_0xfeed('0x4f')](_0x40d252[_0xfeed('0x43')],{'$or':_[_0xfeed('0x35')](_0x40d252[_0xfeed('0x3e')],function(_0x39e32e){var _0x5c8ec8={};_0x5c8ec8[_0x39e32e]={'$like':'%'+_0x3534a3[_0xfeed('0x3a')][_0xfeed('0x46')]+'%'};return _0x5c8ec8;})});}_0x40d252=_['merge']({},_0x40d252,_0x3534a3[_0xfeed('0x47')]);return _0x434981[_0xfeed('0x79')](_0x40d252);}})['then'](function(_0x35d5b8){if(_0x35d5b8){_0x20f518=_0x35d5b8[_0xfeed('0x3f')];if(!_0x3534a3[_0xfeed('0x3a')][_0xfeed('0x40')]('nolimit')){_0x40d252[_0xfeed('0x27')]=qs[_0xfeed('0x27')](_0x3534a3[_0xfeed('0x3a')][_0xfeed('0x27')]);_0x40d252[_0xfeed('0x26')]=qs[_0xfeed('0x26')](_0x3534a3[_0xfeed('0x3a')]['offset']);}return _0x434981[_0xfeed('0x79')](_0x40d252);}})[_0xfeed('0x1a')](function(_0x362cf4){if(_0x362cf4){return _0x362cf4?{'count':_0x20f518,'rows':_0x362cf4}:null;}})[_0xfeed('0x1a')](respondWithResult(_0x4c0e20,null))[_0xfeed('0x4c')](handleError(_0x4c0e20,null));};exports['notify']=function(_0x5588f9,_0xf75718,_0x342859){var _0x2272cf={'channel':_0xfeed('0x7a')};var _0x523ec7=[];var _0x20bcb3=[];var _0x57bc48={};return db[_0xfeed('0x36')]['find']({'where':{'id':_0x5588f9[_0xfeed('0x5a')]['id']},'include':[{'model':db[_0xfeed('0x74')],'as':_0xfeed('0x7b')}]})[_0xfeed('0x1a')](handleEntityNotFound(_0xf75718,null))[_0xfeed('0x1a')](function(_0x58bbd6){_0x2272cf[_0xfeed('0x7c')]=_0x58bbd6;if(_0x2272cf[_0xfeed('0x7c')]&&_0x2272cf['account'][_0xfeed('0x45')]===_0xfeed('0x7d')&&_0x5588f9['body'][_0xfeed('0x7e')]){if(_0x5588f9[_0xfeed('0x52')][_0xfeed('0x7e')][_0xfeed('0x3f')]===0x0)return;if(_0x5588f9[_0xfeed('0x52')][_0xfeed('0x7e')][0x0][_0xfeed('0x7f')]!==_0xfeed('0x80'))return;return db[_0xfeed('0x81')][_0xfeed('0x59')]({'read':!![],'readAt':_0x5588f9['body']['statuses'][0x0]['timestamp']},{'where':{'messageId':_0x5588f9[_0xfeed('0x52')][_0xfeed('0x7e')][0x0][_0xfeed('0x82')]},'individualHooks':!![]})[_0xfeed('0x1a')](function(_0x4f834b){return _0xf75718['status'](0xc8)[_0xfeed('0x25')](_0x4f834b);});}_0x2272cf[_0xfeed('0x83')]=_[_0xfeed('0x84')](_0x58bbd6[_0xfeed('0x7b')],[_0xfeed('0x77')],['asc']);if(_0x2272cf[_0xfeed('0x7c')]['Applications']){delete _0x2272cf['account']['Applications'];}return db[_0xfeed('0x85')]['describe']()[_0xfeed('0x1a')](function(_0x3535d9){if(!_0x3535d9){throw new db[(_0xfeed('0x86'))][(_0xfeed('0x87'))](_0xfeed('0x88'));}_0x523ec7=_[_0xfeed('0x89')](_['keys'](_0x3535d9),[_0xfeed('0x8a'),_0xfeed('0x8b')]);_0x20bcb3=_[_0xfeed('0x89')](_[_0xfeed('0x60')](_0x3535d9),[_0xfeed('0x8a'),'updatedAt','CompanyId',_0xfeed('0x8c')]);_0x2272cf[_0xfeed('0x52')]={'mapKey':_0xfeed('0x8d')};if(_0x2272cf[_0xfeed('0x7c')]&&_0x2272cf[_0xfeed('0x7c')][_0xfeed('0x45')]===_0xfeed('0x8e')){_0x2272cf[_0xfeed('0x52')][_0xfeed('0x8f')]=_0x5588f9[_0xfeed('0x52')]['From']['replace'](_0xfeed('0x90'),'');_0x2272cf[_0xfeed('0x52')]['body']=_0x5588f9[_0xfeed('0x52')]['Body'];_0x2272cf[_0xfeed('0x52')][_0xfeed('0x91')]=_0x5588f9[_0xfeed('0x52')]['MessageSid'];}if(_0x2272cf[_0xfeed('0x7c')]&&_0x2272cf[_0xfeed('0x7c')][_0xfeed('0x45')]==='sinch'){_0x2272cf[_0xfeed('0x52')]['from']=_0x5588f9[_0xfeed('0x52')]['notifications'][0x0]['from'];_0x2272cf[_0xfeed('0x52')]['body']=_0x5588f9[_0xfeed('0x52')][_0xfeed('0x92')][0x0][_0xfeed('0x21')][_0xfeed('0x52')];_0x2272cf['body'][_0xfeed('0x91')]=_0x5588f9[_0xfeed('0x52')]['notifications'][0x0][_0xfeed('0x82')];}if(_0x2272cf[_0xfeed('0x52')]['id']){delete _0x2272cf[_0xfeed('0x52')]['id'];}if(_[_0xfeed('0x93')](_0x2272cf[_0xfeed('0x52')][_0xfeed('0x8f')])){throw new db[(_0xfeed('0x86'))][(_0xfeed('0x87'))](_0xfeed('0x94'));}if(_['isNil'](_0x2272cf[_0xfeed('0x52')][_0xfeed('0x52')])||_0x2272cf['body'][_0xfeed('0x52')]===''){throw new db[(_0xfeed('0x86'))][(_0xfeed('0x87'))](_0xfeed('0x95'));}if(_[_0xfeed('0x93')](_0x2272cf[_0xfeed('0x52')][_0xfeed('0x96')])){throw new db['Sequelize']['ValidationError'](_0xfeed('0x97')+_0x20bcb3);}if(!_[_0xfeed('0x98')](_0x20bcb3,_0x2272cf[_0xfeed('0x52')][_0xfeed('0x96')])){throw new db[(_0xfeed('0x86'))][(_0xfeed('0x87'))](_0xfeed('0x99')+_0x20bcb3);}_0x57bc48[_0x2272cf['body']['mapKey']]=_0x2272cf[_0xfeed('0x52')][_0xfeed('0x8f')];return db[_0xfeed('0x9a')][_0xfeed('0x50')]({'where':{'id':_0x2272cf[_0xfeed('0x7c')]['ListId']},'include':[{'model':db[_0xfeed('0x85')],'as':_0xfeed('0x9b'),'where':_0x57bc48,'limit':0x1,'order':[['updatedAt',_0xfeed('0x9c')]]}]});})[_0xfeed('0x1a')](handleEntityNotFound(_0xf75718,null))[_0xfeed('0x1a')](function(_0x1ea9e0){if(_0x1ea9e0){_0x2272cf['list']=_['omit'](_0x1ea9e0,[_0xfeed('0x9b')]);if(_0x1ea9e0[_0xfeed('0x9b')][_0xfeed('0x3f')]){return _0x1ea9e0[_0xfeed('0x9b')][0x0];}var _0x15c6a0=_[_0xfeed('0x9d')](_0x2272cf[_0xfeed('0x52')],{'firstName':_0x2272cf['body']['from'],'ListId':_0x1ea9e0['id']});_0x15c6a0[_0x2272cf[_0xfeed('0x52')][_0xfeed('0x96')]]=_0x2272cf['body'][_0xfeed('0x8f')];return db['CmContact'][_0xfeed('0x51')](_0x15c6a0,{'fields':_0x523ec7,'raw':!![]});}})[_0xfeed('0x1a')](handleEntityNotFound(_0xf75718,null))[_0xfeed('0x1a')](function(_0x215e2b){if(_0x215e2b){_0x2272cf[_0xfeed('0x9e')]=_0x215e2b;var _0x835206={'ContactId':_0x215e2b['id'],'phone':_0x2272cf[_0xfeed('0x52')]['from'],'WhatsappAccountId':_0x5588f9[_0xfeed('0x5a')]['id']};var _0x4d0039={'ContactId':_0x215e2b['id'],'WhatsappAccountId':_0x5588f9[_0xfeed('0x5a')]['id'],'closed':![]};return db[_0xfeed('0x9f')]['find']({'where':_0x4d0039})[_0xfeed('0x1a')](function(_0x1cbd26){if(_0x1cbd26){return[_0x1cbd26,![]];}return db[_0xfeed('0x9f')][_0xfeed('0x51')](_0x835206)[_0xfeed('0x1a')](function(_0x16a18c){return[_0x16a18c,!![]];});});}})[_0xfeed('0x6a')](function(_0x4f8764,_0x26e84d){_0x2272cf[_0xfeed('0xa0')]=_0x4f8764[_0xfeed('0x2d')]({'plain':!![]});_0x2272cf['interaction'][_0xfeed('0xa1')]=![];if(_0x26e84d){if(_0x2272cf[_0xfeed('0x7c')]['autoclose']){_0x2272cf[_0xfeed('0x83')][_0xfeed('0xa2')]({'id':0x0,'priority':_0x2272cf['applications']['length']+0x1,'app':_0xfeed('0xa3'),'appdata':_0xfeed('0xa4'),'interval':_0xfeed('0xa5')});}_0x2272cf[_0xfeed('0xa0')][_0xfeed('0xa1')]=!![];}return db[_0xfeed('0x81')]['create']({'phone':_0x2272cf[_0xfeed('0x52')][_0xfeed('0x8f')],'messageId':_0x2272cf['body'][_0xfeed('0x91')],'body':_0x2272cf[_0xfeed('0x52')]['body'],'WhatsappAccountId':_0x5588f9['params']['id'],'WhatsappInteractionId':_0x4f8764['id'],'direction':'in','ContactId':_0x4f8764[_0xfeed('0xa6')],'AttachmentId':_0x2272cf[_0xfeed('0x52')][_0xfeed('0xa7')]});})[_0xfeed('0x1a')](function(_0x44efd3){_0x2272cf['message']=_0x44efd3;if(_0x2272cf[_0xfeed('0xa0')][_0xfeed('0xa8')]){return db[_0xfeed('0xa9')][_0xfeed('0x50')]({'attributes':['id',_0xfeed('0x30')],'where':{'id':_0x2272cf[_0xfeed('0xa0')][_0xfeed('0xa8')]}})[_0xfeed('0x1a')](function(_0x449260){if(_0x449260){_0x2272cf[_0xfeed('0x83')][_0xfeed('0xaa')]({'id':0x0,'priority':0x0,'app':_0xfeed('0xab'),'appdata':_0x449260[_0xfeed('0x30')]+','+(_0x2272cf[_0xfeed('0x7c')][_0xfeed('0xac')]||0xa),'interval':_0xfeed('0xa5')});}return respondWithRpcPromise(_0xfeed('0xad'),'startRouting',_0x2272cf);});}return respondWithRpcPromise('Start','startRouting',_0x2272cf);})[_0xfeed('0x1a')](function(_0x11111c){if(_0x11111c){var _0xd49679=0xc8;var _0x4ff740=_0xfeed('0xae');logger[_0xfeed('0x1b')]('WhatsappAccount,\x20%s,\x20%s,\x20%s',_0x4ff740,_0xd49679,_0xfeed('0xaf'));logger[_0xfeed('0xb0')](_0xfeed('0xb1'),_0x4ff740,_0xd49679,_0xfeed('0xaf'),JSON['stringify'](_0x11111c));if(_0x2272cf['account'][_0xfeed('0x45')]==='twilio'){return _0xf75718[_0xfeed('0x23')](_0xd49679)[_0xfeed('0x29')](_0xfeed('0xb2'),_0xfeed('0xb3'))['send'](_0xfeed('0xb4'));}else{return _0xf75718[_0xfeed('0x23')](_0xd49679)[_0xfeed('0x25')](_0x11111c);}}});})[_0xfeed('0x4c')](handleError(_0xf75718,null));};exports[_0xfeed('0x31')]=function(_0x4d91ee,_0x2f4653,_0x215324){var _0x4cdc50,_0x4845de,_0x2de246;if(_[_0xfeed('0x93')](_0x4d91ee[_0xfeed('0x52')][_0xfeed('0x52')])||_0x4d91ee[_0xfeed('0x52')][_0xfeed('0x52')]===''){throw new db[(_0xfeed('0x86'))]['ValidationError'](_0xfeed('0x95'));}if(_[_0xfeed('0x93')](_0x4d91ee[_0xfeed('0x52')]['to'])){throw new db[(_0xfeed('0x86'))][(_0xfeed('0x87'))](_0xfeed('0xb5'));}_0x4cdc50=_0x4d91ee[_0xfeed('0x52')]['to'];return db['WhatsappAccount'][_0xfeed('0x50')]({'where':{'id':_0x4d91ee[_0xfeed('0x5a')]['id']},'include':[{'model':db[_0xfeed('0x9a')],'as':'List','include':[{'model':db['CmContact'],'as':'Contacts','where':{'mobile':_0x4cdc50},'limit':0x1,'order':[[_0xfeed('0x8b'),_0xfeed('0x9c')]]}]}]})[_0xfeed('0x1a')](handleEntityNotFound(_0x2f4653,null))[_0xfeed('0x1a')](function(_0x56d347){if(_0x56d347&&_0x56d347[_0xfeed('0xb6')]){_0x4845de=_0x56d347[_0xfeed('0x2d')]({'plain':!![]});if(_0x4845de['List']&&_0x4845de[_0xfeed('0xb6')]['Contacts'][_0xfeed('0x3f')]){return _0x4845de['List'][_0xfeed('0x9b')][0x0];}return db[_0xfeed('0x85')][_0xfeed('0x51')](_[_0xfeed('0x9d')](_0x4d91ee[_0xfeed('0x52')],{'firstName':_0x4cdc50,'mobile':_0x4cdc50,'phone':_0x4cdc50,'ListId':_0x4845de[_0xfeed('0x8c')]}));}})[_0xfeed('0x1a')](handleEntityNotFound(_0x2f4653,null))[_0xfeed('0x1a')](function(_0x39bad8){if(_0x39bad8){_0x2de246=_0x39bad8;return db[_0xfeed('0x9f')][_0xfeed('0x50')]({'where':{'ContactId':_0x2de246['id'],'closed':![],'WhatsappAccountId':_0x4845de['id']}})[_0xfeed('0x1a')](function(_0x4416a2){if(_0x4416a2){return[_0x4416a2,![]];}return db['WhatsappInteraction'][_0xfeed('0x51')]({'UserId':_0x4d91ee[_0xfeed('0x53')]['id'],'ContactId':_0x2de246['id'],'WhatsappAccountId':_0x4845de['id'],'phone':_0x4cdc50,'firstMsgDirection':_0xfeed('0xb7'),'Messages':[_['merge'](_0x4d91ee['body'],{'read':![],'body':_0x4d91ee['body'][_0xfeed('0x52')],'phone':_0x4cdc50,'WhatsappAccountId':_0x4845de['id'],'UserId':_0x4d91ee[_0xfeed('0x53')]['id'],'ContactId':_0x2de246['id']})]},{'include':[{'model':db[_0xfeed('0x81')],'as':_0xfeed('0xb8')}]})['then'](function(_0x51471f){return[_0x51471f,!![]];});});}})[_0xfeed('0x6a')](function(_0x10a783,_0x2455fd){if(_0x2455fd){return _0x10a783;}return db[_0xfeed('0x81')][_0xfeed('0x51')](_[_0xfeed('0x4f')](_0x4d91ee[_0xfeed('0x52')],{'read':![],'body':_0x4d91ee[_0xfeed('0x52')][_0xfeed('0x52')],'phone':_0x4cdc50,'WhatsappAccountId':_0x4845de['id'],'WhatsappInteractionId':_0x10a783['id'],'UserId':_0x4d91ee[_0xfeed('0x53')]['id'],'ContactId':_0x2de246['id']}))[_0xfeed('0x1a')](function(_0x26c71a){_0x10a783[_0xfeed('0xb9')]['Messages']=[];_0x10a783[_0xfeed('0xb9')][_0xfeed('0xb8')][_0xfeed('0xa2')](_0x26c71a[_0xfeed('0xb9')]);return _0x10a783;});})[_0xfeed('0x1a')](respondWithResult(_0x2f4653,null))[_0xfeed('0x4c')](handleError(_0x2f4653,null));};
\ No newline at end of file