Built motion from commit (unavailable).|2.5.6
[motion2.git] / server / api / whatsappAccount / whatsappAccount.controller.js
index 3513b9d..bf7b1ff 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xd59e=['intersection','model','attributes','query','fields','length','hasOwnProperty','nolimit','sort','pick','filter','where','VIRTUAL','options','WhatsappAccount','include','findAll','rows','show','params','Pause','filtears','includeAll','merge','find','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','autoAssociation','describe','WhatsappAccountId','Disposition','create','getDispositions','order','removeDispositions','ids','CannedAnswer','findOne','removeAnswers','omit','spread','userWhatsappAccount:save','removeAgents','isArray','emit','userWhatsappAccount:remove','getAgents','addApplications','transaction','bulkCreate','WhatsappApplication','findAndCountAll','getApplications','notify','whatsapp','Applications','account','priority','asc','CmContact','Sequelize','ValidationError','difference','createdAt','updatedAt','CompanyId','ListId','mobile','from','From','replace','whatsapp:','Body','messageId','MessageSid','isNil','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','Contacts','DESC','contact','WhatsappInteraction','interaction','autoclose','push','close','unmanaged','*,*,*,*','created','WhatsappMessage','AttachmentId','UserId','User','applications','unshift','Start','startRouting','receiveMessage','WhatsappAccount,\x20%s,\x20%s,\x20%s','entity\x20found','WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s','twilio','set','Content-Type','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','to\x20is\x20mandatory','List','Messages','dataValues','html-pdf','rimraf','request-promise','moment','mustache','util','path','to-csv','ejs','squel','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','register','jayson/promise','http','request','then','info','WhatsappAccount,\x20%s,\x20%s','debug','request\x20sent','stringify','error','code','message','catch','status','end','json','count','offset','limit','Content-Range','apply','reject','save','update','get','WhatsappAccounts','UserProfileResource','destroy','sendStatus','stack','name','send','index','mandatoryDispositionPause','map','rawAttributes','fieldName','type','key','keys','filters'];(function(_0xa464c9,_0x7c86d8){var _0x3d73c4=function(_0x5c2056){while(--_0x5c2056){_0xa464c9['push'](_0xa464c9['shift']());}};_0x3d73c4(++_0x7c86d8);}(_0xd59e,0x74));var _0xed59=function(_0x33149f,_0x50872a){_0x33149f=_0x33149f-0x0;var _0x540c22=_0xd59e[_0x33149f];return _0x540c22;};'use strict';var pdf=require(_0xed59('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xed59('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xed59('0x2'));var moment=require(_0xed59('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xed59('0x4'));var util=require(_0xed59('0x5'));var path=require(_0xed59('0x6'));var sox=require('sox');var csv=require(_0xed59('0x7'));var ejs=require(_0xed59('0x8'));var fs=require('fs');var _=require('lodash');var squel=require(_0xed59('0x9'));var crypto=require(_0xed59('0xa'));var jsforce=require(_0xed59('0xb'));var deskjs=require(_0xed59('0xc'));var toCsv=require(_0xed59('0x7'));var querystring=require('querystring');var Papa=require(_0xed59('0xd'));var Redis=require('ioredis');var authService=require(_0xed59('0xe'));var qs=require(_0xed59('0xf'));var as=require(_0xed59('0x10'));var hardwareService=require(_0xed59('0x11'));var logger=require(_0xed59('0x12'))(_0xed59('0x13'));var utils=require(_0xed59('0x14'));var config=require(_0xed59('0x15'));var licenseUtil=require(_0xed59('0x16'));var db=require(_0xed59('0x17'))['db'];config['redis']=_[_0xed59('0x18')](config[_0xed59('0x19')],{'host':_0xed59('0x1a'),'port':0x18eb});var socket=require(_0xed59('0x1b'))(new Redis(config[_0xed59('0x19')]));require('./whatsappAccount.socket')[_0xed59('0x1c')](socket);var jayson=require(_0xed59('0x1d'));var client=jayson['client'][_0xed59('0x1e')]({'port':0x232c});function respondWithRpcPromise(_0x18de56,_0x4aa3fe,_0x301228,_0x56ecf3){return new BPromise(function(_0x57b880,_0x1cc6f3){var _0x5161c9=_0x56ecf3||client;return _0x5161c9[_0xed59('0x1f')](_0x18de56,_0x301228)[_0xed59('0x20')](function(_0x7cee33){logger[_0xed59('0x21')](_0xed59('0x22'),_0x4aa3fe,'request\x20sent');logger[_0xed59('0x23')]('WhatsappAccount,\x20%s,\x20%s,\x20%s',_0x4aa3fe,_0xed59('0x24'),JSON[_0xed59('0x25')](_0x7cee33));if(_0x7cee33['error']){if(_0x7cee33[_0xed59('0x26')][_0xed59('0x27')]===0x1f4){logger[_0xed59('0x26')]('WhatsappAccount,\x20%s,\x20%s',_0x4aa3fe,_0x7cee33[_0xed59('0x26')][_0xed59('0x28')]);return _0x1cc6f3(_0x7cee33[_0xed59('0x26')][_0xed59('0x28')]);}logger['error'](_0xed59('0x22'),_0x4aa3fe,_0x7cee33[_0xed59('0x26')][_0xed59('0x28')]);return _0x57b880(_0x7cee33[_0xed59('0x26')]['message']);}else{logger[_0xed59('0x21')](_0xed59('0x22'),_0x4aa3fe,'request\x20sent');_0x57b880(_0x7cee33['result']['message']);}})[_0xed59('0x29')](function(_0xc3f402){logger[_0xed59('0x26')](_0xed59('0x22'),_0x4aa3fe,_0xc3f402);_0x1cc6f3(_0xc3f402);});});}function respondWithStatusCode(_0x10a15a,_0xc1b417){_0xc1b417=_0xc1b417||0xcc;return function(_0xb1aeb9){if(_0xb1aeb9){return _0x10a15a['sendStatus'](_0xc1b417);}return _0x10a15a[_0xed59('0x2a')](_0xc1b417)[_0xed59('0x2b')]();};}function respondWithResult(_0x2874b5,_0x1bee46){_0x1bee46=_0x1bee46||0xc8;return function(_0x371d07){if(_0x371d07){return _0x2874b5['status'](_0x1bee46)[_0xed59('0x2c')](_0x371d07);}};}function respondWithFilteredResult(_0x2c2a73,_0x57bc57){return function(_0x1efa4e){if(_0x1efa4e){var _0x1ee883=_0x1efa4e[_0xed59('0x2d')],_0x349a15=_0x57bc57[_0xed59('0x2e')],_0x576832=_0x57bc57['offset']+_0x57bc57[_0xed59('0x2f')],_0x5b690f;if(_0x576832>=_0x1ee883){_0x576832=_0x1ee883;_0x5b690f=0xc8;}else{_0x5b690f=0xce;}_0x2c2a73[_0xed59('0x2a')](_0x5b690f);return _0x2c2a73['set'](_0xed59('0x30'),_0x349a15+'-'+_0x576832+'/'+_0x1ee883)[_0xed59('0x2c')](_0x1efa4e);}return null;};}function patchUpdates(_0x414f9c){return function(_0x40e132){try{jsonpatch[_0xed59('0x31')](_0x40e132,_0x414f9c,!![]);}catch(_0x41d4ed){return BPromise[_0xed59('0x32')](_0x41d4ed);}return _0x40e132[_0xed59('0x33')]();};}function saveUpdates(_0x1dde25,_0x54b4fe){return function(_0x167a87){if(_0x167a87){return _0x167a87[_0xed59('0x34')](_0x1dde25)[_0xed59('0x20')](function(_0x252b0c){return _0x252b0c;});}return null;};}function removeEntity(_0xb66189,_0x2c4e17){return function(_0x518cc3){if(_0x518cc3){return _0x518cc3['destroy']()[_0xed59('0x20')](function(){var _0x2782d5=_0x518cc3[_0xed59('0x35')]({'plain':!![]});var _0xafabb6=_0xed59('0x36');return db[_0xed59('0x37')][_0xed59('0x38')]({'where':{'type':_0xafabb6,'resourceId':_0x2782d5['id']}})[_0xed59('0x20')](function(){return _0x518cc3;});})[_0xed59('0x20')](function(){_0xb66189['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x255a52,_0x5a61cc){return function(_0x3c5178){if(!_0x3c5178){_0x255a52[_0xed59('0x39')](0x194);}return _0x3c5178;};}function handleError(_0x190e55,_0x47aa0d){_0x47aa0d=_0x47aa0d||0x1f4;return function(_0x2e1fbc){logger[_0xed59('0x26')](_0x2e1fbc[_0xed59('0x3a')]);if(_0x2e1fbc['name']){delete _0x2e1fbc[_0xed59('0x3b')];}_0x190e55[_0xed59('0x2a')](_0x47aa0d)[_0xed59('0x3c')](_0x2e1fbc);};}exports[_0xed59('0x3d')]=function(_0x10ab38,_0x5e42ee){var _0x121a1b={'include':[{'model':db['Pause'],'as':_0xed59('0x3e')}]},_0x2a9ad7={},_0x2ae4c6={'count':0x0,'rows':[]};var _0x2c35e4=_[_0xed59('0x3f')](db['WhatsappAccount'][_0xed59('0x40')],function(_0x277557){return{'name':_0x277557[_0xed59('0x41')],'type':_0x277557[_0xed59('0x42')][_0xed59('0x43')]};});_0x2a9ad7['model']=_[_0xed59('0x3f')](_0x2c35e4,'name');_0x2a9ad7['query']=_[_0xed59('0x44')](_0x10ab38['query']);_0x2a9ad7[_0xed59('0x45')]=_[_0xed59('0x46')](_0x2a9ad7[_0xed59('0x47')],_0x2a9ad7['query']);_0x121a1b[_0xed59('0x48')]=_['intersection'](_0x2a9ad7['model'],qs['fields'](_0x10ab38[_0xed59('0x49')][_0xed59('0x4a')]));_0x121a1b[_0xed59('0x48')]=_0x121a1b[_0xed59('0x48')][_0xed59('0x4b')]?_0x121a1b['attributes']:_0x2a9ad7['model'];if(!_0x10ab38[_0xed59('0x49')][_0xed59('0x4c')](_0xed59('0x4d'))){_0x121a1b['limit']=qs[_0xed59('0x2f')](_0x10ab38[_0xed59('0x49')][_0xed59('0x2f')]);_0x121a1b[_0xed59('0x2e')]=qs['offset'](_0x10ab38[_0xed59('0x49')][_0xed59('0x2e')]);}_0x121a1b['order']=qs['sort'](_0x10ab38[_0xed59('0x49')][_0xed59('0x4e')]);_0x121a1b['where']=qs['filters'](_[_0xed59('0x4f')](_0x10ab38['query'],_0x2a9ad7[_0xed59('0x45')]),_0x2c35e4);if(_0x10ab38[_0xed59('0x49')][_0xed59('0x50')]){_0x121a1b[_0xed59('0x51')]=_['merge'](_0x121a1b['where'],{'$or':_[_0xed59('0x3f')](_0x2c35e4,function(_0x10e3e3){if(_0x10e3e3['type']!==_0xed59('0x52')){var _0x2968c0={};_0x2968c0[_0x10e3e3[_0xed59('0x3b')]]={'$like':'%'+_0x10ab38['query'][_0xed59('0x50')]+'%'};return _0x2968c0;}})});}_0x121a1b=_['merge']({},_0x121a1b,_0x10ab38[_0xed59('0x53')]);var _0x1bffae={'where':_0x121a1b[_0xed59('0x51')]};return db[_0xed59('0x54')][_0xed59('0x2d')](_0x1bffae)['then'](function(_0x45c420){_0x2ae4c6['count']=_0x45c420;if(_0x10ab38['query']['includeAll']){_0x121a1b[_0xed59('0x55')]=[{'all':!![]}];}return db[_0xed59('0x54')][_0xed59('0x56')](_0x121a1b);})['then'](function(_0x2a684c){_0x2ae4c6[_0xed59('0x57')]=_0x2a684c;return _0x2ae4c6;})[_0xed59('0x20')](respondWithFilteredResult(_0x5e42ee,_0x121a1b))[_0xed59('0x29')](handleError(_0x5e42ee,null));};exports[_0xed59('0x58')]=function(_0x3a5b8c,_0x59d571){var _0x36f07b={'raw':![],'where':{'id':_0x3a5b8c[_0xed59('0x59')]['id']},'include':[{'model':db[_0xed59('0x5a')],'as':_0xed59('0x3e')}]},_0x4492e9={};_0x4492e9['model']=_[_0xed59('0x44')](db[_0xed59('0x54')][_0xed59('0x40')]);_0x4492e9['query']=_['keys'](_0x3a5b8c[_0xed59('0x49')]);_0x4492e9[_0xed59('0x5b')]=_[_0xed59('0x46')](_0x4492e9[_0xed59('0x47')],_0x4492e9['query']);_0x36f07b['attributes']=_[_0xed59('0x46')](_0x4492e9[_0xed59('0x47')],qs[_0xed59('0x4a')](_0x3a5b8c[_0xed59('0x49')][_0xed59('0x4a')]));_0x36f07b[_0xed59('0x48')]=_0x36f07b[_0xed59('0x48')][_0xed59('0x4b')]?_0x36f07b[_0xed59('0x48')]:_0x4492e9['model'];if(_0x3a5b8c[_0xed59('0x49')][_0xed59('0x5c')]){_0x36f07b[_0xed59('0x55')]=[{'all':!![]}];}_0x36f07b=_[_0xed59('0x5d')]({},_0x36f07b,_0x3a5b8c[_0xed59('0x53')]);return db[_0xed59('0x54')][_0xed59('0x5e')](_0x36f07b)[_0xed59('0x20')](handleEntityNotFound(_0x59d571,null))[_0xed59('0x20')](respondWithResult(_0x59d571,null))['catch'](handleError(_0x59d571,null));};exports['create']=function(_0x4b7982,_0x4ae9dc){return db[_0xed59('0x54')]['create'](_0x4b7982[_0xed59('0x5f')],{})[_0xed59('0x20')](function(_0x374562){var _0x4b0f0d=_0x4b7982[_0xed59('0x60')]['get']({'plain':!![]});if(!_0x4b0f0d)throw new Error(_0xed59('0x61'));if(_0x4b0f0d['role']===_0xed59('0x60')){var _0x5a4836=_0x374562[_0xed59('0x35')]({'plain':!![]});var _0x49fc29=_0xed59('0x36');return db[_0xed59('0x62')][_0xed59('0x5e')]({'where':{'name':_0x49fc29,'userProfileId':_0x4b0f0d[_0xed59('0x63')]},'raw':!![]})[_0xed59('0x20')](function(_0x7a6c47){if(_0x7a6c47&&_0x7a6c47[_0xed59('0x64')]===0x0){return db[_0xed59('0x37')]['create']({'name':_0x5a4836['name'],'resourceId':_0x5a4836['id'],'type':_0x7a6c47[_0xed59('0x3b')],'sectionId':_0x7a6c47['id']},{})['then'](function(){return _0x374562;});}else{return _0x374562;}})[_0xed59('0x29')](function(_0x17aebf){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x17aebf);throw _0x17aebf;});}return _0x374562;})[_0xed59('0x20')](respondWithResult(_0x4ae9dc,0xc9))[_0xed59('0x29')](handleError(_0x4ae9dc,null));};exports[_0xed59('0x34')]=function(_0x2be29d,_0x1aed1e){if(_0x2be29d[_0xed59('0x5f')]['id']){delete _0x2be29d['body']['id'];}return db[_0xed59('0x54')]['find']({'where':{'id':_0x2be29d[_0xed59('0x59')]['id']},'include':[{'model':db[_0xed59('0x5a')],'as':_0xed59('0x3e')}]})['then'](handleEntityNotFound(_0x1aed1e,null))[_0xed59('0x20')](saveUpdates(_0x2be29d[_0xed59('0x5f')],null))['then'](respondWithResult(_0x1aed1e,null))[_0xed59('0x29')](handleError(_0x1aed1e,null));};exports[_0xed59('0x38')]=function(_0x3290fa,_0x103a89){return db['WhatsappAccount'][_0xed59('0x5e')]({'where':{'id':_0x3290fa['params']['id']}})[_0xed59('0x20')](handleEntityNotFound(_0x103a89,null))[_0xed59('0x20')](removeEntity(_0x103a89,null))[_0xed59('0x29')](handleError(_0x103a89,null));};exports[_0xed59('0x65')]=function(_0xd9bd0d,_0x37f24b){return db['WhatsappAccount'][_0xed59('0x65')]()[_0xed59('0x20')](respondWithResult(_0x37f24b,null))[_0xed59('0x29')](handleError(_0x37f24b,null));};exports['addDisposition']=function(_0x27910f,_0x586eab,_0x3dc4ea){if(_0x27910f[_0xed59('0x5f')]['id']){delete _0x27910f['body']['id'];}return db[_0xed59('0x54')][_0xed59('0x5e')]({'where':{'id':_0x27910f['params']['id']}})['then'](handleEntityNotFound(_0x586eab,null))[_0xed59('0x20')](function(_0x34fc07){if(_0x34fc07){_0x27910f[_0xed59('0x5f')][_0xed59('0x66')]=_0x34fc07['id'];return db[_0xed59('0x67')][_0xed59('0x68')](_0x27910f[_0xed59('0x5f')]);}})[_0xed59('0x20')](respondWithResult(_0x586eab,null))['catch'](handleError(_0x586eab,null));};exports[_0xed59('0x69')]=function(_0x54972b,_0x2de12d,_0x21f0de){var _0x36cc1c={'raw':![],'where':{}};var _0x1d8026={};var _0x46e63e={'count':0x0,'rows':[]};return db[_0xed59('0x54')]['findOne']({'where':{'id':_0x54972b[_0xed59('0x59')]['id']}})[_0xed59('0x20')](handleEntityNotFound(_0x2de12d,null))[_0xed59('0x20')](function(_0x332981){if(_0x332981){_0x1d8026[_0xed59('0x47')]=_['keys'](db[_0xed59('0x67')][_0xed59('0x40')]);_0x1d8026[_0xed59('0x49')]=_['keys'](_0x54972b['query']);_0x1d8026[_0xed59('0x45')]=_[_0xed59('0x46')](_0x1d8026[_0xed59('0x47')],_0x1d8026['query']);_0x36cc1c[_0xed59('0x48')]=_[_0xed59('0x46')](_0x1d8026[_0xed59('0x47')],qs['fields'](_0x54972b[_0xed59('0x49')][_0xed59('0x4a')]));_0x36cc1c[_0xed59('0x48')]=_0x36cc1c['attributes']['length']?_0x36cc1c[_0xed59('0x48')]:_0x1d8026[_0xed59('0x47')];if(!_0x54972b[_0xed59('0x49')][_0xed59('0x4c')]('nolimit')){_0x36cc1c[_0xed59('0x2f')]=qs['limit'](_0x54972b[_0xed59('0x49')][_0xed59('0x2f')]);_0x36cc1c['offset']=qs[_0xed59('0x2e')](_0x54972b[_0xed59('0x49')]['offset']);}_0x36cc1c[_0xed59('0x6a')]=qs[_0xed59('0x4e')](_0x54972b[_0xed59('0x49')][_0xed59('0x4e')]);_0x36cc1c[_0xed59('0x51')]=qs[_0xed59('0x45')](_[_0xed59('0x4f')](_0x54972b[_0xed59('0x49')],_0x1d8026[_0xed59('0x45')]));_0x36cc1c[_0xed59('0x51')]['WhatsappAccountId']=_0x332981['id'];if(_0x54972b['query'][_0xed59('0x50')]){_0x36cc1c[_0xed59('0x51')]=_[_0xed59('0x5d')](_0x36cc1c[_0xed59('0x51')],{'$or':_[_0xed59('0x3f')](_0x36cc1c[_0xed59('0x48')],function(_0x503bae){var _0x33382a={};_0x33382a[_0x503bae]={'$like':'%'+_0x54972b['query'][_0xed59('0x50')]+'%'};return _0x33382a;})});}_0x36cc1c=_[_0xed59('0x5d')]({},_0x36cc1c,_0x54972b['options']);return db['Disposition'][_0xed59('0x2d')]({'where':_0x36cc1c[_0xed59('0x51')]})['then'](function(_0x131347){_0x46e63e[_0xed59('0x2d')]=_0x131347;if(_0x54972b['query']['includeAll']){_0x36cc1c[_0xed59('0x55')]=[{'all':!![]}];}return db[_0xed59('0x67')][_0xed59('0x56')](_0x36cc1c);})[_0xed59('0x20')](function(_0x32df29){_0x46e63e[_0xed59('0x57')]=_0x32df29;return _0x46e63e;});}})['then'](respondWithFilteredResult(_0x2de12d,_0x36cc1c))[_0xed59('0x29')](handleError(_0x2de12d,null));};exports[_0xed59('0x6b')]=function(_0x5a7737,_0x1c1bfb,_0x620ea6){return db[_0xed59('0x54')][_0xed59('0x5e')]({'where':{'id':_0x5a7737[_0xed59('0x59')]['id']}})['then'](handleEntityNotFound(_0x1c1bfb,null))[_0xed59('0x20')](function(_0xf4b0d2){if(_0xf4b0d2){return _0xf4b0d2[_0xed59('0x6b')](_0x5a7737[_0xed59('0x49')][_0xed59('0x6c')]);}})[_0xed59('0x20')](respondWithStatusCode(_0x1c1bfb,null))[_0xed59('0x29')](handleError(_0x1c1bfb,null));};exports['addAnswer']=function(_0x388111,_0x54b524,_0x579789){if(_0x388111[_0xed59('0x5f')]['id']){delete _0x388111[_0xed59('0x5f')]['id'];}return db['WhatsappAccount'][_0xed59('0x5e')]({'where':{'id':_0x388111[_0xed59('0x59')]['id']}})[_0xed59('0x20')](handleEntityNotFound(_0x54b524,null))[_0xed59('0x20')](function(_0x52b74b){if(_0x52b74b){_0x388111[_0xed59('0x5f')]['WhatsappAccountId']=_0x52b74b['id'];return db[_0xed59('0x6d')][_0xed59('0x68')](_0x388111[_0xed59('0x5f')]);}})[_0xed59('0x20')](respondWithResult(_0x54b524,null))[_0xed59('0x29')](handleError(_0x54b524,null));};exports['getAnswers']=function(_0x2b41ca,_0x45485a,_0x21247a){var _0xa15f2c={'raw':![],'where':{}};var _0x3349e0={};var _0x2c2a6a={'count':0x0,'rows':[]};return db[_0xed59('0x54')][_0xed59('0x6e')]({'where':{'id':_0x2b41ca[_0xed59('0x59')]['id']}})[_0xed59('0x20')](handleEntityNotFound(_0x45485a,null))[_0xed59('0x20')](function(_0x562185){if(_0x562185){_0x3349e0[_0xed59('0x47')]=_[_0xed59('0x44')](db['CannedAnswer']['rawAttributes']);_0x3349e0[_0xed59('0x49')]=_['keys'](_0x2b41ca['query']);_0x3349e0[_0xed59('0x45')]=_[_0xed59('0x46')](_0x3349e0[_0xed59('0x47')],_0x3349e0['query']);_0xa15f2c[_0xed59('0x48')]=_[_0xed59('0x46')](_0x3349e0[_0xed59('0x47')],qs[_0xed59('0x4a')](_0x2b41ca[_0xed59('0x49')][_0xed59('0x4a')]));_0xa15f2c[_0xed59('0x48')]=_0xa15f2c['attributes'][_0xed59('0x4b')]?_0xa15f2c[_0xed59('0x48')]:_0x3349e0[_0xed59('0x47')];if(!_0x2b41ca[_0xed59('0x49')]['hasOwnProperty'](_0xed59('0x4d'))){_0xa15f2c[_0xed59('0x2f')]=qs[_0xed59('0x2f')](_0x2b41ca[_0xed59('0x49')]['limit']);_0xa15f2c['offset']=qs['offset'](_0x2b41ca[_0xed59('0x49')][_0xed59('0x2e')]);}_0xa15f2c['order']=qs[_0xed59('0x4e')](_0x2b41ca['query'][_0xed59('0x4e')]);_0xa15f2c[_0xed59('0x51')]=qs['filters'](_[_0xed59('0x4f')](_0x2b41ca['query'],_0x3349e0[_0xed59('0x45')]));_0xa15f2c[_0xed59('0x51')]['WhatsappAccountId']=_0x562185['id'];if(_0x2b41ca[_0xed59('0x49')]['filter']){_0xa15f2c[_0xed59('0x51')]=_['merge'](_0xa15f2c['where'],{'$or':_[_0xed59('0x3f')](_0xa15f2c[_0xed59('0x48')],function(_0x35db2e){var _0x342ac3={};_0x342ac3[_0x35db2e]={'$like':'%'+_0x2b41ca[_0xed59('0x49')][_0xed59('0x50')]+'%'};return _0x342ac3;})});}_0xa15f2c=_['merge']({},_0xa15f2c,_0x2b41ca[_0xed59('0x53')]);return db[_0xed59('0x6d')]['count']({'where':_0xa15f2c[_0xed59('0x51')]})[_0xed59('0x20')](function(_0x5a3fe0){_0x2c2a6a['count']=_0x5a3fe0;if(_0x2b41ca[_0xed59('0x49')]['includeAll']){_0xa15f2c[_0xed59('0x55')]=[{'all':!![]}];}return db[_0xed59('0x6d')]['findAll'](_0xa15f2c);})[_0xed59('0x20')](function(_0x5dc6e8){_0x2c2a6a['rows']=_0x5dc6e8;return _0x2c2a6a;});}})['then'](respondWithFilteredResult(_0x45485a,_0xa15f2c))[_0xed59('0x29')](handleError(_0x45485a,null));};exports[_0xed59('0x6f')]=function(_0x3e4e4f,_0x1c5800,_0x33cb76){return db['WhatsappAccount'][_0xed59('0x5e')]({'where':{'id':_0x3e4e4f[_0xed59('0x59')]['id']}})[_0xed59('0x20')](handleEntityNotFound(_0x1c5800,null))['then'](function(_0x8e9927){if(_0x8e9927){return _0x8e9927[_0xed59('0x6f')](_0x3e4e4f['query'][_0xed59('0x6c')]);}})[_0xed59('0x20')](respondWithStatusCode(_0x1c5800,null))[_0xed59('0x29')](handleError(_0x1c5800,null));};exports['addAgents']=function(_0xb5cfe4,_0x1db468,_0x5d9e74){return db[_0xed59('0x54')][_0xed59('0x5e')]({'where':{'id':_0xb5cfe4[_0xed59('0x59')]['id']}})['then'](handleEntityNotFound(_0x1db468,null))['then'](function(_0x5959eb){if(_0x5959eb){return _0x5959eb['addAgents'](_0xb5cfe4[_0xed59('0x5f')][_0xed59('0x6c')],_[_0xed59('0x70')](_0xb5cfe4[_0xed59('0x5f')],['ids','id'])||{})[_0xed59('0x71')](function(_0x25d9c8){for(var _0x4622ca=0x0;_0x4622ca<_0xb5cfe4['body'][_0xed59('0x6c')][_0xed59('0x4b')];_0x4622ca+=0x1){socket['emit'](_0xed59('0x72'),{'UserId':_0xb5cfe4[_0xed59('0x5f')][_0xed59('0x6c')][_0x4622ca],'WhatsappAccountId':_0xb5cfe4[_0xed59('0x59')]['id']});}return _0x25d9c8;});}})[_0xed59('0x20')](respondWithResult(_0x1db468,null))['catch'](handleError(_0x1db468,null));};exports[_0xed59('0x73')]=function(_0x12dce6,_0x1c7b2d,_0x1156fd){return db[_0xed59('0x54')][_0xed59('0x5e')]({'where':{'id':_0x12dce6[_0xed59('0x59')]['id']}})[_0xed59('0x20')](handleEntityNotFound(_0x1c7b2d,null))[_0xed59('0x20')](function(_0x436c08){if(_0x436c08){return _0x436c08[_0xed59('0x73')](_0x12dce6[_0xed59('0x49')]['ids'])[_0xed59('0x20')](function(){if(_[_0xed59('0x74')](_0x12dce6[_0xed59('0x49')][_0xed59('0x6c')])){for(var _0x241763=0x0;_0x241763<_0x12dce6[_0xed59('0x49')][_0xed59('0x6c')][_0xed59('0x4b')];_0x241763+=0x1){socket[_0xed59('0x75')](_0xed59('0x76'),{'UserId':Number(_0x12dce6[_0xed59('0x49')][_0xed59('0x6c')][_0x241763]),'WhatsappAccountId':Number(_0x12dce6[_0xed59('0x59')]['id'])});}}else{socket[_0xed59('0x75')](_0xed59('0x76'),{'UserId':Number(_0x12dce6['query'][_0xed59('0x6c')]),'WhatsappAccountId':Number(_0x12dce6[_0xed59('0x59')]['id'])});}});}})[_0xed59('0x20')](respondWithStatusCode(_0x1c7b2d,null))[_0xed59('0x29')](handleError(_0x1c7b2d,null));};exports[_0xed59('0x77')]=function(_0x4f2ff9,_0x1c147e,_0x423313){var _0x3990dc={};var _0x16a751={};var _0x522f9d;var _0x9cf881;return db[_0xed59('0x54')][_0xed59('0x6e')]({'where':{'id':_0x4f2ff9[_0xed59('0x59')]['id']}})[_0xed59('0x20')](handleEntityNotFound(_0x1c147e,null))[_0xed59('0x20')](function(_0x24abc0){if(_0x24abc0){_0x522f9d=_0x24abc0;_0x16a751[_0xed59('0x47')]=_[_0xed59('0x44')](db['User'][_0xed59('0x40')]);_0x16a751[_0xed59('0x49')]=_['keys'](_0x4f2ff9['query']);_0x16a751[_0xed59('0x45')]=_[_0xed59('0x46')](_0x16a751['model'],_0x16a751[_0xed59('0x49')]);_0x3990dc[_0xed59('0x48')]=_['intersection'](_0x16a751[_0xed59('0x47')],qs[_0xed59('0x4a')](_0x4f2ff9[_0xed59('0x49')]['fields']));_0x3990dc[_0xed59('0x48')]=_0x3990dc['attributes'][_0xed59('0x4b')]?_0x3990dc[_0xed59('0x48')]:_0x16a751[_0xed59('0x47')];_0x3990dc[_0xed59('0x6a')]=qs[_0xed59('0x4e')](_0x4f2ff9[_0xed59('0x49')][_0xed59('0x4e')]);_0x3990dc['where']=qs[_0xed59('0x45')](_[_0xed59('0x4f')](_0x4f2ff9['query'],_0x16a751['filters']));if(_0x4f2ff9['query'][_0xed59('0x50')]){_0x3990dc[_0xed59('0x51')]=_[_0xed59('0x5d')](_0x3990dc['where'],{'$or':_['map'](_0x3990dc[_0xed59('0x48')],function(_0x4d7e42){var _0x40ff15={};_0x40ff15[_0x4d7e42]={'$like':'%'+_0x4f2ff9[_0xed59('0x49')][_0xed59('0x50')]+'%'};return _0x40ff15;})});}_0x3990dc=_['merge']({},_0x3990dc,_0x4f2ff9[_0xed59('0x53')]);return _0x522f9d[_0xed59('0x77')](_0x3990dc);}})[_0xed59('0x20')](function(_0x135867){if(_0x135867){_0x9cf881=_0x135867[_0xed59('0x4b')];if(!_0x4f2ff9[_0xed59('0x49')][_0xed59('0x4c')](_0xed59('0x4d'))){_0x3990dc[_0xed59('0x2f')]=qs['limit'](_0x4f2ff9[_0xed59('0x49')][_0xed59('0x2f')]);_0x3990dc[_0xed59('0x2e')]=qs[_0xed59('0x2e')](_0x4f2ff9['query']['offset']);}return _0x522f9d[_0xed59('0x77')](_0x3990dc);}})[_0xed59('0x20')](function(_0x1cfa18){if(_0x1cfa18){return _0x1cfa18?{'count':_0x9cf881,'rows':_0x1cfa18}:null;}})[_0xed59('0x20')](respondWithResult(_0x1c147e,null))['catch'](handleError(_0x1c147e,null));};exports[_0xed59('0x78')]=function(_0x44d742,_0x3f7bd3,_0xb06be7){return db[_0xed59('0x54')][_0xed59('0x6e')]({'where':{'id':_0x44d742[_0xed59('0x59')]['id']}})[_0xed59('0x20')](handleEntityNotFound(_0x3f7bd3,null))['then'](function(_0x45e277){if(_0x45e277){return db['sequelize'][_0xed59('0x79')](function(_0x25144e){return db['WhatsappApplication'][_0xed59('0x38')]({'where':{'WhatsappAccountId':_0x44d742[_0xed59('0x59')]['id']},'transaction':_0x25144e})[_0xed59('0x20')](function(_0x26f192){var _0x281026=_[_0xed59('0x3f')](_0x44d742['body'],function(_0x22b06e){_0x22b06e[_0xed59('0x66')]=_0x44d742[_0xed59('0x59')]['id'];return _0x22b06e;});return db['WhatsappApplication'][_0xed59('0x7a')](_0x281026,{'transaction':_0x25144e});});})['then'](function(){return db[_0xed59('0x7b')][_0xed59('0x7c')]({'where':{'WhatsappAccountId':_0x44d742[_0xed59('0x59')]['id']},'order':'priority'});});}})['then'](respondWithResult(_0x3f7bd3,null))[_0xed59('0x29')](handleError(_0x3f7bd3,null));};exports['getApplications']=function(_0x2decdd,_0x88d1f2,_0x25d1d1){var _0x322287={};var _0x11c8ae={};var _0x38e7e5;var _0x454f7e;return db[_0xed59('0x54')][_0xed59('0x6e')]({'where':{'id':_0x2decdd['params']['id']}})[_0xed59('0x20')](handleEntityNotFound(_0x88d1f2,null))['then'](function(_0x739828){if(_0x739828){_0x38e7e5=_0x739828;_0x11c8ae['model']=_[_0xed59('0x44')](db['WhatsappApplication'][_0xed59('0x40')]);_0x11c8ae['query']=_['keys'](_0x2decdd[_0xed59('0x49')]);_0x11c8ae[_0xed59('0x45')]=_['intersection'](_0x11c8ae[_0xed59('0x47')],_0x11c8ae[_0xed59('0x49')]);_0x322287[_0xed59('0x48')]=_[_0xed59('0x46')](_0x11c8ae['model'],qs['fields'](_0x2decdd[_0xed59('0x49')][_0xed59('0x4a')]));_0x322287[_0xed59('0x48')]=_0x322287[_0xed59('0x48')][_0xed59('0x4b')]?_0x322287['attributes']:_0x11c8ae[_0xed59('0x47')];_0x322287[_0xed59('0x6a')]=qs['sort'](_0x2decdd[_0xed59('0x49')][_0xed59('0x4e')]);_0x322287[_0xed59('0x51')]=qs['filters'](_[_0xed59('0x4f')](_0x2decdd[_0xed59('0x49')],_0x11c8ae[_0xed59('0x45')]));if(_0x2decdd[_0xed59('0x49')][_0xed59('0x50')]){_0x322287[_0xed59('0x51')]=_[_0xed59('0x5d')](_0x322287[_0xed59('0x51')],{'$or':_['map'](_0x322287[_0xed59('0x48')],function(_0x38f8e4){var _0x5dc040={};_0x5dc040[_0x38f8e4]={'$like':'%'+_0x2decdd[_0xed59('0x49')][_0xed59('0x50')]+'%'};return _0x5dc040;})});}_0x322287=_[_0xed59('0x5d')]({},_0x322287,_0x2decdd['options']);return _0x38e7e5[_0xed59('0x7d')](_0x322287);}})[_0xed59('0x20')](function(_0xf7dc5e){if(_0xf7dc5e){_0x454f7e=_0xf7dc5e[_0xed59('0x4b')];if(!_0x2decdd[_0xed59('0x49')][_0xed59('0x4c')](_0xed59('0x4d'))){_0x322287['limit']=qs[_0xed59('0x2f')](_0x2decdd[_0xed59('0x49')][_0xed59('0x2f')]);_0x322287['offset']=qs[_0xed59('0x2e')](_0x2decdd['query'][_0xed59('0x2e')]);}return _0x38e7e5[_0xed59('0x7d')](_0x322287);}})[_0xed59('0x20')](function(_0x492071){if(_0x492071){return _0x492071?{'count':_0x454f7e,'rows':_0x492071}:null;}})[_0xed59('0x20')](respondWithResult(_0x88d1f2,null))[_0xed59('0x29')](handleError(_0x88d1f2,null));};exports[_0xed59('0x7e')]=function(_0x23bbb4,_0x5dd84e,_0x11297f){var _0x48f234={'channel':_0xed59('0x7f')};var _0x1bf280=[];var _0x4f12f0=[];var _0x355b83={};return db['WhatsappAccount'][_0xed59('0x5e')]({'where':{'id':_0x23bbb4[_0xed59('0x59')]['id']},'include':[{'model':db[_0xed59('0x7b')],'as':_0xed59('0x80')}]})[_0xed59('0x20')](handleEntityNotFound(_0x5dd84e,null))['then'](function(_0x1204d8){_0x48f234[_0xed59('0x81')]=_0x1204d8;_0x48f234['applications']=_['orderBy'](_0x1204d8['Applications'],[_0xed59('0x82')],[_0xed59('0x83')]);if(_0x48f234[_0xed59('0x81')][_0xed59('0x80')]){delete _0x48f234[_0xed59('0x81')][_0xed59('0x80')];}return db[_0xed59('0x84')][_0xed59('0x65')]();})[_0xed59('0x20')](function(_0x196e75){if(!_0x196e75){throw new db[(_0xed59('0x85'))][(_0xed59('0x86'))]('no\x20available\x20attributes');}_0x1bf280=_[_0xed59('0x87')](_[_0xed59('0x44')](_0x196e75),['createdAt','updatedAt']);_0x4f12f0=_[_0xed59('0x87')](_[_0xed59('0x44')](_0x196e75),[_0xed59('0x88'),_0xed59('0x89'),_0xed59('0x8a'),_0xed59('0x8b')]);_0x48f234[_0xed59('0x5f')]={'mapKey':_0xed59('0x8c')};if(_0x48f234[_0xed59('0x81')]['type']&&_0x48f234[_0xed59('0x81')][_0xed59('0x42')]==='twilio'){_0x48f234['body'][_0xed59('0x8d')]=_0x23bbb4[_0xed59('0x5f')][_0xed59('0x8e')][_0xed59('0x8f')](_0xed59('0x90'),'');_0x48f234[_0xed59('0x5f')]['body']=_0x23bbb4[_0xed59('0x5f')][_0xed59('0x91')];_0x48f234[_0xed59('0x5f')][_0xed59('0x92')]=_0x23bbb4[_0xed59('0x5f')][_0xed59('0x93')];}if(_0x48f234['body']['id']){delete _0x48f234['body']['id'];}if(_[_0xed59('0x94')](_0x48f234[_0xed59('0x5f')][_0xed59('0x8d')])){throw new db[(_0xed59('0x85'))][(_0xed59('0x86'))]('from\x20is\x20mandatory');}if(_['isNil'](_0x48f234['body'][_0xed59('0x5f')])||_0x48f234[_0xed59('0x5f')]['body']===''){throw new db['Sequelize'][(_0xed59('0x86'))](_0xed59('0x95'));}if(_[_0xed59('0x94')](_0x48f234[_0xed59('0x5f')]['mapKey'])){throw new db[(_0xed59('0x85'))][(_0xed59('0x86'))](_0xed59('0x96')+_0x4f12f0);}if(!_['includes'](_0x4f12f0,_0x48f234[_0xed59('0x5f')][_0xed59('0x97')])){throw new db[(_0xed59('0x85'))][(_0xed59('0x86'))](_0xed59('0x98')+_0x4f12f0);}_0x355b83[_0x48f234[_0xed59('0x5f')][_0xed59('0x97')]]=_0x48f234['body'][_0xed59('0x8d')];return db[_0xed59('0x99')][_0xed59('0x5e')]({'where':{'id':_0x48f234[_0xed59('0x81')][_0xed59('0x8b')]},'include':[{'model':db[_0xed59('0x84')],'as':_0xed59('0x9a'),'where':_0x355b83,'limit':0x1,'order':[[_0xed59('0x89'),_0xed59('0x9b')]]}]});})['then'](handleEntityNotFound(_0x5dd84e,null))[_0xed59('0x20')](function(_0x2c2b6f){if(_0x2c2b6f){_0x48f234['list']=_['omit'](_0x2c2b6f,[_0xed59('0x9a')]);if(_0x2c2b6f[_0xed59('0x9a')][_0xed59('0x4b')]){return _0x2c2b6f['Contacts'][0x0];}var _0xadaa9d=_[_0xed59('0x18')](_0x48f234[_0xed59('0x5f')],{'firstName':_0x48f234[_0xed59('0x5f')][_0xed59('0x8d')],'ListId':_0x2c2b6f['id']});_0xadaa9d[_0x48f234['body'][_0xed59('0x97')]]=_0x48f234[_0xed59('0x5f')][_0xed59('0x8d')];return db[_0xed59('0x84')]['create'](_0xadaa9d,{'fields':_0x1bf280,'raw':!![]});}})['then'](handleEntityNotFound(_0x5dd84e,null))['then'](function(_0x4caf71){if(_0x4caf71){_0x48f234[_0xed59('0x9c')]=_0x4caf71;var _0x56dd66={'ContactId':_0x4caf71['id'],'phone':_0x48f234[_0xed59('0x5f')][_0xed59('0x8d')],'WhatsappAccountId':_0x23bbb4[_0xed59('0x59')]['id']};var _0x1eabec={'ContactId':_0x4caf71['id'],'WhatsappAccountId':_0x23bbb4['params']['id'],'closed':![]};return db['WhatsappInteraction'][_0xed59('0x5e')]({'where':_0x1eabec})[_0xed59('0x20')](function(_0x31eb42){if(_0x31eb42){return[_0x31eb42,![]];}return db[_0xed59('0x9d')][_0xed59('0x68')](_0x56dd66)['then'](function(_0x364e9b){return[_0x364e9b,!![]];});});}})['spread'](function(_0x43ec20,_0x1ad538){_0x48f234[_0xed59('0x9e')]=_0x43ec20[_0xed59('0x35')]({'plain':!![]});_0x48f234[_0xed59('0x9e')]['created']=![];if(_0x1ad538){if(_0x48f234[_0xed59('0x81')][_0xed59('0x9f')]){_0x48f234['applications'][_0xed59('0xa0')]({'id':0x0,'priority':_0x48f234['applications']['length']+0x1,'app':_0xed59('0xa1'),'appdata':_0xed59('0xa2'),'interval':_0xed59('0xa3')});}_0x48f234[_0xed59('0x9e')][_0xed59('0xa4')]=!![];}return db[_0xed59('0xa5')][_0xed59('0x68')]({'phone':_0x48f234[_0xed59('0x5f')][_0xed59('0x8d')],'messageId':_0x48f234[_0xed59('0x5f')][_0xed59('0x92')],'body':_0x48f234['body']['body'],'WhatsappAccountId':_0x23bbb4['params']['id'],'WhatsappInteractionId':_0x43ec20['id'],'direction':'in','ContactId':_0x43ec20['ContactId'],'AttachmentId':_0x48f234[_0xed59('0x5f')][_0xed59('0xa6')]});})[_0xed59('0x20')](function(_0x3e368b){_0x48f234[_0xed59('0x28')]=_0x3e368b;if(_0x48f234[_0xed59('0x9e')][_0xed59('0xa7')]){return db[_0xed59('0xa8')]['find']({'attributes':['id',_0xed59('0x3b')],'where':{'id':_0x48f234[_0xed59('0x9e')][_0xed59('0xa7')]}})[_0xed59('0x20')](function(_0x138f58){if(_0x138f58){_0x48f234[_0xed59('0xa9')][_0xed59('0xaa')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x138f58[_0xed59('0x3b')]+','+(_0x48f234['account']['waitForTheAssignedAgent']||0xa),'interval':_0xed59('0xa3')});}return respondWithRpcPromise('Start','startRouting',_0x48f234);});}return respondWithRpcPromise(_0xed59('0xab'),_0xed59('0xac'),_0x48f234);})[_0xed59('0x20')](function(_0x51c15e){if(_0x51c15e){var _0x120bf4=0xc8;var _0xc266ce=_0xed59('0xad');logger[_0xed59('0x21')](_0xed59('0xae'),_0xc266ce,_0x120bf4,_0xed59('0xaf'));logger[_0xed59('0x23')](_0xed59('0xb0'),_0xc266ce,_0x120bf4,_0xed59('0xaf'),JSON['stringify'](_0x51c15e));if(_0x48f234[_0xed59('0x81')][_0xed59('0x42')]===_0xed59('0xb1')){return _0x5dd84e['status'](_0x120bf4)[_0xed59('0xb2')](_0xed59('0xb3'),_0xed59('0xb4'))[_0xed59('0x3c')](_0xed59('0xb5'));}else{return _0x5dd84e[_0xed59('0x2a')](_0x120bf4)[_0xed59('0x2c')](_0x51c15e);}}})[_0xed59('0x29')](handleError(_0x5dd84e,null));};exports[_0xed59('0x3c')]=function(_0xce5bf,_0x19bea7,_0xf856e8){var _0x38a460,_0x4bcf3c,_0x34dc74;if(_['isNil'](_0xce5bf[_0xed59('0x5f')][_0xed59('0x5f')])||_0xce5bf['body'][_0xed59('0x5f')]===''){throw new db[(_0xed59('0x85'))][(_0xed59('0x86'))](_0xed59('0x95'));}if(_[_0xed59('0x94')](_0xce5bf[_0xed59('0x5f')]['to'])){throw new db[(_0xed59('0x85'))][(_0xed59('0x86'))](_0xed59('0xb6'));}_0x38a460=_0xce5bf['body']['to'];return db['WhatsappAccount'][_0xed59('0x5e')]({'where':{'id':_0xce5bf['params']['id']},'include':[{'model':db[_0xed59('0x99')],'as':_0xed59('0xb7'),'include':[{'model':db[_0xed59('0x84')],'as':'Contacts','where':{'mobile':_0x38a460},'limit':0x1,'order':[[_0xed59('0x89'),_0xed59('0x9b')]]}]}]})[_0xed59('0x20')](handleEntityNotFound(_0x19bea7,null))[_0xed59('0x20')](function(_0x48a4aa){if(_0x48a4aa&&_0x48a4aa[_0xed59('0xb7')]){_0x4bcf3c=_0x48a4aa['get']({'plain':!![]});if(_0x4bcf3c['List']&&_0x4bcf3c[_0xed59('0xb7')][_0xed59('0x9a')][_0xed59('0x4b')]){return _0x4bcf3c[_0xed59('0xb7')]['Contacts'][0x0];}return db[_0xed59('0x84')]['create'](_[_0xed59('0x18')](_0xce5bf[_0xed59('0x5f')],{'firstName':_0x38a460,'mobile':_0x38a460,'phone':_0x38a460,'ListId':_0x4bcf3c[_0xed59('0x8b')]}));}})[_0xed59('0x20')](handleEntityNotFound(_0x19bea7,null))[_0xed59('0x20')](function(_0x3c8f07){if(_0x3c8f07){_0x34dc74=_0x3c8f07;return db[_0xed59('0x9d')]['find']({'where':{'ContactId':_0x34dc74['id'],'closed':![],'WhatsappAccountId':_0x4bcf3c['id']}})['then'](function(_0xfe334f){if(_0xfe334f){return[_0xfe334f,![]];}return db[_0xed59('0x9d')][_0xed59('0x68')]({'UserId':_0xce5bf[_0xed59('0x60')]['id'],'ContactId':_0x34dc74['id'],'WhatsappAccountId':_0x4bcf3c['id'],'phone':_0x38a460,'firstMsgDirection':'out','Messages':[_[_0xed59('0x5d')](_0xce5bf[_0xed59('0x5f')],{'read':![],'body':_0xce5bf[_0xed59('0x5f')][_0xed59('0x5f')],'phone':_0x38a460,'WhatsappAccountId':_0x4bcf3c['id'],'UserId':_0xce5bf['user']['id'],'ContactId':_0x34dc74['id']})]},{'include':[{'model':db['WhatsappMessage'],'as':_0xed59('0xb8')}]})[_0xed59('0x20')](function(_0x4a7bd6){return[_0x4a7bd6,!![]];});});}})[_0xed59('0x71')](function(_0x1e6c0f,_0x4cf734){if(_0x4cf734){return _0x1e6c0f;}return db[_0xed59('0xa5')]['create'](_['merge'](_0xce5bf[_0xed59('0x5f')],{'read':![],'body':_0xce5bf[_0xed59('0x5f')][_0xed59('0x5f')],'phone':_0x38a460,'WhatsappAccountId':_0x4bcf3c['id'],'WhatsappInteractionId':_0x1e6c0f['id'],'UserId':_0xce5bf[_0xed59('0x60')]['id'],'ContactId':_0x34dc74['id']}))[_0xed59('0x20')](function(_0x1f6001){_0x1e6c0f[_0xed59('0xb9')][_0xed59('0xb8')]=[];_0x1e6c0f['dataValues'][_0xed59('0xb8')]['push'](_0x1f6001[_0xed59('0xb9')]);return _0x1e6c0f;});})[_0xed59('0x20')](respondWithResult(_0x19bea7,null))['catch'](handleError(_0x19bea7,null));};
\ No newline at end of file
+var _0x36f9=['save','destroy','WhatsappAccounts','UserProfileResource','end','stack','name','index','Pause','mandatoryDispositionPause','WhatsappAccount','rawAttributes','type','key','model','map','query','keys','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','filters','pick','filter','merge','includeAll','include','findAll','show','options','find','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','params','describe','addDisposition','WhatsappAccountId','Disposition','getDispositions','findOne','nolimit','removeDispositions','ids','CannedAnswer','rows','removeAnswers','addAgents','omit','spread','emit','userWhatsappAccount:save','removeAgents','userWhatsappAccount:remove','getAgents','transaction','WhatsappApplication','bulkCreate','priority','getApplications','notify','whatsapp','Applications','account','applications','orderBy','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','mobile','From','replace','whatsapp:','Body','MessageSid','isNil','from','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','list','contact','WhatsappInteraction','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','WhatsappMessage','messageId','UserId','User','unshift','Start','startRouting','receiveMessage','entity\x20found','twilio','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','send','to\x20is\x20mandatory','List','Messages','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./whatsappAccount.socket','register','jayson/promise','client','http','then','info','WhatsappAccount,\x20%s,\x20%s','request\x20sent','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','reject'];(function(_0x298b5a,_0x2fdd25){var _0x1498e9=function(_0x2b7dc5){while(--_0x2b7dc5){_0x298b5a['push'](_0x298b5a['shift']());}};_0x1498e9(++_0x2fdd25);}(_0x36f9,0x7f));var _0x936f=function(_0x16f311,_0x1fd02e){_0x16f311=_0x16f311-0x0;var _0x926ea1=_0x36f9[_0x16f311];return _0x926ea1;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x936f('0x0'));var rimraf=require(_0x936f('0x1'));var zipdir=require(_0x936f('0x2'));var jsonpatch=require(_0x936f('0x3'));var rp=require(_0x936f('0x4'));var moment=require(_0x936f('0x5'));var BPromise=require(_0x936f('0x6'));var Mustache=require(_0x936f('0x7'));var util=require(_0x936f('0x8'));var path=require(_0x936f('0x9'));var sox=require(_0x936f('0xa'));var csv=require(_0x936f('0xb'));var ejs=require(_0x936f('0xc'));var fs=require('fs');var _=require(_0x936f('0xd'));var squel=require(_0x936f('0xe'));var crypto=require(_0x936f('0xf'));var jsforce=require('jsforce');var deskjs=require(_0x936f('0x10'));var toCsv=require(_0x936f('0xb'));var querystring=require(_0x936f('0x11'));var Papa=require(_0x936f('0x12'));var Redis=require(_0x936f('0x13'));var authService=require(_0x936f('0x14'));var qs=require(_0x936f('0x15'));var as=require(_0x936f('0x16'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x936f('0x17'))('api');var utils=require(_0x936f('0x18'));var config=require(_0x936f('0x19'));var licenseUtil=require(_0x936f('0x1a'));var db=require(_0x936f('0x1b'))['db'];config[_0x936f('0x1c')]=_[_0x936f('0x1d')](config['redis'],{'host':_0x936f('0x1e'),'port':0x18eb});var socket=require(_0x936f('0x1f'))(new Redis(config[_0x936f('0x1c')]));require(_0x936f('0x20'))[_0x936f('0x21')](socket);var jayson=require(_0x936f('0x22'));var client=jayson[_0x936f('0x23')][_0x936f('0x24')]({'port':0x232c});function respondWithRpcPromise(_0x929784,_0x3a1e7d,_0x1d59b3,_0x47ef4a){return new BPromise(function(_0x2df123,_0x40566a){var _0x3b48b6=_0x47ef4a||client;return _0x3b48b6['request'](_0x929784,_0x1d59b3)[_0x936f('0x25')](function(_0x3ccb5e){logger[_0x936f('0x26')](_0x936f('0x27'),_0x3a1e7d,_0x936f('0x28'));logger[_0x936f('0x29')](_0x936f('0x2a'),_0x3a1e7d,'request\x20sent',JSON[_0x936f('0x2b')](_0x3ccb5e));if(_0x3ccb5e[_0x936f('0x2c')]){if(_0x3ccb5e['error'][_0x936f('0x2d')]===0x1f4){logger[_0x936f('0x2c')](_0x936f('0x27'),_0x3a1e7d,_0x3ccb5e[_0x936f('0x2c')]['message']);return _0x40566a(_0x3ccb5e[_0x936f('0x2c')]['message']);}logger[_0x936f('0x2c')](_0x936f('0x27'),_0x3a1e7d,_0x3ccb5e[_0x936f('0x2c')][_0x936f('0x2e')]);return _0x2df123(_0x3ccb5e['error'][_0x936f('0x2e')]);}else{logger['info'](_0x936f('0x27'),_0x3a1e7d,_0x936f('0x28'));_0x2df123(_0x3ccb5e[_0x936f('0x2f')]['message']);}})[_0x936f('0x30')](function(_0x2528b4){logger[_0x936f('0x2c')](_0x936f('0x27'),_0x3a1e7d,_0x2528b4);_0x40566a(_0x2528b4);});});}function respondWithStatusCode(_0x36e07e,_0x248fe6){_0x248fe6=_0x248fe6||0xcc;return function(_0x1b5144){if(_0x1b5144){return _0x36e07e[_0x936f('0x31')](_0x248fe6);}return _0x36e07e[_0x936f('0x32')](_0x248fe6)['end']();};}function respondWithResult(_0x980f81,_0x1c676c){_0x1c676c=_0x1c676c||0xc8;return function(_0x25719e){if(_0x25719e){return _0x980f81[_0x936f('0x32')](_0x1c676c)[_0x936f('0x33')](_0x25719e);}};}function respondWithFilteredResult(_0x4214c4,_0x40c573){return function(_0x54f32d){if(_0x54f32d){var _0x87606d=_0x54f32d[_0x936f('0x34')],_0x467323=_0x40c573['offset'],_0x2c185b=_0x40c573[_0x936f('0x35')]+_0x40c573[_0x936f('0x36')],_0x258047;if(_0x2c185b>=_0x87606d){_0x2c185b=_0x87606d;_0x258047=0xc8;}else{_0x258047=0xce;}_0x4214c4[_0x936f('0x32')](_0x258047);return _0x4214c4[_0x936f('0x37')](_0x936f('0x38'),_0x467323+'-'+_0x2c185b+'/'+_0x87606d)[_0x936f('0x33')](_0x54f32d);}return null;};}function patchUpdates(_0x39b64d){return function(_0x37fb18){try{jsonpatch[_0x936f('0x39')](_0x37fb18,_0x39b64d,!![]);}catch(_0x879812){return BPromise[_0x936f('0x3a')](_0x879812);}return _0x37fb18[_0x936f('0x3b')]();};}function saveUpdates(_0x503c5f,_0x565e1d){return function(_0x2c77a6){if(_0x2c77a6){return _0x2c77a6['update'](_0x503c5f)['then'](function(_0xdff89f){return _0xdff89f;});}return null;};}function removeEntity(_0x59ac1b,_0x1e575c){return function(_0x370675){if(_0x370675){return _0x370675[_0x936f('0x3c')]()[_0x936f('0x25')](function(){var _0x5490e5=_0x370675['get']({'plain':!![]});var _0x19e00f=_0x936f('0x3d');return db[_0x936f('0x3e')][_0x936f('0x3c')]({'where':{'type':_0x19e00f,'resourceId':_0x5490e5['id']}})['then'](function(){return _0x370675;});})[_0x936f('0x25')](function(){_0x59ac1b[_0x936f('0x32')](0xcc)[_0x936f('0x3f')]();});}};}function handleEntityNotFound(_0x327375,_0x412f77){return function(_0x562a6a){if(!_0x562a6a){_0x327375['sendStatus'](0x194);}return _0x562a6a;};}function handleError(_0x468ff4,_0x24a01f){_0x24a01f=_0x24a01f||0x1f4;return function(_0x473adb){logger[_0x936f('0x2c')](_0x473adb[_0x936f('0x40')]);if(_0x473adb[_0x936f('0x41')]){delete _0x473adb[_0x936f('0x41')];}_0x468ff4[_0x936f('0x32')](_0x24a01f)['send'](_0x473adb);};}exports[_0x936f('0x42')]=function(_0x48adba,_0x1e5583){var _0xa47813={'include':[{'model':db[_0x936f('0x43')],'as':_0x936f('0x44')}]},_0x46ddd6={},_0xb191b3={'count':0x0,'rows':[]};var _0x11568e=_['map'](db[_0x936f('0x45')][_0x936f('0x46')],function(_0x9b91b4){return{'name':_0x9b91b4['fieldName'],'type':_0x9b91b4[_0x936f('0x47')][_0x936f('0x48')]};});_0x46ddd6[_0x936f('0x49')]=_[_0x936f('0x4a')](_0x11568e,'name');_0x46ddd6[_0x936f('0x4b')]=_[_0x936f('0x4c')](_0x48adba[_0x936f('0x4b')]);_0x46ddd6['filters']=_[_0x936f('0x4d')](_0x46ddd6[_0x936f('0x49')],_0x46ddd6[_0x936f('0x4b')]);_0xa47813[_0x936f('0x4e')]=_[_0x936f('0x4d')](_0x46ddd6['model'],qs[_0x936f('0x4f')](_0x48adba[_0x936f('0x4b')]['fields']));_0xa47813['attributes']=_0xa47813[_0x936f('0x4e')][_0x936f('0x50')]?_0xa47813['attributes']:_0x46ddd6[_0x936f('0x49')];if(!_0x48adba[_0x936f('0x4b')][_0x936f('0x51')]('nolimit')){_0xa47813[_0x936f('0x36')]=qs[_0x936f('0x36')](_0x48adba[_0x936f('0x4b')][_0x936f('0x36')]);_0xa47813['offset']=qs[_0x936f('0x35')](_0x48adba[_0x936f('0x4b')][_0x936f('0x35')]);}_0xa47813[_0x936f('0x52')]=qs['sort'](_0x48adba['query'][_0x936f('0x53')]);_0xa47813[_0x936f('0x54')]=qs[_0x936f('0x55')](_[_0x936f('0x56')](_0x48adba[_0x936f('0x4b')],_0x46ddd6[_0x936f('0x55')]),_0x11568e);if(_0x48adba[_0x936f('0x4b')][_0x936f('0x57')]){_0xa47813[_0x936f('0x54')]=_['merge'](_0xa47813['where'],{'$or':_['map'](_0x11568e,function(_0x35c277){if(_0x35c277[_0x936f('0x47')]!=='VIRTUAL'){var _0x499ee2={};_0x499ee2[_0x35c277[_0x936f('0x41')]]={'$like':'%'+_0x48adba[_0x936f('0x4b')][_0x936f('0x57')]+'%'};return _0x499ee2;}})});}_0xa47813=_[_0x936f('0x58')]({},_0xa47813,_0x48adba['options']);var _0x2a7870={'where':_0xa47813['where']};return db[_0x936f('0x45')][_0x936f('0x34')](_0x2a7870)[_0x936f('0x25')](function(_0x3ec750){_0xb191b3[_0x936f('0x34')]=_0x3ec750;if(_0x48adba[_0x936f('0x4b')][_0x936f('0x59')]){_0xa47813[_0x936f('0x5a')]=[{'all':!![]}];}return db[_0x936f('0x45')][_0x936f('0x5b')](_0xa47813);})[_0x936f('0x25')](function(_0x30d947){_0xb191b3['rows']=_0x30d947;return _0xb191b3;})[_0x936f('0x25')](respondWithFilteredResult(_0x1e5583,_0xa47813))[_0x936f('0x30')](handleError(_0x1e5583,null));};exports[_0x936f('0x5c')]=function(_0x1f4de3,_0x569743){var _0x1873c6={'raw':![],'where':{'id':_0x1f4de3['params']['id']},'include':[{'model':db[_0x936f('0x43')],'as':_0x936f('0x44')}]},_0xf97e58={};_0xf97e58[_0x936f('0x49')]=_[_0x936f('0x4c')](db[_0x936f('0x45')][_0x936f('0x46')]);_0xf97e58[_0x936f('0x4b')]=_['keys'](_0x1f4de3[_0x936f('0x4b')]);_0xf97e58['filtears']=_[_0x936f('0x4d')](_0xf97e58[_0x936f('0x49')],_0xf97e58[_0x936f('0x4b')]);_0x1873c6[_0x936f('0x4e')]=_['intersection'](_0xf97e58['model'],qs[_0x936f('0x4f')](_0x1f4de3[_0x936f('0x4b')]['fields']));_0x1873c6[_0x936f('0x4e')]=_0x1873c6[_0x936f('0x4e')][_0x936f('0x50')]?_0x1873c6[_0x936f('0x4e')]:_0xf97e58[_0x936f('0x49')];if(_0x1f4de3[_0x936f('0x4b')][_0x936f('0x59')]){_0x1873c6[_0x936f('0x5a')]=[{'all':!![]}];}_0x1873c6=_[_0x936f('0x58')]({},_0x1873c6,_0x1f4de3[_0x936f('0x5d')]);return db[_0x936f('0x45')][_0x936f('0x5e')](_0x1873c6)['then'](handleEntityNotFound(_0x569743,null))[_0x936f('0x25')](respondWithResult(_0x569743,null))[_0x936f('0x30')](handleError(_0x569743,null));};exports[_0x936f('0x5f')]=function(_0x335a73,_0x8bdbc8){return db['WhatsappAccount'][_0x936f('0x5f')](_0x335a73[_0x936f('0x60')],{})[_0x936f('0x25')](function(_0x4bc3fc){var _0x239dd1=_0x335a73[_0x936f('0x61')][_0x936f('0x62')]({'plain':!![]});if(!_0x239dd1)throw new Error(_0x936f('0x63'));if(_0x239dd1[_0x936f('0x64')]===_0x936f('0x61')){var _0x414e27=_0x4bc3fc[_0x936f('0x62')]({'plain':!![]});var _0x5549af=_0x936f('0x3d');return db[_0x936f('0x65')]['find']({'where':{'name':_0x5549af,'userProfileId':_0x239dd1[_0x936f('0x66')]},'raw':!![]})[_0x936f('0x25')](function(_0x128eb6){if(_0x128eb6&&_0x128eb6[_0x936f('0x67')]===0x0){return db['UserProfileResource'][_0x936f('0x5f')]({'name':_0x414e27[_0x936f('0x41')],'resourceId':_0x414e27['id'],'type':_0x128eb6[_0x936f('0x41')],'sectionId':_0x128eb6['id']},{})[_0x936f('0x25')](function(){return _0x4bc3fc;});}else{return _0x4bc3fc;}})[_0x936f('0x30')](function(_0x298cbb){logger[_0x936f('0x2c')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x298cbb);throw _0x298cbb;});}return _0x4bc3fc;})['then'](respondWithResult(_0x8bdbc8,0xc9))['catch'](handleError(_0x8bdbc8,null));};exports['update']=function(_0x55f795,_0x5538a6){if(_0x55f795['body']['id']){delete _0x55f795[_0x936f('0x60')]['id'];}return db[_0x936f('0x45')][_0x936f('0x5e')]({'where':{'id':_0x55f795['params']['id']},'include':[{'model':db[_0x936f('0x43')],'as':'mandatoryDispositionPause'}]})[_0x936f('0x25')](handleEntityNotFound(_0x5538a6,null))[_0x936f('0x25')](saveUpdates(_0x55f795[_0x936f('0x60')],null))[_0x936f('0x25')](respondWithResult(_0x5538a6,null))['catch'](handleError(_0x5538a6,null));};exports[_0x936f('0x3c')]=function(_0xe73e5,_0x1be754){return db['WhatsappAccount'][_0x936f('0x5e')]({'where':{'id':_0xe73e5[_0x936f('0x68')]['id']}})['then'](handleEntityNotFound(_0x1be754,null))[_0x936f('0x25')](removeEntity(_0x1be754,null))[_0x936f('0x30')](handleError(_0x1be754,null));};exports['describe']=function(_0x29ed1c,_0x24743b){return db['WhatsappAccount'][_0x936f('0x69')]()[_0x936f('0x25')](respondWithResult(_0x24743b,null))[_0x936f('0x30')](handleError(_0x24743b,null));};exports[_0x936f('0x6a')]=function(_0x4acd3e,_0x1bc7ea,_0xa77b1e){if(_0x4acd3e[_0x936f('0x60')]['id']){delete _0x4acd3e[_0x936f('0x60')]['id'];}return db['WhatsappAccount']['find']({'where':{'id':_0x4acd3e['params']['id']}})[_0x936f('0x25')](handleEntityNotFound(_0x1bc7ea,null))[_0x936f('0x25')](function(_0x1acc08){if(_0x1acc08){_0x4acd3e[_0x936f('0x60')][_0x936f('0x6b')]=_0x1acc08['id'];return db[_0x936f('0x6c')][_0x936f('0x5f')](_0x4acd3e[_0x936f('0x60')]);}})[_0x936f('0x25')](respondWithResult(_0x1bc7ea,null))['catch'](handleError(_0x1bc7ea,null));};exports[_0x936f('0x6d')]=function(_0x6c2770,_0x2ad2b2,_0x47ea3c){var _0x32b91e={'raw':![],'where':{}};var _0x1daaa1={};var _0x561f89={'count':0x0,'rows':[]};return db[_0x936f('0x45')][_0x936f('0x6e')]({'where':{'id':_0x6c2770[_0x936f('0x68')]['id']}})[_0x936f('0x25')](handleEntityNotFound(_0x2ad2b2,null))[_0x936f('0x25')](function(_0x4dc872){if(_0x4dc872){_0x1daaa1[_0x936f('0x49')]=_[_0x936f('0x4c')](db['Disposition'][_0x936f('0x46')]);_0x1daaa1[_0x936f('0x4b')]=_['keys'](_0x6c2770[_0x936f('0x4b')]);_0x1daaa1[_0x936f('0x55')]=_[_0x936f('0x4d')](_0x1daaa1[_0x936f('0x49')],_0x1daaa1[_0x936f('0x4b')]);_0x32b91e[_0x936f('0x4e')]=_['intersection'](_0x1daaa1[_0x936f('0x49')],qs[_0x936f('0x4f')](_0x6c2770[_0x936f('0x4b')]['fields']));_0x32b91e[_0x936f('0x4e')]=_0x32b91e[_0x936f('0x4e')][_0x936f('0x50')]?_0x32b91e['attributes']:_0x1daaa1[_0x936f('0x49')];if(!_0x6c2770[_0x936f('0x4b')][_0x936f('0x51')](_0x936f('0x6f'))){_0x32b91e[_0x936f('0x36')]=qs[_0x936f('0x36')](_0x6c2770[_0x936f('0x4b')][_0x936f('0x36')]);_0x32b91e[_0x936f('0x35')]=qs['offset'](_0x6c2770[_0x936f('0x4b')][_0x936f('0x35')]);}_0x32b91e[_0x936f('0x52')]=qs[_0x936f('0x53')](_0x6c2770[_0x936f('0x4b')][_0x936f('0x53')]);_0x32b91e[_0x936f('0x54')]=qs[_0x936f('0x55')](_['pick'](_0x6c2770[_0x936f('0x4b')],_0x1daaa1['filters']));_0x32b91e[_0x936f('0x54')][_0x936f('0x6b')]=_0x4dc872['id'];if(_0x6c2770['query'][_0x936f('0x57')]){_0x32b91e[_0x936f('0x54')]=_[_0x936f('0x58')](_0x32b91e['where'],{'$or':_[_0x936f('0x4a')](_0x32b91e[_0x936f('0x4e')],function(_0x35e985){var _0x2490cb={};_0x2490cb[_0x35e985]={'$like':'%'+_0x6c2770[_0x936f('0x4b')]['filter']+'%'};return _0x2490cb;})});}_0x32b91e=_['merge']({},_0x32b91e,_0x6c2770[_0x936f('0x5d')]);return db[_0x936f('0x6c')][_0x936f('0x34')]({'where':_0x32b91e['where']})['then'](function(_0x2c6b09){_0x561f89[_0x936f('0x34')]=_0x2c6b09;if(_0x6c2770[_0x936f('0x4b')][_0x936f('0x59')]){_0x32b91e[_0x936f('0x5a')]=[{'all':!![]}];}return db[_0x936f('0x6c')][_0x936f('0x5b')](_0x32b91e);})[_0x936f('0x25')](function(_0x58128a){_0x561f89['rows']=_0x58128a;return _0x561f89;});}})['then'](respondWithFilteredResult(_0x2ad2b2,_0x32b91e))[_0x936f('0x30')](handleError(_0x2ad2b2,null));};exports[_0x936f('0x70')]=function(_0x31490c,_0x348b3d,_0x12b755){return db['WhatsappAccount'][_0x936f('0x5e')]({'where':{'id':_0x31490c[_0x936f('0x68')]['id']}})[_0x936f('0x25')](handleEntityNotFound(_0x348b3d,null))[_0x936f('0x25')](function(_0xeb0b3b){if(_0xeb0b3b){return _0xeb0b3b[_0x936f('0x70')](_0x31490c[_0x936f('0x4b')][_0x936f('0x71')]);}})['then'](respondWithStatusCode(_0x348b3d,null))[_0x936f('0x30')](handleError(_0x348b3d,null));};exports['addAnswer']=function(_0x443e5b,_0xa6d77,_0x192bcc){if(_0x443e5b[_0x936f('0x60')]['id']){delete _0x443e5b[_0x936f('0x60')]['id'];}return db[_0x936f('0x45')][_0x936f('0x5e')]({'where':{'id':_0x443e5b[_0x936f('0x68')]['id']}})[_0x936f('0x25')](handleEntityNotFound(_0xa6d77,null))[_0x936f('0x25')](function(_0x1846dd){if(_0x1846dd){_0x443e5b[_0x936f('0x60')]['WhatsappAccountId']=_0x1846dd['id'];return db['CannedAnswer'][_0x936f('0x5f')](_0x443e5b[_0x936f('0x60')]);}})['then'](respondWithResult(_0xa6d77,null))[_0x936f('0x30')](handleError(_0xa6d77,null));};exports['getAnswers']=function(_0x86e601,_0x4c7e09,_0x36a757){var _0x5720c5={'raw':![],'where':{}};var _0x2b794b={};var _0x2b8572={'count':0x0,'rows':[]};return db[_0x936f('0x45')][_0x936f('0x6e')]({'where':{'id':_0x86e601[_0x936f('0x68')]['id']}})[_0x936f('0x25')](handleEntityNotFound(_0x4c7e09,null))['then'](function(_0x58a005){if(_0x58a005){_0x2b794b['model']=_[_0x936f('0x4c')](db[_0x936f('0x72')][_0x936f('0x46')]);_0x2b794b[_0x936f('0x4b')]=_[_0x936f('0x4c')](_0x86e601[_0x936f('0x4b')]);_0x2b794b[_0x936f('0x55')]=_[_0x936f('0x4d')](_0x2b794b[_0x936f('0x49')],_0x2b794b[_0x936f('0x4b')]);_0x5720c5[_0x936f('0x4e')]=_[_0x936f('0x4d')](_0x2b794b[_0x936f('0x49')],qs[_0x936f('0x4f')](_0x86e601[_0x936f('0x4b')]['fields']));_0x5720c5['attributes']=_0x5720c5[_0x936f('0x4e')][_0x936f('0x50')]?_0x5720c5[_0x936f('0x4e')]:_0x2b794b[_0x936f('0x49')];if(!_0x86e601[_0x936f('0x4b')][_0x936f('0x51')](_0x936f('0x6f'))){_0x5720c5[_0x936f('0x36')]=qs[_0x936f('0x36')](_0x86e601[_0x936f('0x4b')][_0x936f('0x36')]);_0x5720c5[_0x936f('0x35')]=qs[_0x936f('0x35')](_0x86e601[_0x936f('0x4b')][_0x936f('0x35')]);}_0x5720c5[_0x936f('0x52')]=qs[_0x936f('0x53')](_0x86e601[_0x936f('0x4b')][_0x936f('0x53')]);_0x5720c5[_0x936f('0x54')]=qs[_0x936f('0x55')](_[_0x936f('0x56')](_0x86e601['query'],_0x2b794b['filters']));_0x5720c5[_0x936f('0x54')][_0x936f('0x6b')]=_0x58a005['id'];if(_0x86e601[_0x936f('0x4b')][_0x936f('0x57')]){_0x5720c5[_0x936f('0x54')]=_['merge'](_0x5720c5[_0x936f('0x54')],{'$or':_[_0x936f('0x4a')](_0x5720c5['attributes'],function(_0x571922){var _0x11af3d={};_0x11af3d[_0x571922]={'$like':'%'+_0x86e601[_0x936f('0x4b')]['filter']+'%'};return _0x11af3d;})});}_0x5720c5=_[_0x936f('0x58')]({},_0x5720c5,_0x86e601[_0x936f('0x5d')]);return db[_0x936f('0x72')][_0x936f('0x34')]({'where':_0x5720c5[_0x936f('0x54')]})[_0x936f('0x25')](function(_0x4d26f6){_0x2b8572[_0x936f('0x34')]=_0x4d26f6;if(_0x86e601[_0x936f('0x4b')][_0x936f('0x59')]){_0x5720c5[_0x936f('0x5a')]=[{'all':!![]}];}return db['CannedAnswer'][_0x936f('0x5b')](_0x5720c5);})[_0x936f('0x25')](function(_0x3ff01b){_0x2b8572[_0x936f('0x73')]=_0x3ff01b;return _0x2b8572;});}})[_0x936f('0x25')](respondWithFilteredResult(_0x4c7e09,_0x5720c5))[_0x936f('0x30')](handleError(_0x4c7e09,null));};exports[_0x936f('0x74')]=function(_0x4806c3,_0x1e18a5,_0x37865a){return db['WhatsappAccount']['find']({'where':{'id':_0x4806c3[_0x936f('0x68')]['id']}})[_0x936f('0x25')](handleEntityNotFound(_0x1e18a5,null))['then'](function(_0x32961d){if(_0x32961d){return _0x32961d[_0x936f('0x74')](_0x4806c3[_0x936f('0x4b')]['ids']);}})['then'](respondWithStatusCode(_0x1e18a5,null))[_0x936f('0x30')](handleError(_0x1e18a5,null));};exports[_0x936f('0x75')]=function(_0x39e37e,_0x16b2e1,_0xfb4e85){return db[_0x936f('0x45')][_0x936f('0x5e')]({'where':{'id':_0x39e37e[_0x936f('0x68')]['id']}})[_0x936f('0x25')](handleEntityNotFound(_0x16b2e1,null))[_0x936f('0x25')](function(_0x12e53){if(_0x12e53){return _0x12e53['addAgents'](_0x39e37e['body'][_0x936f('0x71')],_[_0x936f('0x76')](_0x39e37e[_0x936f('0x60')],['ids','id'])||{})[_0x936f('0x77')](function(_0xaafceb){for(var _0x314c5c=0x0;_0x314c5c<_0x39e37e[_0x936f('0x60')][_0x936f('0x71')][_0x936f('0x50')];_0x314c5c+=0x1){socket[_0x936f('0x78')](_0x936f('0x79'),{'UserId':_0x39e37e[_0x936f('0x60')][_0x936f('0x71')][_0x314c5c],'WhatsappAccountId':_0x39e37e['params']['id']});}return _0xaafceb;});}})[_0x936f('0x25')](respondWithResult(_0x16b2e1,null))[_0x936f('0x30')](handleError(_0x16b2e1,null));};exports['removeAgents']=function(_0x3139e5,_0xbb00a2,_0x11fbf4){return db[_0x936f('0x45')][_0x936f('0x5e')]({'where':{'id':_0x3139e5[_0x936f('0x68')]['id']}})[_0x936f('0x25')](handleEntityNotFound(_0xbb00a2,null))[_0x936f('0x25')](function(_0x456320){if(_0x456320){return _0x456320[_0x936f('0x7a')](_0x3139e5[_0x936f('0x4b')][_0x936f('0x71')])['then'](function(){if(_['isArray'](_0x3139e5[_0x936f('0x4b')][_0x936f('0x71')])){for(var _0xce7c39=0x0;_0xce7c39<_0x3139e5[_0x936f('0x4b')]['ids'][_0x936f('0x50')];_0xce7c39+=0x1){socket['emit'](_0x936f('0x7b'),{'UserId':Number(_0x3139e5[_0x936f('0x4b')]['ids'][_0xce7c39]),'WhatsappAccountId':Number(_0x3139e5['params']['id'])});}}else{socket[_0x936f('0x78')](_0x936f('0x7b'),{'UserId':Number(_0x3139e5[_0x936f('0x4b')][_0x936f('0x71')]),'WhatsappAccountId':Number(_0x3139e5[_0x936f('0x68')]['id'])});}});}})[_0x936f('0x25')](respondWithStatusCode(_0xbb00a2,null))[_0x936f('0x30')](handleError(_0xbb00a2,null));};exports[_0x936f('0x7c')]=function(_0x22e220,_0x119747,_0x3c6c08){var _0x470765={};var _0x399130={};var _0x28c1b9;var _0xa7e99b;return db[_0x936f('0x45')][_0x936f('0x6e')]({'where':{'id':_0x22e220[_0x936f('0x68')]['id']}})['then'](handleEntityNotFound(_0x119747,null))[_0x936f('0x25')](function(_0x107e07){if(_0x107e07){_0x28c1b9=_0x107e07;_0x399130[_0x936f('0x49')]=_['keys'](db['User'][_0x936f('0x46')]);_0x399130[_0x936f('0x4b')]=_[_0x936f('0x4c')](_0x22e220[_0x936f('0x4b')]);_0x399130[_0x936f('0x55')]=_['intersection'](_0x399130[_0x936f('0x49')],_0x399130[_0x936f('0x4b')]);_0x470765[_0x936f('0x4e')]=_[_0x936f('0x4d')](_0x399130[_0x936f('0x49')],qs['fields'](_0x22e220[_0x936f('0x4b')][_0x936f('0x4f')]));_0x470765[_0x936f('0x4e')]=_0x470765[_0x936f('0x4e')]['length']?_0x470765[_0x936f('0x4e')]:_0x399130[_0x936f('0x49')];_0x470765[_0x936f('0x52')]=qs[_0x936f('0x53')](_0x22e220['query'][_0x936f('0x53')]);_0x470765['where']=qs['filters'](_[_0x936f('0x56')](_0x22e220[_0x936f('0x4b')],_0x399130['filters']));if(_0x22e220[_0x936f('0x4b')][_0x936f('0x57')]){_0x470765[_0x936f('0x54')]=_['merge'](_0x470765['where'],{'$or':_[_0x936f('0x4a')](_0x470765['attributes'],function(_0x153988){var _0x3ea745={};_0x3ea745[_0x153988]={'$like':'%'+_0x22e220[_0x936f('0x4b')][_0x936f('0x57')]+'%'};return _0x3ea745;})});}_0x470765=_[_0x936f('0x58')]({},_0x470765,_0x22e220[_0x936f('0x5d')]);return _0x28c1b9[_0x936f('0x7c')](_0x470765);}})[_0x936f('0x25')](function(_0x557d83){if(_0x557d83){_0xa7e99b=_0x557d83[_0x936f('0x50')];if(!_0x22e220['query'][_0x936f('0x51')](_0x936f('0x6f'))){_0x470765[_0x936f('0x36')]=qs['limit'](_0x22e220['query'][_0x936f('0x36')]);_0x470765['offset']=qs[_0x936f('0x35')](_0x22e220[_0x936f('0x4b')][_0x936f('0x35')]);}return _0x28c1b9['getAgents'](_0x470765);}})['then'](function(_0x355cd6){if(_0x355cd6){return _0x355cd6?{'count':_0xa7e99b,'rows':_0x355cd6}:null;}})[_0x936f('0x25')](respondWithResult(_0x119747,null))[_0x936f('0x30')](handleError(_0x119747,null));};exports['addApplications']=function(_0x20d2da,_0x2de412,_0x15e2ec){return db[_0x936f('0x45')][_0x936f('0x6e')]({'where':{'id':_0x20d2da[_0x936f('0x68')]['id']}})['then'](handleEntityNotFound(_0x2de412,null))[_0x936f('0x25')](function(_0x3b3fa8){if(_0x3b3fa8){return db['sequelize'][_0x936f('0x7d')](function(_0x708e37){return db[_0x936f('0x7e')]['destroy']({'where':{'WhatsappAccountId':_0x20d2da['params']['id']},'transaction':_0x708e37})[_0x936f('0x25')](function(_0x2ba569){var _0x4bb015=_[_0x936f('0x4a')](_0x20d2da['body'],function(_0xe2f08c){_0xe2f08c[_0x936f('0x6b')]=_0x20d2da[_0x936f('0x68')]['id'];return _0xe2f08c;});return db[_0x936f('0x7e')][_0x936f('0x7f')](_0x4bb015,{'transaction':_0x708e37});});})[_0x936f('0x25')](function(){return db[_0x936f('0x7e')]['findAndCountAll']({'where':{'WhatsappAccountId':_0x20d2da['params']['id']},'order':_0x936f('0x80')});});}})[_0x936f('0x25')](respondWithResult(_0x2de412,null))[_0x936f('0x30')](handleError(_0x2de412,null));};exports[_0x936f('0x81')]=function(_0x1db047,_0x31d193,_0x1d7e05){var _0xbe7136={};var _0x5c3084={};var _0x4d14c8;var _0x46f4c5;return db[_0x936f('0x45')][_0x936f('0x6e')]({'where':{'id':_0x1db047[_0x936f('0x68')]['id']}})['then'](handleEntityNotFound(_0x31d193,null))['then'](function(_0x5b2401){if(_0x5b2401){_0x4d14c8=_0x5b2401;_0x5c3084[_0x936f('0x49')]=_[_0x936f('0x4c')](db[_0x936f('0x7e')][_0x936f('0x46')]);_0x5c3084[_0x936f('0x4b')]=_[_0x936f('0x4c')](_0x1db047['query']);_0x5c3084[_0x936f('0x55')]=_['intersection'](_0x5c3084[_0x936f('0x49')],_0x5c3084['query']);_0xbe7136[_0x936f('0x4e')]=_[_0x936f('0x4d')](_0x5c3084['model'],qs[_0x936f('0x4f')](_0x1db047['query'][_0x936f('0x4f')]));_0xbe7136[_0x936f('0x4e')]=_0xbe7136[_0x936f('0x4e')][_0x936f('0x50')]?_0xbe7136[_0x936f('0x4e')]:_0x5c3084[_0x936f('0x49')];_0xbe7136['order']=qs[_0x936f('0x53')](_0x1db047['query'][_0x936f('0x53')]);_0xbe7136['where']=qs[_0x936f('0x55')](_[_0x936f('0x56')](_0x1db047['query'],_0x5c3084['filters']));if(_0x1db047['query'][_0x936f('0x57')]){_0xbe7136[_0x936f('0x54')]=_[_0x936f('0x58')](_0xbe7136[_0x936f('0x54')],{'$or':_[_0x936f('0x4a')](_0xbe7136[_0x936f('0x4e')],function(_0x5ce179){var _0xec3e8a={};_0xec3e8a[_0x5ce179]={'$like':'%'+_0x1db047[_0x936f('0x4b')][_0x936f('0x57')]+'%'};return _0xec3e8a;})});}_0xbe7136=_[_0x936f('0x58')]({},_0xbe7136,_0x1db047[_0x936f('0x5d')]);return _0x4d14c8['getApplications'](_0xbe7136);}})[_0x936f('0x25')](function(_0x3f0434){if(_0x3f0434){_0x46f4c5=_0x3f0434[_0x936f('0x50')];if(!_0x1db047['query']['hasOwnProperty'](_0x936f('0x6f'))){_0xbe7136[_0x936f('0x36')]=qs[_0x936f('0x36')](_0x1db047[_0x936f('0x4b')]['limit']);_0xbe7136['offset']=qs['offset'](_0x1db047['query'][_0x936f('0x35')]);}return _0x4d14c8[_0x936f('0x81')](_0xbe7136);}})[_0x936f('0x25')](function(_0xd0e09e){if(_0xd0e09e){return _0xd0e09e?{'count':_0x46f4c5,'rows':_0xd0e09e}:null;}})[_0x936f('0x25')](respondWithResult(_0x31d193,null))[_0x936f('0x30')](handleError(_0x31d193,null));};exports[_0x936f('0x82')]=function(_0x52af63,_0x127632,_0x43a2c6){var _0x4bc3b6={'channel':_0x936f('0x83')};var _0x49bee4=[];var _0x5d1d84=[];var _0x1d772d={};return db['WhatsappAccount'][_0x936f('0x5e')]({'where':{'id':_0x52af63['params']['id']},'include':[{'model':db[_0x936f('0x7e')],'as':_0x936f('0x84')}]})['then'](handleEntityNotFound(_0x127632,null))[_0x936f('0x25')](function(_0x187a8c){_0x4bc3b6[_0x936f('0x85')]=_0x187a8c;_0x4bc3b6[_0x936f('0x86')]=_[_0x936f('0x87')](_0x187a8c[_0x936f('0x84')],[_0x936f('0x80')],['asc']);if(_0x4bc3b6[_0x936f('0x85')]['Applications']){delete _0x4bc3b6[_0x936f('0x85')]['Applications'];}return db[_0x936f('0x88')]['describe']();})[_0x936f('0x25')](function(_0x34b39d){if(!_0x34b39d){throw new db[(_0x936f('0x89'))][(_0x936f('0x8a'))](_0x936f('0x8b'));}_0x49bee4=_[_0x936f('0x8c')](_[_0x936f('0x4c')](_0x34b39d),[_0x936f('0x8d'),_0x936f('0x8e')]);_0x5d1d84=_['difference'](_[_0x936f('0x4c')](_0x34b39d),[_0x936f('0x8d'),'updatedAt',_0x936f('0x8f'),_0x936f('0x90')]);_0x4bc3b6['body']={'mapKey':_0x936f('0x91')};if(_0x4bc3b6[_0x936f('0x85')][_0x936f('0x47')]&&_0x4bc3b6[_0x936f('0x85')][_0x936f('0x47')]==='twilio'){_0x4bc3b6[_0x936f('0x60')]['from']=_0x52af63[_0x936f('0x60')][_0x936f('0x92')][_0x936f('0x93')](_0x936f('0x94'),'');_0x4bc3b6[_0x936f('0x60')]['body']=_0x52af63[_0x936f('0x60')][_0x936f('0x95')];_0x4bc3b6[_0x936f('0x60')]['messageId']=_0x52af63[_0x936f('0x60')][_0x936f('0x96')];}if(_0x4bc3b6[_0x936f('0x60')]['id']){delete _0x4bc3b6[_0x936f('0x60')]['id'];}if(_[_0x936f('0x97')](_0x4bc3b6[_0x936f('0x60')][_0x936f('0x98')])){throw new db['Sequelize'][(_0x936f('0x8a'))]('from\x20is\x20mandatory');}if(_[_0x936f('0x97')](_0x4bc3b6[_0x936f('0x60')][_0x936f('0x60')])||_0x4bc3b6[_0x936f('0x60')][_0x936f('0x60')]===''){throw new db['Sequelize']['ValidationError'](_0x936f('0x99'));}if(_[_0x936f('0x97')](_0x4bc3b6[_0x936f('0x60')][_0x936f('0x9a')])){throw new db['Sequelize'][(_0x936f('0x8a'))](_0x936f('0x9b')+_0x5d1d84);}if(!_[_0x936f('0x9c')](_0x5d1d84,_0x4bc3b6[_0x936f('0x60')]['mapKey'])){throw new db['Sequelize'][(_0x936f('0x8a'))](_0x936f('0x9d')+_0x5d1d84);}_0x1d772d[_0x4bc3b6['body']['mapKey']]=_0x4bc3b6['body'][_0x936f('0x98')];return db[_0x936f('0x9e')]['find']({'where':{'id':_0x4bc3b6[_0x936f('0x85')]['ListId']},'include':[{'model':db[_0x936f('0x88')],'as':_0x936f('0x9f'),'where':_0x1d772d,'limit':0x1,'order':[[_0x936f('0x8e'),_0x936f('0xa0')]]}]});})[_0x936f('0x25')](handleEntityNotFound(_0x127632,null))[_0x936f('0x25')](function(_0x3a7802){if(_0x3a7802){_0x4bc3b6[_0x936f('0xa1')]=_[_0x936f('0x76')](_0x3a7802,['Contacts']);if(_0x3a7802['Contacts'][_0x936f('0x50')]){return _0x3a7802[_0x936f('0x9f')][0x0];}var _0xd6ae66=_[_0x936f('0x1d')](_0x4bc3b6[_0x936f('0x60')],{'firstName':_0x4bc3b6['body']['from'],'ListId':_0x3a7802['id']});_0xd6ae66[_0x4bc3b6[_0x936f('0x60')][_0x936f('0x9a')]]=_0x4bc3b6[_0x936f('0x60')][_0x936f('0x98')];return db[_0x936f('0x88')]['create'](_0xd6ae66,{'fields':_0x49bee4,'raw':!![]});}})[_0x936f('0x25')](handleEntityNotFound(_0x127632,null))[_0x936f('0x25')](function(_0x33d6d2){if(_0x33d6d2){_0x4bc3b6[_0x936f('0xa2')]=_0x33d6d2;var _0x17ef27={'ContactId':_0x33d6d2['id'],'phone':_0x4bc3b6[_0x936f('0x60')][_0x936f('0x98')],'WhatsappAccountId':_0x52af63['params']['id']};var _0x3a0a63={'ContactId':_0x33d6d2['id'],'WhatsappAccountId':_0x52af63['params']['id'],'closed':![]};return db[_0x936f('0xa3')][_0x936f('0x5e')]({'where':_0x3a0a63})[_0x936f('0x25')](function(_0x2b7b72){if(_0x2b7b72){return[_0x2b7b72,![]];}return db[_0x936f('0xa3')]['create'](_0x17ef27)[_0x936f('0x25')](function(_0x45f279){return[_0x45f279,!![]];});});}})[_0x936f('0x77')](function(_0x48218f,_0x1bce7e){_0x4bc3b6[_0x936f('0xa4')]=_0x48218f['get']({'plain':!![]});_0x4bc3b6[_0x936f('0xa4')][_0x936f('0xa5')]=![];if(_0x1bce7e){if(_0x4bc3b6[_0x936f('0x85')][_0x936f('0xa6')]){_0x4bc3b6[_0x936f('0x86')][_0x936f('0xa7')]({'id':0x0,'priority':_0x4bc3b6[_0x936f('0x86')][_0x936f('0x50')]+0x1,'app':_0x936f('0xa8'),'appdata':_0x936f('0xa9'),'interval':_0x936f('0xaa')});}_0x4bc3b6[_0x936f('0xa4')][_0x936f('0xa5')]=!![];}return db[_0x936f('0xab')][_0x936f('0x5f')]({'phone':_0x4bc3b6[_0x936f('0x60')][_0x936f('0x98')],'messageId':_0x4bc3b6[_0x936f('0x60')][_0x936f('0xac')],'body':_0x4bc3b6[_0x936f('0x60')][_0x936f('0x60')],'WhatsappAccountId':_0x52af63[_0x936f('0x68')]['id'],'WhatsappInteractionId':_0x48218f['id'],'direction':'in','ContactId':_0x48218f['ContactId'],'AttachmentId':_0x4bc3b6[_0x936f('0x60')]['AttachmentId']});})['then'](function(_0x54bde9){_0x4bc3b6['message']=_0x54bde9;if(_0x4bc3b6[_0x936f('0xa4')][_0x936f('0xad')]){return db[_0x936f('0xae')][_0x936f('0x5e')]({'attributes':['id',_0x936f('0x41')],'where':{'id':_0x4bc3b6[_0x936f('0xa4')]['UserId']}})[_0x936f('0x25')](function(_0xefc2fe){if(_0xefc2fe){_0x4bc3b6[_0x936f('0x86')][_0x936f('0xaf')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0xefc2fe[_0x936f('0x41')]+','+(_0x4bc3b6[_0x936f('0x85')]['waitForTheAssignedAgent']||0xa),'interval':_0x936f('0xaa')});}return respondWithRpcPromise(_0x936f('0xb0'),_0x936f('0xb1'),_0x4bc3b6);});}return respondWithRpcPromise('Start','startRouting',_0x4bc3b6);})[_0x936f('0x25')](function(_0x3bc52c){if(_0x3bc52c){var _0x3a6adf=0xc8;var _0x228cea=_0x936f('0xb2');logger['info'](_0x936f('0x2a'),_0x228cea,_0x3a6adf,_0x936f('0xb3'));logger[_0x936f('0x29')]('WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s',_0x228cea,_0x3a6adf,_0x936f('0xb3'),JSON['stringify'](_0x3bc52c));if(_0x4bc3b6['account'][_0x936f('0x47')]===_0x936f('0xb4')){return _0x127632[_0x936f('0x32')](_0x3a6adf)[_0x936f('0x37')]('Content-Type','text/xml')['send'](_0x936f('0xb5'));}else{return _0x127632[_0x936f('0x32')](_0x3a6adf)['json'](_0x3bc52c);}}})[_0x936f('0x30')](handleError(_0x127632,null));};exports[_0x936f('0xb6')]=function(_0x1f95b4,_0x2ff9fd,_0x584c19){var _0x537bd3,_0x40f0ec,_0x151117;if(_[_0x936f('0x97')](_0x1f95b4['body'][_0x936f('0x60')])||_0x1f95b4[_0x936f('0x60')][_0x936f('0x60')]===''){throw new db['Sequelize'][(_0x936f('0x8a'))](_0x936f('0x99'));}if(_['isNil'](_0x1f95b4[_0x936f('0x60')]['to'])){throw new db['Sequelize'][(_0x936f('0x8a'))](_0x936f('0xb7'));}_0x537bd3=_0x1f95b4[_0x936f('0x60')]['to'];return db[_0x936f('0x45')][_0x936f('0x5e')]({'where':{'id':_0x1f95b4['params']['id']},'include':[{'model':db['CmList'],'as':_0x936f('0xb8'),'include':[{'model':db[_0x936f('0x88')],'as':'Contacts','where':{'mobile':_0x537bd3},'limit':0x1,'order':[['updatedAt',_0x936f('0xa0')]]}]}]})['then'](handleEntityNotFound(_0x2ff9fd,null))[_0x936f('0x25')](function(_0x4a516e){if(_0x4a516e&&_0x4a516e[_0x936f('0xb8')]){_0x40f0ec=_0x4a516e[_0x936f('0x62')]({'plain':!![]});if(_0x40f0ec[_0x936f('0xb8')]&&_0x40f0ec[_0x936f('0xb8')][_0x936f('0x9f')][_0x936f('0x50')]){return _0x40f0ec[_0x936f('0xb8')][_0x936f('0x9f')][0x0];}return db[_0x936f('0x88')][_0x936f('0x5f')](_[_0x936f('0x1d')](_0x1f95b4[_0x936f('0x60')],{'firstName':_0x537bd3,'mobile':_0x537bd3,'phone':_0x537bd3,'ListId':_0x40f0ec['ListId']}));}})[_0x936f('0x25')](handleEntityNotFound(_0x2ff9fd,null))[_0x936f('0x25')](function(_0xf8fcc){if(_0xf8fcc){_0x151117=_0xf8fcc;return db[_0x936f('0xa3')][_0x936f('0x5e')]({'where':{'ContactId':_0x151117['id'],'closed':![],'WhatsappAccountId':_0x40f0ec['id']}})[_0x936f('0x25')](function(_0x146918){if(_0x146918){return[_0x146918,![]];}return db[_0x936f('0xa3')]['create']({'UserId':_0x1f95b4[_0x936f('0x61')]['id'],'ContactId':_0x151117['id'],'WhatsappAccountId':_0x40f0ec['id'],'phone':_0x537bd3,'firstMsgDirection':'out','Messages':[_[_0x936f('0x58')](_0x1f95b4[_0x936f('0x60')],{'read':![],'body':_0x1f95b4['body']['body'],'phone':_0x537bd3,'WhatsappAccountId':_0x40f0ec['id'],'UserId':_0x1f95b4[_0x936f('0x61')]['id'],'ContactId':_0x151117['id']})]},{'include':[{'model':db[_0x936f('0xab')],'as':'Messages'}]})[_0x936f('0x25')](function(_0x38b036){return[_0x38b036,!![]];});});}})[_0x936f('0x77')](function(_0x5f2810,_0x32f4e4){if(_0x32f4e4){return _0x5f2810;}return db[_0x936f('0xab')][_0x936f('0x5f')](_[_0x936f('0x58')](_0x1f95b4['body'],{'read':![],'body':_0x1f95b4[_0x936f('0x60')][_0x936f('0x60')],'phone':_0x537bd3,'WhatsappAccountId':_0x40f0ec['id'],'WhatsappInteractionId':_0x5f2810['id'],'UserId':_0x1f95b4['user']['id'],'ContactId':_0x151117['id']}))[_0x936f('0x25')](function(_0x5ac40f){_0x5f2810['dataValues']['Messages']=[];_0x5f2810['dataValues'][_0x936f('0xb9')]['push'](_0x5ac40f['dataValues']);return _0x5f2810;});})[_0x936f('0x25')](respondWithResult(_0x2ff9fd,null))['catch'](handleError(_0x2ff9fd,null));};
\ No newline at end of file