Built motion from commit 71df090e.|2.6.31
[motion2.git] / server / api / chatInteraction / chatInteraction.controller.js
index 8c15207..e06c446 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x825c=['merge','where','filter','$gte','split','YYYY-MM-DD\x20HH:mm:ss','includeAll','include','getMyMessages','secret','push','rows','addTags','spread','Tag','findAll','color','emit','chatInteractionTags:save','removeTags','unix','server','files','tmp','attachments','Contact','firstName','lastName','direction','read','Account','get','mkdirSync','Chat','Owner','N.A.','closedAt','toString','disposition','browserName','customerIp','customerPort','tail','existsSync','createReadStream','pipe','createWriteStream','value','renderFile','views','downloadInteraction.ejs','zip-dir','request-promise','moment','bluebird','mustache','util','path','ejs','lodash','ioredis','../../config/logger','../../mysqldb','defaults','redis','localhost','./chatInteraction.socket','register','jayson/promise','http','client','request','then','info','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','ChatInteraction,\x20%s,\x20%s','message','catch','sendStatus','end','status','offset','undefined','limit','count','set','json','destroy','name','send','render','body','contact','agent','account','map','ChatInteraction','rawAttributes','fieldName','getOptions','chat','query','user','params','keys','filters','intersection','model','attributes','fields','length','options','create','update','find','describe','createVidaooSession','ChatWebsite','findOne','ChatWebsiteId','vidaooApiKey','vidaooEscalation','vidaooNote','email','POST','https://api-vidaoo.xcally.com/api/v1/meetings','vidaooTopic','isNull','vidaooMetadata','metadata','ValidationError','Sequelize','Error\x20in\x20Vidaoo\x20configuration','join_url','out','ChatMessage','Unable\x20to\x20create\x20Vidaoo\x20session','updateAttributes','customUpdate','CmContact','abandon','abandonInteraction,\x20%s,\x20%s,\x20%s','entity\x20not\x20found','Interaction\x20already\x20assigned','closed','AbandonInteraction','attachmentUpload','file','originalname','basename','type','mimetype','attachmentDownload','Attachment','attachId','join','server/files/attachments/','offline-chat/','download','close','mailTranscript','root','format','transcript-%s.txt','pathTranscript','Messages','User','ContactId','%s%d','agentAlias','UserId','System','customer','agentIdentifier','agent_alias','alias','fullname','agent_fullname','[%s]\x20%s:\x20%s\x0a','createdAt','MM/DD/YYYY\x20HH:mm:ss','appendFileSync','MailAccount','MailServerOut','Smtp','CloudProvider','getSmtpOptions','SendMail','sendMail','\x22%s\x22\x20<%s>','Mail\x20Transcript','Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a','addMessage','ids','omit','hasOwnProperty','nolimit','order','sort','ChatInteractionId'];(function(_0x9c6e38,_0x1fc24e){var _0x148e08=function(_0x415b66){while(--_0x415b66){_0x9c6e38['push'](_0x9c6e38['shift']());}};_0x148e08(++_0x1fc24e);}(_0x825c,0x1cb));var _0xc825=function(_0x307d86,_0x9264f2){_0x307d86=_0x307d86-0x0;var _0x361745=_0x825c[_0x307d86];return _0x361745;};'use strict';var rimraf=require('rimraf');var zipdir=require(_0xc825('0x0'));var rp=require(_0xc825('0x1'));var moment=require(_0xc825('0x2'));var BPromise=require(_0xc825('0x3'));var Mustache=require(_0xc825('0x4'));var util=require(_0xc825('0x5'));var path=require(_0xc825('0x6'));var ejs=require(_0xc825('0x7'));var fs=require('fs');var _=require(_0xc825('0x8'));var Redis=require(_0xc825('0x9'));var interaction=require('../../components/interaction/service');var qs=require('../../components/parsers/qs');var pdf=require('../../components/export/pdf');var logger=require(_0xc825('0xa'))('api');var config=require('../../config/environment');var db=require(_0xc825('0xb'))['db'];config['redis']=_[_0xc825('0xc')](config[_0xc825('0xd')],{'host':_0xc825('0xe'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xc825('0xd')]));require(_0xc825('0xf'))[_0xc825('0x10')](socket);var jayson=require(_0xc825('0x11'));var client=jayson['client'][_0xc825('0x12')]({'port':0x232b});var client9004=jayson[_0xc825('0x13')]['http']({'port':0x232c});function respondWithRpcPromise(_0x4d4795,_0x241fd3,_0x46c884,_0x188ce2){return new BPromise(function(_0x5c5a02,_0x1626c6){var _0x266cbe=_0x188ce2||client;return _0x266cbe[_0xc825('0x14')](_0x4d4795,_0x46c884)[_0xc825('0x15')](function(_0x5b7ac8){logger[_0xc825('0x16')]('ChatInteraction,\x20%s,\x20%s',_0x241fd3,'request\x20sent');logger[_0xc825('0x17')](_0xc825('0x18'),_0x241fd3,_0xc825('0x19'),JSON[_0xc825('0x1a')](_0x5b7ac8));if(_0x5b7ac8[_0xc825('0x1b')]){if(_0x5b7ac8[_0xc825('0x1b')]['code']===0x1f4){logger[_0xc825('0x1b')](_0xc825('0x1c'),_0x241fd3,_0x5b7ac8[_0xc825('0x1b')][_0xc825('0x1d')]);return _0x1626c6(_0x5b7ac8['error'][_0xc825('0x1d')]);}logger[_0xc825('0x1b')](_0xc825('0x1c'),_0x241fd3,_0x5b7ac8[_0xc825('0x1b')][_0xc825('0x1d')]);return _0x5c5a02(_0x5b7ac8[_0xc825('0x1b')][_0xc825('0x1d')]);}else{logger[_0xc825('0x16')](_0xc825('0x1c'),_0x241fd3,_0xc825('0x19'));_0x5c5a02(_0x5b7ac8['result'][_0xc825('0x1d')]);}})[_0xc825('0x1e')](function(_0x53528d){logger['error'](_0xc825('0x1c'),_0x241fd3,_0x53528d);_0x1626c6(_0x53528d);});});}function respondWithStatusCode(_0x3c7e6f,_0x26e09f){_0x26e09f=_0x26e09f||0xcc;return function(_0x197598){if(_0x197598){return _0x3c7e6f[_0xc825('0x1f')](_0x26e09f);}return _0x3c7e6f['status'](_0x26e09f)[_0xc825('0x20')]();};}function respondWithResult(_0x4147a3,_0x2466c6){_0x2466c6=_0x2466c6||0xc8;return function(_0x26c88b){if(_0x26c88b){return _0x4147a3[_0xc825('0x21')](_0x2466c6)['json'](_0x26c88b);}};}function respondWithFilteredResult(_0x79c632,_0x32330e){return function(_0x12d206){if(_0x12d206){var _0x12d538=typeof _0x32330e[_0xc825('0x22')]===_0xc825('0x23')&&typeof _0x32330e[_0xc825('0x24')]===_0xc825('0x23');var _0x150919=_0x12d206[_0xc825('0x25')];var _0xcaaec5=_0x12d538?0x0:_0x32330e['offset'];var _0x799a87=_0x12d538?_0x12d206['count']:_0x32330e[_0xc825('0x22')]+_0x32330e[_0xc825('0x24')];var _0x27a73e;if(_0x799a87>=_0x150919){_0x799a87=_0x150919;_0x27a73e=0xc8;}else{_0x27a73e=0xce;}_0x79c632[_0xc825('0x21')](_0x27a73e);return _0x79c632[_0xc825('0x26')]('Content-Range',_0xcaaec5+'-'+_0x799a87+'/'+_0x150919)[_0xc825('0x27')](_0x12d206);}return null;};}function saveUpdates(_0xd36abd){return function(_0x57c3f0){if(_0x57c3f0){return _0x57c3f0['update'](_0xd36abd)[_0xc825('0x15')](function(_0x205305){return _0x205305;});}return null;};}function removeEntity(_0x3e63dc){return function(_0x392db4){if(_0x392db4){return _0x392db4[_0xc825('0x28')]()[_0xc825('0x15')](function(){_0x3e63dc['status'](0xcc)[_0xc825('0x20')]();});}};}function handleEntityNotFound(_0x3a7ed5){return function(_0x585337){if(!_0x585337){_0x3a7ed5[_0xc825('0x1f')](0x194);}return _0x585337;};}function handleError(_0x3acab7,_0x2dc6cf){_0x2dc6cf=_0x2dc6cf||0x1f4;return function(_0x403ad0){logger['error'](_0x403ad0['stack']);if(_0x403ad0[_0xc825('0x29')]){delete _0x403ad0[_0xc825('0x29')];}_0x3acab7['status'](_0x2dc6cf)[_0xc825('0x2a')](_0x403ad0);};}function getMustacheRender(_0x1b2660,_0x44135e){return Mustache[_0xc825('0x2b')](_0x1b2660,_['merge'](_0x44135e[_0xc825('0x2c')],{'contact':_0x44135e[_0xc825('0x2d')],'message':_0x44135e[_0xc825('0x1d')],'agent':_0x44135e[_0xc825('0x2e')],'interaction':_0x44135e['interaction'],'account':_0x44135e[_0xc825('0x2f')]}))||'';}exports['index']=function(_0x30db7e,_0x1b3563){var _0x2d3f65={};var _0x40834d=_[_0xc825('0x30')](db[_0xc825('0x31')][_0xc825('0x32')],function(_0x1de89d){return{'name':_0x1de89d[_0xc825('0x33')],'type':_0x1de89d['type']['key']};});_0x2d3f65=qs[_0xc825('0x34')](_0x40834d,_0x30db7e);return interaction['findAll'](_0xc825('0x35'),_0x30db7e[_0xc825('0x36')],_0x30db7e[_0xc825('0x37')],_0x2d3f65,_0x40834d)[_0xc825('0x15')](respondWithFilteredResult(_0x1b3563,_0x2d3f65))['catch'](handleError(_0x1b3563,null));};exports['show']=function(_0x17ad46,_0xe942f9){var _0x25d013={'raw':![],'where':{'id':_0x17ad46[_0xc825('0x38')]['id']}},_0x1cca8a={};_0x1cca8a['model']=_[_0xc825('0x39')](db[_0xc825('0x31')][_0xc825('0x32')]);_0x1cca8a['query']=_[_0xc825('0x39')](_0x17ad46[_0xc825('0x36')]);_0x1cca8a[_0xc825('0x3a')]=_[_0xc825('0x3b')](_0x1cca8a[_0xc825('0x3c')],_0x1cca8a[_0xc825('0x36')]);_0x25d013[_0xc825('0x3d')]=_[_0xc825('0x3b')](_0x1cca8a[_0xc825('0x3c')],qs[_0xc825('0x3e')](_0x17ad46['query'][_0xc825('0x3e')]));_0x25d013[_0xc825('0x3d')]=_0x25d013['attributes'][_0xc825('0x3f')]?_0x25d013['attributes']:_0x1cca8a['model'];if(_0x17ad46[_0xc825('0x36')]['includeAll']){_0x25d013['include']=[{'all':!![]}];}_0x25d013=_['merge']({},_0x25d013,_0x17ad46[_0xc825('0x40')]);return db['ChatInteraction']['find'](_0x25d013)[_0xc825('0x15')](handleEntityNotFound(_0xe942f9,null))[_0xc825('0x15')](respondWithResult(_0xe942f9,null))[_0xc825('0x1e')](handleError(_0xe942f9,null));};exports[_0xc825('0x41')]=function(_0x2c15e2,_0x1e5193){return db[_0xc825('0x31')][_0xc825('0x41')](_0x2c15e2[_0xc825('0x2c')],{})[_0xc825('0x15')](respondWithResult(_0x1e5193,0xc9))[_0xc825('0x1e')](handleError(_0x1e5193,null));};exports[_0xc825('0x42')]=function(_0x4be5de,_0x5acd78){if(_0x4be5de[_0xc825('0x2c')]['id']){delete _0x4be5de[_0xc825('0x2c')]['id'];}return db[_0xc825('0x31')][_0xc825('0x43')]({'where':{'id':_0x4be5de['params']['id']}})[_0xc825('0x15')](handleEntityNotFound(_0x5acd78,null))['then'](saveUpdates(_0x4be5de['body'],null))['then'](respondWithResult(_0x5acd78,null))[_0xc825('0x1e')](handleError(_0x5acd78,null));};exports[_0xc825('0x28')]=function(_0x1e2bed,_0x5b6d54){return db[_0xc825('0x31')][_0xc825('0x43')]({'where':{'id':_0x1e2bed[_0xc825('0x38')]['id']}})[_0xc825('0x15')](handleEntityNotFound(_0x5b6d54,null))[_0xc825('0x15')](removeEntity(_0x5b6d54,null))[_0xc825('0x1e')](handleError(_0x5b6d54,null));};exports[_0xc825('0x44')]=function(_0x3d955d,_0x4b5bcf){return db[_0xc825('0x31')][_0xc825('0x44')]()[_0xc825('0x15')](respondWithResult(_0x4b5bcf,null))[_0xc825('0x1e')](handleError(_0x4b5bcf,null));};exports[_0xc825('0x45')]=function(_0xc05397,_0x46412e){var _0x501be2=_0xc05397[_0xc825('0x38')]['id'];var _0x527f1f;var _0x109451;var _0x49110b;return db[_0xc825('0x31')]['findOne']({'where':{'id':_0x501be2}})['then'](function(_0x1c29ed){_0x527f1f=_0x1c29ed;return db[_0xc825('0x46')][_0xc825('0x47')]({'where':{'id':_0x1c29ed[_0xc825('0x48')]},'attributes':['id',_0xc825('0x49'),_0xc825('0x4a'),'vidaooTopic',_0xc825('0x4b'),'vidaooMetadata'],'raw':!![]});})['then'](function(_0x248fe0){if(_0x248fe0&&_0x248fe0['vidaooApiKey']&&_0x248fe0[_0xc825('0x4a')]){_0x109451=_0x248fe0;var _0x19a552={'interaction':{'id':_0x501be2},'agent':{'id':_0xc05397[_0xc825('0x37')]['id'],'name':_0xc05397[_0xc825('0x37')][_0xc825('0x29')],'fullname':_0xc05397[_0xc825('0x37')]['fullname'],'email':_0xc05397[_0xc825('0x37')][_0xc825('0x4c')]},'contact':_0xc05397[_0xc825('0x2c')][_0xc825('0x2d')],'account':_0xc05397[_0xc825('0x2c')][_0xc825('0x2f')]};var _0x4cfd0e={'rejectUnauthorized':![],'method':_0xc825('0x4d'),'url':_0xc825('0x4e'),'headers':{'X-APIKEY':_0x248fe0[_0xc825('0x49')]},'body':{'duration':null,'scheduledAt':null,'participants':[_0xc05397['user'][_0xc825('0x4c')]],'buttons':null,'topic':_0x109451[_0xc825('0x4f')],'note':_[_0xc825('0x50')](_0x109451[_0xc825('0x4b')])?null:getMustacheRender(_0x109451[_0xc825('0x4b')],_0x19a552),'metadata':null},'redirect':'follow','json':!![]};try{if(!_[_0xc825('0x50')](_0x109451[_0xc825('0x51')])){var _0xe38a47=getMustacheRender(_0x109451[_0xc825('0x51')],_0x19a552);var _0xb6dfe0=JSON['parse'](_0xe38a47);_0x4cfd0e['body'][_0xc825('0x52')]=_0xb6dfe0;}}catch(_0x3cc4fd){throw new db['Sequelize'][(_0xc825('0x53'))]('Error\x20in\x20conversion\x20vidaooMetadata');}return rp(_0x4cfd0e);}else{throw new db[(_0xc825('0x54'))]['ValidationError'](_0xc825('0x55'));}})[_0xc825('0x15')](function(_0x274bbe){_0x49110b=_0x274bbe;if(_0x49110b['id']){var _0x55f378={'body':_0x49110b[_0xc825('0x56')],'ChatWebsiteId':_0x109451['id'],'ChatInteractionId':_0x527f1f['id'],'direction':_0xc825('0x57'),'UserId':_0xc05397[_0xc825('0x37')]['id']};return db[_0xc825('0x58')]['create'](_0x55f378,{});}else{throw new db['Sequelize'][(_0xc825('0x53'))](_0xc825('0x59'));}})[_0xc825('0x15')](function(){return _0x527f1f[_0xc825('0x5a')]({'vidaooSessionId':_0x49110b['id']});})[_0xc825('0x15')](respondWithResult(_0x46412e,null))[_0xc825('0x1e')](handleError(_0x46412e,null));};exports[_0xc825('0x5b')]=function(_0x5a5d69,_0x124744){if(_0x5a5d69[_0xc825('0x2c')]['id']){delete _0x5a5d69[_0xc825('0x2c')]['id'];}return db['ChatInteraction'][_0xc825('0x43')]({'where':{'id':_0x5a5d69[_0xc825('0x38')]['id']},'include':[{'model':db[_0xc825('0x5c')],'as':'Contact'}]})['then'](handleEntityNotFound(_0x124744,null))[_0xc825('0x15')](saveUpdates(_0x5a5d69['body'],null))[_0xc825('0x15')](respondWithResult(_0x124744,null))[_0xc825('0x1e')](handleError(_0x124744,null));};exports[_0xc825('0x5d')]=function(_0x294275,_0x4d40c7){if(_0x294275['body']['id']){delete _0x294275[_0xc825('0x2c')]['id'];}return db['ChatInteraction']['find']({'where':{'id':_0x294275[_0xc825('0x38')]['id']}})['then'](function(_0x4123a7){if(!_0x4123a7){logger[_0xc825('0x1b')](_0xc825('0x5e'),_0xc825('0x5d'),0x194,_0xc825('0x5f'));_0x4d40c7[_0xc825('0x1f')](0x194);}else{if(_0x4123a7['UserId']){throw new db[(_0xc825('0x54'))]['ValidationError'](_0xc825('0x60'));}}return _0x4123a7;})[_0xc825('0x15')](function(_0x9d29d5){if(_0x9d29d5){return _0x9d29d5[_0xc825('0x42')]({'closed':_0x294275[_0xc825('0x2c')][_0xc825('0x61')],'disposition':_0x294275[_0xc825('0x2c')]['disposition']})[_0xc825('0x15')](function(_0x55c155){return _0x55c155;});}})[_0xc825('0x15')](function(){return respondWithRpcPromise(_0xc825('0x62'),_0xc825('0x5d'),_0x294275[_0xc825('0x2c')],client9004);})['then'](respondWithResult(_0x4d40c7,null))['catch'](handleError(_0x4d40c7,null));};exports[_0xc825('0x63')]=function(_0x3a5c8d,_0x167010){_0x3a5c8d['body'][_0xc825('0x29')]=_0x3a5c8d[_0xc825('0x64')][_0xc825('0x65')];_0x3a5c8d[_0xc825('0x2c')][_0xc825('0x66')]=_0x3a5c8d[_0xc825('0x64')]['filename'];_0x3a5c8d['body'][_0xc825('0x67')]=_0x3a5c8d[_0xc825('0x64')][_0xc825('0x68')];return db['Attachment'][_0xc825('0x41')](_0x3a5c8d[_0xc825('0x2c')])['then'](respondWithResult(_0x167010,0xc9))[_0xc825('0x1e')](handleError(_0x167010,null));};exports[_0xc825('0x69')]=function(_0x2e5c0b,_0x6172f7){return db['ChatInteraction'][_0xc825('0x47')]({'where':{'id':_0x2e5c0b[_0xc825('0x38')]['id']},'raw':!![]})[_0xc825('0x15')](handleEntityNotFound(_0x6172f7,null))['then'](function(_0x2f92a0){if(_0x2f92a0){if(_0x2f92a0['closed']){return _0x6172f7[_0xc825('0x21')](0x193)['json']({'status':0x193,'message':'Unauthorized'});}return db[_0xc825('0x6a')][_0xc825('0x47')]({'where':{'id':_0x2e5c0b[_0xc825('0x36')][_0xc825('0x6b')]},'raw':!![]})[_0xc825('0x15')](handleEntityNotFound(_0x6172f7,null));}})[_0xc825('0x15')](function(_0x41193e){if(_0x41193e){var _0xed05e1=_0x41193e['ChatOfflineMessageId']!==null;var _0x496de2=path[_0xc825('0x6c')](config['root'],_0xc825('0x6d'));if(_0xed05e1){_0x496de2=path[_0xc825('0x6c')](_0x496de2,_0xc825('0x6e'));}var _0x2ca9ac=path[_0xc825('0x6c')](_0x496de2,_0x41193e[_0xc825('0x66')]);return _0x6172f7[_0xc825('0x6f')](_0x2ca9ac);}})[_0xc825('0x1e')](handleError(_0x6172f7,null));};exports[_0xc825('0x70')]=function(_0x1a134f,_0xe2bc58){var _0x18cecc=null;var _0x5b656e=null;var _0x5e0ace=null;if(_0x1a134f[_0xc825('0x2c')]['id']){delete _0x1a134f[_0xc825('0x2c')]['id'];}if(_0x1a134f[_0xc825('0x2c')][_0xc825('0x71')]){_0x5e0ace=path[_0xc825('0x6c')](config[_0xc825('0x72')],'server/files/chat/upload/',util[_0xc825('0x73')](_0xc825('0x74'),Date['now']()));_0x1a134f[_0xc825('0x2c')][_0xc825('0x75')]=_0x5e0ace;}return db[_0xc825('0x31')][_0xc825('0x43')]({'where':{'id':_0x1a134f[_0xc825('0x38')]['id']},'include':[{'model':db[_0xc825('0x58')],'as':_0xc825('0x76'),'include':[{'model':db[_0xc825('0x77')],'as':'User'}]}]})['then'](handleEntityNotFound(_0xe2bc58,null))[_0xc825('0x15')](saveUpdates(_0x1a134f['body'],null))[_0xc825('0x15')](function(_0x977732){if(_0x977732){_0x18cecc=_0x977732;return db[_0xc825('0x46')][_0xc825('0x43')]({'where':{'id':_0x18cecc[_0xc825('0x48')]}});}})['then'](function(_0x589c49){if(_0x589c49){_0x5b656e=_0x589c49;return db[_0xc825('0x5c')]['find']({'where':{'id':_0x18cecc[_0xc825('0x78')]}});}})['then'](function(_0x595c05){if(_0x595c05){if(_0x5e0ace){var _0x219f71=null;for(var _0x830ee0=0x1;_0x830ee0<_0x18cecc[_0xc825('0x76')][_0xc825('0x3f')];++_0x830ee0){_0x219f71=_0x18cecc[_0xc825('0x76')][_0x830ee0];var _0x4e74c8=_0x219f71['UserId']?util['format'](_0xc825('0x79'),_0x5b656e[_0xc825('0x7a')],_0x219f71[_0xc825('0x7b')]):_0xc825('0x7c');var _0x56a94e=_0x1a134f[_0xc825('0x2c')][_0xc825('0x7d')]||util[_0xc825('0x73')](_0xc825('0x79'),'Visitor',_0x219f71[_0xc825('0x78')]);switch(_0x5b656e[_0xc825('0x7e')]){case'website_alias':_0x4e74c8=_0x219f71[_0xc825('0x7b')]?util['format'](_0xc825('0x79'),_0x5b656e[_0xc825('0x7a')],_0x219f71[_0xc825('0x7b')]):_0xc825('0x7c');break;case _0xc825('0x7f'):_0x4e74c8=_0x219f71[_0xc825('0x7b')]?_0x219f71[_0xc825('0x77')][_0xc825('0x80')]||_0x219f71[_0xc825('0x77')][_0xc825('0x81')]:_0xc825('0x7c');break;case _0xc825('0x82'):_0x4e74c8=_0x219f71['UserId']?_0x219f71['User']['fullname']:'System';break;default:_0x4e74c8=_0x219f71[_0xc825('0x7b')]?util[_0xc825('0x73')](_0xc825('0x79'),_0x5b656e[_0xc825('0x7a')],_0x219f71[_0xc825('0x7b')]):_0xc825('0x7c');}var _0x30f1f5=util[_0xc825('0x73')](_0xc825('0x83'),moment(_0x219f71[_0xc825('0x84')])['format'](_0xc825('0x85')),_0x219f71['direction']==='in'?_0x56a94e:_0x4e74c8,_0x219f71[_0xc825('0x2c')]);if(!_0x219f71['secret']){fs[_0xc825('0x86')](_0x5e0ace,_0x30f1f5);}}return db[_0xc825('0x87')][_0xc825('0x47')]({'where':{'service':!![]},'include':[{'model':db[_0xc825('0x88')],'as':_0xc825('0x89'),'raw':!![],'include':[{'model':db[_0xc825('0x8a')],'as':'CloudProvider','raw':!![]}]}]});}}})['then'](function(_0x2bc3fd){if(!_0x2bc3fd||!_0x2bc3fd[_0xc825('0x89')]||!_0x1a134f[_0xc825('0x2c')])return _0x18cecc;var _0x591e15=_0x2bc3fd[_0xc825('0x8b')]();return respondWithRpcPromise(_0xc825('0x8c'),_0xc825('0x8d'),{'account':_0x591e15,'message':{'from':util[_0xc825('0x73')](_0xc825('0x8e'),_0x2bc3fd[_0xc825('0x29')],_0x2bc3fd[_0xc825('0x4c')]||_0x2bc3fd[_0xc825('0x89')]['user']),'to':_0x1a134f['body']['mailTranscript'],'subject':_0xc825('0x8f'),'text':util['format'](_0xc825('0x90'),_0x1a134f[_0xc825('0x2c')][_0xc825('0x71')]),'attachments':[{'path':_0x5e0ace}]}})['then'](function(){return _0x18cecc;})[_0xc825('0x1e')](function(_0x4c2d66){logger['error'](_0x4c2d66);});})[_0xc825('0x15')](respondWithStatusCode(_0xe2bc58,0xc8))[_0xc825('0x1e')](handleError(_0xe2bc58,null));};exports[_0xc825('0x91')]=function(_0x326654,_0x38444c){return db[_0xc825('0x58')][_0xc825('0x43')]({'where':{'id':_0x326654['params']['id']}})[_0xc825('0x15')](handleEntityNotFound(_0x38444c,null))[_0xc825('0x15')](function(_0x51aba5){if(_0x51aba5){return _0x51aba5['addMessage'](_0x326654[_0xc825('0x2c')][_0xc825('0x92')],_[_0xc825('0x93')](_0x326654[_0xc825('0x2c')],[_0xc825('0x92'),'id'])||{});}})['then'](respondWithResult(_0x38444c,null))['catch'](handleError(_0x38444c,null));};exports['getMessages']=function(_0x3f64ac,_0x4e63f7){var _0xd7271={'raw':![],'where':{}};var _0x4ff10c={};var _0x54238f={'count':0x0,'rows':[]};return db['ChatInteraction'][_0xc825('0x47')]({'where':{'id':_0x3f64ac[_0xc825('0x38')]['id']}})['then'](handleEntityNotFound(_0x4e63f7,null))[_0xc825('0x15')](function(_0x33c701){if(_0x33c701){_0x4ff10c['model']=_[_0xc825('0x39')](db[_0xc825('0x58')][_0xc825('0x32')]);_0x4ff10c[_0xc825('0x36')]=_[_0xc825('0x39')](_0x3f64ac[_0xc825('0x36')]);_0x4ff10c[_0xc825('0x3a')]=_[_0xc825('0x3b')](_0x4ff10c['model'],_0x4ff10c['query']);_0xd7271[_0xc825('0x3d')]=_[_0xc825('0x3b')](_0x4ff10c[_0xc825('0x3c')],qs[_0xc825('0x3e')](_0x3f64ac[_0xc825('0x36')][_0xc825('0x3e')]));_0xd7271['attributes']=_0xd7271[_0xc825('0x3d')][_0xc825('0x3f')]?_0xd7271[_0xc825('0x3d')]:_0x4ff10c['model'];if(!_0x3f64ac['query'][_0xc825('0x94')](_0xc825('0x95'))){_0xd7271[_0xc825('0x24')]=qs[_0xc825('0x24')](_0x3f64ac[_0xc825('0x36')]['limit']);_0xd7271[_0xc825('0x22')]=qs[_0xc825('0x22')](_0x3f64ac[_0xc825('0x36')][_0xc825('0x22')]);}_0xd7271[_0xc825('0x96')]=qs[_0xc825('0x97')](_0x3f64ac[_0xc825('0x36')][_0xc825('0x97')]);_0xd7271['where']=qs[_0xc825('0x3a')](_['pick'](_0x3f64ac['query'],_0x4ff10c['filters']));_0xd7271['where'][_0xc825('0x98')]=_0x33c701['id'];if(_0x3f64ac[_0xc825('0x36')]['filter']){_0xd7271['where']=_[_0xc825('0x99')](_0xd7271[_0xc825('0x9a')],{'$or':_[_0xc825('0x30')](_0xd7271[_0xc825('0x3d')],function(_0x362e80){var _0x2f05d3={};_0x2f05d3[_0x362e80]={'$like':'%'+_0x3f64ac['query'][_0xc825('0x9b')]+'%'};return _0x2f05d3;})});}if(_0x3f64ac[_0xc825('0x36')][_0xc825('0x9c')]){var _0x389f78=_0x3f64ac[_0xc825('0x36')][_0xc825('0x9c')][_0xc825('0x9d')](',');var _0x474b9e={};_0x474b9e[_0x389f78[0x0]]={'$gte':moment(_0x389f78[0x1])[_0xc825('0x73')](_0xc825('0x9e'))};_0xd7271[_0xc825('0x9a')]=_[_0xc825('0x99')](_0xd7271[_0xc825('0x9a')],_0x474b9e);}_0xd7271=_[_0xc825('0x99')]({},_0xd7271,_0x3f64ac[_0xc825('0x40')]);return db['ChatMessage']['count']({'where':_0xd7271[_0xc825('0x9a')]})[_0xc825('0x15')](function(_0x44d34e){_0x54238f[_0xc825('0x25')]=_0x44d34e;if(_0x3f64ac[_0xc825('0x36')][_0xc825('0x9f')]){_0xd7271[_0xc825('0xa0')]=[{'all':!![]}];}return db[_0xc825('0x58')]['findAll'](_0xd7271);})[_0xc825('0x15')](function(_0x1ece62){_0x54238f['rows']=_0x1ece62;return _0x54238f;});}})[_0xc825('0x15')](respondWithFilteredResult(_0x4e63f7,_0xd7271))[_0xc825('0x1e')](handleError(_0x4e63f7,null));};exports[_0xc825('0xa1')]=function(_0x8ad242,_0x5e34b0){var _0x24a704={'where':{}},_0x44b7ca={},_0x5e3ce3={'count':0x0,'rows':[]};return db[_0xc825('0x31')][_0xc825('0x47')]({'where':{'id':_0x8ad242[_0xc825('0x38')]['id']}})['then'](handleEntityNotFound(_0x5e34b0,null))[_0xc825('0x15')](function(_0x61eda1){if(_0x61eda1){_0x44b7ca[_0xc825('0x3c')]=_[_0xc825('0x39')](db[_0xc825('0x58')][_0xc825('0x32')]);_0x44b7ca[_0xc825('0x36')]=_[_0xc825('0x39')](_0x8ad242[_0xc825('0x36')]);_0x44b7ca['filters']=_[_0xc825('0x3b')](_0x44b7ca['model'],_0x44b7ca[_0xc825('0x36')]);_0x24a704[_0xc825('0x3d')]=_[_0xc825('0x3b')](_0x44b7ca['model'],qs[_0xc825('0x3e')](_0x8ad242['query'][_0xc825('0x3e')]));_0x24a704['attributes']=_0x24a704['attributes'][_0xc825('0x3f')]?_0x24a704[_0xc825('0x3d')]:_0x44b7ca[_0xc825('0x3c')];if(!_0x8ad242[_0xc825('0x36')][_0xc825('0x94')](_0xc825('0x95'))){_0x24a704[_0xc825('0x24')]=qs[_0xc825('0x24')](_0x8ad242[_0xc825('0x36')][_0xc825('0x24')]);_0x24a704['offset']=qs[_0xc825('0x22')](_0x8ad242[_0xc825('0x36')][_0xc825('0x22')]);}_0x24a704[_0xc825('0x96')]=qs[_0xc825('0x97')](_0x8ad242[_0xc825('0x36')][_0xc825('0x97')]);_0x24a704[_0xc825('0x9a')]=qs[_0xc825('0x3a')](_['pick'](_0x8ad242[_0xc825('0x36')],_0x44b7ca[_0xc825('0x3a')]));_0x24a704[_0xc825('0x9a')][_0xc825('0x98')]=_0x61eda1['id'];if(_0x8ad242[_0xc825('0x36')]['filter']){_0x24a704[_0xc825('0x9a')]=_['merge'](_0x24a704[_0xc825('0x9a')],{'$or':_[_0xc825('0x30')](_0x24a704['attributes'],function(_0x341498){var _0xe26688={};_0xe26688[_0x341498]={'$like':'%'+_0x8ad242[_0xc825('0x36')][_0xc825('0x9b')]+'%'};return _0xe26688;})});}_0x24a704[_0xc825('0x9a')][_0xc825('0xa2')]=![];if(_0x8ad242['query']['id']){_0x24a704[_0xc825('0x9a')]['id']={'$gt':_0x8ad242[_0xc825('0x36')]['id']};}_0x24a704=_['merge']({},_0x24a704,_0x8ad242[_0xc825('0x40')]);return db[_0xc825('0x58')][_0xc825('0x25')]({'where':_0x24a704[_0xc825('0x9a')]})[_0xc825('0x15')](function(_0x13ffb1){_0x5e3ce3['count']=_0x13ffb1;_0x24a704[_0xc825('0xa0')]=[];if(_0x8ad242['query']['includeAgent']){_0x24a704['include'][_0xc825('0xa3')]({'model':db['User'],'as':_0xc825('0x77'),'attributes':['id','fullname','alias']});}if(_0x8ad242[_0xc825('0x36')]['includeAll']){_0x24a704[_0xc825('0xa0')]=[{'all':!![]}];}return db[_0xc825('0x58')]['findAll'](_0x24a704);})['then'](function(_0x4a1edf){_0x5e3ce3[_0xc825('0xa4')]=_0x4a1edf;return _0x5e3ce3;});}})['then'](respondWithFilteredResult(_0x5e34b0,_0x24a704))[_0xc825('0x1e')](handleError(_0x5e34b0,null));};exports[_0xc825('0xa5')]=function(_0xe84429,_0x35a2f7){return db[_0xc825('0x31')][_0xc825('0x43')]({'where':{'id':_0xe84429['params']['id']}})[_0xc825('0x15')](handleEntityNotFound(_0x35a2f7,null))[_0xc825('0x15')](function(_0x29ff19){if(_0x29ff19){return _0x29ff19['setTags'](_0xe84429['body'][_0xc825('0x92')],_[_0xc825('0x93')](_0xe84429[_0xc825('0x2c')],[_0xc825('0x92'),'id'])||{})[_0xc825('0xa6')](function(){return db[_0xc825('0xa7')][_0xc825('0xa8')]({'attributes':['id','name',_0xc825('0xa9')],'where':{'id':_0xe84429[_0xc825('0x2c')][_0xc825('0x92')]}});})[_0xc825('0x15')](function(_0x162bc){socket[_0xc825('0xaa')](_0xc825('0xab'),{'id':Number(_0xe84429['params']['id']),'tags':_0x162bc||[]});return{'id':Number(_0xe84429[_0xc825('0x38')]['id']),'tags':_0x162bc||[]};});}})[_0xc825('0x15')](respondWithResult(_0x35a2f7,null))[_0xc825('0x1e')](handleError(_0x35a2f7,null));};exports[_0xc825('0xac')]=function(_0x5c50c7,_0x135eed){return db[_0xc825('0x31')][_0xc825('0x43')]({'where':{'id':_0x5c50c7['params']['id']}})[_0xc825('0x15')](handleEntityNotFound(_0x135eed,null))[_0xc825('0x15')](function(_0x39db3d){if(_0x39db3d){return _0x39db3d[_0xc825('0xac')](_0x5c50c7[_0xc825('0x36')][_0xc825('0x92')]);}})['then'](respondWithStatusCode(_0x135eed,null))[_0xc825('0x1e')](handleError(_0x135eed,null));};exports[_0xc825('0x6f')]=function(_0x10e9b6,_0x24c15f){var _0x2a77ea=moment()[_0xc825('0xad')]()['toString']();var _0x30cfa8=path[_0xc825('0x6c')](config[_0xc825('0x72')],_0xc825('0xae'),_0xc825('0xaf'),_0xc825('0xb0'));var _0x33eb07=path[_0xc825('0x6c')](config[_0xc825('0x72')],_0xc825('0xae'),_0xc825('0xaf'),_0xc825('0xb1'));var _0x594909=path[_0xc825('0x6c')](_0x30cfa8,_0x2a77ea);var _0x31c766=util[_0xc825('0x73')]('transcript-%d-%s.zip',_0x10e9b6[_0xc825('0x38')]['id'],_0x2a77ea);var _0x38b22d=path[_0xc825('0x6c')](_0x30cfa8,_0x31c766);var _0x5ebef4=[];_0x5ebef4[_0xc825('0xa3')]({'model':db[_0xc825('0x77')],'as':_0xc825('0x77'),'attributes':['id',_0xc825('0x81')],'raw':!![]});_0x5ebef4[_0xc825('0xa3')]({'model':db[_0xc825('0x5c')],'as':_0xc825('0xb2'),'attributes':['id',_0xc825('0xb3'),_0xc825('0xb4')],'raw':!![]});if(_0x10e9b6[_0xc825('0x36')][_0xc825('0xb1')]){_0x5ebef4[_0xc825('0xa3')]({'model':db[_0xc825('0x6a')],'as':'Attachment','raw':!![]});}var _0x12db94=[{'model':db[_0xc825('0x58')],'as':_0xc825('0x76'),'attributes':['id',_0xc825('0x2c'),_0xc825('0x84'),_0xc825('0xb5'),_0xc825('0xa2'),_0xc825('0xb6')],'include':_0x5ebef4}];_0x12db94[_0xc825('0xa3')]({'model':db['ChatWebsite'],'as':_0xc825('0xb7'),'attributes':['id',_0xc825('0x29')]});_0x12db94['push']({'model':db[_0xc825('0x77')],'as':'Owner','attributes':['id',_0xc825('0x81')]});return db[_0xc825('0x31')][_0xc825('0x43')]({'where':{'id':_0x10e9b6['params']['id']},'include':_0x12db94})[_0xc825('0x15')](handleEntityNotFound(_0x24c15f,null))[_0xc825('0x15')](function(_0x4aa07f){if(_0x4aa07f){var _0x27ebf4=_0x4aa07f[_0xc825('0xb8')]({'plain':!![]});fs[_0xc825('0xb9')](_0x594909);var _0x512ea8={'channel':_0xc825('0xba'),'account':_0x27ebf4[_0xc825('0xb7')][_0xc825('0x29')],'agent':_0x27ebf4[_0xc825('0xbb')]?_0x27ebf4[_0xc825('0xbb')][_0xc825('0x81')]:_0xc825('0xbc'),'createdAt':moment(_0x27ebf4[_0xc825('0x84')])[_0xc825('0x73')]('YYYY-MM-DD\x20HH:mm:ss')['toString'](),'closedAt':_0x27ebf4[_0xc825('0x61')]?moment(_0x27ebf4[_0xc825('0xbd')])[_0xc825('0x73')](_0xc825('0x9e'))[_0xc825('0xbe')]():'','disposition':_0x27ebf4[_0xc825('0xbf')],'chatInfo':{'browser':_0x27ebf4[_0xc825('0xc0')],'os':_0x27ebf4['osName'],'referer':_0x27ebf4['referer'],'customerIp':_0x27ebf4[_0xc825('0xc1')],'customerPort':_0x27ebf4['customerPort']?_0x27ebf4[_0xc825('0xc2')]:_0xc825('0xbc')},'messages':_(_0x27ebf4['Messages'])[_0xc825('0xc3')]()[_0xc825('0x9b')]({'secret':![]})['map'](function(_0x1570e0){if(_0x1570e0[_0xc825('0x6a')]){var _0x2d6b4d=path[_0xc825('0x6c')](_0x33eb07,_0x1570e0['Attachment'][_0xc825('0x66')]);if(fs[_0xc825('0xc4')](_0x2d6b4d)){fs[_0xc825('0xc5')](_0x2d6b4d)[_0xc825('0xc6')](fs[_0xc825('0xc7')](path[_0xc825('0x6c')](_0x594909,_0x1570e0['Attachment'][_0xc825('0x66')])));}}return{'date':moment(_0x1570e0[_0xc825('0x84')])['format']('YYYY-MM-DD\x20HH:mm:ss')['toString'](),'sender':_0x1570e0[_0xc825('0xb5')]==='out'?_0x1570e0[_0xc825('0x77')]?_0x1570e0[_0xc825('0x77')][_0xc825('0x81')]:_0xc825('0x7c'):_0x1570e0[_0xc825('0xb2')][_0xc825('0xb3')]+(_0x1570e0[_0xc825('0xb2')][_0xc825('0xb4')]?'\x20'+_0x1570e0['Contact'][_0xc825('0xb4')]:''),'body':_0x1570e0[_0xc825('0x6a')]?_0x1570e0[_0xc825('0x6a')][_0xc825('0x66')]:_0x1570e0[_0xc825('0x2c')],'direction':_0x1570e0[_0xc825('0xb5')]==='out'?'A':'C','secret':_0x1570e0[_0xc825('0xa2')],'read':_0x1570e0['read'],'attachment':_0x1570e0[_0xc825('0x6a')]};})[_0xc825('0xc8')]()};return ejs[_0xc825('0xc9')](path[_0xc825('0x6c')](config[_0xc825('0x72')],_0xc825('0xae'),_0xc825('0xca'),_0xc825('0xcb')),{'interaction':_0x512ea8})[_0xc825('0x15')](function(_0xad356e){var _0x8478a3=path[_0xc825('0x6c')](_0x594909,'transcript-'+_0x27ebf4['id']+'-'+_0x2a77ea+'.pdf');var _0x5cf6a0={'path':_0x8478a3,'channel':_0xc825('0xba'),'interactionId':_0x27ebf4['id']};return pdf['createPdfFromHTML'](_0xad356e,_0x5cf6a0);})[_0xc825('0x15')](function(){return new Promise(function(_0x38b80c,_0x1298bc){zipdir(_0x594909,{'saveTo':_0x38b22d},function(_0x7f22bf,_0x38123d){if(_0x7f22bf)return _0x1298bc(_0x7f22bf);return _0x38b80c(_0x38123d);});})[_0xc825('0x15')](function(){return new BPromise(function(_0x1c8cf4,_0x3d1db6){rimraf(_0x594909,function(_0x4ad09f){if(_0x4ad09f)_0x3d1db6(_0x4ad09f);return _0x1c8cf4();});});})['then'](function(){return _0x24c15f[_0xc825('0x6f')](_0x38b22d,_0x31c766,function(_0x243f23){if(_0x243f23){logger[_0xc825('0x1b')]('err',_0x243f23);}else{fs['unlinkSync'](_0x38b22d);}});});});}else{return _0x24c15f[_0xc825('0x1f')](0xc8);}})[_0xc825('0x1e')](handleError(_0x24c15f,null));};
\ No newline at end of file
+var _0xf163=['originalname','file','filename','mimetype','findOne','Unauthorized','Attachment','attachId','join','root','server/files/attachments/','offline-chat/','basename','download','close','mailTranscript','server/files/chat/upload/','format','transcript-%s.txt','now','User','ContactId','Messages','UserId','agentAlias','customer','%s%d','Visitor','agentIdentifier','website_alias','System','agent_alias','alias','agent_fullname','fullname','MM/DD/YYYY\x20HH:mm:ss','secret','MailServerOut','Smtp','CloudProvider','getSmtpOptions','sendMail','\x22%s\x22\x20<%s>','Mail\x20Transcript','addMessage','ChatMessage','ids','omit','filters','hasOwnProperty','sort','ChatInteractionId','filter','where','$gte','YYYY-MM-DD\x20HH:mm:ss','include','rows','nolimit','pick','includeAgent','push','addTags','setTags','Tag','emit','chatInteractionTags:save','removeTags','unix','toString','server','files','tmp','firstName','attachments','createdAt','direction','Owner','get','mkdirSync','Chat','N.A.','browserName','referer','customerIp','customerPort','createReadStream','out','lastName','read','renderFile','views','downloadInteraction.ejs','createPdfFromHTML','err','unlinkSync','zip-dir','request-promise','bluebird','mustache','util','ejs','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','api','../../config/environment','../../mysqldb','redis','localhost','socket.io-emitter','client','http','request','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','sendStatus','end','status','json','offset','undefined','limit','count','set','Content-Range','update','destroy','stack','name','send','render','merge','contact','agent','interaction','index','map','ChatInteraction','fieldName','type','getOptions','findAll','chat','query','then','params','model','rawAttributes','keys','intersection','attributes','fields','length','includeAll','options','find','create','body','describe','createVidaooSession','ChatWebsite','ChatWebsiteId','vidaooApiKey','vidaooEscalation','vidaooMetadata','user','email','POST','https://api-vidaoo.xcally.com/api/v1/meetings','isNull','vidaooNote','parse','metadata','Sequelize','ValidationError','Error\x20in\x20conversion\x20vidaooMetadata','Unable\x20to\x20create\x20Vidaoo\x20session','updateAttributes','customUpdate','CmContact','Contact','abandon','abandonInteraction,\x20%s,\x20%s,\x20%s','Interaction\x20already\x20assigned','closed','disposition','attachmentUpload'];(function(_0x12f4d2,_0x3a416e){var _0x488e5e=function(_0x43fe1e){while(--_0x43fe1e){_0x12f4d2['push'](_0x12f4d2['shift']());}};_0x488e5e(++_0x3a416e);}(_0xf163,0x1ec));var _0x3f16=function(_0x4eaa4c,_0x2f7422){_0x4eaa4c=_0x4eaa4c-0x0;var _0x15aec6=_0xf163[_0x4eaa4c];return _0x15aec6;};'use strict';var rimraf=require('rimraf');var zipdir=require(_0x3f16('0x0'));var rp=require(_0x3f16('0x1'));var moment=require('moment');var BPromise=require(_0x3f16('0x2'));var Mustache=require(_0x3f16('0x3'));var util=require(_0x3f16('0x4'));var path=require('path');var ejs=require(_0x3f16('0x5'));var fs=require('fs');var _=require(_0x3f16('0x6'));var Redis=require(_0x3f16('0x7'));var interaction=require(_0x3f16('0x8'));var qs=require(_0x3f16('0x9'));var pdf=require(_0x3f16('0xa'));var logger=require('../../config/logger')(_0x3f16('0xb'));var config=require(_0x3f16('0xc'));var db=require(_0x3f16('0xd'))['db'];config[_0x3f16('0xe')]=_['defaults'](config[_0x3f16('0xe')],{'host':_0x3f16('0xf'),'port':0x18eb});var socket=require(_0x3f16('0x10'))(new Redis(config['redis']));require('./chatInteraction.socket')['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0x3f16('0x11')][_0x3f16('0x12')]({'port':0x232b});var client9004=jayson[_0x3f16('0x11')][_0x3f16('0x12')]({'port':0x232c});function respondWithRpcPromise(_0x3bdbb2,_0x15237c,_0x2d7781,_0x101dca){return new BPromise(function(_0x265e43,_0x592eaf){var _0x3fb33d=_0x101dca||client;return _0x3fb33d[_0x3f16('0x13')](_0x3bdbb2,_0x2d7781)['then'](function(_0x4d5eb5){logger[_0x3f16('0x14')](_0x3f16('0x15'),_0x15237c,_0x3f16('0x16'));logger[_0x3f16('0x17')](_0x3f16('0x18'),_0x15237c,'request\x20sent',JSON[_0x3f16('0x19')](_0x4d5eb5));if(_0x4d5eb5['error']){if(_0x4d5eb5[_0x3f16('0x1a')]['code']===0x1f4){logger['error'](_0x3f16('0x15'),_0x15237c,_0x4d5eb5[_0x3f16('0x1a')]['message']);return _0x592eaf(_0x4d5eb5['error'][_0x3f16('0x1b')]);}logger[_0x3f16('0x1a')](_0x3f16('0x15'),_0x15237c,_0x4d5eb5[_0x3f16('0x1a')][_0x3f16('0x1b')]);return _0x265e43(_0x4d5eb5[_0x3f16('0x1a')][_0x3f16('0x1b')]);}else{logger[_0x3f16('0x14')](_0x3f16('0x15'),_0x15237c,'request\x20sent');_0x265e43(_0x4d5eb5[_0x3f16('0x1c')][_0x3f16('0x1b')]);}})[_0x3f16('0x1d')](function(_0x2660d8){logger[_0x3f16('0x1a')](_0x3f16('0x15'),_0x15237c,_0x2660d8);_0x592eaf(_0x2660d8);});});}function respondWithStatusCode(_0x228c29,_0x31614a){_0x31614a=_0x31614a||0xcc;return function(_0x2a481c){if(_0x2a481c){return _0x228c29[_0x3f16('0x1e')](_0x31614a);}return _0x228c29['status'](_0x31614a)[_0x3f16('0x1f')]();};}function respondWithResult(_0x35f270,_0x3986e4){_0x3986e4=_0x3986e4||0xc8;return function(_0x2f55f7){if(_0x2f55f7){return _0x35f270[_0x3f16('0x20')](_0x3986e4)[_0x3f16('0x21')](_0x2f55f7);}};}function respondWithFilteredResult(_0x3b8155,_0x35b044){return function(_0x1b22c9){if(_0x1b22c9){var _0x478d7d=typeof _0x35b044[_0x3f16('0x22')]===_0x3f16('0x23')&&typeof _0x35b044[_0x3f16('0x24')]==='undefined';var _0x4ef0c2=_0x1b22c9[_0x3f16('0x25')];var _0x4a7c2b=_0x478d7d?0x0:_0x35b044[_0x3f16('0x22')];var _0x53c3ea=_0x478d7d?_0x1b22c9[_0x3f16('0x25')]:_0x35b044['offset']+_0x35b044['limit'];var _0xfdf9c;if(_0x53c3ea>=_0x4ef0c2){_0x53c3ea=_0x4ef0c2;_0xfdf9c=0xc8;}else{_0xfdf9c=0xce;}_0x3b8155['status'](_0xfdf9c);return _0x3b8155[_0x3f16('0x26')](_0x3f16('0x27'),_0x4a7c2b+'-'+_0x53c3ea+'/'+_0x4ef0c2)[_0x3f16('0x21')](_0x1b22c9);}return null;};}function saveUpdates(_0x44eba9){return function(_0x57d2f2){if(_0x57d2f2){return _0x57d2f2[_0x3f16('0x28')](_0x44eba9)['then'](function(_0x14aeb9){return _0x14aeb9;});}return null;};}function removeEntity(_0x480143){return function(_0x53f49f){if(_0x53f49f){return _0x53f49f[_0x3f16('0x29')]()['then'](function(){_0x480143[_0x3f16('0x20')](0xcc)[_0x3f16('0x1f')]();});}};}function handleEntityNotFound(_0x1050f9){return function(_0x2440d1){if(!_0x2440d1){_0x1050f9[_0x3f16('0x1e')](0x194);}return _0x2440d1;};}function handleError(_0x3bd86b,_0x1de7d3){_0x1de7d3=_0x1de7d3||0x1f4;return function(_0x11239a){logger['error'](_0x11239a[_0x3f16('0x2a')]);if(_0x11239a[_0x3f16('0x2b')]){delete _0x11239a[_0x3f16('0x2b')];}_0x3bd86b[_0x3f16('0x20')](_0x1de7d3)[_0x3f16('0x2c')](_0x11239a);};}function getMustacheRender(_0x24a4ba,_0x4d13ef){return Mustache[_0x3f16('0x2d')](_0x24a4ba,_[_0x3f16('0x2e')](_0x4d13ef['body'],{'contact':_0x4d13ef[_0x3f16('0x2f')],'message':_0x4d13ef['message'],'agent':_0x4d13ef[_0x3f16('0x30')],'interaction':_0x4d13ef[_0x3f16('0x31')],'account':_0x4d13ef['account']}))||'';}exports[_0x3f16('0x32')]=function(_0x110426,_0x3bf5ef){var _0x3fa6e6={};var _0x491885=_[_0x3f16('0x33')](db[_0x3f16('0x34')]['rawAttributes'],function(_0x383493){return{'name':_0x383493[_0x3f16('0x35')],'type':_0x383493[_0x3f16('0x36')]['key']};});_0x3fa6e6=qs[_0x3f16('0x37')](_0x491885,_0x110426);return interaction[_0x3f16('0x38')](_0x3f16('0x39'),_0x110426[_0x3f16('0x3a')],_0x110426['user'],_0x3fa6e6,_0x491885)[_0x3f16('0x3b')](respondWithFilteredResult(_0x3bf5ef,_0x3fa6e6))[_0x3f16('0x1d')](handleError(_0x3bf5ef,null));};exports['show']=function(_0xd98e09,_0x510376){var _0x33052d={'raw':![],'where':{'id':_0xd98e09[_0x3f16('0x3c')]['id']}},_0x2bf687={};_0x2bf687[_0x3f16('0x3d')]=_['keys'](db[_0x3f16('0x34')][_0x3f16('0x3e')]);_0x2bf687[_0x3f16('0x3a')]=_[_0x3f16('0x3f')](_0xd98e09[_0x3f16('0x3a')]);_0x2bf687['filters']=_[_0x3f16('0x40')](_0x2bf687['model'],_0x2bf687['query']);_0x33052d[_0x3f16('0x41')]=_['intersection'](_0x2bf687['model'],qs['fields'](_0xd98e09[_0x3f16('0x3a')][_0x3f16('0x42')]));_0x33052d['attributes']=_0x33052d[_0x3f16('0x41')][_0x3f16('0x43')]?_0x33052d[_0x3f16('0x41')]:_0x2bf687[_0x3f16('0x3d')];if(_0xd98e09['query'][_0x3f16('0x44')]){_0x33052d['include']=[{'all':!![]}];}_0x33052d=_[_0x3f16('0x2e')]({},_0x33052d,_0xd98e09[_0x3f16('0x45')]);return db['ChatInteraction'][_0x3f16('0x46')](_0x33052d)[_0x3f16('0x3b')](handleEntityNotFound(_0x510376,null))[_0x3f16('0x3b')](respondWithResult(_0x510376,null))['catch'](handleError(_0x510376,null));};exports['create']=function(_0x320468,_0x3b0397){return db['ChatInteraction'][_0x3f16('0x47')](_0x320468[_0x3f16('0x48')],{})[_0x3f16('0x3b')](respondWithResult(_0x3b0397,0xc9))[_0x3f16('0x1d')](handleError(_0x3b0397,null));};exports[_0x3f16('0x28')]=function(_0x1efd30,_0x34ab9f){if(_0x1efd30[_0x3f16('0x48')]['id']){delete _0x1efd30[_0x3f16('0x48')]['id'];}return db[_0x3f16('0x34')][_0x3f16('0x46')]({'where':{'id':_0x1efd30['params']['id']}})[_0x3f16('0x3b')](handleEntityNotFound(_0x34ab9f,null))[_0x3f16('0x3b')](saveUpdates(_0x1efd30['body'],null))[_0x3f16('0x3b')](respondWithResult(_0x34ab9f,null))[_0x3f16('0x1d')](handleError(_0x34ab9f,null));};exports[_0x3f16('0x29')]=function(_0xa27c5b,_0x127bb7){return db[_0x3f16('0x34')][_0x3f16('0x46')]({'where':{'id':_0xa27c5b[_0x3f16('0x3c')]['id']}})[_0x3f16('0x3b')](handleEntityNotFound(_0x127bb7,null))[_0x3f16('0x3b')](removeEntity(_0x127bb7,null))[_0x3f16('0x1d')](handleError(_0x127bb7,null));};exports[_0x3f16('0x49')]=function(_0xdd2169,_0x496bdd){return db[_0x3f16('0x34')][_0x3f16('0x49')]()[_0x3f16('0x3b')](respondWithResult(_0x496bdd,null))[_0x3f16('0x1d')](handleError(_0x496bdd,null));};exports[_0x3f16('0x4a')]=function(_0x3b3dc7,_0x2fd38d){var _0x16793c=_0x3b3dc7[_0x3f16('0x3c')]['id'];var _0xeb1272;var _0x28596a;var _0x3db6b4;return db[_0x3f16('0x34')]['findOne']({'where':{'id':_0x16793c}})[_0x3f16('0x3b')](function(_0x95ff0e){_0xeb1272=_0x95ff0e;return db[_0x3f16('0x4b')]['findOne']({'where':{'id':_0x95ff0e[_0x3f16('0x4c')]},'attributes':['id',_0x3f16('0x4d'),_0x3f16('0x4e'),'vidaooTopic','vidaooNote',_0x3f16('0x4f')],'raw':!![]});})[_0x3f16('0x3b')](function(_0x57314d){if(_0x57314d&&_0x57314d[_0x3f16('0x4d')]&&_0x57314d['vidaooEscalation']){_0x28596a=_0x57314d;var _0x644070={'interaction':{'id':_0x16793c},'agent':{'id':_0x3b3dc7[_0x3f16('0x50')]['id'],'name':_0x3b3dc7[_0x3f16('0x50')][_0x3f16('0x2b')],'fullname':_0x3b3dc7[_0x3f16('0x50')]['fullname'],'email':_0x3b3dc7[_0x3f16('0x50')][_0x3f16('0x51')]},'contact':_0x3b3dc7[_0x3f16('0x48')][_0x3f16('0x2f')],'account':_0x3b3dc7['body']['account']};var _0x4c6678={'rejectUnauthorized':![],'method':_0x3f16('0x52'),'url':_0x3f16('0x53'),'headers':{'X-APIKEY':_0x57314d[_0x3f16('0x4d')]},'body':{'duration':null,'scheduledAt':null,'participants':[_0x3b3dc7['user'][_0x3f16('0x51')]],'buttons':null,'topic':_0x28596a['vidaooTopic'],'note':_[_0x3f16('0x54')](_0x28596a[_0x3f16('0x55')])?null:getMustacheRender(_0x28596a[_0x3f16('0x55')],_0x644070),'metadata':null},'redirect':'follow','json':!![]};try{if(!_[_0x3f16('0x54')](_0x28596a[_0x3f16('0x4f')])){var _0x440ff4=getMustacheRender(_0x28596a[_0x3f16('0x4f')],_0x644070);var _0x40f8f0=JSON[_0x3f16('0x56')](_0x440ff4);_0x4c6678[_0x3f16('0x48')][_0x3f16('0x57')]=_0x40f8f0;}}catch(_0x5892fc){throw new db[(_0x3f16('0x58'))][(_0x3f16('0x59'))](_0x3f16('0x5a'));}return rp(_0x4c6678);}else{throw new db[(_0x3f16('0x58'))]['ValidationError']('Error\x20in\x20Vidaoo\x20configuration');}})[_0x3f16('0x3b')](function(_0x132472){_0x3db6b4=_0x132472;if(_0x3db6b4['id']){var _0x111dde={'body':_0x3db6b4['join_url'],'ChatWebsiteId':_0x28596a['id'],'ChatInteractionId':_0xeb1272['id'],'direction':'out','UserId':_0x3b3dc7['user']['id']};return db['ChatMessage'][_0x3f16('0x47')](_0x111dde,{});}else{throw new db[(_0x3f16('0x58'))][(_0x3f16('0x59'))](_0x3f16('0x5b'));}})[_0x3f16('0x3b')](function(){return _0xeb1272[_0x3f16('0x5c')]({'vidaooSessionId':_0x3db6b4['id']});})[_0x3f16('0x3b')](respondWithResult(_0x2fd38d,null))[_0x3f16('0x1d')](handleError(_0x2fd38d,null));};exports[_0x3f16('0x5d')]=function(_0x1a79f7,_0x47885b){if(_0x1a79f7[_0x3f16('0x48')]['id']){delete _0x1a79f7['body']['id'];}return db[_0x3f16('0x34')][_0x3f16('0x46')]({'where':{'id':_0x1a79f7[_0x3f16('0x3c')]['id']},'include':[{'model':db[_0x3f16('0x5e')],'as':_0x3f16('0x5f')}]})['then'](handleEntityNotFound(_0x47885b,null))[_0x3f16('0x3b')](saveUpdates(_0x1a79f7['body'],null))['then'](respondWithResult(_0x47885b,null))['catch'](handleError(_0x47885b,null));};exports[_0x3f16('0x60')]=function(_0x1c07ba,_0xf3025b){if(_0x1c07ba[_0x3f16('0x48')]['id']){delete _0x1c07ba[_0x3f16('0x48')]['id'];}return db[_0x3f16('0x34')][_0x3f16('0x46')]({'where':{'id':_0x1c07ba[_0x3f16('0x3c')]['id']}})[_0x3f16('0x3b')](function(_0x18d74a){if(!_0x18d74a){logger['error'](_0x3f16('0x61'),_0x3f16('0x60'),0x194,'entity\x20not\x20found');_0xf3025b[_0x3f16('0x1e')](0x194);}else{if(_0x18d74a['UserId']){throw new db[(_0x3f16('0x58'))]['ValidationError'](_0x3f16('0x62'));}}return _0x18d74a;})[_0x3f16('0x3b')](function(_0x55cff2){if(_0x55cff2){return _0x55cff2[_0x3f16('0x28')]({'closed':_0x1c07ba['body'][_0x3f16('0x63')],'disposition':_0x1c07ba[_0x3f16('0x48')][_0x3f16('0x64')]})[_0x3f16('0x3b')](function(_0x87c5b){return _0x87c5b;});}})[_0x3f16('0x3b')](function(){return respondWithRpcPromise('AbandonInteraction',_0x3f16('0x60'),_0x1c07ba[_0x3f16('0x48')],client9004);})[_0x3f16('0x3b')](respondWithResult(_0xf3025b,null))['catch'](handleError(_0xf3025b,null));};exports[_0x3f16('0x65')]=function(_0x31691d,_0x3db514){_0x31691d['body']['name']=_0x31691d['file'][_0x3f16('0x66')];_0x31691d['body']['basename']=_0x31691d[_0x3f16('0x67')][_0x3f16('0x68')];_0x31691d[_0x3f16('0x48')]['type']=_0x31691d[_0x3f16('0x67')][_0x3f16('0x69')];return db['Attachment'][_0x3f16('0x47')](_0x31691d[_0x3f16('0x48')])[_0x3f16('0x3b')](respondWithResult(_0x3db514,0xc9))[_0x3f16('0x1d')](handleError(_0x3db514,null));};exports['attachmentDownload']=function(_0x537fee,_0x162dd4){return db['ChatInteraction'][_0x3f16('0x6a')]({'where':{'id':_0x537fee[_0x3f16('0x3c')]['id']},'raw':!![]})[_0x3f16('0x3b')](handleEntityNotFound(_0x162dd4,null))[_0x3f16('0x3b')](function(_0x467609){if(_0x467609){if(_0x467609['closed']){return _0x162dd4[_0x3f16('0x20')](0x193)[_0x3f16('0x21')]({'status':0x193,'message':_0x3f16('0x6b')});}return db[_0x3f16('0x6c')][_0x3f16('0x6a')]({'where':{'id':_0x537fee['query'][_0x3f16('0x6d')]},'raw':!![]})['then'](handleEntityNotFound(_0x162dd4,null));}})[_0x3f16('0x3b')](function(_0x55c39b){if(_0x55c39b){var _0x5191cb=_0x55c39b['ChatOfflineMessageId']!==null;var _0x5ac499=path[_0x3f16('0x6e')](config[_0x3f16('0x6f')],_0x3f16('0x70'));if(_0x5191cb){_0x5ac499=path[_0x3f16('0x6e')](_0x5ac499,_0x3f16('0x71'));}var _0xaec424=path[_0x3f16('0x6e')](_0x5ac499,_0x55c39b[_0x3f16('0x72')]);return _0x162dd4[_0x3f16('0x73')](_0xaec424);}})[_0x3f16('0x1d')](handleError(_0x162dd4,null));};exports[_0x3f16('0x74')]=function(_0x59221a,_0x135a31){var _0x545cc7=null;var _0x4b5ebb=null;var _0x70501=null;if(_0x59221a[_0x3f16('0x48')]['id']){delete _0x59221a[_0x3f16('0x48')]['id'];}if(_0x59221a[_0x3f16('0x48')][_0x3f16('0x75')]){_0x70501=path[_0x3f16('0x6e')](config[_0x3f16('0x6f')],_0x3f16('0x76'),util[_0x3f16('0x77')](_0x3f16('0x78'),Date[_0x3f16('0x79')]()));_0x59221a[_0x3f16('0x48')]['pathTranscript']=_0x70501;}return db[_0x3f16('0x34')]['find']({'where':{'id':_0x59221a[_0x3f16('0x3c')]['id']},'include':[{'model':db['ChatMessage'],'as':'Messages','include':[{'model':db[_0x3f16('0x7a')],'as':_0x3f16('0x7a')}]}]})[_0x3f16('0x3b')](handleEntityNotFound(_0x135a31,null))['then'](saveUpdates(_0x59221a[_0x3f16('0x48')],null))[_0x3f16('0x3b')](function(_0x698381){if(_0x698381){_0x545cc7=_0x698381;return db[_0x3f16('0x4b')]['find']({'where':{'id':_0x545cc7['ChatWebsiteId']}});}})[_0x3f16('0x3b')](function(_0x43fdc2){if(_0x43fdc2){_0x4b5ebb=_0x43fdc2;return db[_0x3f16('0x5e')][_0x3f16('0x46')]({'where':{'id':_0x545cc7[_0x3f16('0x7b')]}});}})[_0x3f16('0x3b')](function(_0x98ad04){if(_0x98ad04){if(_0x70501){var _0x1f308b=null;for(var _0x281285=0x1;_0x281285<_0x545cc7[_0x3f16('0x7c')][_0x3f16('0x43')];++_0x281285){_0x1f308b=_0x545cc7['Messages'][_0x281285];var _0x3ba3e0=_0x1f308b[_0x3f16('0x7d')]?util['format']('%s%d',_0x4b5ebb[_0x3f16('0x7e')],_0x1f308b[_0x3f16('0x7d')]):'System';var _0x38292e=_0x59221a[_0x3f16('0x48')][_0x3f16('0x7f')]||util[_0x3f16('0x77')](_0x3f16('0x80'),_0x3f16('0x81'),_0x1f308b[_0x3f16('0x7b')]);switch(_0x4b5ebb[_0x3f16('0x82')]){case _0x3f16('0x83'):_0x3ba3e0=_0x1f308b[_0x3f16('0x7d')]?util[_0x3f16('0x77')](_0x3f16('0x80'),_0x4b5ebb[_0x3f16('0x7e')],_0x1f308b[_0x3f16('0x7d')]):_0x3f16('0x84');break;case _0x3f16('0x85'):_0x3ba3e0=_0x1f308b[_0x3f16('0x7d')]?_0x1f308b[_0x3f16('0x7a')][_0x3f16('0x86')]||_0x1f308b[_0x3f16('0x7a')]['fullname']:_0x3f16('0x84');break;case _0x3f16('0x87'):_0x3ba3e0=_0x1f308b[_0x3f16('0x7d')]?_0x1f308b['User'][_0x3f16('0x88')]:_0x3f16('0x84');break;default:_0x3ba3e0=_0x1f308b['UserId']?util[_0x3f16('0x77')](_0x3f16('0x80'),_0x4b5ebb['agentAlias'],_0x1f308b[_0x3f16('0x7d')]):'System';}var _0x2ef482=util['format']('[%s]\x20%s:\x20%s\x0a',moment(_0x1f308b['createdAt'])['format'](_0x3f16('0x89')),_0x1f308b['direction']==='in'?_0x38292e:_0x3ba3e0,_0x1f308b[_0x3f16('0x48')]);if(!_0x1f308b[_0x3f16('0x8a')]){fs['appendFileSync'](_0x70501,_0x2ef482);}}return db['MailAccount'][_0x3f16('0x6a')]({'where':{'service':!![]},'include':[{'model':db[_0x3f16('0x8b')],'as':_0x3f16('0x8c'),'raw':!![],'include':[{'model':db[_0x3f16('0x8d')],'as':_0x3f16('0x8d'),'raw':!![]}]}]});}}})[_0x3f16('0x3b')](function(_0x3439e2){if(!_0x3439e2||!_0x3439e2['Smtp']||!_0x59221a['body'])return _0x545cc7;var _0x3c6a09=_0x3439e2[_0x3f16('0x8e')]();return respondWithRpcPromise('SendMail',_0x3f16('0x8f'),{'account':_0x3c6a09,'message':{'from':util[_0x3f16('0x77')](_0x3f16('0x90'),_0x3439e2[_0x3f16('0x2b')],_0x3439e2[_0x3f16('0x51')]||_0x3439e2[_0x3f16('0x8c')]['user']),'to':_0x59221a[_0x3f16('0x48')]['mailTranscript'],'subject':_0x3f16('0x91'),'text':util['format']('Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a',_0x59221a[_0x3f16('0x48')][_0x3f16('0x75')]),'attachments':[{'path':_0x70501}]}})[_0x3f16('0x3b')](function(){return _0x545cc7;})[_0x3f16('0x1d')](function(_0x588e5c){logger[_0x3f16('0x1a')](_0x588e5c);});})[_0x3f16('0x3b')](respondWithStatusCode(_0x135a31,0xc8))[_0x3f16('0x1d')](handleError(_0x135a31,null));};exports[_0x3f16('0x92')]=function(_0x24071b,_0x2ade5e){return db[_0x3f16('0x93')][_0x3f16('0x46')]({'where':{'id':_0x24071b[_0x3f16('0x3c')]['id']}})[_0x3f16('0x3b')](handleEntityNotFound(_0x2ade5e,null))[_0x3f16('0x3b')](function(_0x454930){if(_0x454930){return _0x454930[_0x3f16('0x92')](_0x24071b[_0x3f16('0x48')][_0x3f16('0x94')],_[_0x3f16('0x95')](_0x24071b[_0x3f16('0x48')],[_0x3f16('0x94'),'id'])||{});}})[_0x3f16('0x3b')](respondWithResult(_0x2ade5e,null))[_0x3f16('0x1d')](handleError(_0x2ade5e,null));};exports['getMessages']=function(_0x42d76e,_0xa99d2d){var _0x3a33d6={'raw':![],'where':{}};var _0x4c71d9={};var _0x34e37c={'count':0x0,'rows':[]};return db['ChatInteraction'][_0x3f16('0x6a')]({'where':{'id':_0x42d76e['params']['id']}})[_0x3f16('0x3b')](handleEntityNotFound(_0xa99d2d,null))[_0x3f16('0x3b')](function(_0x3e87fc){if(_0x3e87fc){_0x4c71d9[_0x3f16('0x3d')]=_[_0x3f16('0x3f')](db[_0x3f16('0x93')][_0x3f16('0x3e')]);_0x4c71d9[_0x3f16('0x3a')]=_[_0x3f16('0x3f')](_0x42d76e[_0x3f16('0x3a')]);_0x4c71d9[_0x3f16('0x96')]=_[_0x3f16('0x40')](_0x4c71d9[_0x3f16('0x3d')],_0x4c71d9[_0x3f16('0x3a')]);_0x3a33d6[_0x3f16('0x41')]=_['intersection'](_0x4c71d9[_0x3f16('0x3d')],qs[_0x3f16('0x42')](_0x42d76e[_0x3f16('0x3a')][_0x3f16('0x42')]));_0x3a33d6[_0x3f16('0x41')]=_0x3a33d6['attributes'][_0x3f16('0x43')]?_0x3a33d6[_0x3f16('0x41')]:_0x4c71d9[_0x3f16('0x3d')];if(!_0x42d76e[_0x3f16('0x3a')][_0x3f16('0x97')]('nolimit')){_0x3a33d6[_0x3f16('0x24')]=qs[_0x3f16('0x24')](_0x42d76e[_0x3f16('0x3a')]['limit']);_0x3a33d6['offset']=qs[_0x3f16('0x22')](_0x42d76e[_0x3f16('0x3a')][_0x3f16('0x22')]);}_0x3a33d6['order']=qs['sort'](_0x42d76e[_0x3f16('0x3a')][_0x3f16('0x98')]);_0x3a33d6['where']=qs[_0x3f16('0x96')](_['pick'](_0x42d76e[_0x3f16('0x3a')],_0x4c71d9['filters']));_0x3a33d6['where'][_0x3f16('0x99')]=_0x3e87fc['id'];if(_0x42d76e['query'][_0x3f16('0x9a')]){_0x3a33d6[_0x3f16('0x9b')]=_[_0x3f16('0x2e')](_0x3a33d6[_0x3f16('0x9b')],{'$or':_[_0x3f16('0x33')](_0x3a33d6[_0x3f16('0x41')],function(_0x5e1801){var _0x23033e={};_0x23033e[_0x5e1801]={'$like':'%'+_0x42d76e[_0x3f16('0x3a')][_0x3f16('0x9a')]+'%'};return _0x23033e;})});}if(_0x42d76e[_0x3f16('0x3a')][_0x3f16('0x9c')]){var _0x52d639=_0x42d76e[_0x3f16('0x3a')][_0x3f16('0x9c')]['split'](',');var _0xebdc77={};_0xebdc77[_0x52d639[0x0]]={'$gte':moment(_0x52d639[0x1])[_0x3f16('0x77')](_0x3f16('0x9d'))};_0x3a33d6['where']=_[_0x3f16('0x2e')](_0x3a33d6[_0x3f16('0x9b')],_0xebdc77);}_0x3a33d6=_[_0x3f16('0x2e')]({},_0x3a33d6,_0x42d76e[_0x3f16('0x45')]);return db[_0x3f16('0x93')]['count']({'where':_0x3a33d6[_0x3f16('0x9b')]})[_0x3f16('0x3b')](function(_0x54d5f1){_0x34e37c['count']=_0x54d5f1;if(_0x42d76e[_0x3f16('0x3a')][_0x3f16('0x44')]){_0x3a33d6[_0x3f16('0x9e')]=[{'all':!![]}];}return db['ChatMessage']['findAll'](_0x3a33d6);})[_0x3f16('0x3b')](function(_0x2eb5b1){_0x34e37c[_0x3f16('0x9f')]=_0x2eb5b1;return _0x34e37c;});}})['then'](respondWithFilteredResult(_0xa99d2d,_0x3a33d6))[_0x3f16('0x1d')](handleError(_0xa99d2d,null));};exports['getMyMessages']=function(_0x5e28c3,_0x420a5a){var _0x120148={'where':{}},_0x58a71c={},_0x524be1={'count':0x0,'rows':[]};return db[_0x3f16('0x34')][_0x3f16('0x6a')]({'where':{'id':_0x5e28c3[_0x3f16('0x3c')]['id']}})['then'](handleEntityNotFound(_0x420a5a,null))[_0x3f16('0x3b')](function(_0x513eea){if(_0x513eea){_0x58a71c[_0x3f16('0x3d')]=_['keys'](db['ChatMessage'][_0x3f16('0x3e')]);_0x58a71c[_0x3f16('0x3a')]=_[_0x3f16('0x3f')](_0x5e28c3['query']);_0x58a71c[_0x3f16('0x96')]=_['intersection'](_0x58a71c[_0x3f16('0x3d')],_0x58a71c['query']);_0x120148[_0x3f16('0x41')]=_[_0x3f16('0x40')](_0x58a71c[_0x3f16('0x3d')],qs[_0x3f16('0x42')](_0x5e28c3[_0x3f16('0x3a')][_0x3f16('0x42')]));_0x120148[_0x3f16('0x41')]=_0x120148[_0x3f16('0x41')][_0x3f16('0x43')]?_0x120148[_0x3f16('0x41')]:_0x58a71c[_0x3f16('0x3d')];if(!_0x5e28c3[_0x3f16('0x3a')]['hasOwnProperty'](_0x3f16('0xa0'))){_0x120148[_0x3f16('0x24')]=qs[_0x3f16('0x24')](_0x5e28c3['query']['limit']);_0x120148['offset']=qs[_0x3f16('0x22')](_0x5e28c3[_0x3f16('0x3a')][_0x3f16('0x22')]);}_0x120148['order']=qs[_0x3f16('0x98')](_0x5e28c3[_0x3f16('0x3a')][_0x3f16('0x98')]);_0x120148['where']=qs[_0x3f16('0x96')](_[_0x3f16('0xa1')](_0x5e28c3[_0x3f16('0x3a')],_0x58a71c['filters']));_0x120148['where'][_0x3f16('0x99')]=_0x513eea['id'];if(_0x5e28c3['query'][_0x3f16('0x9a')]){_0x120148[_0x3f16('0x9b')]=_[_0x3f16('0x2e')](_0x120148[_0x3f16('0x9b')],{'$or':_[_0x3f16('0x33')](_0x120148[_0x3f16('0x41')],function(_0x325d66){var _0x2a68d1={};_0x2a68d1[_0x325d66]={'$like':'%'+_0x5e28c3[_0x3f16('0x3a')][_0x3f16('0x9a')]+'%'};return _0x2a68d1;})});}_0x120148[_0x3f16('0x9b')][_0x3f16('0x8a')]=![];if(_0x5e28c3[_0x3f16('0x3a')]['id']){_0x120148[_0x3f16('0x9b')]['id']={'$gt':_0x5e28c3['query']['id']};}_0x120148=_['merge']({},_0x120148,_0x5e28c3[_0x3f16('0x45')]);return db[_0x3f16('0x93')][_0x3f16('0x25')]({'where':_0x120148[_0x3f16('0x9b')]})[_0x3f16('0x3b')](function(_0x2af2b4){_0x524be1[_0x3f16('0x25')]=_0x2af2b4;_0x120148[_0x3f16('0x9e')]=[];if(_0x5e28c3['query'][_0x3f16('0xa2')]){_0x120148[_0x3f16('0x9e')][_0x3f16('0xa3')]({'model':db[_0x3f16('0x7a')],'as':'User','attributes':['id','fullname',_0x3f16('0x86')]});}if(_0x5e28c3['query'][_0x3f16('0x44')]){_0x120148['include']=[{'all':!![]}];}return db['ChatMessage'][_0x3f16('0x38')](_0x120148);})[_0x3f16('0x3b')](function(_0x5ada33){_0x524be1['rows']=_0x5ada33;return _0x524be1;});}})[_0x3f16('0x3b')](respondWithFilteredResult(_0x420a5a,_0x120148))[_0x3f16('0x1d')](handleError(_0x420a5a,null));};exports[_0x3f16('0xa4')]=function(_0x2d1313,_0x5036eb){return db[_0x3f16('0x34')]['find']({'where':{'id':_0x2d1313[_0x3f16('0x3c')]['id']}})[_0x3f16('0x3b')](handleEntityNotFound(_0x5036eb,null))[_0x3f16('0x3b')](function(_0x333055){if(_0x333055){return _0x333055[_0x3f16('0xa5')](_0x2d1313['body']['ids'],_['omit'](_0x2d1313[_0x3f16('0x48')],['ids','id'])||{})['spread'](function(){return db[_0x3f16('0xa6')][_0x3f16('0x38')]({'attributes':['id',_0x3f16('0x2b'),'color'],'where':{'id':_0x2d1313['body'][_0x3f16('0x94')]}});})[_0x3f16('0x3b')](function(_0x32abd3){socket[_0x3f16('0xa7')](_0x3f16('0xa8'),{'id':Number(_0x2d1313['params']['id']),'tags':_0x32abd3||[]});return{'id':Number(_0x2d1313[_0x3f16('0x3c')]['id']),'tags':_0x32abd3||[]};});}})[_0x3f16('0x3b')](respondWithResult(_0x5036eb,null))[_0x3f16('0x1d')](handleError(_0x5036eb,null));};exports[_0x3f16('0xa9')]=function(_0x4bf03a,_0x14b10a){return db[_0x3f16('0x34')][_0x3f16('0x46')]({'where':{'id':_0x4bf03a[_0x3f16('0x3c')]['id']}})[_0x3f16('0x3b')](handleEntityNotFound(_0x14b10a,null))[_0x3f16('0x3b')](function(_0x4f7df3){if(_0x4f7df3){return _0x4f7df3['removeTags'](_0x4bf03a['query'][_0x3f16('0x94')]);}})['then'](respondWithStatusCode(_0x14b10a,null))[_0x3f16('0x1d')](handleError(_0x14b10a,null));};exports['download']=function(_0x490b16,_0x556ff6){var _0x124d7a=moment()[_0x3f16('0xaa')]()[_0x3f16('0xab')]();var _0x47e930=path[_0x3f16('0x6e')](config['root'],_0x3f16('0xac'),_0x3f16('0xad'),_0x3f16('0xae'));var _0x2d6d6c=path[_0x3f16('0x6e')](config[_0x3f16('0x6f')],_0x3f16('0xac'),_0x3f16('0xad'),'attachments');var _0x3f6a12=path[_0x3f16('0x6e')](_0x47e930,_0x124d7a);var _0x25aa11=util[_0x3f16('0x77')]('transcript-%d-%s.zip',_0x490b16[_0x3f16('0x3c')]['id'],_0x124d7a);var _0x3ddb46=path[_0x3f16('0x6e')](_0x47e930,_0x25aa11);var _0x3861a5=[];_0x3861a5[_0x3f16('0xa3')]({'model':db['User'],'as':_0x3f16('0x7a'),'attributes':['id','fullname'],'raw':!![]});_0x3861a5[_0x3f16('0xa3')]({'model':db[_0x3f16('0x5e')],'as':_0x3f16('0x5f'),'attributes':['id',_0x3f16('0xaf'),'lastName'],'raw':!![]});if(_0x490b16['query'][_0x3f16('0xb0')]){_0x3861a5[_0x3f16('0xa3')]({'model':db[_0x3f16('0x6c')],'as':_0x3f16('0x6c'),'raw':!![]});}var _0x3d2597=[{'model':db[_0x3f16('0x93')],'as':'Messages','attributes':['id','body',_0x3f16('0xb1'),_0x3f16('0xb2'),_0x3f16('0x8a'),'read'],'include':_0x3861a5}];_0x3d2597[_0x3f16('0xa3')]({'model':db[_0x3f16('0x4b')],'as':'Account','attributes':['id',_0x3f16('0x2b')]});_0x3d2597[_0x3f16('0xa3')]({'model':db[_0x3f16('0x7a')],'as':_0x3f16('0xb3'),'attributes':['id',_0x3f16('0x88')]});return db[_0x3f16('0x34')][_0x3f16('0x46')]({'where':{'id':_0x490b16[_0x3f16('0x3c')]['id']},'include':_0x3d2597})[_0x3f16('0x3b')](handleEntityNotFound(_0x556ff6,null))['then'](function(_0x3e93bb){if(_0x3e93bb){var _0x3862d3=_0x3e93bb[_0x3f16('0xb4')]({'plain':!![]});fs[_0x3f16('0xb5')](_0x3f6a12);var _0x59e64b={'channel':_0x3f16('0xb6'),'account':_0x3862d3['Account']['name'],'agent':_0x3862d3[_0x3f16('0xb3')]?_0x3862d3[_0x3f16('0xb3')][_0x3f16('0x88')]:_0x3f16('0xb7'),'createdAt':moment(_0x3862d3[_0x3f16('0xb1')])[_0x3f16('0x77')]('YYYY-MM-DD\x20HH:mm:ss')['toString'](),'closedAt':_0x3862d3[_0x3f16('0x63')]?moment(_0x3862d3['closedAt'])[_0x3f16('0x77')](_0x3f16('0x9d'))[_0x3f16('0xab')]():'','disposition':_0x3862d3['disposition'],'chatInfo':{'browser':_0x3862d3[_0x3f16('0xb8')],'os':_0x3862d3['osName'],'referer':_0x3862d3[_0x3f16('0xb9')],'customerIp':_0x3862d3[_0x3f16('0xba')],'customerPort':_0x3862d3[_0x3f16('0xbb')]?_0x3862d3[_0x3f16('0xbb')]:_0x3f16('0xb7')},'messages':_(_0x3862d3[_0x3f16('0x7c')])['tail']()[_0x3f16('0x9a')]({'secret':![]})[_0x3f16('0x33')](function(_0x325dce){if(_0x325dce[_0x3f16('0x6c')]){var _0x39906c=path['join'](_0x2d6d6c,_0x325dce[_0x3f16('0x6c')][_0x3f16('0x72')]);if(fs['existsSync'](_0x39906c)){fs[_0x3f16('0xbc')](_0x39906c)['pipe'](fs['createWriteStream'](path[_0x3f16('0x6e')](_0x3f6a12,_0x325dce['Attachment'][_0x3f16('0x72')])));}}return{'date':moment(_0x325dce['createdAt'])[_0x3f16('0x77')](_0x3f16('0x9d'))[_0x3f16('0xab')](),'sender':_0x325dce[_0x3f16('0xb2')]===_0x3f16('0xbd')?_0x325dce[_0x3f16('0x7a')]?_0x325dce[_0x3f16('0x7a')][_0x3f16('0x88')]:_0x3f16('0x84'):_0x325dce[_0x3f16('0x5f')]['firstName']+(_0x325dce[_0x3f16('0x5f')]['lastName']?'\x20'+_0x325dce[_0x3f16('0x5f')][_0x3f16('0xbe')]:''),'body':_0x325dce[_0x3f16('0x6c')]?_0x325dce[_0x3f16('0x6c')][_0x3f16('0x72')]:_0x325dce[_0x3f16('0x48')],'direction':_0x325dce[_0x3f16('0xb2')]===_0x3f16('0xbd')?'A':'C','secret':_0x325dce[_0x3f16('0x8a')],'read':_0x325dce[_0x3f16('0xbf')],'attachment':_0x325dce[_0x3f16('0x6c')]};})['value']()};return ejs[_0x3f16('0xc0')](path[_0x3f16('0x6e')](config[_0x3f16('0x6f')],_0x3f16('0xac'),_0x3f16('0xc1'),_0x3f16('0xc2')),{'interaction':_0x59e64b})[_0x3f16('0x3b')](function(_0x1e2765){var _0x43e508=path['join'](_0x3f6a12,'transcript-'+_0x3862d3['id']+'-'+_0x124d7a+'.pdf');var _0xa17db3={'path':_0x43e508,'channel':'Chat','interactionId':_0x3862d3['id']};return pdf[_0x3f16('0xc3')](_0x1e2765,_0xa17db3);})[_0x3f16('0x3b')](function(){return new Promise(function(_0x55f6a7,_0x468917){zipdir(_0x3f6a12,{'saveTo':_0x3ddb46},function(_0x3365bb,_0x57878e){if(_0x3365bb)return _0x468917(_0x3365bb);return _0x55f6a7(_0x57878e);});})[_0x3f16('0x3b')](function(){return new BPromise(function(_0x4f8376,_0x51dc9c){rimraf(_0x3f6a12,function(_0x3ac378){if(_0x3ac378)_0x51dc9c(_0x3ac378);return _0x4f8376();});});})[_0x3f16('0x3b')](function(){return _0x556ff6[_0x3f16('0x73')](_0x3ddb46,_0x25aa11,function(_0xa0a84a){if(_0xa0a84a){logger['error'](_0x3f16('0xc4'),_0xa0a84a);}else{fs[_0x3f16('0xc5')](_0x3ddb46);}});});});}else{return _0x556ff6[_0x3f16('0x1e')](0xc8);}})[_0x3f16('0x1d')](handleError(_0x556ff6,null));};
\ No newline at end of file