Built motion from commit (unavailable).|2.5.4
[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 _0xf109=['unshift','agent','waitForTheAssignedAgent','Start','startRouting','receiveMessage','info','entity\x20found','WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s','Content-Type','send','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','body\x20is\x20mandatory\x20and\x20not\x20empty','to\x20is\x20mandatory','List','DESC','out','WhatsappMessage','dataValues','Messages','html-pdf','eml-format','rimraf','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../mysqldb','defaults','redis','localhost','./whatsappAccount.socket','jayson/promise','client','test','ValidationError','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','then','WhatsappAccount,\x20%s,\x20%s','request\x20sent','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','sendStatus','status','end','json','offset','limit','set','reject','save','update','destroy','get','WhatsappAccounts','name','index','map','WhatsappAccount','rawAttributes','fieldName','type','key','model','query','intersection','attributes','fields','nolimit','sort','where','filters','pick','filter','merge','VIRTUAL','options','count','includeAll','findAll','rows','catch','show','Pause','mandatoryDispositionPause','keys','length','include','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','params','describe','Disposition','findOne','hasOwnProperty','order','WhatsappAccountId','removeDispositions','ids','addAnswer','getAnswers','CannedAnswer','addAgents','omit','spread','emit','userWhatsappAccount:save','removeAgents','isArray','userWhatsappAccount:remove','getAgents','User','sequelize','transaction','WhatsappApplication','bulkCreate','findAndCountAll','getApplications','notify','whatsapp','Applications','applications','orderBy','priority','asc','account','CmContact','Sequelize','no\x20available\x20attributes','difference','createdAt','updatedAt','ListId','mobile','twilio','from','From','replace','messageId','from\x20is\x20mandatory','isNil','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','Contacts','list','contact','WhatsappInteraction','interaction','created','autoclose','push','*,*,*,*','ContactId','AttachmentId','UserId'];(function(_0x4eca8b,_0xd59631){var _0xa77097=function(_0x4e3870){while(--_0x4e3870){_0x4eca8b['push'](_0x4eca8b['shift']());}};_0xa77097(++_0xd59631);}(_0xf109,0xce));var _0x9f10=function(_0x35da42,_0x5c2610){_0x35da42=_0x35da42-0x0;var _0x370035=_0xf109[_0x35da42];return _0x370035;};'use strict';var pdf=require(_0x9f10('0x0'));var emlformat=require(_0x9f10('0x1'));var rimraf=require(_0x9f10('0x2'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x9f10('0x3'));var BPromise=require(_0x9f10('0x4'));var Mustache=require(_0x9f10('0x5'));var util=require(_0x9f10('0x6'));var path=require(_0x9f10('0x7'));var sox=require(_0x9f10('0x8'));var csv=require(_0x9f10('0x9'));var ejs=require(_0x9f10('0xa'));var fs=require('fs');var _=require(_0x9f10('0xb'));var squel=require(_0x9f10('0xc'));var crypto=require(_0x9f10('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x9f10('0xe'));var toCsv=require(_0x9f10('0x9'));var querystring=require(_0x9f10('0xf'));var Papa=require(_0x9f10('0x10'));var Redis=require(_0x9f10('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x9f10('0x12'));var as=require(_0x9f10('0x13'));var hardwareService=require(_0x9f10('0x14'));var logger=require('../../config/logger')('api');var utils=require(_0x9f10('0x15'));var config=require(_0x9f10('0x16'));var db=require(_0x9f10('0x17'))['db'];config['redis']=_[_0x9f10('0x18')](config[_0x9f10('0x19')],{'host':_0x9f10('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x9f10('0x19')]));require(_0x9f10('0x1b'))['register'](socket);var jayson=require(_0x9f10('0x1c'));var client=jayson[_0x9f10('0x1d')]['http']({'port':0x232c});function checkPasswordPattern(_0x59bcad,_0x2b6c4c,_0x177918){if(_0x177918){var _0x549217=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x549217[_0x9f10('0x1e')](_0x2b6c4c)){return _0x59bcad;}else{throw new db['Sequelize'][(_0x9f10('0x1f'))](_0x9f10('0x20'));}}else{return _0x59bcad;}}function respondWithRpcPromise(_0x4b1b8f,_0x11cc56,_0xd2950c,_0x509fba){return new BPromise(function(_0x150813,_0x53bfbd){var _0xe221d0=_0x509fba||client;return _0xe221d0['request'](_0x4b1b8f,_0xd2950c)[_0x9f10('0x21')](function(_0x56fb44){logger['info'](_0x9f10('0x22'),_0x11cc56,_0x9f10('0x23'));logger[_0x9f10('0x24')](_0x9f10('0x25'),_0x11cc56,_0x9f10('0x23'),JSON[_0x9f10('0x26')](_0x56fb44));if(_0x56fb44[_0x9f10('0x27')]){if(_0x56fb44['error'][_0x9f10('0x28')]===0x1f4){logger['error'](_0x9f10('0x22'),_0x11cc56,_0x56fb44[_0x9f10('0x27')][_0x9f10('0x29')]);return _0x53bfbd(_0x56fb44['error'][_0x9f10('0x29')]);}logger[_0x9f10('0x27')](_0x9f10('0x22'),_0x11cc56,_0x56fb44['error'][_0x9f10('0x29')]);return _0x150813(_0x56fb44[_0x9f10('0x27')][_0x9f10('0x29')]);}else{logger['info'](_0x9f10('0x22'),_0x11cc56,_0x9f10('0x23'));_0x150813(_0x56fb44[_0x9f10('0x2a')][_0x9f10('0x29')]);}})['catch'](function(_0x57539b){logger['error'](_0x9f10('0x22'),_0x11cc56,_0x57539b);_0x53bfbd(_0x57539b);});});}function respondWithStatusCode(_0x4a0407,_0x314794){_0x314794=_0x314794||0xcc;return function(_0x1de75a){if(_0x1de75a){return _0x4a0407[_0x9f10('0x2b')](_0x314794);}return _0x4a0407[_0x9f10('0x2c')](_0x314794)[_0x9f10('0x2d')]();};}function respondWithResult(_0x4f6b0c,_0x522805){_0x522805=_0x522805||0xc8;return function(_0x22814f){if(_0x22814f){return _0x4f6b0c[_0x9f10('0x2c')](_0x522805)[_0x9f10('0x2e')](_0x22814f);}};}function respondWithFilteredResult(_0x181aec,_0x2c4373){return function(_0x581b1d){if(_0x581b1d){var _0x358d3f=_0x581b1d['count'],_0x501ee=_0x2c4373[_0x9f10('0x2f')],_0x44207f=_0x2c4373[_0x9f10('0x2f')]+_0x2c4373[_0x9f10('0x30')],_0x1b03ee;if(_0x44207f>=_0x358d3f){_0x44207f=_0x358d3f;_0x1b03ee=0xc8;}else{_0x1b03ee=0xce;}_0x181aec['status'](_0x1b03ee);return _0x181aec[_0x9f10('0x31')]('Content-Range',_0x501ee+'-'+_0x44207f+'/'+_0x358d3f)[_0x9f10('0x2e')](_0x581b1d);}return null;};}function patchUpdates(_0x362cab){return function(_0x13532b){try{jsonpatch['apply'](_0x13532b,_0x362cab,!![]);}catch(_0x3ac139){return BPromise[_0x9f10('0x32')](_0x3ac139);}return _0x13532b[_0x9f10('0x33')]();};}function saveUpdates(_0x11f128,_0x148a5b){return function(_0x47bb88){if(_0x47bb88){return _0x47bb88[_0x9f10('0x34')](_0x11f128)['then'](function(_0x24d21d){return _0x24d21d;});}return null;};}function removeEntity(_0x17081c,_0x1990da){return function(_0x11ee9c){if(_0x11ee9c){return _0x11ee9c[_0x9f10('0x35')]()[_0x9f10('0x21')](function(){var _0x4b87b0=_0x11ee9c[_0x9f10('0x36')]({'plain':!![]});var _0x3a1601=_0x9f10('0x37');return db['UserProfileResource'][_0x9f10('0x35')]({'where':{'type':_0x3a1601,'resourceId':_0x4b87b0['id']}})[_0x9f10('0x21')](function(){return _0x11ee9c;});})['then'](function(){_0x17081c[_0x9f10('0x2c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x428bf0,_0x1b7a66){return function(_0x26df66){if(!_0x26df66){_0x428bf0[_0x9f10('0x2b')](0x194);}return _0x26df66;};}function handleError(_0x20605a,_0x1ba4be){_0x1ba4be=_0x1ba4be||0x1f4;return function(_0x12036c){logger[_0x9f10('0x27')](_0x12036c['stack']);if(_0x12036c[_0x9f10('0x38')]){delete _0x12036c[_0x9f10('0x38')];}_0x20605a[_0x9f10('0x2c')](_0x1ba4be)['send'](_0x12036c);};}exports[_0x9f10('0x39')]=function(_0x193b59,_0x52914c){var _0x30b04b={'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]},_0x26f0ba={},_0x433c7a={'count':0x0,'rows':[]};var _0x2e4e2d=_[_0x9f10('0x3a')](db[_0x9f10('0x3b')][_0x9f10('0x3c')],function(_0x2e5e46){return{'name':_0x2e5e46[_0x9f10('0x3d')],'type':_0x2e5e46[_0x9f10('0x3e')][_0x9f10('0x3f')]};});_0x26f0ba[_0x9f10('0x40')]=_[_0x9f10('0x3a')](_0x2e4e2d,_0x9f10('0x38'));_0x26f0ba[_0x9f10('0x41')]=_['keys'](_0x193b59['query']);_0x26f0ba['filters']=_[_0x9f10('0x42')](_0x26f0ba['model'],_0x26f0ba[_0x9f10('0x41')]);_0x30b04b[_0x9f10('0x43')]=_[_0x9f10('0x42')](_0x26f0ba['model'],qs[_0x9f10('0x44')](_0x193b59[_0x9f10('0x41')][_0x9f10('0x44')]));_0x30b04b[_0x9f10('0x43')]=_0x30b04b[_0x9f10('0x43')]['length']?_0x30b04b['attributes']:_0x26f0ba['model'];if(!_0x193b59[_0x9f10('0x41')]['hasOwnProperty'](_0x9f10('0x45'))){_0x30b04b['limit']=qs[_0x9f10('0x30')](_0x193b59[_0x9f10('0x41')][_0x9f10('0x30')]);_0x30b04b[_0x9f10('0x2f')]=qs['offset'](_0x193b59[_0x9f10('0x41')][_0x9f10('0x2f')]);}_0x30b04b['order']=qs[_0x9f10('0x46')](_0x193b59[_0x9f10('0x41')][_0x9f10('0x46')]);_0x30b04b[_0x9f10('0x47')]=qs[_0x9f10('0x48')](_[_0x9f10('0x49')](_0x193b59[_0x9f10('0x41')],_0x26f0ba[_0x9f10('0x48')]),_0x2e4e2d);if(_0x193b59[_0x9f10('0x41')][_0x9f10('0x4a')]){_0x30b04b['where']=_[_0x9f10('0x4b')](_0x30b04b[_0x9f10('0x47')],{'$or':_['map'](_0x2e4e2d,function(_0x403ec6){if(_0x403ec6[_0x9f10('0x3e')]!==_0x9f10('0x4c')){var _0x1807b3={};_0x1807b3[_0x403ec6['name']]={'$like':'%'+_0x193b59[_0x9f10('0x41')][_0x9f10('0x4a')]+'%'};return _0x1807b3;}})});}_0x30b04b=_[_0x9f10('0x4b')]({},_0x30b04b,_0x193b59[_0x9f10('0x4d')]);var _0x26f39a={'where':_0x30b04b[_0x9f10('0x47')]};return db['WhatsappAccount'][_0x9f10('0x4e')](_0x26f39a)[_0x9f10('0x21')](function(_0x1ba49d){_0x433c7a[_0x9f10('0x4e')]=_0x1ba49d;if(_0x193b59[_0x9f10('0x41')][_0x9f10('0x4f')]){_0x30b04b['include']=[{'all':!![]}];}return db[_0x9f10('0x3b')][_0x9f10('0x50')](_0x30b04b);})[_0x9f10('0x21')](function(_0x14c808){_0x433c7a[_0x9f10('0x51')]=_0x14c808;return _0x433c7a;})[_0x9f10('0x21')](respondWithFilteredResult(_0x52914c,_0x30b04b))[_0x9f10('0x52')](handleError(_0x52914c,null));};exports[_0x9f10('0x53')]=function(_0x578fc6,_0xd1da11){var _0x59cf43={'raw':![],'where':{'id':_0x578fc6['params']['id']},'include':[{'model':db[_0x9f10('0x54')],'as':_0x9f10('0x55')}]},_0x26b1e8={};_0x26b1e8[_0x9f10('0x40')]=_[_0x9f10('0x56')](db[_0x9f10('0x3b')]['rawAttributes']);_0x26b1e8[_0x9f10('0x41')]=_[_0x9f10('0x56')](_0x578fc6[_0x9f10('0x41')]);_0x26b1e8[_0x9f10('0x48')]=_['intersection'](_0x26b1e8['model'],_0x26b1e8[_0x9f10('0x41')]);_0x59cf43[_0x9f10('0x43')]=_['intersection'](_0x26b1e8['model'],qs[_0x9f10('0x44')](_0x578fc6[_0x9f10('0x41')][_0x9f10('0x44')]));_0x59cf43['attributes']=_0x59cf43[_0x9f10('0x43')][_0x9f10('0x57')]?_0x59cf43[_0x9f10('0x43')]:_0x26b1e8['model'];if(_0x578fc6[_0x9f10('0x41')][_0x9f10('0x4f')]){_0x59cf43[_0x9f10('0x58')]=[{'all':!![]}];}_0x59cf43=_['merge']({},_0x59cf43,_0x578fc6[_0x9f10('0x4d')]);return db[_0x9f10('0x3b')]['find'](_0x59cf43)[_0x9f10('0x21')](handleEntityNotFound(_0xd1da11,null))[_0x9f10('0x21')](respondWithResult(_0xd1da11,null))[_0x9f10('0x52')](handleError(_0xd1da11,null));};exports[_0x9f10('0x59')]=function(_0x334ab4,_0x55cb99){return db[_0x9f10('0x3b')]['create'](_0x334ab4['body'],{})[_0x9f10('0x21')](function(_0x19b489){var _0x1f109a=_0x334ab4[_0x9f10('0x5a')][_0x9f10('0x36')]({'plain':!![]});if(!_0x1f109a)throw new Error(_0x9f10('0x5b'));if(_0x1f109a[_0x9f10('0x5c')]==='user'){var _0x53a80c=_0x19b489[_0x9f10('0x36')]({'plain':!![]});var _0x4e5e30=_0x9f10('0x37');return db[_0x9f10('0x5d')][_0x9f10('0x5e')]({'where':{'name':_0x4e5e30,'userProfileId':_0x1f109a[_0x9f10('0x5f')]},'raw':!![]})[_0x9f10('0x21')](function(_0x526184){if(_0x526184&&_0x526184[_0x9f10('0x60')]===0x0){return db[_0x9f10('0x61')]['create']({'name':_0x53a80c[_0x9f10('0x38')],'resourceId':_0x53a80c['id'],'type':_0x526184[_0x9f10('0x38')],'sectionId':_0x526184['id']},{})['then'](function(){return _0x19b489;});}else{return _0x19b489;}})[_0x9f10('0x52')](function(_0x3542ab){logger['error'](_0x9f10('0x62'),_0x3542ab);throw _0x3542ab;});}return _0x19b489;})['then'](respondWithResult(_0x55cb99,0xc9))[_0x9f10('0x52')](handleError(_0x55cb99,null));};exports[_0x9f10('0x34')]=function(_0x1a1f7b,_0x208d48){if(_0x1a1f7b[_0x9f10('0x63')]['id']){delete _0x1a1f7b['body']['id'];}return db[_0x9f10('0x3b')][_0x9f10('0x5e')]({'where':{'id':_0x1a1f7b[_0x9f10('0x64')]['id']},'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]})[_0x9f10('0x21')](handleEntityNotFound(_0x208d48,null))[_0x9f10('0x21')](saveUpdates(_0x1a1f7b[_0x9f10('0x63')],null))[_0x9f10('0x21')](respondWithResult(_0x208d48,null))[_0x9f10('0x52')](handleError(_0x208d48,null));};exports[_0x9f10('0x35')]=function(_0x2fd96b,_0x56e527){return db[_0x9f10('0x3b')][_0x9f10('0x5e')]({'where':{'id':_0x2fd96b['params']['id']}})[_0x9f10('0x21')](handleEntityNotFound(_0x56e527,null))['then'](removeEntity(_0x56e527,null))[_0x9f10('0x52')](handleError(_0x56e527,null));};exports[_0x9f10('0x65')]=function(_0x5ebfc4,_0x3f669c){return db['WhatsappAccount'][_0x9f10('0x65')]()[_0x9f10('0x21')](respondWithResult(_0x3f669c,null))[_0x9f10('0x52')](handleError(_0x3f669c,null));};exports['addDisposition']=function(_0x35bfbd,_0x53e320,_0x2d704b){if(_0x35bfbd[_0x9f10('0x63')]['id']){delete _0x35bfbd[_0x9f10('0x63')]['id'];}return db['WhatsappAccount'][_0x9f10('0x5e')]({'where':{'id':_0x35bfbd['params']['id']}})['then'](handleEntityNotFound(_0x53e320,null))[_0x9f10('0x21')](function(_0x34520c){if(_0x34520c){_0x35bfbd[_0x9f10('0x63')]['WhatsappAccountId']=_0x34520c['id'];return db[_0x9f10('0x66')]['create'](_0x35bfbd['body']);}})[_0x9f10('0x21')](respondWithResult(_0x53e320,null))['catch'](handleError(_0x53e320,null));};exports['getDispositions']=function(_0x13a2cb,_0x5302d3,_0x1a08f5){var _0x9f6f4b={'raw':![],'where':{}};var _0x42f559={};var _0x5bc191={'count':0x0,'rows':[]};return db[_0x9f10('0x3b')][_0x9f10('0x67')]({'where':{'id':_0x13a2cb['params']['id']}})[_0x9f10('0x21')](handleEntityNotFound(_0x5302d3,null))['then'](function(_0x5bc6ce){if(_0x5bc6ce){_0x42f559[_0x9f10('0x40')]=_[_0x9f10('0x56')](db[_0x9f10('0x66')][_0x9f10('0x3c')]);_0x42f559[_0x9f10('0x41')]=_[_0x9f10('0x56')](_0x13a2cb[_0x9f10('0x41')]);_0x42f559['filters']=_[_0x9f10('0x42')](_0x42f559[_0x9f10('0x40')],_0x42f559[_0x9f10('0x41')]);_0x9f6f4b[_0x9f10('0x43')]=_[_0x9f10('0x42')](_0x42f559[_0x9f10('0x40')],qs[_0x9f10('0x44')](_0x13a2cb[_0x9f10('0x41')][_0x9f10('0x44')]));_0x9f6f4b['attributes']=_0x9f6f4b[_0x9f10('0x43')][_0x9f10('0x57')]?_0x9f6f4b[_0x9f10('0x43')]:_0x42f559[_0x9f10('0x40')];if(!_0x13a2cb['query'][_0x9f10('0x68')](_0x9f10('0x45'))){_0x9f6f4b[_0x9f10('0x30')]=qs[_0x9f10('0x30')](_0x13a2cb['query']['limit']);_0x9f6f4b[_0x9f10('0x2f')]=qs[_0x9f10('0x2f')](_0x13a2cb[_0x9f10('0x41')][_0x9f10('0x2f')]);}_0x9f6f4b[_0x9f10('0x69')]=qs[_0x9f10('0x46')](_0x13a2cb[_0x9f10('0x41')][_0x9f10('0x46')]);_0x9f6f4b[_0x9f10('0x47')]=qs[_0x9f10('0x48')](_[_0x9f10('0x49')](_0x13a2cb[_0x9f10('0x41')],_0x42f559[_0x9f10('0x48')]));_0x9f6f4b[_0x9f10('0x47')][_0x9f10('0x6a')]=_0x5bc6ce['id'];if(_0x13a2cb['query'][_0x9f10('0x4a')]){_0x9f6f4b[_0x9f10('0x47')]=_['merge'](_0x9f6f4b[_0x9f10('0x47')],{'$or':_[_0x9f10('0x3a')](_0x9f6f4b[_0x9f10('0x43')],function(_0x24118b){var _0x515b89={};_0x515b89[_0x24118b]={'$like':'%'+_0x13a2cb[_0x9f10('0x41')]['filter']+'%'};return _0x515b89;})});}_0x9f6f4b=_[_0x9f10('0x4b')]({},_0x9f6f4b,_0x13a2cb[_0x9f10('0x4d')]);return db[_0x9f10('0x66')]['count']({'where':_0x9f6f4b[_0x9f10('0x47')]})[_0x9f10('0x21')](function(_0x4139c6){_0x5bc191['count']=_0x4139c6;if(_0x13a2cb[_0x9f10('0x41')][_0x9f10('0x4f')]){_0x9f6f4b[_0x9f10('0x58')]=[{'all':!![]}];}return db['Disposition']['findAll'](_0x9f6f4b);})['then'](function(_0x5b78cd){_0x5bc191['rows']=_0x5b78cd;return _0x5bc191;});}})['then'](respondWithFilteredResult(_0x5302d3,_0x9f6f4b))['catch'](handleError(_0x5302d3,null));};exports[_0x9f10('0x6b')]=function(_0x2571a6,_0x4dc5d5,_0xa0988b){return db[_0x9f10('0x3b')][_0x9f10('0x5e')]({'where':{'id':_0x2571a6[_0x9f10('0x64')]['id']}})[_0x9f10('0x21')](handleEntityNotFound(_0x4dc5d5,null))[_0x9f10('0x21')](function(_0x45ebcc){if(_0x45ebcc){return _0x45ebcc[_0x9f10('0x6b')](_0x2571a6[_0x9f10('0x41')][_0x9f10('0x6c')]);}})['then'](respondWithStatusCode(_0x4dc5d5,null))[_0x9f10('0x52')](handleError(_0x4dc5d5,null));};exports[_0x9f10('0x6d')]=function(_0x480978,_0x42a8bf,_0x5b2f86){if(_0x480978['body']['id']){delete _0x480978[_0x9f10('0x63')]['id'];}return db[_0x9f10('0x3b')]['find']({'where':{'id':_0x480978[_0x9f10('0x64')]['id']}})[_0x9f10('0x21')](handleEntityNotFound(_0x42a8bf,null))['then'](function(_0x3ef019){if(_0x3ef019){_0x480978[_0x9f10('0x63')][_0x9f10('0x6a')]=_0x3ef019['id'];return db['CannedAnswer'][_0x9f10('0x59')](_0x480978[_0x9f10('0x63')]);}})['then'](respondWithResult(_0x42a8bf,null))['catch'](handleError(_0x42a8bf,null));};exports[_0x9f10('0x6e')]=function(_0x3d64e8,_0x505e7a,_0x19b616){var _0x3f8cfd={'raw':![],'where':{}};var _0x4ceae4={};var _0x4db9be={'count':0x0,'rows':[]};return db[_0x9f10('0x3b')][_0x9f10('0x67')]({'where':{'id':_0x3d64e8['params']['id']}})['then'](handleEntityNotFound(_0x505e7a,null))[_0x9f10('0x21')](function(_0x13a8a8){if(_0x13a8a8){_0x4ceae4['model']=_[_0x9f10('0x56')](db[_0x9f10('0x6f')][_0x9f10('0x3c')]);_0x4ceae4[_0x9f10('0x41')]=_[_0x9f10('0x56')](_0x3d64e8['query']);_0x4ceae4['filters']=_['intersection'](_0x4ceae4[_0x9f10('0x40')],_0x4ceae4[_0x9f10('0x41')]);_0x3f8cfd[_0x9f10('0x43')]=_['intersection'](_0x4ceae4[_0x9f10('0x40')],qs['fields'](_0x3d64e8[_0x9f10('0x41')]['fields']));_0x3f8cfd['attributes']=_0x3f8cfd['attributes'][_0x9f10('0x57')]?_0x3f8cfd[_0x9f10('0x43')]:_0x4ceae4[_0x9f10('0x40')];if(!_0x3d64e8[_0x9f10('0x41')][_0x9f10('0x68')](_0x9f10('0x45'))){_0x3f8cfd[_0x9f10('0x30')]=qs[_0x9f10('0x30')](_0x3d64e8['query'][_0x9f10('0x30')]);_0x3f8cfd[_0x9f10('0x2f')]=qs[_0x9f10('0x2f')](_0x3d64e8['query'][_0x9f10('0x2f')]);}_0x3f8cfd[_0x9f10('0x69')]=qs[_0x9f10('0x46')](_0x3d64e8[_0x9f10('0x41')][_0x9f10('0x46')]);_0x3f8cfd['where']=qs[_0x9f10('0x48')](_['pick'](_0x3d64e8[_0x9f10('0x41')],_0x4ceae4[_0x9f10('0x48')]));_0x3f8cfd['where'][_0x9f10('0x6a')]=_0x13a8a8['id'];if(_0x3d64e8[_0x9f10('0x41')][_0x9f10('0x4a')]){_0x3f8cfd[_0x9f10('0x47')]=_['merge'](_0x3f8cfd[_0x9f10('0x47')],{'$or':_['map'](_0x3f8cfd[_0x9f10('0x43')],function(_0x40debc){var _0x4e0a49={};_0x4e0a49[_0x40debc]={'$like':'%'+_0x3d64e8['query'][_0x9f10('0x4a')]+'%'};return _0x4e0a49;})});}_0x3f8cfd=_['merge']({},_0x3f8cfd,_0x3d64e8['options']);return db['CannedAnswer'][_0x9f10('0x4e')]({'where':_0x3f8cfd[_0x9f10('0x47')]})['then'](function(_0x144567){_0x4db9be[_0x9f10('0x4e')]=_0x144567;if(_0x3d64e8[_0x9f10('0x41')][_0x9f10('0x4f')]){_0x3f8cfd[_0x9f10('0x58')]=[{'all':!![]}];}return db[_0x9f10('0x6f')][_0x9f10('0x50')](_0x3f8cfd);})[_0x9f10('0x21')](function(_0x15043f){_0x4db9be[_0x9f10('0x51')]=_0x15043f;return _0x4db9be;});}})['then'](respondWithFilteredResult(_0x505e7a,_0x3f8cfd))['catch'](handleError(_0x505e7a,null));};exports['removeAnswers']=function(_0x5bdcc3,_0x4222c6,_0xeaa529){return db[_0x9f10('0x3b')][_0x9f10('0x5e')]({'where':{'id':_0x5bdcc3[_0x9f10('0x64')]['id']}})['then'](handleEntityNotFound(_0x4222c6,null))[_0x9f10('0x21')](function(_0x3dd01e){if(_0x3dd01e){return _0x3dd01e['removeAnswers'](_0x5bdcc3[_0x9f10('0x41')][_0x9f10('0x6c')]);}})[_0x9f10('0x21')](respondWithStatusCode(_0x4222c6,null))[_0x9f10('0x52')](handleError(_0x4222c6,null));};exports[_0x9f10('0x70')]=function(_0x2a9986,_0x4504bd,_0x405fca){return db[_0x9f10('0x3b')]['find']({'where':{'id':_0x2a9986['params']['id']}})[_0x9f10('0x21')](handleEntityNotFound(_0x4504bd,null))[_0x9f10('0x21')](function(_0x45c82c){if(_0x45c82c){return _0x45c82c[_0x9f10('0x70')](_0x2a9986['body'][_0x9f10('0x6c')],_[_0x9f10('0x71')](_0x2a9986[_0x9f10('0x63')],[_0x9f10('0x6c'),'id'])||{})[_0x9f10('0x72')](function(_0x2c4ce4){for(var _0x4cc25c=0x0;_0x4cc25c<_0x2a9986['body']['ids'][_0x9f10('0x57')];_0x4cc25c+=0x1){socket[_0x9f10('0x73')](_0x9f10('0x74'),{'UserId':_0x2a9986[_0x9f10('0x63')][_0x9f10('0x6c')][_0x4cc25c],'WhatsappAccountId':_0x2a9986[_0x9f10('0x64')]['id']});}return _0x2c4ce4;});}})[_0x9f10('0x21')](respondWithResult(_0x4504bd,null))[_0x9f10('0x52')](handleError(_0x4504bd,null));};exports[_0x9f10('0x75')]=function(_0x527cb4,_0x3fd751,_0x35a005){return db[_0x9f10('0x3b')]['find']({'where':{'id':_0x527cb4[_0x9f10('0x64')]['id']}})['then'](handleEntityNotFound(_0x3fd751,null))[_0x9f10('0x21')](function(_0x257daa){if(_0x257daa){return _0x257daa['removeAgents'](_0x527cb4[_0x9f10('0x41')][_0x9f10('0x6c')])[_0x9f10('0x21')](function(){if(_[_0x9f10('0x76')](_0x527cb4[_0x9f10('0x41')]['ids'])){for(var _0x442334=0x0;_0x442334<_0x527cb4['query'][_0x9f10('0x6c')]['length'];_0x442334+=0x1){socket['emit'](_0x9f10('0x77'),{'UserId':Number(_0x527cb4[_0x9f10('0x41')][_0x9f10('0x6c')][_0x442334]),'WhatsappAccountId':Number(_0x527cb4[_0x9f10('0x64')]['id'])});}}else{socket[_0x9f10('0x73')](_0x9f10('0x77'),{'UserId':Number(_0x527cb4['query'][_0x9f10('0x6c')]),'WhatsappAccountId':Number(_0x527cb4[_0x9f10('0x64')]['id'])});}});}})[_0x9f10('0x21')](respondWithStatusCode(_0x3fd751,null))[_0x9f10('0x52')](handleError(_0x3fd751,null));};exports[_0x9f10('0x78')]=function(_0x22add9,_0xf7c500,_0x4048ca){var _0x1ea477={};var _0x204b3e={};var _0x21b883;var _0x168bf3;return db['WhatsappAccount'][_0x9f10('0x67')]({'where':{'id':_0x22add9['params']['id']}})[_0x9f10('0x21')](handleEntityNotFound(_0xf7c500,null))[_0x9f10('0x21')](function(_0x866476){if(_0x866476){_0x21b883=_0x866476;_0x204b3e['model']=_[_0x9f10('0x56')](db[_0x9f10('0x79')][_0x9f10('0x3c')]);_0x204b3e[_0x9f10('0x41')]=_[_0x9f10('0x56')](_0x22add9[_0x9f10('0x41')]);_0x204b3e['filters']=_[_0x9f10('0x42')](_0x204b3e[_0x9f10('0x40')],_0x204b3e['query']);_0x1ea477[_0x9f10('0x43')]=_[_0x9f10('0x42')](_0x204b3e[_0x9f10('0x40')],qs[_0x9f10('0x44')](_0x22add9['query']['fields']));_0x1ea477[_0x9f10('0x43')]=_0x1ea477['attributes'][_0x9f10('0x57')]?_0x1ea477[_0x9f10('0x43')]:_0x204b3e['model'];_0x1ea477[_0x9f10('0x69')]=qs[_0x9f10('0x46')](_0x22add9[_0x9f10('0x41')][_0x9f10('0x46')]);_0x1ea477['where']=qs[_0x9f10('0x48')](_[_0x9f10('0x49')](_0x22add9['query'],_0x204b3e[_0x9f10('0x48')]));if(_0x22add9['query']['filter']){_0x1ea477[_0x9f10('0x47')]=_[_0x9f10('0x4b')](_0x1ea477[_0x9f10('0x47')],{'$or':_[_0x9f10('0x3a')](_0x1ea477[_0x9f10('0x43')],function(_0x4e7496){var _0x3a1f83={};_0x3a1f83[_0x4e7496]={'$like':'%'+_0x22add9['query'][_0x9f10('0x4a')]+'%'};return _0x3a1f83;})});}_0x1ea477=_[_0x9f10('0x4b')]({},_0x1ea477,_0x22add9['options']);return _0x21b883[_0x9f10('0x78')](_0x1ea477);}})['then'](function(_0x3218b9){if(_0x3218b9){_0x168bf3=_0x3218b9[_0x9f10('0x57')];if(!_0x22add9[_0x9f10('0x41')][_0x9f10('0x68')](_0x9f10('0x45'))){_0x1ea477[_0x9f10('0x30')]=qs[_0x9f10('0x30')](_0x22add9[_0x9f10('0x41')]['limit']);_0x1ea477[_0x9f10('0x2f')]=qs[_0x9f10('0x2f')](_0x22add9[_0x9f10('0x41')][_0x9f10('0x2f')]);}return _0x21b883[_0x9f10('0x78')](_0x1ea477);}})[_0x9f10('0x21')](function(_0x21372c){if(_0x21372c){return _0x21372c?{'count':_0x168bf3,'rows':_0x21372c}:null;}})[_0x9f10('0x21')](respondWithResult(_0xf7c500,null))[_0x9f10('0x52')](handleError(_0xf7c500,null));};exports['addApplications']=function(_0x501562,_0x51a0db,_0xa2c256){return db['WhatsappAccount'][_0x9f10('0x67')]({'where':{'id':_0x501562[_0x9f10('0x64')]['id']}})['then'](handleEntityNotFound(_0x51a0db,null))[_0x9f10('0x21')](function(_0x1b48e0){if(_0x1b48e0){return db[_0x9f10('0x7a')][_0x9f10('0x7b')](function(_0x36d169){return db[_0x9f10('0x7c')][_0x9f10('0x35')]({'where':{'WhatsappAccountId':_0x501562[_0x9f10('0x64')]['id']},'transaction':_0x36d169})[_0x9f10('0x21')](function(_0x37eb7b){var _0x1bb7f5=_['map'](_0x501562[_0x9f10('0x63')],function(_0x195dca){_0x195dca[_0x9f10('0x6a')]=_0x501562[_0x9f10('0x64')]['id'];return _0x195dca;});return db['WhatsappApplication'][_0x9f10('0x7d')](_0x1bb7f5,{'transaction':_0x36d169});});})[_0x9f10('0x21')](function(){return db[_0x9f10('0x7c')][_0x9f10('0x7e')]({'where':{'WhatsappAccountId':_0x501562[_0x9f10('0x64')]['id']},'order':'priority'});});}})[_0x9f10('0x21')](respondWithResult(_0x51a0db,null))[_0x9f10('0x52')](handleError(_0x51a0db,null));};exports[_0x9f10('0x7f')]=function(_0xe1b053,_0x1e124e,_0x17bdee){var _0x12b9ec={};var _0x5da96e={};var _0x293341;var _0x5934ac;return db[_0x9f10('0x3b')][_0x9f10('0x67')]({'where':{'id':_0xe1b053[_0x9f10('0x64')]['id']}})[_0x9f10('0x21')](handleEntityNotFound(_0x1e124e,null))['then'](function(_0x4bb770){if(_0x4bb770){_0x293341=_0x4bb770;_0x5da96e[_0x9f10('0x40')]=_[_0x9f10('0x56')](db['WhatsappApplication'][_0x9f10('0x3c')]);_0x5da96e['query']=_[_0x9f10('0x56')](_0xe1b053[_0x9f10('0x41')]);_0x5da96e[_0x9f10('0x48')]=_[_0x9f10('0x42')](_0x5da96e[_0x9f10('0x40')],_0x5da96e[_0x9f10('0x41')]);_0x12b9ec[_0x9f10('0x43')]=_[_0x9f10('0x42')](_0x5da96e[_0x9f10('0x40')],qs[_0x9f10('0x44')](_0xe1b053['query']['fields']));_0x12b9ec['attributes']=_0x12b9ec[_0x9f10('0x43')][_0x9f10('0x57')]?_0x12b9ec[_0x9f10('0x43')]:_0x5da96e['model'];_0x12b9ec[_0x9f10('0x69')]=qs[_0x9f10('0x46')](_0xe1b053['query'][_0x9f10('0x46')]);_0x12b9ec[_0x9f10('0x47')]=qs[_0x9f10('0x48')](_[_0x9f10('0x49')](_0xe1b053[_0x9f10('0x41')],_0x5da96e[_0x9f10('0x48')]));if(_0xe1b053[_0x9f10('0x41')][_0x9f10('0x4a')]){_0x12b9ec[_0x9f10('0x47')]=_['merge'](_0x12b9ec[_0x9f10('0x47')],{'$or':_[_0x9f10('0x3a')](_0x12b9ec[_0x9f10('0x43')],function(_0x549b1f){var _0x1ae7e1={};_0x1ae7e1[_0x549b1f]={'$like':'%'+_0xe1b053[_0x9f10('0x41')][_0x9f10('0x4a')]+'%'};return _0x1ae7e1;})});}_0x12b9ec=_[_0x9f10('0x4b')]({},_0x12b9ec,_0xe1b053[_0x9f10('0x4d')]);return _0x293341[_0x9f10('0x7f')](_0x12b9ec);}})['then'](function(_0x30d249){if(_0x30d249){_0x5934ac=_0x30d249[_0x9f10('0x57')];if(!_0xe1b053['query'][_0x9f10('0x68')]('nolimit')){_0x12b9ec[_0x9f10('0x30')]=qs[_0x9f10('0x30')](_0xe1b053[_0x9f10('0x41')]['limit']);_0x12b9ec['offset']=qs[_0x9f10('0x2f')](_0xe1b053[_0x9f10('0x41')][_0x9f10('0x2f')]);}return _0x293341[_0x9f10('0x7f')](_0x12b9ec);}})[_0x9f10('0x21')](function(_0xe3cd33){if(_0xe3cd33){return _0xe3cd33?{'count':_0x5934ac,'rows':_0xe3cd33}:null;}})[_0x9f10('0x21')](respondWithResult(_0x1e124e,null))[_0x9f10('0x52')](handleError(_0x1e124e,null));};exports[_0x9f10('0x80')]=function(_0x598dd9,_0x2dc23f,_0x115b36){var _0x39087c={'channel':_0x9f10('0x81')};var _0x3f06ac=[];var _0xe1e75f=[];var _0xcd1fba={};return db[_0x9f10('0x3b')][_0x9f10('0x5e')]({'where':{'id':_0x598dd9[_0x9f10('0x64')]['id']},'include':[{'model':db[_0x9f10('0x7c')],'as':_0x9f10('0x82')}]})['then'](handleEntityNotFound(_0x2dc23f,null))[_0x9f10('0x21')](function(_0x54900c){_0x39087c['account']=_0x54900c;_0x39087c[_0x9f10('0x83')]=_[_0x9f10('0x84')](_0x54900c[_0x9f10('0x82')],[_0x9f10('0x85')],[_0x9f10('0x86')]);if(_0x39087c['account']['Applications']){delete _0x39087c[_0x9f10('0x87')][_0x9f10('0x82')];}return db[_0x9f10('0x88')][_0x9f10('0x65')]();})['then'](function(_0x5bc74b){if(!_0x5bc74b){throw new db[(_0x9f10('0x89'))][(_0x9f10('0x1f'))](_0x9f10('0x8a'));}_0x3f06ac=_[_0x9f10('0x8b')](_[_0x9f10('0x56')](_0x5bc74b),[_0x9f10('0x8c'),'updatedAt']);_0xe1e75f=_[_0x9f10('0x8b')](_[_0x9f10('0x56')](_0x5bc74b),[_0x9f10('0x8c'),_0x9f10('0x8d'),'CompanyId',_0x9f10('0x8e')]);_0x39087c[_0x9f10('0x63')]={'mapKey':_0x9f10('0x8f')};if(_0x39087c[_0x9f10('0x87')][_0x9f10('0x3e')]&&_0x39087c[_0x9f10('0x87')][_0x9f10('0x3e')]===_0x9f10('0x90')){_0x39087c['body'][_0x9f10('0x91')]=_0x598dd9[_0x9f10('0x63')][_0x9f10('0x92')][_0x9f10('0x93')]('whatsapp:','');_0x39087c[_0x9f10('0x63')][_0x9f10('0x63')]=_0x598dd9[_0x9f10('0x63')]['Body'];_0x39087c[_0x9f10('0x63')][_0x9f10('0x94')]=_0x598dd9[_0x9f10('0x63')]['MessageSid'];}if(_0x39087c[_0x9f10('0x63')]['id']){delete _0x39087c[_0x9f10('0x63')]['id'];}if(_['isNil'](_0x39087c['body']['from'])){throw new db[(_0x9f10('0x89'))][(_0x9f10('0x1f'))](_0x9f10('0x95'));}if(_[_0x9f10('0x96')](_0x39087c[_0x9f10('0x63')]['body'])||_0x39087c[_0x9f10('0x63')]['body']===''){throw new db[(_0x9f10('0x89'))][(_0x9f10('0x1f'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x9f10('0x96')](_0x39087c[_0x9f10('0x63')][_0x9f10('0x97')])){throw new db[(_0x9f10('0x89'))][(_0x9f10('0x1f'))](_0x9f10('0x98')+_0xe1e75f);}if(!_['includes'](_0xe1e75f,_0x39087c[_0x9f10('0x63')][_0x9f10('0x97')])){throw new db[(_0x9f10('0x89'))][(_0x9f10('0x1f'))](_0x9f10('0x99')+_0xe1e75f);}_0xcd1fba[_0x39087c[_0x9f10('0x63')][_0x9f10('0x97')]]=_0x39087c[_0x9f10('0x63')][_0x9f10('0x91')];return db['CmList'][_0x9f10('0x5e')]({'where':{'id':_0x39087c[_0x9f10('0x87')]['ListId']},'include':[{'model':db[_0x9f10('0x88')],'as':_0x9f10('0x9a'),'where':_0xcd1fba,'limit':0x1,'order':[[_0x9f10('0x8d'),'DESC']]}]});})[_0x9f10('0x21')](handleEntityNotFound(_0x2dc23f,null))[_0x9f10('0x21')](function(_0x2d2cc1){if(_0x2d2cc1){_0x39087c[_0x9f10('0x9b')]=_['omit'](_0x2d2cc1,['Contacts']);if(_0x2d2cc1['Contacts'][_0x9f10('0x57')]){return _0x2d2cc1[_0x9f10('0x9a')][0x0];}var _0x4ccd7a=_['defaults'](_0x39087c[_0x9f10('0x63')],{'firstName':_0x39087c['body']['from'],'ListId':_0x2d2cc1['id']});_0x4ccd7a[_0x39087c[_0x9f10('0x63')][_0x9f10('0x97')]]=_0x39087c[_0x9f10('0x63')][_0x9f10('0x91')];return db[_0x9f10('0x88')]['create'](_0x4ccd7a,{'fields':_0x3f06ac,'raw':!![]});}})[_0x9f10('0x21')](handleEntityNotFound(_0x2dc23f,null))['then'](function(_0x5782c2){if(_0x5782c2){_0x39087c[_0x9f10('0x9c')]=_0x5782c2;var _0xb658c8={'ContactId':_0x5782c2['id'],'phone':_0x39087c['body']['from'],'WhatsappAccountId':_0x598dd9[_0x9f10('0x64')]['id']};var _0xd36646={'ContactId':_0x5782c2['id'],'WhatsappAccountId':_0x598dd9[_0x9f10('0x64')]['id'],'closed':![]};return db['WhatsappInteraction']['find']({'where':_0xd36646})[_0x9f10('0x21')](function(_0x3bc4d9){if(_0x3bc4d9){return[_0x3bc4d9,![]];}return db[_0x9f10('0x9d')][_0x9f10('0x59')](_0xb658c8)[_0x9f10('0x21')](function(_0x4636fc){return[_0x4636fc,!![]];});});}})[_0x9f10('0x72')](function(_0x4853e0,_0x385f79){_0x39087c[_0x9f10('0x9e')]=_0x4853e0['get']({'plain':!![]});_0x39087c[_0x9f10('0x9e')][_0x9f10('0x9f')]=![];if(_0x385f79){if(_0x39087c['account'][_0x9f10('0xa0')]){_0x39087c[_0x9f10('0x83')][_0x9f10('0xa1')]({'id':0x0,'priority':_0x39087c[_0x9f10('0x83')][_0x9f10('0x57')]+0x1,'app':'close','appdata':'unmanaged','interval':_0x9f10('0xa2')});}_0x39087c[_0x9f10('0x9e')][_0x9f10('0x9f')]=!![];}return db['WhatsappMessage']['create']({'phone':_0x39087c[_0x9f10('0x63')][_0x9f10('0x91')],'messageId':_0x39087c['body']['messageId'],'body':_0x39087c['body']['body'],'WhatsappAccountId':_0x598dd9[_0x9f10('0x64')]['id'],'WhatsappInteractionId':_0x4853e0['id'],'direction':'in','ContactId':_0x4853e0[_0x9f10('0xa3')],'AttachmentId':_0x39087c[_0x9f10('0x63')][_0x9f10('0xa4')]});})[_0x9f10('0x21')](function(_0x1d49c1){_0x39087c['message']=_0x1d49c1;if(_0x39087c[_0x9f10('0x9e')][_0x9f10('0xa5')]){return db[_0x9f10('0x79')][_0x9f10('0x5e')]({'attributes':['id',_0x9f10('0x38')],'where':{'id':_0x39087c[_0x9f10('0x9e')][_0x9f10('0xa5')]}})[_0x9f10('0x21')](function(_0x162f72){if(_0x162f72){_0x39087c[_0x9f10('0x83')][_0x9f10('0xa6')]({'id':0x0,'priority':0x0,'app':_0x9f10('0xa7'),'appdata':_0x162f72[_0x9f10('0x38')]+','+(_0x39087c[_0x9f10('0x87')][_0x9f10('0xa8')]||0xa),'interval':_0x9f10('0xa2')});}return respondWithRpcPromise(_0x9f10('0xa9'),'startRouting',_0x39087c);});}return respondWithRpcPromise(_0x9f10('0xa9'),_0x9f10('0xaa'),_0x39087c);})[_0x9f10('0x21')](function(_0xad8d56){if(_0xad8d56){var _0x5a7bb8=0xc8;var _0x29465f=_0x9f10('0xab');logger[_0x9f10('0xac')]('WhatsappAccount,\x20%s,\x20%s,\x20%s',_0x29465f,_0x5a7bb8,_0x9f10('0xad'));logger['debug'](_0x9f10('0xae'),_0x29465f,_0x5a7bb8,'entity\x20found',JSON['stringify'](_0xad8d56));if(_0x39087c[_0x9f10('0x87')]['type']===_0x9f10('0x90')){return _0x2dc23f[_0x9f10('0x2c')](_0x5a7bb8)[_0x9f10('0x31')](_0x9f10('0xaf'),'text/xml')[_0x9f10('0xb0')](_0x9f10('0xb1'));}else{return _0x2dc23f[_0x9f10('0x2c')](_0x5a7bb8)['json'](_0xad8d56);}}})[_0x9f10('0x52')](handleError(_0x2dc23f,null));};exports[_0x9f10('0xb0')]=function(_0xe27bde,_0x136a3c,_0x3334fc){var _0x25ed02,_0x3a5932,_0x492f30;if(_['isNil'](_0xe27bde['body']['body'])||_0xe27bde[_0x9f10('0x63')][_0x9f10('0x63')]===''){throw new db[(_0x9f10('0x89'))][(_0x9f10('0x1f'))](_0x9f10('0xb2'));}if(_[_0x9f10('0x96')](_0xe27bde[_0x9f10('0x63')]['to'])){throw new db[(_0x9f10('0x89'))][(_0x9f10('0x1f'))](_0x9f10('0xb3'));}_0x25ed02=_0xe27bde[_0x9f10('0x63')]['to'];return db[_0x9f10('0x3b')][_0x9f10('0x5e')]({'where':{'id':_0xe27bde[_0x9f10('0x64')]['id']},'include':[{'model':db['CmList'],'as':_0x9f10('0xb4'),'include':[{'model':db[_0x9f10('0x88')],'as':_0x9f10('0x9a'),'where':{'mobile':_0x25ed02},'limit':0x1,'order':[[_0x9f10('0x8d'),_0x9f10('0xb5')]]}]}]})['then'](handleEntityNotFound(_0x136a3c,null))[_0x9f10('0x21')](function(_0x418e34){if(_0x418e34&&_0x418e34[_0x9f10('0xb4')]){_0x3a5932=_0x418e34[_0x9f10('0x36')]({'plain':!![]});if(_0x3a5932[_0x9f10('0xb4')]&&_0x3a5932[_0x9f10('0xb4')][_0x9f10('0x9a')][_0x9f10('0x57')]){return _0x3a5932[_0x9f10('0xb4')][_0x9f10('0x9a')][0x0];}return db[_0x9f10('0x88')][_0x9f10('0x59')](_[_0x9f10('0x18')](_0xe27bde[_0x9f10('0x63')],{'firstName':_0x25ed02,'mobile':_0x25ed02,'phone':_0x25ed02,'ListId':_0x3a5932[_0x9f10('0x8e')]}));}})[_0x9f10('0x21')](handleEntityNotFound(_0x136a3c,null))[_0x9f10('0x21')](function(_0x50d895){if(_0x50d895){_0x492f30=_0x50d895;return db[_0x9f10('0x9d')]['find']({'where':{'ContactId':_0x492f30['id'],'closed':![],'WhatsappAccountId':_0x3a5932['id']}})[_0x9f10('0x21')](function(_0xc4e595){if(_0xc4e595){return[_0xc4e595,![]];}return db[_0x9f10('0x9d')]['create']({'UserId':_0xe27bde[_0x9f10('0x5a')]['id'],'ContactId':_0x492f30['id'],'WhatsappAccountId':_0x3a5932['id'],'phone':_0x25ed02,'firstMsgDirection':_0x9f10('0xb6'),'Messages':[_[_0x9f10('0x4b')](_0xe27bde['body'],{'read':![],'body':_0xe27bde[_0x9f10('0x63')][_0x9f10('0x63')],'phone':_0x25ed02,'WhatsappAccountId':_0x3a5932['id'],'UserId':_0xe27bde[_0x9f10('0x5a')]['id'],'ContactId':_0x492f30['id']})]},{'include':[{'model':db[_0x9f10('0xb7')],'as':'Messages'}]})[_0x9f10('0x21')](function(_0x4aa55a){return[_0x4aa55a,!![]];});});}})[_0x9f10('0x72')](function(_0x1a843a,_0x18b8c1){if(_0x18b8c1){return _0x1a843a;}return db[_0x9f10('0xb7')]['create'](_[_0x9f10('0x4b')](_0xe27bde[_0x9f10('0x63')],{'read':![],'body':_0xe27bde[_0x9f10('0x63')][_0x9f10('0x63')],'phone':_0x25ed02,'WhatsappAccountId':_0x3a5932['id'],'WhatsappInteractionId':_0x1a843a['id'],'UserId':_0xe27bde[_0x9f10('0x5a')]['id'],'ContactId':_0x492f30['id']}))[_0x9f10('0x21')](function(_0x1ddcc2){_0x1a843a[_0x9f10('0xb8')][_0x9f10('0xb9')]=[];_0x1a843a['dataValues']['Messages'][_0x9f10('0xa1')](_0x1ddcc2[_0x9f10('0xb8')]);return _0x1a843a;});})[_0x9f10('0x21')](respondWithResult(_0x136a3c,null))['catch'](handleError(_0x136a3c,null));};