Built motion from commit a8c4dd89.|2.6.33
[motion2.git] / server / api / whatsappAccount / whatsappAccount.controller.js
index bd400ad..4b7eed1 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf804=['agent','queueId','WhatsappQueue','queue','waitForTheAssignedQueue','startRouting','receiveMessage','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','List','out','Messages','dataValues','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./whatsappAccount.socket','jayson/promise','client','http','request','then','info','WhatsappAccount,\x20%s,\x20%s','request\x20sent','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','sendStatus','end','json','offset','limit','undefined','count','status','save','update','destroy','WhatsappAccounts','UserProfileResource','stack','send','Pause','mandatoryDispositionPause','rawAttributes','fieldName','type','model','map','name','query','keys','intersection','attributes','fields','filters','pick','where','merge','VIRTUAL','filter','WhatsappAccount','includeAll','rows','params','length','include','find','body','role','user','get','UserProfileSection','userProfileId','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','WhatsappAccountId','getDispositions','findOne','Disposition','nolimit','order','sort','findAll','removeDispositions','ids','CannedAnswer','getAnswers','hasOwnProperty','options','removeAnswers','addAgents','omit','spread','emit','userWhatsappAccount:save','removeAgents','isArray','userWhatsappAccount:remove','getAgents','User','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','WhatsappApplication','bulkCreate','priority','getApplications','notify','whatsapp','Applications','account','sinch','statuses','state','read','WhatsappMessage','message_id','orderBy','Sequelize','ValidationError','difference','createdAt','updatedAt','CompanyId','ListId','mobile','twilio','From','Body','from','notifications','messageId','from\x20is\x20mandatory','isNil','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','CmContact','Contacts','DESC','contact','WhatsappInteraction','interaction','applications','push','close','*,*,*,*','created','ContactId','AttachmentId','UserId','unshift'];(function(_0x42fdcf,_0x274558){var _0x4f9dc8=function(_0x5c6e71){while(--_0x5c6e71){_0x42fdcf['push'](_0x42fdcf['shift']());}};_0x4f9dc8(++_0x274558);}(_0xf804,0x197));var _0x4f80=function(_0x122ef9,_0x451d2a){_0x122ef9=_0x122ef9-0x0;var _0x42fba0=_0xf804[_0x122ef9];return _0x42fba0;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x4f80('0x0'));var zipdir=require(_0x4f80('0x1'));var jsonpatch=require(_0x4f80('0x2'));var rp=require(_0x4f80('0x3'));var moment=require(_0x4f80('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x4f80('0x5'));var util=require(_0x4f80('0x6'));var path=require('path');var sox=require(_0x4f80('0x7'));var csv=require(_0x4f80('0x8'));var ejs=require(_0x4f80('0x9'));var fs=require('fs');var fs_extra=require(_0x4f80('0xa'));var _=require(_0x4f80('0xb'));var squel=require(_0x4f80('0xc'));var crypto=require('crypto');var jsforce=require(_0x4f80('0xd'));var deskjs=require(_0x4f80('0xe'));var toCsv=require(_0x4f80('0x8'));var querystring=require(_0x4f80('0xf'));var Papa=require(_0x4f80('0x10'));var Redis=require(_0x4f80('0x11'));var authService=require(_0x4f80('0x12'));var qs=require(_0x4f80('0x13'));var as=require(_0x4f80('0x14'));var hardwareService=require(_0x4f80('0x15'));var logger=require(_0x4f80('0x16'))('api');var utils=require(_0x4f80('0x17'));var config=require(_0x4f80('0x18'));var licenseUtil=require('../../config/license/util');var db=require(_0x4f80('0x19'))['db'];config[_0x4f80('0x1a')]=_[_0x4f80('0x1b')](config[_0x4f80('0x1a')],{'host':_0x4f80('0x1c'),'port':0x18eb});var socket=require(_0x4f80('0x1d'))(new Redis(config[_0x4f80('0x1a')]));require(_0x4f80('0x1e'))['register'](socket);var jayson=require(_0x4f80('0x1f'));var client=jayson[_0x4f80('0x20')][_0x4f80('0x21')]({'port':0x232c});function respondWithRpcPromise(_0x3a1992,_0xb4fd11,_0x7eab79,_0x2ace1a){return new BPromise(function(_0x49df56,_0x56970f){var _0x5bc15e=_0x2ace1a||client;return _0x5bc15e[_0x4f80('0x22')](_0x3a1992,_0x7eab79)[_0x4f80('0x23')](function(_0x15486f){logger[_0x4f80('0x24')](_0x4f80('0x25'),_0xb4fd11,_0x4f80('0x26'));logger[_0x4f80('0x27')](_0x4f80('0x28'),_0xb4fd11,_0x4f80('0x26'),JSON[_0x4f80('0x29')](_0x15486f));if(_0x15486f[_0x4f80('0x2a')]){if(_0x15486f['error'][_0x4f80('0x2b')]===0x1f4){logger[_0x4f80('0x2a')](_0x4f80('0x25'),_0xb4fd11,_0x15486f[_0x4f80('0x2a')][_0x4f80('0x2c')]);return _0x56970f(_0x15486f['error']['message']);}logger['error'](_0x4f80('0x25'),_0xb4fd11,_0x15486f[_0x4f80('0x2a')][_0x4f80('0x2c')]);return _0x49df56(_0x15486f[_0x4f80('0x2a')]['message']);}else{logger['info'](_0x4f80('0x25'),_0xb4fd11,'request\x20sent');_0x49df56(_0x15486f['result'][_0x4f80('0x2c')]);}})[_0x4f80('0x2d')](function(_0x58ce6d){logger[_0x4f80('0x2a')](_0x4f80('0x25'),_0xb4fd11,_0x58ce6d);_0x56970f(_0x58ce6d);});});}function respondWithStatusCode(_0x12ce84,_0x1b0017){_0x1b0017=_0x1b0017||0xcc;return function(_0x1c1b03){if(_0x1c1b03){return _0x12ce84[_0x4f80('0x2e')](_0x1b0017);}return _0x12ce84['status'](_0x1b0017)[_0x4f80('0x2f')]();};}function respondWithResult(_0x35ad53,_0x12f20e){_0x12f20e=_0x12f20e||0xc8;return function(_0x55a818){if(_0x55a818){return _0x35ad53['status'](_0x12f20e)[_0x4f80('0x30')](_0x55a818);}};}function respondWithFilteredResult(_0x1442d2,_0x5e2336){return function(_0x64981d){if(_0x64981d){var _0x479859=typeof _0x5e2336[_0x4f80('0x31')]==='undefined'&&typeof _0x5e2336[_0x4f80('0x32')]===_0x4f80('0x33');var _0x14bd20=_0x64981d[_0x4f80('0x34')];var _0x2da16e=_0x479859?0x0:_0x5e2336[_0x4f80('0x31')];var _0x4b30e7=_0x479859?_0x64981d[_0x4f80('0x34')]:_0x5e2336['offset']+_0x5e2336[_0x4f80('0x32')];var _0x58f8e6;if(_0x4b30e7>=_0x14bd20){_0x4b30e7=_0x14bd20;_0x58f8e6=0xc8;}else{_0x58f8e6=0xce;}_0x1442d2[_0x4f80('0x35')](_0x58f8e6);return _0x1442d2['set']('Content-Range',_0x2da16e+'-'+_0x4b30e7+'/'+_0x14bd20)['json'](_0x64981d);}return null;};}function patchUpdates(_0x4ce073){return function(_0x5b89c4){try{jsonpatch['apply'](_0x5b89c4,_0x4ce073,!![]);}catch(_0x43823e){return BPromise['reject'](_0x43823e);}return _0x5b89c4[_0x4f80('0x36')]();};}function saveUpdates(_0x4e0fd7,_0x1fd58d){return function(_0x4c915d){if(_0x4c915d){return _0x4c915d[_0x4f80('0x37')](_0x4e0fd7)[_0x4f80('0x23')](function(_0x3f4598){return _0x3f4598;});}return null;};}function removeEntity(_0x4f2383,_0x18faa1){return function(_0xea7f5b){if(_0xea7f5b){return _0xea7f5b[_0x4f80('0x38')]()[_0x4f80('0x23')](function(){var _0x229e79=_0xea7f5b['get']({'plain':!![]});var _0x3309d4=_0x4f80('0x39');return db[_0x4f80('0x3a')]['destroy']({'where':{'type':_0x3309d4,'resourceId':_0x229e79['id']}})[_0x4f80('0x23')](function(){return _0xea7f5b;});})[_0x4f80('0x23')](function(){_0x4f2383['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0xe45c28,_0x4771a4){return function(_0x46954f){if(!_0x46954f){_0xe45c28[_0x4f80('0x2e')](0x194);}return _0x46954f;};}function handleError(_0x5e71b3,_0x35b1e3){_0x35b1e3=_0x35b1e3||0x1f4;return function(_0x337480){logger[_0x4f80('0x2a')](_0x337480[_0x4f80('0x3b')]);if(_0x337480['name']){delete _0x337480['name'];}_0x5e71b3[_0x4f80('0x35')](_0x35b1e3)[_0x4f80('0x3c')](_0x337480);};}exports['index']=function(_0x21f415,_0x1d82a5){var _0xd210b3={'include':[{'model':db[_0x4f80('0x3d')],'as':_0x4f80('0x3e')}]},_0x581555={},_0x4b632f={'count':0x0,'rows':[]};var _0x5343b9=_['map'](db['WhatsappAccount'][_0x4f80('0x3f')],function(_0x3e05bd){return{'name':_0x3e05bd[_0x4f80('0x40')],'type':_0x3e05bd[_0x4f80('0x41')]['key']};});_0x581555[_0x4f80('0x42')]=_[_0x4f80('0x43')](_0x5343b9,_0x4f80('0x44'));_0x581555[_0x4f80('0x45')]=_[_0x4f80('0x46')](_0x21f415[_0x4f80('0x45')]);_0x581555['filters']=_[_0x4f80('0x47')](_0x581555[_0x4f80('0x42')],_0x581555[_0x4f80('0x45')]);_0xd210b3[_0x4f80('0x48')]=_[_0x4f80('0x47')](_0x581555['model'],qs['fields'](_0x21f415[_0x4f80('0x45')][_0x4f80('0x49')]));_0xd210b3[_0x4f80('0x48')]=_0xd210b3[_0x4f80('0x48')]['length']?_0xd210b3[_0x4f80('0x48')]:_0x581555[_0x4f80('0x42')];if(!_0x21f415[_0x4f80('0x45')]['hasOwnProperty']('nolimit')){_0xd210b3[_0x4f80('0x32')]=qs[_0x4f80('0x32')](_0x21f415['query']['limit']);_0xd210b3['offset']=qs[_0x4f80('0x31')](_0x21f415['query'][_0x4f80('0x31')]);}_0xd210b3['order']=qs['sort'](_0x21f415[_0x4f80('0x45')]['sort']);_0xd210b3['where']=qs[_0x4f80('0x4a')](_[_0x4f80('0x4b')](_0x21f415[_0x4f80('0x45')],_0x581555[_0x4f80('0x4a')]),_0x5343b9);if(_0x21f415['query']['filter']){_0xd210b3[_0x4f80('0x4c')]=_[_0x4f80('0x4d')](_0xd210b3[_0x4f80('0x4c')],{'$or':_['map'](_0x5343b9,function(_0x1704c1){if(_0x1704c1[_0x4f80('0x41')]!==_0x4f80('0x4e')){var _0x352adf={};_0x352adf[_0x1704c1['name']]={'$like':'%'+_0x21f415[_0x4f80('0x45')][_0x4f80('0x4f')]+'%'};return _0x352adf;}})});}_0xd210b3=_[_0x4f80('0x4d')]({},_0xd210b3,_0x21f415['options']);var _0x42cb50={'where':_0xd210b3[_0x4f80('0x4c')]};return db[_0x4f80('0x50')][_0x4f80('0x34')](_0x42cb50)[_0x4f80('0x23')](function(_0x1cffb9){_0x4b632f['count']=_0x1cffb9;if(_0x21f415[_0x4f80('0x45')][_0x4f80('0x51')]){_0xd210b3['include']=[{'all':!![]}];}return db[_0x4f80('0x50')]['findAll'](_0xd210b3);})['then'](function(_0x29e7f9){_0x4b632f[_0x4f80('0x52')]=_0x29e7f9;return _0x4b632f;})['then'](respondWithFilteredResult(_0x1d82a5,_0xd210b3))[_0x4f80('0x2d')](handleError(_0x1d82a5,null));};exports['show']=function(_0x573f66,_0x86edd){var _0x58f167={'raw':![],'where':{'id':_0x573f66[_0x4f80('0x53')]['id']},'include':[{'model':db[_0x4f80('0x3d')],'as':'mandatoryDispositionPause'}]},_0x272a20={};_0x272a20[_0x4f80('0x42')]=_[_0x4f80('0x46')](db[_0x4f80('0x50')][_0x4f80('0x3f')]);_0x272a20[_0x4f80('0x45')]=_[_0x4f80('0x46')](_0x573f66[_0x4f80('0x45')]);_0x272a20[_0x4f80('0x4a')]=_[_0x4f80('0x47')](_0x272a20['model'],_0x272a20[_0x4f80('0x45')]);_0x58f167[_0x4f80('0x48')]=_[_0x4f80('0x47')](_0x272a20[_0x4f80('0x42')],qs[_0x4f80('0x49')](_0x573f66['query'][_0x4f80('0x49')]));_0x58f167[_0x4f80('0x48')]=_0x58f167[_0x4f80('0x48')][_0x4f80('0x54')]?_0x58f167['attributes']:_0x272a20[_0x4f80('0x42')];if(_0x573f66[_0x4f80('0x45')][_0x4f80('0x51')]){_0x58f167[_0x4f80('0x55')]=[{'all':!![]}];}_0x58f167=_[_0x4f80('0x4d')]({},_0x58f167,_0x573f66['options']);return db[_0x4f80('0x50')][_0x4f80('0x56')](_0x58f167)['then'](handleEntityNotFound(_0x86edd,null))[_0x4f80('0x23')](respondWithResult(_0x86edd,null))[_0x4f80('0x2d')](handleError(_0x86edd,null));};exports['create']=function(_0x18e496,_0x3c0e6){return db['WhatsappAccount']['create'](_0x18e496[_0x4f80('0x57')],{})[_0x4f80('0x23')](function(_0x4dfafc){var _0x536bf4=_0x18e496['user']['get']({'plain':!![]});if(!_0x536bf4)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x536bf4[_0x4f80('0x58')]===_0x4f80('0x59')){var _0x2ab247=_0x4dfafc[_0x4f80('0x5a')]({'plain':!![]});var _0x575e02='WhatsappAccounts';return db[_0x4f80('0x5b')][_0x4f80('0x56')]({'where':{'name':_0x575e02,'userProfileId':_0x536bf4[_0x4f80('0x5c')]},'raw':!![]})['then'](function(_0x5101aa){if(_0x5101aa&&_0x5101aa['autoAssociation']===0x0){return db['UserProfileResource'][_0x4f80('0x5d')]({'name':_0x2ab247['name'],'resourceId':_0x2ab247['id'],'type':_0x5101aa[_0x4f80('0x44')],'sectionId':_0x5101aa['id']},{})['then'](function(){return _0x4dfafc;});}else{return _0x4dfafc;}})['catch'](function(_0x39bcc5){logger[_0x4f80('0x2a')](_0x4f80('0x5e'),_0x39bcc5);throw _0x39bcc5;});}return _0x4dfafc;})[_0x4f80('0x23')](respondWithResult(_0x3c0e6,0xc9))[_0x4f80('0x2d')](handleError(_0x3c0e6,null));};exports[_0x4f80('0x37')]=function(_0x32b60a,_0x305684){if(_0x32b60a[_0x4f80('0x57')]['id']){delete _0x32b60a[_0x4f80('0x57')]['id'];}return db[_0x4f80('0x50')][_0x4f80('0x56')]({'where':{'id':_0x32b60a['params']['id']},'include':[{'model':db[_0x4f80('0x3d')],'as':_0x4f80('0x3e')}]})[_0x4f80('0x23')](handleEntityNotFound(_0x305684,null))[_0x4f80('0x23')](saveUpdates(_0x32b60a[_0x4f80('0x57')],null))[_0x4f80('0x23')](respondWithResult(_0x305684,null))[_0x4f80('0x2d')](handleError(_0x305684,null));};exports[_0x4f80('0x38')]=function(_0x5d56da,_0x5b7bd6){return db[_0x4f80('0x50')][_0x4f80('0x56')]({'where':{'id':_0x5d56da['params']['id']}})[_0x4f80('0x23')](handleEntityNotFound(_0x5b7bd6,null))[_0x4f80('0x23')](removeEntity(_0x5b7bd6,null))[_0x4f80('0x2d')](handleError(_0x5b7bd6,null));};exports[_0x4f80('0x5f')]=function(_0x3c50e4,_0x3bd53f){return db['WhatsappAccount']['describe']()[_0x4f80('0x23')](respondWithResult(_0x3bd53f,null))['catch'](handleError(_0x3bd53f,null));};exports['addDisposition']=function(_0x520a39,_0x4594a4,_0x1fcfc3){if(_0x520a39[_0x4f80('0x57')]['id']){delete _0x520a39[_0x4f80('0x57')]['id'];}return db[_0x4f80('0x50')][_0x4f80('0x56')]({'where':{'id':_0x520a39[_0x4f80('0x53')]['id']}})[_0x4f80('0x23')](handleEntityNotFound(_0x4594a4,null))[_0x4f80('0x23')](function(_0x182875){if(_0x182875){_0x520a39['body'][_0x4f80('0x60')]=_0x182875['id'];return db['Disposition'][_0x4f80('0x5d')](_0x520a39['body']);}})[_0x4f80('0x23')](respondWithResult(_0x4594a4,null))[_0x4f80('0x2d')](handleError(_0x4594a4,null));};exports[_0x4f80('0x61')]=function(_0x349e76,_0x3ddfce,_0x52fba0){var _0xccf0c6={'raw':![],'where':{}};var _0x584a9f={};var _0x446b94={'count':0x0,'rows':[]};return db['WhatsappAccount'][_0x4f80('0x62')]({'where':{'id':_0x349e76[_0x4f80('0x53')]['id']}})['then'](handleEntityNotFound(_0x3ddfce,null))['then'](function(_0x2665f5){if(_0x2665f5){_0x584a9f['model']=_['keys'](db[_0x4f80('0x63')][_0x4f80('0x3f')]);_0x584a9f[_0x4f80('0x45')]=_[_0x4f80('0x46')](_0x349e76['query']);_0x584a9f[_0x4f80('0x4a')]=_[_0x4f80('0x47')](_0x584a9f[_0x4f80('0x42')],_0x584a9f[_0x4f80('0x45')]);_0xccf0c6['attributes']=_['intersection'](_0x584a9f[_0x4f80('0x42')],qs[_0x4f80('0x49')](_0x349e76['query']['fields']));_0xccf0c6['attributes']=_0xccf0c6[_0x4f80('0x48')][_0x4f80('0x54')]?_0xccf0c6[_0x4f80('0x48')]:_0x584a9f[_0x4f80('0x42')];if(!_0x349e76[_0x4f80('0x45')]['hasOwnProperty'](_0x4f80('0x64'))){_0xccf0c6[_0x4f80('0x32')]=qs[_0x4f80('0x32')](_0x349e76['query']['limit']);_0xccf0c6['offset']=qs[_0x4f80('0x31')](_0x349e76['query'][_0x4f80('0x31')]);}_0xccf0c6[_0x4f80('0x65')]=qs[_0x4f80('0x66')](_0x349e76[_0x4f80('0x45')][_0x4f80('0x66')]);_0xccf0c6[_0x4f80('0x4c')]=qs[_0x4f80('0x4a')](_[_0x4f80('0x4b')](_0x349e76['query'],_0x584a9f['filters']));_0xccf0c6[_0x4f80('0x4c')][_0x4f80('0x60')]=_0x2665f5['id'];if(_0x349e76[_0x4f80('0x45')][_0x4f80('0x4f')]){_0xccf0c6[_0x4f80('0x4c')]=_[_0x4f80('0x4d')](_0xccf0c6[_0x4f80('0x4c')],{'$or':_[_0x4f80('0x43')](_0xccf0c6[_0x4f80('0x48')],function(_0x91a723){var _0x5c4832={};_0x5c4832[_0x91a723]={'$like':'%'+_0x349e76[_0x4f80('0x45')][_0x4f80('0x4f')]+'%'};return _0x5c4832;})});}_0xccf0c6=_['merge']({},_0xccf0c6,_0x349e76['options']);return db[_0x4f80('0x63')][_0x4f80('0x34')]({'where':_0xccf0c6[_0x4f80('0x4c')]})[_0x4f80('0x23')](function(_0x1b5711){_0x446b94[_0x4f80('0x34')]=_0x1b5711;if(_0x349e76['query'][_0x4f80('0x51')]){_0xccf0c6[_0x4f80('0x55')]=[{'all':!![]}];}return db[_0x4f80('0x63')][_0x4f80('0x67')](_0xccf0c6);})[_0x4f80('0x23')](function(_0x41e0b7){_0x446b94['rows']=_0x41e0b7;return _0x446b94;});}})[_0x4f80('0x23')](respondWithFilteredResult(_0x3ddfce,_0xccf0c6))[_0x4f80('0x2d')](handleError(_0x3ddfce,null));};exports[_0x4f80('0x68')]=function(_0x4ff3f9,_0x2d451b,_0x2ece78){return db[_0x4f80('0x50')][_0x4f80('0x56')]({'where':{'id':_0x4ff3f9['params']['id']}})['then'](handleEntityNotFound(_0x2d451b,null))[_0x4f80('0x23')](function(_0x3dc91b){if(_0x3dc91b){return _0x3dc91b[_0x4f80('0x68')](_0x4ff3f9['query'][_0x4f80('0x69')]);}})['then'](respondWithStatusCode(_0x2d451b,null))[_0x4f80('0x2d')](handleError(_0x2d451b,null));};exports['addAnswer']=function(_0x5f4064,_0x4a595e,_0x1cd075){if(_0x5f4064['body']['id']){delete _0x5f4064['body']['id'];}return db[_0x4f80('0x50')]['find']({'where':{'id':_0x5f4064[_0x4f80('0x53')]['id']}})[_0x4f80('0x23')](handleEntityNotFound(_0x4a595e,null))[_0x4f80('0x23')](function(_0x4fe93f){if(_0x4fe93f){_0x5f4064['body']['WhatsappAccountId']=_0x4fe93f['id'];return db[_0x4f80('0x6a')][_0x4f80('0x5d')](_0x5f4064[_0x4f80('0x57')]);}})[_0x4f80('0x23')](respondWithResult(_0x4a595e,null))['catch'](handleError(_0x4a595e,null));};exports[_0x4f80('0x6b')]=function(_0x2fedcc,_0x452f4f,_0x386e61){var _0x4f9e6f={'raw':![],'where':{}};var _0x1b821c={};var _0x2278cd={'count':0x0,'rows':[]};return db['WhatsappAccount']['findOne']({'where':{'id':_0x2fedcc[_0x4f80('0x53')]['id']}})['then'](handleEntityNotFound(_0x452f4f,null))[_0x4f80('0x23')](function(_0x40494d){if(_0x40494d){_0x1b821c[_0x4f80('0x42')]=_[_0x4f80('0x46')](db['CannedAnswer'][_0x4f80('0x3f')]);_0x1b821c['query']=_['keys'](_0x2fedcc[_0x4f80('0x45')]);_0x1b821c[_0x4f80('0x4a')]=_[_0x4f80('0x47')](_0x1b821c[_0x4f80('0x42')],_0x1b821c['query']);_0x4f9e6f[_0x4f80('0x48')]=_[_0x4f80('0x47')](_0x1b821c[_0x4f80('0x42')],qs[_0x4f80('0x49')](_0x2fedcc[_0x4f80('0x45')][_0x4f80('0x49')]));_0x4f9e6f['attributes']=_0x4f9e6f[_0x4f80('0x48')][_0x4f80('0x54')]?_0x4f9e6f[_0x4f80('0x48')]:_0x1b821c[_0x4f80('0x42')];if(!_0x2fedcc[_0x4f80('0x45')][_0x4f80('0x6c')](_0x4f80('0x64'))){_0x4f9e6f[_0x4f80('0x32')]=qs['limit'](_0x2fedcc['query']['limit']);_0x4f9e6f[_0x4f80('0x31')]=qs[_0x4f80('0x31')](_0x2fedcc[_0x4f80('0x45')]['offset']);}_0x4f9e6f['order']=qs[_0x4f80('0x66')](_0x2fedcc['query'][_0x4f80('0x66')]);_0x4f9e6f[_0x4f80('0x4c')]=qs[_0x4f80('0x4a')](_[_0x4f80('0x4b')](_0x2fedcc[_0x4f80('0x45')],_0x1b821c[_0x4f80('0x4a')]));_0x4f9e6f[_0x4f80('0x4c')][_0x4f80('0x60')]=_0x40494d['id'];if(_0x2fedcc[_0x4f80('0x45')][_0x4f80('0x4f')]){_0x4f9e6f[_0x4f80('0x4c')]=_['merge'](_0x4f9e6f[_0x4f80('0x4c')],{'$or':_['map'](_0x4f9e6f[_0x4f80('0x48')],function(_0xd2586a){var _0x4e13fc={};_0x4e13fc[_0xd2586a]={'$like':'%'+_0x2fedcc[_0x4f80('0x45')][_0x4f80('0x4f')]+'%'};return _0x4e13fc;})});}_0x4f9e6f=_[_0x4f80('0x4d')]({},_0x4f9e6f,_0x2fedcc[_0x4f80('0x6d')]);return db[_0x4f80('0x6a')][_0x4f80('0x34')]({'where':_0x4f9e6f[_0x4f80('0x4c')]})[_0x4f80('0x23')](function(_0x1ab1e6){_0x2278cd[_0x4f80('0x34')]=_0x1ab1e6;if(_0x2fedcc[_0x4f80('0x45')][_0x4f80('0x51')]){_0x4f9e6f['include']=[{'all':!![]}];}return db['CannedAnswer'][_0x4f80('0x67')](_0x4f9e6f);})[_0x4f80('0x23')](function(_0x50a15d){_0x2278cd[_0x4f80('0x52')]=_0x50a15d;return _0x2278cd;});}})[_0x4f80('0x23')](respondWithFilteredResult(_0x452f4f,_0x4f9e6f))[_0x4f80('0x2d')](handleError(_0x452f4f,null));};exports[_0x4f80('0x6e')]=function(_0x2a7917,_0x4d4b84,_0x441aa2){return db[_0x4f80('0x50')][_0x4f80('0x56')]({'where':{'id':_0x2a7917[_0x4f80('0x53')]['id']}})['then'](handleEntityNotFound(_0x4d4b84,null))[_0x4f80('0x23')](function(_0x369254){if(_0x369254){return _0x369254[_0x4f80('0x6e')](_0x2a7917[_0x4f80('0x45')]['ids']);}})[_0x4f80('0x23')](respondWithStatusCode(_0x4d4b84,null))[_0x4f80('0x2d')](handleError(_0x4d4b84,null));};exports[_0x4f80('0x6f')]=function(_0xa7f402,_0x1e5893,_0x1b72f0){return db[_0x4f80('0x50')][_0x4f80('0x56')]({'where':{'id':_0xa7f402['params']['id']}})[_0x4f80('0x23')](handleEntityNotFound(_0x1e5893,null))['then'](function(_0x2e189b){if(_0x2e189b){return _0x2e189b[_0x4f80('0x6f')](_0xa7f402[_0x4f80('0x57')][_0x4f80('0x69')],_[_0x4f80('0x70')](_0xa7f402[_0x4f80('0x57')],[_0x4f80('0x69'),'id'])||{})[_0x4f80('0x71')](function(_0x5ae7fd){for(var _0x2d77e3=0x0;_0x2d77e3<_0xa7f402['body']['ids'][_0x4f80('0x54')];_0x2d77e3+=0x1){socket[_0x4f80('0x72')](_0x4f80('0x73'),{'UserId':Number(_0xa7f402[_0x4f80('0x57')][_0x4f80('0x69')][_0x2d77e3]),'WhatsappAccountId':Number(_0xa7f402[_0x4f80('0x53')]['id'])});}return _0x5ae7fd;});}})[_0x4f80('0x23')](respondWithResult(_0x1e5893,null))[_0x4f80('0x2d')](handleError(_0x1e5893,null));};exports[_0x4f80('0x74')]=function(_0x398b12,_0x177dda,_0x4dba3b){return db['WhatsappAccount'][_0x4f80('0x56')]({'where':{'id':_0x398b12['params']['id']}})['then'](handleEntityNotFound(_0x177dda,null))[_0x4f80('0x23')](function(_0x49ccae){if(_0x49ccae){return _0x49ccae[_0x4f80('0x74')](_0x398b12['query'][_0x4f80('0x69')])[_0x4f80('0x23')](function(){if(_[_0x4f80('0x75')](_0x398b12[_0x4f80('0x45')]['ids'])){for(var _0x18eaf2=0x0;_0x18eaf2<_0x398b12[_0x4f80('0x45')][_0x4f80('0x69')][_0x4f80('0x54')];_0x18eaf2+=0x1){socket[_0x4f80('0x72')]('userWhatsappAccount:remove',{'UserId':Number(_0x398b12[_0x4f80('0x45')]['ids'][_0x18eaf2]),'WhatsappAccountId':Number(_0x398b12[_0x4f80('0x53')]['id'])});}}else{socket[_0x4f80('0x72')](_0x4f80('0x76'),{'UserId':Number(_0x398b12['query'][_0x4f80('0x69')]),'WhatsappAccountId':Number(_0x398b12[_0x4f80('0x53')]['id'])});}});}})[_0x4f80('0x23')](respondWithStatusCode(_0x177dda,null))[_0x4f80('0x2d')](handleError(_0x177dda,null));};exports[_0x4f80('0x77')]=function(_0x3b70ac,_0x488aa6,_0xa02e32){var _0x44ab97={};var _0x21b1af={};var _0x5ae151;var _0x224656;return db[_0x4f80('0x50')][_0x4f80('0x62')]({'where':{'id':_0x3b70ac[_0x4f80('0x53')]['id']}})[_0x4f80('0x23')](handleEntityNotFound(_0x488aa6,null))[_0x4f80('0x23')](function(_0x2d76cd){if(_0x2d76cd){_0x5ae151=_0x2d76cd;_0x21b1af[_0x4f80('0x42')]=_[_0x4f80('0x46')](db[_0x4f80('0x78')][_0x4f80('0x3f')]);_0x21b1af[_0x4f80('0x45')]=_[_0x4f80('0x46')](_0x3b70ac[_0x4f80('0x45')]);_0x21b1af[_0x4f80('0x4a')]=_[_0x4f80('0x47')](_0x21b1af[_0x4f80('0x42')],_0x21b1af[_0x4f80('0x45')]);_0x44ab97[_0x4f80('0x48')]=_[_0x4f80('0x47')](_0x21b1af['model'],qs[_0x4f80('0x49')](_0x3b70ac['query'][_0x4f80('0x49')]));_0x44ab97[_0x4f80('0x48')]=_0x44ab97[_0x4f80('0x48')]['length']?_0x44ab97[_0x4f80('0x48')]:_0x21b1af[_0x4f80('0x42')];_0x44ab97[_0x4f80('0x65')]=qs['sort'](_0x3b70ac[_0x4f80('0x45')][_0x4f80('0x66')]);_0x44ab97[_0x4f80('0x4c')]=qs[_0x4f80('0x4a')](_[_0x4f80('0x4b')](_0x3b70ac[_0x4f80('0x45')],_0x21b1af[_0x4f80('0x4a')]));if(_0x3b70ac[_0x4f80('0x45')]['filter']){_0x44ab97[_0x4f80('0x4c')]=_['merge'](_0x44ab97[_0x4f80('0x4c')],{'$or':_[_0x4f80('0x43')](_0x44ab97['attributes'],function(_0x134c69){var _0x3fb531={};_0x3fb531[_0x134c69]={'$like':'%'+_0x3b70ac['query'][_0x4f80('0x4f')]+'%'};return _0x3fb531;})});}_0x44ab97=_['merge']({},_0x44ab97,_0x3b70ac[_0x4f80('0x6d')]);return _0x5ae151['getAgents'](_0x44ab97);}})[_0x4f80('0x23')](function(_0x2301ff){if(_0x2301ff){_0x224656=_0x2301ff[_0x4f80('0x54')];if(!_0x3b70ac[_0x4f80('0x45')][_0x4f80('0x6c')](_0x4f80('0x64'))){_0x44ab97['limit']=qs['limit'](_0x3b70ac[_0x4f80('0x45')][_0x4f80('0x32')]);_0x44ab97['offset']=qs[_0x4f80('0x31')](_0x3b70ac[_0x4f80('0x45')][_0x4f80('0x31')]);}return _0x5ae151[_0x4f80('0x77')](_0x44ab97);}})['then'](function(_0x2c2973){if(_0x2c2973){return _0x2c2973?{'count':_0x224656,'rows':_0x2c2973}:null;}})[_0x4f80('0x23')](respondWithResult(_0x488aa6,null))[_0x4f80('0x2d')](handleError(_0x488aa6,null));};exports[_0x4f80('0x79')]=function(_0x109a78,_0x3ca09d){var _0x115625=_0x109a78[_0x4f80('0x53')]['id'];var _0x57e613=_0x109a78[_0x4f80('0x57')];var _0xd87e52=0xc8;var _0xbc9f66=null;return db[_0x4f80('0x7a')][_0x4f80('0x7b')]({'isolationLevel':db['sequelize'][_0x4f80('0x7c')][_0x4f80('0x7d')][_0x4f80('0x7e')]},function(_0x4f7574){return db['WhatsappAccount'][_0x4f80('0x62')]({'where':{'id':_0x115625},'transaction':_0x4f7574})['then'](function(_0xa9ee0f){if(_0xa9ee0f){return db[_0x4f80('0x7f')]['destroy']({'where':{'WhatsappAccountId':_0x115625},'transaction':_0x4f7574})[_0x4f80('0x23')](function(){var _0x4198c7=_[_0x4f80('0x43')](_0x57e613,function(_0x5c7139){_0x5c7139['WhatsappAccountId']=_0x115625;return _0x5c7139;});return db[_0x4f80('0x7f')][_0x4f80('0x80')](_0x4198c7,{'transaction':_0x4f7574});});}else{_0xd87e52=0x194;_0xbc9f66=[];}});})[_0x4f80('0x23')](function(){if(_0xd87e52!==0x194){return db[_0x4f80('0x7f')]['findAndCountAll']({'where':{'WhatsappAccountId':_0x115625},'order':_0x4f80('0x81')})['then'](function(_0x1ee5ef){_0xbc9f66=_0x1ee5ef;});}})[_0x4f80('0x2d')](function(_0x1031e0){_0xd87e52=0x1f4;logger[_0x4f80('0x2a')](_0x1031e0[_0x4f80('0x3b')]);if(_0x1031e0['name']){delete _0x1031e0[_0x4f80('0x44')];}_0xbc9f66=_0x1031e0;})['finally'](function(){if(_0xbc9f66===null){_0x3ca09d[_0x4f80('0x2e')](_0xd87e52);}else{if(_0xd87e52===0x1f4){_0x3ca09d[_0x4f80('0x35')](_0xd87e52)['send'](_0xbc9f66);}else{_0x3ca09d['status'](_0xd87e52)['json'](_0xbc9f66);}}});};exports['getApplications']=function(_0x3f7890,_0x5c21ad,_0x258074){var _0x2e8f3d={};var _0x1863bc={};var _0x1fad04;var _0x3c0af7;return db[_0x4f80('0x50')][_0x4f80('0x62')]({'where':{'id':_0x3f7890[_0x4f80('0x53')]['id']}})[_0x4f80('0x23')](handleEntityNotFound(_0x5c21ad,null))[_0x4f80('0x23')](function(_0x413b62){if(_0x413b62){_0x1fad04=_0x413b62;_0x1863bc[_0x4f80('0x42')]=_[_0x4f80('0x46')](db[_0x4f80('0x7f')][_0x4f80('0x3f')]);_0x1863bc[_0x4f80('0x45')]=_['keys'](_0x3f7890[_0x4f80('0x45')]);_0x1863bc[_0x4f80('0x4a')]=_[_0x4f80('0x47')](_0x1863bc[_0x4f80('0x42')],_0x1863bc[_0x4f80('0x45')]);_0x2e8f3d[_0x4f80('0x48')]=_['intersection'](_0x1863bc[_0x4f80('0x42')],qs[_0x4f80('0x49')](_0x3f7890[_0x4f80('0x45')]['fields']));_0x2e8f3d[_0x4f80('0x48')]=_0x2e8f3d[_0x4f80('0x48')][_0x4f80('0x54')]?_0x2e8f3d[_0x4f80('0x48')]:_0x1863bc['model'];_0x2e8f3d[_0x4f80('0x65')]=qs[_0x4f80('0x66')](_0x3f7890[_0x4f80('0x45')][_0x4f80('0x66')]);_0x2e8f3d[_0x4f80('0x4c')]=qs[_0x4f80('0x4a')](_[_0x4f80('0x4b')](_0x3f7890[_0x4f80('0x45')],_0x1863bc[_0x4f80('0x4a')]));if(_0x3f7890['query'][_0x4f80('0x4f')]){_0x2e8f3d[_0x4f80('0x4c')]=_[_0x4f80('0x4d')](_0x2e8f3d[_0x4f80('0x4c')],{'$or':_[_0x4f80('0x43')](_0x2e8f3d['attributes'],function(_0x233394){var _0x24c739={};_0x24c739[_0x233394]={'$like':'%'+_0x3f7890['query'][_0x4f80('0x4f')]+'%'};return _0x24c739;})});}_0x2e8f3d=_[_0x4f80('0x4d')]({},_0x2e8f3d,_0x3f7890[_0x4f80('0x6d')]);return _0x1fad04['getApplications'](_0x2e8f3d);}})['then'](function(_0xa566db){if(_0xa566db){_0x3c0af7=_0xa566db['length'];if(!_0x3f7890[_0x4f80('0x45')]['hasOwnProperty']('nolimit')){_0x2e8f3d[_0x4f80('0x32')]=qs[_0x4f80('0x32')](_0x3f7890['query'][_0x4f80('0x32')]);_0x2e8f3d['offset']=qs[_0x4f80('0x31')](_0x3f7890[_0x4f80('0x45')][_0x4f80('0x31')]);}return _0x1fad04[_0x4f80('0x82')](_0x2e8f3d);}})['then'](function(_0x2975df){if(_0x2975df){return _0x2975df?{'count':_0x3c0af7,'rows':_0x2975df}:null;}})[_0x4f80('0x23')](respondWithResult(_0x5c21ad,null))[_0x4f80('0x2d')](handleError(_0x5c21ad,null));};exports[_0x4f80('0x83')]=function(_0x2704e2,_0x499706,_0x440c03){var _0x44554b={'channel':_0x4f80('0x84')};var _0x116837=[];var _0x2ec91e=[];var _0x4a102a={};return db[_0x4f80('0x50')]['find']({'where':{'id':_0x2704e2[_0x4f80('0x53')]['id']},'include':[{'model':db[_0x4f80('0x7f')],'as':_0x4f80('0x85')}]})[_0x4f80('0x23')](handleEntityNotFound(_0x499706,null))[_0x4f80('0x23')](function(_0x41c6ca){_0x44554b[_0x4f80('0x86')]=_0x41c6ca;if(_0x44554b[_0x4f80('0x86')]&&_0x44554b[_0x4f80('0x86')]['type']===_0x4f80('0x87')&&_0x2704e2[_0x4f80('0x57')][_0x4f80('0x88')]){if(_0x2704e2[_0x4f80('0x57')][_0x4f80('0x88')][_0x4f80('0x54')]===0x0)return;if(_0x2704e2[_0x4f80('0x57')]['statuses'][0x0][_0x4f80('0x89')]!==_0x4f80('0x8a'))return;return db[_0x4f80('0x8b')]['update']({'read':!![],'readAt':_0x2704e2[_0x4f80('0x57')][_0x4f80('0x88')][0x0]['timestamp']},{'where':{'messageId':_0x2704e2[_0x4f80('0x57')]['statuses'][0x0][_0x4f80('0x8c')]},'individualHooks':!![]})[_0x4f80('0x23')](function(_0x3df654){return _0x499706[_0x4f80('0x35')](0xc8)[_0x4f80('0x30')](_0x3df654);});}_0x44554b['applications']=_[_0x4f80('0x8d')](_0x41c6ca['Applications'],[_0x4f80('0x81')],['asc']);if(_0x44554b[_0x4f80('0x86')]['Applications']){delete _0x44554b[_0x4f80('0x86')]['Applications'];}return db['CmContact'][_0x4f80('0x5f')]()['then'](function(_0x4487c0){if(!_0x4487c0){throw new db[(_0x4f80('0x8e'))][(_0x4f80('0x8f'))]('no\x20available\x20attributes');}_0x116837=_[_0x4f80('0x90')](_[_0x4f80('0x46')](_0x4487c0),[_0x4f80('0x91'),_0x4f80('0x92')]);_0x2ec91e=_[_0x4f80('0x90')](_[_0x4f80('0x46')](_0x4487c0),[_0x4f80('0x91'),_0x4f80('0x92'),_0x4f80('0x93'),_0x4f80('0x94')]);_0x44554b[_0x4f80('0x57')]={'mapKey':_0x4f80('0x95')};if(_0x44554b[_0x4f80('0x86')]&&_0x44554b[_0x4f80('0x86')][_0x4f80('0x41')]===_0x4f80('0x96')){_0x44554b['body']['from']=_0x2704e2['body'][_0x4f80('0x97')]['replace']('whatsapp:','');_0x44554b[_0x4f80('0x57')][_0x4f80('0x57')]=_0x2704e2[_0x4f80('0x57')][_0x4f80('0x98')];_0x44554b['body']['messageId']=_0x2704e2[_0x4f80('0x57')]['MessageSid'];}if(_0x44554b[_0x4f80('0x86')]&&_0x44554b[_0x4f80('0x86')]['type']===_0x4f80('0x87')){_0x44554b['body'][_0x4f80('0x99')]=_0x2704e2[_0x4f80('0x57')][_0x4f80('0x9a')][0x0][_0x4f80('0x99')];_0x44554b[_0x4f80('0x57')][_0x4f80('0x57')]=_0x2704e2[_0x4f80('0x57')][_0x4f80('0x9a')][0x0][_0x4f80('0x2c')][_0x4f80('0x57')];_0x44554b[_0x4f80('0x57')][_0x4f80('0x9b')]=_0x2704e2[_0x4f80('0x57')][_0x4f80('0x9a')][0x0]['message_id'];}if(_0x44554b['body']['id']){delete _0x44554b[_0x4f80('0x57')]['id'];}if(_['isNil'](_0x44554b[_0x4f80('0x57')][_0x4f80('0x99')])){throw new db[(_0x4f80('0x8e'))][(_0x4f80('0x8f'))](_0x4f80('0x9c'));}if(_[_0x4f80('0x9d')](_0x44554b[_0x4f80('0x57')][_0x4f80('0x57')])||_0x44554b[_0x4f80('0x57')][_0x4f80('0x57')]===''){throw new db['Sequelize']['ValidationError'](_0x4f80('0x9e'));}if(_[_0x4f80('0x9d')](_0x44554b[_0x4f80('0x57')][_0x4f80('0x9f')])){throw new db[(_0x4f80('0x8e'))][(_0x4f80('0x8f'))](_0x4f80('0xa0')+_0x2ec91e);}if(!_['includes'](_0x2ec91e,_0x44554b[_0x4f80('0x57')][_0x4f80('0x9f')])){throw new db[(_0x4f80('0x8e'))][(_0x4f80('0x8f'))](_0x4f80('0xa1')+_0x2ec91e);}_0x4a102a[_0x44554b[_0x4f80('0x57')]['mapKey']]=_0x44554b[_0x4f80('0x57')]['from'];return db[_0x4f80('0xa2')][_0x4f80('0x56')]({'where':{'id':_0x44554b[_0x4f80('0x86')][_0x4f80('0x94')]},'include':[{'model':db[_0x4f80('0xa3')],'as':_0x4f80('0xa4'),'where':_0x4a102a,'limit':0x1,'order':[[_0x4f80('0x92'),_0x4f80('0xa5')]]}]});})[_0x4f80('0x23')](handleEntityNotFound(_0x499706,null))[_0x4f80('0x23')](function(_0x21a389){if(_0x21a389){_0x44554b['list']=_[_0x4f80('0x70')](_0x21a389,['Contacts']);if(_0x21a389[_0x4f80('0xa4')][_0x4f80('0x54')]){return _0x21a389[_0x4f80('0xa4')][0x0];}var _0x2600be=_[_0x4f80('0x1b')](_0x44554b[_0x4f80('0x57')],{'firstName':_0x44554b[_0x4f80('0x57')][_0x4f80('0x99')],'ListId':_0x21a389['id']});_0x2600be[_0x44554b[_0x4f80('0x57')][_0x4f80('0x9f')]]=_0x44554b[_0x4f80('0x57')][_0x4f80('0x99')];return db[_0x4f80('0xa3')][_0x4f80('0x5d')](_0x2600be,{'fields':_0x116837,'raw':!![]});}})[_0x4f80('0x23')](handleEntityNotFound(_0x499706,null))[_0x4f80('0x23')](function(_0x28eb90){if(_0x28eb90){_0x44554b[_0x4f80('0xa6')]=_0x28eb90;var _0x542d8f={'ContactId':_0x28eb90['id'],'phone':_0x44554b['body'][_0x4f80('0x99')],'WhatsappAccountId':_0x2704e2[_0x4f80('0x53')]['id']};var _0x393e14={'ContactId':_0x28eb90['id'],'WhatsappAccountId':_0x2704e2[_0x4f80('0x53')]['id'],'closed':![]};return db[_0x4f80('0xa7')]['find']({'where':_0x393e14})['then'](function(_0x503529){if(_0x503529){return[_0x503529,![]];}return db[_0x4f80('0xa7')][_0x4f80('0x5d')](_0x542d8f)['then'](function(_0x216036){return[_0x216036,!![]];});});}})['spread'](function(_0x12d2ae,_0x449e98){_0x44554b[_0x4f80('0xa8')]=_0x12d2ae['get']({'plain':!![]});_0x44554b['interaction']['created']=![];if(_0x449e98){if(_0x44554b[_0x4f80('0x86')]['autoclose']){_0x44554b[_0x4f80('0xa9')][_0x4f80('0xaa')]({'id':0x0,'priority':_0x44554b['applications']['length']+0x1,'app':_0x4f80('0xab'),'appdata':'unmanaged','interval':_0x4f80('0xac')});}_0x44554b[_0x4f80('0xa8')][_0x4f80('0xad')]=!![];}return db[_0x4f80('0x8b')][_0x4f80('0x5d')]({'phone':_0x44554b[_0x4f80('0x57')]['from'],'messageId':_0x44554b['body']['messageId'],'body':_0x44554b[_0x4f80('0x57')][_0x4f80('0x57')],'WhatsappAccountId':_0x2704e2[_0x4f80('0x53')]['id'],'WhatsappInteractionId':_0x12d2ae['id'],'direction':'in','ContactId':_0x12d2ae[_0x4f80('0xae')],'AttachmentId':_0x44554b['body'][_0x4f80('0xaf')]});})[_0x4f80('0x23')](function(_0x2062a1){_0x44554b[_0x4f80('0x2c')]=_0x2062a1;if(!_0x44554b['interaction'][_0x4f80('0xb0')])return;return db[_0x4f80('0x78')][_0x4f80('0x56')]({'attributes':['id',_0x4f80('0x44')],'where':{'id':_0x44554b[_0x4f80('0xa8')][_0x4f80('0xb0')]}});})['then'](function(_0xd9ced2){if(_0xd9ced2){_0x44554b['applications'][_0x4f80('0xb1')]({'id':0x0,'priority':0x0,'app':_0x4f80('0xb2'),'appdata':_0xd9ced2[_0x4f80('0x44')]+','+(_0x44554b[_0x4f80('0x86')]['waitForTheAssignedAgent']||0xa),'interval':_0x4f80('0xac')});}if(!_0x44554b['interaction'][_0x4f80('0xb3')])return;return db[_0x4f80('0xb4')][_0x4f80('0x56')]({'attributes':['id','name'],'where':{'id':_0x44554b[_0x4f80('0xa8')]['queueId']}});})[_0x4f80('0x23')](function(_0x41ac3a){if(_0x41ac3a){_0x44554b['applications']['unshift']({'id':0x0,'priority':0x1,'app':_0x4f80('0xb5'),'appdata':_0x41ac3a[_0x4f80('0x44')]+','+(_0x44554b['account'][_0x4f80('0xb6')]||0x12c),'interval':_0x4f80('0xac')});}return respondWithRpcPromise('Start',_0x4f80('0xb7'),_0x44554b);})[_0x4f80('0x23')](function(_0x129f1f){if(_0x129f1f){var _0x3bf90f=0xc8;var _0x2e20ea=_0x4f80('0xb8');logger['info']('WhatsappAccount,\x20%s,\x20%s,\x20%s',_0x2e20ea,_0x3bf90f,_0x4f80('0xb9'));logger[_0x4f80('0x27')](_0x4f80('0xba'),_0x2e20ea,_0x3bf90f,_0x4f80('0xb9'),JSON[_0x4f80('0x29')](_0x129f1f));if(_0x44554b[_0x4f80('0x86')][_0x4f80('0x41')]===_0x4f80('0x96')){return _0x499706[_0x4f80('0x35')](_0x3bf90f)[_0x4f80('0xbb')](_0x4f80('0xbc'),'text/xml')[_0x4f80('0x3c')](_0x4f80('0xbd'));}else{return _0x499706[_0x4f80('0x35')](_0x3bf90f)[_0x4f80('0x30')](_0x129f1f);}}});})['catch'](handleError(_0x499706,null));};exports[_0x4f80('0x3c')]=function(_0x3985,_0x16e953,_0xdf3cfa){var _0x3ae92a,_0x241948,_0x5eaea7;if(_[_0x4f80('0x9d')](_0x3985[_0x4f80('0x57')][_0x4f80('0x57')])||_0x3985[_0x4f80('0x57')]['body']===''){throw new db[(_0x4f80('0x8e'))][(_0x4f80('0x8f'))](_0x4f80('0x9e'));}if(_[_0x4f80('0x9d')](_0x3985[_0x4f80('0x57')]['to'])){throw new db[(_0x4f80('0x8e'))][(_0x4f80('0x8f'))](_0x4f80('0xbe'));}_0x3ae92a=_0x3985[_0x4f80('0x57')]['to'];return db[_0x4f80('0x50')][_0x4f80('0x56')]({'where':{'id':_0x3985['params']['id']},'include':[{'model':db[_0x4f80('0xa2')],'as':_0x4f80('0xbf'),'include':[{'model':db[_0x4f80('0xa3')],'as':_0x4f80('0xa4'),'where':{'mobile':_0x3ae92a},'limit':0x1,'order':[[_0x4f80('0x92'),_0x4f80('0xa5')]]}]}]})[_0x4f80('0x23')](handleEntityNotFound(_0x16e953,null))[_0x4f80('0x23')](function(_0x297ff0){if(_0x297ff0&&_0x297ff0[_0x4f80('0xbf')]){_0x241948=_0x297ff0[_0x4f80('0x5a')]({'plain':!![]});if(_0x241948['List']&&_0x241948['List'][_0x4f80('0xa4')]['length']){return _0x241948[_0x4f80('0xbf')][_0x4f80('0xa4')][0x0];}return db[_0x4f80('0xa3')][_0x4f80('0x5d')](_[_0x4f80('0x1b')](_0x3985[_0x4f80('0x57')],{'firstName':_0x3ae92a,'mobile':_0x3ae92a,'phone':_0x3ae92a,'ListId':_0x241948[_0x4f80('0x94')]}));}})['then'](handleEntityNotFound(_0x16e953,null))['then'](function(_0x55c731){if(_0x55c731){_0x5eaea7=_0x55c731;return db[_0x4f80('0xa7')][_0x4f80('0x56')]({'where':{'ContactId':_0x5eaea7['id'],'closed':![],'WhatsappAccountId':_0x241948['id']}})['then'](function(_0x555cde){if(_0x555cde){return[_0x555cde,![]];}return db[_0x4f80('0xa7')][_0x4f80('0x5d')]({'UserId':_0x3985['user']['id'],'ContactId':_0x5eaea7['id'],'WhatsappAccountId':_0x241948['id'],'phone':_0x3ae92a,'firstMsgDirection':_0x4f80('0xc0'),'Messages':[_['merge'](_0x3985['body'],{'read':![],'body':_0x3985[_0x4f80('0x57')][_0x4f80('0x57')],'phone':_0x3ae92a,'WhatsappAccountId':_0x241948['id'],'UserId':_0x3985[_0x4f80('0x59')]['id'],'ContactId':_0x5eaea7['id']})]},{'include':[{'model':db['WhatsappMessage'],'as':_0x4f80('0xc1')}]})[_0x4f80('0x23')](function(_0x3a3a78){return[_0x3a3a78,!![]];});});}})['spread'](function(_0x3a1aa7,_0x504b9a){if(_0x504b9a){return _0x3a1aa7;}return db['WhatsappMessage'][_0x4f80('0x5d')](_['merge'](_0x3985[_0x4f80('0x57')],{'read':![],'body':_0x3985[_0x4f80('0x57')][_0x4f80('0x57')],'phone':_0x3ae92a,'WhatsappAccountId':_0x241948['id'],'WhatsappInteractionId':_0x3a1aa7['id'],'UserId':_0x3985[_0x4f80('0x59')]['id'],'ContactId':_0x5eaea7['id']}))[_0x4f80('0x23')](function(_0x203fe0){_0x3a1aa7[_0x4f80('0xc2')][_0x4f80('0xc1')]=[];_0x3a1aa7[_0x4f80('0xc2')][_0x4f80('0xc1')][_0x4f80('0xaa')](_0x203fe0['dataValues']);return _0x3a1aa7;});})['then'](respondWithResult(_0x16e953,null))[_0x4f80('0x2d')](handleError(_0x16e953,null));};
\ No newline at end of file
+var _0x6e9c=['filters','attributes','intersection','fields','length','hasOwnProperty','limit','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','Pause','find','create','body','role','user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','params','Disposition','findOne','nolimit','WhatsappAccountId','removeDispositions','ids','addAnswer','CannedAnswer','rows','addAgents','omit','emit','removeAgents','isArray','userWhatsappAccount:remove','getAgents','order','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','bulkCreate','WhatsappApplication','findAndCountAll','priority','stack','finally','getApplications','notify','whatsapp','account','sinch','statuses','state','read','WhatsappMessage','timestamp','orderBy','Applications','asc','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','updatedAt','difference','createdAt','ListId','mobile','From','replace','whatsapp:','Body','MessageSid','from','messageId','notifications','message_id','isNil','from\x20is\x20mandatory','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey','Contacts','DESC','list','contact','WhatsappInteraction','spread','interaction','created','autoclose','push','applications','close','unmanaged','*,*,*,*','ContactId','AttachmentId','User','UserId','unshift','agent','waitForTheAssignedAgent','queueId','WhatsappQueue','waitForTheAssignedQueue','Start','startRouting','receiveMessage','entity\x20found','WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s','twilio','Content-Type','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','body\x20is\x20mandatory\x20and\x20not\x20empty','to\x20is\x20mandatory','CmList','List','Messages','dataValues','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','util','ejs','fs-extra','lodash','squel','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./whatsappAccount.socket','jayson/promise','client','http','then','info','WhatsappAccount,\x20%s,\x20%s','request\x20sent','WhatsappAccount,\x20%s,\x20%s,\x20%s','error','message','result','sendStatus','end','status','json','offset','undefined','count','set','Content-Range','reject','update','destroy','get','WhatsappAccounts','UserProfileResource','name','send','index','mandatoryDispositionPause','map','WhatsappAccount','rawAttributes','fieldName','type','key','model','query','keys'];(function(_0x11ba09,_0x2a01a8){var _0x44f298=function(_0x59bcc5){while(--_0x59bcc5){_0x11ba09['push'](_0x11ba09['shift']());}};_0x44f298(++_0x2a01a8);}(_0x6e9c,0x153));var _0xc6e9=function(_0x27ad96,_0x2431f9){_0x27ad96=_0x27ad96-0x0;var _0xd75b77=_0x6e9c[_0x27ad96];return _0xd75b77;};'use strict';var emlformat=require(_0xc6e9('0x0'));var rimraf=require(_0xc6e9('0x1'));var zipdir=require(_0xc6e9('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xc6e9('0x3'));var moment=require(_0xc6e9('0x4'));var BPromise=require(_0xc6e9('0x5'));var Mustache=require('mustache');var util=require(_0xc6e9('0x6'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xc6e9('0x7'));var fs=require('fs');var fs_extra=require(_0xc6e9('0x8'));var _=require(_0xc6e9('0x9'));var squel=require(_0xc6e9('0xa'));var crypto=require('crypto');var jsforce=require(_0xc6e9('0xb'));var deskjs=require(_0xc6e9('0xc'));var toCsv=require(_0xc6e9('0xd'));var querystring=require(_0xc6e9('0xe'));var Papa=require(_0xc6e9('0xf'));var Redis=require(_0xc6e9('0x10'));var authService=require(_0xc6e9('0x11'));var qs=require(_0xc6e9('0x12'));var as=require(_0xc6e9('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0xc6e9('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0xc6e9('0x15'));var db=require(_0xc6e9('0x16'))['db'];config[_0xc6e9('0x17')]=_[_0xc6e9('0x18')](config[_0xc6e9('0x17')],{'host':_0xc6e9('0x19'),'port':0x18eb});var socket=require(_0xc6e9('0x1a'))(new Redis(config['redis']));require(_0xc6e9('0x1b'))['register'](socket);var jayson=require(_0xc6e9('0x1c'));var client=jayson[_0xc6e9('0x1d')][_0xc6e9('0x1e')]({'port':0x232c});function respondWithRpcPromise(_0x4939da,_0x5e9fba,_0x57a204,_0xf615e5){return new BPromise(function(_0x44eb58,_0x3004fd){var _0x49dd5c=_0xf615e5||client;return _0x49dd5c['request'](_0x4939da,_0x57a204)[_0xc6e9('0x1f')](function(_0x137ecf){logger[_0xc6e9('0x20')](_0xc6e9('0x21'),_0x5e9fba,_0xc6e9('0x22'));logger['debug'](_0xc6e9('0x23'),_0x5e9fba,_0xc6e9('0x22'),JSON['stringify'](_0x137ecf));if(_0x137ecf['error']){if(_0x137ecf[_0xc6e9('0x24')]['code']===0x1f4){logger[_0xc6e9('0x24')](_0xc6e9('0x21'),_0x5e9fba,_0x137ecf['error'][_0xc6e9('0x25')]);return _0x3004fd(_0x137ecf[_0xc6e9('0x24')][_0xc6e9('0x25')]);}logger[_0xc6e9('0x24')](_0xc6e9('0x21'),_0x5e9fba,_0x137ecf[_0xc6e9('0x24')][_0xc6e9('0x25')]);return _0x44eb58(_0x137ecf[_0xc6e9('0x24')][_0xc6e9('0x25')]);}else{logger[_0xc6e9('0x20')]('WhatsappAccount,\x20%s,\x20%s',_0x5e9fba,_0xc6e9('0x22'));_0x44eb58(_0x137ecf[_0xc6e9('0x26')][_0xc6e9('0x25')]);}})['catch'](function(_0x5257cc){logger[_0xc6e9('0x24')]('WhatsappAccount,\x20%s,\x20%s',_0x5e9fba,_0x5257cc);_0x3004fd(_0x5257cc);});});}function respondWithStatusCode(_0x45693b,_0x20f5f8){_0x20f5f8=_0x20f5f8||0xcc;return function(_0x87928e){if(_0x87928e){return _0x45693b[_0xc6e9('0x27')](_0x20f5f8);}return _0x45693b['status'](_0x20f5f8)[_0xc6e9('0x28')]();};}function respondWithResult(_0x238e79,_0x2eabf1){_0x2eabf1=_0x2eabf1||0xc8;return function(_0x2611bf){if(_0x2611bf){return _0x238e79[_0xc6e9('0x29')](_0x2eabf1)[_0xc6e9('0x2a')](_0x2611bf);}};}function respondWithFilteredResult(_0x2ccead,_0x4c7d2b){return function(_0x497f97){if(_0x497f97){var _0x26cbc5=typeof _0x4c7d2b[_0xc6e9('0x2b')]===_0xc6e9('0x2c')&&typeof _0x4c7d2b['limit']===_0xc6e9('0x2c');var _0x3a9c14=_0x497f97['count'];var _0x4787bd=_0x26cbc5?0x0:_0x4c7d2b[_0xc6e9('0x2b')];var _0x3760bf=_0x26cbc5?_0x497f97[_0xc6e9('0x2d')]:_0x4c7d2b[_0xc6e9('0x2b')]+_0x4c7d2b['limit'];var _0x4aef05;if(_0x3760bf>=_0x3a9c14){_0x3760bf=_0x3a9c14;_0x4aef05=0xc8;}else{_0x4aef05=0xce;}_0x2ccead[_0xc6e9('0x29')](_0x4aef05);return _0x2ccead[_0xc6e9('0x2e')](_0xc6e9('0x2f'),_0x4787bd+'-'+_0x3760bf+'/'+_0x3a9c14)[_0xc6e9('0x2a')](_0x497f97);}return null;};}function patchUpdates(_0x5db620){return function(_0x5b94ff){try{jsonpatch['apply'](_0x5b94ff,_0x5db620,!![]);}catch(_0x31669a){return BPromise[_0xc6e9('0x30')](_0x31669a);}return _0x5b94ff['save']();};}function saveUpdates(_0x1b5f3e,_0xac8c94){return function(_0x464c3d){if(_0x464c3d){return _0x464c3d[_0xc6e9('0x31')](_0x1b5f3e)['then'](function(_0x117c40){return _0x117c40;});}return null;};}function removeEntity(_0x38657e,_0x3e8ffb){return function(_0x427814){if(_0x427814){return _0x427814[_0xc6e9('0x32')]()['then'](function(){var _0x34ffcb=_0x427814[_0xc6e9('0x33')]({'plain':!![]});var _0x1fde88=_0xc6e9('0x34');return db[_0xc6e9('0x35')]['destroy']({'where':{'type':_0x1fde88,'resourceId':_0x34ffcb['id']}})[_0xc6e9('0x1f')](function(){return _0x427814;});})[_0xc6e9('0x1f')](function(){_0x38657e[_0xc6e9('0x29')](0xcc)[_0xc6e9('0x28')]();});}};}function handleEntityNotFound(_0x1a00ea,_0x132bb8){return function(_0x76f049){if(!_0x76f049){_0x1a00ea[_0xc6e9('0x27')](0x194);}return _0x76f049;};}function handleError(_0x5a9d3a,_0x5a0c38){_0x5a0c38=_0x5a0c38||0x1f4;return function(_0x3f3d60){logger[_0xc6e9('0x24')](_0x3f3d60['stack']);if(_0x3f3d60[_0xc6e9('0x36')]){delete _0x3f3d60[_0xc6e9('0x36')];}_0x5a9d3a[_0xc6e9('0x29')](_0x5a0c38)[_0xc6e9('0x37')](_0x3f3d60);};}exports[_0xc6e9('0x38')]=function(_0x279eca,_0xde2354){var _0x28afd3={'include':[{'model':db['Pause'],'as':_0xc6e9('0x39')}]},_0x1ca222={},_0x42ee89={'count':0x0,'rows':[]};var _0x4dc3a5=_[_0xc6e9('0x3a')](db[_0xc6e9('0x3b')][_0xc6e9('0x3c')],function(_0x34dd2a){return{'name':_0x34dd2a[_0xc6e9('0x3d')],'type':_0x34dd2a[_0xc6e9('0x3e')][_0xc6e9('0x3f')]};});_0x1ca222[_0xc6e9('0x40')]=_[_0xc6e9('0x3a')](_0x4dc3a5,'name');_0x1ca222[_0xc6e9('0x41')]=_[_0xc6e9('0x42')](_0x279eca[_0xc6e9('0x41')]);_0x1ca222[_0xc6e9('0x43')]=_['intersection'](_0x1ca222[_0xc6e9('0x40')],_0x1ca222[_0xc6e9('0x41')]);_0x28afd3[_0xc6e9('0x44')]=_[_0xc6e9('0x45')](_0x1ca222['model'],qs[_0xc6e9('0x46')](_0x279eca['query']['fields']));_0x28afd3[_0xc6e9('0x44')]=_0x28afd3[_0xc6e9('0x44')][_0xc6e9('0x47')]?_0x28afd3['attributes']:_0x1ca222[_0xc6e9('0x40')];if(!_0x279eca[_0xc6e9('0x41')][_0xc6e9('0x48')]('nolimit')){_0x28afd3[_0xc6e9('0x49')]=qs[_0xc6e9('0x49')](_0x279eca[_0xc6e9('0x41')]['limit']);_0x28afd3['offset']=qs[_0xc6e9('0x2b')](_0x279eca[_0xc6e9('0x41')][_0xc6e9('0x2b')]);}_0x28afd3['order']=qs[_0xc6e9('0x4a')](_0x279eca[_0xc6e9('0x41')][_0xc6e9('0x4a')]);_0x28afd3['where']=qs[_0xc6e9('0x43')](_[_0xc6e9('0x4b')](_0x279eca[_0xc6e9('0x41')],_0x1ca222[_0xc6e9('0x43')]),_0x4dc3a5);if(_0x279eca[_0xc6e9('0x41')][_0xc6e9('0x4c')]){_0x28afd3[_0xc6e9('0x4d')]=_[_0xc6e9('0x4e')](_0x28afd3['where'],{'$or':_[_0xc6e9('0x3a')](_0x4dc3a5,function(_0x51dcd1){if(_0x51dcd1[_0xc6e9('0x3e')]!==_0xc6e9('0x4f')){var _0x5bcbd4={};_0x5bcbd4[_0x51dcd1[_0xc6e9('0x36')]]={'$like':'%'+_0x279eca[_0xc6e9('0x41')][_0xc6e9('0x4c')]+'%'};return _0x5bcbd4;}})});}_0x28afd3=_['merge']({},_0x28afd3,_0x279eca[_0xc6e9('0x50')]);var _0x390f43={'where':_0x28afd3['where']};return db[_0xc6e9('0x3b')][_0xc6e9('0x2d')](_0x390f43)[_0xc6e9('0x1f')](function(_0x85ddf5){_0x42ee89[_0xc6e9('0x2d')]=_0x85ddf5;if(_0x279eca[_0xc6e9('0x41')][_0xc6e9('0x51')]){_0x28afd3[_0xc6e9('0x52')]=[{'all':!![]}];}return db[_0xc6e9('0x3b')][_0xc6e9('0x53')](_0x28afd3);})[_0xc6e9('0x1f')](function(_0x389c2d){_0x42ee89['rows']=_0x389c2d;return _0x42ee89;})['then'](respondWithFilteredResult(_0xde2354,_0x28afd3))[_0xc6e9('0x54')](handleError(_0xde2354,null));};exports[_0xc6e9('0x55')]=function(_0x2e364e,_0x2f55d6){var _0x7e49c8={'raw':![],'where':{'id':_0x2e364e['params']['id']},'include':[{'model':db[_0xc6e9('0x56')],'as':'mandatoryDispositionPause'}]},_0x33ed6d={};_0x33ed6d['model']=_['keys'](db[_0xc6e9('0x3b')]['rawAttributes']);_0x33ed6d[_0xc6e9('0x41')]=_[_0xc6e9('0x42')](_0x2e364e[_0xc6e9('0x41')]);_0x33ed6d[_0xc6e9('0x43')]=_['intersection'](_0x33ed6d[_0xc6e9('0x40')],_0x33ed6d[_0xc6e9('0x41')]);_0x7e49c8['attributes']=_['intersection'](_0x33ed6d['model'],qs['fields'](_0x2e364e['query'][_0xc6e9('0x46')]));_0x7e49c8[_0xc6e9('0x44')]=_0x7e49c8[_0xc6e9('0x44')][_0xc6e9('0x47')]?_0x7e49c8['attributes']:_0x33ed6d['model'];if(_0x2e364e[_0xc6e9('0x41')][_0xc6e9('0x51')]){_0x7e49c8['include']=[{'all':!![]}];}_0x7e49c8=_[_0xc6e9('0x4e')]({},_0x7e49c8,_0x2e364e[_0xc6e9('0x50')]);return db[_0xc6e9('0x3b')][_0xc6e9('0x57')](_0x7e49c8)[_0xc6e9('0x1f')](handleEntityNotFound(_0x2f55d6,null))['then'](respondWithResult(_0x2f55d6,null))['catch'](handleError(_0x2f55d6,null));};exports['create']=function(_0x2796b4,_0x1bf6a4){return db['WhatsappAccount'][_0xc6e9('0x58')](_0x2796b4[_0xc6e9('0x59')],{})[_0xc6e9('0x1f')](function(_0x598d54){var _0x55154d=_0x2796b4['user']['get']({'plain':!![]});if(!_0x55154d)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x55154d[_0xc6e9('0x5a')]===_0xc6e9('0x5b')){var _0xfcc03=_0x598d54[_0xc6e9('0x33')]({'plain':!![]});var _0x17ccf8='WhatsappAccounts';return db[_0xc6e9('0x5c')][_0xc6e9('0x57')]({'where':{'name':_0x17ccf8,'userProfileId':_0x55154d[_0xc6e9('0x5d')]},'raw':!![]})['then'](function(_0x237809){if(_0x237809&&_0x237809[_0xc6e9('0x5e')]===0x0){return db[_0xc6e9('0x35')][_0xc6e9('0x58')]({'name':_0xfcc03[_0xc6e9('0x36')],'resourceId':_0xfcc03['id'],'type':_0x237809[_0xc6e9('0x36')],'sectionId':_0x237809['id']},{})[_0xc6e9('0x1f')](function(){return _0x598d54;});}else{return _0x598d54;}})['catch'](function(_0xd08f6c){logger[_0xc6e9('0x24')](_0xc6e9('0x5f'),_0xd08f6c);throw _0xd08f6c;});}return _0x598d54;})['then'](respondWithResult(_0x1bf6a4,0xc9))['catch'](handleError(_0x1bf6a4,null));};exports[_0xc6e9('0x31')]=function(_0x30b83c,_0x535308){if(_0x30b83c[_0xc6e9('0x59')]['id']){delete _0x30b83c[_0xc6e9('0x59')]['id'];}return db[_0xc6e9('0x3b')][_0xc6e9('0x57')]({'where':{'id':_0x30b83c['params']['id']},'include':[{'model':db[_0xc6e9('0x56')],'as':'mandatoryDispositionPause'}]})[_0xc6e9('0x1f')](handleEntityNotFound(_0x535308,null))['then'](saveUpdates(_0x30b83c[_0xc6e9('0x59')],null))[_0xc6e9('0x1f')](respondWithResult(_0x535308,null))[_0xc6e9('0x54')](handleError(_0x535308,null));};exports[_0xc6e9('0x32')]=function(_0x5e8810,_0x63113a){return db['WhatsappAccount'][_0xc6e9('0x57')]({'where':{'id':_0x5e8810['params']['id']}})['then'](handleEntityNotFound(_0x63113a,null))[_0xc6e9('0x1f')](removeEntity(_0x63113a,null))[_0xc6e9('0x54')](handleError(_0x63113a,null));};exports['describe']=function(_0x4f1a78,_0xedda93){return db[_0xc6e9('0x3b')][_0xc6e9('0x60')]()['then'](respondWithResult(_0xedda93,null))['catch'](handleError(_0xedda93,null));};exports[_0xc6e9('0x61')]=function(_0x475f00,_0x111464,_0xf1f822){if(_0x475f00[_0xc6e9('0x59')]['id']){delete _0x475f00[_0xc6e9('0x59')]['id'];}return db['WhatsappAccount'][_0xc6e9('0x57')]({'where':{'id':_0x475f00[_0xc6e9('0x62')]['id']}})[_0xc6e9('0x1f')](handleEntityNotFound(_0x111464,null))[_0xc6e9('0x1f')](function(_0x4f67f6){if(_0x4f67f6){_0x475f00[_0xc6e9('0x59')]['WhatsappAccountId']=_0x4f67f6['id'];return db[_0xc6e9('0x63')]['create'](_0x475f00['body']);}})[_0xc6e9('0x1f')](respondWithResult(_0x111464,null))['catch'](handleError(_0x111464,null));};exports['getDispositions']=function(_0x2a5c8d,_0x1c30ed,_0x32cbb2){var _0x37fb41={'raw':![],'where':{}};var _0x412580={};var _0x185ba4={'count':0x0,'rows':[]};return db[_0xc6e9('0x3b')][_0xc6e9('0x64')]({'where':{'id':_0x2a5c8d['params']['id']}})[_0xc6e9('0x1f')](handleEntityNotFound(_0x1c30ed,null))[_0xc6e9('0x1f')](function(_0x1517ab){if(_0x1517ab){_0x412580[_0xc6e9('0x40')]=_['keys'](db[_0xc6e9('0x63')][_0xc6e9('0x3c')]);_0x412580[_0xc6e9('0x41')]=_['keys'](_0x2a5c8d[_0xc6e9('0x41')]);_0x412580[_0xc6e9('0x43')]=_[_0xc6e9('0x45')](_0x412580[_0xc6e9('0x40')],_0x412580[_0xc6e9('0x41')]);_0x37fb41['attributes']=_[_0xc6e9('0x45')](_0x412580[_0xc6e9('0x40')],qs[_0xc6e9('0x46')](_0x2a5c8d['query'][_0xc6e9('0x46')]));_0x37fb41[_0xc6e9('0x44')]=_0x37fb41[_0xc6e9('0x44')][_0xc6e9('0x47')]?_0x37fb41[_0xc6e9('0x44')]:_0x412580[_0xc6e9('0x40')];if(!_0x2a5c8d[_0xc6e9('0x41')][_0xc6e9('0x48')](_0xc6e9('0x65'))){_0x37fb41['limit']=qs[_0xc6e9('0x49')](_0x2a5c8d[_0xc6e9('0x41')]['limit']);_0x37fb41[_0xc6e9('0x2b')]=qs[_0xc6e9('0x2b')](_0x2a5c8d[_0xc6e9('0x41')][_0xc6e9('0x2b')]);}_0x37fb41['order']=qs['sort'](_0x2a5c8d[_0xc6e9('0x41')][_0xc6e9('0x4a')]);_0x37fb41[_0xc6e9('0x4d')]=qs[_0xc6e9('0x43')](_[_0xc6e9('0x4b')](_0x2a5c8d[_0xc6e9('0x41')],_0x412580[_0xc6e9('0x43')]));_0x37fb41[_0xc6e9('0x4d')][_0xc6e9('0x66')]=_0x1517ab['id'];if(_0x2a5c8d[_0xc6e9('0x41')][_0xc6e9('0x4c')]){_0x37fb41[_0xc6e9('0x4d')]=_[_0xc6e9('0x4e')](_0x37fb41[_0xc6e9('0x4d')],{'$or':_[_0xc6e9('0x3a')](_0x37fb41[_0xc6e9('0x44')],function(_0x26615b){var _0x2e7e75={};_0x2e7e75[_0x26615b]={'$like':'%'+_0x2a5c8d['query'][_0xc6e9('0x4c')]+'%'};return _0x2e7e75;})});}_0x37fb41=_[_0xc6e9('0x4e')]({},_0x37fb41,_0x2a5c8d[_0xc6e9('0x50')]);return db[_0xc6e9('0x63')][_0xc6e9('0x2d')]({'where':_0x37fb41[_0xc6e9('0x4d')]})[_0xc6e9('0x1f')](function(_0x19bd28){_0x185ba4['count']=_0x19bd28;if(_0x2a5c8d[_0xc6e9('0x41')][_0xc6e9('0x51')]){_0x37fb41['include']=[{'all':!![]}];}return db[_0xc6e9('0x63')][_0xc6e9('0x53')](_0x37fb41);})[_0xc6e9('0x1f')](function(_0x194449){_0x185ba4['rows']=_0x194449;return _0x185ba4;});}})['then'](respondWithFilteredResult(_0x1c30ed,_0x37fb41))[_0xc6e9('0x54')](handleError(_0x1c30ed,null));};exports['removeDispositions']=function(_0x3f77b7,_0x59d52b,_0x1c265f){return db[_0xc6e9('0x3b')][_0xc6e9('0x57')]({'where':{'id':_0x3f77b7['params']['id']}})[_0xc6e9('0x1f')](handleEntityNotFound(_0x59d52b,null))[_0xc6e9('0x1f')](function(_0x42b4c5){if(_0x42b4c5){return _0x42b4c5[_0xc6e9('0x67')](_0x3f77b7[_0xc6e9('0x41')][_0xc6e9('0x68')]);}})[_0xc6e9('0x1f')](respondWithStatusCode(_0x59d52b,null))[_0xc6e9('0x54')](handleError(_0x59d52b,null));};exports[_0xc6e9('0x69')]=function(_0x5e4f72,_0x17e22d,_0x5a2775){if(_0x5e4f72[_0xc6e9('0x59')]['id']){delete _0x5e4f72[_0xc6e9('0x59')]['id'];}return db[_0xc6e9('0x3b')]['find']({'where':{'id':_0x5e4f72[_0xc6e9('0x62')]['id']}})[_0xc6e9('0x1f')](handleEntityNotFound(_0x17e22d,null))['then'](function(_0x33c8ae){if(_0x33c8ae){_0x5e4f72[_0xc6e9('0x59')][_0xc6e9('0x66')]=_0x33c8ae['id'];return db[_0xc6e9('0x6a')]['create'](_0x5e4f72[_0xc6e9('0x59')]);}})[_0xc6e9('0x1f')](respondWithResult(_0x17e22d,null))[_0xc6e9('0x54')](handleError(_0x17e22d,null));};exports['getAnswers']=function(_0x154348,_0x18c222,_0x3d9271){var _0x183dd0={'raw':![],'where':{}};var _0x28919f={};var _0x54714c={'count':0x0,'rows':[]};return db['WhatsappAccount'][_0xc6e9('0x64')]({'where':{'id':_0x154348[_0xc6e9('0x62')]['id']}})[_0xc6e9('0x1f')](handleEntityNotFound(_0x18c222,null))[_0xc6e9('0x1f')](function(_0x377cdd){if(_0x377cdd){_0x28919f[_0xc6e9('0x40')]=_[_0xc6e9('0x42')](db[_0xc6e9('0x6a')][_0xc6e9('0x3c')]);_0x28919f[_0xc6e9('0x41')]=_['keys'](_0x154348[_0xc6e9('0x41')]);_0x28919f[_0xc6e9('0x43')]=_[_0xc6e9('0x45')](_0x28919f[_0xc6e9('0x40')],_0x28919f[_0xc6e9('0x41')]);_0x183dd0[_0xc6e9('0x44')]=_['intersection'](_0x28919f['model'],qs[_0xc6e9('0x46')](_0x154348['query'][_0xc6e9('0x46')]));_0x183dd0[_0xc6e9('0x44')]=_0x183dd0[_0xc6e9('0x44')]['length']?_0x183dd0[_0xc6e9('0x44')]:_0x28919f[_0xc6e9('0x40')];if(!_0x154348[_0xc6e9('0x41')]['hasOwnProperty'](_0xc6e9('0x65'))){_0x183dd0[_0xc6e9('0x49')]=qs[_0xc6e9('0x49')](_0x154348[_0xc6e9('0x41')][_0xc6e9('0x49')]);_0x183dd0[_0xc6e9('0x2b')]=qs[_0xc6e9('0x2b')](_0x154348[_0xc6e9('0x41')][_0xc6e9('0x2b')]);}_0x183dd0['order']=qs['sort'](_0x154348[_0xc6e9('0x41')][_0xc6e9('0x4a')]);_0x183dd0[_0xc6e9('0x4d')]=qs[_0xc6e9('0x43')](_[_0xc6e9('0x4b')](_0x154348[_0xc6e9('0x41')],_0x28919f[_0xc6e9('0x43')]));_0x183dd0[_0xc6e9('0x4d')]['WhatsappAccountId']=_0x377cdd['id'];if(_0x154348[_0xc6e9('0x41')][_0xc6e9('0x4c')]){_0x183dd0[_0xc6e9('0x4d')]=_[_0xc6e9('0x4e')](_0x183dd0[_0xc6e9('0x4d')],{'$or':_['map'](_0x183dd0[_0xc6e9('0x44')],function(_0xcf1d7b){var _0x59fef0={};_0x59fef0[_0xcf1d7b]={'$like':'%'+_0x154348[_0xc6e9('0x41')][_0xc6e9('0x4c')]+'%'};return _0x59fef0;})});}_0x183dd0=_[_0xc6e9('0x4e')]({},_0x183dd0,_0x154348[_0xc6e9('0x50')]);return db[_0xc6e9('0x6a')][_0xc6e9('0x2d')]({'where':_0x183dd0['where']})['then'](function(_0x3bb84f){_0x54714c['count']=_0x3bb84f;if(_0x154348[_0xc6e9('0x41')][_0xc6e9('0x51')]){_0x183dd0[_0xc6e9('0x52')]=[{'all':!![]}];}return db[_0xc6e9('0x6a')][_0xc6e9('0x53')](_0x183dd0);})['then'](function(_0x5b266b){_0x54714c[_0xc6e9('0x6b')]=_0x5b266b;return _0x54714c;});}})[_0xc6e9('0x1f')](respondWithFilteredResult(_0x18c222,_0x183dd0))['catch'](handleError(_0x18c222,null));};exports['removeAnswers']=function(_0x43fa4b,_0x321b62,_0x5a84dd){return db[_0xc6e9('0x3b')]['find']({'where':{'id':_0x43fa4b[_0xc6e9('0x62')]['id']}})[_0xc6e9('0x1f')](handleEntityNotFound(_0x321b62,null))['then'](function(_0x4edbaf){if(_0x4edbaf){return _0x4edbaf['removeAnswers'](_0x43fa4b[_0xc6e9('0x41')][_0xc6e9('0x68')]);}})[_0xc6e9('0x1f')](respondWithStatusCode(_0x321b62,null))[_0xc6e9('0x54')](handleError(_0x321b62,null));};exports[_0xc6e9('0x6c')]=function(_0x551df1,_0x15bcf2,_0x3b76c1){return db['WhatsappAccount'][_0xc6e9('0x57')]({'where':{'id':_0x551df1[_0xc6e9('0x62')]['id']}})[_0xc6e9('0x1f')](handleEntityNotFound(_0x15bcf2,null))[_0xc6e9('0x1f')](function(_0x54a47f){if(_0x54a47f){return _0x54a47f[_0xc6e9('0x6c')](_0x551df1['body'][_0xc6e9('0x68')],_[_0xc6e9('0x6d')](_0x551df1[_0xc6e9('0x59')],[_0xc6e9('0x68'),'id'])||{})['spread'](function(_0x420fa1){for(var _0x24fc91=0x0;_0x24fc91<_0x551df1[_0xc6e9('0x59')][_0xc6e9('0x68')][_0xc6e9('0x47')];_0x24fc91+=0x1){socket[_0xc6e9('0x6e')]('userWhatsappAccount:save',{'UserId':Number(_0x551df1[_0xc6e9('0x59')]['ids'][_0x24fc91]),'WhatsappAccountId':Number(_0x551df1[_0xc6e9('0x62')]['id'])});}return _0x420fa1;});}})['then'](respondWithResult(_0x15bcf2,null))[_0xc6e9('0x54')](handleError(_0x15bcf2,null));};exports[_0xc6e9('0x6f')]=function(_0x1029de,_0x14a557,_0x2d6be0){return db[_0xc6e9('0x3b')]['find']({'where':{'id':_0x1029de[_0xc6e9('0x62')]['id']}})[_0xc6e9('0x1f')](handleEntityNotFound(_0x14a557,null))['then'](function(_0x291c15){if(_0x291c15){return _0x291c15[_0xc6e9('0x6f')](_0x1029de[_0xc6e9('0x41')]['ids'])[_0xc6e9('0x1f')](function(){if(_[_0xc6e9('0x70')](_0x1029de['query'][_0xc6e9('0x68')])){for(var _0x125be1=0x0;_0x125be1<_0x1029de[_0xc6e9('0x41')][_0xc6e9('0x68')][_0xc6e9('0x47')];_0x125be1+=0x1){socket[_0xc6e9('0x6e')](_0xc6e9('0x71'),{'UserId':Number(_0x1029de[_0xc6e9('0x41')][_0xc6e9('0x68')][_0x125be1]),'WhatsappAccountId':Number(_0x1029de[_0xc6e9('0x62')]['id'])});}}else{socket['emit'](_0xc6e9('0x71'),{'UserId':Number(_0x1029de['query'][_0xc6e9('0x68')]),'WhatsappAccountId':Number(_0x1029de[_0xc6e9('0x62')]['id'])});}});}})['then'](respondWithStatusCode(_0x14a557,null))[_0xc6e9('0x54')](handleError(_0x14a557,null));};exports[_0xc6e9('0x72')]=function(_0xdbb2bf,_0x462856,_0x409a21){var _0x4ba435={};var _0x35f560={};var _0x8a1abf;var _0x44abc5;return db[_0xc6e9('0x3b')]['findOne']({'where':{'id':_0xdbb2bf[_0xc6e9('0x62')]['id']}})['then'](handleEntityNotFound(_0x462856,null))['then'](function(_0x4c01bf){if(_0x4c01bf){_0x8a1abf=_0x4c01bf;_0x35f560[_0xc6e9('0x40')]=_[_0xc6e9('0x42')](db['User'][_0xc6e9('0x3c')]);_0x35f560[_0xc6e9('0x41')]=_[_0xc6e9('0x42')](_0xdbb2bf[_0xc6e9('0x41')]);_0x35f560[_0xc6e9('0x43')]=_['intersection'](_0x35f560[_0xc6e9('0x40')],_0x35f560['query']);_0x4ba435[_0xc6e9('0x44')]=_[_0xc6e9('0x45')](_0x35f560[_0xc6e9('0x40')],qs[_0xc6e9('0x46')](_0xdbb2bf['query'][_0xc6e9('0x46')]));_0x4ba435['attributes']=_0x4ba435[_0xc6e9('0x44')][_0xc6e9('0x47')]?_0x4ba435[_0xc6e9('0x44')]:_0x35f560[_0xc6e9('0x40')];_0x4ba435[_0xc6e9('0x73')]=qs[_0xc6e9('0x4a')](_0xdbb2bf[_0xc6e9('0x41')]['sort']);_0x4ba435[_0xc6e9('0x4d')]=qs[_0xc6e9('0x43')](_['pick'](_0xdbb2bf[_0xc6e9('0x41')],_0x35f560[_0xc6e9('0x43')]));if(_0xdbb2bf[_0xc6e9('0x41')]['filter']){_0x4ba435[_0xc6e9('0x4d')]=_[_0xc6e9('0x4e')](_0x4ba435[_0xc6e9('0x4d')],{'$or':_['map'](_0x4ba435[_0xc6e9('0x44')],function(_0x4d6302){var _0x2dc00e={};_0x2dc00e[_0x4d6302]={'$like':'%'+_0xdbb2bf[_0xc6e9('0x41')]['filter']+'%'};return _0x2dc00e;})});}_0x4ba435=_[_0xc6e9('0x4e')]({},_0x4ba435,_0xdbb2bf[_0xc6e9('0x50')]);return _0x8a1abf[_0xc6e9('0x72')](_0x4ba435);}})[_0xc6e9('0x1f')](function(_0x57219d){if(_0x57219d){_0x44abc5=_0x57219d[_0xc6e9('0x47')];if(!_0xdbb2bf[_0xc6e9('0x41')][_0xc6e9('0x48')](_0xc6e9('0x65'))){_0x4ba435[_0xc6e9('0x49')]=qs[_0xc6e9('0x49')](_0xdbb2bf[_0xc6e9('0x41')][_0xc6e9('0x49')]);_0x4ba435['offset']=qs[_0xc6e9('0x2b')](_0xdbb2bf[_0xc6e9('0x41')][_0xc6e9('0x2b')]);}return _0x8a1abf[_0xc6e9('0x72')](_0x4ba435);}})[_0xc6e9('0x1f')](function(_0x2629b1){if(_0x2629b1){return _0x2629b1?{'count':_0x44abc5,'rows':_0x2629b1}:null;}})[_0xc6e9('0x1f')](respondWithResult(_0x462856,null))['catch'](handleError(_0x462856,null));};exports[_0xc6e9('0x74')]=function(_0x59818f,_0x35c91a){var _0x1cf773=_0x59818f[_0xc6e9('0x62')]['id'];var _0x44acf9=_0x59818f['body'];var _0x13d0ea=0xc8;var _0x45d786=null;return db[_0xc6e9('0x75')][_0xc6e9('0x76')]({'isolationLevel':db[_0xc6e9('0x75')][_0xc6e9('0x77')][_0xc6e9('0x78')][_0xc6e9('0x79')]},function(_0x125e4c){return db[_0xc6e9('0x3b')][_0xc6e9('0x64')]({'where':{'id':_0x1cf773},'transaction':_0x125e4c})['then'](function(_0x1a96df){if(_0x1a96df){return db['WhatsappApplication'][_0xc6e9('0x32')]({'where':{'WhatsappAccountId':_0x1cf773},'transaction':_0x125e4c})[_0xc6e9('0x1f')](function(){var _0x197d15=_['map'](_0x44acf9,function(_0x1d113f){_0x1d113f[_0xc6e9('0x66')]=_0x1cf773;return _0x1d113f;});return db['WhatsappApplication'][_0xc6e9('0x7a')](_0x197d15,{'transaction':_0x125e4c});});}else{_0x13d0ea=0x194;_0x45d786=[];}});})['then'](function(){if(_0x13d0ea!==0x194){return db[_0xc6e9('0x7b')][_0xc6e9('0x7c')]({'where':{'WhatsappAccountId':_0x1cf773},'order':_0xc6e9('0x7d')})[_0xc6e9('0x1f')](function(_0x10e46c){_0x45d786=_0x10e46c;});}})[_0xc6e9('0x54')](function(_0x4d2adb){_0x13d0ea=0x1f4;logger[_0xc6e9('0x24')](_0x4d2adb[_0xc6e9('0x7e')]);if(_0x4d2adb[_0xc6e9('0x36')]){delete _0x4d2adb['name'];}_0x45d786=_0x4d2adb;})[_0xc6e9('0x7f')](function(){if(_0x45d786===null){_0x35c91a[_0xc6e9('0x27')](_0x13d0ea);}else{if(_0x13d0ea===0x1f4){_0x35c91a['status'](_0x13d0ea)['send'](_0x45d786);}else{_0x35c91a[_0xc6e9('0x29')](_0x13d0ea)['json'](_0x45d786);}}});};exports[_0xc6e9('0x80')]=function(_0x29013a,_0x212fab,_0xa3154f){var _0x13eab1={};var _0x4ce093={};var _0x3f9c35;var _0x517457;return db[_0xc6e9('0x3b')][_0xc6e9('0x64')]({'where':{'id':_0x29013a[_0xc6e9('0x62')]['id']}})[_0xc6e9('0x1f')](handleEntityNotFound(_0x212fab,null))[_0xc6e9('0x1f')](function(_0x1c091c){if(_0x1c091c){_0x3f9c35=_0x1c091c;_0x4ce093[_0xc6e9('0x40')]=_[_0xc6e9('0x42')](db[_0xc6e9('0x7b')][_0xc6e9('0x3c')]);_0x4ce093[_0xc6e9('0x41')]=_[_0xc6e9('0x42')](_0x29013a[_0xc6e9('0x41')]);_0x4ce093[_0xc6e9('0x43')]=_['intersection'](_0x4ce093[_0xc6e9('0x40')],_0x4ce093['query']);_0x13eab1['attributes']=_['intersection'](_0x4ce093['model'],qs[_0xc6e9('0x46')](_0x29013a[_0xc6e9('0x41')][_0xc6e9('0x46')]));_0x13eab1['attributes']=_0x13eab1[_0xc6e9('0x44')][_0xc6e9('0x47')]?_0x13eab1[_0xc6e9('0x44')]:_0x4ce093['model'];_0x13eab1['order']=qs[_0xc6e9('0x4a')](_0x29013a[_0xc6e9('0x41')][_0xc6e9('0x4a')]);_0x13eab1[_0xc6e9('0x4d')]=qs[_0xc6e9('0x43')](_['pick'](_0x29013a[_0xc6e9('0x41')],_0x4ce093['filters']));if(_0x29013a[_0xc6e9('0x41')]['filter']){_0x13eab1['where']=_[_0xc6e9('0x4e')](_0x13eab1[_0xc6e9('0x4d')],{'$or':_[_0xc6e9('0x3a')](_0x13eab1[_0xc6e9('0x44')],function(_0x54a8ce){var _0x4f6d5b={};_0x4f6d5b[_0x54a8ce]={'$like':'%'+_0x29013a[_0xc6e9('0x41')]['filter']+'%'};return _0x4f6d5b;})});}_0x13eab1=_[_0xc6e9('0x4e')]({},_0x13eab1,_0x29013a[_0xc6e9('0x50')]);return _0x3f9c35[_0xc6e9('0x80')](_0x13eab1);}})[_0xc6e9('0x1f')](function(_0x221456){if(_0x221456){_0x517457=_0x221456[_0xc6e9('0x47')];if(!_0x29013a[_0xc6e9('0x41')][_0xc6e9('0x48')](_0xc6e9('0x65'))){_0x13eab1[_0xc6e9('0x49')]=qs[_0xc6e9('0x49')](_0x29013a[_0xc6e9('0x41')][_0xc6e9('0x49')]);_0x13eab1[_0xc6e9('0x2b')]=qs[_0xc6e9('0x2b')](_0x29013a[_0xc6e9('0x41')][_0xc6e9('0x2b')]);}return _0x3f9c35[_0xc6e9('0x80')](_0x13eab1);}})[_0xc6e9('0x1f')](function(_0x5437b7){if(_0x5437b7){return _0x5437b7?{'count':_0x517457,'rows':_0x5437b7}:null;}})['then'](respondWithResult(_0x212fab,null))['catch'](handleError(_0x212fab,null));};exports[_0xc6e9('0x81')]=function(_0x1b6892,_0xcc44aa,_0x437e09){var _0x3e23b5={'channel':_0xc6e9('0x82')};var _0x446ff2=[];var _0x3a05a6=[];var _0x209164={};return db['WhatsappAccount'][_0xc6e9('0x57')]({'where':{'id':_0x1b6892[_0xc6e9('0x62')]['id']},'include':[{'model':db['WhatsappApplication'],'as':'Applications'}]})[_0xc6e9('0x1f')](handleEntityNotFound(_0xcc44aa,null))[_0xc6e9('0x1f')](function(_0x5494e1){_0x3e23b5[_0xc6e9('0x83')]=_0x5494e1;if(_0x3e23b5[_0xc6e9('0x83')]&&_0x3e23b5[_0xc6e9('0x83')][_0xc6e9('0x3e')]===_0xc6e9('0x84')&&_0x1b6892[_0xc6e9('0x59')]['statuses']){if(_0x1b6892['body'][_0xc6e9('0x85')][_0xc6e9('0x47')]===0x0)return;if(_0x1b6892[_0xc6e9('0x59')][_0xc6e9('0x85')][0x0][_0xc6e9('0x86')]!==_0xc6e9('0x87'))return;return db[_0xc6e9('0x88')][_0xc6e9('0x31')]({'read':!![],'readAt':_0x1b6892[_0xc6e9('0x59')][_0xc6e9('0x85')][0x0][_0xc6e9('0x89')]},{'where':{'messageId':_0x1b6892[_0xc6e9('0x59')][_0xc6e9('0x85')][0x0]['message_id']},'individualHooks':!![]})[_0xc6e9('0x1f')](function(_0x217b57){return _0xcc44aa['status'](0xc8)[_0xc6e9('0x2a')](_0x217b57);});}_0x3e23b5['applications']=_[_0xc6e9('0x8a')](_0x5494e1[_0xc6e9('0x8b')],['priority'],[_0xc6e9('0x8c')]);if(_0x3e23b5['account'][_0xc6e9('0x8b')]){delete _0x3e23b5[_0xc6e9('0x83')][_0xc6e9('0x8b')];}return db[_0xc6e9('0x8d')]['describe']()[_0xc6e9('0x1f')](function(_0x389a96){if(!_0x389a96){throw new db[(_0xc6e9('0x8e'))][(_0xc6e9('0x8f'))](_0xc6e9('0x90'));}_0x446ff2=_['difference'](_[_0xc6e9('0x42')](_0x389a96),['createdAt',_0xc6e9('0x91')]);_0x3a05a6=_[_0xc6e9('0x92')](_[_0xc6e9('0x42')](_0x389a96),[_0xc6e9('0x93'),_0xc6e9('0x91'),'CompanyId',_0xc6e9('0x94')]);_0x3e23b5[_0xc6e9('0x59')]={'mapKey':_0xc6e9('0x95')};if(_0x3e23b5[_0xc6e9('0x83')]&&_0x3e23b5[_0xc6e9('0x83')][_0xc6e9('0x3e')]==='twilio'){_0x3e23b5[_0xc6e9('0x59')]['from']=_0x1b6892['body'][_0xc6e9('0x96')][_0xc6e9('0x97')](_0xc6e9('0x98'),'');_0x3e23b5[_0xc6e9('0x59')][_0xc6e9('0x59')]=_0x1b6892[_0xc6e9('0x59')][_0xc6e9('0x99')];_0x3e23b5[_0xc6e9('0x59')]['messageId']=_0x1b6892[_0xc6e9('0x59')][_0xc6e9('0x9a')];}if(_0x3e23b5[_0xc6e9('0x83')]&&_0x3e23b5['account'][_0xc6e9('0x3e')]==='sinch'){_0x3e23b5['body'][_0xc6e9('0x9b')]=_0x1b6892[_0xc6e9('0x59')]['notifications'][0x0][_0xc6e9('0x9b')];_0x3e23b5[_0xc6e9('0x59')][_0xc6e9('0x59')]=_0x1b6892['body']['notifications'][0x0][_0xc6e9('0x25')][_0xc6e9('0x59')];_0x3e23b5[_0xc6e9('0x59')][_0xc6e9('0x9c')]=_0x1b6892[_0xc6e9('0x59')][_0xc6e9('0x9d')][0x0][_0xc6e9('0x9e')];}if(_0x3e23b5[_0xc6e9('0x59')]['id']){delete _0x3e23b5[_0xc6e9('0x59')]['id'];}if(_[_0xc6e9('0x9f')](_0x3e23b5[_0xc6e9('0x59')][_0xc6e9('0x9b')])){throw new db['Sequelize']['ValidationError'](_0xc6e9('0xa0'));}if(_['isNil'](_0x3e23b5[_0xc6e9('0x59')][_0xc6e9('0x59')])||_0x3e23b5[_0xc6e9('0x59')][_0xc6e9('0x59')]===''){throw new db[(_0xc6e9('0x8e'))][(_0xc6e9('0x8f'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0xc6e9('0x9f')](_0x3e23b5[_0xc6e9('0x59')]['mapKey'])){throw new db[(_0xc6e9('0x8e'))][(_0xc6e9('0x8f'))](_0xc6e9('0xa1')+_0x3a05a6);}if(!_[_0xc6e9('0xa2')](_0x3a05a6,_0x3e23b5[_0xc6e9('0x59')][_0xc6e9('0xa3')])){throw new db[(_0xc6e9('0x8e'))][(_0xc6e9('0x8f'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x3a05a6);}_0x209164[_0x3e23b5['body']['mapKey']]=_0x3e23b5[_0xc6e9('0x59')][_0xc6e9('0x9b')];return db['CmList'][_0xc6e9('0x57')]({'where':{'id':_0x3e23b5[_0xc6e9('0x83')][_0xc6e9('0x94')]},'include':[{'model':db['CmContact'],'as':_0xc6e9('0xa4'),'where':_0x209164,'limit':0x1,'order':[[_0xc6e9('0x91'),_0xc6e9('0xa5')]]}]});})[_0xc6e9('0x1f')](handleEntityNotFound(_0xcc44aa,null))['then'](function(_0x58e778){if(_0x58e778){_0x3e23b5[_0xc6e9('0xa6')]=_[_0xc6e9('0x6d')](_0x58e778,[_0xc6e9('0xa4')]);if(_0x58e778[_0xc6e9('0xa4')]['length']){return _0x58e778['Contacts'][0x0];}var _0x1a5175=_[_0xc6e9('0x18')](_0x3e23b5[_0xc6e9('0x59')],{'firstName':_0x3e23b5['body'][_0xc6e9('0x9b')],'ListId':_0x58e778['id']});_0x1a5175[_0x3e23b5['body'][_0xc6e9('0xa3')]]=_0x3e23b5['body'][_0xc6e9('0x9b')];return db[_0xc6e9('0x8d')][_0xc6e9('0x58')](_0x1a5175,{'fields':_0x446ff2,'raw':!![]});}})[_0xc6e9('0x1f')](handleEntityNotFound(_0xcc44aa,null))[_0xc6e9('0x1f')](function(_0x11c84f){if(_0x11c84f){_0x3e23b5[_0xc6e9('0xa7')]=_0x11c84f;var _0x111420={'ContactId':_0x11c84f['id'],'phone':_0x3e23b5[_0xc6e9('0x59')][_0xc6e9('0x9b')],'WhatsappAccountId':_0x1b6892['params']['id']};var _0x39b1da={'ContactId':_0x11c84f['id'],'WhatsappAccountId':_0x1b6892[_0xc6e9('0x62')]['id'],'closed':![]};return db[_0xc6e9('0xa8')][_0xc6e9('0x57')]({'where':_0x39b1da})[_0xc6e9('0x1f')](function(_0x4797c5){if(_0x4797c5){return[_0x4797c5,![]];}return db[_0xc6e9('0xa8')][_0xc6e9('0x58')](_0x111420)[_0xc6e9('0x1f')](function(_0x3a891a){return[_0x3a891a,!![]];});});}})[_0xc6e9('0xa9')](function(_0x1220a5,_0x265ffe){_0x3e23b5[_0xc6e9('0xaa')]=_0x1220a5['get']({'plain':!![]});_0x3e23b5[_0xc6e9('0xaa')][_0xc6e9('0xab')]=![];if(_0x265ffe){if(_0x3e23b5[_0xc6e9('0x83')][_0xc6e9('0xac')]){_0x3e23b5['applications'][_0xc6e9('0xad')]({'id':0x0,'priority':_0x3e23b5[_0xc6e9('0xae')][_0xc6e9('0x47')]+0x1,'app':_0xc6e9('0xaf'),'appdata':_0xc6e9('0xb0'),'interval':_0xc6e9('0xb1')});}_0x3e23b5[_0xc6e9('0xaa')]['created']=!![];}return db[_0xc6e9('0x88')][_0xc6e9('0x58')]({'phone':_0x3e23b5[_0xc6e9('0x59')]['from'],'messageId':_0x3e23b5[_0xc6e9('0x59')][_0xc6e9('0x9c')],'body':_0x3e23b5['body'][_0xc6e9('0x59')],'WhatsappAccountId':_0x1b6892[_0xc6e9('0x62')]['id'],'WhatsappInteractionId':_0x1220a5['id'],'direction':'in','ContactId':_0x1220a5[_0xc6e9('0xb2')],'AttachmentId':_0x3e23b5[_0xc6e9('0x59')][_0xc6e9('0xb3')]});})['then'](function(_0x4fd31a){_0x3e23b5[_0xc6e9('0x25')]=_0x4fd31a;if(!_0x3e23b5[_0xc6e9('0xaa')]['UserId'])return;return db[_0xc6e9('0xb4')][_0xc6e9('0x57')]({'attributes':['id',_0xc6e9('0x36')],'where':{'id':_0x3e23b5[_0xc6e9('0xaa')][_0xc6e9('0xb5')]}});})['then'](function(_0x4d5a27){if(_0x4d5a27){_0x3e23b5[_0xc6e9('0xae')][_0xc6e9('0xb6')]({'id':0x0,'priority':0x0,'app':_0xc6e9('0xb7'),'appdata':_0x4d5a27[_0xc6e9('0x36')]+','+(_0x3e23b5[_0xc6e9('0x83')][_0xc6e9('0xb8')]||0xa),'interval':_0xc6e9('0xb1')});}if(!_0x3e23b5[_0xc6e9('0xaa')][_0xc6e9('0xb9')])return;return db[_0xc6e9('0xba')][_0xc6e9('0x57')]({'attributes':['id',_0xc6e9('0x36')],'where':{'id':_0x3e23b5[_0xc6e9('0xaa')][_0xc6e9('0xb9')]}});})['then'](function(_0x12e34d){if(_0x12e34d){_0x3e23b5[_0xc6e9('0xae')][_0xc6e9('0xb6')]({'id':0x0,'priority':0x1,'app':'queue','appdata':_0x12e34d[_0xc6e9('0x36')]+','+(_0x3e23b5[_0xc6e9('0x83')][_0xc6e9('0xbb')]||0x12c),'interval':'*,*,*,*'});}return respondWithRpcPromise(_0xc6e9('0xbc'),_0xc6e9('0xbd'),_0x3e23b5);})[_0xc6e9('0x1f')](function(_0x4da538){if(_0x4da538){var _0x3579b4=0xc8;var _0x3b6ece=_0xc6e9('0xbe');logger[_0xc6e9('0x20')](_0xc6e9('0x23'),_0x3b6ece,_0x3579b4,_0xc6e9('0xbf'));logger['debug'](_0xc6e9('0xc0'),_0x3b6ece,_0x3579b4,_0xc6e9('0xbf'),JSON['stringify'](_0x4da538));if(_0x3e23b5[_0xc6e9('0x83')][_0xc6e9('0x3e')]===_0xc6e9('0xc1')){return _0xcc44aa[_0xc6e9('0x29')](_0x3579b4)[_0xc6e9('0x2e')](_0xc6e9('0xc2'),_0xc6e9('0xc3'))[_0xc6e9('0x37')](_0xc6e9('0xc4'));}else{return _0xcc44aa[_0xc6e9('0x29')](_0x3579b4)[_0xc6e9('0x2a')](_0x4da538);}}});})[_0xc6e9('0x54')](handleError(_0xcc44aa,null));};exports[_0xc6e9('0x37')]=function(_0x14a409,_0x201579,_0x36ccea){var _0x4f1283,_0x4d30bd,_0x5600d2;if(_[_0xc6e9('0x9f')](_0x14a409[_0xc6e9('0x59')]['body'])||_0x14a409[_0xc6e9('0x59')][_0xc6e9('0x59')]===''){throw new db['Sequelize'][(_0xc6e9('0x8f'))](_0xc6e9('0xc5'));}if(_[_0xc6e9('0x9f')](_0x14a409[_0xc6e9('0x59')]['to'])){throw new db['Sequelize'][(_0xc6e9('0x8f'))](_0xc6e9('0xc6'));}_0x4f1283=_0x14a409['body']['to'];return db[_0xc6e9('0x3b')]['find']({'where':{'id':_0x14a409[_0xc6e9('0x62')]['id']},'include':[{'model':db[_0xc6e9('0xc7')],'as':'List','include':[{'model':db['CmContact'],'as':_0xc6e9('0xa4'),'where':{'mobile':_0x4f1283},'limit':0x1,'order':[[_0xc6e9('0x91'),_0xc6e9('0xa5')]]}]}]})['then'](handleEntityNotFound(_0x201579,null))[_0xc6e9('0x1f')](function(_0x2e6ba8){if(_0x2e6ba8&&_0x2e6ba8['List']){_0x4d30bd=_0x2e6ba8['get']({'plain':!![]});if(_0x4d30bd[_0xc6e9('0xc8')]&&_0x4d30bd[_0xc6e9('0xc8')][_0xc6e9('0xa4')]['length']){return _0x4d30bd['List'][_0xc6e9('0xa4')][0x0];}return db['CmContact'][_0xc6e9('0x58')](_[_0xc6e9('0x18')](_0x14a409[_0xc6e9('0x59')],{'firstName':_0x4f1283,'mobile':_0x4f1283,'phone':_0x4f1283,'ListId':_0x4d30bd['ListId']}));}})[_0xc6e9('0x1f')](handleEntityNotFound(_0x201579,null))[_0xc6e9('0x1f')](function(_0x5d462e){if(_0x5d462e){_0x5600d2=_0x5d462e;return db[_0xc6e9('0xa8')][_0xc6e9('0x57')]({'where':{'ContactId':_0x5600d2['id'],'closed':![],'WhatsappAccountId':_0x4d30bd['id']}})[_0xc6e9('0x1f')](function(_0x10bf51){if(_0x10bf51){return[_0x10bf51,![]];}return db[_0xc6e9('0xa8')]['create']({'UserId':_0x14a409[_0xc6e9('0x5b')]['id'],'ContactId':_0x5600d2['id'],'WhatsappAccountId':_0x4d30bd['id'],'phone':_0x4f1283,'firstMsgDirection':'out','Messages':[_['merge'](_0x14a409[_0xc6e9('0x59')],{'read':![],'body':_0x14a409[_0xc6e9('0x59')]['body'],'phone':_0x4f1283,'WhatsappAccountId':_0x4d30bd['id'],'UserId':_0x14a409[_0xc6e9('0x5b')]['id'],'ContactId':_0x5600d2['id']})]},{'include':[{'model':db['WhatsappMessage'],'as':_0xc6e9('0xc9')}]})['then'](function(_0x184c9b){return[_0x184c9b,!![]];});});}})[_0xc6e9('0xa9')](function(_0x2b8490,_0x277149){if(_0x277149){return _0x2b8490;}return db[_0xc6e9('0x88')]['create'](_[_0xc6e9('0x4e')](_0x14a409[_0xc6e9('0x59')],{'read':![],'body':_0x14a409[_0xc6e9('0x59')][_0xc6e9('0x59')],'phone':_0x4f1283,'WhatsappAccountId':_0x4d30bd['id'],'WhatsappInteractionId':_0x2b8490['id'],'UserId':_0x14a409[_0xc6e9('0x5b')]['id'],'ContactId':_0x5600d2['id']}))[_0xc6e9('0x1f')](function(_0x17b6e7){_0x2b8490[_0xc6e9('0xca')][_0xc6e9('0xc9')]=[];_0x2b8490[_0xc6e9('0xca')][_0xc6e9('0xc9')]['push'](_0x17b6e7[_0xc6e9('0xca')]);return _0x2b8490;});})['then'](respondWithResult(_0x201579,null))[_0xc6e9('0x54')](handleError(_0x201579,null));};
\ No newline at end of file