bb6c9cee0937027c88408f37a2f18f05833dc0dc
[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 _0xbfcc=['desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./whatsappAccount.socket','register','jayson/promise','client','http','then','info','WhatsappAccount,\x20%s,\x20%s','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','status','end','json','offset','undefined','count','set','Content-Range','save','update','get','UserProfileResource','destroy','sendStatus','index','Pause','map','WhatsappAccount','rawAttributes','fieldName','type','key','model','keys','query','attributes','intersection','fields','limit','order','sort','where','filters','pick','merge','name','filter','options','includeAll','include','findAll','show','params','mandatoryDispositionPause','length','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','WhatsappAccounts','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','Disposition','findOne','hasOwnProperty','nolimit','WhatsappAccountId','rows','removeDispositions','CannedAnswer','getAnswers','removeAnswers','ids','addAgents','omit','spread','emit','userWhatsappAccount:save','removeAgents','isArray','userWhatsappAccount:remove','getAgents','User','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','WhatsappApplication','findAndCountAll','priority','stack','finally','send','getApplications','whatsapp','Applications','account','sinch','statuses','read','WhatsappMessage','message_id','orderBy','asc','CmContact','Sequelize','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','mobile','twilio','from','From','replace','Body','MessageSid','notifications','messageId','ValidationError','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','ListId','Contacts','DESC','contact','interaction','created','autoclose','push','applications','unmanaged','ContactId','AttachmentId','UserId','unshift','agent','waitForTheAssignedAgent','*,*,*,*','queueId','WhatsappQueue','waitForTheAssignedQueue','Start','entity\x20found','WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s','Content-Type','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','to\x20is\x20mandatory','List','WhatsappInteraction','out','Messages','dataValues','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','path','to-csv','ejs','fs-extra','crypto'];(function(_0x2d2b63,_0x277d0a){var _0x5d18f8=function(_0x4eca54){while(--_0x4eca54){_0x2d2b63['push'](_0x2d2b63['shift']());}};_0x5d18f8(++_0x277d0a);}(_0xbfcc,0x186));var _0xcbfc=function(_0x335271,_0x5025f2){_0x335271=_0x335271-0x0;var _0xa9fff8=_0xbfcc[_0x335271];return _0xa9fff8;};'use strict';var emlformat=require(_0xcbfc('0x0'));var rimraf=require(_0xcbfc('0x1'));var zipdir=require(_0xcbfc('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xcbfc('0x3'));var moment=require(_0xcbfc('0x4'));var BPromise=require(_0xcbfc('0x5'));var Mustache=require(_0xcbfc('0x6'));var util=require('util');var path=require(_0xcbfc('0x7'));var sox=require('sox');var csv=require(_0xcbfc('0x8'));var ejs=require(_0xcbfc('0x9'));var fs=require('fs');var fs_extra=require(_0xcbfc('0xa'));var _=require('lodash');var squel=require('squel');var crypto=require(_0xcbfc('0xb'));var jsforce=require('jsforce');var deskjs=require(_0xcbfc('0xc'));var toCsv=require('to-csv');var querystring=require(_0xcbfc('0xd'));var Papa=require(_0xcbfc('0xe'));var Redis=require(_0xcbfc('0xf'));var authService=require(_0xcbfc('0x10'));var qs=require(_0xcbfc('0x11'));var as=require(_0xcbfc('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xcbfc('0x13'))(_0xcbfc('0x14'));var utils=require(_0xcbfc('0x15'));var config=require(_0xcbfc('0x16'));var licenseUtil=require(_0xcbfc('0x17'));var db=require(_0xcbfc('0x18'))['db'];config['redis']=_[_0xcbfc('0x19')](config[_0xcbfc('0x1a')],{'host':_0xcbfc('0x1b'),'port':0x18eb});var socket=require(_0xcbfc('0x1c'))(new Redis(config[_0xcbfc('0x1a')]));require(_0xcbfc('0x1d'))[_0xcbfc('0x1e')](socket);var jayson=require(_0xcbfc('0x1f'));var client=jayson[_0xcbfc('0x20')][_0xcbfc('0x21')]({'port':0x232c});function respondWithRpcPromise(_0x34c151,_0x4078a2,_0x25db2f,_0x5b3e44){return new BPromise(function(_0x29aff6,_0x5f580f){var _0x23bd03=_0x5b3e44||client;return _0x23bd03['request'](_0x34c151,_0x25db2f)[_0xcbfc('0x22')](function(_0x4af8e3){logger[_0xcbfc('0x23')](_0xcbfc('0x24'),_0x4078a2,'request\x20sent');logger[_0xcbfc('0x25')](_0xcbfc('0x26'),_0x4078a2,'request\x20sent',JSON[_0xcbfc('0x27')](_0x4af8e3));if(_0x4af8e3[_0xcbfc('0x28')]){if(_0x4af8e3[_0xcbfc('0x28')][_0xcbfc('0x29')]===0x1f4){logger[_0xcbfc('0x28')](_0xcbfc('0x24'),_0x4078a2,_0x4af8e3[_0xcbfc('0x28')][_0xcbfc('0x2a')]);return _0x5f580f(_0x4af8e3['error'][_0xcbfc('0x2a')]);}logger[_0xcbfc('0x28')](_0xcbfc('0x24'),_0x4078a2,_0x4af8e3[_0xcbfc('0x28')][_0xcbfc('0x2a')]);return _0x29aff6(_0x4af8e3[_0xcbfc('0x28')][_0xcbfc('0x2a')]);}else{logger[_0xcbfc('0x23')]('WhatsappAccount,\x20%s,\x20%s',_0x4078a2,'request\x20sent');_0x29aff6(_0x4af8e3['result'][_0xcbfc('0x2a')]);}})[_0xcbfc('0x2b')](function(_0x28833b){logger[_0xcbfc('0x28')](_0xcbfc('0x24'),_0x4078a2,_0x28833b);_0x5f580f(_0x28833b);});});}function respondWithStatusCode(_0x7073ed,_0x4237fc){_0x4237fc=_0x4237fc||0xcc;return function(_0x174779){if(_0x174779){return _0x7073ed['sendStatus'](_0x4237fc);}return _0x7073ed[_0xcbfc('0x2c')](_0x4237fc)[_0xcbfc('0x2d')]();};}function respondWithResult(_0x38c498,_0x54715d){_0x54715d=_0x54715d||0xc8;return function(_0x28cfc3){if(_0x28cfc3){return _0x38c498[_0xcbfc('0x2c')](_0x54715d)[_0xcbfc('0x2e')](_0x28cfc3);}};}function respondWithFilteredResult(_0xace3d2,_0x413e75){return function(_0x30a541){if(_0x30a541){var _0x51100f=typeof _0x413e75[_0xcbfc('0x2f')]===_0xcbfc('0x30')&&typeof _0x413e75['limit']===_0xcbfc('0x30');var _0x36cb4d=_0x30a541[_0xcbfc('0x31')];var _0x21dcaf=_0x51100f?0x0:_0x413e75[_0xcbfc('0x2f')];var _0x4fcb2e=_0x51100f?_0x30a541[_0xcbfc('0x31')]:_0x413e75[_0xcbfc('0x2f')]+_0x413e75['limit'];var _0x15cb4e;if(_0x4fcb2e>=_0x36cb4d){_0x4fcb2e=_0x36cb4d;_0x15cb4e=0xc8;}else{_0x15cb4e=0xce;}_0xace3d2[_0xcbfc('0x2c')](_0x15cb4e);return _0xace3d2[_0xcbfc('0x32')](_0xcbfc('0x33'),_0x21dcaf+'-'+_0x4fcb2e+'/'+_0x36cb4d)[_0xcbfc('0x2e')](_0x30a541);}return null;};}function patchUpdates(_0x278966){return function(_0xa474a1){try{jsonpatch['apply'](_0xa474a1,_0x278966,!![]);}catch(_0x2a0ec2){return BPromise['reject'](_0x2a0ec2);}return _0xa474a1[_0xcbfc('0x34')]();};}function saveUpdates(_0x245cc3,_0x1c4c58){return function(_0x2494bc){if(_0x2494bc){return _0x2494bc[_0xcbfc('0x35')](_0x245cc3)[_0xcbfc('0x22')](function(_0x471b7c){return _0x471b7c;});}return null;};}function removeEntity(_0x488426,_0x158f4a){return function(_0x3176dd){if(_0x3176dd){return _0x3176dd['destroy']()[_0xcbfc('0x22')](function(){var _0x246d7e=_0x3176dd[_0xcbfc('0x36')]({'plain':!![]});var _0x3d662f='WhatsappAccounts';return db[_0xcbfc('0x37')][_0xcbfc('0x38')]({'where':{'type':_0x3d662f,'resourceId':_0x246d7e['id']}})[_0xcbfc('0x22')](function(){return _0x3176dd;});})[_0xcbfc('0x22')](function(){_0x488426[_0xcbfc('0x2c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x12ecce,_0x1914ce){return function(_0x238717){if(!_0x238717){_0x12ecce[_0xcbfc('0x39')](0x194);}return _0x238717;};}function handleError(_0x383052,_0x214788){_0x214788=_0x214788||0x1f4;return function(_0x4d1d4e){logger[_0xcbfc('0x28')](_0x4d1d4e['stack']);if(_0x4d1d4e['name']){delete _0x4d1d4e['name'];}_0x383052[_0xcbfc('0x2c')](_0x214788)['send'](_0x4d1d4e);};}exports[_0xcbfc('0x3a')]=function(_0x144849,_0x34caa2){var _0x2a2ad3={'include':[{'model':db[_0xcbfc('0x3b')],'as':'mandatoryDispositionPause'}]},_0x52d607={},_0x48b987={'count':0x0,'rows':[]};var _0x5a4efa=_[_0xcbfc('0x3c')](db[_0xcbfc('0x3d')][_0xcbfc('0x3e')],function(_0x474b2a){return{'name':_0x474b2a[_0xcbfc('0x3f')],'type':_0x474b2a[_0xcbfc('0x40')][_0xcbfc('0x41')]};});_0x52d607[_0xcbfc('0x42')]=_[_0xcbfc('0x3c')](_0x5a4efa,'name');_0x52d607['query']=_[_0xcbfc('0x43')](_0x144849[_0xcbfc('0x44')]);_0x52d607['filters']=_['intersection'](_0x52d607[_0xcbfc('0x42')],_0x52d607[_0xcbfc('0x44')]);_0x2a2ad3[_0xcbfc('0x45')]=_[_0xcbfc('0x46')](_0x52d607[_0xcbfc('0x42')],qs[_0xcbfc('0x47')](_0x144849[_0xcbfc('0x44')]['fields']));_0x2a2ad3[_0xcbfc('0x45')]=_0x2a2ad3[_0xcbfc('0x45')]['length']?_0x2a2ad3[_0xcbfc('0x45')]:_0x52d607['model'];if(!_0x144849[_0xcbfc('0x44')]['hasOwnProperty']('nolimit')){_0x2a2ad3[_0xcbfc('0x48')]=qs[_0xcbfc('0x48')](_0x144849[_0xcbfc('0x44')][_0xcbfc('0x48')]);_0x2a2ad3['offset']=qs[_0xcbfc('0x2f')](_0x144849[_0xcbfc('0x44')]['offset']);}_0x2a2ad3[_0xcbfc('0x49')]=qs[_0xcbfc('0x4a')](_0x144849[_0xcbfc('0x44')][_0xcbfc('0x4a')]);_0x2a2ad3[_0xcbfc('0x4b')]=qs[_0xcbfc('0x4c')](_[_0xcbfc('0x4d')](_0x144849['query'],_0x52d607[_0xcbfc('0x4c')]),_0x5a4efa);if(_0x144849[_0xcbfc('0x44')]['filter']){_0x2a2ad3[_0xcbfc('0x4b')]=_[_0xcbfc('0x4e')](_0x2a2ad3['where'],{'$or':_[_0xcbfc('0x3c')](_0x5a4efa,function(_0x86c04b){if(_0x86c04b['type']!=='VIRTUAL'){var _0x425fec={};_0x425fec[_0x86c04b[_0xcbfc('0x4f')]]={'$like':'%'+_0x144849[_0xcbfc('0x44')][_0xcbfc('0x50')]+'%'};return _0x425fec;}})});}_0x2a2ad3=_['merge']({},_0x2a2ad3,_0x144849[_0xcbfc('0x51')]);var _0x58af43={'where':_0x2a2ad3[_0xcbfc('0x4b')]};return db[_0xcbfc('0x3d')][_0xcbfc('0x31')](_0x58af43)[_0xcbfc('0x22')](function(_0x1780f3){_0x48b987[_0xcbfc('0x31')]=_0x1780f3;if(_0x144849[_0xcbfc('0x44')][_0xcbfc('0x52')]){_0x2a2ad3[_0xcbfc('0x53')]=[{'all':!![]}];}return db[_0xcbfc('0x3d')][_0xcbfc('0x54')](_0x2a2ad3);})[_0xcbfc('0x22')](function(_0x3dcae5){_0x48b987['rows']=_0x3dcae5;return _0x48b987;})[_0xcbfc('0x22')](respondWithFilteredResult(_0x34caa2,_0x2a2ad3))['catch'](handleError(_0x34caa2,null));};exports[_0xcbfc('0x55')]=function(_0x3735d6,_0x9602de){var _0x4d6944={'raw':![],'where':{'id':_0x3735d6[_0xcbfc('0x56')]['id']},'include':[{'model':db[_0xcbfc('0x3b')],'as':_0xcbfc('0x57')}]},_0xf73433={};_0xf73433['model']=_[_0xcbfc('0x43')](db[_0xcbfc('0x3d')][_0xcbfc('0x3e')]);_0xf73433[_0xcbfc('0x44')]=_[_0xcbfc('0x43')](_0x3735d6[_0xcbfc('0x44')]);_0xf73433[_0xcbfc('0x4c')]=_[_0xcbfc('0x46')](_0xf73433[_0xcbfc('0x42')],_0xf73433['query']);_0x4d6944[_0xcbfc('0x45')]=_[_0xcbfc('0x46')](_0xf73433[_0xcbfc('0x42')],qs[_0xcbfc('0x47')](_0x3735d6[_0xcbfc('0x44')][_0xcbfc('0x47')]));_0x4d6944[_0xcbfc('0x45')]=_0x4d6944[_0xcbfc('0x45')][_0xcbfc('0x58')]?_0x4d6944['attributes']:_0xf73433['model'];if(_0x3735d6[_0xcbfc('0x44')][_0xcbfc('0x52')]){_0x4d6944[_0xcbfc('0x53')]=[{'all':!![]}];}_0x4d6944=_[_0xcbfc('0x4e')]({},_0x4d6944,_0x3735d6['options']);return db[_0xcbfc('0x3d')][_0xcbfc('0x59')](_0x4d6944)['then'](handleEntityNotFound(_0x9602de,null))[_0xcbfc('0x22')](respondWithResult(_0x9602de,null))[_0xcbfc('0x2b')](handleError(_0x9602de,null));};exports[_0xcbfc('0x5a')]=function(_0x5a2bf7,_0x1db049){return db[_0xcbfc('0x3d')]['create'](_0x5a2bf7[_0xcbfc('0x5b')],{})['then'](function(_0x1e8cdb){var _0x3e4f71=_0x5a2bf7['user'][_0xcbfc('0x36')]({'plain':!![]});if(!_0x3e4f71)throw new Error(_0xcbfc('0x5c'));if(_0x3e4f71[_0xcbfc('0x5d')]===_0xcbfc('0x5e')){var _0x565606=_0x1e8cdb[_0xcbfc('0x36')]({'plain':!![]});var _0x206c12=_0xcbfc('0x5f');return db[_0xcbfc('0x60')][_0xcbfc('0x59')]({'where':{'name':_0x206c12,'userProfileId':_0x3e4f71['userProfileId']},'raw':!![]})[_0xcbfc('0x22')](function(_0x330a58){if(_0x330a58&&_0x330a58[_0xcbfc('0x61')]===0x0){return db[_0xcbfc('0x37')][_0xcbfc('0x5a')]({'name':_0x565606['name'],'resourceId':_0x565606['id'],'type':_0x330a58['name'],'sectionId':_0x330a58['id']},{})[_0xcbfc('0x22')](function(){return _0x1e8cdb;});}else{return _0x1e8cdb;}})['catch'](function(_0x53f31f){logger[_0xcbfc('0x28')](_0xcbfc('0x62'),_0x53f31f);throw _0x53f31f;});}return _0x1e8cdb;})['then'](respondWithResult(_0x1db049,0xc9))[_0xcbfc('0x2b')](handleError(_0x1db049,null));};exports[_0xcbfc('0x35')]=function(_0x4e1dae,_0xc9576b){if(_0x4e1dae['body']['id']){delete _0x4e1dae[_0xcbfc('0x5b')]['id'];}return db[_0xcbfc('0x3d')]['find']({'where':{'id':_0x4e1dae[_0xcbfc('0x56')]['id']},'include':[{'model':db[_0xcbfc('0x3b')],'as':'mandatoryDispositionPause'}]})[_0xcbfc('0x22')](handleEntityNotFound(_0xc9576b,null))[_0xcbfc('0x22')](saveUpdates(_0x4e1dae[_0xcbfc('0x5b')],null))[_0xcbfc('0x22')](respondWithResult(_0xc9576b,null))[_0xcbfc('0x2b')](handleError(_0xc9576b,null));};exports[_0xcbfc('0x38')]=function(_0x537feb,_0x420a13){return db[_0xcbfc('0x3d')][_0xcbfc('0x59')]({'where':{'id':_0x537feb[_0xcbfc('0x56')]['id']}})[_0xcbfc('0x22')](handleEntityNotFound(_0x420a13,null))[_0xcbfc('0x22')](removeEntity(_0x420a13,null))[_0xcbfc('0x2b')](handleError(_0x420a13,null));};exports[_0xcbfc('0x63')]=function(_0x5ad1c9,_0x1f09f1){return db['WhatsappAccount'][_0xcbfc('0x63')]()[_0xcbfc('0x22')](respondWithResult(_0x1f09f1,null))['catch'](handleError(_0x1f09f1,null));};exports[_0xcbfc('0x64')]=function(_0x31235a,_0x48878d,_0x21a7f8){if(_0x31235a['body']['id']){delete _0x31235a[_0xcbfc('0x5b')]['id'];}return db[_0xcbfc('0x3d')]['find']({'where':{'id':_0x31235a[_0xcbfc('0x56')]['id']}})[_0xcbfc('0x22')](handleEntityNotFound(_0x48878d,null))['then'](function(_0x7143f9){if(_0x7143f9){_0x31235a['body']['WhatsappAccountId']=_0x7143f9['id'];return db[_0xcbfc('0x65')][_0xcbfc('0x5a')](_0x31235a[_0xcbfc('0x5b')]);}})[_0xcbfc('0x22')](respondWithResult(_0x48878d,null))[_0xcbfc('0x2b')](handleError(_0x48878d,null));};exports['getDispositions']=function(_0x5d8abd,_0x2c4918,_0x212a31){var _0x1aa45d={'raw':![],'where':{}};var _0x86fbf5={};var _0x15c9e2={'count':0x0,'rows':[]};return db['WhatsappAccount'][_0xcbfc('0x66')]({'where':{'id':_0x5d8abd[_0xcbfc('0x56')]['id']}})[_0xcbfc('0x22')](handleEntityNotFound(_0x2c4918,null))[_0xcbfc('0x22')](function(_0x4fd60e){if(_0x4fd60e){_0x86fbf5[_0xcbfc('0x42')]=_['keys'](db[_0xcbfc('0x65')][_0xcbfc('0x3e')]);_0x86fbf5[_0xcbfc('0x44')]=_[_0xcbfc('0x43')](_0x5d8abd['query']);_0x86fbf5[_0xcbfc('0x4c')]=_[_0xcbfc('0x46')](_0x86fbf5[_0xcbfc('0x42')],_0x86fbf5[_0xcbfc('0x44')]);_0x1aa45d[_0xcbfc('0x45')]=_['intersection'](_0x86fbf5[_0xcbfc('0x42')],qs[_0xcbfc('0x47')](_0x5d8abd[_0xcbfc('0x44')][_0xcbfc('0x47')]));_0x1aa45d[_0xcbfc('0x45')]=_0x1aa45d[_0xcbfc('0x45')]['length']?_0x1aa45d[_0xcbfc('0x45')]:_0x86fbf5[_0xcbfc('0x42')];if(!_0x5d8abd[_0xcbfc('0x44')][_0xcbfc('0x67')](_0xcbfc('0x68'))){_0x1aa45d[_0xcbfc('0x48')]=qs['limit'](_0x5d8abd[_0xcbfc('0x44')][_0xcbfc('0x48')]);_0x1aa45d[_0xcbfc('0x2f')]=qs[_0xcbfc('0x2f')](_0x5d8abd['query'][_0xcbfc('0x2f')]);}_0x1aa45d[_0xcbfc('0x49')]=qs[_0xcbfc('0x4a')](_0x5d8abd[_0xcbfc('0x44')]['sort']);_0x1aa45d['where']=qs['filters'](_[_0xcbfc('0x4d')](_0x5d8abd[_0xcbfc('0x44')],_0x86fbf5['filters']));_0x1aa45d[_0xcbfc('0x4b')][_0xcbfc('0x69')]=_0x4fd60e['id'];if(_0x5d8abd[_0xcbfc('0x44')][_0xcbfc('0x50')]){_0x1aa45d['where']=_['merge'](_0x1aa45d[_0xcbfc('0x4b')],{'$or':_[_0xcbfc('0x3c')](_0x1aa45d[_0xcbfc('0x45')],function(_0x546c21){var _0xbc2397={};_0xbc2397[_0x546c21]={'$like':'%'+_0x5d8abd[_0xcbfc('0x44')][_0xcbfc('0x50')]+'%'};return _0xbc2397;})});}_0x1aa45d=_[_0xcbfc('0x4e')]({},_0x1aa45d,_0x5d8abd[_0xcbfc('0x51')]);return db[_0xcbfc('0x65')]['count']({'where':_0x1aa45d[_0xcbfc('0x4b')]})[_0xcbfc('0x22')](function(_0x3ffd0c){_0x15c9e2['count']=_0x3ffd0c;if(_0x5d8abd[_0xcbfc('0x44')]['includeAll']){_0x1aa45d[_0xcbfc('0x53')]=[{'all':!![]}];}return db[_0xcbfc('0x65')]['findAll'](_0x1aa45d);})[_0xcbfc('0x22')](function(_0x4a18ed){_0x15c9e2[_0xcbfc('0x6a')]=_0x4a18ed;return _0x15c9e2;});}})['then'](respondWithFilteredResult(_0x2c4918,_0x1aa45d))[_0xcbfc('0x2b')](handleError(_0x2c4918,null));};exports[_0xcbfc('0x6b')]=function(_0x121df1,_0x29aa86,_0x5b60e4){return db[_0xcbfc('0x3d')][_0xcbfc('0x59')]({'where':{'id':_0x121df1[_0xcbfc('0x56')]['id']}})['then'](handleEntityNotFound(_0x29aa86,null))[_0xcbfc('0x22')](function(_0x31ee8a){if(_0x31ee8a){return _0x31ee8a[_0xcbfc('0x6b')](_0x121df1[_0xcbfc('0x44')]['ids']);}})[_0xcbfc('0x22')](respondWithStatusCode(_0x29aa86,null))[_0xcbfc('0x2b')](handleError(_0x29aa86,null));};exports['addAnswer']=function(_0x192f5,_0x454e30,_0x30495e){if(_0x192f5[_0xcbfc('0x5b')]['id']){delete _0x192f5['body']['id'];}return db[_0xcbfc('0x3d')]['find']({'where':{'id':_0x192f5[_0xcbfc('0x56')]['id']}})[_0xcbfc('0x22')](handleEntityNotFound(_0x454e30,null))[_0xcbfc('0x22')](function(_0x2eedda){if(_0x2eedda){_0x192f5['body'][_0xcbfc('0x69')]=_0x2eedda['id'];return db[_0xcbfc('0x6c')]['create'](_0x192f5[_0xcbfc('0x5b')]);}})['then'](respondWithResult(_0x454e30,null))[_0xcbfc('0x2b')](handleError(_0x454e30,null));};exports[_0xcbfc('0x6d')]=function(_0x2d1c19,_0x21f8a2,_0x5319c7){var _0x13a32={'raw':![],'where':{}};var _0x48778f={};var _0x36e96e={'count':0x0,'rows':[]};return db['WhatsappAccount'][_0xcbfc('0x66')]({'where':{'id':_0x2d1c19[_0xcbfc('0x56')]['id']}})['then'](handleEntityNotFound(_0x21f8a2,null))['then'](function(_0x12317a){if(_0x12317a){_0x48778f[_0xcbfc('0x42')]=_[_0xcbfc('0x43')](db[_0xcbfc('0x6c')][_0xcbfc('0x3e')]);_0x48778f[_0xcbfc('0x44')]=_[_0xcbfc('0x43')](_0x2d1c19[_0xcbfc('0x44')]);_0x48778f[_0xcbfc('0x4c')]=_['intersection'](_0x48778f[_0xcbfc('0x42')],_0x48778f[_0xcbfc('0x44')]);_0x13a32[_0xcbfc('0x45')]=_[_0xcbfc('0x46')](_0x48778f[_0xcbfc('0x42')],qs[_0xcbfc('0x47')](_0x2d1c19[_0xcbfc('0x44')]['fields']));_0x13a32[_0xcbfc('0x45')]=_0x13a32[_0xcbfc('0x45')][_0xcbfc('0x58')]?_0x13a32[_0xcbfc('0x45')]:_0x48778f[_0xcbfc('0x42')];if(!_0x2d1c19[_0xcbfc('0x44')][_0xcbfc('0x67')](_0xcbfc('0x68'))){_0x13a32[_0xcbfc('0x48')]=qs[_0xcbfc('0x48')](_0x2d1c19[_0xcbfc('0x44')][_0xcbfc('0x48')]);_0x13a32['offset']=qs['offset'](_0x2d1c19[_0xcbfc('0x44')][_0xcbfc('0x2f')]);}_0x13a32[_0xcbfc('0x49')]=qs[_0xcbfc('0x4a')](_0x2d1c19['query'][_0xcbfc('0x4a')]);_0x13a32[_0xcbfc('0x4b')]=qs['filters'](_['pick'](_0x2d1c19['query'],_0x48778f[_0xcbfc('0x4c')]));_0x13a32[_0xcbfc('0x4b')][_0xcbfc('0x69')]=_0x12317a['id'];if(_0x2d1c19[_0xcbfc('0x44')][_0xcbfc('0x50')]){_0x13a32[_0xcbfc('0x4b')]=_[_0xcbfc('0x4e')](_0x13a32['where'],{'$or':_['map'](_0x13a32['attributes'],function(_0x2eaf6a){var _0x4f680b={};_0x4f680b[_0x2eaf6a]={'$like':'%'+_0x2d1c19[_0xcbfc('0x44')][_0xcbfc('0x50')]+'%'};return _0x4f680b;})});}_0x13a32=_[_0xcbfc('0x4e')]({},_0x13a32,_0x2d1c19[_0xcbfc('0x51')]);return db[_0xcbfc('0x6c')][_0xcbfc('0x31')]({'where':_0x13a32[_0xcbfc('0x4b')]})['then'](function(_0x45f685){_0x36e96e['count']=_0x45f685;if(_0x2d1c19[_0xcbfc('0x44')][_0xcbfc('0x52')]){_0x13a32[_0xcbfc('0x53')]=[{'all':!![]}];}return db['CannedAnswer']['findAll'](_0x13a32);})[_0xcbfc('0x22')](function(_0x649ae8){_0x36e96e[_0xcbfc('0x6a')]=_0x649ae8;return _0x36e96e;});}})[_0xcbfc('0x22')](respondWithFilteredResult(_0x21f8a2,_0x13a32))['catch'](handleError(_0x21f8a2,null));};exports[_0xcbfc('0x6e')]=function(_0x52d8a2,_0x350dca,_0x460fe3){return db['WhatsappAccount']['find']({'where':{'id':_0x52d8a2[_0xcbfc('0x56')]['id']}})['then'](handleEntityNotFound(_0x350dca,null))[_0xcbfc('0x22')](function(_0x3a13c0){if(_0x3a13c0){return _0x3a13c0[_0xcbfc('0x6e')](_0x52d8a2['query'][_0xcbfc('0x6f')]);}})[_0xcbfc('0x22')](respondWithStatusCode(_0x350dca,null))[_0xcbfc('0x2b')](handleError(_0x350dca,null));};exports[_0xcbfc('0x70')]=function(_0x5cc1ef,_0x13329a,_0x21fefc){return db['WhatsappAccount']['find']({'where':{'id':_0x5cc1ef[_0xcbfc('0x56')]['id']}})[_0xcbfc('0x22')](handleEntityNotFound(_0x13329a,null))[_0xcbfc('0x22')](function(_0x488cbc){if(_0x488cbc){return _0x488cbc[_0xcbfc('0x70')](_0x5cc1ef['body']['ids'],_[_0xcbfc('0x71')](_0x5cc1ef[_0xcbfc('0x5b')],['ids','id'])||{})[_0xcbfc('0x72')](function(_0x411dec){for(var _0x14d804=0x0;_0x14d804<_0x5cc1ef[_0xcbfc('0x5b')][_0xcbfc('0x6f')][_0xcbfc('0x58')];_0x14d804+=0x1){socket[_0xcbfc('0x73')](_0xcbfc('0x74'),{'UserId':Number(_0x5cc1ef['body'][_0xcbfc('0x6f')][_0x14d804]),'WhatsappAccountId':Number(_0x5cc1ef['params']['id'])});}return _0x411dec;});}})[_0xcbfc('0x22')](respondWithResult(_0x13329a,null))['catch'](handleError(_0x13329a,null));};exports[_0xcbfc('0x75')]=function(_0x436282,_0x31e540,_0x1be420){return db[_0xcbfc('0x3d')][_0xcbfc('0x59')]({'where':{'id':_0x436282['params']['id']}})[_0xcbfc('0x22')](handleEntityNotFound(_0x31e540,null))['then'](function(_0x254909){if(_0x254909){return _0x254909[_0xcbfc('0x75')](_0x436282['query'][_0xcbfc('0x6f')])[_0xcbfc('0x22')](function(){if(_[_0xcbfc('0x76')](_0x436282['query']['ids'])){for(var _0x433181=0x0;_0x433181<_0x436282['query'][_0xcbfc('0x6f')][_0xcbfc('0x58')];_0x433181+=0x1){socket[_0xcbfc('0x73')](_0xcbfc('0x77'),{'UserId':Number(_0x436282[_0xcbfc('0x44')]['ids'][_0x433181]),'WhatsappAccountId':Number(_0x436282[_0xcbfc('0x56')]['id'])});}}else{socket[_0xcbfc('0x73')](_0xcbfc('0x77'),{'UserId':Number(_0x436282[_0xcbfc('0x44')]['ids']),'WhatsappAccountId':Number(_0x436282[_0xcbfc('0x56')]['id'])});}});}})['then'](respondWithStatusCode(_0x31e540,null))[_0xcbfc('0x2b')](handleError(_0x31e540,null));};exports[_0xcbfc('0x78')]=function(_0x2b6d5b,_0x35bac6,_0xea05cc){var _0x14cfb9={};var _0x563d59={};var _0x35d1bc;var _0x2f0bd7;return db[_0xcbfc('0x3d')][_0xcbfc('0x66')]({'where':{'id':_0x2b6d5b[_0xcbfc('0x56')]['id']}})[_0xcbfc('0x22')](handleEntityNotFound(_0x35bac6,null))['then'](function(_0x184f1a){if(_0x184f1a){_0x35d1bc=_0x184f1a;_0x563d59['model']=_[_0xcbfc('0x43')](db[_0xcbfc('0x79')][_0xcbfc('0x3e')]);_0x563d59[_0xcbfc('0x44')]=_[_0xcbfc('0x43')](_0x2b6d5b[_0xcbfc('0x44')]);_0x563d59[_0xcbfc('0x4c')]=_[_0xcbfc('0x46')](_0x563d59[_0xcbfc('0x42')],_0x563d59[_0xcbfc('0x44')]);_0x14cfb9[_0xcbfc('0x45')]=_[_0xcbfc('0x46')](_0x563d59[_0xcbfc('0x42')],qs[_0xcbfc('0x47')](_0x2b6d5b['query'][_0xcbfc('0x47')]));_0x14cfb9['attributes']=_0x14cfb9['attributes'][_0xcbfc('0x58')]?_0x14cfb9[_0xcbfc('0x45')]:_0x563d59['model'];_0x14cfb9[_0xcbfc('0x49')]=qs[_0xcbfc('0x4a')](_0x2b6d5b[_0xcbfc('0x44')]['sort']);_0x14cfb9[_0xcbfc('0x4b')]=qs[_0xcbfc('0x4c')](_[_0xcbfc('0x4d')](_0x2b6d5b[_0xcbfc('0x44')],_0x563d59['filters']));if(_0x2b6d5b['query'][_0xcbfc('0x50')]){_0x14cfb9[_0xcbfc('0x4b')]=_[_0xcbfc('0x4e')](_0x14cfb9[_0xcbfc('0x4b')],{'$or':_[_0xcbfc('0x3c')](_0x14cfb9['attributes'],function(_0x24f8d7){var _0x1ac86f={};_0x1ac86f[_0x24f8d7]={'$like':'%'+_0x2b6d5b['query'][_0xcbfc('0x50')]+'%'};return _0x1ac86f;})});}_0x14cfb9=_[_0xcbfc('0x4e')]({},_0x14cfb9,_0x2b6d5b[_0xcbfc('0x51')]);return _0x35d1bc['getAgents'](_0x14cfb9);}})[_0xcbfc('0x22')](function(_0xa156d7){if(_0xa156d7){_0x2f0bd7=_0xa156d7[_0xcbfc('0x58')];if(!_0x2b6d5b[_0xcbfc('0x44')]['hasOwnProperty'](_0xcbfc('0x68'))){_0x14cfb9[_0xcbfc('0x48')]=qs['limit'](_0x2b6d5b[_0xcbfc('0x44')]['limit']);_0x14cfb9['offset']=qs[_0xcbfc('0x2f')](_0x2b6d5b[_0xcbfc('0x44')][_0xcbfc('0x2f')]);}return _0x35d1bc[_0xcbfc('0x78')](_0x14cfb9);}})[_0xcbfc('0x22')](function(_0x39710b){if(_0x39710b){return _0x39710b?{'count':_0x2f0bd7,'rows':_0x39710b}:null;}})[_0xcbfc('0x22')](respondWithResult(_0x35bac6,null))[_0xcbfc('0x2b')](handleError(_0x35bac6,null));};exports[_0xcbfc('0x7a')]=function(_0x13de23,_0x306d8c){var _0x55fe16=_0x13de23[_0xcbfc('0x56')]['id'];var _0x5a6068=_0x13de23[_0xcbfc('0x5b')];var _0xcbce99=0xc8;var _0x737ace=null;return db[_0xcbfc('0x7b')][_0xcbfc('0x7c')]({'isolationLevel':db['sequelize'][_0xcbfc('0x7d')][_0xcbfc('0x7e')]['READ_COMMITTED']},function(_0x207041){return db['WhatsappAccount'][_0xcbfc('0x66')]({'where':{'id':_0x55fe16},'transaction':_0x207041})[_0xcbfc('0x22')](function(_0x43778b){if(_0x43778b){return db['WhatsappApplication'][_0xcbfc('0x38')]({'where':{'WhatsappAccountId':_0x55fe16},'transaction':_0x207041})[_0xcbfc('0x22')](function(){var _0x4d436d=_[_0xcbfc('0x3c')](_0x5a6068,function(_0x229689){_0x229689['WhatsappAccountId']=_0x55fe16;return _0x229689;});return db[_0xcbfc('0x7f')]['bulkCreate'](_0x4d436d,{'transaction':_0x207041});});}else{_0xcbce99=0x194;_0x737ace=[];}});})[_0xcbfc('0x22')](function(){if(_0xcbce99!==0x194){return db[_0xcbfc('0x7f')][_0xcbfc('0x80')]({'where':{'WhatsappAccountId':_0x55fe16},'order':_0xcbfc('0x81')})['then'](function(_0x3555f4){_0x737ace=_0x3555f4;});}})[_0xcbfc('0x2b')](function(_0x91a689){_0xcbce99=0x1f4;logger['error'](_0x91a689[_0xcbfc('0x82')]);if(_0x91a689[_0xcbfc('0x4f')]){delete _0x91a689['name'];}_0x737ace=_0x91a689;})[_0xcbfc('0x83')](function(){if(_0x737ace===null){_0x306d8c[_0xcbfc('0x39')](_0xcbce99);}else{if(_0xcbce99===0x1f4){_0x306d8c[_0xcbfc('0x2c')](_0xcbce99)[_0xcbfc('0x84')](_0x737ace);}else{_0x306d8c[_0xcbfc('0x2c')](_0xcbce99)['json'](_0x737ace);}}});};exports[_0xcbfc('0x85')]=function(_0x358e53,_0x256ff6,_0x75cad3){var _0x2f0ed9={};var _0x5babc7={};var _0xb00b4a;var _0x174de5;return db[_0xcbfc('0x3d')][_0xcbfc('0x66')]({'where':{'id':_0x358e53[_0xcbfc('0x56')]['id']}})[_0xcbfc('0x22')](handleEntityNotFound(_0x256ff6,null))[_0xcbfc('0x22')](function(_0x5ca7c7){if(_0x5ca7c7){_0xb00b4a=_0x5ca7c7;_0x5babc7[_0xcbfc('0x42')]=_[_0xcbfc('0x43')](db['WhatsappApplication'][_0xcbfc('0x3e')]);_0x5babc7[_0xcbfc('0x44')]=_[_0xcbfc('0x43')](_0x358e53[_0xcbfc('0x44')]);_0x5babc7['filters']=_['intersection'](_0x5babc7[_0xcbfc('0x42')],_0x5babc7[_0xcbfc('0x44')]);_0x2f0ed9[_0xcbfc('0x45')]=_['intersection'](_0x5babc7['model'],qs[_0xcbfc('0x47')](_0x358e53[_0xcbfc('0x44')]['fields']));_0x2f0ed9['attributes']=_0x2f0ed9[_0xcbfc('0x45')][_0xcbfc('0x58')]?_0x2f0ed9['attributes']:_0x5babc7[_0xcbfc('0x42')];_0x2f0ed9['order']=qs[_0xcbfc('0x4a')](_0x358e53['query'][_0xcbfc('0x4a')]);_0x2f0ed9['where']=qs[_0xcbfc('0x4c')](_['pick'](_0x358e53[_0xcbfc('0x44')],_0x5babc7[_0xcbfc('0x4c')]));if(_0x358e53['query'][_0xcbfc('0x50')]){_0x2f0ed9[_0xcbfc('0x4b')]=_[_0xcbfc('0x4e')](_0x2f0ed9[_0xcbfc('0x4b')],{'$or':_[_0xcbfc('0x3c')](_0x2f0ed9['attributes'],function(_0x539dbd){var _0x311950={};_0x311950[_0x539dbd]={'$like':'%'+_0x358e53[_0xcbfc('0x44')][_0xcbfc('0x50')]+'%'};return _0x311950;})});}_0x2f0ed9=_[_0xcbfc('0x4e')]({},_0x2f0ed9,_0x358e53[_0xcbfc('0x51')]);return _0xb00b4a[_0xcbfc('0x85')](_0x2f0ed9);}})[_0xcbfc('0x22')](function(_0x287d4b){if(_0x287d4b){_0x174de5=_0x287d4b[_0xcbfc('0x58')];if(!_0x358e53[_0xcbfc('0x44')]['hasOwnProperty']('nolimit')){_0x2f0ed9['limit']=qs['limit'](_0x358e53[_0xcbfc('0x44')]['limit']);_0x2f0ed9[_0xcbfc('0x2f')]=qs[_0xcbfc('0x2f')](_0x358e53['query'][_0xcbfc('0x2f')]);}return _0xb00b4a['getApplications'](_0x2f0ed9);}})['then'](function(_0x439911){if(_0x439911){return _0x439911?{'count':_0x174de5,'rows':_0x439911}:null;}})['then'](respondWithResult(_0x256ff6,null))[_0xcbfc('0x2b')](handleError(_0x256ff6,null));};exports['notify']=function(_0x2d8f3f,_0x2388e2,_0x2079ec){var _0x240e74={'channel':_0xcbfc('0x86')};var _0x5a93a9=[];var _0x48cc13=[];var _0x54421d={};return db[_0xcbfc('0x3d')][_0xcbfc('0x59')]({'where':{'id':_0x2d8f3f[_0xcbfc('0x56')]['id']},'include':[{'model':db[_0xcbfc('0x7f')],'as':_0xcbfc('0x87')}]})[_0xcbfc('0x22')](handleEntityNotFound(_0x2388e2,null))['then'](function(_0x4582c8){_0x240e74[_0xcbfc('0x88')]=_0x4582c8;if(_0x240e74['account']&&_0x240e74[_0xcbfc('0x88')][_0xcbfc('0x40')]===_0xcbfc('0x89')&&_0x2d8f3f['body'][_0xcbfc('0x8a')]){if(_0x2d8f3f[_0xcbfc('0x5b')][_0xcbfc('0x8a')]['length']===0x0)return;if(_0x2d8f3f['body'][_0xcbfc('0x8a')][0x0]['state']!==_0xcbfc('0x8b'))return;return db[_0xcbfc('0x8c')][_0xcbfc('0x35')]({'read':!![],'readAt':_0x2d8f3f[_0xcbfc('0x5b')]['statuses'][0x0]['timestamp']},{'where':{'messageId':_0x2d8f3f[_0xcbfc('0x5b')][_0xcbfc('0x8a')][0x0][_0xcbfc('0x8d')]},'individualHooks':!![]})[_0xcbfc('0x22')](function(_0x3f2d04){return _0x2388e2[_0xcbfc('0x2c')](0xc8)[_0xcbfc('0x2e')](_0x3f2d04);});}_0x240e74['applications']=_[_0xcbfc('0x8e')](_0x4582c8[_0xcbfc('0x87')],[_0xcbfc('0x81')],[_0xcbfc('0x8f')]);if(_0x240e74['account'][_0xcbfc('0x87')]){delete _0x240e74[_0xcbfc('0x88')][_0xcbfc('0x87')];}return db[_0xcbfc('0x90')]['describe']()[_0xcbfc('0x22')](function(_0x2c8baa){if(!_0x2c8baa){throw new db[(_0xcbfc('0x91'))]['ValidationError'](_0xcbfc('0x92'));}_0x5a93a9=_[_0xcbfc('0x93')](_['keys'](_0x2c8baa),[_0xcbfc('0x94'),_0xcbfc('0x95')]);_0x48cc13=_['difference'](_[_0xcbfc('0x43')](_0x2c8baa),[_0xcbfc('0x94'),_0xcbfc('0x95'),_0xcbfc('0x96'),'ListId']);_0x240e74['body']={'mapKey':_0xcbfc('0x97')};if(_0x240e74[_0xcbfc('0x88')]&&_0x240e74[_0xcbfc('0x88')][_0xcbfc('0x40')]===_0xcbfc('0x98')){_0x240e74[_0xcbfc('0x5b')][_0xcbfc('0x99')]=_0x2d8f3f[_0xcbfc('0x5b')][_0xcbfc('0x9a')][_0xcbfc('0x9b')]('whatsapp:','');_0x240e74[_0xcbfc('0x5b')][_0xcbfc('0x5b')]=_0x2d8f3f['body'][_0xcbfc('0x9c')];_0x240e74['body']['messageId']=_0x2d8f3f['body'][_0xcbfc('0x9d')];}if(_0x240e74[_0xcbfc('0x88')]&&_0x240e74['account'][_0xcbfc('0x40')]===_0xcbfc('0x89')){_0x240e74[_0xcbfc('0x5b')][_0xcbfc('0x99')]=_0x2d8f3f[_0xcbfc('0x5b')]['notifications'][0x0][_0xcbfc('0x99')];_0x240e74[_0xcbfc('0x5b')][_0xcbfc('0x5b')]=_0x2d8f3f[_0xcbfc('0x5b')][_0xcbfc('0x9e')][0x0][_0xcbfc('0x2a')][_0xcbfc('0x5b')];_0x240e74[_0xcbfc('0x5b')][_0xcbfc('0x9f')]=_0x2d8f3f[_0xcbfc('0x5b')][_0xcbfc('0x9e')][0x0][_0xcbfc('0x8d')];}if(_0x240e74[_0xcbfc('0x5b')]['id']){delete _0x240e74['body']['id'];}if(_['isNil'](_0x240e74['body'][_0xcbfc('0x99')])){throw new db[(_0xcbfc('0x91'))][(_0xcbfc('0xa0'))](_0xcbfc('0xa1'));}if(_[_0xcbfc('0xa2')](_0x240e74['body']['body'])||_0x240e74[_0xcbfc('0x5b')][_0xcbfc('0x5b')]===''){throw new db[(_0xcbfc('0x91'))][(_0xcbfc('0xa0'))](_0xcbfc('0xa3'));}if(_['isNil'](_0x240e74['body'][_0xcbfc('0xa4')])){throw new db['Sequelize'][(_0xcbfc('0xa0'))](_0xcbfc('0xa5')+_0x48cc13);}if(!_[_0xcbfc('0xa6')](_0x48cc13,_0x240e74[_0xcbfc('0x5b')]['mapKey'])){throw new db[(_0xcbfc('0x91'))][(_0xcbfc('0xa0'))](_0xcbfc('0xa7')+_0x48cc13);}_0x54421d[_0x240e74['body'][_0xcbfc('0xa4')]]=_0x240e74[_0xcbfc('0x5b')][_0xcbfc('0x99')];return db[_0xcbfc('0xa8')][_0xcbfc('0x59')]({'where':{'id':_0x240e74['account'][_0xcbfc('0xa9')]},'include':[{'model':db['CmContact'],'as':_0xcbfc('0xaa'),'where':_0x54421d,'limit':0x1,'order':[[_0xcbfc('0x95'),_0xcbfc('0xab')]]}]});})[_0xcbfc('0x22')](handleEntityNotFound(_0x2388e2,null))[_0xcbfc('0x22')](function(_0x4f6e39){if(_0x4f6e39){_0x240e74['list']=_[_0xcbfc('0x71')](_0x4f6e39,[_0xcbfc('0xaa')]);if(_0x4f6e39[_0xcbfc('0xaa')][_0xcbfc('0x58')]){return _0x4f6e39[_0xcbfc('0xaa')][0x0];}var _0x373431=_['defaults'](_0x240e74[_0xcbfc('0x5b')],{'firstName':_0x240e74[_0xcbfc('0x5b')][_0xcbfc('0x99')],'ListId':_0x4f6e39['id']});_0x373431[_0x240e74[_0xcbfc('0x5b')][_0xcbfc('0xa4')]]=_0x240e74[_0xcbfc('0x5b')][_0xcbfc('0x99')];return db[_0xcbfc('0x90')][_0xcbfc('0x5a')](_0x373431,{'fields':_0x5a93a9,'raw':!![]});}})[_0xcbfc('0x22')](handleEntityNotFound(_0x2388e2,null))[_0xcbfc('0x22')](function(_0x763858){if(_0x763858){_0x240e74[_0xcbfc('0xac')]=_0x763858;var _0x48de1f={'ContactId':_0x763858['id'],'phone':_0x240e74['body'][_0xcbfc('0x99')],'WhatsappAccountId':_0x2d8f3f['params']['id']};var _0x30de1c={'ContactId':_0x763858['id'],'WhatsappAccountId':_0x2d8f3f[_0xcbfc('0x56')]['id'],'closed':![]};return db['WhatsappInteraction'][_0xcbfc('0x59')]({'where':_0x30de1c})[_0xcbfc('0x22')](function(_0x1413d5){if(_0x1413d5){return[_0x1413d5,![]];}return db['WhatsappInteraction'][_0xcbfc('0x5a')](_0x48de1f)[_0xcbfc('0x22')](function(_0x364812){return[_0x364812,!![]];});});}})[_0xcbfc('0x72')](function(_0xdda102,_0x505985){_0x240e74[_0xcbfc('0xad')]=_0xdda102['get']({'plain':!![]});_0x240e74['interaction'][_0xcbfc('0xae')]=![];if(_0x505985){if(_0x240e74['account'][_0xcbfc('0xaf')]){_0x240e74['applications'][_0xcbfc('0xb0')]({'id':0x0,'priority':_0x240e74[_0xcbfc('0xb1')][_0xcbfc('0x58')]+0x1,'app':'close','appdata':_0xcbfc('0xb2'),'interval':'*,*,*,*'});}_0x240e74[_0xcbfc('0xad')][_0xcbfc('0xae')]=!![];}return db[_0xcbfc('0x8c')]['create']({'phone':_0x240e74[_0xcbfc('0x5b')]['from'],'messageId':_0x240e74['body']['messageId'],'body':_0x240e74['body'][_0xcbfc('0x5b')],'WhatsappAccountId':_0x2d8f3f['params']['id'],'WhatsappInteractionId':_0xdda102['id'],'direction':'in','ContactId':_0xdda102[_0xcbfc('0xb3')],'AttachmentId':_0x240e74[_0xcbfc('0x5b')][_0xcbfc('0xb4')]});})['then'](function(_0x41175c){_0x240e74[_0xcbfc('0x2a')]=_0x41175c;if(!_0x240e74[_0xcbfc('0xad')][_0xcbfc('0xb5')])return;return db[_0xcbfc('0x79')][_0xcbfc('0x59')]({'attributes':['id',_0xcbfc('0x4f')],'where':{'id':_0x240e74[_0xcbfc('0xad')][_0xcbfc('0xb5')]}});})[_0xcbfc('0x22')](function(_0x285ec7){if(_0x285ec7){_0x240e74[_0xcbfc('0xb1')][_0xcbfc('0xb6')]({'id':0x0,'priority':0x0,'app':_0xcbfc('0xb7'),'appdata':_0x285ec7[_0xcbfc('0x4f')]+','+(_0x240e74[_0xcbfc('0x88')][_0xcbfc('0xb8')]||0xa),'interval':_0xcbfc('0xb9')});}if(!_0x240e74[_0xcbfc('0xad')][_0xcbfc('0xba')])return;return db[_0xcbfc('0xbb')]['find']({'attributes':['id',_0xcbfc('0x4f')],'where':{'id':_0x240e74['interaction'][_0xcbfc('0xba')]}});})[_0xcbfc('0x22')](function(_0x1ea6a7){if(_0x1ea6a7){_0x240e74['applications'][_0xcbfc('0xb6')]({'id':0x0,'priority':0x1,'app':'queue','appdata':_0x1ea6a7['name']+','+(_0x240e74[_0xcbfc('0x88')][_0xcbfc('0xbc')]||0x12c),'interval':'*,*,*,*'});}return respondWithRpcPromise(_0xcbfc('0xbd'),'startRouting',_0x240e74);})[_0xcbfc('0x22')](function(_0x3204a9){if(_0x3204a9){var _0x3b784a=0xc8;var _0x303d51='receiveMessage';logger[_0xcbfc('0x23')](_0xcbfc('0x26'),_0x303d51,_0x3b784a,_0xcbfc('0xbe'));logger[_0xcbfc('0x25')](_0xcbfc('0xbf'),_0x303d51,_0x3b784a,_0xcbfc('0xbe'),JSON[_0xcbfc('0x27')](_0x3204a9));if(_0x240e74[_0xcbfc('0x88')][_0xcbfc('0x40')]===_0xcbfc('0x98')){return _0x2388e2[_0xcbfc('0x2c')](_0x3b784a)[_0xcbfc('0x32')](_0xcbfc('0xc0'),_0xcbfc('0xc1'))[_0xcbfc('0x84')](_0xcbfc('0xc2'));}else{return _0x2388e2[_0xcbfc('0x2c')](_0x3b784a)[_0xcbfc('0x2e')](_0x3204a9);}}});})[_0xcbfc('0x2b')](handleError(_0x2388e2,null));};exports['send']=function(_0x3e5850,_0x58b0a4,_0x16ae8a){var _0x121b8a,_0x2aa0b1,_0x5bc38c;if(_['isNil'](_0x3e5850[_0xcbfc('0x5b')][_0xcbfc('0x5b')])||_0x3e5850[_0xcbfc('0x5b')][_0xcbfc('0x5b')]===''){throw new db['Sequelize']['ValidationError'](_0xcbfc('0xa3'));}if(_[_0xcbfc('0xa2')](_0x3e5850[_0xcbfc('0x5b')]['to'])){throw new db['Sequelize'][(_0xcbfc('0xa0'))](_0xcbfc('0xc3'));}_0x121b8a=_0x3e5850[_0xcbfc('0x5b')]['to'];return db[_0xcbfc('0x3d')][_0xcbfc('0x59')]({'where':{'id':_0x3e5850[_0xcbfc('0x56')]['id']},'include':[{'model':db[_0xcbfc('0xa8')],'as':_0xcbfc('0xc4'),'include':[{'model':db[_0xcbfc('0x90')],'as':'Contacts','where':{'mobile':_0x121b8a},'limit':0x1,'order':[[_0xcbfc('0x95'),_0xcbfc('0xab')]]}]}]})[_0xcbfc('0x22')](handleEntityNotFound(_0x58b0a4,null))[_0xcbfc('0x22')](function(_0x58cd26){if(_0x58cd26&&_0x58cd26[_0xcbfc('0xc4')]){_0x2aa0b1=_0x58cd26[_0xcbfc('0x36')]({'plain':!![]});if(_0x2aa0b1[_0xcbfc('0xc4')]&&_0x2aa0b1[_0xcbfc('0xc4')][_0xcbfc('0xaa')]['length']){return _0x2aa0b1[_0xcbfc('0xc4')][_0xcbfc('0xaa')][0x0];}return db[_0xcbfc('0x90')][_0xcbfc('0x5a')](_[_0xcbfc('0x19')](_0x3e5850[_0xcbfc('0x5b')],{'firstName':_0x121b8a,'mobile':_0x121b8a,'phone':_0x121b8a,'ListId':_0x2aa0b1['ListId']}));}})[_0xcbfc('0x22')](handleEntityNotFound(_0x58b0a4,null))[_0xcbfc('0x22')](function(_0x140758){if(_0x140758){_0x5bc38c=_0x140758;return db[_0xcbfc('0xc5')][_0xcbfc('0x59')]({'where':{'ContactId':_0x5bc38c['id'],'closed':![],'WhatsappAccountId':_0x2aa0b1['id']}})[_0xcbfc('0x22')](function(_0xe4974d){if(_0xe4974d){return[_0xe4974d,![]];}return db['WhatsappInteraction'][_0xcbfc('0x5a')]({'UserId':_0x3e5850[_0xcbfc('0x5e')]['id'],'ContactId':_0x5bc38c['id'],'WhatsappAccountId':_0x2aa0b1['id'],'phone':_0x121b8a,'firstMsgDirection':_0xcbfc('0xc6'),'Messages':[_[_0xcbfc('0x4e')](_0x3e5850[_0xcbfc('0x5b')],{'read':![],'body':_0x3e5850[_0xcbfc('0x5b')]['body'],'phone':_0x121b8a,'WhatsappAccountId':_0x2aa0b1['id'],'UserId':_0x3e5850['user']['id'],'ContactId':_0x5bc38c['id']})]},{'include':[{'model':db[_0xcbfc('0x8c')],'as':_0xcbfc('0xc7')}]})[_0xcbfc('0x22')](function(_0x38409b){return[_0x38409b,!![]];});});}})[_0xcbfc('0x72')](function(_0x5b8793,_0x101d08){if(_0x101d08){return _0x5b8793;}return db[_0xcbfc('0x8c')][_0xcbfc('0x5a')](_[_0xcbfc('0x4e')](_0x3e5850[_0xcbfc('0x5b')],{'read':![],'body':_0x3e5850[_0xcbfc('0x5b')][_0xcbfc('0x5b')],'phone':_0x121b8a,'WhatsappAccountId':_0x2aa0b1['id'],'WhatsappInteractionId':_0x5b8793['id'],'UserId':_0x3e5850[_0xcbfc('0x5e')]['id'],'ContactId':_0x5bc38c['id']}))[_0xcbfc('0x22')](function(_0x405d88){_0x5b8793[_0xcbfc('0xc8')][_0xcbfc('0xc7')]=[];_0x5b8793[_0xcbfc('0xc8')][_0xcbfc('0xc7')][_0xcbfc('0xb0')](_0x405d88[_0xcbfc('0xc8')]);return _0x5b8793;});})[_0xcbfc('0x22')](respondWithResult(_0x58b0a4,null))[_0xcbfc('0x2b')](handleError(_0x58b0a4,null));};