9a9ff1a90184b0513665c18a91e3eea9e2c84e09
[motion2.git] / server / api / whatsappAccount / whatsappAccount.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x7bb9=['isArray','userWhatsappAccount:remove','getAgents','User','transaction','sequelize','Transaction','ISOLATION_LEVELS','READ_COMMITTED','WhatsappApplication','bulkCreate','findAndCountAll','priority','finally','getApplications','notify','whatsapp','Applications','account','sinch','statuses','state','read','WhatsappMessage','message_id','applications','orderBy','asc','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','mobile','twilio','From','replace','whatsapp:','Body','MessageSid','from','notifications','from\x20is\x20mandatory','isNil','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','list','Contacts','contact','WhatsappInteraction','interaction','created','autoclose','push','unmanaged','AttachmentId','unshift','agent','waitForTheAssignedAgent','*,*,*,*','queueId','WhatsappQueue','queue','waitForTheAssignedQueue','Start','startRouting','entity\x20found','WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s','set','text/xml','DESC','List','out','dataValues','Messages','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./whatsappAccount.socket','register','jayson/promise','client','http','request','then','info','WhatsappAccount,\x20%s,\x20%s','request\x20sent','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','sendStatus','end','status','json','limit','undefined','count','offset','Content-Range','apply','save','update','destroy','get','WhatsappAccounts','UserProfileResource','stack','name','send','index','Pause','mandatoryDispositionPause','map','WhatsappAccount','rawAttributes','type','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filter','VIRTUAL','merge','options','includeAll','findAll','rows','params','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','describe','addDisposition','WhatsappAccountId','Disposition','findOne','pick','include','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','addAgents','omit','spread','emit','userWhatsappAccount:save','removeAgents'];(function(_0x35d4e9,_0x298c61){var _0x5c2770=function(_0x2f326a){while(--_0x2f326a){_0x35d4e9['push'](_0x35d4e9['shift']());}};_0x5c2770(++_0x298c61);}(_0x7bb9,0x1eb));var _0x97bb=function(_0x1ccdf7,_0x215d5a){_0x1ccdf7=_0x1ccdf7-0x0;var _0x52a0ae=_0x7bb9[_0x1ccdf7];return _0x52a0ae;};'use strict';var emlformat=require(_0x97bb('0x0'));var rimraf=require(_0x97bb('0x1'));var zipdir=require(_0x97bb('0x2'));var jsonpatch=require(_0x97bb('0x3'));var rp=require(_0x97bb('0x4'));var moment=require('moment');var BPromise=require(_0x97bb('0x5'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0x97bb('0x6'));var csv=require(_0x97bb('0x7'));var ejs=require(_0x97bb('0x8'));var fs=require('fs');var fs_extra=require(_0x97bb('0x9'));var _=require(_0x97bb('0xa'));var squel=require(_0x97bb('0xb'));var crypto=require(_0x97bb('0xc'));var jsforce=require(_0x97bb('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x97bb('0x7'));var querystring=require(_0x97bb('0xe'));var Papa=require(_0x97bb('0xf'));var Redis=require(_0x97bb('0x10'));var authService=require(_0x97bb('0x11'));var qs=require(_0x97bb('0x12'));var as=require(_0x97bb('0x13'));var hardwareService=require(_0x97bb('0x14'));var logger=require(_0x97bb('0x15'))(_0x97bb('0x16'));var utils=require(_0x97bb('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0x97bb('0x18'));var db=require('../../mysqldb')['db'];config[_0x97bb('0x19')]=_[_0x97bb('0x1a')](config[_0x97bb('0x19')],{'host':_0x97bb('0x1b'),'port':0x18eb});var socket=require(_0x97bb('0x1c'))(new Redis(config[_0x97bb('0x19')]));require(_0x97bb('0x1d'))[_0x97bb('0x1e')](socket);var jayson=require(_0x97bb('0x1f'));var client=jayson[_0x97bb('0x20')][_0x97bb('0x21')]({'port':0x232c});function respondWithRpcPromise(_0x1daffb,_0x3d63f2,_0x5dbbd9,_0x149bfe){return new BPromise(function(_0x308a77,_0x4f8506){var _0x101741=_0x149bfe||client;return _0x101741[_0x97bb('0x22')](_0x1daffb,_0x5dbbd9)[_0x97bb('0x23')](function(_0x33bcfb){logger[_0x97bb('0x24')](_0x97bb('0x25'),_0x3d63f2,_0x97bb('0x26'));logger[_0x97bb('0x27')](_0x97bb('0x28'),_0x3d63f2,_0x97bb('0x26'),JSON[_0x97bb('0x29')](_0x33bcfb));if(_0x33bcfb[_0x97bb('0x2a')]){if(_0x33bcfb[_0x97bb('0x2a')]['code']===0x1f4){logger[_0x97bb('0x2a')](_0x97bb('0x25'),_0x3d63f2,_0x33bcfb[_0x97bb('0x2a')][_0x97bb('0x2b')]);return _0x4f8506(_0x33bcfb[_0x97bb('0x2a')][_0x97bb('0x2b')]);}logger[_0x97bb('0x2a')](_0x97bb('0x25'),_0x3d63f2,_0x33bcfb[_0x97bb('0x2a')]['message']);return _0x308a77(_0x33bcfb[_0x97bb('0x2a')][_0x97bb('0x2b')]);}else{logger[_0x97bb('0x24')](_0x97bb('0x25'),_0x3d63f2,_0x97bb('0x26'));_0x308a77(_0x33bcfb[_0x97bb('0x2c')]['message']);}})[_0x97bb('0x2d')](function(_0x3a55b4){logger[_0x97bb('0x2a')]('WhatsappAccount,\x20%s,\x20%s',_0x3d63f2,_0x3a55b4);_0x4f8506(_0x3a55b4);});});}function respondWithStatusCode(_0x4d7ecd,_0x4e4701){_0x4e4701=_0x4e4701||0xcc;return function(_0x38e7a4){if(_0x38e7a4){return _0x4d7ecd[_0x97bb('0x2e')](_0x4e4701);}return _0x4d7ecd['status'](_0x4e4701)[_0x97bb('0x2f')]();};}function respondWithResult(_0x4d5c06,_0x5768d3){_0x5768d3=_0x5768d3||0xc8;return function(_0x46f90e){if(_0x46f90e){return _0x4d5c06[_0x97bb('0x30')](_0x5768d3)[_0x97bb('0x31')](_0x46f90e);}};}function respondWithFilteredResult(_0x2ed467,_0x49b4aa){return function(_0x2c1d70){if(_0x2c1d70){var _0xe3aa4e=typeof _0x49b4aa['offset']==='undefined'&&typeof _0x49b4aa[_0x97bb('0x32')]===_0x97bb('0x33');var _0x11e872=_0x2c1d70[_0x97bb('0x34')];var _0x1fc0d0=_0xe3aa4e?0x0:_0x49b4aa[_0x97bb('0x35')];var _0x294504=_0xe3aa4e?_0x2c1d70[_0x97bb('0x34')]:_0x49b4aa['offset']+_0x49b4aa[_0x97bb('0x32')];var _0x5cd733;if(_0x294504>=_0x11e872){_0x294504=_0x11e872;_0x5cd733=0xc8;}else{_0x5cd733=0xce;}_0x2ed467['status'](_0x5cd733);return _0x2ed467['set'](_0x97bb('0x36'),_0x1fc0d0+'-'+_0x294504+'/'+_0x11e872)[_0x97bb('0x31')](_0x2c1d70);}return null;};}function patchUpdates(_0x53cc9f){return function(_0x47fea0){try{jsonpatch[_0x97bb('0x37')](_0x47fea0,_0x53cc9f,!![]);}catch(_0x51b34e){return BPromise['reject'](_0x51b34e);}return _0x47fea0[_0x97bb('0x38')]();};}function saveUpdates(_0x5211ac,_0x1f135e){return function(_0x506af1){if(_0x506af1){return _0x506af1[_0x97bb('0x39')](_0x5211ac)[_0x97bb('0x23')](function(_0x44ca59){return _0x44ca59;});}return null;};}function removeEntity(_0xa524f2,_0x1c64c9){return function(_0x1baf65){if(_0x1baf65){return _0x1baf65[_0x97bb('0x3a')]()[_0x97bb('0x23')](function(){var _0x4d626c=_0x1baf65[_0x97bb('0x3b')]({'plain':!![]});var _0x28c0e4=_0x97bb('0x3c');return db[_0x97bb('0x3d')][_0x97bb('0x3a')]({'where':{'type':_0x28c0e4,'resourceId':_0x4d626c['id']}})[_0x97bb('0x23')](function(){return _0x1baf65;});})['then'](function(){_0xa524f2['status'](0xcc)[_0x97bb('0x2f')]();});}};}function handleEntityNotFound(_0x4f60d6,_0x49d45c){return function(_0x2686e1){if(!_0x2686e1){_0x4f60d6[_0x97bb('0x2e')](0x194);}return _0x2686e1;};}function handleError(_0xf96aa8,_0x27830c){_0x27830c=_0x27830c||0x1f4;return function(_0x243977){logger[_0x97bb('0x2a')](_0x243977[_0x97bb('0x3e')]);if(_0x243977[_0x97bb('0x3f')]){delete _0x243977[_0x97bb('0x3f')];}_0xf96aa8[_0x97bb('0x30')](_0x27830c)[_0x97bb('0x40')](_0x243977);};}exports[_0x97bb('0x41')]=function(_0x2888a5,_0x22d591){var _0x4e332e={'include':[{'model':db[_0x97bb('0x42')],'as':_0x97bb('0x43')}]},_0x554311={},_0x11b202={'count':0x0,'rows':[]};var _0x277987=_[_0x97bb('0x44')](db[_0x97bb('0x45')][_0x97bb('0x46')],function(_0x31fa26){return{'name':_0x31fa26['fieldName'],'type':_0x31fa26[_0x97bb('0x47')]['key']};});_0x554311[_0x97bb('0x48')]=_[_0x97bb('0x44')](_0x277987,_0x97bb('0x3f'));_0x554311[_0x97bb('0x49')]=_[_0x97bb('0x4a')](_0x2888a5[_0x97bb('0x49')]);_0x554311[_0x97bb('0x4b')]=_[_0x97bb('0x4c')](_0x554311[_0x97bb('0x48')],_0x554311['query']);_0x4e332e[_0x97bb('0x4d')]=_['intersection'](_0x554311['model'],qs[_0x97bb('0x4e')](_0x2888a5['query']['fields']));_0x4e332e['attributes']=_0x4e332e[_0x97bb('0x4d')][_0x97bb('0x4f')]?_0x4e332e['attributes']:_0x554311[_0x97bb('0x48')];if(!_0x2888a5[_0x97bb('0x49')][_0x97bb('0x50')](_0x97bb('0x51'))){_0x4e332e[_0x97bb('0x32')]=qs[_0x97bb('0x32')](_0x2888a5[_0x97bb('0x49')][_0x97bb('0x32')]);_0x4e332e[_0x97bb('0x35')]=qs[_0x97bb('0x35')](_0x2888a5[_0x97bb('0x49')][_0x97bb('0x35')]);}_0x4e332e[_0x97bb('0x52')]=qs['sort'](_0x2888a5[_0x97bb('0x49')][_0x97bb('0x53')]);_0x4e332e[_0x97bb('0x54')]=qs[_0x97bb('0x4b')](_['pick'](_0x2888a5[_0x97bb('0x49')],_0x554311[_0x97bb('0x4b')]),_0x277987);if(_0x2888a5[_0x97bb('0x49')][_0x97bb('0x55')]){_0x4e332e[_0x97bb('0x54')]=_['merge'](_0x4e332e[_0x97bb('0x54')],{'$or':_[_0x97bb('0x44')](_0x277987,function(_0x3d10ef){if(_0x3d10ef['type']!==_0x97bb('0x56')){var _0x375ac0={};_0x375ac0[_0x3d10ef[_0x97bb('0x3f')]]={'$like':'%'+_0x2888a5['query']['filter']+'%'};return _0x375ac0;}})});}_0x4e332e=_[_0x97bb('0x57')]({},_0x4e332e,_0x2888a5[_0x97bb('0x58')]);var _0x4376b1={'where':_0x4e332e['where']};return db[_0x97bb('0x45')][_0x97bb('0x34')](_0x4376b1)['then'](function(_0x271053){_0x11b202['count']=_0x271053;if(_0x2888a5[_0x97bb('0x49')][_0x97bb('0x59')]){_0x4e332e['include']=[{'all':!![]}];}return db[_0x97bb('0x45')][_0x97bb('0x5a')](_0x4e332e);})[_0x97bb('0x23')](function(_0x36274f){_0x11b202[_0x97bb('0x5b')]=_0x36274f;return _0x11b202;})[_0x97bb('0x23')](respondWithFilteredResult(_0x22d591,_0x4e332e))[_0x97bb('0x2d')](handleError(_0x22d591,null));};exports['show']=function(_0x5b399b,_0x353866){var _0x4ce6b8={'raw':![],'where':{'id':_0x5b399b[_0x97bb('0x5c')]['id']},'include':[{'model':db[_0x97bb('0x42')],'as':'mandatoryDispositionPause'}]},_0x3031d0={};_0x3031d0[_0x97bb('0x48')]=_['keys'](db[_0x97bb('0x45')][_0x97bb('0x46')]);_0x3031d0[_0x97bb('0x49')]=_[_0x97bb('0x4a')](_0x5b399b[_0x97bb('0x49')]);_0x3031d0[_0x97bb('0x4b')]=_[_0x97bb('0x4c')](_0x3031d0['model'],_0x3031d0[_0x97bb('0x49')]);_0x4ce6b8[_0x97bb('0x4d')]=_[_0x97bb('0x4c')](_0x3031d0[_0x97bb('0x48')],qs[_0x97bb('0x4e')](_0x5b399b[_0x97bb('0x49')][_0x97bb('0x4e')]));_0x4ce6b8[_0x97bb('0x4d')]=_0x4ce6b8[_0x97bb('0x4d')][_0x97bb('0x4f')]?_0x4ce6b8[_0x97bb('0x4d')]:_0x3031d0[_0x97bb('0x48')];if(_0x5b399b[_0x97bb('0x49')]['includeAll']){_0x4ce6b8['include']=[{'all':!![]}];}_0x4ce6b8=_['merge']({},_0x4ce6b8,_0x5b399b[_0x97bb('0x58')]);return db[_0x97bb('0x45')][_0x97bb('0x5d')](_0x4ce6b8)[_0x97bb('0x23')](handleEntityNotFound(_0x353866,null))[_0x97bb('0x23')](respondWithResult(_0x353866,null))['catch'](handleError(_0x353866,null));};exports[_0x97bb('0x5e')]=function(_0x13f2c9,_0x301d23){return db[_0x97bb('0x45')][_0x97bb('0x5e')](_0x13f2c9[_0x97bb('0x5f')],{})['then'](function(_0x12c307){var _0x5da80a=_0x13f2c9[_0x97bb('0x60')][_0x97bb('0x3b')]({'plain':!![]});if(!_0x5da80a)throw new Error(_0x97bb('0x61'));if(_0x5da80a[_0x97bb('0x62')]===_0x97bb('0x60')){var _0x145a12=_0x12c307[_0x97bb('0x3b')]({'plain':!![]});var _0x10a637='WhatsappAccounts';return db[_0x97bb('0x63')]['find']({'where':{'name':_0x10a637,'userProfileId':_0x5da80a[_0x97bb('0x64')]},'raw':!![]})['then'](function(_0x381417){if(_0x381417&&_0x381417[_0x97bb('0x65')]===0x0){return db[_0x97bb('0x3d')][_0x97bb('0x5e')]({'name':_0x145a12[_0x97bb('0x3f')],'resourceId':_0x145a12['id'],'type':_0x381417[_0x97bb('0x3f')],'sectionId':_0x381417['id']},{})[_0x97bb('0x23')](function(){return _0x12c307;});}else{return _0x12c307;}})[_0x97bb('0x2d')](function(_0x4ffdc6){logger[_0x97bb('0x2a')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x4ffdc6);throw _0x4ffdc6;});}return _0x12c307;})[_0x97bb('0x23')](respondWithResult(_0x301d23,0xc9))[_0x97bb('0x2d')](handleError(_0x301d23,null));};exports[_0x97bb('0x39')]=function(_0x251c5a,_0x44d1d4){if(_0x251c5a[_0x97bb('0x5f')]['id']){delete _0x251c5a[_0x97bb('0x5f')]['id'];}return db[_0x97bb('0x45')][_0x97bb('0x5d')]({'where':{'id':_0x251c5a[_0x97bb('0x5c')]['id']},'include':[{'model':db['Pause'],'as':_0x97bb('0x43')}]})[_0x97bb('0x23')](handleEntityNotFound(_0x44d1d4,null))['then'](saveUpdates(_0x251c5a[_0x97bb('0x5f')],null))[_0x97bb('0x23')](respondWithResult(_0x44d1d4,null))[_0x97bb('0x2d')](handleError(_0x44d1d4,null));};exports[_0x97bb('0x3a')]=function(_0x461628,_0x26dac4){return db[_0x97bb('0x45')][_0x97bb('0x5d')]({'where':{'id':_0x461628[_0x97bb('0x5c')]['id']}})[_0x97bb('0x23')](handleEntityNotFound(_0x26dac4,null))[_0x97bb('0x23')](removeEntity(_0x26dac4,null))[_0x97bb('0x2d')](handleError(_0x26dac4,null));};exports[_0x97bb('0x66')]=function(_0x441c1f,_0x310d5a){return db[_0x97bb('0x45')]['describe']()['then'](respondWithResult(_0x310d5a,null))[_0x97bb('0x2d')](handleError(_0x310d5a,null));};exports[_0x97bb('0x67')]=function(_0x5c2489,_0x946eb2,_0x1ee1f6){if(_0x5c2489['body']['id']){delete _0x5c2489['body']['id'];}return db[_0x97bb('0x45')]['find']({'where':{'id':_0x5c2489[_0x97bb('0x5c')]['id']}})[_0x97bb('0x23')](handleEntityNotFound(_0x946eb2,null))[_0x97bb('0x23')](function(_0x244cb8){if(_0x244cb8){_0x5c2489[_0x97bb('0x5f')][_0x97bb('0x68')]=_0x244cb8['id'];return db[_0x97bb('0x69')][_0x97bb('0x5e')](_0x5c2489[_0x97bb('0x5f')]);}})[_0x97bb('0x23')](respondWithResult(_0x946eb2,null))[_0x97bb('0x2d')](handleError(_0x946eb2,null));};exports['getDispositions']=function(_0x54aea7,_0xf1478a,_0x395175){var _0x338b75={'raw':![],'where':{}};var _0x3fffdf={};var _0x8d9838={'count':0x0,'rows':[]};return db[_0x97bb('0x45')][_0x97bb('0x6a')]({'where':{'id':_0x54aea7['params']['id']}})['then'](handleEntityNotFound(_0xf1478a,null))[_0x97bb('0x23')](function(_0x809746){if(_0x809746){_0x3fffdf[_0x97bb('0x48')]=_['keys'](db[_0x97bb('0x69')][_0x97bb('0x46')]);_0x3fffdf['query']=_['keys'](_0x54aea7[_0x97bb('0x49')]);_0x3fffdf[_0x97bb('0x4b')]=_[_0x97bb('0x4c')](_0x3fffdf['model'],_0x3fffdf['query']);_0x338b75[_0x97bb('0x4d')]=_[_0x97bb('0x4c')](_0x3fffdf[_0x97bb('0x48')],qs['fields'](_0x54aea7[_0x97bb('0x49')][_0x97bb('0x4e')]));_0x338b75[_0x97bb('0x4d')]=_0x338b75['attributes'][_0x97bb('0x4f')]?_0x338b75[_0x97bb('0x4d')]:_0x3fffdf['model'];if(!_0x54aea7[_0x97bb('0x49')]['hasOwnProperty']('nolimit')){_0x338b75[_0x97bb('0x32')]=qs[_0x97bb('0x32')](_0x54aea7[_0x97bb('0x49')][_0x97bb('0x32')]);_0x338b75[_0x97bb('0x35')]=qs[_0x97bb('0x35')](_0x54aea7[_0x97bb('0x49')][_0x97bb('0x35')]);}_0x338b75['order']=qs['sort'](_0x54aea7[_0x97bb('0x49')]['sort']);_0x338b75['where']=qs[_0x97bb('0x4b')](_[_0x97bb('0x6b')](_0x54aea7[_0x97bb('0x49')],_0x3fffdf[_0x97bb('0x4b')]));_0x338b75['where'][_0x97bb('0x68')]=_0x809746['id'];if(_0x54aea7[_0x97bb('0x49')]['filter']){_0x338b75[_0x97bb('0x54')]=_[_0x97bb('0x57')](_0x338b75[_0x97bb('0x54')],{'$or':_['map'](_0x338b75[_0x97bb('0x4d')],function(_0x5f01a0){var _0x3227f5={};_0x3227f5[_0x5f01a0]={'$like':'%'+_0x54aea7['query'][_0x97bb('0x55')]+'%'};return _0x3227f5;})});}_0x338b75=_[_0x97bb('0x57')]({},_0x338b75,_0x54aea7[_0x97bb('0x58')]);return db[_0x97bb('0x69')][_0x97bb('0x34')]({'where':_0x338b75[_0x97bb('0x54')]})[_0x97bb('0x23')](function(_0x39d58e){_0x8d9838[_0x97bb('0x34')]=_0x39d58e;if(_0x54aea7[_0x97bb('0x49')][_0x97bb('0x59')]){_0x338b75[_0x97bb('0x6c')]=[{'all':!![]}];}return db['Disposition'][_0x97bb('0x5a')](_0x338b75);})[_0x97bb('0x23')](function(_0xf29d90){_0x8d9838[_0x97bb('0x5b')]=_0xf29d90;return _0x8d9838;});}})[_0x97bb('0x23')](respondWithFilteredResult(_0xf1478a,_0x338b75))[_0x97bb('0x2d')](handleError(_0xf1478a,null));};exports[_0x97bb('0x6d')]=function(_0x14b1cd,_0x181cf1,_0x5be8e0){return db[_0x97bb('0x45')][_0x97bb('0x5d')]({'where':{'id':_0x14b1cd[_0x97bb('0x5c')]['id']}})[_0x97bb('0x23')](handleEntityNotFound(_0x181cf1,null))[_0x97bb('0x23')](function(_0x5c18fc){if(_0x5c18fc){return _0x5c18fc[_0x97bb('0x6d')](_0x14b1cd[_0x97bb('0x49')][_0x97bb('0x6e')]);}})[_0x97bb('0x23')](respondWithStatusCode(_0x181cf1,null))[_0x97bb('0x2d')](handleError(_0x181cf1,null));};exports[_0x97bb('0x6f')]=function(_0x3e373a,_0x2fbb8d,_0x4cc100){if(_0x3e373a[_0x97bb('0x5f')]['id']){delete _0x3e373a['body']['id'];}return db[_0x97bb('0x45')][_0x97bb('0x5d')]({'where':{'id':_0x3e373a[_0x97bb('0x5c')]['id']}})['then'](handleEntityNotFound(_0x2fbb8d,null))[_0x97bb('0x23')](function(_0x24683f){if(_0x24683f){_0x3e373a['body'][_0x97bb('0x68')]=_0x24683f['id'];return db[_0x97bb('0x70')][_0x97bb('0x5e')](_0x3e373a[_0x97bb('0x5f')]);}})[_0x97bb('0x23')](respondWithResult(_0x2fbb8d,null))['catch'](handleError(_0x2fbb8d,null));};exports[_0x97bb('0x71')]=function(_0x288e12,_0x535a66,_0xc55d67){var _0x1e532a={'raw':![],'where':{}};var _0x2023ad={};var _0x451cb1={'count':0x0,'rows':[]};return db['WhatsappAccount'][_0x97bb('0x6a')]({'where':{'id':_0x288e12[_0x97bb('0x5c')]['id']}})[_0x97bb('0x23')](handleEntityNotFound(_0x535a66,null))[_0x97bb('0x23')](function(_0xe9d971){if(_0xe9d971){_0x2023ad['model']=_['keys'](db[_0x97bb('0x70')][_0x97bb('0x46')]);_0x2023ad[_0x97bb('0x49')]=_[_0x97bb('0x4a')](_0x288e12[_0x97bb('0x49')]);_0x2023ad['filters']=_[_0x97bb('0x4c')](_0x2023ad[_0x97bb('0x48')],_0x2023ad[_0x97bb('0x49')]);_0x1e532a['attributes']=_[_0x97bb('0x4c')](_0x2023ad[_0x97bb('0x48')],qs[_0x97bb('0x4e')](_0x288e12[_0x97bb('0x49')][_0x97bb('0x4e')]));_0x1e532a['attributes']=_0x1e532a[_0x97bb('0x4d')][_0x97bb('0x4f')]?_0x1e532a[_0x97bb('0x4d')]:_0x2023ad[_0x97bb('0x48')];if(!_0x288e12[_0x97bb('0x49')][_0x97bb('0x50')](_0x97bb('0x51'))){_0x1e532a[_0x97bb('0x32')]=qs['limit'](_0x288e12[_0x97bb('0x49')][_0x97bb('0x32')]);_0x1e532a[_0x97bb('0x35')]=qs[_0x97bb('0x35')](_0x288e12['query']['offset']);}_0x1e532a[_0x97bb('0x52')]=qs['sort'](_0x288e12['query']['sort']);_0x1e532a[_0x97bb('0x54')]=qs[_0x97bb('0x4b')](_[_0x97bb('0x6b')](_0x288e12[_0x97bb('0x49')],_0x2023ad[_0x97bb('0x4b')]));_0x1e532a[_0x97bb('0x54')]['WhatsappAccountId']=_0xe9d971['id'];if(_0x288e12['query'][_0x97bb('0x55')]){_0x1e532a[_0x97bb('0x54')]=_[_0x97bb('0x57')](_0x1e532a['where'],{'$or':_[_0x97bb('0x44')](_0x1e532a[_0x97bb('0x4d')],function(_0x534c60){var _0x44cfe8={};_0x44cfe8[_0x534c60]={'$like':'%'+_0x288e12[_0x97bb('0x49')][_0x97bb('0x55')]+'%'};return _0x44cfe8;})});}_0x1e532a=_[_0x97bb('0x57')]({},_0x1e532a,_0x288e12[_0x97bb('0x58')]);return db[_0x97bb('0x70')]['count']({'where':_0x1e532a[_0x97bb('0x54')]})[_0x97bb('0x23')](function(_0x2b040d){_0x451cb1[_0x97bb('0x34')]=_0x2b040d;if(_0x288e12[_0x97bb('0x49')][_0x97bb('0x59')]){_0x1e532a[_0x97bb('0x6c')]=[{'all':!![]}];}return db['CannedAnswer']['findAll'](_0x1e532a);})['then'](function(_0x3d800b){_0x451cb1['rows']=_0x3d800b;return _0x451cb1;});}})[_0x97bb('0x23')](respondWithFilteredResult(_0x535a66,_0x1e532a))[_0x97bb('0x2d')](handleError(_0x535a66,null));};exports['removeAnswers']=function(_0x58bf0b,_0x3a2399,_0x303818){return db[_0x97bb('0x45')][_0x97bb('0x5d')]({'where':{'id':_0x58bf0b['params']['id']}})[_0x97bb('0x23')](handleEntityNotFound(_0x3a2399,null))[_0x97bb('0x23')](function(_0x571d18){if(_0x571d18){return _0x571d18[_0x97bb('0x72')](_0x58bf0b[_0x97bb('0x49')][_0x97bb('0x6e')]);}})[_0x97bb('0x23')](respondWithStatusCode(_0x3a2399,null))[_0x97bb('0x2d')](handleError(_0x3a2399,null));};exports[_0x97bb('0x73')]=function(_0x5a8b81,_0x503300,_0xd5aab4){return db[_0x97bb('0x45')][_0x97bb('0x5d')]({'where':{'id':_0x5a8b81[_0x97bb('0x5c')]['id']}})[_0x97bb('0x23')](handleEntityNotFound(_0x503300,null))[_0x97bb('0x23')](function(_0x1162df){if(_0x1162df){return _0x1162df[_0x97bb('0x73')](_0x5a8b81[_0x97bb('0x5f')]['ids'],_[_0x97bb('0x74')](_0x5a8b81[_0x97bb('0x5f')],['ids','id'])||{})[_0x97bb('0x75')](function(_0x5a3565){for(var _0x2af565=0x0;_0x2af565<_0x5a8b81[_0x97bb('0x5f')][_0x97bb('0x6e')][_0x97bb('0x4f')];_0x2af565+=0x1){socket[_0x97bb('0x76')](_0x97bb('0x77'),{'UserId':Number(_0x5a8b81[_0x97bb('0x5f')]['ids'][_0x2af565]),'WhatsappAccountId':Number(_0x5a8b81['params']['id'])});}return _0x5a3565;});}})['then'](respondWithResult(_0x503300,null))[_0x97bb('0x2d')](handleError(_0x503300,null));};exports[_0x97bb('0x78')]=function(_0x361cc9,_0x5e3ff5,_0x2b7cbf){return db['WhatsappAccount'][_0x97bb('0x5d')]({'where':{'id':_0x361cc9[_0x97bb('0x5c')]['id']}})[_0x97bb('0x23')](handleEntityNotFound(_0x5e3ff5,null))[_0x97bb('0x23')](function(_0x2c1f4d){if(_0x2c1f4d){return _0x2c1f4d['removeAgents'](_0x361cc9[_0x97bb('0x49')][_0x97bb('0x6e')])[_0x97bb('0x23')](function(){if(_[_0x97bb('0x79')](_0x361cc9[_0x97bb('0x49')][_0x97bb('0x6e')])){for(var _0x2a63da=0x0;_0x2a63da<_0x361cc9[_0x97bb('0x49')][_0x97bb('0x6e')][_0x97bb('0x4f')];_0x2a63da+=0x1){socket['emit'](_0x97bb('0x7a'),{'UserId':Number(_0x361cc9[_0x97bb('0x49')][_0x97bb('0x6e')][_0x2a63da]),'WhatsappAccountId':Number(_0x361cc9[_0x97bb('0x5c')]['id'])});}}else{socket[_0x97bb('0x76')](_0x97bb('0x7a'),{'UserId':Number(_0x361cc9['query'][_0x97bb('0x6e')]),'WhatsappAccountId':Number(_0x361cc9['params']['id'])});}});}})[_0x97bb('0x23')](respondWithStatusCode(_0x5e3ff5,null))[_0x97bb('0x2d')](handleError(_0x5e3ff5,null));};exports[_0x97bb('0x7b')]=function(_0x70e9d1,_0x42fc97,_0x87df23){var _0x586219={};var _0x2c3aff={};var _0x556256;var _0x45d8da;return db[_0x97bb('0x45')][_0x97bb('0x6a')]({'where':{'id':_0x70e9d1[_0x97bb('0x5c')]['id']}})[_0x97bb('0x23')](handleEntityNotFound(_0x42fc97,null))[_0x97bb('0x23')](function(_0x2696b5){if(_0x2696b5){_0x556256=_0x2696b5;_0x2c3aff[_0x97bb('0x48')]=_['keys'](db[_0x97bb('0x7c')][_0x97bb('0x46')]);_0x2c3aff[_0x97bb('0x49')]=_[_0x97bb('0x4a')](_0x70e9d1[_0x97bb('0x49')]);_0x2c3aff[_0x97bb('0x4b')]=_['intersection'](_0x2c3aff[_0x97bb('0x48')],_0x2c3aff[_0x97bb('0x49')]);_0x586219[_0x97bb('0x4d')]=_[_0x97bb('0x4c')](_0x2c3aff[_0x97bb('0x48')],qs[_0x97bb('0x4e')](_0x70e9d1[_0x97bb('0x49')]['fields']));_0x586219[_0x97bb('0x4d')]=_0x586219[_0x97bb('0x4d')]['length']?_0x586219[_0x97bb('0x4d')]:_0x2c3aff[_0x97bb('0x48')];_0x586219[_0x97bb('0x52')]=qs['sort'](_0x70e9d1[_0x97bb('0x49')][_0x97bb('0x53')]);_0x586219[_0x97bb('0x54')]=qs[_0x97bb('0x4b')](_[_0x97bb('0x6b')](_0x70e9d1[_0x97bb('0x49')],_0x2c3aff[_0x97bb('0x4b')]));if(_0x70e9d1[_0x97bb('0x49')]['filter']){_0x586219[_0x97bb('0x54')]=_[_0x97bb('0x57')](_0x586219[_0x97bb('0x54')],{'$or':_[_0x97bb('0x44')](_0x586219[_0x97bb('0x4d')],function(_0x334528){var _0x12c033={};_0x12c033[_0x334528]={'$like':'%'+_0x70e9d1[_0x97bb('0x49')][_0x97bb('0x55')]+'%'};return _0x12c033;})});}_0x586219=_[_0x97bb('0x57')]({},_0x586219,_0x70e9d1['options']);return _0x556256[_0x97bb('0x7b')](_0x586219);}})[_0x97bb('0x23')](function(_0x1d7be1){if(_0x1d7be1){_0x45d8da=_0x1d7be1[_0x97bb('0x4f')];if(!_0x70e9d1[_0x97bb('0x49')][_0x97bb('0x50')](_0x97bb('0x51'))){_0x586219[_0x97bb('0x32')]=qs[_0x97bb('0x32')](_0x70e9d1['query'][_0x97bb('0x32')]);_0x586219[_0x97bb('0x35')]=qs['offset'](_0x70e9d1['query'][_0x97bb('0x35')]);}return _0x556256[_0x97bb('0x7b')](_0x586219);}})[_0x97bb('0x23')](function(_0x585075){if(_0x585075){return _0x585075?{'count':_0x45d8da,'rows':_0x585075}:null;}})['then'](respondWithResult(_0x42fc97,null))[_0x97bb('0x2d')](handleError(_0x42fc97,null));};exports['addApplications']=function(_0x1b2ca9,_0x12f745){var _0x5c1056=_0x1b2ca9[_0x97bb('0x5c')]['id'];var _0x10567b=_0x1b2ca9[_0x97bb('0x5f')];var _0x22699f=0xc8;var _0x3a7621=null;return db['sequelize'][_0x97bb('0x7d')]({'isolationLevel':db[_0x97bb('0x7e')][_0x97bb('0x7f')][_0x97bb('0x80')][_0x97bb('0x81')]},function(_0x41d2a2){return db[_0x97bb('0x45')]['findOne']({'where':{'id':_0x5c1056},'transaction':_0x41d2a2})['then'](function(_0x14f187){if(_0x14f187){return db[_0x97bb('0x82')][_0x97bb('0x3a')]({'where':{'WhatsappAccountId':_0x5c1056},'transaction':_0x41d2a2})[_0x97bb('0x23')](function(){var _0x226515=_['map'](_0x10567b,function(_0x4d8c81){_0x4d8c81[_0x97bb('0x68')]=_0x5c1056;return _0x4d8c81;});return db['WhatsappApplication'][_0x97bb('0x83')](_0x226515,{'transaction':_0x41d2a2});});}else{_0x22699f=0x194;_0x3a7621=[];}});})[_0x97bb('0x23')](function(){if(_0x22699f!==0x194){return db[_0x97bb('0x82')][_0x97bb('0x84')]({'where':{'WhatsappAccountId':_0x5c1056},'order':_0x97bb('0x85')})[_0x97bb('0x23')](function(_0xb3bb2c){_0x3a7621=_0xb3bb2c;});}})[_0x97bb('0x2d')](function(_0x5c98a0){_0x22699f=0x1f4;logger[_0x97bb('0x2a')](_0x5c98a0[_0x97bb('0x3e')]);if(_0x5c98a0[_0x97bb('0x3f')]){delete _0x5c98a0[_0x97bb('0x3f')];}_0x3a7621=_0x5c98a0;})[_0x97bb('0x86')](function(){if(_0x3a7621===null){_0x12f745[_0x97bb('0x2e')](_0x22699f);}else{if(_0x22699f===0x1f4){_0x12f745[_0x97bb('0x30')](_0x22699f)[_0x97bb('0x40')](_0x3a7621);}else{_0x12f745['status'](_0x22699f)[_0x97bb('0x31')](_0x3a7621);}}});};exports[_0x97bb('0x87')]=function(_0x370156,_0xf5c471,_0x4effd6){var _0x3103d5={};var _0x4656e8={};var _0x4a3ea3;var _0x31e51e;return db[_0x97bb('0x45')][_0x97bb('0x6a')]({'where':{'id':_0x370156['params']['id']}})['then'](handleEntityNotFound(_0xf5c471,null))[_0x97bb('0x23')](function(_0x2eddea){if(_0x2eddea){_0x4a3ea3=_0x2eddea;_0x4656e8[_0x97bb('0x48')]=_['keys'](db[_0x97bb('0x82')][_0x97bb('0x46')]);_0x4656e8[_0x97bb('0x49')]=_[_0x97bb('0x4a')](_0x370156['query']);_0x4656e8[_0x97bb('0x4b')]=_['intersection'](_0x4656e8[_0x97bb('0x48')],_0x4656e8[_0x97bb('0x49')]);_0x3103d5[_0x97bb('0x4d')]=_[_0x97bb('0x4c')](_0x4656e8[_0x97bb('0x48')],qs[_0x97bb('0x4e')](_0x370156['query'][_0x97bb('0x4e')]));_0x3103d5[_0x97bb('0x4d')]=_0x3103d5[_0x97bb('0x4d')][_0x97bb('0x4f')]?_0x3103d5[_0x97bb('0x4d')]:_0x4656e8[_0x97bb('0x48')];_0x3103d5[_0x97bb('0x52')]=qs['sort'](_0x370156['query'][_0x97bb('0x53')]);_0x3103d5[_0x97bb('0x54')]=qs[_0x97bb('0x4b')](_[_0x97bb('0x6b')](_0x370156[_0x97bb('0x49')],_0x4656e8['filters']));if(_0x370156[_0x97bb('0x49')]['filter']){_0x3103d5['where']=_[_0x97bb('0x57')](_0x3103d5[_0x97bb('0x54')],{'$or':_[_0x97bb('0x44')](_0x3103d5[_0x97bb('0x4d')],function(_0x1d505e){var _0x34b4a5={};_0x34b4a5[_0x1d505e]={'$like':'%'+_0x370156[_0x97bb('0x49')][_0x97bb('0x55')]+'%'};return _0x34b4a5;})});}_0x3103d5=_['merge']({},_0x3103d5,_0x370156[_0x97bb('0x58')]);return _0x4a3ea3['getApplications'](_0x3103d5);}})[_0x97bb('0x23')](function(_0x5029a3){if(_0x5029a3){_0x31e51e=_0x5029a3[_0x97bb('0x4f')];if(!_0x370156['query'][_0x97bb('0x50')](_0x97bb('0x51'))){_0x3103d5[_0x97bb('0x32')]=qs[_0x97bb('0x32')](_0x370156[_0x97bb('0x49')][_0x97bb('0x32')]);_0x3103d5[_0x97bb('0x35')]=qs[_0x97bb('0x35')](_0x370156[_0x97bb('0x49')]['offset']);}return _0x4a3ea3[_0x97bb('0x87')](_0x3103d5);}})[_0x97bb('0x23')](function(_0x321e5c){if(_0x321e5c){return _0x321e5c?{'count':_0x31e51e,'rows':_0x321e5c}:null;}})[_0x97bb('0x23')](respondWithResult(_0xf5c471,null))[_0x97bb('0x2d')](handleError(_0xf5c471,null));};exports[_0x97bb('0x88')]=function(_0x83116e,_0x26fc25,_0x451e08){var _0x1d1f9d={'channel':_0x97bb('0x89')};var _0x116737=[];var _0x1ee20b=[];var _0x3328f9={};return db[_0x97bb('0x45')][_0x97bb('0x5d')]({'where':{'id':_0x83116e['params']['id']},'include':[{'model':db[_0x97bb('0x82')],'as':_0x97bb('0x8a')}]})[_0x97bb('0x23')](handleEntityNotFound(_0x26fc25,null))['then'](function(_0x321932){_0x1d1f9d[_0x97bb('0x8b')]=_0x321932;if(_0x1d1f9d[_0x97bb('0x8b')]&&_0x1d1f9d[_0x97bb('0x8b')][_0x97bb('0x47')]===_0x97bb('0x8c')&&_0x83116e['body'][_0x97bb('0x8d')]){if(_0x83116e[_0x97bb('0x5f')][_0x97bb('0x8d')]['length']===0x0)return;if(_0x83116e[_0x97bb('0x5f')][_0x97bb('0x8d')][0x0][_0x97bb('0x8e')]!==_0x97bb('0x8f'))return;return db[_0x97bb('0x90')][_0x97bb('0x39')]({'read':!![],'readAt':_0x83116e['body']['statuses'][0x0]['timestamp']},{'where':{'messageId':_0x83116e[_0x97bb('0x5f')]['statuses'][0x0][_0x97bb('0x91')]},'individualHooks':!![]})[_0x97bb('0x23')](function(_0x56d74a){return _0x26fc25[_0x97bb('0x30')](0xc8)[_0x97bb('0x31')](_0x56d74a);});}_0x1d1f9d[_0x97bb('0x92')]=_[_0x97bb('0x93')](_0x321932[_0x97bb('0x8a')],['priority'],[_0x97bb('0x94')]);if(_0x1d1f9d[_0x97bb('0x8b')]['Applications']){delete _0x1d1f9d[_0x97bb('0x8b')][_0x97bb('0x8a')];}return db[_0x97bb('0x95')][_0x97bb('0x66')]()[_0x97bb('0x23')](function(_0x14fa37){if(!_0x14fa37){throw new db[(_0x97bb('0x96'))][(_0x97bb('0x97'))](_0x97bb('0x98'));}_0x116737=_[_0x97bb('0x99')](_[_0x97bb('0x4a')](_0x14fa37),[_0x97bb('0x9a'),_0x97bb('0x9b')]);_0x1ee20b=_['difference'](_[_0x97bb('0x4a')](_0x14fa37),['createdAt',_0x97bb('0x9b'),_0x97bb('0x9c'),_0x97bb('0x9d')]);_0x1d1f9d['body']={'mapKey':_0x97bb('0x9e')};if(_0x1d1f9d[_0x97bb('0x8b')]&&_0x1d1f9d[_0x97bb('0x8b')][_0x97bb('0x47')]===_0x97bb('0x9f')){_0x1d1f9d['body']['from']=_0x83116e['body'][_0x97bb('0xa0')][_0x97bb('0xa1')](_0x97bb('0xa2'),'');_0x1d1f9d[_0x97bb('0x5f')][_0x97bb('0x5f')]=_0x83116e['body'][_0x97bb('0xa3')];_0x1d1f9d[_0x97bb('0x5f')]['messageId']=_0x83116e[_0x97bb('0x5f')][_0x97bb('0xa4')];}if(_0x1d1f9d[_0x97bb('0x8b')]&&_0x1d1f9d[_0x97bb('0x8b')][_0x97bb('0x47')]==='sinch'){_0x1d1f9d[_0x97bb('0x5f')][_0x97bb('0xa5')]=_0x83116e['body']['notifications'][0x0][_0x97bb('0xa5')];_0x1d1f9d['body'][_0x97bb('0x5f')]=_0x83116e[_0x97bb('0x5f')][_0x97bb('0xa6')][0x0][_0x97bb('0x2b')][_0x97bb('0x5f')];_0x1d1f9d[_0x97bb('0x5f')]['messageId']=_0x83116e[_0x97bb('0x5f')][_0x97bb('0xa6')][0x0][_0x97bb('0x91')];}if(_0x1d1f9d['body']['id']){delete _0x1d1f9d[_0x97bb('0x5f')]['id'];}if(_['isNil'](_0x1d1f9d[_0x97bb('0x5f')][_0x97bb('0xa5')])){throw new db[(_0x97bb('0x96'))][(_0x97bb('0x97'))](_0x97bb('0xa7'));}if(_[_0x97bb('0xa8')](_0x1d1f9d[_0x97bb('0x5f')][_0x97bb('0x5f')])||_0x1d1f9d[_0x97bb('0x5f')][_0x97bb('0x5f')]===''){throw new db[(_0x97bb('0x96'))]['ValidationError'](_0x97bb('0xa9'));}if(_[_0x97bb('0xa8')](_0x1d1f9d[_0x97bb('0x5f')][_0x97bb('0xaa')])){throw new db[(_0x97bb('0x96'))]['ValidationError'](_0x97bb('0xab')+_0x1ee20b);}if(!_[_0x97bb('0xac')](_0x1ee20b,_0x1d1f9d[_0x97bb('0x5f')][_0x97bb('0xaa')])){throw new db[(_0x97bb('0x96'))][(_0x97bb('0x97'))](_0x97bb('0xad')+_0x1ee20b);}_0x3328f9[_0x1d1f9d[_0x97bb('0x5f')][_0x97bb('0xaa')]]=_0x1d1f9d[_0x97bb('0x5f')][_0x97bb('0xa5')];return db[_0x97bb('0xae')][_0x97bb('0x5d')]({'where':{'id':_0x1d1f9d[_0x97bb('0x8b')][_0x97bb('0x9d')]},'include':[{'model':db[_0x97bb('0x95')],'as':'Contacts','where':_0x3328f9,'limit':0x1,'order':[[_0x97bb('0x9b'),'DESC']]}]});})[_0x97bb('0x23')](handleEntityNotFound(_0x26fc25,null))['then'](function(_0x3d4079){if(_0x3d4079){_0x1d1f9d[_0x97bb('0xaf')]=_[_0x97bb('0x74')](_0x3d4079,[_0x97bb('0xb0')]);if(_0x3d4079['Contacts'][_0x97bb('0x4f')]){return _0x3d4079[_0x97bb('0xb0')][0x0];}var _0x19574c=_[_0x97bb('0x1a')](_0x1d1f9d[_0x97bb('0x5f')],{'firstName':_0x1d1f9d[_0x97bb('0x5f')][_0x97bb('0xa5')],'ListId':_0x3d4079['id']});_0x19574c[_0x1d1f9d['body']['mapKey']]=_0x1d1f9d[_0x97bb('0x5f')][_0x97bb('0xa5')];return db[_0x97bb('0x95')][_0x97bb('0x5e')](_0x19574c,{'fields':_0x116737,'raw':!![]});}})[_0x97bb('0x23')](handleEntityNotFound(_0x26fc25,null))[_0x97bb('0x23')](function(_0x52cb5d){if(_0x52cb5d){_0x1d1f9d[_0x97bb('0xb1')]=_0x52cb5d;var _0x58a54e={'ContactId':_0x52cb5d['id'],'phone':_0x1d1f9d[_0x97bb('0x5f')][_0x97bb('0xa5')],'WhatsappAccountId':_0x83116e[_0x97bb('0x5c')]['id']};var _0x2cc95a={'ContactId':_0x52cb5d['id'],'WhatsappAccountId':_0x83116e[_0x97bb('0x5c')]['id'],'closed':![]};return db['WhatsappInteraction'][_0x97bb('0x5d')]({'where':_0x2cc95a})[_0x97bb('0x23')](function(_0x490beb){if(_0x490beb){return[_0x490beb,![]];}return db[_0x97bb('0xb2')][_0x97bb('0x5e')](_0x58a54e)[_0x97bb('0x23')](function(_0x53174b){return[_0x53174b,!![]];});});}})['spread'](function(_0x27677e,_0xfa5a0f){_0x1d1f9d[_0x97bb('0xb3')]=_0x27677e['get']({'plain':!![]});_0x1d1f9d[_0x97bb('0xb3')][_0x97bb('0xb4')]=![];if(_0xfa5a0f){if(_0x1d1f9d['account'][_0x97bb('0xb5')]){_0x1d1f9d[_0x97bb('0x92')][_0x97bb('0xb6')]({'id':0x0,'priority':_0x1d1f9d['applications'][_0x97bb('0x4f')]+0x1,'app':'close','appdata':_0x97bb('0xb7'),'interval':'*,*,*,*'});}_0x1d1f9d[_0x97bb('0xb3')][_0x97bb('0xb4')]=!![];}return db[_0x97bb('0x90')]['create']({'phone':_0x1d1f9d['body'][_0x97bb('0xa5')],'messageId':_0x1d1f9d[_0x97bb('0x5f')]['messageId'],'body':_0x1d1f9d[_0x97bb('0x5f')][_0x97bb('0x5f')],'WhatsappAccountId':_0x83116e[_0x97bb('0x5c')]['id'],'WhatsappInteractionId':_0x27677e['id'],'direction':'in','ContactId':_0x27677e['ContactId'],'AttachmentId':_0x1d1f9d[_0x97bb('0x5f')][_0x97bb('0xb8')]});})['then'](function(_0x4587ca){_0x1d1f9d[_0x97bb('0x2b')]=_0x4587ca;if(!_0x1d1f9d[_0x97bb('0xb3')]['UserId'])return;return db['User'][_0x97bb('0x5d')]({'attributes':['id',_0x97bb('0x3f')],'where':{'id':_0x1d1f9d['interaction']['UserId']}});})['then'](function(_0x1dbd3a){if(_0x1dbd3a){_0x1d1f9d[_0x97bb('0x92')][_0x97bb('0xb9')]({'id':0x0,'priority':0x0,'app':_0x97bb('0xba'),'appdata':_0x1dbd3a[_0x97bb('0x3f')]+','+(_0x1d1f9d[_0x97bb('0x8b')][_0x97bb('0xbb')]||0xa),'interval':_0x97bb('0xbc')});}if(!_0x1d1f9d['interaction'][_0x97bb('0xbd')])return;return db[_0x97bb('0xbe')][_0x97bb('0x5d')]({'attributes':['id',_0x97bb('0x3f')],'where':{'id':_0x1d1f9d['interaction'][_0x97bb('0xbd')]}});})['then'](function(_0xa85063){if(_0xa85063){_0x1d1f9d[_0x97bb('0x92')][_0x97bb('0xb9')]({'id':0x0,'priority':0x1,'app':_0x97bb('0xbf'),'appdata':_0xa85063['name']+','+(_0x1d1f9d[_0x97bb('0x8b')][_0x97bb('0xc0')]||0x12c),'interval':_0x97bb('0xbc')});}return respondWithRpcPromise(_0x97bb('0xc1'),_0x97bb('0xc2'),_0x1d1f9d);})[_0x97bb('0x23')](function(_0x5a10fb){if(_0x5a10fb){var _0x22aca1=0xc8;var _0xf8d658='receiveMessage';logger['info'](_0x97bb('0x28'),_0xf8d658,_0x22aca1,_0x97bb('0xc3'));logger[_0x97bb('0x27')](_0x97bb('0xc4'),_0xf8d658,_0x22aca1,_0x97bb('0xc3'),JSON[_0x97bb('0x29')](_0x5a10fb));if(_0x1d1f9d[_0x97bb('0x8b')]['type']===_0x97bb('0x9f')){return _0x26fc25[_0x97bb('0x30')](_0x22aca1)[_0x97bb('0xc5')]('Content-Type',_0x97bb('0xc6'))['send']('<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>');}else{return _0x26fc25['status'](_0x22aca1)['json'](_0x5a10fb);}}});})[_0x97bb('0x2d')](handleError(_0x26fc25,null));};exports['send']=function(_0x8458d3,_0x3c6a7d,_0x18d6fb){var _0x1df677,_0x51c456,_0x9ae2be;if(_['isNil'](_0x8458d3[_0x97bb('0x5f')]['body'])||_0x8458d3[_0x97bb('0x5f')][_0x97bb('0x5f')]===''){throw new db[(_0x97bb('0x96'))][(_0x97bb('0x97'))](_0x97bb('0xa9'));}if(_[_0x97bb('0xa8')](_0x8458d3[_0x97bb('0x5f')]['to'])){throw new db[(_0x97bb('0x96'))]['ValidationError']('to\x20is\x20mandatory');}_0x1df677=_0x8458d3[_0x97bb('0x5f')]['to'];return db[_0x97bb('0x45')][_0x97bb('0x5d')]({'where':{'id':_0x8458d3[_0x97bb('0x5c')]['id']},'include':[{'model':db[_0x97bb('0xae')],'as':'List','include':[{'model':db[_0x97bb('0x95')],'as':_0x97bb('0xb0'),'where':{'mobile':_0x1df677},'limit':0x1,'order':[['updatedAt',_0x97bb('0xc7')]]}]}]})[_0x97bb('0x23')](handleEntityNotFound(_0x3c6a7d,null))['then'](function(_0x3c9fa2){if(_0x3c9fa2&&_0x3c9fa2[_0x97bb('0xc8')]){_0x51c456=_0x3c9fa2[_0x97bb('0x3b')]({'plain':!![]});if(_0x51c456[_0x97bb('0xc8')]&&_0x51c456[_0x97bb('0xc8')][_0x97bb('0xb0')][_0x97bb('0x4f')]){return _0x51c456['List'][_0x97bb('0xb0')][0x0];}return db[_0x97bb('0x95')][_0x97bb('0x5e')](_[_0x97bb('0x1a')](_0x8458d3[_0x97bb('0x5f')],{'firstName':_0x1df677,'mobile':_0x1df677,'phone':_0x1df677,'ListId':_0x51c456[_0x97bb('0x9d')]}));}})[_0x97bb('0x23')](handleEntityNotFound(_0x3c6a7d,null))[_0x97bb('0x23')](function(_0x4d251d){if(_0x4d251d){_0x9ae2be=_0x4d251d;return db['WhatsappInteraction'][_0x97bb('0x5d')]({'where':{'ContactId':_0x9ae2be['id'],'closed':![],'WhatsappAccountId':_0x51c456['id']}})[_0x97bb('0x23')](function(_0x16a188){if(_0x16a188){return[_0x16a188,![]];}return db[_0x97bb('0xb2')][_0x97bb('0x5e')]({'UserId':_0x8458d3['user']['id'],'ContactId':_0x9ae2be['id'],'WhatsappAccountId':_0x51c456['id'],'phone':_0x1df677,'firstMsgDirection':_0x97bb('0xc9'),'Messages':[_[_0x97bb('0x57')](_0x8458d3[_0x97bb('0x5f')],{'read':![],'body':_0x8458d3['body'][_0x97bb('0x5f')],'phone':_0x1df677,'WhatsappAccountId':_0x51c456['id'],'UserId':_0x8458d3[_0x97bb('0x60')]['id'],'ContactId':_0x9ae2be['id']})]},{'include':[{'model':db['WhatsappMessage'],'as':'Messages'}]})['then'](function(_0x2ace41){return[_0x2ace41,!![]];});});}})[_0x97bb('0x75')](function(_0x3e114b,_0x4513b6){if(_0x4513b6){return _0x3e114b;}return db[_0x97bb('0x90')][_0x97bb('0x5e')](_['merge'](_0x8458d3[_0x97bb('0x5f')],{'read':![],'body':_0x8458d3[_0x97bb('0x5f')]['body'],'phone':_0x1df677,'WhatsappAccountId':_0x51c456['id'],'WhatsappInteractionId':_0x3e114b['id'],'UserId':_0x8458d3[_0x97bb('0x60')]['id'],'ContactId':_0x9ae2be['id']}))[_0x97bb('0x23')](function(_0x1e81e8){_0x3e114b[_0x97bb('0xca')][_0x97bb('0xcb')]=[];_0x3e114b[_0x97bb('0xca')][_0x97bb('0xcb')][_0x97bb('0xb6')](_0x1e81e8[_0x97bb('0xca')]);return _0x3e114b;});})[_0x97bb('0x23')](respondWithResult(_0x3c6a7d,null))[_0x97bb('0x2d')](handleError(_0x3c6a7d,null));};