Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / api / whatsappAccount / whatsappAccount.controller.js
index a1d13a9..d2d6183 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xc79f=['destroy','stack','name','send','render','merge','contact','agent','account','Pause','mandatoryDispositionPause','map','WhatsappAccount','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','nolimit','sort','where','pick','filter','includeAll','findAll','rows','show','params','keys','include','find','create','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','WhatsappAccounts','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','addDisposition','Disposition','getDispositions','order','WhatsappAccountId','options','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','findOne','hasOwnProperty','removeAnswers','addAgents','omit','spread','userWhatsappAccount:save','removeAgents','isArray','userWhatsappAccount:remove','User','getAgents','transaction','WhatsappApplication','bulkCreate','priority','getApplications','whatsapp','Applications','applications','orderBy','asc','CmContact','ValidationError','no\x20available\x20attributes','createdAt','difference','updatedAt','CompanyId','mobile','from','From','replace','Body','MessageSid','isNil','Sequelize','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','ListId','Contacts','DESC','WhatsappInteraction','interaction','created','autoclose','close','unmanaged','WhatsappMessage','messageId','AttachmentId','UserId','unshift','*,*,*,*','Start','startRouting','receiveMessage','WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s','entity\x20found','twilio','set','Content-Type','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','List','out','dataValues','Messages','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','defaults','localhost','socket.io-emitter','redis','register','jayson/promise','client','http','then','info','WhatsappAccount,\x20%s,\x20%s','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','sendStatus','end','status','json','offset','limit','undefined','count','Content-Range','apply','reject','save','UserProfileResource'];(function(_0x5ed54f,_0x104679){var _0x4b2023=function(_0x5a570c){while(--_0x5a570c){_0x5ed54f['push'](_0x5ed54f['shift']());}};_0x4b2023(++_0x104679);}(_0xc79f,0x82));var _0xfc79=function(_0x2bf635,_0x454fe4){_0x2bf635=_0x2bf635-0x0;var _0xfed6a=_0xc79f[_0x2bf635];return _0xfed6a;};'use strict';var emlformat=require(_0xfc79('0x0'));var rimraf=require(_0xfc79('0x1'));var zipdir=require(_0xfc79('0x2'));var jsonpatch=require(_0xfc79('0x3'));var rp=require(_0xfc79('0x4'));var moment=require('moment');var BPromise=require(_0xfc79('0x5'));var Mustache=require(_0xfc79('0x6'));var util=require(_0xfc79('0x7'));var path=require(_0xfc79('0x8'));var sox=require(_0xfc79('0x9'));var csv=require(_0xfc79('0xa'));var ejs=require(_0xfc79('0xb'));var fs=require('fs');var fs_extra=require(_0xfc79('0xc'));var _=require(_0xfc79('0xd'));var squel=require('squel');var crypto=require(_0xfc79('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xfc79('0xf'));var toCsv=require(_0xfc79('0xa'));var querystring=require(_0xfc79('0x10'));var Papa=require('papaparse');var Redis=require(_0xfc79('0x11'));var authService=require(_0xfc79('0x12'));var qs=require(_0xfc79('0x13'));var as=require(_0xfc79('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xfc79('0x15'))(_0xfc79('0x16'));var utils=require(_0xfc79('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0xfc79('0x18'));var db=require(_0xfc79('0x19'))['db'];config['redis']=_[_0xfc79('0x1a')](config['redis'],{'host':_0xfc79('0x1b'),'port':0x18eb});var socket=require(_0xfc79('0x1c'))(new Redis(config[_0xfc79('0x1d')]));require('./whatsappAccount.socket')[_0xfc79('0x1e')](socket);var jayson=require(_0xfc79('0x1f'));var client=jayson[_0xfc79('0x20')][_0xfc79('0x21')]({'port':0x232c});function respondWithRpcPromise(_0x895b17,_0x7ef734,_0x4cb052,_0x228dab){return new BPromise(function(_0x4625da,_0x44e29e){var _0x322972=_0x228dab||client;return _0x322972['request'](_0x895b17,_0x4cb052)[_0xfc79('0x22')](function(_0x2eebdc){logger[_0xfc79('0x23')](_0xfc79('0x24'),_0x7ef734,'request\x20sent');logger['debug'](_0xfc79('0x25'),_0x7ef734,'request\x20sent',JSON[_0xfc79('0x26')](_0x2eebdc));if(_0x2eebdc[_0xfc79('0x27')]){if(_0x2eebdc[_0xfc79('0x27')][_0xfc79('0x28')]===0x1f4){logger['error'](_0xfc79('0x24'),_0x7ef734,_0x2eebdc[_0xfc79('0x27')][_0xfc79('0x29')]);return _0x44e29e(_0x2eebdc[_0xfc79('0x27')][_0xfc79('0x29')]);}logger[_0xfc79('0x27')](_0xfc79('0x24'),_0x7ef734,_0x2eebdc['error'][_0xfc79('0x29')]);return _0x4625da(_0x2eebdc[_0xfc79('0x27')][_0xfc79('0x29')]);}else{logger[_0xfc79('0x23')](_0xfc79('0x24'),_0x7ef734,'request\x20sent');_0x4625da(_0x2eebdc['result']['message']);}})[_0xfc79('0x2a')](function(_0x3dc4e4){logger[_0xfc79('0x27')](_0xfc79('0x24'),_0x7ef734,_0x3dc4e4);_0x44e29e(_0x3dc4e4);});});}function respondWithStatusCode(_0x5dcf36,_0x1c152){_0x1c152=_0x1c152||0xcc;return function(_0x5ca265){if(_0x5ca265){return _0x5dcf36[_0xfc79('0x2b')](_0x1c152);}return _0x5dcf36['status'](_0x1c152)[_0xfc79('0x2c')]();};}function respondWithResult(_0x3206fb,_0x96ceeb){_0x96ceeb=_0x96ceeb||0xc8;return function(_0x523270){if(_0x523270){return _0x3206fb[_0xfc79('0x2d')](_0x96ceeb)[_0xfc79('0x2e')](_0x523270);}};}function respondWithFilteredResult(_0x168ec2,_0x3a8ca3){return function(_0x2ae979){if(_0x2ae979){var _0x158b2f=typeof _0x3a8ca3[_0xfc79('0x2f')]==='undefined'&&typeof _0x3a8ca3[_0xfc79('0x30')]===_0xfc79('0x31');var _0x333af1=_0x2ae979[_0xfc79('0x32')];var _0x52212b=_0x158b2f?0x0:_0x3a8ca3[_0xfc79('0x2f')];var _0x106f1a=_0x158b2f?_0x2ae979[_0xfc79('0x32')]:_0x3a8ca3[_0xfc79('0x2f')]+_0x3a8ca3[_0xfc79('0x30')];var _0x4715d8;if(_0x106f1a>=_0x333af1){_0x106f1a=_0x333af1;_0x4715d8=0xc8;}else{_0x4715d8=0xce;}_0x168ec2['status'](_0x4715d8);return _0x168ec2['set'](_0xfc79('0x33'),_0x52212b+'-'+_0x106f1a+'/'+_0x333af1)['json'](_0x2ae979);}return null;};}function patchUpdates(_0x137420){return function(_0x324b52){try{jsonpatch[_0xfc79('0x34')](_0x324b52,_0x137420,!![]);}catch(_0x23a827){return BPromise[_0xfc79('0x35')](_0x23a827);}return _0x324b52[_0xfc79('0x36')]();};}function saveUpdates(_0x284a7e,_0x384271){return function(_0x22b206){if(_0x22b206){return _0x22b206['update'](_0x284a7e)[_0xfc79('0x22')](function(_0x43a26d){return _0x43a26d;});}return null;};}function removeEntity(_0x36c224,_0x2aac80){return function(_0x19eb4c){if(_0x19eb4c){return _0x19eb4c['destroy']()[_0xfc79('0x22')](function(){var _0x25deb8=_0x19eb4c['get']({'plain':!![]});var _0x4f7df6='WhatsappAccounts';return db[_0xfc79('0x37')][_0xfc79('0x38')]({'where':{'type':_0x4f7df6,'resourceId':_0x25deb8['id']}})[_0xfc79('0x22')](function(){return _0x19eb4c;});})[_0xfc79('0x22')](function(){_0x36c224[_0xfc79('0x2d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2126f9,_0x2ef7f5){return function(_0x274edc){if(!_0x274edc){_0x2126f9['sendStatus'](0x194);}return _0x274edc;};}function handleError(_0xa101a1,_0x26632a){_0x26632a=_0x26632a||0x1f4;return function(_0x5acace){logger['error'](_0x5acace[_0xfc79('0x39')]);if(_0x5acace[_0xfc79('0x3a')]){delete _0x5acace[_0xfc79('0x3a')];}_0xa101a1[_0xfc79('0x2d')](_0x26632a)[_0xfc79('0x3b')](_0x5acace);};}function getMustacheRender(_0x2abb2a,_0x812fb5){return Mustache[_0xfc79('0x3c')](_0x2abb2a,_[_0xfc79('0x3d')](_0x812fb5['body'],{'contact':_0x812fb5[_0xfc79('0x3e')],'message':_0x812fb5[_0xfc79('0x29')],'agent':_0x812fb5[_0xfc79('0x3f')],'interaction':_0x812fb5['interaction'],'account':_0x812fb5[_0xfc79('0x40')]}))||'';}exports['index']=function(_0x1ae4e2,_0x36cb81){var _0x71dc7d={'include':[{'model':db[_0xfc79('0x41')],'as':_0xfc79('0x42')}]},_0x17d970={},_0x20f6ac={'count':0x0,'rows':[]};var _0x3022a7=_[_0xfc79('0x43')](db[_0xfc79('0x44')][_0xfc79('0x45')],function(_0xda4714){return{'name':_0xda4714[_0xfc79('0x46')],'type':_0xda4714[_0xfc79('0x47')][_0xfc79('0x48')]};});_0x17d970[_0xfc79('0x49')]=_[_0xfc79('0x43')](_0x3022a7,'name');_0x17d970[_0xfc79('0x4a')]=_['keys'](_0x1ae4e2[_0xfc79('0x4a')]);_0x17d970[_0xfc79('0x4b')]=_[_0xfc79('0x4c')](_0x17d970[_0xfc79('0x49')],_0x17d970[_0xfc79('0x4a')]);_0x71dc7d[_0xfc79('0x4d')]=_[_0xfc79('0x4c')](_0x17d970[_0xfc79('0x49')],qs[_0xfc79('0x4e')](_0x1ae4e2[_0xfc79('0x4a')][_0xfc79('0x4e')]));_0x71dc7d['attributes']=_0x71dc7d['attributes'][_0xfc79('0x4f')]?_0x71dc7d['attributes']:_0x17d970[_0xfc79('0x49')];if(!_0x1ae4e2['query']['hasOwnProperty'](_0xfc79('0x50'))){_0x71dc7d['limit']=qs[_0xfc79('0x30')](_0x1ae4e2[_0xfc79('0x4a')][_0xfc79('0x30')]);_0x71dc7d[_0xfc79('0x2f')]=qs['offset'](_0x1ae4e2[_0xfc79('0x4a')][_0xfc79('0x2f')]);}_0x71dc7d['order']=qs[_0xfc79('0x51')](_0x1ae4e2[_0xfc79('0x4a')][_0xfc79('0x51')]);_0x71dc7d[_0xfc79('0x52')]=qs[_0xfc79('0x4b')](_[_0xfc79('0x53')](_0x1ae4e2[_0xfc79('0x4a')],_0x17d970[_0xfc79('0x4b')]),_0x3022a7);if(_0x1ae4e2[_0xfc79('0x4a')][_0xfc79('0x54')]){_0x71dc7d['where']=_['merge'](_0x71dc7d['where'],{'$or':_[_0xfc79('0x43')](_0x3022a7,function(_0x2002d4){if(_0x2002d4['type']!=='VIRTUAL'){var _0x2c3b32={};_0x2c3b32[_0x2002d4[_0xfc79('0x3a')]]={'$like':'%'+_0x1ae4e2[_0xfc79('0x4a')][_0xfc79('0x54')]+'%'};return _0x2c3b32;}})});}_0x71dc7d=_[_0xfc79('0x3d')]({},_0x71dc7d,_0x1ae4e2['options']);var _0x3148e5={'where':_0x71dc7d[_0xfc79('0x52')]};return db['WhatsappAccount'][_0xfc79('0x32')](_0x3148e5)['then'](function(_0x2cada8){_0x20f6ac[_0xfc79('0x32')]=_0x2cada8;if(_0x1ae4e2[_0xfc79('0x4a')][_0xfc79('0x55')]){_0x71dc7d['include']=[{'all':!![]}];}return db[_0xfc79('0x44')][_0xfc79('0x56')](_0x71dc7d);})[_0xfc79('0x22')](function(_0x44804b){_0x20f6ac[_0xfc79('0x57')]=_0x44804b;return _0x20f6ac;})['then'](respondWithFilteredResult(_0x36cb81,_0x71dc7d))[_0xfc79('0x2a')](handleError(_0x36cb81,null));};exports[_0xfc79('0x58')]=function(_0x4eceb2,_0x249705){var _0x42898b={'raw':![],'where':{'id':_0x4eceb2[_0xfc79('0x59')]['id']},'include':[{'model':db[_0xfc79('0x41')],'as':_0xfc79('0x42')}]},_0x4363ec={};_0x4363ec[_0xfc79('0x49')]=_['keys'](db['WhatsappAccount'][_0xfc79('0x45')]);_0x4363ec[_0xfc79('0x4a')]=_[_0xfc79('0x5a')](_0x4eceb2[_0xfc79('0x4a')]);_0x4363ec['filters']=_[_0xfc79('0x4c')](_0x4363ec[_0xfc79('0x49')],_0x4363ec[_0xfc79('0x4a')]);_0x42898b[_0xfc79('0x4d')]=_['intersection'](_0x4363ec[_0xfc79('0x49')],qs[_0xfc79('0x4e')](_0x4eceb2[_0xfc79('0x4a')][_0xfc79('0x4e')]));_0x42898b[_0xfc79('0x4d')]=_0x42898b[_0xfc79('0x4d')][_0xfc79('0x4f')]?_0x42898b[_0xfc79('0x4d')]:_0x4363ec['model'];if(_0x4eceb2[_0xfc79('0x4a')][_0xfc79('0x55')]){_0x42898b[_0xfc79('0x5b')]=[{'all':!![]}];}_0x42898b=_['merge']({},_0x42898b,_0x4eceb2['options']);return db[_0xfc79('0x44')][_0xfc79('0x5c')](_0x42898b)['then'](handleEntityNotFound(_0x249705,null))[_0xfc79('0x22')](respondWithResult(_0x249705,null))[_0xfc79('0x2a')](handleError(_0x249705,null));};exports['create']=function(_0x4885d4,_0x20dea4){return db['WhatsappAccount'][_0xfc79('0x5d')](_0x4885d4['body'],{})[_0xfc79('0x22')](function(_0x1ff468){var _0x171cf8=_0x4885d4[_0xfc79('0x5e')][_0xfc79('0x5f')]({'plain':!![]});if(!_0x171cf8)throw new Error(_0xfc79('0x60'));if(_0x171cf8['role']==='user'){var _0x42ed31=_0x1ff468['get']({'plain':!![]});var _0x1644be=_0xfc79('0x61');return db[_0xfc79('0x62')]['find']({'where':{'name':_0x1644be,'userProfileId':_0x171cf8[_0xfc79('0x63')]},'raw':!![]})[_0xfc79('0x22')](function(_0x2b1b25){if(_0x2b1b25&&_0x2b1b25[_0xfc79('0x64')]===0x0){return db[_0xfc79('0x37')][_0xfc79('0x5d')]({'name':_0x42ed31[_0xfc79('0x3a')],'resourceId':_0x42ed31['id'],'type':_0x2b1b25[_0xfc79('0x3a')],'sectionId':_0x2b1b25['id']},{})[_0xfc79('0x22')](function(){return _0x1ff468;});}else{return _0x1ff468;}})['catch'](function(_0x4b1667){logger[_0xfc79('0x27')](_0xfc79('0x65'),_0x4b1667);throw _0x4b1667;});}return _0x1ff468;})[_0xfc79('0x22')](respondWithResult(_0x20dea4,0xc9))[_0xfc79('0x2a')](handleError(_0x20dea4,null));};exports['update']=function(_0x173460,_0x4035b6){if(_0x173460[_0xfc79('0x66')]['id']){delete _0x173460[_0xfc79('0x66')]['id'];}return db[_0xfc79('0x44')][_0xfc79('0x5c')]({'where':{'id':_0x173460[_0xfc79('0x59')]['id']},'include':[{'model':db[_0xfc79('0x41')],'as':_0xfc79('0x42')}]})[_0xfc79('0x22')](handleEntityNotFound(_0x4035b6,null))[_0xfc79('0x22')](saveUpdates(_0x173460['body'],null))[_0xfc79('0x22')](respondWithResult(_0x4035b6,null))[_0xfc79('0x2a')](handleError(_0x4035b6,null));};exports[_0xfc79('0x38')]=function(_0xf894e,_0xd05ed3){return db['WhatsappAccount'][_0xfc79('0x5c')]({'where':{'id':_0xf894e['params']['id']}})[_0xfc79('0x22')](handleEntityNotFound(_0xd05ed3,null))[_0xfc79('0x22')](removeEntity(_0xd05ed3,null))[_0xfc79('0x2a')](handleError(_0xd05ed3,null));};exports[_0xfc79('0x67')]=function(_0x8849cd,_0x316640){return db[_0xfc79('0x44')][_0xfc79('0x67')]()[_0xfc79('0x22')](respondWithResult(_0x316640,null))[_0xfc79('0x2a')](handleError(_0x316640,null));};exports[_0xfc79('0x68')]=function(_0x4e04e4,_0x362273,_0x59c330){if(_0x4e04e4[_0xfc79('0x66')]['id']){delete _0x4e04e4['body']['id'];}return db[_0xfc79('0x44')][_0xfc79('0x5c')]({'where':{'id':_0x4e04e4[_0xfc79('0x59')]['id']}})[_0xfc79('0x22')](handleEntityNotFound(_0x362273,null))[_0xfc79('0x22')](function(_0x1883f5){if(_0x1883f5){_0x4e04e4[_0xfc79('0x66')]['WhatsappAccountId']=_0x1883f5['id'];return db[_0xfc79('0x69')][_0xfc79('0x5d')](_0x4e04e4['body']);}})['then'](respondWithResult(_0x362273,null))['catch'](handleError(_0x362273,null));};exports[_0xfc79('0x6a')]=function(_0x30f193,_0x20d5ac,_0x4d545c){var _0xdf008b={'raw':![],'where':{}};var _0x535854={};var _0x470650={'count':0x0,'rows':[]};return db['WhatsappAccount']['findOne']({'where':{'id':_0x30f193[_0xfc79('0x59')]['id']}})['then'](handleEntityNotFound(_0x20d5ac,null))['then'](function(_0x460a7d){if(_0x460a7d){_0x535854[_0xfc79('0x49')]=_[_0xfc79('0x5a')](db[_0xfc79('0x69')]['rawAttributes']);_0x535854[_0xfc79('0x4a')]=_[_0xfc79('0x5a')](_0x30f193[_0xfc79('0x4a')]);_0x535854[_0xfc79('0x4b')]=_[_0xfc79('0x4c')](_0x535854[_0xfc79('0x49')],_0x535854['query']);_0xdf008b[_0xfc79('0x4d')]=_[_0xfc79('0x4c')](_0x535854[_0xfc79('0x49')],qs['fields'](_0x30f193['query'][_0xfc79('0x4e')]));_0xdf008b[_0xfc79('0x4d')]=_0xdf008b[_0xfc79('0x4d')][_0xfc79('0x4f')]?_0xdf008b[_0xfc79('0x4d')]:_0x535854[_0xfc79('0x49')];if(!_0x30f193[_0xfc79('0x4a')]['hasOwnProperty']('nolimit')){_0xdf008b[_0xfc79('0x30')]=qs['limit'](_0x30f193[_0xfc79('0x4a')]['limit']);_0xdf008b[_0xfc79('0x2f')]=qs[_0xfc79('0x2f')](_0x30f193['query'][_0xfc79('0x2f')]);}_0xdf008b[_0xfc79('0x6b')]=qs[_0xfc79('0x51')](_0x30f193['query']['sort']);_0xdf008b['where']=qs['filters'](_[_0xfc79('0x53')](_0x30f193[_0xfc79('0x4a')],_0x535854[_0xfc79('0x4b')]));_0xdf008b[_0xfc79('0x52')][_0xfc79('0x6c')]=_0x460a7d['id'];if(_0x30f193['query'][_0xfc79('0x54')]){_0xdf008b[_0xfc79('0x52')]=_['merge'](_0xdf008b['where'],{'$or':_[_0xfc79('0x43')](_0xdf008b['attributes'],function(_0x288f94){var _0x23662b={};_0x23662b[_0x288f94]={'$like':'%'+_0x30f193[_0xfc79('0x4a')]['filter']+'%'};return _0x23662b;})});}_0xdf008b=_[_0xfc79('0x3d')]({},_0xdf008b,_0x30f193[_0xfc79('0x6d')]);return db[_0xfc79('0x69')][_0xfc79('0x32')]({'where':_0xdf008b['where']})['then'](function(_0x4407b1){_0x470650[_0xfc79('0x32')]=_0x4407b1;if(_0x30f193[_0xfc79('0x4a')][_0xfc79('0x55')]){_0xdf008b[_0xfc79('0x5b')]=[{'all':!![]}];}return db['Disposition'][_0xfc79('0x56')](_0xdf008b);})[_0xfc79('0x22')](function(_0x36226a){_0x470650[_0xfc79('0x57')]=_0x36226a;return _0x470650;});}})[_0xfc79('0x22')](respondWithFilteredResult(_0x20d5ac,_0xdf008b))[_0xfc79('0x2a')](handleError(_0x20d5ac,null));};exports[_0xfc79('0x6e')]=function(_0x31a27c,_0x71b37,_0x2d3d0c){return db[_0xfc79('0x44')][_0xfc79('0x5c')]({'where':{'id':_0x31a27c[_0xfc79('0x59')]['id']}})[_0xfc79('0x22')](handleEntityNotFound(_0x71b37,null))[_0xfc79('0x22')](function(_0x1d4ae0){if(_0x1d4ae0){return _0x1d4ae0[_0xfc79('0x6e')](_0x31a27c['query'][_0xfc79('0x6f')]);}})[_0xfc79('0x22')](respondWithStatusCode(_0x71b37,null))[_0xfc79('0x2a')](handleError(_0x71b37,null));};exports[_0xfc79('0x70')]=function(_0x59d117,_0x14ef97,_0x361f69){if(_0x59d117[_0xfc79('0x66')]['id']){delete _0x59d117['body']['id'];}return db['WhatsappAccount']['find']({'where':{'id':_0x59d117[_0xfc79('0x59')]['id']}})[_0xfc79('0x22')](handleEntityNotFound(_0x14ef97,null))[_0xfc79('0x22')](function(_0x1ae589){if(_0x1ae589){_0x59d117[_0xfc79('0x66')][_0xfc79('0x6c')]=_0x1ae589['id'];return db[_0xfc79('0x71')][_0xfc79('0x5d')](_0x59d117['body']);}})[_0xfc79('0x22')](respondWithResult(_0x14ef97,null))['catch'](handleError(_0x14ef97,null));};exports[_0xfc79('0x72')]=function(_0x582b4b,_0x20f47e,_0x3c2361){var _0x526ca4={'raw':![],'where':{}};var _0x1640a4={};var _0xa9229={'count':0x0,'rows':[]};return db[_0xfc79('0x44')][_0xfc79('0x73')]({'where':{'id':_0x582b4b[_0xfc79('0x59')]['id']}})['then'](handleEntityNotFound(_0x20f47e,null))[_0xfc79('0x22')](function(_0x4ed043){if(_0x4ed043){_0x1640a4[_0xfc79('0x49')]=_[_0xfc79('0x5a')](db[_0xfc79('0x71')]['rawAttributes']);_0x1640a4[_0xfc79('0x4a')]=_[_0xfc79('0x5a')](_0x582b4b[_0xfc79('0x4a')]);_0x1640a4[_0xfc79('0x4b')]=_['intersection'](_0x1640a4['model'],_0x1640a4[_0xfc79('0x4a')]);_0x526ca4['attributes']=_[_0xfc79('0x4c')](_0x1640a4[_0xfc79('0x49')],qs[_0xfc79('0x4e')](_0x582b4b[_0xfc79('0x4a')][_0xfc79('0x4e')]));_0x526ca4[_0xfc79('0x4d')]=_0x526ca4[_0xfc79('0x4d')][_0xfc79('0x4f')]?_0x526ca4['attributes']:_0x1640a4[_0xfc79('0x49')];if(!_0x582b4b[_0xfc79('0x4a')][_0xfc79('0x74')](_0xfc79('0x50'))){_0x526ca4[_0xfc79('0x30')]=qs['limit'](_0x582b4b[_0xfc79('0x4a')][_0xfc79('0x30')]);_0x526ca4['offset']=qs['offset'](_0x582b4b[_0xfc79('0x4a')][_0xfc79('0x2f')]);}_0x526ca4[_0xfc79('0x6b')]=qs['sort'](_0x582b4b[_0xfc79('0x4a')][_0xfc79('0x51')]);_0x526ca4[_0xfc79('0x52')]=qs[_0xfc79('0x4b')](_[_0xfc79('0x53')](_0x582b4b[_0xfc79('0x4a')],_0x1640a4[_0xfc79('0x4b')]));_0x526ca4[_0xfc79('0x52')]['WhatsappAccountId']=_0x4ed043['id'];if(_0x582b4b[_0xfc79('0x4a')][_0xfc79('0x54')]){_0x526ca4[_0xfc79('0x52')]=_[_0xfc79('0x3d')](_0x526ca4['where'],{'$or':_[_0xfc79('0x43')](_0x526ca4[_0xfc79('0x4d')],function(_0x436ae7){var _0x34391c={};_0x34391c[_0x436ae7]={'$like':'%'+_0x582b4b[_0xfc79('0x4a')][_0xfc79('0x54')]+'%'};return _0x34391c;})});}_0x526ca4=_[_0xfc79('0x3d')]({},_0x526ca4,_0x582b4b[_0xfc79('0x6d')]);return db[_0xfc79('0x71')][_0xfc79('0x32')]({'where':_0x526ca4['where']})['then'](function(_0x1a236d){_0xa9229['count']=_0x1a236d;if(_0x582b4b['query']['includeAll']){_0x526ca4[_0xfc79('0x5b')]=[{'all':!![]}];}return db['CannedAnswer'][_0xfc79('0x56')](_0x526ca4);})['then'](function(_0x8452b4){_0xa9229['rows']=_0x8452b4;return _0xa9229;});}})[_0xfc79('0x22')](respondWithFilteredResult(_0x20f47e,_0x526ca4))[_0xfc79('0x2a')](handleError(_0x20f47e,null));};exports[_0xfc79('0x75')]=function(_0x49f31e,_0x277bde,_0x417eec){return db[_0xfc79('0x44')][_0xfc79('0x5c')]({'where':{'id':_0x49f31e['params']['id']}})[_0xfc79('0x22')](handleEntityNotFound(_0x277bde,null))[_0xfc79('0x22')](function(_0xdb9dc5){if(_0xdb9dc5){return _0xdb9dc5[_0xfc79('0x75')](_0x49f31e['query'][_0xfc79('0x6f')]);}})[_0xfc79('0x22')](respondWithStatusCode(_0x277bde,null))[_0xfc79('0x2a')](handleError(_0x277bde,null));};exports['addAgents']=function(_0x1d1fcc,_0x59a6f2,_0x3d79c0){return db[_0xfc79('0x44')][_0xfc79('0x5c')]({'where':{'id':_0x1d1fcc[_0xfc79('0x59')]['id']}})[_0xfc79('0x22')](handleEntityNotFound(_0x59a6f2,null))[_0xfc79('0x22')](function(_0x2b92e9){if(_0x2b92e9){return _0x2b92e9[_0xfc79('0x76')](_0x1d1fcc[_0xfc79('0x66')][_0xfc79('0x6f')],_[_0xfc79('0x77')](_0x1d1fcc['body'],[_0xfc79('0x6f'),'id'])||{})[_0xfc79('0x78')](function(_0x1cf991){for(var _0x5acd5c=0x0;_0x5acd5c<_0x1d1fcc[_0xfc79('0x66')][_0xfc79('0x6f')][_0xfc79('0x4f')];_0x5acd5c+=0x1){socket['emit'](_0xfc79('0x79'),{'UserId':_0x1d1fcc[_0xfc79('0x66')][_0xfc79('0x6f')][_0x5acd5c],'WhatsappAccountId':_0x1d1fcc[_0xfc79('0x59')]['id']});}return _0x1cf991;});}})[_0xfc79('0x22')](respondWithResult(_0x59a6f2,null))[_0xfc79('0x2a')](handleError(_0x59a6f2,null));};exports[_0xfc79('0x7a')]=function(_0x1e7c9a,_0x17d0b6,_0x1d74a3){return db[_0xfc79('0x44')][_0xfc79('0x5c')]({'where':{'id':_0x1e7c9a[_0xfc79('0x59')]['id']}})[_0xfc79('0x22')](handleEntityNotFound(_0x17d0b6,null))[_0xfc79('0x22')](function(_0x2ab60d){if(_0x2ab60d){return _0x2ab60d[_0xfc79('0x7a')](_0x1e7c9a[_0xfc79('0x4a')][_0xfc79('0x6f')])[_0xfc79('0x22')](function(){if(_[_0xfc79('0x7b')](_0x1e7c9a['query'][_0xfc79('0x6f')])){for(var _0x16e844=0x0;_0x16e844<_0x1e7c9a[_0xfc79('0x4a')][_0xfc79('0x6f')][_0xfc79('0x4f')];_0x16e844+=0x1){socket['emit'](_0xfc79('0x7c'),{'UserId':Number(_0x1e7c9a[_0xfc79('0x4a')][_0xfc79('0x6f')][_0x16e844]),'WhatsappAccountId':Number(_0x1e7c9a[_0xfc79('0x59')]['id'])});}}else{socket['emit'](_0xfc79('0x7c'),{'UserId':Number(_0x1e7c9a[_0xfc79('0x4a')][_0xfc79('0x6f')]),'WhatsappAccountId':Number(_0x1e7c9a[_0xfc79('0x59')]['id'])});}});}})[_0xfc79('0x22')](respondWithStatusCode(_0x17d0b6,null))[_0xfc79('0x2a')](handleError(_0x17d0b6,null));};exports['getAgents']=function(_0x35ff21,_0x5ea80c,_0x48177e){var _0x3c8be8={};var _0x3cb350={};var _0x3fbdbe;var _0x51315b;return db['WhatsappAccount']['findOne']({'where':{'id':_0x35ff21[_0xfc79('0x59')]['id']}})[_0xfc79('0x22')](handleEntityNotFound(_0x5ea80c,null))['then'](function(_0x344418){if(_0x344418){_0x3fbdbe=_0x344418;_0x3cb350[_0xfc79('0x49')]=_[_0xfc79('0x5a')](db[_0xfc79('0x7d')]['rawAttributes']);_0x3cb350[_0xfc79('0x4a')]=_['keys'](_0x35ff21[_0xfc79('0x4a')]);_0x3cb350[_0xfc79('0x4b')]=_[_0xfc79('0x4c')](_0x3cb350[_0xfc79('0x49')],_0x3cb350[_0xfc79('0x4a')]);_0x3c8be8['attributes']=_['intersection'](_0x3cb350[_0xfc79('0x49')],qs[_0xfc79('0x4e')](_0x35ff21['query'][_0xfc79('0x4e')]));_0x3c8be8[_0xfc79('0x4d')]=_0x3c8be8[_0xfc79('0x4d')]['length']?_0x3c8be8[_0xfc79('0x4d')]:_0x3cb350[_0xfc79('0x49')];_0x3c8be8['order']=qs[_0xfc79('0x51')](_0x35ff21[_0xfc79('0x4a')][_0xfc79('0x51')]);_0x3c8be8[_0xfc79('0x52')]=qs[_0xfc79('0x4b')](_['pick'](_0x35ff21[_0xfc79('0x4a')],_0x3cb350[_0xfc79('0x4b')]));if(_0x35ff21[_0xfc79('0x4a')][_0xfc79('0x54')]){_0x3c8be8[_0xfc79('0x52')]=_[_0xfc79('0x3d')](_0x3c8be8['where'],{'$or':_[_0xfc79('0x43')](_0x3c8be8[_0xfc79('0x4d')],function(_0x148522){var _0x15c19e={};_0x15c19e[_0x148522]={'$like':'%'+_0x35ff21[_0xfc79('0x4a')][_0xfc79('0x54')]+'%'};return _0x15c19e;})});}_0x3c8be8=_['merge']({},_0x3c8be8,_0x35ff21[_0xfc79('0x6d')]);return _0x3fbdbe['getAgents'](_0x3c8be8);}})['then'](function(_0x14b39b){if(_0x14b39b){_0x51315b=_0x14b39b[_0xfc79('0x4f')];if(!_0x35ff21[_0xfc79('0x4a')][_0xfc79('0x74')](_0xfc79('0x50'))){_0x3c8be8['limit']=qs[_0xfc79('0x30')](_0x35ff21['query'][_0xfc79('0x30')]);_0x3c8be8[_0xfc79('0x2f')]=qs[_0xfc79('0x2f')](_0x35ff21['query'][_0xfc79('0x2f')]);}return _0x3fbdbe[_0xfc79('0x7e')](_0x3c8be8);}})['then'](function(_0x40d755){if(_0x40d755){return _0x40d755?{'count':_0x51315b,'rows':_0x40d755}:null;}})[_0xfc79('0x22')](respondWithResult(_0x5ea80c,null))['catch'](handleError(_0x5ea80c,null));};exports['addApplications']=function(_0x4458ff,_0x2a9215,_0x49cbf6){return db[_0xfc79('0x44')]['findOne']({'where':{'id':_0x4458ff[_0xfc79('0x59')]['id']}})['then'](handleEntityNotFound(_0x2a9215,null))[_0xfc79('0x22')](function(_0x2aee9a){if(_0x2aee9a){return db['sequelize'][_0xfc79('0x7f')](function(_0x263a7e){return db[_0xfc79('0x80')]['destroy']({'where':{'WhatsappAccountId':_0x4458ff[_0xfc79('0x59')]['id']},'transaction':_0x263a7e})['then'](function(_0x4aaa11){var _0x427fcb=_[_0xfc79('0x43')](_0x4458ff[_0xfc79('0x66')],function(_0x59cd78){_0x59cd78[_0xfc79('0x6c')]=_0x4458ff[_0xfc79('0x59')]['id'];return _0x59cd78;});return db['WhatsappApplication'][_0xfc79('0x81')](_0x427fcb,{'transaction':_0x263a7e});});})[_0xfc79('0x22')](function(){return db['WhatsappApplication']['findAndCountAll']({'where':{'WhatsappAccountId':_0x4458ff[_0xfc79('0x59')]['id']},'order':_0xfc79('0x82')});});}})[_0xfc79('0x22')](respondWithResult(_0x2a9215,null))[_0xfc79('0x2a')](handleError(_0x2a9215,null));};exports[_0xfc79('0x83')]=function(_0x1e016b,_0x3a8880,_0x48c122){var _0x24366e={};var _0x596732={};var _0x1e3200;var _0x1656f5;return db['WhatsappAccount'][_0xfc79('0x73')]({'where':{'id':_0x1e016b[_0xfc79('0x59')]['id']}})[_0xfc79('0x22')](handleEntityNotFound(_0x3a8880,null))['then'](function(_0x3817e4){if(_0x3817e4){_0x1e3200=_0x3817e4;_0x596732[_0xfc79('0x49')]=_[_0xfc79('0x5a')](db[_0xfc79('0x80')]['rawAttributes']);_0x596732[_0xfc79('0x4a')]=_[_0xfc79('0x5a')](_0x1e016b[_0xfc79('0x4a')]);_0x596732[_0xfc79('0x4b')]=_[_0xfc79('0x4c')](_0x596732[_0xfc79('0x49')],_0x596732['query']);_0x24366e[_0xfc79('0x4d')]=_[_0xfc79('0x4c')](_0x596732[_0xfc79('0x49')],qs[_0xfc79('0x4e')](_0x1e016b['query'][_0xfc79('0x4e')]));_0x24366e[_0xfc79('0x4d')]=_0x24366e[_0xfc79('0x4d')][_0xfc79('0x4f')]?_0x24366e[_0xfc79('0x4d')]:_0x596732[_0xfc79('0x49')];_0x24366e[_0xfc79('0x6b')]=qs[_0xfc79('0x51')](_0x1e016b[_0xfc79('0x4a')][_0xfc79('0x51')]);_0x24366e[_0xfc79('0x52')]=qs[_0xfc79('0x4b')](_[_0xfc79('0x53')](_0x1e016b['query'],_0x596732[_0xfc79('0x4b')]));if(_0x1e016b[_0xfc79('0x4a')][_0xfc79('0x54')]){_0x24366e[_0xfc79('0x52')]=_[_0xfc79('0x3d')](_0x24366e[_0xfc79('0x52')],{'$or':_['map'](_0x24366e[_0xfc79('0x4d')],function(_0x5f43cd){var _0x9c9d56={};_0x9c9d56[_0x5f43cd]={'$like':'%'+_0x1e016b[_0xfc79('0x4a')][_0xfc79('0x54')]+'%'};return _0x9c9d56;})});}_0x24366e=_[_0xfc79('0x3d')]({},_0x24366e,_0x1e016b[_0xfc79('0x6d')]);return _0x1e3200[_0xfc79('0x83')](_0x24366e);}})[_0xfc79('0x22')](function(_0x61b973){if(_0x61b973){_0x1656f5=_0x61b973[_0xfc79('0x4f')];if(!_0x1e016b['query'][_0xfc79('0x74')](_0xfc79('0x50'))){_0x24366e[_0xfc79('0x30')]=qs[_0xfc79('0x30')](_0x1e016b[_0xfc79('0x4a')][_0xfc79('0x30')]);_0x24366e[_0xfc79('0x2f')]=qs[_0xfc79('0x2f')](_0x1e016b['query'][_0xfc79('0x2f')]);}return _0x1e3200['getApplications'](_0x24366e);}})[_0xfc79('0x22')](function(_0xa9cb60){if(_0xa9cb60){return _0xa9cb60?{'count':_0x1656f5,'rows':_0xa9cb60}:null;}})['then'](respondWithResult(_0x3a8880,null))[_0xfc79('0x2a')](handleError(_0x3a8880,null));};exports['notify']=function(_0x561fa5,_0x1e196f,_0x5164ee){var _0x5e88a0={'channel':_0xfc79('0x84')};var _0xcee408=[];var _0x33ba54=[];var _0x1d6090={};return db[_0xfc79('0x44')][_0xfc79('0x5c')]({'where':{'id':_0x561fa5['params']['id']},'include':[{'model':db[_0xfc79('0x80')],'as':_0xfc79('0x85')}]})[_0xfc79('0x22')](handleEntityNotFound(_0x1e196f,null))[_0xfc79('0x22')](function(_0x45aad1){_0x5e88a0[_0xfc79('0x40')]=_0x45aad1;_0x5e88a0[_0xfc79('0x86')]=_[_0xfc79('0x87')](_0x45aad1['Applications'],[_0xfc79('0x82')],[_0xfc79('0x88')]);if(_0x5e88a0['account'][_0xfc79('0x85')]){delete _0x5e88a0[_0xfc79('0x40')][_0xfc79('0x85')];}return db[_0xfc79('0x89')][_0xfc79('0x67')]();})[_0xfc79('0x22')](function(_0x10ecff){if(!_0x10ecff){throw new db['Sequelize'][(_0xfc79('0x8a'))](_0xfc79('0x8b'));}_0xcee408=_['difference'](_[_0xfc79('0x5a')](_0x10ecff),[_0xfc79('0x8c'),'updatedAt']);_0x33ba54=_[_0xfc79('0x8d')](_[_0xfc79('0x5a')](_0x10ecff),[_0xfc79('0x8c'),_0xfc79('0x8e'),_0xfc79('0x8f'),'ListId']);_0x5e88a0[_0xfc79('0x66')]={'mapKey':_0xfc79('0x90')};if(_0x5e88a0[_0xfc79('0x40')]['type']&&_0x5e88a0['account'][_0xfc79('0x47')]==='twilio'){_0x5e88a0[_0xfc79('0x66')][_0xfc79('0x91')]=_0x561fa5[_0xfc79('0x66')][_0xfc79('0x92')][_0xfc79('0x93')]('whatsapp:','');_0x5e88a0[_0xfc79('0x66')][_0xfc79('0x66')]=_0x561fa5[_0xfc79('0x66')][_0xfc79('0x94')];_0x5e88a0[_0xfc79('0x66')]['messageId']=_0x561fa5['body'][_0xfc79('0x95')];}if(_0x5e88a0[_0xfc79('0x66')]['id']){delete _0x5e88a0[_0xfc79('0x66')]['id'];}if(_[_0xfc79('0x96')](_0x5e88a0[_0xfc79('0x66')]['from'])){throw new db[(_0xfc79('0x97'))][(_0xfc79('0x8a'))]('from\x20is\x20mandatory');}if(_['isNil'](_0x5e88a0[_0xfc79('0x66')][_0xfc79('0x66')])||_0x5e88a0[_0xfc79('0x66')][_0xfc79('0x66')]===''){throw new db[(_0xfc79('0x97'))][(_0xfc79('0x8a'))](_0xfc79('0x98'));}if(_[_0xfc79('0x96')](_0x5e88a0['body'][_0xfc79('0x99')])){throw new db[(_0xfc79('0x97'))][(_0xfc79('0x8a'))](_0xfc79('0x9a')+_0x33ba54);}if(!_['includes'](_0x33ba54,_0x5e88a0[_0xfc79('0x66')]['mapKey'])){throw new db[(_0xfc79('0x97'))][(_0xfc79('0x8a'))](_0xfc79('0x9b')+_0x33ba54);}_0x1d6090[_0x5e88a0[_0xfc79('0x66')]['mapKey']]=_0x5e88a0[_0xfc79('0x66')]['from'];return db[_0xfc79('0x9c')][_0xfc79('0x5c')]({'where':{'id':_0x5e88a0[_0xfc79('0x40')][_0xfc79('0x9d')]},'include':[{'model':db['CmContact'],'as':_0xfc79('0x9e'),'where':_0x1d6090,'limit':0x1,'order':[[_0xfc79('0x8e'),_0xfc79('0x9f')]]}]});})[_0xfc79('0x22')](handleEntityNotFound(_0x1e196f,null))[_0xfc79('0x22')](function(_0x4b407d){if(_0x4b407d){_0x5e88a0['list']=_[_0xfc79('0x77')](_0x4b407d,['Contacts']);if(_0x4b407d['Contacts']['length']){return _0x4b407d[_0xfc79('0x9e')][0x0];}var _0x2fe8d4=_['defaults'](_0x5e88a0[_0xfc79('0x66')],{'firstName':_0x5e88a0[_0xfc79('0x66')][_0xfc79('0x91')],'ListId':_0x4b407d['id']});_0x2fe8d4[_0x5e88a0[_0xfc79('0x66')][_0xfc79('0x99')]]=_0x5e88a0[_0xfc79('0x66')][_0xfc79('0x91')];return db[_0xfc79('0x89')][_0xfc79('0x5d')](_0x2fe8d4,{'fields':_0xcee408,'raw':!![]});}})[_0xfc79('0x22')](handleEntityNotFound(_0x1e196f,null))[_0xfc79('0x22')](function(_0x5bfdd3){if(_0x5bfdd3){_0x5e88a0['contact']=_0x5bfdd3;var _0x3d6b2f={'ContactId':_0x5bfdd3['id'],'phone':_0x5e88a0[_0xfc79('0x66')][_0xfc79('0x91')],'WhatsappAccountId':_0x561fa5[_0xfc79('0x59')]['id']};var _0xbd6884={'ContactId':_0x5bfdd3['id'],'WhatsappAccountId':_0x561fa5['params']['id'],'closed':![]};return db[_0xfc79('0xa0')][_0xfc79('0x5c')]({'where':_0xbd6884})[_0xfc79('0x22')](function(_0x3fcadf){if(_0x3fcadf){return[_0x3fcadf,![]];}return db[_0xfc79('0xa0')][_0xfc79('0x5d')](_0x3d6b2f)[_0xfc79('0x22')](function(_0x3c2ab5){return[_0x3c2ab5,!![]];});});}})[_0xfc79('0x78')](function(_0x2cb3d8,_0x5ea4e8){_0x5e88a0[_0xfc79('0xa1')]=_0x2cb3d8[_0xfc79('0x5f')]({'plain':!![]});_0x5e88a0[_0xfc79('0xa1')][_0xfc79('0xa2')]=![];if(_0x5ea4e8){if(_0x5e88a0[_0xfc79('0x40')][_0xfc79('0xa3')]){_0x5e88a0['applications']['push']({'id':0x0,'priority':_0x5e88a0[_0xfc79('0x86')]['length']+0x1,'app':_0xfc79('0xa4'),'appdata':_0xfc79('0xa5'),'interval':'*,*,*,*'});}_0x5e88a0['interaction']['created']=!![];}return db[_0xfc79('0xa6')][_0xfc79('0x5d')]({'phone':_0x5e88a0['body']['from'],'messageId':_0x5e88a0['body'][_0xfc79('0xa7')],'body':_0x5e88a0[_0xfc79('0x66')][_0xfc79('0x66')],'WhatsappAccountId':_0x561fa5[_0xfc79('0x59')]['id'],'WhatsappInteractionId':_0x2cb3d8['id'],'direction':'in','ContactId':_0x2cb3d8['ContactId'],'AttachmentId':_0x5e88a0[_0xfc79('0x66')][_0xfc79('0xa8')]});})[_0xfc79('0x22')](function(_0x2d7482){_0x5e88a0[_0xfc79('0x29')]=_0x2d7482;if(_0x5e88a0[_0xfc79('0xa1')][_0xfc79('0xa9')]){return db['User'][_0xfc79('0x5c')]({'attributes':['id',_0xfc79('0x3a')],'where':{'id':_0x5e88a0[_0xfc79('0xa1')]['UserId']}})[_0xfc79('0x22')](function(_0x49160b){if(_0x49160b){_0x5e88a0[_0xfc79('0x86')][_0xfc79('0xaa')]({'id':0x0,'priority':0x0,'app':_0xfc79('0x3f'),'appdata':_0x49160b['name']+','+(_0x5e88a0[_0xfc79('0x40')]['waitForTheAssignedAgent']||0xa),'interval':_0xfc79('0xab')});}return respondWithRpcPromise(_0xfc79('0xac'),_0xfc79('0xad'),_0x5e88a0);});}return respondWithRpcPromise(_0xfc79('0xac'),'startRouting',_0x5e88a0);})[_0xfc79('0x22')](function(_0x1a1cb6){if(_0x1a1cb6){var _0x30f039=0xc8;var _0x482ba9=_0xfc79('0xae');logger[_0xfc79('0x23')](_0xfc79('0x25'),_0x482ba9,_0x30f039,'entity\x20found');logger['debug'](_0xfc79('0xaf'),_0x482ba9,_0x30f039,_0xfc79('0xb0'),JSON[_0xfc79('0x26')](_0x1a1cb6));if(_0x5e88a0[_0xfc79('0x40')]['type']===_0xfc79('0xb1')){return _0x1e196f[_0xfc79('0x2d')](_0x30f039)[_0xfc79('0xb2')](_0xfc79('0xb3'),_0xfc79('0xb4'))[_0xfc79('0x3b')](_0xfc79('0xb5'));}else{return _0x1e196f[_0xfc79('0x2d')](_0x30f039)[_0xfc79('0x2e')](_0x1a1cb6);}}})['catch'](handleError(_0x1e196f,null));};exports[_0xfc79('0x3b')]=function(_0x119905,_0x5a8afe,_0x11b49a){var _0x366a66,_0x437844,_0x70d9d;if(_[_0xfc79('0x96')](_0x119905['body']['body'])||_0x119905[_0xfc79('0x66')]['body']===''){throw new db[(_0xfc79('0x97'))]['ValidationError'](_0xfc79('0x98'));}if(_[_0xfc79('0x96')](_0x119905[_0xfc79('0x66')]['to'])){throw new db[(_0xfc79('0x97'))][(_0xfc79('0x8a'))]('to\x20is\x20mandatory');}_0x366a66=_0x119905[_0xfc79('0x66')]['to'];return db['WhatsappAccount']['find']({'where':{'id':_0x119905[_0xfc79('0x59')]['id']},'include':[{'model':db[_0xfc79('0x9c')],'as':_0xfc79('0xb6'),'include':[{'model':db[_0xfc79('0x89')],'as':'Contacts','where':{'mobile':_0x366a66},'limit':0x1,'order':[['updatedAt',_0xfc79('0x9f')]]}]}]})['then'](handleEntityNotFound(_0x5a8afe,null))[_0xfc79('0x22')](function(_0x3352ed){if(_0x3352ed&&_0x3352ed[_0xfc79('0xb6')]){_0x437844=_0x3352ed['get']({'plain':!![]});if(_0x437844['List']&&_0x437844[_0xfc79('0xb6')]['Contacts'][_0xfc79('0x4f')]){return _0x437844[_0xfc79('0xb6')][_0xfc79('0x9e')][0x0];}return db[_0xfc79('0x89')][_0xfc79('0x5d')](_[_0xfc79('0x1a')](_0x119905['body'],{'firstName':_0x366a66,'mobile':_0x366a66,'phone':_0x366a66,'ListId':_0x437844[_0xfc79('0x9d')]}));}})[_0xfc79('0x22')](handleEntityNotFound(_0x5a8afe,null))[_0xfc79('0x22')](function(_0x4ff5a2){if(_0x4ff5a2){_0x70d9d=_0x4ff5a2;return db[_0xfc79('0xa0')][_0xfc79('0x5c')]({'where':{'ContactId':_0x70d9d['id'],'closed':![],'WhatsappAccountId':_0x437844['id']}})['then'](function(_0x237322){if(_0x237322){return[_0x237322,![]];}return db[_0xfc79('0xa0')]['create']({'UserId':_0x119905[_0xfc79('0x5e')]['id'],'ContactId':_0x70d9d['id'],'WhatsappAccountId':_0x437844['id'],'phone':_0x366a66,'firstMsgDirection':_0xfc79('0xb7'),'Messages':[_['merge'](_0x119905[_0xfc79('0x66')],{'read':![],'body':_0x119905[_0xfc79('0x66')]['body'],'phone':_0x366a66,'WhatsappAccountId':_0x437844['id'],'UserId':_0x119905[_0xfc79('0x5e')]['id'],'ContactId':_0x70d9d['id']})]},{'include':[{'model':db['WhatsappMessage'],'as':'Messages'}]})['then'](function(_0x26e2ac){return[_0x26e2ac,!![]];});});}})['spread'](function(_0x1afa4f,_0x327a87){if(_0x327a87){return _0x1afa4f;}return db['WhatsappMessage'][_0xfc79('0x5d')](_['merge'](_0x119905[_0xfc79('0x66')],{'read':![],'body':_0x119905[_0xfc79('0x66')]['body'],'phone':_0x366a66,'WhatsappAccountId':_0x437844['id'],'WhatsappInteractionId':_0x1afa4f['id'],'UserId':_0x119905[_0xfc79('0x5e')]['id'],'ContactId':_0x70d9d['id']}))[_0xfc79('0x22')](function(_0x3ea611){_0x1afa4f[_0xfc79('0xb8')][_0xfc79('0xb9')]=[];_0x1afa4f['dataValues'][_0xfc79('0xb9')]['push'](_0x3ea611[_0xfc79('0xb8')]);return _0x1afa4f;});})[_0xfc79('0x22')](respondWithResult(_0x5a8afe,null))[_0xfc79('0x2a')](handleError(_0x5a8afe,null));};
\ No newline at end of file
+var _0x9b9b=['removeAnswers','addAgents','spread','emit','userWhatsappAccount:save','removeAgents','userWhatsappAccount:remove','getAgents','User','addApplications','sequelize','transaction','WhatsappApplication','bulkCreate','findAndCountAll','getApplications','notify','whatsapp','Applications','applications','orderBy','priority','asc','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','mobile','twilio','from','From','replace','whatsapp:','Body','messageId','MessageSid','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','CmContact','DESC','list','Contacts','WhatsappInteraction','created','autoclose','push','close','unmanaged','ContactId','AttachmentId','UserId','unshift','waitForTheAssignedAgent','*,*,*,*','Start','startRouting','receiveMessage','entity\x20found','debug','WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','to\x20is\x20mandatory','List','out','WhatsappMessage','Messages','dataValues','rimraf','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','register','client','http','request','info','WhatsappAccount,\x20%s,\x20%s','request\x20sent','WhatsappAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','save','update','then','destroy','get','WhatsappAccounts','sendStatus','stack','name','send','render','merge','body','contact','agent','interaction','account','index','Pause','mandatoryDispositionPause','map','WhatsappAccount','rawAttributes','fieldName','type','key','model','query','filters','attributes','intersection','fields','hasOwnProperty','nolimit','order','sort','where','filter','VIRTUAL','options','includeAll','include','findAll','rows','show','params','keys','length','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','WhatsappAccountId','Disposition','getDispositions','findOne','pick','removeDispositions','ids','CannedAnswer','getAnswers'];(function(_0x360532,_0x2d275d){var _0x7ed35c=function(_0x2704ec){while(--_0x2704ec){_0x360532['push'](_0x360532['shift']());}};_0x7ed35c(++_0x2d275d);}(_0x9b9b,0x114));var _0xb9b9=function(_0x505f51,_0x1a3e1d){_0x505f51=_0x505f51-0x0;var _0x5468b3=_0x9b9b[_0x505f51];return _0x5468b3;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xb9b9('0x0'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xb9b9('0x1'));var moment=require(_0xb9b9('0x2'));var BPromise=require(_0xb9b9('0x3'));var Mustache=require(_0xb9b9('0x4'));var util=require(_0xb9b9('0x5'));var path=require(_0xb9b9('0x6'));var sox=require(_0xb9b9('0x7'));var csv=require(_0xb9b9('0x8'));var ejs=require(_0xb9b9('0x9'));var fs=require('fs');var fs_extra=require(_0xb9b9('0xa'));var _=require(_0xb9b9('0xb'));var squel=require(_0xb9b9('0xc'));var crypto=require(_0xb9b9('0xd'));var jsforce=require(_0xb9b9('0xe'));var deskjs=require(_0xb9b9('0xf'));var toCsv=require(_0xb9b9('0x8'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xb9b9('0x10'));var authService=require(_0xb9b9('0x11'));var qs=require(_0xb9b9('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb9b9('0x13'));var logger=require(_0xb9b9('0x14'))(_0xb9b9('0x15'));var utils=require('../../config/utils');var config=require(_0xb9b9('0x16'));var licenseUtil=require(_0xb9b9('0x17'));var db=require(_0xb9b9('0x18'))['db'];config[_0xb9b9('0x19')]=_[_0xb9b9('0x1a')](config[_0xb9b9('0x19')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xb9b9('0x19')]));require('./whatsappAccount.socket')[_0xb9b9('0x1b')](socket);var jayson=require('jayson/promise');var client=jayson[_0xb9b9('0x1c')][_0xb9b9('0x1d')]({'port':0x232c});function respondWithRpcPromise(_0x21fa2a,_0x29794c,_0x177ad9,_0x3fd09c){return new BPromise(function(_0x42a55f,_0x2b2e3d){var _0x4ae8e6=_0x3fd09c||client;return _0x4ae8e6[_0xb9b9('0x1e')](_0x21fa2a,_0x177ad9)['then'](function(_0x403a5b){logger[_0xb9b9('0x1f')](_0xb9b9('0x20'),_0x29794c,_0xb9b9('0x21'));logger['debug'](_0xb9b9('0x22'),_0x29794c,_0xb9b9('0x21'),JSON[_0xb9b9('0x23')](_0x403a5b));if(_0x403a5b[_0xb9b9('0x24')]){if(_0x403a5b[_0xb9b9('0x24')][_0xb9b9('0x25')]===0x1f4){logger[_0xb9b9('0x24')](_0xb9b9('0x20'),_0x29794c,_0x403a5b[_0xb9b9('0x24')][_0xb9b9('0x26')]);return _0x2b2e3d(_0x403a5b[_0xb9b9('0x24')][_0xb9b9('0x26')]);}logger[_0xb9b9('0x24')]('WhatsappAccount,\x20%s,\x20%s',_0x29794c,_0x403a5b[_0xb9b9('0x24')][_0xb9b9('0x26')]);return _0x42a55f(_0x403a5b[_0xb9b9('0x24')]['message']);}else{logger[_0xb9b9('0x1f')](_0xb9b9('0x20'),_0x29794c,'request\x20sent');_0x42a55f(_0x403a5b[_0xb9b9('0x27')][_0xb9b9('0x26')]);}})[_0xb9b9('0x28')](function(_0x40b801){logger[_0xb9b9('0x24')]('WhatsappAccount,\x20%s,\x20%s',_0x29794c,_0x40b801);_0x2b2e3d(_0x40b801);});});}function respondWithStatusCode(_0x4dfa3f,_0x33ab82){_0x33ab82=_0x33ab82||0xcc;return function(_0x426f2c){if(_0x426f2c){return _0x4dfa3f['sendStatus'](_0x33ab82);}return _0x4dfa3f[_0xb9b9('0x29')](_0x33ab82)[_0xb9b9('0x2a')]();};}function respondWithResult(_0x20ffc1,_0x21f68f){_0x21f68f=_0x21f68f||0xc8;return function(_0x125f6c){if(_0x125f6c){return _0x20ffc1['status'](_0x21f68f)[_0xb9b9('0x2b')](_0x125f6c);}};}function respondWithFilteredResult(_0x554850,_0x1e0c5e){return function(_0xe28f3c){if(_0xe28f3c){var _0x4f47da=typeof _0x1e0c5e[_0xb9b9('0x2c')]===_0xb9b9('0x2d')&&typeof _0x1e0c5e[_0xb9b9('0x2e')]==='undefined';var _0x16df87=_0xe28f3c[_0xb9b9('0x2f')];var _0x2e1d12=_0x4f47da?0x0:_0x1e0c5e[_0xb9b9('0x2c')];var _0x4f002a=_0x4f47da?_0xe28f3c[_0xb9b9('0x2f')]:_0x1e0c5e[_0xb9b9('0x2c')]+_0x1e0c5e['limit'];var _0x42b31f;if(_0x4f002a>=_0x16df87){_0x4f002a=_0x16df87;_0x42b31f=0xc8;}else{_0x42b31f=0xce;}_0x554850[_0xb9b9('0x29')](_0x42b31f);return _0x554850[_0xb9b9('0x30')](_0xb9b9('0x31'),_0x2e1d12+'-'+_0x4f002a+'/'+_0x16df87)['json'](_0xe28f3c);}return null;};}function patchUpdates(_0xd66ace){return function(_0x1bcac4){try{jsonpatch[_0xb9b9('0x32')](_0x1bcac4,_0xd66ace,!![]);}catch(_0x2f68c5){return BPromise['reject'](_0x2f68c5);}return _0x1bcac4[_0xb9b9('0x33')]();};}function saveUpdates(_0x28fe9b,_0x532fa4){return function(_0x126fe2){if(_0x126fe2){return _0x126fe2[_0xb9b9('0x34')](_0x28fe9b)[_0xb9b9('0x35')](function(_0xa680b5){return _0xa680b5;});}return null;};}function removeEntity(_0x359509,_0x17f3c3){return function(_0x5e10c9){if(_0x5e10c9){return _0x5e10c9[_0xb9b9('0x36')]()[_0xb9b9('0x35')](function(){var _0x48bcd2=_0x5e10c9[_0xb9b9('0x37')]({'plain':!![]});var _0x3bbfa1=_0xb9b9('0x38');return db['UserProfileResource'][_0xb9b9('0x36')]({'where':{'type':_0x3bbfa1,'resourceId':_0x48bcd2['id']}})['then'](function(){return _0x5e10c9;});})[_0xb9b9('0x35')](function(){_0x359509['status'](0xcc)[_0xb9b9('0x2a')]();});}};}function handleEntityNotFound(_0x1a8237,_0x22b567){return function(_0x1f1faf){if(!_0x1f1faf){_0x1a8237[_0xb9b9('0x39')](0x194);}return _0x1f1faf;};}function handleError(_0x76f4d4,_0x394c20){_0x394c20=_0x394c20||0x1f4;return function(_0x4960e1){logger['error'](_0x4960e1[_0xb9b9('0x3a')]);if(_0x4960e1[_0xb9b9('0x3b')]){delete _0x4960e1[_0xb9b9('0x3b')];}_0x76f4d4['status'](_0x394c20)[_0xb9b9('0x3c')](_0x4960e1);};}function getMustacheRender(_0x59caf9,_0x2778f9){return Mustache[_0xb9b9('0x3d')](_0x59caf9,_[_0xb9b9('0x3e')](_0x2778f9[_0xb9b9('0x3f')],{'contact':_0x2778f9[_0xb9b9('0x40')],'message':_0x2778f9[_0xb9b9('0x26')],'agent':_0x2778f9[_0xb9b9('0x41')],'interaction':_0x2778f9[_0xb9b9('0x42')],'account':_0x2778f9[_0xb9b9('0x43')]}))||'';}exports[_0xb9b9('0x44')]=function(_0x56b72c,_0xf484fd){var _0x2fd1bc={'include':[{'model':db[_0xb9b9('0x45')],'as':_0xb9b9('0x46')}]},_0x382131={},_0x2e50fa={'count':0x0,'rows':[]};var _0x36717c=_[_0xb9b9('0x47')](db[_0xb9b9('0x48')][_0xb9b9('0x49')],function(_0x500637){return{'name':_0x500637[_0xb9b9('0x4a')],'type':_0x500637[_0xb9b9('0x4b')][_0xb9b9('0x4c')]};});_0x382131[_0xb9b9('0x4d')]=_['map'](_0x36717c,_0xb9b9('0x3b'));_0x382131['query']=_['keys'](_0x56b72c[_0xb9b9('0x4e')]);_0x382131[_0xb9b9('0x4f')]=_['intersection'](_0x382131['model'],_0x382131[_0xb9b9('0x4e')]);_0x2fd1bc[_0xb9b9('0x50')]=_[_0xb9b9('0x51')](_0x382131[_0xb9b9('0x4d')],qs['fields'](_0x56b72c[_0xb9b9('0x4e')][_0xb9b9('0x52')]));_0x2fd1bc[_0xb9b9('0x50')]=_0x2fd1bc['attributes']['length']?_0x2fd1bc[_0xb9b9('0x50')]:_0x382131['model'];if(!_0x56b72c[_0xb9b9('0x4e')][_0xb9b9('0x53')](_0xb9b9('0x54'))){_0x2fd1bc[_0xb9b9('0x2e')]=qs['limit'](_0x56b72c[_0xb9b9('0x4e')][_0xb9b9('0x2e')]);_0x2fd1bc[_0xb9b9('0x2c')]=qs[_0xb9b9('0x2c')](_0x56b72c[_0xb9b9('0x4e')][_0xb9b9('0x2c')]);}_0x2fd1bc[_0xb9b9('0x55')]=qs[_0xb9b9('0x56')](_0x56b72c[_0xb9b9('0x4e')][_0xb9b9('0x56')]);_0x2fd1bc[_0xb9b9('0x57')]=qs[_0xb9b9('0x4f')](_['pick'](_0x56b72c[_0xb9b9('0x4e')],_0x382131['filters']),_0x36717c);if(_0x56b72c[_0xb9b9('0x4e')][_0xb9b9('0x58')]){_0x2fd1bc[_0xb9b9('0x57')]=_[_0xb9b9('0x3e')](_0x2fd1bc['where'],{'$or':_[_0xb9b9('0x47')](_0x36717c,function(_0x5be034){if(_0x5be034[_0xb9b9('0x4b')]!==_0xb9b9('0x59')){var _0x41dfa0={};_0x41dfa0[_0x5be034[_0xb9b9('0x3b')]]={'$like':'%'+_0x56b72c[_0xb9b9('0x4e')][_0xb9b9('0x58')]+'%'};return _0x41dfa0;}})});}_0x2fd1bc=_[_0xb9b9('0x3e')]({},_0x2fd1bc,_0x56b72c[_0xb9b9('0x5a')]);var _0x1c2f19={'where':_0x2fd1bc[_0xb9b9('0x57')]};return db[_0xb9b9('0x48')]['count'](_0x1c2f19)['then'](function(_0x4da7d8){_0x2e50fa[_0xb9b9('0x2f')]=_0x4da7d8;if(_0x56b72c['query'][_0xb9b9('0x5b')]){_0x2fd1bc[_0xb9b9('0x5c')]=[{'all':!![]}];}return db[_0xb9b9('0x48')][_0xb9b9('0x5d')](_0x2fd1bc);})['then'](function(_0x39c444){_0x2e50fa[_0xb9b9('0x5e')]=_0x39c444;return _0x2e50fa;})['then'](respondWithFilteredResult(_0xf484fd,_0x2fd1bc))[_0xb9b9('0x28')](handleError(_0xf484fd,null));};exports[_0xb9b9('0x5f')]=function(_0x52cc9f,_0x50f2e0){var _0x451f70={'raw':![],'where':{'id':_0x52cc9f[_0xb9b9('0x60')]['id']},'include':[{'model':db['Pause'],'as':_0xb9b9('0x46')}]},_0x2bbe9f={};_0x2bbe9f[_0xb9b9('0x4d')]=_['keys'](db[_0xb9b9('0x48')][_0xb9b9('0x49')]);_0x2bbe9f[_0xb9b9('0x4e')]=_[_0xb9b9('0x61')](_0x52cc9f['query']);_0x2bbe9f[_0xb9b9('0x4f')]=_[_0xb9b9('0x51')](_0x2bbe9f[_0xb9b9('0x4d')],_0x2bbe9f['query']);_0x451f70[_0xb9b9('0x50')]=_[_0xb9b9('0x51')](_0x2bbe9f[_0xb9b9('0x4d')],qs[_0xb9b9('0x52')](_0x52cc9f[_0xb9b9('0x4e')]['fields']));_0x451f70['attributes']=_0x451f70[_0xb9b9('0x50')][_0xb9b9('0x62')]?_0x451f70[_0xb9b9('0x50')]:_0x2bbe9f[_0xb9b9('0x4d')];if(_0x52cc9f[_0xb9b9('0x4e')]['includeAll']){_0x451f70[_0xb9b9('0x5c')]=[{'all':!![]}];}_0x451f70=_[_0xb9b9('0x3e')]({},_0x451f70,_0x52cc9f[_0xb9b9('0x5a')]);return db[_0xb9b9('0x48')][_0xb9b9('0x63')](_0x451f70)['then'](handleEntityNotFound(_0x50f2e0,null))[_0xb9b9('0x35')](respondWithResult(_0x50f2e0,null))[_0xb9b9('0x28')](handleError(_0x50f2e0,null));};exports[_0xb9b9('0x64')]=function(_0x1e38f5,_0x5e81b0){return db[_0xb9b9('0x48')]['create'](_0x1e38f5[_0xb9b9('0x3f')],{})[_0xb9b9('0x35')](function(_0x19a252){var _0x386f85=_0x1e38f5[_0xb9b9('0x65')][_0xb9b9('0x37')]({'plain':!![]});if(!_0x386f85)throw new Error(_0xb9b9('0x66'));if(_0x386f85[_0xb9b9('0x67')]===_0xb9b9('0x65')){var _0x13add3=_0x19a252['get']({'plain':!![]});var _0xac7b51=_0xb9b9('0x38');return db[_0xb9b9('0x68')]['find']({'where':{'name':_0xac7b51,'userProfileId':_0x386f85[_0xb9b9('0x69')]},'raw':!![]})[_0xb9b9('0x35')](function(_0x412a7b){if(_0x412a7b&&_0x412a7b[_0xb9b9('0x6a')]===0x0){return db[_0xb9b9('0x6b')][_0xb9b9('0x64')]({'name':_0x13add3['name'],'resourceId':_0x13add3['id'],'type':_0x412a7b[_0xb9b9('0x3b')],'sectionId':_0x412a7b['id']},{})[_0xb9b9('0x35')](function(){return _0x19a252;});}else{return _0x19a252;}})[_0xb9b9('0x28')](function(_0x1e1da9){logger[_0xb9b9('0x24')](_0xb9b9('0x6c'),_0x1e1da9);throw _0x1e1da9;});}return _0x19a252;})[_0xb9b9('0x35')](respondWithResult(_0x5e81b0,0xc9))[_0xb9b9('0x28')](handleError(_0x5e81b0,null));};exports['update']=function(_0x15f2df,_0x27920f){if(_0x15f2df[_0xb9b9('0x3f')]['id']){delete _0x15f2df['body']['id'];}return db[_0xb9b9('0x48')][_0xb9b9('0x63')]({'where':{'id':_0x15f2df['params']['id']},'include':[{'model':db[_0xb9b9('0x45')],'as':_0xb9b9('0x46')}]})[_0xb9b9('0x35')](handleEntityNotFound(_0x27920f,null))[_0xb9b9('0x35')](saveUpdates(_0x15f2df[_0xb9b9('0x3f')],null))[_0xb9b9('0x35')](respondWithResult(_0x27920f,null))['catch'](handleError(_0x27920f,null));};exports[_0xb9b9('0x36')]=function(_0x246ed7,_0xff2dc0){return db[_0xb9b9('0x48')][_0xb9b9('0x63')]({'where':{'id':_0x246ed7['params']['id']}})['then'](handleEntityNotFound(_0xff2dc0,null))[_0xb9b9('0x35')](removeEntity(_0xff2dc0,null))[_0xb9b9('0x28')](handleError(_0xff2dc0,null));};exports[_0xb9b9('0x6d')]=function(_0x53159a,_0x30cf13){return db['WhatsappAccount'][_0xb9b9('0x6d')]()[_0xb9b9('0x35')](respondWithResult(_0x30cf13,null))[_0xb9b9('0x28')](handleError(_0x30cf13,null));};exports[_0xb9b9('0x6e')]=function(_0x2eb543,_0xaf8594,_0x2fbc92){if(_0x2eb543['body']['id']){delete _0x2eb543['body']['id'];}return db['WhatsappAccount']['find']({'where':{'id':_0x2eb543['params']['id']}})[_0xb9b9('0x35')](handleEntityNotFound(_0xaf8594,null))[_0xb9b9('0x35')](function(_0x273598){if(_0x273598){_0x2eb543[_0xb9b9('0x3f')][_0xb9b9('0x6f')]=_0x273598['id'];return db[_0xb9b9('0x70')][_0xb9b9('0x64')](_0x2eb543['body']);}})[_0xb9b9('0x35')](respondWithResult(_0xaf8594,null))[_0xb9b9('0x28')](handleError(_0xaf8594,null));};exports[_0xb9b9('0x71')]=function(_0xb54f42,_0x4df804,_0x4a724d){var _0x1039e9={'raw':![],'where':{}};var _0x7aeebf={};var _0x3110b5={'count':0x0,'rows':[]};return db[_0xb9b9('0x48')][_0xb9b9('0x72')]({'where':{'id':_0xb54f42['params']['id']}})['then'](handleEntityNotFound(_0x4df804,null))[_0xb9b9('0x35')](function(_0xe9b7f8){if(_0xe9b7f8){_0x7aeebf[_0xb9b9('0x4d')]=_[_0xb9b9('0x61')](db[_0xb9b9('0x70')]['rawAttributes']);_0x7aeebf[_0xb9b9('0x4e')]=_[_0xb9b9('0x61')](_0xb54f42[_0xb9b9('0x4e')]);_0x7aeebf[_0xb9b9('0x4f')]=_[_0xb9b9('0x51')](_0x7aeebf['model'],_0x7aeebf['query']);_0x1039e9[_0xb9b9('0x50')]=_[_0xb9b9('0x51')](_0x7aeebf[_0xb9b9('0x4d')],qs[_0xb9b9('0x52')](_0xb54f42['query'][_0xb9b9('0x52')]));_0x1039e9[_0xb9b9('0x50')]=_0x1039e9[_0xb9b9('0x50')][_0xb9b9('0x62')]?_0x1039e9['attributes']:_0x7aeebf[_0xb9b9('0x4d')];if(!_0xb54f42[_0xb9b9('0x4e')]['hasOwnProperty'](_0xb9b9('0x54'))){_0x1039e9[_0xb9b9('0x2e')]=qs['limit'](_0xb54f42[_0xb9b9('0x4e')]['limit']);_0x1039e9[_0xb9b9('0x2c')]=qs['offset'](_0xb54f42['query'][_0xb9b9('0x2c')]);}_0x1039e9[_0xb9b9('0x55')]=qs[_0xb9b9('0x56')](_0xb54f42[_0xb9b9('0x4e')][_0xb9b9('0x56')]);_0x1039e9[_0xb9b9('0x57')]=qs[_0xb9b9('0x4f')](_[_0xb9b9('0x73')](_0xb54f42[_0xb9b9('0x4e')],_0x7aeebf['filters']));_0x1039e9[_0xb9b9('0x57')]['WhatsappAccountId']=_0xe9b7f8['id'];if(_0xb54f42['query']['filter']){_0x1039e9[_0xb9b9('0x57')]=_['merge'](_0x1039e9['where'],{'$or':_[_0xb9b9('0x47')](_0x1039e9['attributes'],function(_0x405a5e){var _0xe7196a={};_0xe7196a[_0x405a5e]={'$like':'%'+_0xb54f42[_0xb9b9('0x4e')]['filter']+'%'};return _0xe7196a;})});}_0x1039e9=_[_0xb9b9('0x3e')]({},_0x1039e9,_0xb54f42['options']);return db[_0xb9b9('0x70')][_0xb9b9('0x2f')]({'where':_0x1039e9['where']})[_0xb9b9('0x35')](function(_0x4d123c){_0x3110b5[_0xb9b9('0x2f')]=_0x4d123c;if(_0xb54f42[_0xb9b9('0x4e')][_0xb9b9('0x5b')]){_0x1039e9['include']=[{'all':!![]}];}return db[_0xb9b9('0x70')][_0xb9b9('0x5d')](_0x1039e9);})[_0xb9b9('0x35')](function(_0x576c01){_0x3110b5[_0xb9b9('0x5e')]=_0x576c01;return _0x3110b5;});}})[_0xb9b9('0x35')](respondWithFilteredResult(_0x4df804,_0x1039e9))[_0xb9b9('0x28')](handleError(_0x4df804,null));};exports[_0xb9b9('0x74')]=function(_0x5b6500,_0x2fead4,_0x1c6b69){return db[_0xb9b9('0x48')][_0xb9b9('0x63')]({'where':{'id':_0x5b6500[_0xb9b9('0x60')]['id']}})['then'](handleEntityNotFound(_0x2fead4,null))['then'](function(_0x23db94){if(_0x23db94){return _0x23db94[_0xb9b9('0x74')](_0x5b6500[_0xb9b9('0x4e')][_0xb9b9('0x75')]);}})['then'](respondWithStatusCode(_0x2fead4,null))[_0xb9b9('0x28')](handleError(_0x2fead4,null));};exports['addAnswer']=function(_0x4e9283,_0xd8de61,_0x32a022){if(_0x4e9283['body']['id']){delete _0x4e9283['body']['id'];}return db['WhatsappAccount']['find']({'where':{'id':_0x4e9283[_0xb9b9('0x60')]['id']}})[_0xb9b9('0x35')](handleEntityNotFound(_0xd8de61,null))['then'](function(_0x3d93d1){if(_0x3d93d1){_0x4e9283['body'][_0xb9b9('0x6f')]=_0x3d93d1['id'];return db[_0xb9b9('0x76')][_0xb9b9('0x64')](_0x4e9283[_0xb9b9('0x3f')]);}})[_0xb9b9('0x35')](respondWithResult(_0xd8de61,null))[_0xb9b9('0x28')](handleError(_0xd8de61,null));};exports[_0xb9b9('0x77')]=function(_0x30a3ab,_0x2ceba2,_0x39632a){var _0x404299={'raw':![],'where':{}};var _0x26c1e7={};var _0x291893={'count':0x0,'rows':[]};return db[_0xb9b9('0x48')][_0xb9b9('0x72')]({'where':{'id':_0x30a3ab[_0xb9b9('0x60')]['id']}})[_0xb9b9('0x35')](handleEntityNotFound(_0x2ceba2,null))[_0xb9b9('0x35')](function(_0x7aa221){if(_0x7aa221){_0x26c1e7[_0xb9b9('0x4d')]=_[_0xb9b9('0x61')](db[_0xb9b9('0x76')][_0xb9b9('0x49')]);_0x26c1e7[_0xb9b9('0x4e')]=_[_0xb9b9('0x61')](_0x30a3ab['query']);_0x26c1e7[_0xb9b9('0x4f')]=_[_0xb9b9('0x51')](_0x26c1e7[_0xb9b9('0x4d')],_0x26c1e7[_0xb9b9('0x4e')]);_0x404299[_0xb9b9('0x50')]=_[_0xb9b9('0x51')](_0x26c1e7[_0xb9b9('0x4d')],qs[_0xb9b9('0x52')](_0x30a3ab['query']['fields']));_0x404299[_0xb9b9('0x50')]=_0x404299[_0xb9b9('0x50')][_0xb9b9('0x62')]?_0x404299[_0xb9b9('0x50')]:_0x26c1e7[_0xb9b9('0x4d')];if(!_0x30a3ab['query'][_0xb9b9('0x53')]('nolimit')){_0x404299['limit']=qs['limit'](_0x30a3ab[_0xb9b9('0x4e')][_0xb9b9('0x2e')]);_0x404299[_0xb9b9('0x2c')]=qs[_0xb9b9('0x2c')](_0x30a3ab[_0xb9b9('0x4e')][_0xb9b9('0x2c')]);}_0x404299['order']=qs['sort'](_0x30a3ab['query'][_0xb9b9('0x56')]);_0x404299[_0xb9b9('0x57')]=qs[_0xb9b9('0x4f')](_['pick'](_0x30a3ab[_0xb9b9('0x4e')],_0x26c1e7[_0xb9b9('0x4f')]));_0x404299[_0xb9b9('0x57')][_0xb9b9('0x6f')]=_0x7aa221['id'];if(_0x30a3ab[_0xb9b9('0x4e')][_0xb9b9('0x58')]){_0x404299['where']=_[_0xb9b9('0x3e')](_0x404299[_0xb9b9('0x57')],{'$or':_[_0xb9b9('0x47')](_0x404299[_0xb9b9('0x50')],function(_0x5aaa68){var _0x4db67f={};_0x4db67f[_0x5aaa68]={'$like':'%'+_0x30a3ab['query'][_0xb9b9('0x58')]+'%'};return _0x4db67f;})});}_0x404299=_['merge']({},_0x404299,_0x30a3ab[_0xb9b9('0x5a')]);return db['CannedAnswer'][_0xb9b9('0x2f')]({'where':_0x404299[_0xb9b9('0x57')]})[_0xb9b9('0x35')](function(_0x27816c){_0x291893[_0xb9b9('0x2f')]=_0x27816c;if(_0x30a3ab['query'][_0xb9b9('0x5b')]){_0x404299[_0xb9b9('0x5c')]=[{'all':!![]}];}return db['CannedAnswer'][_0xb9b9('0x5d')](_0x404299);})[_0xb9b9('0x35')](function(_0x48337a){_0x291893[_0xb9b9('0x5e')]=_0x48337a;return _0x291893;});}})['then'](respondWithFilteredResult(_0x2ceba2,_0x404299))[_0xb9b9('0x28')](handleError(_0x2ceba2,null));};exports['removeAnswers']=function(_0xffbeab,_0x593c92,_0x54de49){return db[_0xb9b9('0x48')][_0xb9b9('0x63')]({'where':{'id':_0xffbeab[_0xb9b9('0x60')]['id']}})[_0xb9b9('0x35')](handleEntityNotFound(_0x593c92,null))[_0xb9b9('0x35')](function(_0xa977af){if(_0xa977af){return _0xa977af[_0xb9b9('0x78')](_0xffbeab[_0xb9b9('0x4e')]['ids']);}})[_0xb9b9('0x35')](respondWithStatusCode(_0x593c92,null))[_0xb9b9('0x28')](handleError(_0x593c92,null));};exports['addAgents']=function(_0x9f662e,_0x323360,_0x30ae6d){return db['WhatsappAccount'][_0xb9b9('0x63')]({'where':{'id':_0x9f662e['params']['id']}})[_0xb9b9('0x35')](handleEntityNotFound(_0x323360,null))[_0xb9b9('0x35')](function(_0x32aef6){if(_0x32aef6){return _0x32aef6[_0xb9b9('0x79')](_0x9f662e[_0xb9b9('0x3f')]['ids'],_['omit'](_0x9f662e[_0xb9b9('0x3f')],[_0xb9b9('0x75'),'id'])||{})[_0xb9b9('0x7a')](function(_0x4de523){for(var _0x19f90f=0x0;_0x19f90f<_0x9f662e[_0xb9b9('0x3f')][_0xb9b9('0x75')][_0xb9b9('0x62')];_0x19f90f+=0x1){socket[_0xb9b9('0x7b')](_0xb9b9('0x7c'),{'UserId':_0x9f662e[_0xb9b9('0x3f')][_0xb9b9('0x75')][_0x19f90f],'WhatsappAccountId':_0x9f662e[_0xb9b9('0x60')]['id']});}return _0x4de523;});}})[_0xb9b9('0x35')](respondWithResult(_0x323360,null))['catch'](handleError(_0x323360,null));};exports[_0xb9b9('0x7d')]=function(_0x519406,_0x5442c7,_0x172626){return db[_0xb9b9('0x48')]['find']({'where':{'id':_0x519406['params']['id']}})[_0xb9b9('0x35')](handleEntityNotFound(_0x5442c7,null))['then'](function(_0x37aec9){if(_0x37aec9){return _0x37aec9[_0xb9b9('0x7d')](_0x519406[_0xb9b9('0x4e')][_0xb9b9('0x75')])[_0xb9b9('0x35')](function(){if(_['isArray'](_0x519406[_0xb9b9('0x4e')][_0xb9b9('0x75')])){for(var _0x17db11=0x0;_0x17db11<_0x519406['query'][_0xb9b9('0x75')][_0xb9b9('0x62')];_0x17db11+=0x1){socket[_0xb9b9('0x7b')](_0xb9b9('0x7e'),{'UserId':Number(_0x519406[_0xb9b9('0x4e')][_0xb9b9('0x75')][_0x17db11]),'WhatsappAccountId':Number(_0x519406[_0xb9b9('0x60')]['id'])});}}else{socket[_0xb9b9('0x7b')](_0xb9b9('0x7e'),{'UserId':Number(_0x519406[_0xb9b9('0x4e')][_0xb9b9('0x75')]),'WhatsappAccountId':Number(_0x519406['params']['id'])});}});}})[_0xb9b9('0x35')](respondWithStatusCode(_0x5442c7,null))[_0xb9b9('0x28')](handleError(_0x5442c7,null));};exports[_0xb9b9('0x7f')]=function(_0x4b0c9d,_0x33d95f,_0x2c7b0f){var _0x5242e4={};var _0x28a896={};var _0x2ce492;var _0x213063;return db[_0xb9b9('0x48')][_0xb9b9('0x72')]({'where':{'id':_0x4b0c9d['params']['id']}})['then'](handleEntityNotFound(_0x33d95f,null))[_0xb9b9('0x35')](function(_0x94b4df){if(_0x94b4df){_0x2ce492=_0x94b4df;_0x28a896[_0xb9b9('0x4d')]=_[_0xb9b9('0x61')](db[_0xb9b9('0x80')]['rawAttributes']);_0x28a896[_0xb9b9('0x4e')]=_['keys'](_0x4b0c9d[_0xb9b9('0x4e')]);_0x28a896['filters']=_[_0xb9b9('0x51')](_0x28a896[_0xb9b9('0x4d')],_0x28a896[_0xb9b9('0x4e')]);_0x5242e4[_0xb9b9('0x50')]=_['intersection'](_0x28a896[_0xb9b9('0x4d')],qs[_0xb9b9('0x52')](_0x4b0c9d[_0xb9b9('0x4e')][_0xb9b9('0x52')]));_0x5242e4[_0xb9b9('0x50')]=_0x5242e4[_0xb9b9('0x50')][_0xb9b9('0x62')]?_0x5242e4[_0xb9b9('0x50')]:_0x28a896[_0xb9b9('0x4d')];_0x5242e4['order']=qs[_0xb9b9('0x56')](_0x4b0c9d[_0xb9b9('0x4e')][_0xb9b9('0x56')]);_0x5242e4['where']=qs[_0xb9b9('0x4f')](_[_0xb9b9('0x73')](_0x4b0c9d['query'],_0x28a896[_0xb9b9('0x4f')]));if(_0x4b0c9d[_0xb9b9('0x4e')][_0xb9b9('0x58')]){_0x5242e4[_0xb9b9('0x57')]=_[_0xb9b9('0x3e')](_0x5242e4[_0xb9b9('0x57')],{'$or':_[_0xb9b9('0x47')](_0x5242e4[_0xb9b9('0x50')],function(_0x11fc85){var _0x53fce9={};_0x53fce9[_0x11fc85]={'$like':'%'+_0x4b0c9d[_0xb9b9('0x4e')][_0xb9b9('0x58')]+'%'};return _0x53fce9;})});}_0x5242e4=_['merge']({},_0x5242e4,_0x4b0c9d['options']);return _0x2ce492[_0xb9b9('0x7f')](_0x5242e4);}})[_0xb9b9('0x35')](function(_0x371afc){if(_0x371afc){_0x213063=_0x371afc[_0xb9b9('0x62')];if(!_0x4b0c9d['query'][_0xb9b9('0x53')](_0xb9b9('0x54'))){_0x5242e4['limit']=qs[_0xb9b9('0x2e')](_0x4b0c9d[_0xb9b9('0x4e')]['limit']);_0x5242e4[_0xb9b9('0x2c')]=qs[_0xb9b9('0x2c')](_0x4b0c9d[_0xb9b9('0x4e')]['offset']);}return _0x2ce492['getAgents'](_0x5242e4);}})[_0xb9b9('0x35')](function(_0x263723){if(_0x263723){return _0x263723?{'count':_0x213063,'rows':_0x263723}:null;}})[_0xb9b9('0x35')](respondWithResult(_0x33d95f,null))['catch'](handleError(_0x33d95f,null));};exports[_0xb9b9('0x81')]=function(_0x93ec7b,_0x15286a,_0x298d84){return db[_0xb9b9('0x48')][_0xb9b9('0x72')]({'where':{'id':_0x93ec7b[_0xb9b9('0x60')]['id']}})[_0xb9b9('0x35')](handleEntityNotFound(_0x15286a,null))['then'](function(_0x403a56){if(_0x403a56){return db[_0xb9b9('0x82')][_0xb9b9('0x83')](function(_0x16108a){return db[_0xb9b9('0x84')][_0xb9b9('0x36')]({'where':{'WhatsappAccountId':_0x93ec7b[_0xb9b9('0x60')]['id']},'transaction':_0x16108a})['then'](function(_0x19ec94){var _0x4b3df5=_[_0xb9b9('0x47')](_0x93ec7b[_0xb9b9('0x3f')],function(_0x220703){_0x220703[_0xb9b9('0x6f')]=_0x93ec7b['params']['id'];return _0x220703;});return db[_0xb9b9('0x84')][_0xb9b9('0x85')](_0x4b3df5,{'transaction':_0x16108a});});})[_0xb9b9('0x35')](function(){return db['WhatsappApplication'][_0xb9b9('0x86')]({'where':{'WhatsappAccountId':_0x93ec7b[_0xb9b9('0x60')]['id']},'order':'priority'});});}})[_0xb9b9('0x35')](respondWithResult(_0x15286a,null))[_0xb9b9('0x28')](handleError(_0x15286a,null));};exports[_0xb9b9('0x87')]=function(_0x4d291c,_0x4603fe,_0x515f5d){var _0x3c9f00={};var _0x4459a8={};var _0x1fbf12;var _0x3d81ce;return db[_0xb9b9('0x48')][_0xb9b9('0x72')]({'where':{'id':_0x4d291c[_0xb9b9('0x60')]['id']}})[_0xb9b9('0x35')](handleEntityNotFound(_0x4603fe,null))[_0xb9b9('0x35')](function(_0xda26a5){if(_0xda26a5){_0x1fbf12=_0xda26a5;_0x4459a8['model']=_['keys'](db[_0xb9b9('0x84')]['rawAttributes']);_0x4459a8[_0xb9b9('0x4e')]=_[_0xb9b9('0x61')](_0x4d291c[_0xb9b9('0x4e')]);_0x4459a8[_0xb9b9('0x4f')]=_[_0xb9b9('0x51')](_0x4459a8[_0xb9b9('0x4d')],_0x4459a8[_0xb9b9('0x4e')]);_0x3c9f00[_0xb9b9('0x50')]=_[_0xb9b9('0x51')](_0x4459a8['model'],qs[_0xb9b9('0x52')](_0x4d291c['query']['fields']));_0x3c9f00[_0xb9b9('0x50')]=_0x3c9f00['attributes']['length']?_0x3c9f00['attributes']:_0x4459a8['model'];_0x3c9f00[_0xb9b9('0x55')]=qs[_0xb9b9('0x56')](_0x4d291c['query'][_0xb9b9('0x56')]);_0x3c9f00[_0xb9b9('0x57')]=qs[_0xb9b9('0x4f')](_[_0xb9b9('0x73')](_0x4d291c[_0xb9b9('0x4e')],_0x4459a8[_0xb9b9('0x4f')]));if(_0x4d291c[_0xb9b9('0x4e')][_0xb9b9('0x58')]){_0x3c9f00['where']=_[_0xb9b9('0x3e')](_0x3c9f00[_0xb9b9('0x57')],{'$or':_['map'](_0x3c9f00['attributes'],function(_0xc85164){var _0x150653={};_0x150653[_0xc85164]={'$like':'%'+_0x4d291c[_0xb9b9('0x4e')][_0xb9b9('0x58')]+'%'};return _0x150653;})});}_0x3c9f00=_[_0xb9b9('0x3e')]({},_0x3c9f00,_0x4d291c['options']);return _0x1fbf12[_0xb9b9('0x87')](_0x3c9f00);}})['then'](function(_0xe5c63f){if(_0xe5c63f){_0x3d81ce=_0xe5c63f['length'];if(!_0x4d291c['query'][_0xb9b9('0x53')](_0xb9b9('0x54'))){_0x3c9f00[_0xb9b9('0x2e')]=qs[_0xb9b9('0x2e')](_0x4d291c[_0xb9b9('0x4e')][_0xb9b9('0x2e')]);_0x3c9f00[_0xb9b9('0x2c')]=qs[_0xb9b9('0x2c')](_0x4d291c[_0xb9b9('0x4e')]['offset']);}return _0x1fbf12[_0xb9b9('0x87')](_0x3c9f00);}})['then'](function(_0xb6e54c){if(_0xb6e54c){return _0xb6e54c?{'count':_0x3d81ce,'rows':_0xb6e54c}:null;}})[_0xb9b9('0x35')](respondWithResult(_0x4603fe,null))[_0xb9b9('0x28')](handleError(_0x4603fe,null));};exports[_0xb9b9('0x88')]=function(_0x1390fd,_0x337826,_0x532436){var _0x471ada={'channel':_0xb9b9('0x89')};var _0x33c792=[];var _0x10688f=[];var _0x22a8e6={};return db[_0xb9b9('0x48')][_0xb9b9('0x63')]({'where':{'id':_0x1390fd[_0xb9b9('0x60')]['id']},'include':[{'model':db[_0xb9b9('0x84')],'as':_0xb9b9('0x8a')}]})[_0xb9b9('0x35')](handleEntityNotFound(_0x337826,null))['then'](function(_0x5e581d){_0x471ada['account']=_0x5e581d;_0x471ada[_0xb9b9('0x8b')]=_[_0xb9b9('0x8c')](_0x5e581d[_0xb9b9('0x8a')],[_0xb9b9('0x8d')],[_0xb9b9('0x8e')]);if(_0x471ada[_0xb9b9('0x43')][_0xb9b9('0x8a')]){delete _0x471ada[_0xb9b9('0x43')][_0xb9b9('0x8a')];}return db['CmContact'][_0xb9b9('0x6d')]();})[_0xb9b9('0x35')](function(_0x27050e){if(!_0x27050e){throw new db[(_0xb9b9('0x8f'))][(_0xb9b9('0x90'))](_0xb9b9('0x91'));}_0x33c792=_[_0xb9b9('0x92')](_[_0xb9b9('0x61')](_0x27050e),[_0xb9b9('0x93'),_0xb9b9('0x94')]);_0x10688f=_[_0xb9b9('0x92')](_[_0xb9b9('0x61')](_0x27050e),[_0xb9b9('0x93'),_0xb9b9('0x94'),_0xb9b9('0x95'),_0xb9b9('0x96')]);_0x471ada['body']={'mapKey':_0xb9b9('0x97')};if(_0x471ada[_0xb9b9('0x43')][_0xb9b9('0x4b')]&&_0x471ada['account']['type']===_0xb9b9('0x98')){_0x471ada['body'][_0xb9b9('0x99')]=_0x1390fd['body'][_0xb9b9('0x9a')][_0xb9b9('0x9b')](_0xb9b9('0x9c'),'');_0x471ada[_0xb9b9('0x3f')][_0xb9b9('0x3f')]=_0x1390fd[_0xb9b9('0x3f')][_0xb9b9('0x9d')];_0x471ada[_0xb9b9('0x3f')][_0xb9b9('0x9e')]=_0x1390fd[_0xb9b9('0x3f')][_0xb9b9('0x9f')];}if(_0x471ada[_0xb9b9('0x3f')]['id']){delete _0x471ada[_0xb9b9('0x3f')]['id'];}if(_['isNil'](_0x471ada[_0xb9b9('0x3f')][_0xb9b9('0x99')])){throw new db[(_0xb9b9('0x8f'))][(_0xb9b9('0x90'))](_0xb9b9('0xa0'));}if(_[_0xb9b9('0xa1')](_0x471ada[_0xb9b9('0x3f')][_0xb9b9('0x3f')])||_0x471ada[_0xb9b9('0x3f')]['body']===''){throw new db[(_0xb9b9('0x8f'))]['ValidationError'](_0xb9b9('0xa2'));}if(_[_0xb9b9('0xa1')](_0x471ada[_0xb9b9('0x3f')][_0xb9b9('0xa3')])){throw new db[(_0xb9b9('0x8f'))][(_0xb9b9('0x90'))](_0xb9b9('0xa4')+_0x10688f);}if(!_[_0xb9b9('0xa5')](_0x10688f,_0x471ada['body'][_0xb9b9('0xa3')])){throw new db['Sequelize'][(_0xb9b9('0x90'))](_0xb9b9('0xa6')+_0x10688f);}_0x22a8e6[_0x471ada['body']['mapKey']]=_0x471ada[_0xb9b9('0x3f')][_0xb9b9('0x99')];return db[_0xb9b9('0xa7')][_0xb9b9('0x63')]({'where':{'id':_0x471ada['account']['ListId']},'include':[{'model':db[_0xb9b9('0xa8')],'as':'Contacts','where':_0x22a8e6,'limit':0x1,'order':[['updatedAt',_0xb9b9('0xa9')]]}]});})[_0xb9b9('0x35')](handleEntityNotFound(_0x337826,null))[_0xb9b9('0x35')](function(_0xbb8699){if(_0xbb8699){_0x471ada[_0xb9b9('0xaa')]=_['omit'](_0xbb8699,[_0xb9b9('0xab')]);if(_0xbb8699[_0xb9b9('0xab')]['length']){return _0xbb8699[_0xb9b9('0xab')][0x0];}var _0x546571=_[_0xb9b9('0x1a')](_0x471ada[_0xb9b9('0x3f')],{'firstName':_0x471ada[_0xb9b9('0x3f')][_0xb9b9('0x99')],'ListId':_0xbb8699['id']});_0x546571[_0x471ada['body'][_0xb9b9('0xa3')]]=_0x471ada[_0xb9b9('0x3f')][_0xb9b9('0x99')];return db[_0xb9b9('0xa8')]['create'](_0x546571,{'fields':_0x33c792,'raw':!![]});}})['then'](handleEntityNotFound(_0x337826,null))['then'](function(_0x1e94bc){if(_0x1e94bc){_0x471ada['contact']=_0x1e94bc;var _0x5255e6={'ContactId':_0x1e94bc['id'],'phone':_0x471ada[_0xb9b9('0x3f')]['from'],'WhatsappAccountId':_0x1390fd[_0xb9b9('0x60')]['id']};var _0xa9c5cf={'ContactId':_0x1e94bc['id'],'WhatsappAccountId':_0x1390fd[_0xb9b9('0x60')]['id'],'closed':![]};return db[_0xb9b9('0xac')][_0xb9b9('0x63')]({'where':_0xa9c5cf})[_0xb9b9('0x35')](function(_0x47eb53){if(_0x47eb53){return[_0x47eb53,![]];}return db[_0xb9b9('0xac')][_0xb9b9('0x64')](_0x5255e6)[_0xb9b9('0x35')](function(_0xe6296){return[_0xe6296,!![]];});});}})[_0xb9b9('0x7a')](function(_0x2530b1,_0x36080c){_0x471ada[_0xb9b9('0x42')]=_0x2530b1[_0xb9b9('0x37')]({'plain':!![]});_0x471ada[_0xb9b9('0x42')][_0xb9b9('0xad')]=![];if(_0x36080c){if(_0x471ada[_0xb9b9('0x43')][_0xb9b9('0xae')]){_0x471ada[_0xb9b9('0x8b')][_0xb9b9('0xaf')]({'id':0x0,'priority':_0x471ada[_0xb9b9('0x8b')][_0xb9b9('0x62')]+0x1,'app':_0xb9b9('0xb0'),'appdata':_0xb9b9('0xb1'),'interval':'*,*,*,*'});}_0x471ada[_0xb9b9('0x42')][_0xb9b9('0xad')]=!![];}return db['WhatsappMessage']['create']({'phone':_0x471ada[_0xb9b9('0x3f')][_0xb9b9('0x99')],'messageId':_0x471ada[_0xb9b9('0x3f')][_0xb9b9('0x9e')],'body':_0x471ada[_0xb9b9('0x3f')][_0xb9b9('0x3f')],'WhatsappAccountId':_0x1390fd[_0xb9b9('0x60')]['id'],'WhatsappInteractionId':_0x2530b1['id'],'direction':'in','ContactId':_0x2530b1[_0xb9b9('0xb2')],'AttachmentId':_0x471ada[_0xb9b9('0x3f')][_0xb9b9('0xb3')]});})[_0xb9b9('0x35')](function(_0x2e0da1){_0x471ada[_0xb9b9('0x26')]=_0x2e0da1;if(_0x471ada[_0xb9b9('0x42')]['UserId']){return db[_0xb9b9('0x80')]['find']({'attributes':['id',_0xb9b9('0x3b')],'where':{'id':_0x471ada['interaction'][_0xb9b9('0xb4')]}})['then'](function(_0x43b1ce){if(_0x43b1ce){_0x471ada[_0xb9b9('0x8b')][_0xb9b9('0xb5')]({'id':0x0,'priority':0x0,'app':_0xb9b9('0x41'),'appdata':_0x43b1ce['name']+','+(_0x471ada['account'][_0xb9b9('0xb6')]||0xa),'interval':_0xb9b9('0xb7')});}return respondWithRpcPromise(_0xb9b9('0xb8'),_0xb9b9('0xb9'),_0x471ada);});}return respondWithRpcPromise(_0xb9b9('0xb8'),_0xb9b9('0xb9'),_0x471ada);})[_0xb9b9('0x35')](function(_0x130c45){if(_0x130c45){var _0x257b32=0xc8;var _0x343507=_0xb9b9('0xba');logger['info'](_0xb9b9('0x22'),_0x343507,_0x257b32,_0xb9b9('0xbb'));logger[_0xb9b9('0xbc')](_0xb9b9('0xbd'),_0x343507,_0x257b32,_0xb9b9('0xbb'),JSON['stringify'](_0x130c45));if(_0x471ada['account']['type']===_0xb9b9('0x98')){return _0x337826[_0xb9b9('0x29')](_0x257b32)['set']('Content-Type',_0xb9b9('0xbe'))[_0xb9b9('0x3c')](_0xb9b9('0xbf'));}else{return _0x337826[_0xb9b9('0x29')](_0x257b32)[_0xb9b9('0x2b')](_0x130c45);}}})[_0xb9b9('0x28')](handleError(_0x337826,null));};exports['send']=function(_0x4b01c3,_0x2557c8,_0x10fd03){var _0x169ecb,_0x5780bf,_0x2b3f28;if(_['isNil'](_0x4b01c3[_0xb9b9('0x3f')][_0xb9b9('0x3f')])||_0x4b01c3[_0xb9b9('0x3f')][_0xb9b9('0x3f')]===''){throw new db[(_0xb9b9('0x8f'))]['ValidationError'](_0xb9b9('0xa2'));}if(_['isNil'](_0x4b01c3[_0xb9b9('0x3f')]['to'])){throw new db[(_0xb9b9('0x8f'))][(_0xb9b9('0x90'))](_0xb9b9('0xc0'));}_0x169ecb=_0x4b01c3[_0xb9b9('0x3f')]['to'];return db[_0xb9b9('0x48')][_0xb9b9('0x63')]({'where':{'id':_0x4b01c3[_0xb9b9('0x60')]['id']},'include':[{'model':db[_0xb9b9('0xa7')],'as':_0xb9b9('0xc1'),'include':[{'model':db['CmContact'],'as':_0xb9b9('0xab'),'where':{'mobile':_0x169ecb},'limit':0x1,'order':[[_0xb9b9('0x94'),_0xb9b9('0xa9')]]}]}]})['then'](handleEntityNotFound(_0x2557c8,null))[_0xb9b9('0x35')](function(_0x18b213){if(_0x18b213&&_0x18b213['List']){_0x5780bf=_0x18b213[_0xb9b9('0x37')]({'plain':!![]});if(_0x5780bf[_0xb9b9('0xc1')]&&_0x5780bf[_0xb9b9('0xc1')][_0xb9b9('0xab')][_0xb9b9('0x62')]){return _0x5780bf[_0xb9b9('0xc1')][_0xb9b9('0xab')][0x0];}return db['CmContact']['create'](_['defaults'](_0x4b01c3[_0xb9b9('0x3f')],{'firstName':_0x169ecb,'mobile':_0x169ecb,'phone':_0x169ecb,'ListId':_0x5780bf[_0xb9b9('0x96')]}));}})[_0xb9b9('0x35')](handleEntityNotFound(_0x2557c8,null))['then'](function(_0x56834e){if(_0x56834e){_0x2b3f28=_0x56834e;return db[_0xb9b9('0xac')][_0xb9b9('0x63')]({'where':{'ContactId':_0x2b3f28['id'],'closed':![],'WhatsappAccountId':_0x5780bf['id']}})[_0xb9b9('0x35')](function(_0x3ec359){if(_0x3ec359){return[_0x3ec359,![]];}return db['WhatsappInteraction'][_0xb9b9('0x64')]({'UserId':_0x4b01c3[_0xb9b9('0x65')]['id'],'ContactId':_0x2b3f28['id'],'WhatsappAccountId':_0x5780bf['id'],'phone':_0x169ecb,'firstMsgDirection':_0xb9b9('0xc2'),'Messages':[_[_0xb9b9('0x3e')](_0x4b01c3[_0xb9b9('0x3f')],{'read':![],'body':_0x4b01c3['body'][_0xb9b9('0x3f')],'phone':_0x169ecb,'WhatsappAccountId':_0x5780bf['id'],'UserId':_0x4b01c3[_0xb9b9('0x65')]['id'],'ContactId':_0x2b3f28['id']})]},{'include':[{'model':db[_0xb9b9('0xc3')],'as':_0xb9b9('0xc4')}]})[_0xb9b9('0x35')](function(_0x496185){return[_0x496185,!![]];});});}})[_0xb9b9('0x7a')](function(_0x446a44,_0x1d4b6e){if(_0x1d4b6e){return _0x446a44;}return db[_0xb9b9('0xc3')]['create'](_[_0xb9b9('0x3e')](_0x4b01c3[_0xb9b9('0x3f')],{'read':![],'body':_0x4b01c3['body'][_0xb9b9('0x3f')],'phone':_0x169ecb,'WhatsappAccountId':_0x5780bf['id'],'WhatsappInteractionId':_0x446a44['id'],'UserId':_0x4b01c3[_0xb9b9('0x65')]['id'],'ContactId':_0x2b3f28['id']}))[_0xb9b9('0x35')](function(_0x5014a0){_0x446a44[_0xb9b9('0xc5')][_0xb9b9('0xc4')]=[];_0x446a44[_0xb9b9('0xc5')][_0xb9b9('0xc4')][_0xb9b9('0xaf')](_0x5014a0[_0xb9b9('0xc5')]);return _0x446a44;});})[_0xb9b9('0x35')](respondWithResult(_0x2557c8,null))['catch'](handleError(_0x2557c8,null));};
\ No newline at end of file