Built motion from commit 994c64e1.|2.6.1
[motion2.git] / server / api / whatsappAccount / whatsappAccount.controller.js
index 1c6c915..bc5c616 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xd64b=['waitForTheAssignedAgent','Start','entity\x20found','WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s','set','Content-Type','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','to\x20is\x20mandatory','CmList','List','DESC','out','Messages','dataValues','html-pdf','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./whatsappAccount.socket','register','jayson/promise','client','test','ValidationError','request','info','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','WhatsappAccount,\x20%s,\x20%s','message','catch','status','json','count','offset','limit','apply','save','update','then','destroy','get','end','sendStatus','stack','name','send','index','Pause','mandatoryDispositionPause','rawAttributes','type','key','model','map','keys','intersection','query','attributes','fields','hasOwnProperty','nolimit','order','sort','filters','filter','where','merge','VIRTUAL','options','WhatsappAccount','includeAll','include','findAll','rows','show','length','find','create','body','user','WhatsappAccounts','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','WhatsappAccountId','Disposition','getDispositions','findOne','pick','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','addAgents','spread','userWhatsappAccount:save','removeAgents','userWhatsappAccount:remove','emit','getAgents','addApplications','sequelize','transaction','WhatsappApplication','bulkCreate','getApplications','notify','whatsapp','Applications','account','applications','priority','asc','CmContact','difference','createdAt','updatedAt','twilio','From','replace','whatsapp:','Body','messageId','MessageSid','from','from\x20is\x20mandatory','isNil','Sequelize','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','ListId','Contacts','contact','WhatsappInteraction','interaction','created','autoclose','push','close','*,*,*,*','WhatsappMessage','ContactId','AttachmentId','UserId','agent'];(function(_0x3b1fc4,_0x470ef7){var _0x3e258d=function(_0x462e96){while(--_0x462e96){_0x3b1fc4['push'](_0x3b1fc4['shift']());}};_0x3e258d(++_0x470ef7);}(_0xd64b,0xc1));var _0xbd64=function(_0x2cdf4e,_0x210079){_0x2cdf4e=_0x2cdf4e-0x0;var _0x5a4400=_0xd64b[_0x2cdf4e];return _0x5a4400;};'use strict';var pdf=require(_0xbd64('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xbd64('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xbd64('0x2'));var rp=require(_0xbd64('0x3'));var moment=require(_0xbd64('0x4'));var BPromise=require(_0xbd64('0x5'));var Mustache=require(_0xbd64('0x6'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xbd64('0x7'));var fs=require('fs');var _=require(_0xbd64('0x8'));var squel=require(_0xbd64('0x9'));var crypto=require(_0xbd64('0xa'));var jsforce=require(_0xbd64('0xb'));var deskjs=require(_0xbd64('0xc'));var toCsv=require(_0xbd64('0xd'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xbd64('0xe'));var authService=require(_0xbd64('0xf'));var qs=require(_0xbd64('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbd64('0x11'));var logger=require(_0xbd64('0x12'))(_0xbd64('0x13'));var utils=require(_0xbd64('0x14'));var config=require('../../config/environment');var db=require(_0xbd64('0x15'))['db'];config['redis']=_[_0xbd64('0x16')](config[_0xbd64('0x17')],{'host':_0xbd64('0x18'),'port':0x18eb});var socket=require(_0xbd64('0x19'))(new Redis(config[_0xbd64('0x17')]));require(_0xbd64('0x1a'))[_0xbd64('0x1b')](socket);var jayson=require(_0xbd64('0x1c'));var client=jayson[_0xbd64('0x1d')]['http']({'port':0x232c});function checkPasswordPattern(_0x2d1159,_0x13e7a4,_0x3ff550){if(_0x3ff550){var _0x32fd34=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x32fd34[_0xbd64('0x1e')](_0x13e7a4)){return _0x2d1159;}else{throw new db['Sequelize'][(_0xbd64('0x1f'))]('The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.');}}else{return _0x2d1159;}}function respondWithRpcPromise(_0xccb0d5,_0x1432a6,_0x3aef70,_0x1d7a14){return new BPromise(function(_0x17d015,_0x2f4554){var _0xa5491d=_0x1d7a14||client;return _0xa5491d[_0xbd64('0x20')](_0xccb0d5,_0x3aef70)['then'](function(_0x305545){logger[_0xbd64('0x21')]('WhatsappAccount,\x20%s,\x20%s',_0x1432a6,'request\x20sent');logger[_0xbd64('0x22')](_0xbd64('0x23'),_0x1432a6,_0xbd64('0x24'),JSON[_0xbd64('0x25')](_0x305545));if(_0x305545[_0xbd64('0x26')]){if(_0x305545[_0xbd64('0x26')]['code']===0x1f4){logger['error'](_0xbd64('0x27'),_0x1432a6,_0x305545[_0xbd64('0x26')][_0xbd64('0x28')]);return _0x2f4554(_0x305545[_0xbd64('0x26')]['message']);}logger['error'](_0xbd64('0x27'),_0x1432a6,_0x305545['error'][_0xbd64('0x28')]);return _0x17d015(_0x305545['error'][_0xbd64('0x28')]);}else{logger[_0xbd64('0x21')](_0xbd64('0x27'),_0x1432a6,_0xbd64('0x24'));_0x17d015(_0x305545['result'][_0xbd64('0x28')]);}})[_0xbd64('0x29')](function(_0x13f527){logger[_0xbd64('0x26')]('WhatsappAccount,\x20%s,\x20%s',_0x1432a6,_0x13f527);_0x2f4554(_0x13f527);});});}function respondWithStatusCode(_0x4e8719,_0x29c9c8){_0x29c9c8=_0x29c9c8||0xcc;return function(_0x49eac5){if(_0x49eac5){return _0x4e8719['sendStatus'](_0x29c9c8);}return _0x4e8719[_0xbd64('0x2a')](_0x29c9c8)['end']();};}function respondWithResult(_0x3cf5b7,_0x5300e8){_0x5300e8=_0x5300e8||0xc8;return function(_0x28199c){if(_0x28199c){return _0x3cf5b7['status'](_0x5300e8)[_0xbd64('0x2b')](_0x28199c);}};}function respondWithFilteredResult(_0x3c0eaf,_0x3be63a){return function(_0x210fff){if(_0x210fff){var _0x306f19=_0x210fff[_0xbd64('0x2c')],_0x207ffc=_0x3be63a[_0xbd64('0x2d')],_0x4ed44a=_0x3be63a[_0xbd64('0x2d')]+_0x3be63a[_0xbd64('0x2e')],_0x35bdd5;if(_0x4ed44a>=_0x306f19){_0x4ed44a=_0x306f19;_0x35bdd5=0xc8;}else{_0x35bdd5=0xce;}_0x3c0eaf[_0xbd64('0x2a')](_0x35bdd5);return _0x3c0eaf['set']('Content-Range',_0x207ffc+'-'+_0x4ed44a+'/'+_0x306f19)[_0xbd64('0x2b')](_0x210fff);}return null;};}function patchUpdates(_0x576604){return function(_0xebed78){try{jsonpatch[_0xbd64('0x2f')](_0xebed78,_0x576604,!![]);}catch(_0x54459f){return BPromise['reject'](_0x54459f);}return _0xebed78[_0xbd64('0x30')]();};}function saveUpdates(_0x4e1834,_0x5b6948){return function(_0x1867af){if(_0x1867af){return _0x1867af[_0xbd64('0x31')](_0x4e1834)[_0xbd64('0x32')](function(_0x50c58e){return _0x50c58e;});}return null;};}function removeEntity(_0x231c37,_0x569cb6){return function(_0x1fc9cf){if(_0x1fc9cf){return _0x1fc9cf[_0xbd64('0x33')]()[_0xbd64('0x32')](function(){var _0x243588=_0x1fc9cf[_0xbd64('0x34')]({'plain':!![]});var _0x429aec='WhatsappAccounts';return db['UserProfileResource'][_0xbd64('0x33')]({'where':{'type':_0x429aec,'resourceId':_0x243588['id']}})[_0xbd64('0x32')](function(){return _0x1fc9cf;});})[_0xbd64('0x32')](function(){_0x231c37[_0xbd64('0x2a')](0xcc)[_0xbd64('0x35')]();});}};}function handleEntityNotFound(_0x3b245e,_0x54784f){return function(_0x5a74a9){if(!_0x5a74a9){_0x3b245e[_0xbd64('0x36')](0x194);}return _0x5a74a9;};}function handleError(_0x1bcd4c,_0x21f518){_0x21f518=_0x21f518||0x1f4;return function(_0x4df52a){logger['error'](_0x4df52a[_0xbd64('0x37')]);if(_0x4df52a['name']){delete _0x4df52a[_0xbd64('0x38')];}_0x1bcd4c['status'](_0x21f518)[_0xbd64('0x39')](_0x4df52a);};}exports[_0xbd64('0x3a')]=function(_0x550221,_0x107da1){var _0x51ae42={'include':[{'model':db[_0xbd64('0x3b')],'as':_0xbd64('0x3c')}]},_0x534091={},_0x380f32={'count':0x0,'rows':[]};var _0x52f401=_['map'](db['WhatsappAccount'][_0xbd64('0x3d')],function(_0xbfd402){return{'name':_0xbfd402['fieldName'],'type':_0xbfd402[_0xbd64('0x3e')][_0xbd64('0x3f')]};});_0x534091[_0xbd64('0x40')]=_[_0xbd64('0x41')](_0x52f401,'name');_0x534091['query']=_[_0xbd64('0x42')](_0x550221['query']);_0x534091['filters']=_[_0xbd64('0x43')](_0x534091[_0xbd64('0x40')],_0x534091[_0xbd64('0x44')]);_0x51ae42[_0xbd64('0x45')]=_[_0xbd64('0x43')](_0x534091[_0xbd64('0x40')],qs[_0xbd64('0x46')](_0x550221[_0xbd64('0x44')]['fields']));_0x51ae42[_0xbd64('0x45')]=_0x51ae42[_0xbd64('0x45')]['length']?_0x51ae42[_0xbd64('0x45')]:_0x534091[_0xbd64('0x40')];if(!_0x550221[_0xbd64('0x44')][_0xbd64('0x47')](_0xbd64('0x48'))){_0x51ae42[_0xbd64('0x2e')]=qs[_0xbd64('0x2e')](_0x550221['query'][_0xbd64('0x2e')]);_0x51ae42['offset']=qs[_0xbd64('0x2d')](_0x550221['query'][_0xbd64('0x2d')]);}_0x51ae42[_0xbd64('0x49')]=qs[_0xbd64('0x4a')](_0x550221['query'][_0xbd64('0x4a')]);_0x51ae42['where']=qs['filters'](_['pick'](_0x550221[_0xbd64('0x44')],_0x534091[_0xbd64('0x4b')]),_0x52f401);if(_0x550221[_0xbd64('0x44')][_0xbd64('0x4c')]){_0x51ae42[_0xbd64('0x4d')]=_[_0xbd64('0x4e')](_0x51ae42[_0xbd64('0x4d')],{'$or':_['map'](_0x52f401,function(_0x59ac2d){if(_0x59ac2d[_0xbd64('0x3e')]!==_0xbd64('0x4f')){var _0x4e5efe={};_0x4e5efe[_0x59ac2d[_0xbd64('0x38')]]={'$like':'%'+_0x550221[_0xbd64('0x44')][_0xbd64('0x4c')]+'%'};return _0x4e5efe;}})});}_0x51ae42=_[_0xbd64('0x4e')]({},_0x51ae42,_0x550221[_0xbd64('0x50')]);var _0x5a6b5e={'where':_0x51ae42[_0xbd64('0x4d')]};return db[_0xbd64('0x51')][_0xbd64('0x2c')](_0x5a6b5e)[_0xbd64('0x32')](function(_0x485cd1){_0x380f32['count']=_0x485cd1;if(_0x550221[_0xbd64('0x44')][_0xbd64('0x52')]){_0x51ae42[_0xbd64('0x53')]=[{'all':!![]}];}return db[_0xbd64('0x51')][_0xbd64('0x54')](_0x51ae42);})[_0xbd64('0x32')](function(_0x49cd2f){_0x380f32[_0xbd64('0x55')]=_0x49cd2f;return _0x380f32;})[_0xbd64('0x32')](respondWithFilteredResult(_0x107da1,_0x51ae42))[_0xbd64('0x29')](handleError(_0x107da1,null));};exports[_0xbd64('0x56')]=function(_0x3027bb,_0x3f81d8){var _0x152816={'raw':![],'where':{'id':_0x3027bb['params']['id']},'include':[{'model':db[_0xbd64('0x3b')],'as':'mandatoryDispositionPause'}]},_0x5dd6b6={};_0x5dd6b6['model']=_['keys'](db['WhatsappAccount'][_0xbd64('0x3d')]);_0x5dd6b6[_0xbd64('0x44')]=_['keys'](_0x3027bb[_0xbd64('0x44')]);_0x5dd6b6[_0xbd64('0x4b')]=_[_0xbd64('0x43')](_0x5dd6b6['model'],_0x5dd6b6[_0xbd64('0x44')]);_0x152816[_0xbd64('0x45')]=_[_0xbd64('0x43')](_0x5dd6b6[_0xbd64('0x40')],qs[_0xbd64('0x46')](_0x3027bb[_0xbd64('0x44')]['fields']));_0x152816['attributes']=_0x152816['attributes'][_0xbd64('0x57')]?_0x152816[_0xbd64('0x45')]:_0x5dd6b6[_0xbd64('0x40')];if(_0x3027bb[_0xbd64('0x44')]['includeAll']){_0x152816[_0xbd64('0x53')]=[{'all':!![]}];}_0x152816=_[_0xbd64('0x4e')]({},_0x152816,_0x3027bb[_0xbd64('0x50')]);return db[_0xbd64('0x51')][_0xbd64('0x58')](_0x152816)[_0xbd64('0x32')](handleEntityNotFound(_0x3f81d8,null))['then'](respondWithResult(_0x3f81d8,null))[_0xbd64('0x29')](handleError(_0x3f81d8,null));};exports[_0xbd64('0x59')]=function(_0x15f1fc,_0x1fe3e5){return db[_0xbd64('0x51')][_0xbd64('0x59')](_0x15f1fc[_0xbd64('0x5a')],{})[_0xbd64('0x32')](function(_0x430566){var _0x1e8e1c=_0x15f1fc[_0xbd64('0x5b')][_0xbd64('0x34')]({'plain':!![]});if(!_0x1e8e1c)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x1e8e1c['role']===_0xbd64('0x5b')){var _0x2bcf68=_0x430566['get']({'plain':!![]});var _0x550f5f=_0xbd64('0x5c');return db[_0xbd64('0x5d')]['find']({'where':{'name':_0x550f5f,'userProfileId':_0x1e8e1c[_0xbd64('0x5e')]},'raw':!![]})[_0xbd64('0x32')](function(_0x45573c){if(_0x45573c&&_0x45573c[_0xbd64('0x5f')]===0x0){return db[_0xbd64('0x60')][_0xbd64('0x59')]({'name':_0x2bcf68[_0xbd64('0x38')],'resourceId':_0x2bcf68['id'],'type':_0x45573c[_0xbd64('0x38')],'sectionId':_0x45573c['id']},{})[_0xbd64('0x32')](function(){return _0x430566;});}else{return _0x430566;}})['catch'](function(_0x358ba8){logger[_0xbd64('0x26')](_0xbd64('0x61'),_0x358ba8);throw _0x358ba8;});}return _0x430566;})['then'](respondWithResult(_0x1fe3e5,0xc9))[_0xbd64('0x29')](handleError(_0x1fe3e5,null));};exports[_0xbd64('0x31')]=function(_0x4aa83e,_0x4423d9){if(_0x4aa83e[_0xbd64('0x5a')]['id']){delete _0x4aa83e[_0xbd64('0x5a')]['id'];}return db[_0xbd64('0x51')][_0xbd64('0x58')]({'where':{'id':_0x4aa83e[_0xbd64('0x62')]['id']},'include':[{'model':db['Pause'],'as':_0xbd64('0x3c')}]})[_0xbd64('0x32')](handleEntityNotFound(_0x4423d9,null))[_0xbd64('0x32')](saveUpdates(_0x4aa83e[_0xbd64('0x5a')],null))['then'](respondWithResult(_0x4423d9,null))[_0xbd64('0x29')](handleError(_0x4423d9,null));};exports[_0xbd64('0x33')]=function(_0x502d84,_0x78d88){return db['WhatsappAccount'][_0xbd64('0x58')]({'where':{'id':_0x502d84[_0xbd64('0x62')]['id']}})[_0xbd64('0x32')](handleEntityNotFound(_0x78d88,null))[_0xbd64('0x32')](removeEntity(_0x78d88,null))['catch'](handleError(_0x78d88,null));};exports[_0xbd64('0x63')]=function(_0x54a3b1,_0x30bdef){return db[_0xbd64('0x51')][_0xbd64('0x63')]()[_0xbd64('0x32')](respondWithResult(_0x30bdef,null))['catch'](handleError(_0x30bdef,null));};exports['addDisposition']=function(_0x5616bc,_0x36f3a8,_0xd1b21f){if(_0x5616bc[_0xbd64('0x5a')]['id']){delete _0x5616bc[_0xbd64('0x5a')]['id'];}return db[_0xbd64('0x51')][_0xbd64('0x58')]({'where':{'id':_0x5616bc['params']['id']}})[_0xbd64('0x32')](handleEntityNotFound(_0x36f3a8,null))[_0xbd64('0x32')](function(_0x305ffc){if(_0x305ffc){_0x5616bc[_0xbd64('0x5a')][_0xbd64('0x64')]=_0x305ffc['id'];return db[_0xbd64('0x65')][_0xbd64('0x59')](_0x5616bc[_0xbd64('0x5a')]);}})[_0xbd64('0x32')](respondWithResult(_0x36f3a8,null))[_0xbd64('0x29')](handleError(_0x36f3a8,null));};exports[_0xbd64('0x66')]=function(_0x582c85,_0x48f1a5,_0x5f16fd){var _0x7e5c1c={'raw':![],'where':{}};var _0x363da8={};var _0x2ec631={'count':0x0,'rows':[]};return db['WhatsappAccount'][_0xbd64('0x67')]({'where':{'id':_0x582c85['params']['id']}})[_0xbd64('0x32')](handleEntityNotFound(_0x48f1a5,null))[_0xbd64('0x32')](function(_0x1c2930){if(_0x1c2930){_0x363da8[_0xbd64('0x40')]=_['keys'](db[_0xbd64('0x65')]['rawAttributes']);_0x363da8[_0xbd64('0x44')]=_[_0xbd64('0x42')](_0x582c85[_0xbd64('0x44')]);_0x363da8[_0xbd64('0x4b')]=_[_0xbd64('0x43')](_0x363da8['model'],_0x363da8[_0xbd64('0x44')]);_0x7e5c1c[_0xbd64('0x45')]=_['intersection'](_0x363da8[_0xbd64('0x40')],qs[_0xbd64('0x46')](_0x582c85[_0xbd64('0x44')][_0xbd64('0x46')]));_0x7e5c1c['attributes']=_0x7e5c1c[_0xbd64('0x45')]['length']?_0x7e5c1c[_0xbd64('0x45')]:_0x363da8[_0xbd64('0x40')];if(!_0x582c85[_0xbd64('0x44')]['hasOwnProperty']('nolimit')){_0x7e5c1c['limit']=qs['limit'](_0x582c85[_0xbd64('0x44')][_0xbd64('0x2e')]);_0x7e5c1c[_0xbd64('0x2d')]=qs[_0xbd64('0x2d')](_0x582c85[_0xbd64('0x44')]['offset']);}_0x7e5c1c[_0xbd64('0x49')]=qs[_0xbd64('0x4a')](_0x582c85[_0xbd64('0x44')][_0xbd64('0x4a')]);_0x7e5c1c[_0xbd64('0x4d')]=qs['filters'](_[_0xbd64('0x68')](_0x582c85[_0xbd64('0x44')],_0x363da8[_0xbd64('0x4b')]));_0x7e5c1c[_0xbd64('0x4d')]['WhatsappAccountId']=_0x1c2930['id'];if(_0x582c85['query'][_0xbd64('0x4c')]){_0x7e5c1c[_0xbd64('0x4d')]=_[_0xbd64('0x4e')](_0x7e5c1c[_0xbd64('0x4d')],{'$or':_[_0xbd64('0x41')](_0x7e5c1c[_0xbd64('0x45')],function(_0x86124){var _0x344285={};_0x344285[_0x86124]={'$like':'%'+_0x582c85['query'][_0xbd64('0x4c')]+'%'};return _0x344285;})});}_0x7e5c1c=_['merge']({},_0x7e5c1c,_0x582c85[_0xbd64('0x50')]);return db[_0xbd64('0x65')][_0xbd64('0x2c')]({'where':_0x7e5c1c['where']})[_0xbd64('0x32')](function(_0x5c30f9){_0x2ec631['count']=_0x5c30f9;if(_0x582c85[_0xbd64('0x44')][_0xbd64('0x52')]){_0x7e5c1c[_0xbd64('0x53')]=[{'all':!![]}];}return db['Disposition'][_0xbd64('0x54')](_0x7e5c1c);})[_0xbd64('0x32')](function(_0x8150bb){_0x2ec631[_0xbd64('0x55')]=_0x8150bb;return _0x2ec631;});}})['then'](respondWithFilteredResult(_0x48f1a5,_0x7e5c1c))[_0xbd64('0x29')](handleError(_0x48f1a5,null));};exports[_0xbd64('0x69')]=function(_0x355b87,_0x1964f9,_0x339e52){return db[_0xbd64('0x51')][_0xbd64('0x58')]({'where':{'id':_0x355b87[_0xbd64('0x62')]['id']}})[_0xbd64('0x32')](handleEntityNotFound(_0x1964f9,null))[_0xbd64('0x32')](function(_0x3f49f3){if(_0x3f49f3){return _0x3f49f3[_0xbd64('0x69')](_0x355b87[_0xbd64('0x44')][_0xbd64('0x6a')]);}})['then'](respondWithStatusCode(_0x1964f9,null))['catch'](handleError(_0x1964f9,null));};exports[_0xbd64('0x6b')]=function(_0x322093,_0x155b41,_0x586056){if(_0x322093[_0xbd64('0x5a')]['id']){delete _0x322093['body']['id'];}return db[_0xbd64('0x51')][_0xbd64('0x58')]({'where':{'id':_0x322093[_0xbd64('0x62')]['id']}})[_0xbd64('0x32')](handleEntityNotFound(_0x155b41,null))['then'](function(_0x44ecf9){if(_0x44ecf9){_0x322093[_0xbd64('0x5a')]['WhatsappAccountId']=_0x44ecf9['id'];return db[_0xbd64('0x6c')]['create'](_0x322093[_0xbd64('0x5a')]);}})[_0xbd64('0x32')](respondWithResult(_0x155b41,null))[_0xbd64('0x29')](handleError(_0x155b41,null));};exports[_0xbd64('0x6d')]=function(_0x30b3a1,_0x38b974,_0x53717e){var _0x4190a3={'raw':![],'where':{}};var _0x588452={};var _0x366672={'count':0x0,'rows':[]};return db[_0xbd64('0x51')]['findOne']({'where':{'id':_0x30b3a1[_0xbd64('0x62')]['id']}})['then'](handleEntityNotFound(_0x38b974,null))[_0xbd64('0x32')](function(_0x2ac722){if(_0x2ac722){_0x588452[_0xbd64('0x40')]=_['keys'](db[_0xbd64('0x6c')][_0xbd64('0x3d')]);_0x588452[_0xbd64('0x44')]=_[_0xbd64('0x42')](_0x30b3a1[_0xbd64('0x44')]);_0x588452['filters']=_['intersection'](_0x588452[_0xbd64('0x40')],_0x588452[_0xbd64('0x44')]);_0x4190a3[_0xbd64('0x45')]=_[_0xbd64('0x43')](_0x588452[_0xbd64('0x40')],qs[_0xbd64('0x46')](_0x30b3a1[_0xbd64('0x44')][_0xbd64('0x46')]));_0x4190a3[_0xbd64('0x45')]=_0x4190a3[_0xbd64('0x45')][_0xbd64('0x57')]?_0x4190a3[_0xbd64('0x45')]:_0x588452[_0xbd64('0x40')];if(!_0x30b3a1['query'][_0xbd64('0x47')](_0xbd64('0x48'))){_0x4190a3['limit']=qs[_0xbd64('0x2e')](_0x30b3a1[_0xbd64('0x44')][_0xbd64('0x2e')]);_0x4190a3[_0xbd64('0x2d')]=qs['offset'](_0x30b3a1['query'][_0xbd64('0x2d')]);}_0x4190a3[_0xbd64('0x49')]=qs[_0xbd64('0x4a')](_0x30b3a1[_0xbd64('0x44')][_0xbd64('0x4a')]);_0x4190a3[_0xbd64('0x4d')]=qs[_0xbd64('0x4b')](_[_0xbd64('0x68')](_0x30b3a1[_0xbd64('0x44')],_0x588452[_0xbd64('0x4b')]));_0x4190a3[_0xbd64('0x4d')][_0xbd64('0x64')]=_0x2ac722['id'];if(_0x30b3a1['query'][_0xbd64('0x4c')]){_0x4190a3[_0xbd64('0x4d')]=_[_0xbd64('0x4e')](_0x4190a3['where'],{'$or':_['map'](_0x4190a3[_0xbd64('0x45')],function(_0x2dbbd4){var _0x5d9b13={};_0x5d9b13[_0x2dbbd4]={'$like':'%'+_0x30b3a1[_0xbd64('0x44')][_0xbd64('0x4c')]+'%'};return _0x5d9b13;})});}_0x4190a3=_[_0xbd64('0x4e')]({},_0x4190a3,_0x30b3a1[_0xbd64('0x50')]);return db[_0xbd64('0x6c')][_0xbd64('0x2c')]({'where':_0x4190a3[_0xbd64('0x4d')]})[_0xbd64('0x32')](function(_0x2686fe){_0x366672[_0xbd64('0x2c')]=_0x2686fe;if(_0x30b3a1[_0xbd64('0x44')][_0xbd64('0x52')]){_0x4190a3['include']=[{'all':!![]}];}return db[_0xbd64('0x6c')]['findAll'](_0x4190a3);})[_0xbd64('0x32')](function(_0x25d8d8){_0x366672[_0xbd64('0x55')]=_0x25d8d8;return _0x366672;});}})[_0xbd64('0x32')](respondWithFilteredResult(_0x38b974,_0x4190a3))[_0xbd64('0x29')](handleError(_0x38b974,null));};exports['removeAnswers']=function(_0x219149,_0x357ac2,_0x72185e){return db[_0xbd64('0x51')]['find']({'where':{'id':_0x219149[_0xbd64('0x62')]['id']}})['then'](handleEntityNotFound(_0x357ac2,null))[_0xbd64('0x32')](function(_0x993847){if(_0x993847){return _0x993847[_0xbd64('0x6e')](_0x219149[_0xbd64('0x44')][_0xbd64('0x6a')]);}})[_0xbd64('0x32')](respondWithStatusCode(_0x357ac2,null))[_0xbd64('0x29')](handleError(_0x357ac2,null));};exports['addAgents']=function(_0x2824dc,_0x2c640e,_0x33cfc8){return db[_0xbd64('0x51')]['find']({'where':{'id':_0x2824dc[_0xbd64('0x62')]['id']}})[_0xbd64('0x32')](handleEntityNotFound(_0x2c640e,null))[_0xbd64('0x32')](function(_0x19a780){if(_0x19a780){return _0x19a780[_0xbd64('0x6f')](_0x2824dc[_0xbd64('0x5a')][_0xbd64('0x6a')],_['omit'](_0x2824dc[_0xbd64('0x5a')],['ids','id'])||{})[_0xbd64('0x70')](function(_0x59cc30){for(var _0x4a7220=0x0;_0x4a7220<_0x2824dc[_0xbd64('0x5a')][_0xbd64('0x6a')][_0xbd64('0x57')];_0x4a7220+=0x1){socket['emit'](_0xbd64('0x71'),{'UserId':_0x2824dc['body'][_0xbd64('0x6a')][_0x4a7220],'WhatsappAccountId':_0x2824dc['params']['id']});}return _0x59cc30;});}})['then'](respondWithResult(_0x2c640e,null))[_0xbd64('0x29')](handleError(_0x2c640e,null));};exports[_0xbd64('0x72')]=function(_0x30a8b4,_0x310ee4,_0x34c941){return db[_0xbd64('0x51')][_0xbd64('0x58')]({'where':{'id':_0x30a8b4[_0xbd64('0x62')]['id']}})['then'](handleEntityNotFound(_0x310ee4,null))['then'](function(_0xd7e9dd){if(_0xd7e9dd){return _0xd7e9dd['removeAgents'](_0x30a8b4[_0xbd64('0x44')][_0xbd64('0x6a')])[_0xbd64('0x32')](function(){if(_['isArray'](_0x30a8b4[_0xbd64('0x44')][_0xbd64('0x6a')])){for(var _0x5f4e47=0x0;_0x5f4e47<_0x30a8b4[_0xbd64('0x44')][_0xbd64('0x6a')]['length'];_0x5f4e47+=0x1){socket['emit'](_0xbd64('0x73'),{'UserId':Number(_0x30a8b4[_0xbd64('0x44')][_0xbd64('0x6a')][_0x5f4e47]),'WhatsappAccountId':Number(_0x30a8b4[_0xbd64('0x62')]['id'])});}}else{socket[_0xbd64('0x74')](_0xbd64('0x73'),{'UserId':Number(_0x30a8b4[_0xbd64('0x44')][_0xbd64('0x6a')]),'WhatsappAccountId':Number(_0x30a8b4[_0xbd64('0x62')]['id'])});}});}})[_0xbd64('0x32')](respondWithStatusCode(_0x310ee4,null))[_0xbd64('0x29')](handleError(_0x310ee4,null));};exports[_0xbd64('0x75')]=function(_0x1f630b,_0x2d1f0c,_0x2419b7){var _0x5568cd={};var _0x2a6b2f={};var _0x4dda62;var _0x2a59da;return db[_0xbd64('0x51')]['findOne']({'where':{'id':_0x1f630b[_0xbd64('0x62')]['id']}})['then'](handleEntityNotFound(_0x2d1f0c,null))[_0xbd64('0x32')](function(_0x1fb323){if(_0x1fb323){_0x4dda62=_0x1fb323;_0x2a6b2f[_0xbd64('0x40')]=_[_0xbd64('0x42')](db['User'][_0xbd64('0x3d')]);_0x2a6b2f[_0xbd64('0x44')]=_[_0xbd64('0x42')](_0x1f630b[_0xbd64('0x44')]);_0x2a6b2f['filters']=_['intersection'](_0x2a6b2f[_0xbd64('0x40')],_0x2a6b2f[_0xbd64('0x44')]);_0x5568cd[_0xbd64('0x45')]=_['intersection'](_0x2a6b2f[_0xbd64('0x40')],qs['fields'](_0x1f630b[_0xbd64('0x44')][_0xbd64('0x46')]));_0x5568cd[_0xbd64('0x45')]=_0x5568cd[_0xbd64('0x45')][_0xbd64('0x57')]?_0x5568cd['attributes']:_0x2a6b2f['model'];_0x5568cd[_0xbd64('0x49')]=qs[_0xbd64('0x4a')](_0x1f630b[_0xbd64('0x44')]['sort']);_0x5568cd[_0xbd64('0x4d')]=qs['filters'](_[_0xbd64('0x68')](_0x1f630b[_0xbd64('0x44')],_0x2a6b2f[_0xbd64('0x4b')]));if(_0x1f630b['query'][_0xbd64('0x4c')]){_0x5568cd[_0xbd64('0x4d')]=_['merge'](_0x5568cd['where'],{'$or':_[_0xbd64('0x41')](_0x5568cd['attributes'],function(_0x4d1a95){var _0x1442ee={};_0x1442ee[_0x4d1a95]={'$like':'%'+_0x1f630b[_0xbd64('0x44')]['filter']+'%'};return _0x1442ee;})});}_0x5568cd=_[_0xbd64('0x4e')]({},_0x5568cd,_0x1f630b['options']);return _0x4dda62[_0xbd64('0x75')](_0x5568cd);}})[_0xbd64('0x32')](function(_0x38795c){if(_0x38795c){_0x2a59da=_0x38795c['length'];if(!_0x1f630b[_0xbd64('0x44')]['hasOwnProperty']('nolimit')){_0x5568cd['limit']=qs[_0xbd64('0x2e')](_0x1f630b[_0xbd64('0x44')][_0xbd64('0x2e')]);_0x5568cd['offset']=qs[_0xbd64('0x2d')](_0x1f630b['query'][_0xbd64('0x2d')]);}return _0x4dda62['getAgents'](_0x5568cd);}})['then'](function(_0x5415ed){if(_0x5415ed){return _0x5415ed?{'count':_0x2a59da,'rows':_0x5415ed}:null;}})[_0xbd64('0x32')](respondWithResult(_0x2d1f0c,null))[_0xbd64('0x29')](handleError(_0x2d1f0c,null));};exports[_0xbd64('0x76')]=function(_0x2ccf8d,_0x4d6781,_0x4094b8){return db[_0xbd64('0x51')][_0xbd64('0x67')]({'where':{'id':_0x2ccf8d['params']['id']}})[_0xbd64('0x32')](handleEntityNotFound(_0x4d6781,null))['then'](function(_0x142436){if(_0x142436){return db[_0xbd64('0x77')][_0xbd64('0x78')](function(_0x27ae4b){return db[_0xbd64('0x79')][_0xbd64('0x33')]({'where':{'WhatsappAccountId':_0x2ccf8d[_0xbd64('0x62')]['id']},'transaction':_0x27ae4b})[_0xbd64('0x32')](function(_0x3bc73d){var _0x871906=_[_0xbd64('0x41')](_0x2ccf8d[_0xbd64('0x5a')],function(_0x103561){_0x103561['WhatsappAccountId']=_0x2ccf8d['params']['id'];return _0x103561;});return db[_0xbd64('0x79')][_0xbd64('0x7a')](_0x871906,{'transaction':_0x27ae4b});});})[_0xbd64('0x32')](function(){return db[_0xbd64('0x79')]['findAndCountAll']({'where':{'WhatsappAccountId':_0x2ccf8d[_0xbd64('0x62')]['id']},'order':'priority'});});}})[_0xbd64('0x32')](respondWithResult(_0x4d6781,null))['catch'](handleError(_0x4d6781,null));};exports['getApplications']=function(_0x421cd3,_0x762409,_0x58c849){var _0x2058c5={};var _0x494908={};var _0x40ff49;var _0x592e2c;return db[_0xbd64('0x51')][_0xbd64('0x67')]({'where':{'id':_0x421cd3[_0xbd64('0x62')]['id']}})['then'](handleEntityNotFound(_0x762409,null))[_0xbd64('0x32')](function(_0x287a9a){if(_0x287a9a){_0x40ff49=_0x287a9a;_0x494908[_0xbd64('0x40')]=_[_0xbd64('0x42')](db[_0xbd64('0x79')][_0xbd64('0x3d')]);_0x494908[_0xbd64('0x44')]=_['keys'](_0x421cd3[_0xbd64('0x44')]);_0x494908[_0xbd64('0x4b')]=_['intersection'](_0x494908['model'],_0x494908['query']);_0x2058c5[_0xbd64('0x45')]=_[_0xbd64('0x43')](_0x494908[_0xbd64('0x40')],qs['fields'](_0x421cd3[_0xbd64('0x44')]['fields']));_0x2058c5[_0xbd64('0x45')]=_0x2058c5['attributes'][_0xbd64('0x57')]?_0x2058c5[_0xbd64('0x45')]:_0x494908[_0xbd64('0x40')];_0x2058c5[_0xbd64('0x49')]=qs[_0xbd64('0x4a')](_0x421cd3[_0xbd64('0x44')][_0xbd64('0x4a')]);_0x2058c5[_0xbd64('0x4d')]=qs[_0xbd64('0x4b')](_[_0xbd64('0x68')](_0x421cd3[_0xbd64('0x44')],_0x494908['filters']));if(_0x421cd3[_0xbd64('0x44')][_0xbd64('0x4c')]){_0x2058c5[_0xbd64('0x4d')]=_[_0xbd64('0x4e')](_0x2058c5[_0xbd64('0x4d')],{'$or':_[_0xbd64('0x41')](_0x2058c5[_0xbd64('0x45')],function(_0x27eb30){var _0x2f97b5={};_0x2f97b5[_0x27eb30]={'$like':'%'+_0x421cd3['query']['filter']+'%'};return _0x2f97b5;})});}_0x2058c5=_[_0xbd64('0x4e')]({},_0x2058c5,_0x421cd3[_0xbd64('0x50')]);return _0x40ff49['getApplications'](_0x2058c5);}})[_0xbd64('0x32')](function(_0x2b78b4){if(_0x2b78b4){_0x592e2c=_0x2b78b4['length'];if(!_0x421cd3[_0xbd64('0x44')]['hasOwnProperty'](_0xbd64('0x48'))){_0x2058c5[_0xbd64('0x2e')]=qs[_0xbd64('0x2e')](_0x421cd3[_0xbd64('0x44')][_0xbd64('0x2e')]);_0x2058c5['offset']=qs['offset'](_0x421cd3['query']['offset']);}return _0x40ff49[_0xbd64('0x7b')](_0x2058c5);}})['then'](function(_0x3cf54a){if(_0x3cf54a){return _0x3cf54a?{'count':_0x592e2c,'rows':_0x3cf54a}:null;}})['then'](respondWithResult(_0x762409,null))['catch'](handleError(_0x762409,null));};exports[_0xbd64('0x7c')]=function(_0x1bcc1c,_0x45cbb6,_0x302596){var _0x24f5c0={'channel':_0xbd64('0x7d')};var _0x13fae5=[];var _0xf95ff=[];var _0x14bb25={};return db[_0xbd64('0x51')][_0xbd64('0x58')]({'where':{'id':_0x1bcc1c[_0xbd64('0x62')]['id']},'include':[{'model':db['WhatsappApplication'],'as':_0xbd64('0x7e')}]})[_0xbd64('0x32')](handleEntityNotFound(_0x45cbb6,null))[_0xbd64('0x32')](function(_0x3d2e6a){_0x24f5c0[_0xbd64('0x7f')]=_0x3d2e6a;_0x24f5c0[_0xbd64('0x80')]=_['orderBy'](_0x3d2e6a[_0xbd64('0x7e')],[_0xbd64('0x81')],[_0xbd64('0x82')]);if(_0x24f5c0[_0xbd64('0x7f')]['Applications']){delete _0x24f5c0[_0xbd64('0x7f')][_0xbd64('0x7e')];}return db[_0xbd64('0x83')][_0xbd64('0x63')]();})['then'](function(_0x3ac365){if(!_0x3ac365){throw new db['Sequelize']['ValidationError']('no\x20available\x20attributes');}_0x13fae5=_[_0xbd64('0x84')](_[_0xbd64('0x42')](_0x3ac365),['createdAt','updatedAt']);_0xf95ff=_[_0xbd64('0x84')](_[_0xbd64('0x42')](_0x3ac365),[_0xbd64('0x85'),_0xbd64('0x86'),'CompanyId','ListId']);_0x24f5c0[_0xbd64('0x5a')]={'mapKey':'mobile'};if(_0x24f5c0[_0xbd64('0x7f')]['type']&&_0x24f5c0[_0xbd64('0x7f')][_0xbd64('0x3e')]===_0xbd64('0x87')){_0x24f5c0[_0xbd64('0x5a')]['from']=_0x1bcc1c[_0xbd64('0x5a')][_0xbd64('0x88')][_0xbd64('0x89')](_0xbd64('0x8a'),'');_0x24f5c0['body'][_0xbd64('0x5a')]=_0x1bcc1c[_0xbd64('0x5a')][_0xbd64('0x8b')];_0x24f5c0[_0xbd64('0x5a')][_0xbd64('0x8c')]=_0x1bcc1c[_0xbd64('0x5a')][_0xbd64('0x8d')];}if(_0x24f5c0[_0xbd64('0x5a')]['id']){delete _0x24f5c0[_0xbd64('0x5a')]['id'];}if(_['isNil'](_0x24f5c0['body'][_0xbd64('0x8e')])){throw new db['Sequelize'][(_0xbd64('0x1f'))](_0xbd64('0x8f'));}if(_[_0xbd64('0x90')](_0x24f5c0['body']['body'])||_0x24f5c0[_0xbd64('0x5a')][_0xbd64('0x5a')]===''){throw new db[(_0xbd64('0x91'))][(_0xbd64('0x1f'))](_0xbd64('0x92'));}if(_[_0xbd64('0x90')](_0x24f5c0[_0xbd64('0x5a')][_0xbd64('0x93')])){throw new db[(_0xbd64('0x91'))]['ValidationError']('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0xf95ff);}if(!_[_0xbd64('0x94')](_0xf95ff,_0x24f5c0[_0xbd64('0x5a')][_0xbd64('0x93')])){throw new db[(_0xbd64('0x91'))]['ValidationError'](_0xbd64('0x95')+_0xf95ff);}_0x14bb25[_0x24f5c0['body'][_0xbd64('0x93')]]=_0x24f5c0['body'][_0xbd64('0x8e')];return db['CmList'][_0xbd64('0x58')]({'where':{'id':_0x24f5c0[_0xbd64('0x7f')][_0xbd64('0x96')]},'include':[{'model':db[_0xbd64('0x83')],'as':_0xbd64('0x97'),'where':_0x14bb25,'limit':0x1,'order':[[_0xbd64('0x86'),'DESC']]}]});})[_0xbd64('0x32')](handleEntityNotFound(_0x45cbb6,null))['then'](function(_0x2b3440){if(_0x2b3440){_0x24f5c0['list']=_['omit'](_0x2b3440,[_0xbd64('0x97')]);if(_0x2b3440[_0xbd64('0x97')][_0xbd64('0x57')]){return _0x2b3440['Contacts'][0x0];}var _0x4680fb=_[_0xbd64('0x16')](_0x24f5c0[_0xbd64('0x5a')],{'firstName':_0x24f5c0[_0xbd64('0x5a')][_0xbd64('0x8e')],'ListId':_0x2b3440['id']});_0x4680fb[_0x24f5c0['body'][_0xbd64('0x93')]]=_0x24f5c0['body']['from'];return db[_0xbd64('0x83')][_0xbd64('0x59')](_0x4680fb,{'fields':_0x13fae5,'raw':!![]});}})[_0xbd64('0x32')](handleEntityNotFound(_0x45cbb6,null))[_0xbd64('0x32')](function(_0x291a3e){if(_0x291a3e){_0x24f5c0[_0xbd64('0x98')]=_0x291a3e;var _0x18acee={'ContactId':_0x291a3e['id'],'phone':_0x24f5c0[_0xbd64('0x5a')][_0xbd64('0x8e')],'WhatsappAccountId':_0x1bcc1c[_0xbd64('0x62')]['id']};var _0x46e995={'ContactId':_0x291a3e['id'],'WhatsappAccountId':_0x1bcc1c['params']['id'],'closed':![]};return db[_0xbd64('0x99')][_0xbd64('0x58')]({'where':_0x46e995})[_0xbd64('0x32')](function(_0xeca842){if(_0xeca842){return[_0xeca842,![]];}return db['WhatsappInteraction'][_0xbd64('0x59')](_0x18acee)[_0xbd64('0x32')](function(_0x4a6ea9){return[_0x4a6ea9,!![]];});});}})['spread'](function(_0x34e543,_0x19ccdb){_0x24f5c0[_0xbd64('0x9a')]=_0x34e543[_0xbd64('0x34')]({'plain':!![]});_0x24f5c0[_0xbd64('0x9a')][_0xbd64('0x9b')]=![];if(_0x19ccdb){if(_0x24f5c0['account'][_0xbd64('0x9c')]){_0x24f5c0[_0xbd64('0x80')][_0xbd64('0x9d')]({'id':0x0,'priority':_0x24f5c0[_0xbd64('0x80')]['length']+0x1,'app':_0xbd64('0x9e'),'appdata':'unmanaged','interval':_0xbd64('0x9f')});}_0x24f5c0[_0xbd64('0x9a')][_0xbd64('0x9b')]=!![];}return db[_0xbd64('0xa0')]['create']({'phone':_0x24f5c0[_0xbd64('0x5a')]['from'],'messageId':_0x24f5c0[_0xbd64('0x5a')]['messageId'],'body':_0x24f5c0[_0xbd64('0x5a')]['body'],'WhatsappAccountId':_0x1bcc1c[_0xbd64('0x62')]['id'],'WhatsappInteractionId':_0x34e543['id'],'direction':'in','ContactId':_0x34e543[_0xbd64('0xa1')],'AttachmentId':_0x24f5c0['body'][_0xbd64('0xa2')]});})[_0xbd64('0x32')](function(_0x530305){_0x24f5c0[_0xbd64('0x28')]=_0x530305;if(_0x24f5c0[_0xbd64('0x9a')][_0xbd64('0xa3')]){return db['User'][_0xbd64('0x58')]({'attributes':['id',_0xbd64('0x38')],'where':{'id':_0x24f5c0[_0xbd64('0x9a')]['UserId']}})[_0xbd64('0x32')](function(_0x46f980){if(_0x46f980){_0x24f5c0['applications']['unshift']({'id':0x0,'priority':0x0,'app':_0xbd64('0xa4'),'appdata':_0x46f980['name']+','+(_0x24f5c0['account'][_0xbd64('0xa5')]||0xa),'interval':_0xbd64('0x9f')});}return respondWithRpcPromise(_0xbd64('0xa6'),'startRouting',_0x24f5c0);});}return respondWithRpcPromise(_0xbd64('0xa6'),'startRouting',_0x24f5c0);})[_0xbd64('0x32')](function(_0x4f6ace){if(_0x4f6ace){var _0x45f692=0xc8;var _0x1a899a='receiveMessage';logger[_0xbd64('0x21')](_0xbd64('0x23'),_0x1a899a,_0x45f692,_0xbd64('0xa7'));logger[_0xbd64('0x22')](_0xbd64('0xa8'),_0x1a899a,_0x45f692,_0xbd64('0xa7'),JSON['stringify'](_0x4f6ace));if(_0x24f5c0[_0xbd64('0x7f')][_0xbd64('0x3e')]===_0xbd64('0x87')){return _0x45cbb6[_0xbd64('0x2a')](_0x45f692)[_0xbd64('0xa9')](_0xbd64('0xaa'),'text/xml')['send'](_0xbd64('0xab'));}else{return _0x45cbb6[_0xbd64('0x2a')](_0x45f692)[_0xbd64('0x2b')](_0x4f6ace);}}})['catch'](handleError(_0x45cbb6,null));};exports[_0xbd64('0x39')]=function(_0x2ab4d7,_0x3067fa,_0x3a35ad){var _0xa573d0,_0x46c4a4,_0x5a0256;if(_['isNil'](_0x2ab4d7[_0xbd64('0x5a')][_0xbd64('0x5a')])||_0x2ab4d7[_0xbd64('0x5a')][_0xbd64('0x5a')]===''){throw new db['Sequelize']['ValidationError']('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0xbd64('0x90')](_0x2ab4d7['body']['to'])){throw new db[(_0xbd64('0x91'))][(_0xbd64('0x1f'))](_0xbd64('0xac'));}_0xa573d0=_0x2ab4d7['body']['to'];return db[_0xbd64('0x51')][_0xbd64('0x58')]({'where':{'id':_0x2ab4d7[_0xbd64('0x62')]['id']},'include':[{'model':db[_0xbd64('0xad')],'as':_0xbd64('0xae'),'include':[{'model':db[_0xbd64('0x83')],'as':_0xbd64('0x97'),'where':{'mobile':_0xa573d0},'limit':0x1,'order':[[_0xbd64('0x86'),_0xbd64('0xaf')]]}]}]})[_0xbd64('0x32')](handleEntityNotFound(_0x3067fa,null))[_0xbd64('0x32')](function(_0x3dc17f){if(_0x3dc17f&&_0x3dc17f[_0xbd64('0xae')]){_0x46c4a4=_0x3dc17f['get']({'plain':!![]});if(_0x46c4a4[_0xbd64('0xae')]&&_0x46c4a4['List'][_0xbd64('0x97')][_0xbd64('0x57')]){return _0x46c4a4[_0xbd64('0xae')][_0xbd64('0x97')][0x0];}return db[_0xbd64('0x83')][_0xbd64('0x59')](_['defaults'](_0x2ab4d7['body'],{'firstName':_0xa573d0,'mobile':_0xa573d0,'phone':_0xa573d0,'ListId':_0x46c4a4['ListId']}));}})['then'](handleEntityNotFound(_0x3067fa,null))[_0xbd64('0x32')](function(_0x82132a){if(_0x82132a){_0x5a0256=_0x82132a;return db[_0xbd64('0x99')][_0xbd64('0x58')]({'where':{'ContactId':_0x5a0256['id'],'closed':![],'WhatsappAccountId':_0x46c4a4['id']}})[_0xbd64('0x32')](function(_0x35d11f){if(_0x35d11f){return[_0x35d11f,![]];}return db[_0xbd64('0x99')][_0xbd64('0x59')]({'UserId':_0x2ab4d7['user']['id'],'ContactId':_0x5a0256['id'],'WhatsappAccountId':_0x46c4a4['id'],'phone':_0xa573d0,'firstMsgDirection':_0xbd64('0xb0'),'Messages':[_[_0xbd64('0x4e')](_0x2ab4d7['body'],{'read':![],'body':_0x2ab4d7[_0xbd64('0x5a')][_0xbd64('0x5a')],'phone':_0xa573d0,'WhatsappAccountId':_0x46c4a4['id'],'UserId':_0x2ab4d7[_0xbd64('0x5b')]['id'],'ContactId':_0x5a0256['id']})]},{'include':[{'model':db[_0xbd64('0xa0')],'as':_0xbd64('0xb1')}]})[_0xbd64('0x32')](function(_0x1981f6){return[_0x1981f6,!![]];});});}})[_0xbd64('0x70')](function(_0x2635a9,_0x42ef5f){if(_0x42ef5f){return _0x2635a9;}return db[_0xbd64('0xa0')]['create'](_[_0xbd64('0x4e')](_0x2ab4d7[_0xbd64('0x5a')],{'read':![],'body':_0x2ab4d7[_0xbd64('0x5a')]['body'],'phone':_0xa573d0,'WhatsappAccountId':_0x46c4a4['id'],'WhatsappInteractionId':_0x2635a9['id'],'UserId':_0x2ab4d7[_0xbd64('0x5b')]['id'],'ContactId':_0x5a0256['id']}))['then'](function(_0x35505f){_0x2635a9[_0xbd64('0xb2')][_0xbd64('0xb1')]=[];_0x2635a9['dataValues']['Messages'][_0xbd64('0x9d')](_0x35505f[_0xbd64('0xb2')]);return _0x2635a9;});})['then'](respondWithResult(_0x3067fa,null))[_0xbd64('0x29')](handleError(_0x3067fa,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