ef68a1b2858a13d11fa4271b40463026b903d9b2
[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 _0xccc2=['http','WhatsappAccount,\x20%s,\x20%s','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','info','result','sendStatus','status','offset','undefined','limit','count','set','Content-Range','json','save','update','destroy','then','WhatsappAccounts','UserProfileResource','end','name','send','index','Pause','WhatsappAccount','rawAttributes','type','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','mandatoryDispositionPause','find','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','autoAssociation','catch','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','addDisposition','WhatsappAccountId','Disposition','getDispositions','findOne','map','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','addAgents','spread','emit','removeAgents','isArray','userWhatsappAccount:remove','getAgents','addApplications','sequelize','transaction','Transaction','WhatsappApplication','findAndCountAll','priority','stack','finally','getApplications','notify','account','sinch','statuses','state','WhatsappMessage','message_id','applications','orderBy','asc','Applications','CmContact','Sequelize','ValidationError','difference','createdAt','updatedAt','ListId','from','From','Body','messageId','MessageSid','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','Contacts','list','omit','contact','WhatsappInteraction','interaction','created','close','unmanaged','*,*,*,*','AttachmentId','User','UserId','unshift','waitForTheAssignedAgent','queueId','WhatsappQueue','queue','Start','startRouting','entity\x20found','twilio','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','to\x20is\x20mandatory','List','DESC','out','Messages','dataValues','push','eml-format','fast-json-patch','bluebird','util','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','./whatsappAccount.socket','register'];(function(_0x502c7d,_0x2f1285){var _0x30b7ed=function(_0x2d92f3){while(--_0x2d92f3){_0x502c7d['push'](_0x502c7d['shift']());}};_0x30b7ed(++_0x2f1285);}(_0xccc2,0xa2));var _0x2ccc=function(_0x4642e0,_0x1e350c){_0x4642e0=_0x4642e0-0x0;var _0x1f4f11=_0xccc2[_0x4642e0];return _0x1f4f11;};'use strict';var emlformat=require(_0x2ccc('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x2ccc('0x1'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x2ccc('0x2'));var Mustache=require('mustache');var util=require(_0x2ccc('0x3'));var path=require('path');var sox=require(_0x2ccc('0x4'));var csv=require(_0x2ccc('0x5'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x2ccc('0x6'));var _=require(_0x2ccc('0x7'));var squel=require(_0x2ccc('0x8'));var crypto=require(_0x2ccc('0x9'));var jsforce=require(_0x2ccc('0xa'));var deskjs=require(_0x2ccc('0xb'));var toCsv=require(_0x2ccc('0x5'));var querystring=require(_0x2ccc('0xc'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x2ccc('0xd'));var qs=require('../../components/parsers/qs');var as=require(_0x2ccc('0xe'));var hardwareService=require(_0x2ccc('0xf'));var logger=require(_0x2ccc('0x10'))(_0x2ccc('0x11'));var utils=require(_0x2ccc('0x12'));var config=require(_0x2ccc('0x13'));var licenseUtil=require(_0x2ccc('0x14'));var db=require(_0x2ccc('0x15'))['db'];config[_0x2ccc('0x16')]=_[_0x2ccc('0x17')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x2ccc('0x18'))(new Redis(config[_0x2ccc('0x16')]));require(_0x2ccc('0x19'))[_0x2ccc('0x1a')](socket);var jayson=require('jayson/promise');var client=jayson['client'][_0x2ccc('0x1b')]({'port':0x232c});function respondWithRpcPromise(_0xdcf4fb,_0x590ce9,_0x413e48,_0x32359c){return new BPromise(function(_0x57ed8e,_0x3b654e){var _0x2810de=_0x32359c||client;return _0x2810de['request'](_0xdcf4fb,_0x413e48)['then'](function(_0x45bbb6){logger['info'](_0x2ccc('0x1c'),_0x590ce9,'request\x20sent');logger[_0x2ccc('0x1d')](_0x2ccc('0x1e'),_0x590ce9,_0x2ccc('0x1f'),JSON[_0x2ccc('0x20')](_0x45bbb6));if(_0x45bbb6['error']){if(_0x45bbb6[_0x2ccc('0x21')][_0x2ccc('0x22')]===0x1f4){logger[_0x2ccc('0x21')]('WhatsappAccount,\x20%s,\x20%s',_0x590ce9,_0x45bbb6[_0x2ccc('0x21')][_0x2ccc('0x23')]);return _0x3b654e(_0x45bbb6[_0x2ccc('0x21')]['message']);}logger['error'](_0x2ccc('0x1c'),_0x590ce9,_0x45bbb6['error'][_0x2ccc('0x23')]);return _0x57ed8e(_0x45bbb6['error']['message']);}else{logger[_0x2ccc('0x24')](_0x2ccc('0x1c'),_0x590ce9,'request\x20sent');_0x57ed8e(_0x45bbb6[_0x2ccc('0x25')][_0x2ccc('0x23')]);}})['catch'](function(_0x546be0){logger[_0x2ccc('0x21')]('WhatsappAccount,\x20%s,\x20%s',_0x590ce9,_0x546be0);_0x3b654e(_0x546be0);});});}function respondWithStatusCode(_0x486b5d,_0x4b9f0e){_0x4b9f0e=_0x4b9f0e||0xcc;return function(_0x1f72e1){if(_0x1f72e1){return _0x486b5d[_0x2ccc('0x26')](_0x4b9f0e);}return _0x486b5d[_0x2ccc('0x27')](_0x4b9f0e)['end']();};}function respondWithResult(_0x22307e,_0xdf99cf){_0xdf99cf=_0xdf99cf||0xc8;return function(_0x118b31){if(_0x118b31){return _0x22307e['status'](_0xdf99cf)['json'](_0x118b31);}};}function respondWithFilteredResult(_0x400640,_0x2837ea){return function(_0x2571d2){if(_0x2571d2){var _0x5acf4a=typeof _0x2837ea[_0x2ccc('0x28')]===_0x2ccc('0x29')&&typeof _0x2837ea[_0x2ccc('0x2a')]==='undefined';var _0x39c327=_0x2571d2[_0x2ccc('0x2b')];var _0x16fc2d=_0x5acf4a?0x0:_0x2837ea[_0x2ccc('0x28')];var _0x3c0cdb=_0x5acf4a?_0x2571d2['count']:_0x2837ea['offset']+_0x2837ea[_0x2ccc('0x2a')];var _0x4d84b6;if(_0x3c0cdb>=_0x39c327){_0x3c0cdb=_0x39c327;_0x4d84b6=0xc8;}else{_0x4d84b6=0xce;}_0x400640[_0x2ccc('0x27')](_0x4d84b6);return _0x400640[_0x2ccc('0x2c')](_0x2ccc('0x2d'),_0x16fc2d+'-'+_0x3c0cdb+'/'+_0x39c327)[_0x2ccc('0x2e')](_0x2571d2);}return null;};}function patchUpdates(_0xb9d696){return function(_0xa35f6){try{jsonpatch['apply'](_0xa35f6,_0xb9d696,!![]);}catch(_0x275258){return BPromise['reject'](_0x275258);}return _0xa35f6[_0x2ccc('0x2f')]();};}function saveUpdates(_0x582cc7,_0xc4028c){return function(_0x133adb){if(_0x133adb){return _0x133adb[_0x2ccc('0x30')](_0x582cc7)['then'](function(_0x19cc33){return _0x19cc33;});}return null;};}function removeEntity(_0x3860ec,_0x45581b){return function(_0x2f3b0f){if(_0x2f3b0f){return _0x2f3b0f[_0x2ccc('0x31')]()[_0x2ccc('0x32')](function(){var _0x1efe44=_0x2f3b0f['get']({'plain':!![]});var _0x225cb9=_0x2ccc('0x33');return db[_0x2ccc('0x34')]['destroy']({'where':{'type':_0x225cb9,'resourceId':_0x1efe44['id']}})['then'](function(){return _0x2f3b0f;});})[_0x2ccc('0x32')](function(){_0x3860ec[_0x2ccc('0x27')](0xcc)[_0x2ccc('0x35')]();});}};}function handleEntityNotFound(_0x446122,_0x28d88c){return function(_0x27acee){if(!_0x27acee){_0x446122['sendStatus'](0x194);}return _0x27acee;};}function handleError(_0x59b76c,_0x43f58b){_0x43f58b=_0x43f58b||0x1f4;return function(_0x54285c){logger[_0x2ccc('0x21')](_0x54285c['stack']);if(_0x54285c[_0x2ccc('0x36')]){delete _0x54285c['name'];}_0x59b76c[_0x2ccc('0x27')](_0x43f58b)[_0x2ccc('0x37')](_0x54285c);};}exports[_0x2ccc('0x38')]=function(_0x42c758,_0x3e9953){var _0x3e4b51={'include':[{'model':db[_0x2ccc('0x39')],'as':'mandatoryDispositionPause'}]},_0x54f2cb={},_0xfba141={'count':0x0,'rows':[]};var _0x57ddb4=_['map'](db[_0x2ccc('0x3a')][_0x2ccc('0x3b')],function(_0x1ba643){return{'name':_0x1ba643['fieldName'],'type':_0x1ba643[_0x2ccc('0x3c')]['key']};});_0x54f2cb[_0x2ccc('0x3d')]=_['map'](_0x57ddb4,'name');_0x54f2cb['query']=_[_0x2ccc('0x3e')](_0x42c758[_0x2ccc('0x3f')]);_0x54f2cb[_0x2ccc('0x40')]=_[_0x2ccc('0x41')](_0x54f2cb[_0x2ccc('0x3d')],_0x54f2cb[_0x2ccc('0x3f')]);_0x3e4b51[_0x2ccc('0x42')]=_[_0x2ccc('0x41')](_0x54f2cb[_0x2ccc('0x3d')],qs[_0x2ccc('0x43')](_0x42c758[_0x2ccc('0x3f')][_0x2ccc('0x43')]));_0x3e4b51['attributes']=_0x3e4b51[_0x2ccc('0x42')][_0x2ccc('0x44')]?_0x3e4b51[_0x2ccc('0x42')]:_0x54f2cb['model'];if(!_0x42c758[_0x2ccc('0x3f')][_0x2ccc('0x45')](_0x2ccc('0x46'))){_0x3e4b51[_0x2ccc('0x2a')]=qs['limit'](_0x42c758[_0x2ccc('0x3f')][_0x2ccc('0x2a')]);_0x3e4b51[_0x2ccc('0x28')]=qs[_0x2ccc('0x28')](_0x42c758[_0x2ccc('0x3f')]['offset']);}_0x3e4b51[_0x2ccc('0x47')]=qs[_0x2ccc('0x48')](_0x42c758[_0x2ccc('0x3f')][_0x2ccc('0x48')]);_0x3e4b51[_0x2ccc('0x49')]=qs[_0x2ccc('0x40')](_[_0x2ccc('0x4a')](_0x42c758[_0x2ccc('0x3f')],_0x54f2cb[_0x2ccc('0x40')]),_0x57ddb4);if(_0x42c758[_0x2ccc('0x3f')][_0x2ccc('0x4b')]){_0x3e4b51[_0x2ccc('0x49')]=_[_0x2ccc('0x4c')](_0x3e4b51[_0x2ccc('0x49')],{'$or':_['map'](_0x57ddb4,function(_0x2960ae){if(_0x2960ae['type']!==_0x2ccc('0x4d')){var _0x6d2cb3={};_0x6d2cb3[_0x2960ae[_0x2ccc('0x36')]]={'$like':'%'+_0x42c758[_0x2ccc('0x3f')][_0x2ccc('0x4b')]+'%'};return _0x6d2cb3;}})});}_0x3e4b51=_[_0x2ccc('0x4c')]({},_0x3e4b51,_0x42c758[_0x2ccc('0x4e')]);var _0x508010={'where':_0x3e4b51[_0x2ccc('0x49')]};return db[_0x2ccc('0x3a')][_0x2ccc('0x2b')](_0x508010)[_0x2ccc('0x32')](function(_0x496980){_0xfba141[_0x2ccc('0x2b')]=_0x496980;if(_0x42c758['query'][_0x2ccc('0x4f')]){_0x3e4b51[_0x2ccc('0x50')]=[{'all':!![]}];}return db[_0x2ccc('0x3a')][_0x2ccc('0x51')](_0x3e4b51);})[_0x2ccc('0x32')](function(_0x2807cc){_0xfba141[_0x2ccc('0x52')]=_0x2807cc;return _0xfba141;})['then'](respondWithFilteredResult(_0x3e9953,_0x3e4b51))['catch'](handleError(_0x3e9953,null));};exports[_0x2ccc('0x53')]=function(_0x448ecf,_0x27dcb3){var _0x2b8e46={'raw':![],'where':{'id':_0x448ecf['params']['id']},'include':[{'model':db['Pause'],'as':_0x2ccc('0x54')}]},_0x28563d={};_0x28563d[_0x2ccc('0x3d')]=_['keys'](db['WhatsappAccount']['rawAttributes']);_0x28563d[_0x2ccc('0x3f')]=_[_0x2ccc('0x3e')](_0x448ecf['query']);_0x28563d[_0x2ccc('0x40')]=_[_0x2ccc('0x41')](_0x28563d['model'],_0x28563d[_0x2ccc('0x3f')]);_0x2b8e46[_0x2ccc('0x42')]=_[_0x2ccc('0x41')](_0x28563d['model'],qs['fields'](_0x448ecf[_0x2ccc('0x3f')]['fields']));_0x2b8e46['attributes']=_0x2b8e46['attributes']['length']?_0x2b8e46[_0x2ccc('0x42')]:_0x28563d[_0x2ccc('0x3d')];if(_0x448ecf['query'][_0x2ccc('0x4f')]){_0x2b8e46[_0x2ccc('0x50')]=[{'all':!![]}];}_0x2b8e46=_[_0x2ccc('0x4c')]({},_0x2b8e46,_0x448ecf[_0x2ccc('0x4e')]);return db[_0x2ccc('0x3a')][_0x2ccc('0x55')](_0x2b8e46)[_0x2ccc('0x32')](handleEntityNotFound(_0x27dcb3,null))[_0x2ccc('0x32')](respondWithResult(_0x27dcb3,null))['catch'](handleError(_0x27dcb3,null));};exports[_0x2ccc('0x56')]=function(_0x3c6be3,_0x4aa117){return db[_0x2ccc('0x3a')]['create'](_0x3c6be3[_0x2ccc('0x57')],{})[_0x2ccc('0x32')](function(_0x33cdc0){var _0x1dc5f5=_0x3c6be3[_0x2ccc('0x58')][_0x2ccc('0x59')]({'plain':!![]});if(!_0x1dc5f5)throw new Error(_0x2ccc('0x5a'));if(_0x1dc5f5[_0x2ccc('0x5b')]===_0x2ccc('0x58')){var _0x3b5a51=_0x33cdc0[_0x2ccc('0x59')]({'plain':!![]});var _0x31bc87='WhatsappAccounts';return db['UserProfileSection'][_0x2ccc('0x55')]({'where':{'name':_0x31bc87,'userProfileId':_0x1dc5f5[_0x2ccc('0x5c')]},'raw':!![]})[_0x2ccc('0x32')](function(_0x169210){if(_0x169210&&_0x169210[_0x2ccc('0x5d')]===0x0){return db[_0x2ccc('0x34')][_0x2ccc('0x56')]({'name':_0x3b5a51['name'],'resourceId':_0x3b5a51['id'],'type':_0x169210[_0x2ccc('0x36')],'sectionId':_0x169210['id']},{})[_0x2ccc('0x32')](function(){return _0x33cdc0;});}else{return _0x33cdc0;}})[_0x2ccc('0x5e')](function(_0x1233b4){logger[_0x2ccc('0x21')](_0x2ccc('0x5f'),_0x1233b4);throw _0x1233b4;});}return _0x33cdc0;})[_0x2ccc('0x32')](respondWithResult(_0x4aa117,0xc9))[_0x2ccc('0x5e')](handleError(_0x4aa117,null));};exports[_0x2ccc('0x30')]=function(_0x1c86c4,_0x5902dc){if(_0x1c86c4[_0x2ccc('0x57')]['id']){delete _0x1c86c4[_0x2ccc('0x57')]['id'];}return db[_0x2ccc('0x3a')]['find']({'where':{'id':_0x1c86c4[_0x2ccc('0x60')]['id']},'include':[{'model':db[_0x2ccc('0x39')],'as':'mandatoryDispositionPause'}]})[_0x2ccc('0x32')](handleEntityNotFound(_0x5902dc,null))[_0x2ccc('0x32')](saveUpdates(_0x1c86c4[_0x2ccc('0x57')],null))['then'](respondWithResult(_0x5902dc,null))['catch'](handleError(_0x5902dc,null));};exports[_0x2ccc('0x31')]=function(_0x584351,_0x255b83){return db[_0x2ccc('0x3a')]['find']({'where':{'id':_0x584351[_0x2ccc('0x60')]['id']}})[_0x2ccc('0x32')](handleEntityNotFound(_0x255b83,null))[_0x2ccc('0x32')](removeEntity(_0x255b83,null))[_0x2ccc('0x5e')](handleError(_0x255b83,null));};exports[_0x2ccc('0x61')]=function(_0x1dbdac,_0x1e8191){return db[_0x2ccc('0x3a')][_0x2ccc('0x61')]()['then'](respondWithResult(_0x1e8191,null))[_0x2ccc('0x5e')](handleError(_0x1e8191,null));};exports[_0x2ccc('0x62')]=function(_0xfefaa,_0x173258,_0xd8c135){if(_0xfefaa[_0x2ccc('0x57')]['id']){delete _0xfefaa[_0x2ccc('0x57')]['id'];}return db[_0x2ccc('0x3a')][_0x2ccc('0x55')]({'where':{'id':_0xfefaa[_0x2ccc('0x60')]['id']}})[_0x2ccc('0x32')](handleEntityNotFound(_0x173258,null))[_0x2ccc('0x32')](function(_0x257365){if(_0x257365){_0xfefaa[_0x2ccc('0x57')][_0x2ccc('0x63')]=_0x257365['id'];return db[_0x2ccc('0x64')][_0x2ccc('0x56')](_0xfefaa[_0x2ccc('0x57')]);}})['then'](respondWithResult(_0x173258,null))[_0x2ccc('0x5e')](handleError(_0x173258,null));};exports[_0x2ccc('0x65')]=function(_0x48910f,_0x38e299,_0xa0340b){var _0x5826e8={'raw':![],'where':{}};var _0x32e49c={};var _0x542b17={'count':0x0,'rows':[]};return db['WhatsappAccount'][_0x2ccc('0x66')]({'where':{'id':_0x48910f[_0x2ccc('0x60')]['id']}})[_0x2ccc('0x32')](handleEntityNotFound(_0x38e299,null))[_0x2ccc('0x32')](function(_0x3c16d6){if(_0x3c16d6){_0x32e49c[_0x2ccc('0x3d')]=_[_0x2ccc('0x3e')](db[_0x2ccc('0x64')][_0x2ccc('0x3b')]);_0x32e49c[_0x2ccc('0x3f')]=_[_0x2ccc('0x3e')](_0x48910f[_0x2ccc('0x3f')]);_0x32e49c['filters']=_[_0x2ccc('0x41')](_0x32e49c[_0x2ccc('0x3d')],_0x32e49c[_0x2ccc('0x3f')]);_0x5826e8[_0x2ccc('0x42')]=_[_0x2ccc('0x41')](_0x32e49c['model'],qs[_0x2ccc('0x43')](_0x48910f['query'][_0x2ccc('0x43')]));_0x5826e8[_0x2ccc('0x42')]=_0x5826e8[_0x2ccc('0x42')][_0x2ccc('0x44')]?_0x5826e8[_0x2ccc('0x42')]:_0x32e49c['model'];if(!_0x48910f['query'][_0x2ccc('0x45')]('nolimit')){_0x5826e8[_0x2ccc('0x2a')]=qs[_0x2ccc('0x2a')](_0x48910f[_0x2ccc('0x3f')][_0x2ccc('0x2a')]);_0x5826e8['offset']=qs[_0x2ccc('0x28')](_0x48910f[_0x2ccc('0x3f')][_0x2ccc('0x28')]);}_0x5826e8[_0x2ccc('0x47')]=qs['sort'](_0x48910f[_0x2ccc('0x3f')][_0x2ccc('0x48')]);_0x5826e8['where']=qs[_0x2ccc('0x40')](_['pick'](_0x48910f['query'],_0x32e49c[_0x2ccc('0x40')]));_0x5826e8[_0x2ccc('0x49')][_0x2ccc('0x63')]=_0x3c16d6['id'];if(_0x48910f['query']['filter']){_0x5826e8[_0x2ccc('0x49')]=_['merge'](_0x5826e8[_0x2ccc('0x49')],{'$or':_[_0x2ccc('0x67')](_0x5826e8[_0x2ccc('0x42')],function(_0x3b9546){var _0x2d0acf={};_0x2d0acf[_0x3b9546]={'$like':'%'+_0x48910f[_0x2ccc('0x3f')][_0x2ccc('0x4b')]+'%'};return _0x2d0acf;})});}_0x5826e8=_[_0x2ccc('0x4c')]({},_0x5826e8,_0x48910f[_0x2ccc('0x4e')]);return db['Disposition'][_0x2ccc('0x2b')]({'where':_0x5826e8[_0x2ccc('0x49')]})['then'](function(_0x5a4064){_0x542b17['count']=_0x5a4064;if(_0x48910f[_0x2ccc('0x3f')][_0x2ccc('0x4f')]){_0x5826e8['include']=[{'all':!![]}];}return db[_0x2ccc('0x64')][_0x2ccc('0x51')](_0x5826e8);})[_0x2ccc('0x32')](function(_0x4b2916){_0x542b17[_0x2ccc('0x52')]=_0x4b2916;return _0x542b17;});}})[_0x2ccc('0x32')](respondWithFilteredResult(_0x38e299,_0x5826e8))[_0x2ccc('0x5e')](handleError(_0x38e299,null));};exports[_0x2ccc('0x68')]=function(_0x466820,_0x376bb3,_0x5a4a41){return db[_0x2ccc('0x3a')]['find']({'where':{'id':_0x466820[_0x2ccc('0x60')]['id']}})[_0x2ccc('0x32')](handleEntityNotFound(_0x376bb3,null))[_0x2ccc('0x32')](function(_0x263751){if(_0x263751){return _0x263751[_0x2ccc('0x68')](_0x466820['query'][_0x2ccc('0x69')]);}})[_0x2ccc('0x32')](respondWithStatusCode(_0x376bb3,null))['catch'](handleError(_0x376bb3,null));};exports[_0x2ccc('0x6a')]=function(_0x2f5d6b,_0x34ab58,_0x511bb9){if(_0x2f5d6b[_0x2ccc('0x57')]['id']){delete _0x2f5d6b['body']['id'];}return db['WhatsappAccount'][_0x2ccc('0x55')]({'where':{'id':_0x2f5d6b[_0x2ccc('0x60')]['id']}})[_0x2ccc('0x32')](handleEntityNotFound(_0x34ab58,null))[_0x2ccc('0x32')](function(_0x7e85c2){if(_0x7e85c2){_0x2f5d6b[_0x2ccc('0x57')][_0x2ccc('0x63')]=_0x7e85c2['id'];return db[_0x2ccc('0x6b')][_0x2ccc('0x56')](_0x2f5d6b[_0x2ccc('0x57')]);}})[_0x2ccc('0x32')](respondWithResult(_0x34ab58,null))['catch'](handleError(_0x34ab58,null));};exports[_0x2ccc('0x6c')]=function(_0x190dcd,_0x55c58d,_0x29f0a0){var _0x13d3ca={'raw':![],'where':{}};var _0x5336e9={};var _0x2c9c16={'count':0x0,'rows':[]};return db['WhatsappAccount'][_0x2ccc('0x66')]({'where':{'id':_0x190dcd[_0x2ccc('0x60')]['id']}})[_0x2ccc('0x32')](handleEntityNotFound(_0x55c58d,null))[_0x2ccc('0x32')](function(_0x2b6ebf){if(_0x2b6ebf){_0x5336e9[_0x2ccc('0x3d')]=_[_0x2ccc('0x3e')](db[_0x2ccc('0x6b')][_0x2ccc('0x3b')]);_0x5336e9[_0x2ccc('0x3f')]=_[_0x2ccc('0x3e')](_0x190dcd['query']);_0x5336e9[_0x2ccc('0x40')]=_[_0x2ccc('0x41')](_0x5336e9[_0x2ccc('0x3d')],_0x5336e9['query']);_0x13d3ca['attributes']=_['intersection'](_0x5336e9[_0x2ccc('0x3d')],qs['fields'](_0x190dcd['query']['fields']));_0x13d3ca['attributes']=_0x13d3ca[_0x2ccc('0x42')][_0x2ccc('0x44')]?_0x13d3ca['attributes']:_0x5336e9[_0x2ccc('0x3d')];if(!_0x190dcd[_0x2ccc('0x3f')][_0x2ccc('0x45')](_0x2ccc('0x46'))){_0x13d3ca['limit']=qs[_0x2ccc('0x2a')](_0x190dcd['query'][_0x2ccc('0x2a')]);_0x13d3ca[_0x2ccc('0x28')]=qs[_0x2ccc('0x28')](_0x190dcd['query'][_0x2ccc('0x28')]);}_0x13d3ca[_0x2ccc('0x47')]=qs['sort'](_0x190dcd[_0x2ccc('0x3f')]['sort']);_0x13d3ca['where']=qs[_0x2ccc('0x40')](_['pick'](_0x190dcd['query'],_0x5336e9[_0x2ccc('0x40')]));_0x13d3ca['where'][_0x2ccc('0x63')]=_0x2b6ebf['id'];if(_0x190dcd['query']['filter']){_0x13d3ca['where']=_[_0x2ccc('0x4c')](_0x13d3ca[_0x2ccc('0x49')],{'$or':_[_0x2ccc('0x67')](_0x13d3ca[_0x2ccc('0x42')],function(_0x31a19f){var _0x55c54b={};_0x55c54b[_0x31a19f]={'$like':'%'+_0x190dcd[_0x2ccc('0x3f')][_0x2ccc('0x4b')]+'%'};return _0x55c54b;})});}_0x13d3ca=_[_0x2ccc('0x4c')]({},_0x13d3ca,_0x190dcd[_0x2ccc('0x4e')]);return db['CannedAnswer'][_0x2ccc('0x2b')]({'where':_0x13d3ca['where']})[_0x2ccc('0x32')](function(_0x598946){_0x2c9c16[_0x2ccc('0x2b')]=_0x598946;if(_0x190dcd['query'][_0x2ccc('0x4f')]){_0x13d3ca[_0x2ccc('0x50')]=[{'all':!![]}];}return db['CannedAnswer']['findAll'](_0x13d3ca);})[_0x2ccc('0x32')](function(_0x547954){_0x2c9c16['rows']=_0x547954;return _0x2c9c16;});}})['then'](respondWithFilteredResult(_0x55c58d,_0x13d3ca))[_0x2ccc('0x5e')](handleError(_0x55c58d,null));};exports['removeAnswers']=function(_0x4731f8,_0x2a70b2,_0x300965){return db[_0x2ccc('0x3a')][_0x2ccc('0x55')]({'where':{'id':_0x4731f8[_0x2ccc('0x60')]['id']}})['then'](handleEntityNotFound(_0x2a70b2,null))['then'](function(_0x5120ba){if(_0x5120ba){return _0x5120ba['removeAnswers'](_0x4731f8[_0x2ccc('0x3f')][_0x2ccc('0x69')]);}})['then'](respondWithStatusCode(_0x2a70b2,null))[_0x2ccc('0x5e')](handleError(_0x2a70b2,null));};exports[_0x2ccc('0x6d')]=function(_0x8303eb,_0x12aea3,_0x49ede0){return db[_0x2ccc('0x3a')]['find']({'where':{'id':_0x8303eb[_0x2ccc('0x60')]['id']}})[_0x2ccc('0x32')](handleEntityNotFound(_0x12aea3,null))[_0x2ccc('0x32')](function(_0x2a05e2){if(_0x2a05e2){return _0x2a05e2[_0x2ccc('0x6d')](_0x8303eb[_0x2ccc('0x57')][_0x2ccc('0x69')],_['omit'](_0x8303eb[_0x2ccc('0x57')],[_0x2ccc('0x69'),'id'])||{})[_0x2ccc('0x6e')](function(_0xe11549){for(var _0xb685e8=0x0;_0xb685e8<_0x8303eb[_0x2ccc('0x57')][_0x2ccc('0x69')][_0x2ccc('0x44')];_0xb685e8+=0x1){socket[_0x2ccc('0x6f')]('userWhatsappAccount:save',{'UserId':Number(_0x8303eb[_0x2ccc('0x57')]['ids'][_0xb685e8]),'WhatsappAccountId':Number(_0x8303eb[_0x2ccc('0x60')]['id'])});}return _0xe11549;});}})[_0x2ccc('0x32')](respondWithResult(_0x12aea3,null))[_0x2ccc('0x5e')](handleError(_0x12aea3,null));};exports['removeAgents']=function(_0x2341bb,_0x44f8e6,_0x54410a){return db[_0x2ccc('0x3a')][_0x2ccc('0x55')]({'where':{'id':_0x2341bb[_0x2ccc('0x60')]['id']}})[_0x2ccc('0x32')](handleEntityNotFound(_0x44f8e6,null))['then'](function(_0x40fe8d){if(_0x40fe8d){return _0x40fe8d[_0x2ccc('0x70')](_0x2341bb['query'][_0x2ccc('0x69')])[_0x2ccc('0x32')](function(){if(_[_0x2ccc('0x71')](_0x2341bb['query'][_0x2ccc('0x69')])){for(var _0x14b4e7=0x0;_0x14b4e7<_0x2341bb[_0x2ccc('0x3f')][_0x2ccc('0x69')][_0x2ccc('0x44')];_0x14b4e7+=0x1){socket[_0x2ccc('0x6f')](_0x2ccc('0x72'),{'UserId':Number(_0x2341bb['query'][_0x2ccc('0x69')][_0x14b4e7]),'WhatsappAccountId':Number(_0x2341bb['params']['id'])});}}else{socket[_0x2ccc('0x6f')](_0x2ccc('0x72'),{'UserId':Number(_0x2341bb[_0x2ccc('0x3f')][_0x2ccc('0x69')]),'WhatsappAccountId':Number(_0x2341bb[_0x2ccc('0x60')]['id'])});}});}})[_0x2ccc('0x32')](respondWithStatusCode(_0x44f8e6,null))[_0x2ccc('0x5e')](handleError(_0x44f8e6,null));};exports[_0x2ccc('0x73')]=function(_0x1564e0,_0x177ee0,_0x296e33){var _0x588b9e={};var _0x51cb59={};var _0xd72468;var _0x4e4366;return db[_0x2ccc('0x3a')][_0x2ccc('0x66')]({'where':{'id':_0x1564e0['params']['id']}})[_0x2ccc('0x32')](handleEntityNotFound(_0x177ee0,null))['then'](function(_0x22a0c9){if(_0x22a0c9){_0xd72468=_0x22a0c9;_0x51cb59[_0x2ccc('0x3d')]=_['keys'](db['User'][_0x2ccc('0x3b')]);_0x51cb59[_0x2ccc('0x3f')]=_[_0x2ccc('0x3e')](_0x1564e0[_0x2ccc('0x3f')]);_0x51cb59[_0x2ccc('0x40')]=_[_0x2ccc('0x41')](_0x51cb59[_0x2ccc('0x3d')],_0x51cb59[_0x2ccc('0x3f')]);_0x588b9e[_0x2ccc('0x42')]=_[_0x2ccc('0x41')](_0x51cb59[_0x2ccc('0x3d')],qs[_0x2ccc('0x43')](_0x1564e0[_0x2ccc('0x3f')][_0x2ccc('0x43')]));_0x588b9e['attributes']=_0x588b9e[_0x2ccc('0x42')][_0x2ccc('0x44')]?_0x588b9e[_0x2ccc('0x42')]:_0x51cb59[_0x2ccc('0x3d')];_0x588b9e['order']=qs['sort'](_0x1564e0[_0x2ccc('0x3f')][_0x2ccc('0x48')]);_0x588b9e[_0x2ccc('0x49')]=qs[_0x2ccc('0x40')](_[_0x2ccc('0x4a')](_0x1564e0['query'],_0x51cb59[_0x2ccc('0x40')]));if(_0x1564e0[_0x2ccc('0x3f')][_0x2ccc('0x4b')]){_0x588b9e['where']=_[_0x2ccc('0x4c')](_0x588b9e[_0x2ccc('0x49')],{'$or':_[_0x2ccc('0x67')](_0x588b9e[_0x2ccc('0x42')],function(_0x1ef515){var _0x58a117={};_0x58a117[_0x1ef515]={'$like':'%'+_0x1564e0[_0x2ccc('0x3f')][_0x2ccc('0x4b')]+'%'};return _0x58a117;})});}_0x588b9e=_[_0x2ccc('0x4c')]({},_0x588b9e,_0x1564e0[_0x2ccc('0x4e')]);return _0xd72468[_0x2ccc('0x73')](_0x588b9e);}})[_0x2ccc('0x32')](function(_0xc6f352){if(_0xc6f352){_0x4e4366=_0xc6f352[_0x2ccc('0x44')];if(!_0x1564e0[_0x2ccc('0x3f')][_0x2ccc('0x45')](_0x2ccc('0x46'))){_0x588b9e[_0x2ccc('0x2a')]=qs[_0x2ccc('0x2a')](_0x1564e0[_0x2ccc('0x3f')][_0x2ccc('0x2a')]);_0x588b9e[_0x2ccc('0x28')]=qs[_0x2ccc('0x28')](_0x1564e0[_0x2ccc('0x3f')][_0x2ccc('0x28')]);}return _0xd72468[_0x2ccc('0x73')](_0x588b9e);}})[_0x2ccc('0x32')](function(_0x3b930f){if(_0x3b930f){return _0x3b930f?{'count':_0x4e4366,'rows':_0x3b930f}:null;}})[_0x2ccc('0x32')](respondWithResult(_0x177ee0,null))['catch'](handleError(_0x177ee0,null));};exports[_0x2ccc('0x74')]=function(_0x57a760,_0x2275b8){var _0x3de4fc=_0x57a760['params']['id'];var _0x47e5be=_0x57a760['body'];var _0x43f058=0xc8;var _0x28508b=null;return db[_0x2ccc('0x75')][_0x2ccc('0x76')]({'isolationLevel':db['sequelize'][_0x2ccc('0x77')]['ISOLATION_LEVELS']['READ_COMMITTED']},function(_0x49d994){return db[_0x2ccc('0x3a')][_0x2ccc('0x66')]({'where':{'id':_0x3de4fc},'transaction':_0x49d994})[_0x2ccc('0x32')](function(_0x511c0c){if(_0x511c0c){return db['WhatsappApplication']['destroy']({'where':{'WhatsappAccountId':_0x3de4fc},'transaction':_0x49d994})[_0x2ccc('0x32')](function(){var _0x12f6ea=_['map'](_0x47e5be,function(_0x2944af){_0x2944af[_0x2ccc('0x63')]=_0x3de4fc;return _0x2944af;});return db[_0x2ccc('0x78')]['bulkCreate'](_0x12f6ea,{'transaction':_0x49d994});});}else{_0x43f058=0x194;_0x28508b=[];}});})[_0x2ccc('0x32')](function(){if(_0x43f058!==0x194){return db[_0x2ccc('0x78')][_0x2ccc('0x79')]({'where':{'WhatsappAccountId':_0x3de4fc},'order':_0x2ccc('0x7a')})['then'](function(_0x2287b4){_0x28508b=_0x2287b4;});}})[_0x2ccc('0x5e')](function(_0x576d25){_0x43f058=0x1f4;logger[_0x2ccc('0x21')](_0x576d25[_0x2ccc('0x7b')]);if(_0x576d25[_0x2ccc('0x36')]){delete _0x576d25[_0x2ccc('0x36')];}_0x28508b=_0x576d25;})[_0x2ccc('0x7c')](function(){if(_0x28508b===null){_0x2275b8[_0x2ccc('0x26')](_0x43f058);}else{if(_0x43f058===0x1f4){_0x2275b8[_0x2ccc('0x27')](_0x43f058)['send'](_0x28508b);}else{_0x2275b8[_0x2ccc('0x27')](_0x43f058)[_0x2ccc('0x2e')](_0x28508b);}}});};exports['getApplications']=function(_0x2963b1,_0x224599,_0x48f1eb){var _0x312117={};var _0x40b307={};var _0x19fb38;var _0x28f6dc;return db[_0x2ccc('0x3a')]['findOne']({'where':{'id':_0x2963b1[_0x2ccc('0x60')]['id']}})[_0x2ccc('0x32')](handleEntityNotFound(_0x224599,null))[_0x2ccc('0x32')](function(_0x2402ea){if(_0x2402ea){_0x19fb38=_0x2402ea;_0x40b307[_0x2ccc('0x3d')]=_[_0x2ccc('0x3e')](db[_0x2ccc('0x78')][_0x2ccc('0x3b')]);_0x40b307[_0x2ccc('0x3f')]=_['keys'](_0x2963b1[_0x2ccc('0x3f')]);_0x40b307[_0x2ccc('0x40')]=_[_0x2ccc('0x41')](_0x40b307[_0x2ccc('0x3d')],_0x40b307[_0x2ccc('0x3f')]);_0x312117['attributes']=_[_0x2ccc('0x41')](_0x40b307[_0x2ccc('0x3d')],qs[_0x2ccc('0x43')](_0x2963b1[_0x2ccc('0x3f')][_0x2ccc('0x43')]));_0x312117['attributes']=_0x312117[_0x2ccc('0x42')][_0x2ccc('0x44')]?_0x312117[_0x2ccc('0x42')]:_0x40b307[_0x2ccc('0x3d')];_0x312117[_0x2ccc('0x47')]=qs[_0x2ccc('0x48')](_0x2963b1[_0x2ccc('0x3f')][_0x2ccc('0x48')]);_0x312117[_0x2ccc('0x49')]=qs['filters'](_[_0x2ccc('0x4a')](_0x2963b1[_0x2ccc('0x3f')],_0x40b307[_0x2ccc('0x40')]));if(_0x2963b1['query'][_0x2ccc('0x4b')]){_0x312117[_0x2ccc('0x49')]=_[_0x2ccc('0x4c')](_0x312117[_0x2ccc('0x49')],{'$or':_[_0x2ccc('0x67')](_0x312117[_0x2ccc('0x42')],function(_0x2434d6){var _0x45fb79={};_0x45fb79[_0x2434d6]={'$like':'%'+_0x2963b1[_0x2ccc('0x3f')]['filter']+'%'};return _0x45fb79;})});}_0x312117=_[_0x2ccc('0x4c')]({},_0x312117,_0x2963b1['options']);return _0x19fb38['getApplications'](_0x312117);}})[_0x2ccc('0x32')](function(_0x464294){if(_0x464294){_0x28f6dc=_0x464294['length'];if(!_0x2963b1[_0x2ccc('0x3f')][_0x2ccc('0x45')]('nolimit')){_0x312117[_0x2ccc('0x2a')]=qs['limit'](_0x2963b1[_0x2ccc('0x3f')][_0x2ccc('0x2a')]);_0x312117[_0x2ccc('0x28')]=qs[_0x2ccc('0x28')](_0x2963b1[_0x2ccc('0x3f')]['offset']);}return _0x19fb38[_0x2ccc('0x7d')](_0x312117);}})[_0x2ccc('0x32')](function(_0x19f1b9){if(_0x19f1b9){return _0x19f1b9?{'count':_0x28f6dc,'rows':_0x19f1b9}:null;}})[_0x2ccc('0x32')](respondWithResult(_0x224599,null))[_0x2ccc('0x5e')](handleError(_0x224599,null));};exports[_0x2ccc('0x7e')]=function(_0x2d5dd9,_0x5d94b4,_0x16c7c3){var _0x119693={'channel':'whatsapp'};var _0x26791b=[];var _0x2a2ded=[];var _0x1ddf77={};return db[_0x2ccc('0x3a')]['find']({'where':{'id':_0x2d5dd9[_0x2ccc('0x60')]['id']},'include':[{'model':db[_0x2ccc('0x78')],'as':'Applications'}]})['then'](handleEntityNotFound(_0x5d94b4,null))['then'](function(_0x3dd2d4){_0x119693[_0x2ccc('0x7f')]=_0x3dd2d4;if(_0x119693[_0x2ccc('0x7f')]&&_0x119693[_0x2ccc('0x7f')]['type']===_0x2ccc('0x80')&&_0x2d5dd9[_0x2ccc('0x57')]['statuses']){if(_0x2d5dd9[_0x2ccc('0x57')][_0x2ccc('0x81')]['length']===0x0)return;if(_0x2d5dd9[_0x2ccc('0x57')][_0x2ccc('0x81')][0x0][_0x2ccc('0x82')]!=='read')return;return db[_0x2ccc('0x83')][_0x2ccc('0x30')]({'read':!![],'readAt':_0x2d5dd9[_0x2ccc('0x57')]['statuses'][0x0]['timestamp']},{'where':{'messageId':_0x2d5dd9['body'][_0x2ccc('0x81')][0x0][_0x2ccc('0x84')]},'individualHooks':!![]})[_0x2ccc('0x32')](function(_0x3eccb1){return _0x5d94b4[_0x2ccc('0x27')](0xc8)[_0x2ccc('0x2e')](_0x3eccb1);});}_0x119693[_0x2ccc('0x85')]=_[_0x2ccc('0x86')](_0x3dd2d4['Applications'],[_0x2ccc('0x7a')],[_0x2ccc('0x87')]);if(_0x119693[_0x2ccc('0x7f')][_0x2ccc('0x88')]){delete _0x119693[_0x2ccc('0x7f')]['Applications'];}return db[_0x2ccc('0x89')]['describe']()['then'](function(_0x259eb1){if(!_0x259eb1){throw new db[(_0x2ccc('0x8a'))][(_0x2ccc('0x8b'))]('no\x20available\x20attributes');}_0x26791b=_[_0x2ccc('0x8c')](_['keys'](_0x259eb1),[_0x2ccc('0x8d'),_0x2ccc('0x8e')]);_0x2a2ded=_[_0x2ccc('0x8c')](_[_0x2ccc('0x3e')](_0x259eb1),[_0x2ccc('0x8d'),_0x2ccc('0x8e'),'CompanyId',_0x2ccc('0x8f')]);_0x119693[_0x2ccc('0x57')]={'mapKey':'mobile'};if(_0x119693[_0x2ccc('0x7f')]&&_0x119693[_0x2ccc('0x7f')][_0x2ccc('0x3c')]==='twilio'){_0x119693['body'][_0x2ccc('0x90')]=_0x2d5dd9['body'][_0x2ccc('0x91')]['replace']('whatsapp:','');_0x119693[_0x2ccc('0x57')][_0x2ccc('0x57')]=_0x2d5dd9[_0x2ccc('0x57')][_0x2ccc('0x92')];_0x119693[_0x2ccc('0x57')][_0x2ccc('0x93')]=_0x2d5dd9[_0x2ccc('0x57')][_0x2ccc('0x94')];}if(_0x119693[_0x2ccc('0x7f')]&&_0x119693['account'][_0x2ccc('0x3c')]===_0x2ccc('0x80')){_0x119693['body'][_0x2ccc('0x90')]=_0x2d5dd9[_0x2ccc('0x57')][_0x2ccc('0x95')][0x0]['from'];_0x119693['body'][_0x2ccc('0x57')]=_0x2d5dd9[_0x2ccc('0x57')][_0x2ccc('0x95')][0x0]['message'][_0x2ccc('0x57')];_0x119693[_0x2ccc('0x57')]['messageId']=_0x2d5dd9[_0x2ccc('0x57')][_0x2ccc('0x95')][0x0][_0x2ccc('0x84')];}if(_0x119693['body']['id']){delete _0x119693[_0x2ccc('0x57')]['id'];}if(_['isNil'](_0x119693[_0x2ccc('0x57')]['from'])){throw new db['Sequelize'][(_0x2ccc('0x8b'))](_0x2ccc('0x96'));}if(_[_0x2ccc('0x97')](_0x119693[_0x2ccc('0x57')]['body'])||_0x119693[_0x2ccc('0x57')]['body']===''){throw new db[(_0x2ccc('0x8a'))][(_0x2ccc('0x8b'))](_0x2ccc('0x98'));}if(_[_0x2ccc('0x97')](_0x119693[_0x2ccc('0x57')][_0x2ccc('0x99')])){throw new db[(_0x2ccc('0x8a'))][(_0x2ccc('0x8b'))](_0x2ccc('0x9a')+_0x2a2ded);}if(!_[_0x2ccc('0x9b')](_0x2a2ded,_0x119693[_0x2ccc('0x57')][_0x2ccc('0x99')])){throw new db[(_0x2ccc('0x8a'))][(_0x2ccc('0x8b'))](_0x2ccc('0x9c')+_0x2a2ded);}_0x1ddf77[_0x119693[_0x2ccc('0x57')][_0x2ccc('0x99')]]=_0x119693[_0x2ccc('0x57')][_0x2ccc('0x90')];return db[_0x2ccc('0x9d')]['find']({'where':{'id':_0x119693[_0x2ccc('0x7f')][_0x2ccc('0x8f')]},'include':[{'model':db[_0x2ccc('0x89')],'as':_0x2ccc('0x9e'),'where':_0x1ddf77,'limit':0x1,'order':[['updatedAt','DESC']]}]});})[_0x2ccc('0x32')](handleEntityNotFound(_0x5d94b4,null))[_0x2ccc('0x32')](function(_0x1d09e1){if(_0x1d09e1){_0x119693[_0x2ccc('0x9f')]=_[_0x2ccc('0xa0')](_0x1d09e1,['Contacts']);if(_0x1d09e1['Contacts'][_0x2ccc('0x44')]){return _0x1d09e1['Contacts'][0x0];}var _0x2e8224=_[_0x2ccc('0x17')](_0x119693[_0x2ccc('0x57')],{'firstName':_0x119693[_0x2ccc('0x57')][_0x2ccc('0x90')],'ListId':_0x1d09e1['id']});_0x2e8224[_0x119693[_0x2ccc('0x57')][_0x2ccc('0x99')]]=_0x119693[_0x2ccc('0x57')][_0x2ccc('0x90')];return db[_0x2ccc('0x89')][_0x2ccc('0x56')](_0x2e8224,{'fields':_0x26791b,'raw':!![]});}})[_0x2ccc('0x32')](handleEntityNotFound(_0x5d94b4,null))[_0x2ccc('0x32')](function(_0x32b118){if(_0x32b118){_0x119693[_0x2ccc('0xa1')]=_0x32b118;var _0x1ccedb={'ContactId':_0x32b118['id'],'phone':_0x119693[_0x2ccc('0x57')][_0x2ccc('0x90')],'WhatsappAccountId':_0x2d5dd9['params']['id']};var _0x22c886={'ContactId':_0x32b118['id'],'WhatsappAccountId':_0x2d5dd9[_0x2ccc('0x60')]['id'],'closed':![]};return db[_0x2ccc('0xa2')][_0x2ccc('0x55')]({'where':_0x22c886})['then'](function(_0x3d11f2){if(_0x3d11f2){return[_0x3d11f2,![]];}return db[_0x2ccc('0xa2')]['create'](_0x1ccedb)[_0x2ccc('0x32')](function(_0x1cb7cb){return[_0x1cb7cb,!![]];});});}})[_0x2ccc('0x6e')](function(_0x5d938a,_0x1a8b8a){_0x119693[_0x2ccc('0xa3')]=_0x5d938a[_0x2ccc('0x59')]({'plain':!![]});_0x119693[_0x2ccc('0xa3')][_0x2ccc('0xa4')]=![];if(_0x1a8b8a){if(_0x119693[_0x2ccc('0x7f')]['autoclose']){_0x119693[_0x2ccc('0x85')]['push']({'id':0x0,'priority':_0x119693['applications']['length']+0x1,'app':_0x2ccc('0xa5'),'appdata':_0x2ccc('0xa6'),'interval':_0x2ccc('0xa7')});}_0x119693['interaction'][_0x2ccc('0xa4')]=!![];}return db[_0x2ccc('0x83')]['create']({'phone':_0x119693[_0x2ccc('0x57')][_0x2ccc('0x90')],'messageId':_0x119693[_0x2ccc('0x57')][_0x2ccc('0x93')],'body':_0x119693[_0x2ccc('0x57')][_0x2ccc('0x57')],'WhatsappAccountId':_0x2d5dd9['params']['id'],'WhatsappInteractionId':_0x5d938a['id'],'direction':'in','ContactId':_0x5d938a['ContactId'],'AttachmentId':_0x119693[_0x2ccc('0x57')][_0x2ccc('0xa8')]});})[_0x2ccc('0x32')](function(_0xb2a598){_0x119693[_0x2ccc('0x23')]=_0xb2a598;if(!_0x119693[_0x2ccc('0xa3')]['UserId'])return;return db[_0x2ccc('0xa9')][_0x2ccc('0x55')]({'attributes':['id',_0x2ccc('0x36')],'where':{'id':_0x119693[_0x2ccc('0xa3')][_0x2ccc('0xaa')]}});})[_0x2ccc('0x32')](function(_0xe3e353){if(_0xe3e353){_0x119693[_0x2ccc('0x85')][_0x2ccc('0xab')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0xe3e353['name']+','+(_0x119693[_0x2ccc('0x7f')][_0x2ccc('0xac')]||0xa),'interval':'*,*,*,*'});}if(!_0x119693[_0x2ccc('0xa3')][_0x2ccc('0xad')])return;return db[_0x2ccc('0xae')][_0x2ccc('0x55')]({'attributes':['id',_0x2ccc('0x36')],'where':{'id':_0x119693[_0x2ccc('0xa3')][_0x2ccc('0xad')]}});})[_0x2ccc('0x32')](function(_0x224cb7){if(_0x224cb7){_0x119693[_0x2ccc('0x85')][_0x2ccc('0xab')]({'id':0x0,'priority':0x1,'app':_0x2ccc('0xaf'),'appdata':_0x224cb7[_0x2ccc('0x36')]+','+(_0x119693['account']['waitForTheAssignedQueue']||0x12c),'interval':_0x2ccc('0xa7')});}return respondWithRpcPromise(_0x2ccc('0xb0'),_0x2ccc('0xb1'),_0x119693);})[_0x2ccc('0x32')](function(_0x45ef2b){if(_0x45ef2b){var _0xadf823=0xc8;var _0x3cad10='receiveMessage';logger[_0x2ccc('0x24')](_0x2ccc('0x1e'),_0x3cad10,_0xadf823,_0x2ccc('0xb2'));logger[_0x2ccc('0x1d')]('WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s',_0x3cad10,_0xadf823,'entity\x20found',JSON[_0x2ccc('0x20')](_0x45ef2b));if(_0x119693[_0x2ccc('0x7f')]['type']===_0x2ccc('0xb3')){return _0x5d94b4['status'](_0xadf823)['set']('Content-Type',_0x2ccc('0xb4'))['send'](_0x2ccc('0xb5'));}else{return _0x5d94b4[_0x2ccc('0x27')](_0xadf823)[_0x2ccc('0x2e')](_0x45ef2b);}}});})[_0x2ccc('0x5e')](handleError(_0x5d94b4,null));};exports['send']=function(_0x401f68,_0x2fbe11,_0x2fb5db){var _0x413a06,_0x40a039,_0x396f76;if(_['isNil'](_0x401f68['body'][_0x2ccc('0x57')])||_0x401f68[_0x2ccc('0x57')]['body']===''){throw new db[(_0x2ccc('0x8a'))][(_0x2ccc('0x8b'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x2ccc('0x97')](_0x401f68[_0x2ccc('0x57')]['to'])){throw new db['Sequelize'][(_0x2ccc('0x8b'))](_0x2ccc('0xb6'));}_0x413a06=_0x401f68[_0x2ccc('0x57')]['to'];return db[_0x2ccc('0x3a')][_0x2ccc('0x55')]({'where':{'id':_0x401f68[_0x2ccc('0x60')]['id']},'include':[{'model':db['CmList'],'as':_0x2ccc('0xb7'),'include':[{'model':db['CmContact'],'as':_0x2ccc('0x9e'),'where':{'mobile':_0x413a06},'limit':0x1,'order':[[_0x2ccc('0x8e'),_0x2ccc('0xb8')]]}]}]})[_0x2ccc('0x32')](handleEntityNotFound(_0x2fbe11,null))[_0x2ccc('0x32')](function(_0x413461){if(_0x413461&&_0x413461[_0x2ccc('0xb7')]){_0x40a039=_0x413461[_0x2ccc('0x59')]({'plain':!![]});if(_0x40a039[_0x2ccc('0xb7')]&&_0x40a039[_0x2ccc('0xb7')][_0x2ccc('0x9e')]['length']){return _0x40a039[_0x2ccc('0xb7')][_0x2ccc('0x9e')][0x0];}return db[_0x2ccc('0x89')][_0x2ccc('0x56')](_[_0x2ccc('0x17')](_0x401f68['body'],{'firstName':_0x413a06,'mobile':_0x413a06,'phone':_0x413a06,'ListId':_0x40a039['ListId']}));}})[_0x2ccc('0x32')](handleEntityNotFound(_0x2fbe11,null))[_0x2ccc('0x32')](function(_0x3b7f05){if(_0x3b7f05){_0x396f76=_0x3b7f05;return db[_0x2ccc('0xa2')][_0x2ccc('0x55')]({'where':{'ContactId':_0x396f76['id'],'closed':![],'WhatsappAccountId':_0x40a039['id']}})[_0x2ccc('0x32')](function(_0x16803c){if(_0x16803c){return[_0x16803c,![]];}return db[_0x2ccc('0xa2')][_0x2ccc('0x56')]({'UserId':_0x401f68[_0x2ccc('0x58')]['id'],'ContactId':_0x396f76['id'],'WhatsappAccountId':_0x40a039['id'],'phone':_0x413a06,'firstMsgDirection':_0x2ccc('0xb9'),'Messages':[_[_0x2ccc('0x4c')](_0x401f68['body'],{'read':![],'body':_0x401f68[_0x2ccc('0x57')][_0x2ccc('0x57')],'phone':_0x413a06,'WhatsappAccountId':_0x40a039['id'],'UserId':_0x401f68[_0x2ccc('0x58')]['id'],'ContactId':_0x396f76['id']})]},{'include':[{'model':db[_0x2ccc('0x83')],'as':_0x2ccc('0xba')}]})[_0x2ccc('0x32')](function(_0x481786){return[_0x481786,!![]];});});}})[_0x2ccc('0x6e')](function(_0x3b22b4,_0x437250){if(_0x437250){return _0x3b22b4;}return db[_0x2ccc('0x83')]['create'](_[_0x2ccc('0x4c')](_0x401f68[_0x2ccc('0x57')],{'read':![],'body':_0x401f68[_0x2ccc('0x57')][_0x2ccc('0x57')],'phone':_0x413a06,'WhatsappAccountId':_0x40a039['id'],'WhatsappInteractionId':_0x3b22b4['id'],'UserId':_0x401f68[_0x2ccc('0x58')]['id'],'ContactId':_0x396f76['id']}))[_0x2ccc('0x32')](function(_0xcc796a){_0x3b22b4[_0x2ccc('0xbb')]['Messages']=[];_0x3b22b4[_0x2ccc('0xbb')][_0x2ccc('0xba')][_0x2ccc('0xbc')](_0xcc796a['dataValues']);return _0x3b22b4;});})[_0x2ccc('0x32')](respondWithResult(_0x2fbe11,null))[_0x2ccc('0x5e')](handleError(_0x2fbe11,null));};