Built motion from commit 42801a18.|2.6.28
[motion2.git] / server / api / whatsappAccount / whatsappAccount.controller.js
index 8cd0b7c..3e6bea1 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x726f=['defaults','localhost','socket.io-emitter','./whatsappAccount.socket','jayson/promise','request','then','WhatsappAccount,\x20%s,\x20%s','debug','request\x20sent','error','code','message','info','sendStatus','status','json','undefined','limit','offset','set','reject','save','destroy','get','UserProfileResource','name','mandatoryDispositionPause','map','WhatsappAccount','rawAttributes','fieldName','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','type','filter','count','includeAll','include','rows','params','Pause','options','find','create','body','role','user','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','catch','describe','addDisposition','WhatsappAccountId','getDispositions','findOne','Disposition','findAll','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','addAgents','omit','spread','emit','removeAgents','isArray','getAgents','User','addApplications','sequelize','transaction','Transaction','READ_COMMITTED','bulkCreate','WhatsappApplication','findAndCountAll','stack','finally','getApplications','whatsapp','Applications','account','sinch','statuses','read','WhatsappMessage','timestamp','applications','orderBy','asc','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','ListId','mobile','twilio','from','From','replace','Body','messageId','notifications','message_id','body\x20is\x20mandatory\x20and\x20not\x20empty','isNil','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey','CmList','CmContact','Contacts','DESC','list','contact','WhatsappInteraction','interaction','created','autoclose','close','unmanaged','*,*,*,*','ContactId','UserId','waitForTheAssignedAgent','queueId','unshift','waitForTheAssignedQueue','Start','startRouting','receiveMessage','WhatsappAccount,\x20%s,\x20%s,\x20%s','WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s','entity\x20found','send','to\x20is\x20mandatory','List','out','Messages','dataValues','push','eml-format','rimraf','fast-json-patch','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../config/license/hardware','../../config/utils','../../config/environment','../../mysqldb','redis'];(function(_0x46efd7,_0x43f84d){var _0x5637e4=function(_0x54e078){while(--_0x54e078){_0x46efd7['push'](_0x46efd7['shift']());}};_0x5637e4(++_0x43f84d);}(_0x726f,0xa2));var _0xf726=function(_0x8c43de,_0x90ff31){_0x8c43de=_0x8c43de-0x0;var _0xa6591b=_0x726f[_0x8c43de];return _0xa6591b;};'use strict';var emlformat=require(_0xf726('0x0'));var rimraf=require(_0xf726('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf726('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xf726('0x3'));var Mustache=require(_0xf726('0x4'));var util=require(_0xf726('0x5'));var path=require(_0xf726('0x6'));var sox=require(_0xf726('0x7'));var csv=require(_0xf726('0x8'));var ejs=require(_0xf726('0x9'));var fs=require('fs');var fs_extra=require(_0xf726('0xa'));var _=require(_0xf726('0xb'));var squel=require(_0xf726('0xc'));var crypto=require(_0xf726('0xd'));var jsforce=require(_0xf726('0xe'));var deskjs=require(_0xf726('0xf'));var toCsv=require(_0xf726('0x8'));var querystring=require(_0xf726('0x10'));var Papa=require(_0xf726('0x11'));var Redis=require(_0xf726('0x12'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf726('0x13'));var logger=require('../../config/logger')('api');var utils=require(_0xf726('0x14'));var config=require(_0xf726('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0xf726('0x16'))['db'];config[_0xf726('0x17')]=_[_0xf726('0x18')](config[_0xf726('0x17')],{'host':_0xf726('0x19'),'port':0x18eb});var socket=require(_0xf726('0x1a'))(new Redis(config[_0xf726('0x17')]));require(_0xf726('0x1b'))['register'](socket);var jayson=require(_0xf726('0x1c'));var client=jayson['client']['http']({'port':0x232c});function respondWithRpcPromise(_0x3d5cbf,_0x359cbf,_0x5dee54,_0x942f6c){return new BPromise(function(_0x13c001,_0x6c89cc){var _0x545e84=_0x942f6c||client;return _0x545e84[_0xf726('0x1d')](_0x3d5cbf,_0x5dee54)[_0xf726('0x1e')](function(_0x1a849b){logger['info'](_0xf726('0x1f'),_0x359cbf,'request\x20sent');logger[_0xf726('0x20')]('WhatsappAccount,\x20%s,\x20%s,\x20%s',_0x359cbf,_0xf726('0x21'),JSON['stringify'](_0x1a849b));if(_0x1a849b[_0xf726('0x22')]){if(_0x1a849b[_0xf726('0x22')][_0xf726('0x23')]===0x1f4){logger['error'](_0xf726('0x1f'),_0x359cbf,_0x1a849b['error'][_0xf726('0x24')]);return _0x6c89cc(_0x1a849b[_0xf726('0x22')]['message']);}logger[_0xf726('0x22')](_0xf726('0x1f'),_0x359cbf,_0x1a849b[_0xf726('0x22')][_0xf726('0x24')]);return _0x13c001(_0x1a849b[_0xf726('0x22')][_0xf726('0x24')]);}else{logger[_0xf726('0x25')]('WhatsappAccount,\x20%s,\x20%s',_0x359cbf,_0xf726('0x21'));_0x13c001(_0x1a849b['result'][_0xf726('0x24')]);}})['catch'](function(_0x5e01e9){logger[_0xf726('0x22')](_0xf726('0x1f'),_0x359cbf,_0x5e01e9);_0x6c89cc(_0x5e01e9);});});}function respondWithStatusCode(_0x9a0a3c,_0x3877af){_0x3877af=_0x3877af||0xcc;return function(_0x11015e){if(_0x11015e){return _0x9a0a3c[_0xf726('0x26')](_0x3877af);}return _0x9a0a3c['status'](_0x3877af)['end']();};}function respondWithResult(_0x5cad1c,_0x470be4){_0x470be4=_0x470be4||0xc8;return function(_0x4f6607){if(_0x4f6607){return _0x5cad1c[_0xf726('0x27')](_0x470be4)[_0xf726('0x28')](_0x4f6607);}};}function respondWithFilteredResult(_0x54c057,_0x417362){return function(_0x291869){if(_0x291869){var _0x152b29=typeof _0x417362['offset']===_0xf726('0x29')&&typeof _0x417362[_0xf726('0x2a')]===_0xf726('0x29');var _0xfbb649=_0x291869['count'];var _0x1f33d0=_0x152b29?0x0:_0x417362[_0xf726('0x2b')];var _0x3c6859=_0x152b29?_0x291869['count']:_0x417362[_0xf726('0x2b')]+_0x417362[_0xf726('0x2a')];var _0x21c276;if(_0x3c6859>=_0xfbb649){_0x3c6859=_0xfbb649;_0x21c276=0xc8;}else{_0x21c276=0xce;}_0x54c057['status'](_0x21c276);return _0x54c057[_0xf726('0x2c')]('Content-Range',_0x1f33d0+'-'+_0x3c6859+'/'+_0xfbb649)[_0xf726('0x28')](_0x291869);}return null;};}function patchUpdates(_0xa91bb3){return function(_0x30a951){try{jsonpatch['apply'](_0x30a951,_0xa91bb3,!![]);}catch(_0x985282){return BPromise[_0xf726('0x2d')](_0x985282);}return _0x30a951[_0xf726('0x2e')]();};}function saveUpdates(_0x17a046,_0x33c6a7){return function(_0x36791a){if(_0x36791a){return _0x36791a['update'](_0x17a046)[_0xf726('0x1e')](function(_0x53a1e8){return _0x53a1e8;});}return null;};}function removeEntity(_0x335b00,_0x232ac2){return function(_0x3aac79){if(_0x3aac79){return _0x3aac79[_0xf726('0x2f')]()[_0xf726('0x1e')](function(){var _0x3a338c=_0x3aac79[_0xf726('0x30')]({'plain':!![]});var _0x535268='WhatsappAccounts';return db[_0xf726('0x31')]['destroy']({'where':{'type':_0x535268,'resourceId':_0x3a338c['id']}})[_0xf726('0x1e')](function(){return _0x3aac79;});})[_0xf726('0x1e')](function(){_0x335b00[_0xf726('0x27')](0xcc)['end']();});}};}function handleEntityNotFound(_0x492f8a,_0x2894c3){return function(_0xe2c1fd){if(!_0xe2c1fd){_0x492f8a[_0xf726('0x26')](0x194);}return _0xe2c1fd;};}function handleError(_0x1097be,_0x2e7ce5){_0x2e7ce5=_0x2e7ce5||0x1f4;return function(_0x56b62d){logger[_0xf726('0x22')](_0x56b62d['stack']);if(_0x56b62d[_0xf726('0x32')]){delete _0x56b62d[_0xf726('0x32')];}_0x1097be['status'](_0x2e7ce5)['send'](_0x56b62d);};}exports['index']=function(_0x29ff81,_0x12e5e4){var _0x84fbe1={'include':[{'model':db['Pause'],'as':_0xf726('0x33')}]},_0x425ebb={},_0x34ae20={'count':0x0,'rows':[]};var _0x579d17=_[_0xf726('0x34')](db[_0xf726('0x35')][_0xf726('0x36')],function(_0x57c682){return{'name':_0x57c682[_0xf726('0x37')],'type':_0x57c682['type']['key']};});_0x425ebb[_0xf726('0x38')]=_[_0xf726('0x34')](_0x579d17,_0xf726('0x32'));_0x425ebb[_0xf726('0x39')]=_[_0xf726('0x3a')](_0x29ff81['query']);_0x425ebb[_0xf726('0x3b')]=_[_0xf726('0x3c')](_0x425ebb[_0xf726('0x38')],_0x425ebb[_0xf726('0x39')]);_0x84fbe1[_0xf726('0x3d')]=_[_0xf726('0x3c')](_0x425ebb[_0xf726('0x38')],qs['fields'](_0x29ff81[_0xf726('0x39')][_0xf726('0x3e')]));_0x84fbe1[_0xf726('0x3d')]=_0x84fbe1[_0xf726('0x3d')][_0xf726('0x3f')]?_0x84fbe1[_0xf726('0x3d')]:_0x425ebb[_0xf726('0x38')];if(!_0x29ff81['query'][_0xf726('0x40')](_0xf726('0x41'))){_0x84fbe1['limit']=qs['limit'](_0x29ff81[_0xf726('0x39')][_0xf726('0x2a')]);_0x84fbe1['offset']=qs[_0xf726('0x2b')](_0x29ff81['query'][_0xf726('0x2b')]);}_0x84fbe1[_0xf726('0x42')]=qs[_0xf726('0x43')](_0x29ff81[_0xf726('0x39')][_0xf726('0x43')]);_0x84fbe1[_0xf726('0x44')]=qs[_0xf726('0x3b')](_[_0xf726('0x45')](_0x29ff81[_0xf726('0x39')],_0x425ebb[_0xf726('0x3b')]),_0x579d17);if(_0x29ff81['query']['filter']){_0x84fbe1[_0xf726('0x44')]=_[_0xf726('0x46')](_0x84fbe1['where'],{'$or':_[_0xf726('0x34')](_0x579d17,function(_0x3cdd4a){if(_0x3cdd4a[_0xf726('0x47')]!=='VIRTUAL'){var _0x2c2f19={};_0x2c2f19[_0x3cdd4a[_0xf726('0x32')]]={'$like':'%'+_0x29ff81[_0xf726('0x39')][_0xf726('0x48')]+'%'};return _0x2c2f19;}})});}_0x84fbe1=_[_0xf726('0x46')]({},_0x84fbe1,_0x29ff81['options']);var _0x5b6c38={'where':_0x84fbe1[_0xf726('0x44')]};return db[_0xf726('0x35')][_0xf726('0x49')](_0x5b6c38)[_0xf726('0x1e')](function(_0x4e0d81){_0x34ae20['count']=_0x4e0d81;if(_0x29ff81['query'][_0xf726('0x4a')]){_0x84fbe1[_0xf726('0x4b')]=[{'all':!![]}];}return db[_0xf726('0x35')]['findAll'](_0x84fbe1);})[_0xf726('0x1e')](function(_0x2b35d8){_0x34ae20[_0xf726('0x4c')]=_0x2b35d8;return _0x34ae20;})[_0xf726('0x1e')](respondWithFilteredResult(_0x12e5e4,_0x84fbe1))['catch'](handleError(_0x12e5e4,null));};exports['show']=function(_0x3e5561,_0xb9f953){var _0x552a40={'raw':![],'where':{'id':_0x3e5561[_0xf726('0x4d')]['id']},'include':[{'model':db[_0xf726('0x4e')],'as':_0xf726('0x33')}]},_0x344f51={};_0x344f51[_0xf726('0x38')]=_[_0xf726('0x3a')](db[_0xf726('0x35')][_0xf726('0x36')]);_0x344f51[_0xf726('0x39')]=_[_0xf726('0x3a')](_0x3e5561['query']);_0x344f51[_0xf726('0x3b')]=_[_0xf726('0x3c')](_0x344f51[_0xf726('0x38')],_0x344f51['query']);_0x552a40[_0xf726('0x3d')]=_[_0xf726('0x3c')](_0x344f51[_0xf726('0x38')],qs['fields'](_0x3e5561[_0xf726('0x39')]['fields']));_0x552a40['attributes']=_0x552a40['attributes'][_0xf726('0x3f')]?_0x552a40[_0xf726('0x3d')]:_0x344f51[_0xf726('0x38')];if(_0x3e5561['query'][_0xf726('0x4a')]){_0x552a40[_0xf726('0x4b')]=[{'all':!![]}];}_0x552a40=_[_0xf726('0x46')]({},_0x552a40,_0x3e5561[_0xf726('0x4f')]);return db[_0xf726('0x35')][_0xf726('0x50')](_0x552a40)[_0xf726('0x1e')](handleEntityNotFound(_0xb9f953,null))[_0xf726('0x1e')](respondWithResult(_0xb9f953,null))['catch'](handleError(_0xb9f953,null));};exports['create']=function(_0x560dfc,_0x425f35){return db[_0xf726('0x35')][_0xf726('0x51')](_0x560dfc[_0xf726('0x52')],{})[_0xf726('0x1e')](function(_0x26bb26){var _0x5b60a3=_0x560dfc['user'][_0xf726('0x30')]({'plain':!![]});if(!_0x5b60a3)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x5b60a3[_0xf726('0x53')]===_0xf726('0x54')){var _0x28fdea=_0x26bb26[_0xf726('0x30')]({'plain':!![]});var _0xb62fc1='WhatsappAccounts';return db['UserProfileSection']['find']({'where':{'name':_0xb62fc1,'userProfileId':_0x5b60a3[_0xf726('0x55')]},'raw':!![]})['then'](function(_0x52afda){if(_0x52afda&&_0x52afda[_0xf726('0x56')]===0x0){return db[_0xf726('0x31')][_0xf726('0x51')]({'name':_0x28fdea[_0xf726('0x32')],'resourceId':_0x28fdea['id'],'type':_0x52afda['name'],'sectionId':_0x52afda['id']},{})[_0xf726('0x1e')](function(){return _0x26bb26;});}else{return _0x26bb26;}})['catch'](function(_0x243b67){logger[_0xf726('0x22')](_0xf726('0x57'),_0x243b67);throw _0x243b67;});}return _0x26bb26;})[_0xf726('0x1e')](respondWithResult(_0x425f35,0xc9))['catch'](handleError(_0x425f35,null));};exports[_0xf726('0x58')]=function(_0x2a8f40,_0x33f530){if(_0x2a8f40[_0xf726('0x52')]['id']){delete _0x2a8f40[_0xf726('0x52')]['id'];}return db[_0xf726('0x35')][_0xf726('0x50')]({'where':{'id':_0x2a8f40[_0xf726('0x4d')]['id']},'include':[{'model':db[_0xf726('0x4e')],'as':_0xf726('0x33')}]})[_0xf726('0x1e')](handleEntityNotFound(_0x33f530,null))['then'](saveUpdates(_0x2a8f40[_0xf726('0x52')],null))['then'](respondWithResult(_0x33f530,null))[_0xf726('0x59')](handleError(_0x33f530,null));};exports[_0xf726('0x2f')]=function(_0x16ba28,_0x48aace){return db['WhatsappAccount'][_0xf726('0x50')]({'where':{'id':_0x16ba28['params']['id']}})[_0xf726('0x1e')](handleEntityNotFound(_0x48aace,null))[_0xf726('0x1e')](removeEntity(_0x48aace,null))[_0xf726('0x59')](handleError(_0x48aace,null));};exports[_0xf726('0x5a')]=function(_0x3b4754,_0xfe3926){return db['WhatsappAccount'][_0xf726('0x5a')]()['then'](respondWithResult(_0xfe3926,null))[_0xf726('0x59')](handleError(_0xfe3926,null));};exports[_0xf726('0x5b')]=function(_0x27348a,_0x4d99d6,_0x29dfe7){if(_0x27348a['body']['id']){delete _0x27348a[_0xf726('0x52')]['id'];}return db['WhatsappAccount'][_0xf726('0x50')]({'where':{'id':_0x27348a[_0xf726('0x4d')]['id']}})[_0xf726('0x1e')](handleEntityNotFound(_0x4d99d6,null))[_0xf726('0x1e')](function(_0x1a9ffb){if(_0x1a9ffb){_0x27348a['body'][_0xf726('0x5c')]=_0x1a9ffb['id'];return db['Disposition']['create'](_0x27348a[_0xf726('0x52')]);}})[_0xf726('0x1e')](respondWithResult(_0x4d99d6,null))[_0xf726('0x59')](handleError(_0x4d99d6,null));};exports[_0xf726('0x5d')]=function(_0x553ee4,_0x4d5391,_0x922a84){var _0x39d27c={'raw':![],'where':{}};var _0x281c45={};var _0x5e680e={'count':0x0,'rows':[]};return db[_0xf726('0x35')][_0xf726('0x5e')]({'where':{'id':_0x553ee4[_0xf726('0x4d')]['id']}})[_0xf726('0x1e')](handleEntityNotFound(_0x4d5391,null))['then'](function(_0x2a2ef1){if(_0x2a2ef1){_0x281c45['model']=_['keys'](db[_0xf726('0x5f')][_0xf726('0x36')]);_0x281c45[_0xf726('0x39')]=_['keys'](_0x553ee4[_0xf726('0x39')]);_0x281c45[_0xf726('0x3b')]=_[_0xf726('0x3c')](_0x281c45[_0xf726('0x38')],_0x281c45[_0xf726('0x39')]);_0x39d27c[_0xf726('0x3d')]=_[_0xf726('0x3c')](_0x281c45[_0xf726('0x38')],qs[_0xf726('0x3e')](_0x553ee4[_0xf726('0x39')][_0xf726('0x3e')]));_0x39d27c[_0xf726('0x3d')]=_0x39d27c[_0xf726('0x3d')][_0xf726('0x3f')]?_0x39d27c[_0xf726('0x3d')]:_0x281c45[_0xf726('0x38')];if(!_0x553ee4[_0xf726('0x39')][_0xf726('0x40')](_0xf726('0x41'))){_0x39d27c[_0xf726('0x2a')]=qs[_0xf726('0x2a')](_0x553ee4[_0xf726('0x39')]['limit']);_0x39d27c[_0xf726('0x2b')]=qs['offset'](_0x553ee4[_0xf726('0x39')][_0xf726('0x2b')]);}_0x39d27c[_0xf726('0x42')]=qs[_0xf726('0x43')](_0x553ee4[_0xf726('0x39')][_0xf726('0x43')]);_0x39d27c[_0xf726('0x44')]=qs[_0xf726('0x3b')](_[_0xf726('0x45')](_0x553ee4[_0xf726('0x39')],_0x281c45[_0xf726('0x3b')]));_0x39d27c['where']['WhatsappAccountId']=_0x2a2ef1['id'];if(_0x553ee4[_0xf726('0x39')][_0xf726('0x48')]){_0x39d27c[_0xf726('0x44')]=_[_0xf726('0x46')](_0x39d27c[_0xf726('0x44')],{'$or':_['map'](_0x39d27c[_0xf726('0x3d')],function(_0x7c0858){var _0x41555b={};_0x41555b[_0x7c0858]={'$like':'%'+_0x553ee4[_0xf726('0x39')][_0xf726('0x48')]+'%'};return _0x41555b;})});}_0x39d27c=_[_0xf726('0x46')]({},_0x39d27c,_0x553ee4[_0xf726('0x4f')]);return db[_0xf726('0x5f')]['count']({'where':_0x39d27c[_0xf726('0x44')]})[_0xf726('0x1e')](function(_0xde9deb){_0x5e680e[_0xf726('0x49')]=_0xde9deb;if(_0x553ee4[_0xf726('0x39')][_0xf726('0x4a')]){_0x39d27c[_0xf726('0x4b')]=[{'all':!![]}];}return db[_0xf726('0x5f')][_0xf726('0x60')](_0x39d27c);})['then'](function(_0x2b8e6c){_0x5e680e[_0xf726('0x4c')]=_0x2b8e6c;return _0x5e680e;});}})[_0xf726('0x1e')](respondWithFilteredResult(_0x4d5391,_0x39d27c))['catch'](handleError(_0x4d5391,null));};exports[_0xf726('0x61')]=function(_0x2f5d52,_0x17655e,_0x88598a){return db[_0xf726('0x35')][_0xf726('0x50')]({'where':{'id':_0x2f5d52[_0xf726('0x4d')]['id']}})[_0xf726('0x1e')](handleEntityNotFound(_0x17655e,null))[_0xf726('0x1e')](function(_0x495cb2){if(_0x495cb2){return _0x495cb2[_0xf726('0x61')](_0x2f5d52[_0xf726('0x39')][_0xf726('0x62')]);}})[_0xf726('0x1e')](respondWithStatusCode(_0x17655e,null))[_0xf726('0x59')](handleError(_0x17655e,null));};exports[_0xf726('0x63')]=function(_0x4b2a38,_0xf8d6c8,_0x549014){if(_0x4b2a38[_0xf726('0x52')]['id']){delete _0x4b2a38[_0xf726('0x52')]['id'];}return db[_0xf726('0x35')][_0xf726('0x50')]({'where':{'id':_0x4b2a38[_0xf726('0x4d')]['id']}})[_0xf726('0x1e')](handleEntityNotFound(_0xf8d6c8,null))[_0xf726('0x1e')](function(_0x413052){if(_0x413052){_0x4b2a38[_0xf726('0x52')][_0xf726('0x5c')]=_0x413052['id'];return db[_0xf726('0x64')]['create'](_0x4b2a38[_0xf726('0x52')]);}})['then'](respondWithResult(_0xf8d6c8,null))[_0xf726('0x59')](handleError(_0xf8d6c8,null));};exports[_0xf726('0x65')]=function(_0x5b7859,_0x5ac314,_0x50da3d){var _0x365cdb={'raw':![],'where':{}};var _0x1135d3={};var _0x59b282={'count':0x0,'rows':[]};return db[_0xf726('0x35')][_0xf726('0x5e')]({'where':{'id':_0x5b7859[_0xf726('0x4d')]['id']}})[_0xf726('0x1e')](handleEntityNotFound(_0x5ac314,null))[_0xf726('0x1e')](function(_0x598445){if(_0x598445){_0x1135d3[_0xf726('0x38')]=_['keys'](db[_0xf726('0x64')][_0xf726('0x36')]);_0x1135d3[_0xf726('0x39')]=_[_0xf726('0x3a')](_0x5b7859['query']);_0x1135d3[_0xf726('0x3b')]=_[_0xf726('0x3c')](_0x1135d3[_0xf726('0x38')],_0x1135d3['query']);_0x365cdb['attributes']=_['intersection'](_0x1135d3[_0xf726('0x38')],qs['fields'](_0x5b7859[_0xf726('0x39')][_0xf726('0x3e')]));_0x365cdb[_0xf726('0x3d')]=_0x365cdb[_0xf726('0x3d')]['length']?_0x365cdb[_0xf726('0x3d')]:_0x1135d3['model'];if(!_0x5b7859[_0xf726('0x39')][_0xf726('0x40')](_0xf726('0x41'))){_0x365cdb[_0xf726('0x2a')]=qs[_0xf726('0x2a')](_0x5b7859[_0xf726('0x39')][_0xf726('0x2a')]);_0x365cdb[_0xf726('0x2b')]=qs[_0xf726('0x2b')](_0x5b7859[_0xf726('0x39')][_0xf726('0x2b')]);}_0x365cdb[_0xf726('0x42')]=qs['sort'](_0x5b7859['query'][_0xf726('0x43')]);_0x365cdb[_0xf726('0x44')]=qs[_0xf726('0x3b')](_[_0xf726('0x45')](_0x5b7859[_0xf726('0x39')],_0x1135d3['filters']));_0x365cdb[_0xf726('0x44')]['WhatsappAccountId']=_0x598445['id'];if(_0x5b7859[_0xf726('0x39')][_0xf726('0x48')]){_0x365cdb['where']=_['merge'](_0x365cdb[_0xf726('0x44')],{'$or':_['map'](_0x365cdb['attributes'],function(_0x1f9c0d){var _0x37eb8a={};_0x37eb8a[_0x1f9c0d]={'$like':'%'+_0x5b7859[_0xf726('0x39')]['filter']+'%'};return _0x37eb8a;})});}_0x365cdb=_[_0xf726('0x46')]({},_0x365cdb,_0x5b7859['options']);return db[_0xf726('0x64')][_0xf726('0x49')]({'where':_0x365cdb[_0xf726('0x44')]})[_0xf726('0x1e')](function(_0x3d5d84){_0x59b282[_0xf726('0x49')]=_0x3d5d84;if(_0x5b7859[_0xf726('0x39')][_0xf726('0x4a')]){_0x365cdb['include']=[{'all':!![]}];}return db[_0xf726('0x64')]['findAll'](_0x365cdb);})[_0xf726('0x1e')](function(_0x2417cd){_0x59b282[_0xf726('0x4c')]=_0x2417cd;return _0x59b282;});}})[_0xf726('0x1e')](respondWithFilteredResult(_0x5ac314,_0x365cdb))[_0xf726('0x59')](handleError(_0x5ac314,null));};exports[_0xf726('0x66')]=function(_0x4f6690,_0x152e43,_0x379f7c){return db[_0xf726('0x35')]['find']({'where':{'id':_0x4f6690[_0xf726('0x4d')]['id']}})[_0xf726('0x1e')](handleEntityNotFound(_0x152e43,null))[_0xf726('0x1e')](function(_0x2af6e2){if(_0x2af6e2){return _0x2af6e2[_0xf726('0x66')](_0x4f6690[_0xf726('0x39')]['ids']);}})[_0xf726('0x1e')](respondWithStatusCode(_0x152e43,null))[_0xf726('0x59')](handleError(_0x152e43,null));};exports['addAgents']=function(_0x550cf8,_0x54d38f,_0x9c59b0){return db[_0xf726('0x35')]['find']({'where':{'id':_0x550cf8[_0xf726('0x4d')]['id']}})[_0xf726('0x1e')](handleEntityNotFound(_0x54d38f,null))[_0xf726('0x1e')](function(_0x3470c9){if(_0x3470c9){return _0x3470c9[_0xf726('0x67')](_0x550cf8[_0xf726('0x52')][_0xf726('0x62')],_[_0xf726('0x68')](_0x550cf8[_0xf726('0x52')],[_0xf726('0x62'),'id'])||{})[_0xf726('0x69')](function(_0x5f33cb){for(var _0x6a2672=0x0;_0x6a2672<_0x550cf8['body'][_0xf726('0x62')][_0xf726('0x3f')];_0x6a2672+=0x1){socket[_0xf726('0x6a')]('userWhatsappAccount:save',{'UserId':Number(_0x550cf8[_0xf726('0x52')][_0xf726('0x62')][_0x6a2672]),'WhatsappAccountId':Number(_0x550cf8[_0xf726('0x4d')]['id'])});}return _0x5f33cb;});}})[_0xf726('0x1e')](respondWithResult(_0x54d38f,null))['catch'](handleError(_0x54d38f,null));};exports[_0xf726('0x6b')]=function(_0x65f38c,_0x26365b,_0x2a4f6f){return db['WhatsappAccount'][_0xf726('0x50')]({'where':{'id':_0x65f38c[_0xf726('0x4d')]['id']}})['then'](handleEntityNotFound(_0x26365b,null))[_0xf726('0x1e')](function(_0x2b7136){if(_0x2b7136){return _0x2b7136[_0xf726('0x6b')](_0x65f38c[_0xf726('0x39')]['ids'])['then'](function(){if(_[_0xf726('0x6c')](_0x65f38c['query']['ids'])){for(var _0x59628c=0x0;_0x59628c<_0x65f38c['query'][_0xf726('0x62')][_0xf726('0x3f')];_0x59628c+=0x1){socket[_0xf726('0x6a')]('userWhatsappAccount:remove',{'UserId':Number(_0x65f38c[_0xf726('0x39')]['ids'][_0x59628c]),'WhatsappAccountId':Number(_0x65f38c[_0xf726('0x4d')]['id'])});}}else{socket[_0xf726('0x6a')]('userWhatsappAccount:remove',{'UserId':Number(_0x65f38c['query'][_0xf726('0x62')]),'WhatsappAccountId':Number(_0x65f38c[_0xf726('0x4d')]['id'])});}});}})[_0xf726('0x1e')](respondWithStatusCode(_0x26365b,null))['catch'](handleError(_0x26365b,null));};exports[_0xf726('0x6d')]=function(_0x1701c7,_0x1136f5,_0xe0181){var _0x46e38d={};var _0x48bbad={};var _0x4b9e5b;var _0x1ec513;return db[_0xf726('0x35')][_0xf726('0x5e')]({'where':{'id':_0x1701c7[_0xf726('0x4d')]['id']}})[_0xf726('0x1e')](handleEntityNotFound(_0x1136f5,null))[_0xf726('0x1e')](function(_0x37024d){if(_0x37024d){_0x4b9e5b=_0x37024d;_0x48bbad[_0xf726('0x38')]=_[_0xf726('0x3a')](db[_0xf726('0x6e')][_0xf726('0x36')]);_0x48bbad[_0xf726('0x39')]=_['keys'](_0x1701c7[_0xf726('0x39')]);_0x48bbad['filters']=_[_0xf726('0x3c')](_0x48bbad['model'],_0x48bbad[_0xf726('0x39')]);_0x46e38d[_0xf726('0x3d')]=_['intersection'](_0x48bbad['model'],qs[_0xf726('0x3e')](_0x1701c7['query'][_0xf726('0x3e')]));_0x46e38d[_0xf726('0x3d')]=_0x46e38d[_0xf726('0x3d')]['length']?_0x46e38d[_0xf726('0x3d')]:_0x48bbad[_0xf726('0x38')];_0x46e38d[_0xf726('0x42')]=qs['sort'](_0x1701c7[_0xf726('0x39')][_0xf726('0x43')]);_0x46e38d[_0xf726('0x44')]=qs[_0xf726('0x3b')](_[_0xf726('0x45')](_0x1701c7[_0xf726('0x39')],_0x48bbad['filters']));if(_0x1701c7[_0xf726('0x39')][_0xf726('0x48')]){_0x46e38d[_0xf726('0x44')]=_[_0xf726('0x46')](_0x46e38d[_0xf726('0x44')],{'$or':_[_0xf726('0x34')](_0x46e38d[_0xf726('0x3d')],function(_0x535eed){var _0x1e88d0={};_0x1e88d0[_0x535eed]={'$like':'%'+_0x1701c7[_0xf726('0x39')][_0xf726('0x48')]+'%'};return _0x1e88d0;})});}_0x46e38d=_[_0xf726('0x46')]({},_0x46e38d,_0x1701c7['options']);return _0x4b9e5b['getAgents'](_0x46e38d);}})[_0xf726('0x1e')](function(_0x426cb7){if(_0x426cb7){_0x1ec513=_0x426cb7[_0xf726('0x3f')];if(!_0x1701c7['query'][_0xf726('0x40')]('nolimit')){_0x46e38d[_0xf726('0x2a')]=qs['limit'](_0x1701c7[_0xf726('0x39')][_0xf726('0x2a')]);_0x46e38d[_0xf726('0x2b')]=qs[_0xf726('0x2b')](_0x1701c7[_0xf726('0x39')]['offset']);}return _0x4b9e5b['getAgents'](_0x46e38d);}})[_0xf726('0x1e')](function(_0x242c4e){if(_0x242c4e){return _0x242c4e?{'count':_0x1ec513,'rows':_0x242c4e}:null;}})['then'](respondWithResult(_0x1136f5,null))[_0xf726('0x59')](handleError(_0x1136f5,null));};exports[_0xf726('0x6f')]=function(_0x1bde96,_0x5a2603){var _0x4c2349=_0x1bde96[_0xf726('0x4d')]['id'];var _0x55fba5=_0x1bde96[_0xf726('0x52')];var _0x51b84c=0xc8;var _0x4ae9f0=null;return db[_0xf726('0x70')][_0xf726('0x71')]({'isolationLevel':db[_0xf726('0x70')][_0xf726('0x72')]['ISOLATION_LEVELS'][_0xf726('0x73')]},function(_0x1ec8b5){return db[_0xf726('0x35')][_0xf726('0x5e')]({'where':{'id':_0x4c2349},'transaction':_0x1ec8b5})['then'](function(_0xe55e1f){if(_0xe55e1f){return db['WhatsappApplication'][_0xf726('0x2f')]({'where':{'WhatsappAccountId':_0x4c2349},'transaction':_0x1ec8b5})[_0xf726('0x1e')](function(){var _0x5d1c1d=_['map'](_0x55fba5,function(_0x8de12e){_0x8de12e['WhatsappAccountId']=_0x4c2349;return _0x8de12e;});return db['WhatsappApplication'][_0xf726('0x74')](_0x5d1c1d,{'transaction':_0x1ec8b5});});}else{_0x51b84c=0x194;_0x4ae9f0=[];}});})[_0xf726('0x1e')](function(){if(_0x51b84c!==0x194){return db[_0xf726('0x75')][_0xf726('0x76')]({'where':{'WhatsappAccountId':_0x4c2349},'order':'priority'})['then'](function(_0x5b4259){_0x4ae9f0=_0x5b4259;});}})[_0xf726('0x59')](function(_0x130ab3){_0x51b84c=0x1f4;logger[_0xf726('0x22')](_0x130ab3[_0xf726('0x77')]);if(_0x130ab3[_0xf726('0x32')]){delete _0x130ab3[_0xf726('0x32')];}_0x4ae9f0=_0x130ab3;})[_0xf726('0x78')](function(){if(_0x4ae9f0===null){_0x5a2603[_0xf726('0x26')](_0x51b84c);}else{if(_0x51b84c===0x1f4){_0x5a2603[_0xf726('0x27')](_0x51b84c)['send'](_0x4ae9f0);}else{_0x5a2603[_0xf726('0x27')](_0x51b84c)[_0xf726('0x28')](_0x4ae9f0);}}});};exports[_0xf726('0x79')]=function(_0x2d27a6,_0x2a8072,_0x24cfd7){var _0x140bd4={};var _0x560b72={};var _0x531510;var _0x174873;return db['WhatsappAccount']['findOne']({'where':{'id':_0x2d27a6[_0xf726('0x4d')]['id']}})[_0xf726('0x1e')](handleEntityNotFound(_0x2a8072,null))[_0xf726('0x1e')](function(_0x14a5ab){if(_0x14a5ab){_0x531510=_0x14a5ab;_0x560b72['model']=_[_0xf726('0x3a')](db[_0xf726('0x75')][_0xf726('0x36')]);_0x560b72[_0xf726('0x39')]=_[_0xf726('0x3a')](_0x2d27a6[_0xf726('0x39')]);_0x560b72[_0xf726('0x3b')]=_[_0xf726('0x3c')](_0x560b72[_0xf726('0x38')],_0x560b72[_0xf726('0x39')]);_0x140bd4['attributes']=_['intersection'](_0x560b72[_0xf726('0x38')],qs[_0xf726('0x3e')](_0x2d27a6[_0xf726('0x39')][_0xf726('0x3e')]));_0x140bd4[_0xf726('0x3d')]=_0x140bd4[_0xf726('0x3d')][_0xf726('0x3f')]?_0x140bd4[_0xf726('0x3d')]:_0x560b72['model'];_0x140bd4[_0xf726('0x42')]=qs['sort'](_0x2d27a6[_0xf726('0x39')][_0xf726('0x43')]);_0x140bd4[_0xf726('0x44')]=qs[_0xf726('0x3b')](_[_0xf726('0x45')](_0x2d27a6['query'],_0x560b72[_0xf726('0x3b')]));if(_0x2d27a6['query'][_0xf726('0x48')]){_0x140bd4[_0xf726('0x44')]=_[_0xf726('0x46')](_0x140bd4['where'],{'$or':_[_0xf726('0x34')](_0x140bd4[_0xf726('0x3d')],function(_0x47c1f2){var _0x574ec5={};_0x574ec5[_0x47c1f2]={'$like':'%'+_0x2d27a6[_0xf726('0x39')]['filter']+'%'};return _0x574ec5;})});}_0x140bd4=_[_0xf726('0x46')]({},_0x140bd4,_0x2d27a6[_0xf726('0x4f')]);return _0x531510['getApplications'](_0x140bd4);}})['then'](function(_0x649cb1){if(_0x649cb1){_0x174873=_0x649cb1[_0xf726('0x3f')];if(!_0x2d27a6[_0xf726('0x39')][_0xf726('0x40')](_0xf726('0x41'))){_0x140bd4[_0xf726('0x2a')]=qs[_0xf726('0x2a')](_0x2d27a6[_0xf726('0x39')][_0xf726('0x2a')]);_0x140bd4[_0xf726('0x2b')]=qs['offset'](_0x2d27a6['query']['offset']);}return _0x531510[_0xf726('0x79')](_0x140bd4);}})[_0xf726('0x1e')](function(_0x424e83){if(_0x424e83){return _0x424e83?{'count':_0x174873,'rows':_0x424e83}:null;}})[_0xf726('0x1e')](respondWithResult(_0x2a8072,null))[_0xf726('0x59')](handleError(_0x2a8072,null));};exports['notify']=function(_0x362f98,_0x551dd9,_0x2c79a1){var _0x2a4d18={'channel':_0xf726('0x7a')};var _0x1cc270=[];var _0xd5ea85=[];var _0x5c9200={};return db[_0xf726('0x35')]['find']({'where':{'id':_0x362f98[_0xf726('0x4d')]['id']},'include':[{'model':db[_0xf726('0x75')],'as':_0xf726('0x7b')}]})[_0xf726('0x1e')](handleEntityNotFound(_0x551dd9,null))[_0xf726('0x1e')](function(_0x42791e){_0x2a4d18[_0xf726('0x7c')]=_0x42791e;if(_0x2a4d18['account']&&_0x2a4d18[_0xf726('0x7c')]['type']===_0xf726('0x7d')&&_0x362f98['body'][_0xf726('0x7e')]){if(_0x362f98[_0xf726('0x52')][_0xf726('0x7e')]['length']===0x0)return;if(_0x362f98['body']['statuses'][0x0]['state']!==_0xf726('0x7f'))return;return db[_0xf726('0x80')][_0xf726('0x58')]({'read':!![],'readAt':_0x362f98['body']['statuses'][0x0][_0xf726('0x81')]},{'where':{'messageId':_0x362f98[_0xf726('0x52')][_0xf726('0x7e')][0x0]['message_id']},'individualHooks':!![]})[_0xf726('0x1e')](function(_0x4f578e){return _0x551dd9['status'](0xc8)[_0xf726('0x28')](_0x4f578e);});}_0x2a4d18[_0xf726('0x82')]=_[_0xf726('0x83')](_0x42791e['Applications'],['priority'],[_0xf726('0x84')]);if(_0x2a4d18['account'][_0xf726('0x7b')]){delete _0x2a4d18['account'][_0xf726('0x7b')];}return db['CmContact'][_0xf726('0x5a')]()[_0xf726('0x1e')](function(_0x16cc1d){if(!_0x16cc1d){throw new db[(_0xf726('0x85'))][(_0xf726('0x86'))](_0xf726('0x87'));}_0x1cc270=_[_0xf726('0x88')](_['keys'](_0x16cc1d),[_0xf726('0x89'),_0xf726('0x8a')]);_0xd5ea85=_[_0xf726('0x88')](_[_0xf726('0x3a')](_0x16cc1d),[_0xf726('0x89'),_0xf726('0x8a'),'CompanyId',_0xf726('0x8b')]);_0x2a4d18[_0xf726('0x52')]={'mapKey':_0xf726('0x8c')};if(_0x2a4d18[_0xf726('0x7c')]&&_0x2a4d18[_0xf726('0x7c')][_0xf726('0x47')]===_0xf726('0x8d')){_0x2a4d18[_0xf726('0x52')][_0xf726('0x8e')]=_0x362f98[_0xf726('0x52')][_0xf726('0x8f')][_0xf726('0x90')]('whatsapp:','');_0x2a4d18['body'][_0xf726('0x52')]=_0x362f98['body'][_0xf726('0x91')];_0x2a4d18[_0xf726('0x52')][_0xf726('0x92')]=_0x362f98[_0xf726('0x52')]['MessageSid'];}if(_0x2a4d18['account']&&_0x2a4d18[_0xf726('0x7c')][_0xf726('0x47')]===_0xf726('0x7d')){_0x2a4d18[_0xf726('0x52')][_0xf726('0x8e')]=_0x362f98[_0xf726('0x52')][_0xf726('0x93')][0x0][_0xf726('0x8e')];_0x2a4d18['body'][_0xf726('0x52')]=_0x362f98[_0xf726('0x52')]['notifications'][0x0][_0xf726('0x24')][_0xf726('0x52')];_0x2a4d18['body'][_0xf726('0x92')]=_0x362f98[_0xf726('0x52')]['notifications'][0x0][_0xf726('0x94')];}if(_0x2a4d18[_0xf726('0x52')]['id']){delete _0x2a4d18[_0xf726('0x52')]['id'];}if(_['isNil'](_0x2a4d18[_0xf726('0x52')][_0xf726('0x8e')])){throw new db['Sequelize'][(_0xf726('0x86'))]('from\x20is\x20mandatory');}if(_['isNil'](_0x2a4d18[_0xf726('0x52')][_0xf726('0x52')])||_0x2a4d18[_0xf726('0x52')][_0xf726('0x52')]===''){throw new db['Sequelize'][(_0xf726('0x86'))](_0xf726('0x95'));}if(_[_0xf726('0x96')](_0x2a4d18[_0xf726('0x52')]['mapKey'])){throw new db['Sequelize'][(_0xf726('0x86'))](_0xf726('0x97')+_0xd5ea85);}if(!_[_0xf726('0x98')](_0xd5ea85,_0x2a4d18['body'][_0xf726('0x99')])){throw new db[(_0xf726('0x85'))][(_0xf726('0x86'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0xd5ea85);}_0x5c9200[_0x2a4d18[_0xf726('0x52')]['mapKey']]=_0x2a4d18[_0xf726('0x52')][_0xf726('0x8e')];return db[_0xf726('0x9a')]['find']({'where':{'id':_0x2a4d18[_0xf726('0x7c')]['ListId']},'include':[{'model':db[_0xf726('0x9b')],'as':_0xf726('0x9c'),'where':_0x5c9200,'limit':0x1,'order':[[_0xf726('0x8a'),_0xf726('0x9d')]]}]});})[_0xf726('0x1e')](handleEntityNotFound(_0x551dd9,null))[_0xf726('0x1e')](function(_0x31d7a0){if(_0x31d7a0){_0x2a4d18[_0xf726('0x9e')]=_[_0xf726('0x68')](_0x31d7a0,[_0xf726('0x9c')]);if(_0x31d7a0[_0xf726('0x9c')][_0xf726('0x3f')]){return _0x31d7a0[_0xf726('0x9c')][0x0];}var _0x47915d=_[_0xf726('0x18')](_0x2a4d18[_0xf726('0x52')],{'firstName':_0x2a4d18[_0xf726('0x52')][_0xf726('0x8e')],'ListId':_0x31d7a0['id']});_0x47915d[_0x2a4d18[_0xf726('0x52')][_0xf726('0x99')]]=_0x2a4d18['body'][_0xf726('0x8e')];return db['CmContact'][_0xf726('0x51')](_0x47915d,{'fields':_0x1cc270,'raw':!![]});}})[_0xf726('0x1e')](handleEntityNotFound(_0x551dd9,null))[_0xf726('0x1e')](function(_0x197c90){if(_0x197c90){_0x2a4d18[_0xf726('0x9f')]=_0x197c90;var _0x474f67={'ContactId':_0x197c90['id'],'phone':_0x2a4d18['body'][_0xf726('0x8e')],'WhatsappAccountId':_0x362f98[_0xf726('0x4d')]['id']};var _0x272f74={'ContactId':_0x197c90['id'],'WhatsappAccountId':_0x362f98[_0xf726('0x4d')]['id'],'closed':![]};return db[_0xf726('0xa0')][_0xf726('0x50')]({'where':_0x272f74})['then'](function(_0x14b856){if(_0x14b856){return[_0x14b856,![]];}return db[_0xf726('0xa0')][_0xf726('0x51')](_0x474f67)[_0xf726('0x1e')](function(_0x1dbb1f){return[_0x1dbb1f,!![]];});});}})[_0xf726('0x69')](function(_0x38216d,_0x20b115){_0x2a4d18[_0xf726('0xa1')]=_0x38216d[_0xf726('0x30')]({'plain':!![]});_0x2a4d18[_0xf726('0xa1')][_0xf726('0xa2')]=![];if(_0x20b115){if(_0x2a4d18[_0xf726('0x7c')][_0xf726('0xa3')]){_0x2a4d18[_0xf726('0x82')]['push']({'id':0x0,'priority':_0x2a4d18[_0xf726('0x82')][_0xf726('0x3f')]+0x1,'app':_0xf726('0xa4'),'appdata':_0xf726('0xa5'),'interval':_0xf726('0xa6')});}_0x2a4d18['interaction'][_0xf726('0xa2')]=!![];}return db[_0xf726('0x80')][_0xf726('0x51')]({'phone':_0x2a4d18['body']['from'],'messageId':_0x2a4d18[_0xf726('0x52')]['messageId'],'body':_0x2a4d18[_0xf726('0x52')]['body'],'WhatsappAccountId':_0x362f98[_0xf726('0x4d')]['id'],'WhatsappInteractionId':_0x38216d['id'],'direction':'in','ContactId':_0x38216d[_0xf726('0xa7')],'AttachmentId':_0x2a4d18[_0xf726('0x52')]['AttachmentId']});})['then'](function(_0x212dce){_0x2a4d18['message']=_0x212dce;if(!_0x2a4d18[_0xf726('0xa1')][_0xf726('0xa8')])return;return db[_0xf726('0x6e')][_0xf726('0x50')]({'attributes':['id',_0xf726('0x32')],'where':{'id':_0x2a4d18['interaction'][_0xf726('0xa8')]}});})[_0xf726('0x1e')](function(_0xe9e1e0){if(_0xe9e1e0){_0x2a4d18[_0xf726('0x82')]['unshift']({'id':0x0,'priority':0x0,'app':'agent','appdata':_0xe9e1e0[_0xf726('0x32')]+','+(_0x2a4d18['account'][_0xf726('0xa9')]||0xa),'interval':_0xf726('0xa6')});}if(!_0x2a4d18['interaction'][_0xf726('0xaa')])return;return db['WhatsappQueue'][_0xf726('0x50')]({'attributes':['id',_0xf726('0x32')],'where':{'id':_0x2a4d18[_0xf726('0xa1')][_0xf726('0xaa')]}});})[_0xf726('0x1e')](function(_0xe2df87){if(_0xe2df87){_0x2a4d18['applications'][_0xf726('0xab')]({'id':0x0,'priority':0x1,'app':'queue','appdata':_0xe2df87['name']+','+(_0x2a4d18[_0xf726('0x7c')][_0xf726('0xac')]||0x12c),'interval':_0xf726('0xa6')});}return respondWithRpcPromise(_0xf726('0xad'),_0xf726('0xae'),_0x2a4d18);})[_0xf726('0x1e')](function(_0x34c45e){if(_0x34c45e){var _0x542f7a=0xc8;var _0x3d81a7=_0xf726('0xaf');logger[_0xf726('0x25')](_0xf726('0xb0'),_0x3d81a7,_0x542f7a,'entity\x20found');logger['debug'](_0xf726('0xb1'),_0x3d81a7,_0x542f7a,_0xf726('0xb2'),JSON['stringify'](_0x34c45e));if(_0x2a4d18['account']['type']===_0xf726('0x8d')){return _0x551dd9[_0xf726('0x27')](_0x542f7a)[_0xf726('0x2c')]('Content-Type','text/xml')[_0xf726('0xb3')]('<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>');}else{return _0x551dd9[_0xf726('0x27')](_0x542f7a)['json'](_0x34c45e);}}});})[_0xf726('0x59')](handleError(_0x551dd9,null));};exports[_0xf726('0xb3')]=function(_0x2257db,_0xf9e36a,_0x37efd4){var _0x25cb40,_0x57012f,_0x54248c;if(_['isNil'](_0x2257db['body'][_0xf726('0x52')])||_0x2257db[_0xf726('0x52')]['body']===''){throw new db[(_0xf726('0x85'))][(_0xf726('0x86'))](_0xf726('0x95'));}if(_[_0xf726('0x96')](_0x2257db['body']['to'])){throw new db[(_0xf726('0x85'))]['ValidationError'](_0xf726('0xb4'));}_0x25cb40=_0x2257db[_0xf726('0x52')]['to'];return db['WhatsappAccount']['find']({'where':{'id':_0x2257db[_0xf726('0x4d')]['id']},'include':[{'model':db['CmList'],'as':_0xf726('0xb5'),'include':[{'model':db[_0xf726('0x9b')],'as':'Contacts','where':{'mobile':_0x25cb40},'limit':0x1,'order':[[_0xf726('0x8a'),_0xf726('0x9d')]]}]}]})[_0xf726('0x1e')](handleEntityNotFound(_0xf9e36a,null))[_0xf726('0x1e')](function(_0x30a7ad){if(_0x30a7ad&&_0x30a7ad['List']){_0x57012f=_0x30a7ad[_0xf726('0x30')]({'plain':!![]});if(_0x57012f[_0xf726('0xb5')]&&_0x57012f[_0xf726('0xb5')]['Contacts'][_0xf726('0x3f')]){return _0x57012f[_0xf726('0xb5')][_0xf726('0x9c')][0x0];}return db[_0xf726('0x9b')][_0xf726('0x51')](_['defaults'](_0x2257db[_0xf726('0x52')],{'firstName':_0x25cb40,'mobile':_0x25cb40,'phone':_0x25cb40,'ListId':_0x57012f['ListId']}));}})[_0xf726('0x1e')](handleEntityNotFound(_0xf9e36a,null))['then'](function(_0x530068){if(_0x530068){_0x54248c=_0x530068;return db[_0xf726('0xa0')][_0xf726('0x50')]({'where':{'ContactId':_0x54248c['id'],'closed':![],'WhatsappAccountId':_0x57012f['id']}})[_0xf726('0x1e')](function(_0x60f8ea){if(_0x60f8ea){return[_0x60f8ea,![]];}return db[_0xf726('0xa0')][_0xf726('0x51')]({'UserId':_0x2257db[_0xf726('0x54')]['id'],'ContactId':_0x54248c['id'],'WhatsappAccountId':_0x57012f['id'],'phone':_0x25cb40,'firstMsgDirection':_0xf726('0xb6'),'Messages':[_[_0xf726('0x46')](_0x2257db[_0xf726('0x52')],{'read':![],'body':_0x2257db['body'][_0xf726('0x52')],'phone':_0x25cb40,'WhatsappAccountId':_0x57012f['id'],'UserId':_0x2257db[_0xf726('0x54')]['id'],'ContactId':_0x54248c['id']})]},{'include':[{'model':db[_0xf726('0x80')],'as':_0xf726('0xb7')}]})[_0xf726('0x1e')](function(_0x4f805d){return[_0x4f805d,!![]];});});}})[_0xf726('0x69')](function(_0x626171,_0xb1288a){if(_0xb1288a){return _0x626171;}return db[_0xf726('0x80')][_0xf726('0x51')](_[_0xf726('0x46')](_0x2257db[_0xf726('0x52')],{'read':![],'body':_0x2257db[_0xf726('0x52')][_0xf726('0x52')],'phone':_0x25cb40,'WhatsappAccountId':_0x57012f['id'],'WhatsappInteractionId':_0x626171['id'],'UserId':_0x2257db[_0xf726('0x54')]['id'],'ContactId':_0x54248c['id']}))[_0xf726('0x1e')](function(_0x3e6755){_0x626171[_0xf726('0xb8')][_0xf726('0xb7')]=[];_0x626171[_0xf726('0xb8')][_0xf726('0xb7')][_0xf726('0xb9')](_0x3e6755[_0xf726('0xb8')]);return _0x626171;});})[_0xf726('0x1e')](respondWithResult(_0xf9e36a,null))[_0xf726('0x59')](handleError(_0xf9e36a,null));};
\ No newline at end of file
+var _0x605f=['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>','to\x20is\x20mandatory','List','WhatsappInteraction','out','WhatsappMessage','Messages','dataValues','rimraf','zip-dir','request-promise','moment','mustache','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','./whatsappAccount.socket','jayson/promise','http','request','then','info','WhatsappAccount,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','WhatsappAccount,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','json','undefined','limit','count','offset','set','Content-Range','apply','reject','save','destroy','get','UserProfileResource','name','send','index','Pause','mandatoryDispositionPause','map','WhatsappAccount','rawAttributes','fieldName','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','filters','pick','filter','where','merge','type','VIRTUAL','options','include','findAll','rows','show','params','includeAll','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','WhatsappAccounts','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','WhatsappAccountId','Disposition','getDispositions','findOne','removeDispositions','ids','addAnswer','CannedAnswer','removeAnswers','addAgents','spread','userWhatsappAccount:save','removeAgents','isArray','emit','userWhatsappAccount:remove','getAgents','User','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','WhatsappApplication','bulkCreate','findAndCountAll','getApplications','whatsapp','Applications','account','sinch','statuses','state','update','timestamp','applications','orderBy','CmContact','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','replace','whatsapp:','Body','MessageSid','from','notifications','message_id','isNil','Sequelize','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','Contacts','DESC','list','omit','contact','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','messageId','UserId','agent','waitForTheAssignedAgent','queueId','WhatsappQueue','unshift','queue','Start','startRouting'];(function(_0x4dcdbd,_0xc56f3a){var _0x2916aa=function(_0x547941){while(--_0x547941){_0x4dcdbd['push'](_0x4dcdbd['shift']());}};_0x2916aa(++_0xc56f3a);}(_0x605f,0x1a6));var _0xf605=function(_0x3e2f67,_0x9cb2c6){_0x3e2f67=_0x3e2f67-0x0;var _0x313667=_0x605f[_0x3e2f67];return _0x313667;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf605('0x0'));var zipdir=require(_0xf605('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf605('0x2'));var moment=require(_0xf605('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xf605('0x4'));var util=require(_0xf605('0x5'));var path=require('path');var sox=require(_0xf605('0x6'));var csv=require(_0xf605('0x7'));var ejs=require(_0xf605('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xf605('0x9'));var squel=require(_0xf605('0xa'));var crypto=require(_0xf605('0xb'));var jsforce=require(_0xf605('0xc'));var deskjs=require(_0xf605('0xd'));var toCsv=require('to-csv');var querystring=require(_0xf605('0xe'));var Papa=require(_0xf605('0xf'));var Redis=require(_0xf605('0x10'));var authService=require(_0xf605('0x11'));var qs=require(_0xf605('0x12'));var as=require(_0xf605('0x13'));var hardwareService=require(_0xf605('0x14'));var logger=require(_0xf605('0x15'))('api');var utils=require(_0xf605('0x16'));var config=require(_0xf605('0x17'));var licenseUtil=require(_0xf605('0x18'));var db=require(_0xf605('0x19'))['db'];config[_0xf605('0x1a')]=_[_0xf605('0x1b')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xf605('0x1c'))(new Redis(config[_0xf605('0x1a')]));require(_0xf605('0x1d'))['register'](socket);var jayson=require(_0xf605('0x1e'));var client=jayson['client'][_0xf605('0x1f')]({'port':0x232c});function respondWithRpcPromise(_0x94112c,_0x1146b0,_0x1ed500,_0x2162cf){return new BPromise(function(_0x116514,_0x3178b5){var _0x2dea28=_0x2162cf||client;return _0x2dea28[_0xf605('0x20')](_0x94112c,_0x1ed500)[_0xf605('0x21')](function(_0x61b695){logger[_0xf605('0x22')]('WhatsappAccount,\x20%s,\x20%s',_0x1146b0,'request\x20sent');logger['debug'](_0xf605('0x23'),_0x1146b0,_0xf605('0x24'),JSON[_0xf605('0x25')](_0x61b695));if(_0x61b695[_0xf605('0x26')]){if(_0x61b695[_0xf605('0x26')][_0xf605('0x27')]===0x1f4){logger[_0xf605('0x26')](_0xf605('0x28'),_0x1146b0,_0x61b695[_0xf605('0x26')][_0xf605('0x29')]);return _0x3178b5(_0x61b695[_0xf605('0x26')]['message']);}logger[_0xf605('0x26')]('WhatsappAccount,\x20%s,\x20%s',_0x1146b0,_0x61b695[_0xf605('0x26')]['message']);return _0x116514(_0x61b695[_0xf605('0x26')]['message']);}else{logger[_0xf605('0x22')](_0xf605('0x28'),_0x1146b0,_0xf605('0x24'));_0x116514(_0x61b695[_0xf605('0x2a')][_0xf605('0x29')]);}})[_0xf605('0x2b')](function(_0x5ad86d){logger[_0xf605('0x26')](_0xf605('0x28'),_0x1146b0,_0x5ad86d);_0x3178b5(_0x5ad86d);});});}function respondWithStatusCode(_0x5864a4,_0x51367b){_0x51367b=_0x51367b||0xcc;return function(_0x329376){if(_0x329376){return _0x5864a4[_0xf605('0x2c')](_0x51367b);}return _0x5864a4[_0xf605('0x2d')](_0x51367b)[_0xf605('0x2e')]();};}function respondWithResult(_0x3745b4,_0x35c299){_0x35c299=_0x35c299||0xc8;return function(_0x459b89){if(_0x459b89){return _0x3745b4['status'](_0x35c299)[_0xf605('0x2f')](_0x459b89);}};}function respondWithFilteredResult(_0x28691c,_0x2b41a3){return function(_0x54ea52){if(_0x54ea52){var _0x5f43fa=typeof _0x2b41a3['offset']===_0xf605('0x30')&&typeof _0x2b41a3[_0xf605('0x31')]===_0xf605('0x30');var _0x2a0809=_0x54ea52[_0xf605('0x32')];var _0x73aeb4=_0x5f43fa?0x0:_0x2b41a3[_0xf605('0x33')];var _0x355733=_0x5f43fa?_0x54ea52[_0xf605('0x32')]:_0x2b41a3['offset']+_0x2b41a3[_0xf605('0x31')];var _0x5dbd02;if(_0x355733>=_0x2a0809){_0x355733=_0x2a0809;_0x5dbd02=0xc8;}else{_0x5dbd02=0xce;}_0x28691c[_0xf605('0x2d')](_0x5dbd02);return _0x28691c[_0xf605('0x34')](_0xf605('0x35'),_0x73aeb4+'-'+_0x355733+'/'+_0x2a0809)[_0xf605('0x2f')](_0x54ea52);}return null;};}function patchUpdates(_0x5c93de){return function(_0x27ab47){try{jsonpatch[_0xf605('0x36')](_0x27ab47,_0x5c93de,!![]);}catch(_0x6d5120){return BPromise[_0xf605('0x37')](_0x6d5120);}return _0x27ab47[_0xf605('0x38')]();};}function saveUpdates(_0x22f032,_0x4e12d3){return function(_0xf5612e){if(_0xf5612e){return _0xf5612e['update'](_0x22f032)[_0xf605('0x21')](function(_0x5d9f57){return _0x5d9f57;});}return null;};}function removeEntity(_0x5924ce,_0x278dcb){return function(_0x4cfbb7){if(_0x4cfbb7){return _0x4cfbb7[_0xf605('0x39')]()['then'](function(){var _0x49d6ba=_0x4cfbb7[_0xf605('0x3a')]({'plain':!![]});var _0x234300='WhatsappAccounts';return db[_0xf605('0x3b')][_0xf605('0x39')]({'where':{'type':_0x234300,'resourceId':_0x49d6ba['id']}})[_0xf605('0x21')](function(){return _0x4cfbb7;});})[_0xf605('0x21')](function(){_0x5924ce[_0xf605('0x2d')](0xcc)[_0xf605('0x2e')]();});}};}function handleEntityNotFound(_0x2a0aa3,_0x556d11){return function(_0xe3b337){if(!_0xe3b337){_0x2a0aa3[_0xf605('0x2c')](0x194);}return _0xe3b337;};}function handleError(_0x592ede,_0x207a7e){_0x207a7e=_0x207a7e||0x1f4;return function(_0x886ce3){logger[_0xf605('0x26')](_0x886ce3['stack']);if(_0x886ce3[_0xf605('0x3c')]){delete _0x886ce3[_0xf605('0x3c')];}_0x592ede['status'](_0x207a7e)[_0xf605('0x3d')](_0x886ce3);};}exports[_0xf605('0x3e')]=function(_0x117ef3,_0x45f9e0){var _0x51cd96={'include':[{'model':db[_0xf605('0x3f')],'as':_0xf605('0x40')}]},_0x35a6d0={},_0x2701e8={'count':0x0,'rows':[]};var _0x41dce5=_[_0xf605('0x41')](db[_0xf605('0x42')][_0xf605('0x43')],function(_0x119808){return{'name':_0x119808[_0xf605('0x44')],'type':_0x119808['type'][_0xf605('0x45')]};});_0x35a6d0[_0xf605('0x46')]=_[_0xf605('0x41')](_0x41dce5,_0xf605('0x3c'));_0x35a6d0[_0xf605('0x47')]=_[_0xf605('0x48')](_0x117ef3[_0xf605('0x47')]);_0x35a6d0['filters']=_[_0xf605('0x49')](_0x35a6d0[_0xf605('0x46')],_0x35a6d0[_0xf605('0x47')]);_0x51cd96[_0xf605('0x4a')]=_['intersection'](_0x35a6d0[_0xf605('0x46')],qs[_0xf605('0x4b')](_0x117ef3[_0xf605('0x47')][_0xf605('0x4b')]));_0x51cd96[_0xf605('0x4a')]=_0x51cd96[_0xf605('0x4a')][_0xf605('0x4c')]?_0x51cd96[_0xf605('0x4a')]:_0x35a6d0[_0xf605('0x46')];if(!_0x117ef3[_0xf605('0x47')][_0xf605('0x4d')](_0xf605('0x4e'))){_0x51cd96['limit']=qs['limit'](_0x117ef3[_0xf605('0x47')][_0xf605('0x31')]);_0x51cd96[_0xf605('0x33')]=qs[_0xf605('0x33')](_0x117ef3[_0xf605('0x47')][_0xf605('0x33')]);}_0x51cd96[_0xf605('0x4f')]=qs['sort'](_0x117ef3['query'][_0xf605('0x50')]);_0x51cd96['where']=qs[_0xf605('0x51')](_[_0xf605('0x52')](_0x117ef3[_0xf605('0x47')],_0x35a6d0[_0xf605('0x51')]),_0x41dce5);if(_0x117ef3[_0xf605('0x47')][_0xf605('0x53')]){_0x51cd96[_0xf605('0x54')]=_[_0xf605('0x55')](_0x51cd96[_0xf605('0x54')],{'$or':_[_0xf605('0x41')](_0x41dce5,function(_0x2e1814){if(_0x2e1814[_0xf605('0x56')]!==_0xf605('0x57')){var _0x335857={};_0x335857[_0x2e1814[_0xf605('0x3c')]]={'$like':'%'+_0x117ef3[_0xf605('0x47')][_0xf605('0x53')]+'%'};return _0x335857;}})});}_0x51cd96=_['merge']({},_0x51cd96,_0x117ef3[_0xf605('0x58')]);var _0x57a232={'where':_0x51cd96[_0xf605('0x54')]};return db[_0xf605('0x42')][_0xf605('0x32')](_0x57a232)[_0xf605('0x21')](function(_0x46805a){_0x2701e8['count']=_0x46805a;if(_0x117ef3[_0xf605('0x47')]['includeAll']){_0x51cd96[_0xf605('0x59')]=[{'all':!![]}];}return db['WhatsappAccount'][_0xf605('0x5a')](_0x51cd96);})[_0xf605('0x21')](function(_0x235748){_0x2701e8[_0xf605('0x5b')]=_0x235748;return _0x2701e8;})[_0xf605('0x21')](respondWithFilteredResult(_0x45f9e0,_0x51cd96))[_0xf605('0x2b')](handleError(_0x45f9e0,null));};exports[_0xf605('0x5c')]=function(_0x2ff1c5,_0x5311a7){var _0x32366e={'raw':![],'where':{'id':_0x2ff1c5[_0xf605('0x5d')]['id']},'include':[{'model':db[_0xf605('0x3f')],'as':_0xf605('0x40')}]},_0x13aee8={};_0x13aee8[_0xf605('0x46')]=_[_0xf605('0x48')](db[_0xf605('0x42')]['rawAttributes']);_0x13aee8[_0xf605('0x47')]=_[_0xf605('0x48')](_0x2ff1c5[_0xf605('0x47')]);_0x13aee8[_0xf605('0x51')]=_[_0xf605('0x49')](_0x13aee8['model'],_0x13aee8[_0xf605('0x47')]);_0x32366e[_0xf605('0x4a')]=_[_0xf605('0x49')](_0x13aee8[_0xf605('0x46')],qs[_0xf605('0x4b')](_0x2ff1c5[_0xf605('0x47')]['fields']));_0x32366e[_0xf605('0x4a')]=_0x32366e[_0xf605('0x4a')][_0xf605('0x4c')]?_0x32366e[_0xf605('0x4a')]:_0x13aee8[_0xf605('0x46')];if(_0x2ff1c5[_0xf605('0x47')][_0xf605('0x5e')]){_0x32366e['include']=[{'all':!![]}];}_0x32366e=_[_0xf605('0x55')]({},_0x32366e,_0x2ff1c5[_0xf605('0x58')]);return db[_0xf605('0x42')][_0xf605('0x5f')](_0x32366e)[_0xf605('0x21')](handleEntityNotFound(_0x5311a7,null))[_0xf605('0x21')](respondWithResult(_0x5311a7,null))['catch'](handleError(_0x5311a7,null));};exports[_0xf605('0x60')]=function(_0xe6518a,_0x3a384d){return db[_0xf605('0x42')]['create'](_0xe6518a[_0xf605('0x61')],{})[_0xf605('0x21')](function(_0x50ec6a){var _0x379dab=_0xe6518a['user'][_0xf605('0x3a')]({'plain':!![]});if(!_0x379dab)throw new Error(_0xf605('0x62'));if(_0x379dab['role']===_0xf605('0x63')){var _0x3ec1bc=_0x50ec6a[_0xf605('0x3a')]({'plain':!![]});var _0x5a0e22=_0xf605('0x64');return db['UserProfileSection']['find']({'where':{'name':_0x5a0e22,'userProfileId':_0x379dab[_0xf605('0x65')]},'raw':!![]})[_0xf605('0x21')](function(_0x361f15){if(_0x361f15&&_0x361f15[_0xf605('0x66')]===0x0){return db[_0xf605('0x3b')][_0xf605('0x60')]({'name':_0x3ec1bc['name'],'resourceId':_0x3ec1bc['id'],'type':_0x361f15['name'],'sectionId':_0x361f15['id']},{})[_0xf605('0x21')](function(){return _0x50ec6a;});}else{return _0x50ec6a;}})[_0xf605('0x2b')](function(_0x3b76ee){logger[_0xf605('0x26')](_0xf605('0x67'),_0x3b76ee);throw _0x3b76ee;});}return _0x50ec6a;})['then'](respondWithResult(_0x3a384d,0xc9))['catch'](handleError(_0x3a384d,null));};exports['update']=function(_0x56852a,_0x3a3271){if(_0x56852a[_0xf605('0x61')]['id']){delete _0x56852a[_0xf605('0x61')]['id'];}return db[_0xf605('0x42')][_0xf605('0x5f')]({'where':{'id':_0x56852a[_0xf605('0x5d')]['id']},'include':[{'model':db[_0xf605('0x3f')],'as':_0xf605('0x40')}]})['then'](handleEntityNotFound(_0x3a3271,null))[_0xf605('0x21')](saveUpdates(_0x56852a[_0xf605('0x61')],null))['then'](respondWithResult(_0x3a3271,null))[_0xf605('0x2b')](handleError(_0x3a3271,null));};exports[_0xf605('0x39')]=function(_0x220e02,_0x36d4cf){return db[_0xf605('0x42')]['find']({'where':{'id':_0x220e02[_0xf605('0x5d')]['id']}})['then'](handleEntityNotFound(_0x36d4cf,null))['then'](removeEntity(_0x36d4cf,null))[_0xf605('0x2b')](handleError(_0x36d4cf,null));};exports[_0xf605('0x68')]=function(_0xc9ec2c,_0x4a1c00){return db[_0xf605('0x42')][_0xf605('0x68')]()[_0xf605('0x21')](respondWithResult(_0x4a1c00,null))[_0xf605('0x2b')](handleError(_0x4a1c00,null));};exports[_0xf605('0x69')]=function(_0x1bd788,_0x206166,_0x230439){if(_0x1bd788[_0xf605('0x61')]['id']){delete _0x1bd788[_0xf605('0x61')]['id'];}return db[_0xf605('0x42')][_0xf605('0x5f')]({'where':{'id':_0x1bd788[_0xf605('0x5d')]['id']}})[_0xf605('0x21')](handleEntityNotFound(_0x206166,null))[_0xf605('0x21')](function(_0x12b977){if(_0x12b977){_0x1bd788['body'][_0xf605('0x6a')]=_0x12b977['id'];return db[_0xf605('0x6b')][_0xf605('0x60')](_0x1bd788['body']);}})['then'](respondWithResult(_0x206166,null))['catch'](handleError(_0x206166,null));};exports[_0xf605('0x6c')]=function(_0x1a61f1,_0x131d54,_0x56f4d1){var _0x329916={'raw':![],'where':{}};var _0x1c2855={};var _0x50e7c4={'count':0x0,'rows':[]};return db[_0xf605('0x42')][_0xf605('0x6d')]({'where':{'id':_0x1a61f1[_0xf605('0x5d')]['id']}})[_0xf605('0x21')](handleEntityNotFound(_0x131d54,null))[_0xf605('0x21')](function(_0x38848d){if(_0x38848d){_0x1c2855[_0xf605('0x46')]=_[_0xf605('0x48')](db[_0xf605('0x6b')]['rawAttributes']);_0x1c2855['query']=_[_0xf605('0x48')](_0x1a61f1[_0xf605('0x47')]);_0x1c2855[_0xf605('0x51')]=_[_0xf605('0x49')](_0x1c2855[_0xf605('0x46')],_0x1c2855[_0xf605('0x47')]);_0x329916[_0xf605('0x4a')]=_['intersection'](_0x1c2855[_0xf605('0x46')],qs[_0xf605('0x4b')](_0x1a61f1['query'][_0xf605('0x4b')]));_0x329916[_0xf605('0x4a')]=_0x329916[_0xf605('0x4a')][_0xf605('0x4c')]?_0x329916[_0xf605('0x4a')]:_0x1c2855[_0xf605('0x46')];if(!_0x1a61f1[_0xf605('0x47')]['hasOwnProperty'](_0xf605('0x4e'))){_0x329916['limit']=qs[_0xf605('0x31')](_0x1a61f1[_0xf605('0x47')][_0xf605('0x31')]);_0x329916[_0xf605('0x33')]=qs[_0xf605('0x33')](_0x1a61f1[_0xf605('0x47')]['offset']);}_0x329916[_0xf605('0x4f')]=qs[_0xf605('0x50')](_0x1a61f1['query'][_0xf605('0x50')]);_0x329916[_0xf605('0x54')]=qs[_0xf605('0x51')](_[_0xf605('0x52')](_0x1a61f1[_0xf605('0x47')],_0x1c2855[_0xf605('0x51')]));_0x329916[_0xf605('0x54')][_0xf605('0x6a')]=_0x38848d['id'];if(_0x1a61f1[_0xf605('0x47')][_0xf605('0x53')]){_0x329916[_0xf605('0x54')]=_[_0xf605('0x55')](_0x329916[_0xf605('0x54')],{'$or':_[_0xf605('0x41')](_0x329916[_0xf605('0x4a')],function(_0x1fc54a){var _0x1602ef={};_0x1602ef[_0x1fc54a]={'$like':'%'+_0x1a61f1[_0xf605('0x47')][_0xf605('0x53')]+'%'};return _0x1602ef;})});}_0x329916=_[_0xf605('0x55')]({},_0x329916,_0x1a61f1[_0xf605('0x58')]);return db[_0xf605('0x6b')][_0xf605('0x32')]({'where':_0x329916[_0xf605('0x54')]})[_0xf605('0x21')](function(_0x2173ea){_0x50e7c4['count']=_0x2173ea;if(_0x1a61f1[_0xf605('0x47')][_0xf605('0x5e')]){_0x329916[_0xf605('0x59')]=[{'all':!![]}];}return db[_0xf605('0x6b')][_0xf605('0x5a')](_0x329916);})[_0xf605('0x21')](function(_0x5e7d4b){_0x50e7c4[_0xf605('0x5b')]=_0x5e7d4b;return _0x50e7c4;});}})['then'](respondWithFilteredResult(_0x131d54,_0x329916))[_0xf605('0x2b')](handleError(_0x131d54,null));};exports[_0xf605('0x6e')]=function(_0x1dfbab,_0x2120f5,_0x243c74){return db[_0xf605('0x42')][_0xf605('0x5f')]({'where':{'id':_0x1dfbab['params']['id']}})[_0xf605('0x21')](handleEntityNotFound(_0x2120f5,null))[_0xf605('0x21')](function(_0x1688c3){if(_0x1688c3){return _0x1688c3[_0xf605('0x6e')](_0x1dfbab[_0xf605('0x47')][_0xf605('0x6f')]);}})[_0xf605('0x21')](respondWithStatusCode(_0x2120f5,null))[_0xf605('0x2b')](handleError(_0x2120f5,null));};exports[_0xf605('0x70')]=function(_0x55a2fd,_0x1aa7aa,_0x5a5c67){if(_0x55a2fd[_0xf605('0x61')]['id']){delete _0x55a2fd[_0xf605('0x61')]['id'];}return db[_0xf605('0x42')]['find']({'where':{'id':_0x55a2fd[_0xf605('0x5d')]['id']}})[_0xf605('0x21')](handleEntityNotFound(_0x1aa7aa,null))[_0xf605('0x21')](function(_0x25ec4f){if(_0x25ec4f){_0x55a2fd['body'][_0xf605('0x6a')]=_0x25ec4f['id'];return db[_0xf605('0x71')][_0xf605('0x60')](_0x55a2fd[_0xf605('0x61')]);}})[_0xf605('0x21')](respondWithResult(_0x1aa7aa,null))[_0xf605('0x2b')](handleError(_0x1aa7aa,null));};exports['getAnswers']=function(_0x202a36,_0x515a44,_0xa70444){var _0x10aa8c={'raw':![],'where':{}};var _0x13a0d7={};var _0x47b548={'count':0x0,'rows':[]};return db[_0xf605('0x42')][_0xf605('0x6d')]({'where':{'id':_0x202a36[_0xf605('0x5d')]['id']}})[_0xf605('0x21')](handleEntityNotFound(_0x515a44,null))[_0xf605('0x21')](function(_0x429db5){if(_0x429db5){_0x13a0d7[_0xf605('0x46')]=_['keys'](db[_0xf605('0x71')]['rawAttributes']);_0x13a0d7[_0xf605('0x47')]=_[_0xf605('0x48')](_0x202a36[_0xf605('0x47')]);_0x13a0d7[_0xf605('0x51')]=_[_0xf605('0x49')](_0x13a0d7[_0xf605('0x46')],_0x13a0d7[_0xf605('0x47')]);_0x10aa8c[_0xf605('0x4a')]=_[_0xf605('0x49')](_0x13a0d7[_0xf605('0x46')],qs[_0xf605('0x4b')](_0x202a36[_0xf605('0x47')][_0xf605('0x4b')]));_0x10aa8c[_0xf605('0x4a')]=_0x10aa8c[_0xf605('0x4a')][_0xf605('0x4c')]?_0x10aa8c[_0xf605('0x4a')]:_0x13a0d7[_0xf605('0x46')];if(!_0x202a36[_0xf605('0x47')]['hasOwnProperty']('nolimit')){_0x10aa8c[_0xf605('0x31')]=qs['limit'](_0x202a36[_0xf605('0x47')][_0xf605('0x31')]);_0x10aa8c['offset']=qs['offset'](_0x202a36[_0xf605('0x47')][_0xf605('0x33')]);}_0x10aa8c[_0xf605('0x4f')]=qs[_0xf605('0x50')](_0x202a36[_0xf605('0x47')][_0xf605('0x50')]);_0x10aa8c['where']=qs[_0xf605('0x51')](_[_0xf605('0x52')](_0x202a36[_0xf605('0x47')],_0x13a0d7['filters']));_0x10aa8c['where']['WhatsappAccountId']=_0x429db5['id'];if(_0x202a36[_0xf605('0x47')][_0xf605('0x53')]){_0x10aa8c['where']=_['merge'](_0x10aa8c[_0xf605('0x54')],{'$or':_['map'](_0x10aa8c[_0xf605('0x4a')],function(_0x1fea36){var _0x209888={};_0x209888[_0x1fea36]={'$like':'%'+_0x202a36['query'][_0xf605('0x53')]+'%'};return _0x209888;})});}_0x10aa8c=_['merge']({},_0x10aa8c,_0x202a36[_0xf605('0x58')]);return db[_0xf605('0x71')][_0xf605('0x32')]({'where':_0x10aa8c['where']})[_0xf605('0x21')](function(_0x4db247){_0x47b548['count']=_0x4db247;if(_0x202a36[_0xf605('0x47')]['includeAll']){_0x10aa8c[_0xf605('0x59')]=[{'all':!![]}];}return db[_0xf605('0x71')][_0xf605('0x5a')](_0x10aa8c);})[_0xf605('0x21')](function(_0x5bacac){_0x47b548[_0xf605('0x5b')]=_0x5bacac;return _0x47b548;});}})[_0xf605('0x21')](respondWithFilteredResult(_0x515a44,_0x10aa8c))[_0xf605('0x2b')](handleError(_0x515a44,null));};exports[_0xf605('0x72')]=function(_0x527ff1,_0x5a8842,_0x2bd50a){return db[_0xf605('0x42')][_0xf605('0x5f')]({'where':{'id':_0x527ff1[_0xf605('0x5d')]['id']}})[_0xf605('0x21')](handleEntityNotFound(_0x5a8842,null))[_0xf605('0x21')](function(_0x3f294c){if(_0x3f294c){return _0x3f294c[_0xf605('0x72')](_0x527ff1[_0xf605('0x47')][_0xf605('0x6f')]);}})[_0xf605('0x21')](respondWithStatusCode(_0x5a8842,null))[_0xf605('0x2b')](handleError(_0x5a8842,null));};exports[_0xf605('0x73')]=function(_0x59d67a,_0x44b2ed,_0x211ec7){return db['WhatsappAccount'][_0xf605('0x5f')]({'where':{'id':_0x59d67a[_0xf605('0x5d')]['id']}})[_0xf605('0x21')](handleEntityNotFound(_0x44b2ed,null))[_0xf605('0x21')](function(_0x3636e0){if(_0x3636e0){return _0x3636e0[_0xf605('0x73')](_0x59d67a[_0xf605('0x61')][_0xf605('0x6f')],_['omit'](_0x59d67a['body'],[_0xf605('0x6f'),'id'])||{})[_0xf605('0x74')](function(_0xa8bf5a){for(var _0xd9e342=0x0;_0xd9e342<_0x59d67a['body'][_0xf605('0x6f')][_0xf605('0x4c')];_0xd9e342+=0x1){socket['emit'](_0xf605('0x75'),{'UserId':Number(_0x59d67a[_0xf605('0x61')]['ids'][_0xd9e342]),'WhatsappAccountId':Number(_0x59d67a[_0xf605('0x5d')]['id'])});}return _0xa8bf5a;});}})['then'](respondWithResult(_0x44b2ed,null))['catch'](handleError(_0x44b2ed,null));};exports[_0xf605('0x76')]=function(_0x9144bb,_0xc6d68d,_0x575949){return db[_0xf605('0x42')][_0xf605('0x5f')]({'where':{'id':_0x9144bb[_0xf605('0x5d')]['id']}})['then'](handleEntityNotFound(_0xc6d68d,null))[_0xf605('0x21')](function(_0x9c5554){if(_0x9c5554){return _0x9c5554[_0xf605('0x76')](_0x9144bb[_0xf605('0x47')]['ids'])[_0xf605('0x21')](function(){if(_[_0xf605('0x77')](_0x9144bb[_0xf605('0x47')][_0xf605('0x6f')])){for(var _0xbc15fc=0x0;_0xbc15fc<_0x9144bb[_0xf605('0x47')][_0xf605('0x6f')]['length'];_0xbc15fc+=0x1){socket[_0xf605('0x78')]('userWhatsappAccount:remove',{'UserId':Number(_0x9144bb[_0xf605('0x47')][_0xf605('0x6f')][_0xbc15fc]),'WhatsappAccountId':Number(_0x9144bb[_0xf605('0x5d')]['id'])});}}else{socket[_0xf605('0x78')](_0xf605('0x79'),{'UserId':Number(_0x9144bb['query']['ids']),'WhatsappAccountId':Number(_0x9144bb[_0xf605('0x5d')]['id'])});}});}})['then'](respondWithStatusCode(_0xc6d68d,null))[_0xf605('0x2b')](handleError(_0xc6d68d,null));};exports[_0xf605('0x7a')]=function(_0x109445,_0x571f11,_0x377acf){var _0x423039={};var _0x435c82={};var _0x3507fb;var _0xe2e82;return db[_0xf605('0x42')][_0xf605('0x6d')]({'where':{'id':_0x109445['params']['id']}})[_0xf605('0x21')](handleEntityNotFound(_0x571f11,null))['then'](function(_0x29084a){if(_0x29084a){_0x3507fb=_0x29084a;_0x435c82[_0xf605('0x46')]=_['keys'](db[_0xf605('0x7b')][_0xf605('0x43')]);_0x435c82['query']=_[_0xf605('0x48')](_0x109445['query']);_0x435c82[_0xf605('0x51')]=_[_0xf605('0x49')](_0x435c82[_0xf605('0x46')],_0x435c82['query']);_0x423039[_0xf605('0x4a')]=_[_0xf605('0x49')](_0x435c82['model'],qs['fields'](_0x109445[_0xf605('0x47')]['fields']));_0x423039[_0xf605('0x4a')]=_0x423039[_0xf605('0x4a')][_0xf605('0x4c')]?_0x423039[_0xf605('0x4a')]:_0x435c82[_0xf605('0x46')];_0x423039['order']=qs[_0xf605('0x50')](_0x109445[_0xf605('0x47')][_0xf605('0x50')]);_0x423039[_0xf605('0x54')]=qs[_0xf605('0x51')](_['pick'](_0x109445[_0xf605('0x47')],_0x435c82['filters']));if(_0x109445[_0xf605('0x47')]['filter']){_0x423039[_0xf605('0x54')]=_[_0xf605('0x55')](_0x423039[_0xf605('0x54')],{'$or':_[_0xf605('0x41')](_0x423039[_0xf605('0x4a')],function(_0x5b392d){var _0x57157d={};_0x57157d[_0x5b392d]={'$like':'%'+_0x109445[_0xf605('0x47')][_0xf605('0x53')]+'%'};return _0x57157d;})});}_0x423039=_[_0xf605('0x55')]({},_0x423039,_0x109445[_0xf605('0x58')]);return _0x3507fb[_0xf605('0x7a')](_0x423039);}})['then'](function(_0x2ac4c2){if(_0x2ac4c2){_0xe2e82=_0x2ac4c2[_0xf605('0x4c')];if(!_0x109445['query']['hasOwnProperty']('nolimit')){_0x423039[_0xf605('0x31')]=qs[_0xf605('0x31')](_0x109445['query'][_0xf605('0x31')]);_0x423039['offset']=qs['offset'](_0x109445[_0xf605('0x47')][_0xf605('0x33')]);}return _0x3507fb['getAgents'](_0x423039);}})[_0xf605('0x21')](function(_0x1fb3cd){if(_0x1fb3cd){return _0x1fb3cd?{'count':_0xe2e82,'rows':_0x1fb3cd}:null;}})[_0xf605('0x21')](respondWithResult(_0x571f11,null))[_0xf605('0x2b')](handleError(_0x571f11,null));};exports[_0xf605('0x7c')]=function(_0x1df99e,_0x286a3e){var _0x4b7506=_0x1df99e[_0xf605('0x5d')]['id'];var _0x67fbb0=_0x1df99e[_0xf605('0x61')];var _0x442beb=0xc8;var _0x19cca4=null;return db[_0xf605('0x7d')][_0xf605('0x7e')]({'isolationLevel':db[_0xf605('0x7d')][_0xf605('0x7f')][_0xf605('0x80')][_0xf605('0x81')]},function(_0x52a175){return db[_0xf605('0x42')][_0xf605('0x6d')]({'where':{'id':_0x4b7506},'transaction':_0x52a175})[_0xf605('0x21')](function(_0x537193){if(_0x537193){return db[_0xf605('0x82')][_0xf605('0x39')]({'where':{'WhatsappAccountId':_0x4b7506},'transaction':_0x52a175})['then'](function(){var _0x329ab5=_[_0xf605('0x41')](_0x67fbb0,function(_0x41e1ba){_0x41e1ba[_0xf605('0x6a')]=_0x4b7506;return _0x41e1ba;});return db[_0xf605('0x82')][_0xf605('0x83')](_0x329ab5,{'transaction':_0x52a175});});}else{_0x442beb=0x194;_0x19cca4=[];}});})[_0xf605('0x21')](function(){if(_0x442beb!==0x194){return db['WhatsappApplication'][_0xf605('0x84')]({'where':{'WhatsappAccountId':_0x4b7506},'order':'priority'})['then'](function(_0x1b4c8f){_0x19cca4=_0x1b4c8f;});}})[_0xf605('0x2b')](function(_0x318bc2){_0x442beb=0x1f4;logger['error'](_0x318bc2['stack']);if(_0x318bc2[_0xf605('0x3c')]){delete _0x318bc2[_0xf605('0x3c')];}_0x19cca4=_0x318bc2;})['finally'](function(){if(_0x19cca4===null){_0x286a3e[_0xf605('0x2c')](_0x442beb);}else{if(_0x442beb===0x1f4){_0x286a3e[_0xf605('0x2d')](_0x442beb)[_0xf605('0x3d')](_0x19cca4);}else{_0x286a3e[_0xf605('0x2d')](_0x442beb)[_0xf605('0x2f')](_0x19cca4);}}});};exports[_0xf605('0x85')]=function(_0x136076,_0x53d852,_0x548c9d){var _0x444471={};var _0x41b87a={};var _0x2bac65;var _0x1f4cf2;return db[_0xf605('0x42')]['findOne']({'where':{'id':_0x136076[_0xf605('0x5d')]['id']}})['then'](handleEntityNotFound(_0x53d852,null))[_0xf605('0x21')](function(_0x28956f){if(_0x28956f){_0x2bac65=_0x28956f;_0x41b87a[_0xf605('0x46')]=_[_0xf605('0x48')](db[_0xf605('0x82')][_0xf605('0x43')]);_0x41b87a[_0xf605('0x47')]=_[_0xf605('0x48')](_0x136076[_0xf605('0x47')]);_0x41b87a[_0xf605('0x51')]=_['intersection'](_0x41b87a[_0xf605('0x46')],_0x41b87a[_0xf605('0x47')]);_0x444471[_0xf605('0x4a')]=_[_0xf605('0x49')](_0x41b87a[_0xf605('0x46')],qs[_0xf605('0x4b')](_0x136076[_0xf605('0x47')][_0xf605('0x4b')]));_0x444471['attributes']=_0x444471[_0xf605('0x4a')]['length']?_0x444471[_0xf605('0x4a')]:_0x41b87a[_0xf605('0x46')];_0x444471['order']=qs['sort'](_0x136076[_0xf605('0x47')][_0xf605('0x50')]);_0x444471[_0xf605('0x54')]=qs[_0xf605('0x51')](_[_0xf605('0x52')](_0x136076[_0xf605('0x47')],_0x41b87a[_0xf605('0x51')]));if(_0x136076[_0xf605('0x47')][_0xf605('0x53')]){_0x444471[_0xf605('0x54')]=_[_0xf605('0x55')](_0x444471[_0xf605('0x54')],{'$or':_['map'](_0x444471[_0xf605('0x4a')],function(_0x31a198){var _0x2a2f24={};_0x2a2f24[_0x31a198]={'$like':'%'+_0x136076[_0xf605('0x47')]['filter']+'%'};return _0x2a2f24;})});}_0x444471=_[_0xf605('0x55')]({},_0x444471,_0x136076[_0xf605('0x58')]);return _0x2bac65[_0xf605('0x85')](_0x444471);}})['then'](function(_0x356e44){if(_0x356e44){_0x1f4cf2=_0x356e44[_0xf605('0x4c')];if(!_0x136076[_0xf605('0x47')][_0xf605('0x4d')]('nolimit')){_0x444471[_0xf605('0x31')]=qs[_0xf605('0x31')](_0x136076[_0xf605('0x47')][_0xf605('0x31')]);_0x444471['offset']=qs[_0xf605('0x33')](_0x136076[_0xf605('0x47')][_0xf605('0x33')]);}return _0x2bac65[_0xf605('0x85')](_0x444471);}})[_0xf605('0x21')](function(_0x4c4885){if(_0x4c4885){return _0x4c4885?{'count':_0x1f4cf2,'rows':_0x4c4885}:null;}})['then'](respondWithResult(_0x53d852,null))[_0xf605('0x2b')](handleError(_0x53d852,null));};exports['notify']=function(_0x3bf266,_0x281b36,_0x449ade){var _0x162597={'channel':_0xf605('0x86')};var _0x3cafc8=[];var _0x49deb1=[];var _0x1edcaa={};return db[_0xf605('0x42')][_0xf605('0x5f')]({'where':{'id':_0x3bf266['params']['id']},'include':[{'model':db[_0xf605('0x82')],'as':_0xf605('0x87')}]})['then'](handleEntityNotFound(_0x281b36,null))[_0xf605('0x21')](function(_0x4f12dd){_0x162597[_0xf605('0x88')]=_0x4f12dd;if(_0x162597[_0xf605('0x88')]&&_0x162597[_0xf605('0x88')][_0xf605('0x56')]===_0xf605('0x89')&&_0x3bf266[_0xf605('0x61')][_0xf605('0x8a')]){if(_0x3bf266['body'][_0xf605('0x8a')][_0xf605('0x4c')]===0x0)return;if(_0x3bf266['body'][_0xf605('0x8a')][0x0][_0xf605('0x8b')]!=='read')return;return db['WhatsappMessage'][_0xf605('0x8c')]({'read':!![],'readAt':_0x3bf266[_0xf605('0x61')][_0xf605('0x8a')][0x0][_0xf605('0x8d')]},{'where':{'messageId':_0x3bf266[_0xf605('0x61')][_0xf605('0x8a')][0x0]['message_id']},'individualHooks':!![]})[_0xf605('0x21')](function(_0x1447df){return _0x281b36[_0xf605('0x2d')](0xc8)[_0xf605('0x2f')](_0x1447df);});}_0x162597[_0xf605('0x8e')]=_[_0xf605('0x8f')](_0x4f12dd['Applications'],['priority'],['asc']);if(_0x162597[_0xf605('0x88')][_0xf605('0x87')]){delete _0x162597[_0xf605('0x88')][_0xf605('0x87')];}return db[_0xf605('0x90')][_0xf605('0x68')]()[_0xf605('0x21')](function(_0x144a75){if(!_0x144a75){throw new db['Sequelize'][(_0xf605('0x91'))](_0xf605('0x92'));}_0x3cafc8=_[_0xf605('0x93')](_[_0xf605('0x48')](_0x144a75),[_0xf605('0x94'),_0xf605('0x95')]);_0x49deb1=_['difference'](_[_0xf605('0x48')](_0x144a75),[_0xf605('0x94'),_0xf605('0x95'),_0xf605('0x96'),_0xf605('0x97')]);_0x162597['body']={'mapKey':'mobile'};if(_0x162597['account']&&_0x162597[_0xf605('0x88')][_0xf605('0x56')]==='twilio'){_0x162597['body']['from']=_0x3bf266[_0xf605('0x61')]['From'][_0xf605('0x98')](_0xf605('0x99'),'');_0x162597[_0xf605('0x61')][_0xf605('0x61')]=_0x3bf266[_0xf605('0x61')][_0xf605('0x9a')];_0x162597[_0xf605('0x61')]['messageId']=_0x3bf266[_0xf605('0x61')][_0xf605('0x9b')];}if(_0x162597[_0xf605('0x88')]&&_0x162597[_0xf605('0x88')][_0xf605('0x56')]==='sinch'){_0x162597['body'][_0xf605('0x9c')]=_0x3bf266[_0xf605('0x61')][_0xf605('0x9d')][0x0]['from'];_0x162597[_0xf605('0x61')][_0xf605('0x61')]=_0x3bf266[_0xf605('0x61')][_0xf605('0x9d')][0x0][_0xf605('0x29')][_0xf605('0x61')];_0x162597[_0xf605('0x61')]['messageId']=_0x3bf266[_0xf605('0x61')][_0xf605('0x9d')][0x0][_0xf605('0x9e')];}if(_0x162597[_0xf605('0x61')]['id']){delete _0x162597[_0xf605('0x61')]['id'];}if(_[_0xf605('0x9f')](_0x162597[_0xf605('0x61')][_0xf605('0x9c')])){throw new db[(_0xf605('0xa0'))][(_0xf605('0x91'))](_0xf605('0xa1'));}if(_['isNil'](_0x162597[_0xf605('0x61')][_0xf605('0x61')])||_0x162597[_0xf605('0x61')][_0xf605('0x61')]===''){throw new db['Sequelize']['ValidationError'](_0xf605('0xa2'));}if(_[_0xf605('0x9f')](_0x162597[_0xf605('0x61')][_0xf605('0xa3')])){throw new db['Sequelize'][(_0xf605('0x91'))](_0xf605('0xa4')+_0x49deb1);}if(!_[_0xf605('0xa5')](_0x49deb1,_0x162597[_0xf605('0x61')][_0xf605('0xa3')])){throw new db['Sequelize']['ValidationError'](_0xf605('0xa6')+_0x49deb1);}_0x1edcaa[_0x162597[_0xf605('0x61')]['mapKey']]=_0x162597['body'][_0xf605('0x9c')];return db[_0xf605('0xa7')]['find']({'where':{'id':_0x162597['account'][_0xf605('0x97')]},'include':[{'model':db['CmContact'],'as':_0xf605('0xa8'),'where':_0x1edcaa,'limit':0x1,'order':[[_0xf605('0x95'),_0xf605('0xa9')]]}]});})[_0xf605('0x21')](handleEntityNotFound(_0x281b36,null))[_0xf605('0x21')](function(_0x3c0f8c){if(_0x3c0f8c){_0x162597[_0xf605('0xaa')]=_[_0xf605('0xab')](_0x3c0f8c,[_0xf605('0xa8')]);if(_0x3c0f8c[_0xf605('0xa8')][_0xf605('0x4c')]){return _0x3c0f8c[_0xf605('0xa8')][0x0];}var _0x5eafa6=_[_0xf605('0x1b')](_0x162597[_0xf605('0x61')],{'firstName':_0x162597[_0xf605('0x61')]['from'],'ListId':_0x3c0f8c['id']});_0x5eafa6[_0x162597[_0xf605('0x61')][_0xf605('0xa3')]]=_0x162597[_0xf605('0x61')][_0xf605('0x9c')];return db[_0xf605('0x90')][_0xf605('0x60')](_0x5eafa6,{'fields':_0x3cafc8,'raw':!![]});}})['then'](handleEntityNotFound(_0x281b36,null))[_0xf605('0x21')](function(_0xc2bdab){if(_0xc2bdab){_0x162597[_0xf605('0xac')]=_0xc2bdab;var _0x30b638={'ContactId':_0xc2bdab['id'],'phone':_0x162597[_0xf605('0x61')]['from'],'WhatsappAccountId':_0x3bf266[_0xf605('0x5d')]['id']};var _0x208627={'ContactId':_0xc2bdab['id'],'WhatsappAccountId':_0x3bf266[_0xf605('0x5d')]['id'],'closed':![]};return db['WhatsappInteraction'][_0xf605('0x5f')]({'where':_0x208627})[_0xf605('0x21')](function(_0x81446a){if(_0x81446a){return[_0x81446a,![]];}return db['WhatsappInteraction'][_0xf605('0x60')](_0x30b638)[_0xf605('0x21')](function(_0x1a1f35){return[_0x1a1f35,!![]];});});}})[_0xf605('0x74')](function(_0x34c8b3,_0x219b60){_0x162597[_0xf605('0xad')]=_0x34c8b3[_0xf605('0x3a')]({'plain':!![]});_0x162597[_0xf605('0xad')][_0xf605('0xae')]=![];if(_0x219b60){if(_0x162597[_0xf605('0x88')][_0xf605('0xaf')]){_0x162597[_0xf605('0x8e')][_0xf605('0xb0')]({'id':0x0,'priority':_0x162597[_0xf605('0x8e')][_0xf605('0x4c')]+0x1,'app':_0xf605('0xb1'),'appdata':_0xf605('0xb2'),'interval':_0xf605('0xb3')});}_0x162597['interaction'][_0xf605('0xae')]=!![];}return db['WhatsappMessage']['create']({'phone':_0x162597[_0xf605('0x61')]['from'],'messageId':_0x162597[_0xf605('0x61')][_0xf605('0xb4')],'body':_0x162597[_0xf605('0x61')][_0xf605('0x61')],'WhatsappAccountId':_0x3bf266[_0xf605('0x5d')]['id'],'WhatsappInteractionId':_0x34c8b3['id'],'direction':'in','ContactId':_0x34c8b3['ContactId'],'AttachmentId':_0x162597[_0xf605('0x61')]['AttachmentId']});})[_0xf605('0x21')](function(_0x2c7d4e){_0x162597['message']=_0x2c7d4e;if(!_0x162597['interaction'][_0xf605('0xb5')])return;return db[_0xf605('0x7b')][_0xf605('0x5f')]({'attributes':['id',_0xf605('0x3c')],'where':{'id':_0x162597[_0xf605('0xad')][_0xf605('0xb5')]}});})['then'](function(_0x3f9b0d){if(_0x3f9b0d){_0x162597[_0xf605('0x8e')]['unshift']({'id':0x0,'priority':0x0,'app':_0xf605('0xb6'),'appdata':_0x3f9b0d[_0xf605('0x3c')]+','+(_0x162597[_0xf605('0x88')][_0xf605('0xb7')]||0xa),'interval':_0xf605('0xb3')});}if(!_0x162597['interaction'][_0xf605('0xb8')])return;return db[_0xf605('0xb9')][_0xf605('0x5f')]({'attributes':['id',_0xf605('0x3c')],'where':{'id':_0x162597[_0xf605('0xad')][_0xf605('0xb8')]}});})[_0xf605('0x21')](function(_0x37a948){if(_0x37a948){_0x162597[_0xf605('0x8e')][_0xf605('0xba')]({'id':0x0,'priority':0x1,'app':_0xf605('0xbb'),'appdata':_0x37a948[_0xf605('0x3c')]+','+(_0x162597['account']['waitForTheAssignedQueue']||0x12c),'interval':_0xf605('0xb3')});}return respondWithRpcPromise(_0xf605('0xbc'),_0xf605('0xbd'),_0x162597);})[_0xf605('0x21')](function(_0x348f28){if(_0x348f28){var _0x480182=0xc8;var _0x55f5a4=_0xf605('0xbe');logger[_0xf605('0x22')]('WhatsappAccount,\x20%s,\x20%s,\x20%s',_0x55f5a4,_0x480182,_0xf605('0xbf'));logger['debug'](_0xf605('0xc0'),_0x55f5a4,_0x480182,_0xf605('0xbf'),JSON[_0xf605('0x25')](_0x348f28));if(_0x162597['account'][_0xf605('0x56')]===_0xf605('0xc1')){return _0x281b36['status'](_0x480182)[_0xf605('0x34')](_0xf605('0xc2'),_0xf605('0xc3'))[_0xf605('0x3d')](_0xf605('0xc4'));}else{return _0x281b36[_0xf605('0x2d')](_0x480182)[_0xf605('0x2f')](_0x348f28);}}});})[_0xf605('0x2b')](handleError(_0x281b36,null));};exports['send']=function(_0x1924b9,_0x1971fa,_0x3cfd86){var _0x422834,_0x336143,_0x47d077;if(_[_0xf605('0x9f')](_0x1924b9[_0xf605('0x61')]['body'])||_0x1924b9[_0xf605('0x61')]['body']===''){throw new db[(_0xf605('0xa0'))][(_0xf605('0x91'))](_0xf605('0xa2'));}if(_['isNil'](_0x1924b9[_0xf605('0x61')]['to'])){throw new db[(_0xf605('0xa0'))]['ValidationError'](_0xf605('0xc5'));}_0x422834=_0x1924b9[_0xf605('0x61')]['to'];return db['WhatsappAccount'][_0xf605('0x5f')]({'where':{'id':_0x1924b9[_0xf605('0x5d')]['id']},'include':[{'model':db[_0xf605('0xa7')],'as':_0xf605('0xc6'),'include':[{'model':db[_0xf605('0x90')],'as':_0xf605('0xa8'),'where':{'mobile':_0x422834},'limit':0x1,'order':[[_0xf605('0x95'),_0xf605('0xa9')]]}]}]})[_0xf605('0x21')](handleEntityNotFound(_0x1971fa,null))['then'](function(_0x580450){if(_0x580450&&_0x580450[_0xf605('0xc6')]){_0x336143=_0x580450[_0xf605('0x3a')]({'plain':!![]});if(_0x336143[_0xf605('0xc6')]&&_0x336143[_0xf605('0xc6')][_0xf605('0xa8')]['length']){return _0x336143[_0xf605('0xc6')][_0xf605('0xa8')][0x0];}return db[_0xf605('0x90')][_0xf605('0x60')](_[_0xf605('0x1b')](_0x1924b9[_0xf605('0x61')],{'firstName':_0x422834,'mobile':_0x422834,'phone':_0x422834,'ListId':_0x336143['ListId']}));}})[_0xf605('0x21')](handleEntityNotFound(_0x1971fa,null))[_0xf605('0x21')](function(_0x34b95c){if(_0x34b95c){_0x47d077=_0x34b95c;return db[_0xf605('0xc7')]['find']({'where':{'ContactId':_0x47d077['id'],'closed':![],'WhatsappAccountId':_0x336143['id']}})[_0xf605('0x21')](function(_0xd917d0){if(_0xd917d0){return[_0xd917d0,![]];}return db[_0xf605('0xc7')]['create']({'UserId':_0x1924b9[_0xf605('0x63')]['id'],'ContactId':_0x47d077['id'],'WhatsappAccountId':_0x336143['id'],'phone':_0x422834,'firstMsgDirection':_0xf605('0xc8'),'Messages':[_[_0xf605('0x55')](_0x1924b9[_0xf605('0x61')],{'read':![],'body':_0x1924b9['body']['body'],'phone':_0x422834,'WhatsappAccountId':_0x336143['id'],'UserId':_0x1924b9[_0xf605('0x63')]['id'],'ContactId':_0x47d077['id']})]},{'include':[{'model':db[_0xf605('0xc9')],'as':_0xf605('0xca')}]})['then'](function(_0x44f9e2){return[_0x44f9e2,!![]];});});}})[_0xf605('0x74')](function(_0x32e19,_0x21c100){if(_0x21c100){return _0x32e19;}return db['WhatsappMessage'][_0xf605('0x60')](_[_0xf605('0x55')](_0x1924b9[_0xf605('0x61')],{'read':![],'body':_0x1924b9[_0xf605('0x61')]['body'],'phone':_0x422834,'WhatsappAccountId':_0x336143['id'],'WhatsappInteractionId':_0x32e19['id'],'UserId':_0x1924b9[_0xf605('0x63')]['id'],'ContactId':_0x47d077['id']}))[_0xf605('0x21')](function(_0x26b59e){_0x32e19['dataValues']['Messages']=[];_0x32e19[_0xf605('0xcb')]['Messages'][_0xf605('0xb0')](_0x26b59e[_0xf605('0xcb')]);return _0x32e19;});})[_0xf605('0x21')](respondWithResult(_0x1971fa,null))[_0xf605('0x2b')](handleError(_0x1971fa,null));};
\ No newline at end of file