Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / chatInteraction / chatInteraction.controller.js
index fccfc1c..4a3ae06 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x447e=['Error\x20in\x20conversion\x20vidaooMetadata','Error\x20in\x20Vidaoo\x20configuration','join_url','out','ChatMessage','Unable\x20to\x20create\x20Vidaoo\x20session','updateAttributes','customUpdate','abandon','abandonInteraction,\x20%s,\x20%s,\x20%s','entity\x20not\x20found','closed','disposition','AbandonInteraction','attachmentUpload','originalname','basename','file','type','mimetype','attachmentDownload','findOne','Unauthorized','Attachment','attachId','ChatOfflineMessageId','join','server/files/attachments/','offline-chat/','download','close','mailTranscript','root','server/files/chat/upload/','transcript-%s.txt','pathTranscript','User','CmContact','ContactId','Messages','format','%s%d','agentAlias','UserId','customer','Visitor','agentIdentifier','website_alias','System','alias','fullname','createdAt','MM/DD/YYYY\x20HH:mm:ss','direction','secret','MailAccount','MailServerOut','Smtp','CloudProvider','getSmtpOptions','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','getMessages','hasOwnProperty','nolimit','order','sort','where','pick','ChatInteractionId','filter','$gte','split','rows','includeAgent','push','addTags','setTags','Tag','removeTags','toString','server','files','tmp','transcript-%d-%s.zip','Contact','firstName','attachments','read','Account','Owner','Chat','N.A.','YYYY-MM-DD\x20HH:mm:ss','closedAt','browserName','osName','referer','customerPort','tail','existsSync','createReadStream','createWriteStream','lastName','renderFile','views','downloadInteraction.ejs','transcript-','.pdf','createPdfFromHTML','err','unlinkSync','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','ejs','lodash','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./chatInteraction.socket','register','jayson/promise','client','http','request','then','info','ChatInteraction,\x20%s,\x20%s','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','message','result','catch','sendStatus','end','status','json','offset','undefined','limit','count','Content-Range','update','destroy','stack','name','send','render','merge','body','contact','agent','interaction','account','map','ChatInteraction','rawAttributes','fieldName','key','getOptions','findAll','chat','query','user','params','model','keys','filters','attributes','intersection','fields','length','includeAll','include','options','find','create','createVidaooSession','ChatWebsite','ChatWebsiteId','vidaooApiKey','vidaooEscalation','vidaooMetadata','email','https://api-vidaoo.xcally.com/api/v1/meetings','vidaooTopic','isNull','vidaooNote','follow','parse','metadata','Sequelize','ValidationError'];(function(_0x59ee6f,_0x450239){var _0x4c0979=function(_0x565e92){while(--_0x565e92){_0x59ee6f['push'](_0x59ee6f['shift']());}};_0x4c0979(++_0x450239);}(_0x447e,0x75));var _0xe447=function(_0x40b434,_0x1b71d8){_0x40b434=_0x40b434-0x0;var _0xbccbcc=_0x447e[_0x40b434];return _0xbccbcc;};'use strict';var rimraf=require(_0xe447('0x0'));var zipdir=require(_0xe447('0x1'));var rp=require(_0xe447('0x2'));var moment=require(_0xe447('0x3'));var BPromise=require(_0xe447('0x4'));var Mustache=require(_0xe447('0x5'));var util=require(_0xe447('0x6'));var path=require('path');var ejs=require(_0xe447('0x7'));var fs=require('fs');var _=require(_0xe447('0x8'));var Redis=require('ioredis');var interaction=require(_0xe447('0x9'));var qs=require(_0xe447('0xa'));var pdf=require(_0xe447('0xb'));var logger=require(_0xe447('0xc'))(_0xe447('0xd'));var config=require(_0xe447('0xe'));var db=require(_0xe447('0xf'))['db'];config[_0xe447('0x10')]=_[_0xe447('0x11')](config['redis'],{'host':_0xe447('0x12'),'port':0x18eb});var socket=require(_0xe447('0x13'))(new Redis(config[_0xe447('0x10')]));require(_0xe447('0x14'))[_0xe447('0x15')](socket);var jayson=require(_0xe447('0x16'));var client=jayson[_0xe447('0x17')][_0xe447('0x18')]({'port':0x232b});var client9004=jayson[_0xe447('0x17')]['http']({'port':0x232c});function respondWithRpcPromise(_0x498072,_0xf22741,_0x2a5383,_0x57ae3b){return new BPromise(function(_0x32f3ba,_0x14c77e){var _0x2f120e=_0x57ae3b||client;return _0x2f120e[_0xe447('0x19')](_0x498072,_0x2a5383)[_0xe447('0x1a')](function(_0x619e84){logger[_0xe447('0x1b')](_0xe447('0x1c'),_0xf22741,'request\x20sent');logger[_0xe447('0x1d')](_0xe447('0x1e'),_0xf22741,_0xe447('0x1f'),JSON[_0xe447('0x20')](_0x619e84));if(_0x619e84[_0xe447('0x21')]){if(_0x619e84[_0xe447('0x21')]['code']===0x1f4){logger['error'](_0xe447('0x1c'),_0xf22741,_0x619e84['error'][_0xe447('0x22')]);return _0x14c77e(_0x619e84[_0xe447('0x21')][_0xe447('0x22')]);}logger[_0xe447('0x21')](_0xe447('0x1c'),_0xf22741,_0x619e84[_0xe447('0x21')][_0xe447('0x22')]);return _0x32f3ba(_0x619e84[_0xe447('0x21')][_0xe447('0x22')]);}else{logger[_0xe447('0x1b')](_0xe447('0x1c'),_0xf22741,'request\x20sent');_0x32f3ba(_0x619e84[_0xe447('0x23')][_0xe447('0x22')]);}})[_0xe447('0x24')](function(_0x32c182){logger[_0xe447('0x21')](_0xe447('0x1c'),_0xf22741,_0x32c182);_0x14c77e(_0x32c182);});});}function respondWithStatusCode(_0x4fad17,_0x2ebd12){_0x2ebd12=_0x2ebd12||0xcc;return function(_0x9d499c){if(_0x9d499c){return _0x4fad17[_0xe447('0x25')](_0x2ebd12);}return _0x4fad17['status'](_0x2ebd12)[_0xe447('0x26')]();};}function respondWithResult(_0x54439e,_0x395a1a){_0x395a1a=_0x395a1a||0xc8;return function(_0x463fb2){if(_0x463fb2){return _0x54439e[_0xe447('0x27')](_0x395a1a)[_0xe447('0x28')](_0x463fb2);}};}function respondWithFilteredResult(_0x212ab7,_0xdaf354){return function(_0x1281fa){if(_0x1281fa){var _0x3d9f1f=typeof _0xdaf354[_0xe447('0x29')]===_0xe447('0x2a')&&typeof _0xdaf354[_0xe447('0x2b')]===_0xe447('0x2a');var _0x34019b=_0x1281fa[_0xe447('0x2c')];var _0x31deb1=_0x3d9f1f?0x0:_0xdaf354[_0xe447('0x29')];var _0x572b75=_0x3d9f1f?_0x1281fa[_0xe447('0x2c')]:_0xdaf354[_0xe447('0x29')]+_0xdaf354['limit'];var _0x5e1c15;if(_0x572b75>=_0x34019b){_0x572b75=_0x34019b;_0x5e1c15=0xc8;}else{_0x5e1c15=0xce;}_0x212ab7[_0xe447('0x27')](_0x5e1c15);return _0x212ab7['set'](_0xe447('0x2d'),_0x31deb1+'-'+_0x572b75+'/'+_0x34019b)[_0xe447('0x28')](_0x1281fa);}return null;};}function saveUpdates(_0x9d5f9f){return function(_0x2ea3d2){if(_0x2ea3d2){return _0x2ea3d2[_0xe447('0x2e')](_0x9d5f9f)[_0xe447('0x1a')](function(_0x1e52dd){return _0x1e52dd;});}return null;};}function removeEntity(_0x1dda62){return function(_0x3f2bd8){if(_0x3f2bd8){return _0x3f2bd8[_0xe447('0x2f')]()['then'](function(){_0x1dda62[_0xe447('0x27')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1984bd){return function(_0x15568c){if(!_0x15568c){_0x1984bd[_0xe447('0x25')](0x194);}return _0x15568c;};}function handleError(_0x5e15a7,_0xe2d068){_0xe2d068=_0xe2d068||0x1f4;return function(_0x11c2e){logger[_0xe447('0x21')](_0x11c2e[_0xe447('0x30')]);if(_0x11c2e[_0xe447('0x31')]){delete _0x11c2e[_0xe447('0x31')];}_0x5e15a7[_0xe447('0x27')](_0xe2d068)[_0xe447('0x32')](_0x11c2e);};}function getMustacheRender(_0x3fd972,_0x46d588){return Mustache[_0xe447('0x33')](_0x3fd972,_[_0xe447('0x34')](_0x46d588[_0xe447('0x35')],{'contact':_0x46d588[_0xe447('0x36')],'message':_0x46d588[_0xe447('0x22')],'agent':_0x46d588[_0xe447('0x37')],'interaction':_0x46d588[_0xe447('0x38')],'account':_0x46d588[_0xe447('0x39')]}))||'';}exports['index']=function(_0x44e55b,_0x4cc3a2){var _0x5ce1b1={};var _0x505dde=_[_0xe447('0x3a')](db[_0xe447('0x3b')][_0xe447('0x3c')],function(_0x54bb40){return{'name':_0x54bb40[_0xe447('0x3d')],'type':_0x54bb40['type'][_0xe447('0x3e')]};});_0x5ce1b1=qs[_0xe447('0x3f')](_0x505dde,_0x44e55b);return interaction[_0xe447('0x40')](_0xe447('0x41'),_0x44e55b[_0xe447('0x42')],_0x44e55b[_0xe447('0x43')],_0x5ce1b1,_0x505dde)[_0xe447('0x1a')](respondWithFilteredResult(_0x4cc3a2,_0x5ce1b1))[_0xe447('0x24')](handleError(_0x4cc3a2,null));};exports['show']=function(_0x506530,_0x16f5f1){var _0x1e2577={'raw':![],'where':{'id':_0x506530[_0xe447('0x44')]['id']}},_0x78829e={};_0x78829e[_0xe447('0x45')]=_[_0xe447('0x46')](db['ChatInteraction'][_0xe447('0x3c')]);_0x78829e[_0xe447('0x42')]=_[_0xe447('0x46')](_0x506530[_0xe447('0x42')]);_0x78829e[_0xe447('0x47')]=_['intersection'](_0x78829e[_0xe447('0x45')],_0x78829e[_0xe447('0x42')]);_0x1e2577[_0xe447('0x48')]=_[_0xe447('0x49')](_0x78829e['model'],qs[_0xe447('0x4a')](_0x506530['query']['fields']));_0x1e2577['attributes']=_0x1e2577[_0xe447('0x48')][_0xe447('0x4b')]?_0x1e2577[_0xe447('0x48')]:_0x78829e[_0xe447('0x45')];if(_0x506530[_0xe447('0x42')][_0xe447('0x4c')]){_0x1e2577[_0xe447('0x4d')]=[{'all':!![]}];}_0x1e2577=_[_0xe447('0x34')]({},_0x1e2577,_0x506530[_0xe447('0x4e')]);return db['ChatInteraction'][_0xe447('0x4f')](_0x1e2577)[_0xe447('0x1a')](handleEntityNotFound(_0x16f5f1,null))[_0xe447('0x1a')](respondWithResult(_0x16f5f1,null))['catch'](handleError(_0x16f5f1,null));};exports[_0xe447('0x50')]=function(_0x265f52,_0x38c725){return db[_0xe447('0x3b')][_0xe447('0x50')](_0x265f52[_0xe447('0x35')],{})[_0xe447('0x1a')](respondWithResult(_0x38c725,0xc9))[_0xe447('0x24')](handleError(_0x38c725,null));};exports[_0xe447('0x2e')]=function(_0x39b2f0,_0x11f2a2){if(_0x39b2f0[_0xe447('0x35')]['id']){delete _0x39b2f0[_0xe447('0x35')]['id'];}return db['ChatInteraction'][_0xe447('0x4f')]({'where':{'id':_0x39b2f0[_0xe447('0x44')]['id']}})[_0xe447('0x1a')](handleEntityNotFound(_0x11f2a2,null))[_0xe447('0x1a')](saveUpdates(_0x39b2f0[_0xe447('0x35')],null))[_0xe447('0x1a')](respondWithResult(_0x11f2a2,null))[_0xe447('0x24')](handleError(_0x11f2a2,null));};exports[_0xe447('0x2f')]=function(_0x815bbe,_0x21dea4){return db[_0xe447('0x3b')][_0xe447('0x4f')]({'where':{'id':_0x815bbe[_0xe447('0x44')]['id']}})[_0xe447('0x1a')](handleEntityNotFound(_0x21dea4,null))[_0xe447('0x1a')](removeEntity(_0x21dea4,null))[_0xe447('0x24')](handleError(_0x21dea4,null));};exports['describe']=function(_0x55be9b,_0x7314a5){return db[_0xe447('0x3b')]['describe']()[_0xe447('0x1a')](respondWithResult(_0x7314a5,null))[_0xe447('0x24')](handleError(_0x7314a5,null));};exports[_0xe447('0x51')]=function(_0x57d327,_0x289a65){var _0x5e96e2=_0x57d327['params']['id'];var _0x1af8b0;var _0x170d70;var _0x41d810;return db[_0xe447('0x3b')]['findOne']({'where':{'id':_0x5e96e2}})[_0xe447('0x1a')](function(_0x5e4804){_0x1af8b0=_0x5e4804;return db[_0xe447('0x52')]['findOne']({'where':{'id':_0x5e4804[_0xe447('0x53')]},'attributes':['id',_0xe447('0x54'),_0xe447('0x55'),'vidaooTopic','vidaooNote',_0xe447('0x56')],'raw':!![]});})[_0xe447('0x1a')](function(_0x4f919f){if(_0x4f919f&&_0x4f919f[_0xe447('0x54')]&&_0x4f919f['vidaooEscalation']){_0x170d70=_0x4f919f;var _0x138e28={'interaction':{'id':_0x5e96e2},'agent':{'id':_0x57d327[_0xe447('0x43')]['id'],'name':_0x57d327[_0xe447('0x43')][_0xe447('0x31')],'fullname':_0x57d327[_0xe447('0x43')]['fullname'],'email':_0x57d327[_0xe447('0x43')][_0xe447('0x57')]},'contact':_0x57d327[_0xe447('0x35')][_0xe447('0x36')],'account':_0x57d327[_0xe447('0x35')]['account']};var _0x460cd2={'rejectUnauthorized':![],'method':'POST','url':_0xe447('0x58'),'headers':{'X-APIKEY':_0x4f919f[_0xe447('0x54')]},'body':{'duration':null,'scheduledAt':null,'participants':[_0x57d327[_0xe447('0x43')]['email']],'buttons':null,'topic':_0x170d70[_0xe447('0x59')],'note':_[_0xe447('0x5a')](_0x170d70[_0xe447('0x5b')])?null:getMustacheRender(_0x170d70[_0xe447('0x5b')],_0x138e28),'metadata':null},'redirect':_0xe447('0x5c'),'json':!![]};try{if(!_[_0xe447('0x5a')](_0x170d70['vidaooMetadata'])){var _0x4d3b89=getMustacheRender(_0x170d70[_0xe447('0x56')],_0x138e28);var _0x4d10b6=JSON[_0xe447('0x5d')](_0x4d3b89);_0x460cd2['body'][_0xe447('0x5e')]=_0x4d10b6;}}catch(_0x47256f){throw new db[(_0xe447('0x5f'))][(_0xe447('0x60'))](_0xe447('0x61'));}return rp(_0x460cd2);}else{throw new db[(_0xe447('0x5f'))][(_0xe447('0x60'))](_0xe447('0x62'));}})['then'](function(_0x4908e6){_0x41d810=_0x4908e6;if(_0x41d810['id']){var _0x18a719={'body':_0x41d810[_0xe447('0x63')],'ChatWebsiteId':_0x170d70['id'],'ChatInteractionId':_0x1af8b0['id'],'direction':_0xe447('0x64'),'UserId':_0x57d327[_0xe447('0x43')]['id']};return db[_0xe447('0x65')]['create'](_0x18a719,{});}else{throw new db[(_0xe447('0x5f'))][(_0xe447('0x60'))](_0xe447('0x66'));}})[_0xe447('0x1a')](function(){return _0x1af8b0[_0xe447('0x67')]({'vidaooSessionId':_0x41d810['id']});})[_0xe447('0x1a')](respondWithResult(_0x289a65,null))['catch'](handleError(_0x289a65,null));};exports[_0xe447('0x68')]=function(_0x3affa2,_0x1c2fad){if(_0x3affa2[_0xe447('0x35')]['id']){delete _0x3affa2[_0xe447('0x35')]['id'];}return db[_0xe447('0x3b')]['find']({'where':{'id':_0x3affa2[_0xe447('0x44')]['id']},'include':[{'model':db['CmContact'],'as':'Contact'}]})[_0xe447('0x1a')](handleEntityNotFound(_0x1c2fad,null))[_0xe447('0x1a')](saveUpdates(_0x3affa2['body'],null))[_0xe447('0x1a')](respondWithResult(_0x1c2fad,null))[_0xe447('0x24')](handleError(_0x1c2fad,null));};exports[_0xe447('0x69')]=function(_0x3ec99c,_0x2964e6){if(_0x3ec99c[_0xe447('0x35')]['id']){delete _0x3ec99c[_0xe447('0x35')]['id'];}return db['ChatInteraction'][_0xe447('0x4f')]({'where':{'id':_0x3ec99c[_0xe447('0x44')]['id']}})[_0xe447('0x1a')](function(_0xb082ea){if(!_0xb082ea){logger[_0xe447('0x21')](_0xe447('0x6a'),_0xe447('0x69'),0x194,_0xe447('0x6b'));_0x2964e6['sendStatus'](0x194);}else{if(_0xb082ea['UserId']){throw new db[(_0xe447('0x5f'))][(_0xe447('0x60'))]('Interaction\x20already\x20assigned');}}return _0xb082ea;})[_0xe447('0x1a')](function(_0x1c4224){if(_0x1c4224){return _0x1c4224[_0xe447('0x2e')]({'closed':_0x3ec99c[_0xe447('0x35')][_0xe447('0x6c')],'disposition':_0x3ec99c[_0xe447('0x35')][_0xe447('0x6d')]})['then'](function(_0x5711b1){return _0x5711b1;});}})['then'](function(){return respondWithRpcPromise(_0xe447('0x6e'),'abandon',_0x3ec99c['body'],client9004);})[_0xe447('0x1a')](respondWithResult(_0x2964e6,null))[_0xe447('0x24')](handleError(_0x2964e6,null));};exports[_0xe447('0x6f')]=function(_0x1dd4a1,_0xe3095b){_0x1dd4a1[_0xe447('0x35')][_0xe447('0x31')]=_0x1dd4a1['file'][_0xe447('0x70')];_0x1dd4a1[_0xe447('0x35')][_0xe447('0x71')]=_0x1dd4a1[_0xe447('0x72')]['filename'];_0x1dd4a1[_0xe447('0x35')][_0xe447('0x73')]=_0x1dd4a1[_0xe447('0x72')][_0xe447('0x74')];return db['Attachment'][_0xe447('0x50')](_0x1dd4a1[_0xe447('0x35')])[_0xe447('0x1a')](respondWithResult(_0xe3095b,0xc9))[_0xe447('0x24')](handleError(_0xe3095b,null));};exports[_0xe447('0x75')]=function(_0xd56a0,_0x2fa340){return db[_0xe447('0x3b')][_0xe447('0x76')]({'where':{'id':_0xd56a0[_0xe447('0x44')]['id']},'raw':!![]})[_0xe447('0x1a')](handleEntityNotFound(_0x2fa340,null))[_0xe447('0x1a')](function(_0x21ee05){if(_0x21ee05){if(_0x21ee05['closed']){return _0x2fa340[_0xe447('0x27')](0x193)['json']({'status':0x193,'message':_0xe447('0x77')});}return db[_0xe447('0x78')][_0xe447('0x76')]({'where':{'id':_0xd56a0[_0xe447('0x42')][_0xe447('0x79')]},'raw':!![]})[_0xe447('0x1a')](handleEntityNotFound(_0x2fa340,null));}})[_0xe447('0x1a')](function(_0x23e649){if(_0x23e649){var _0x2daa1e=_0x23e649[_0xe447('0x7a')]!==null;var _0x596e11=path[_0xe447('0x7b')](config['root'],_0xe447('0x7c'));if(_0x2daa1e){_0x596e11=path[_0xe447('0x7b')](_0x596e11,_0xe447('0x7d'));}var _0x363314=path['join'](_0x596e11,_0x23e649['basename']);return _0x2fa340[_0xe447('0x7e')](_0x363314);}})[_0xe447('0x24')](handleError(_0x2fa340,null));};exports[_0xe447('0x7f')]=function(_0x126bcb,_0xf1ad6e){var _0x105e04=null;var _0x117176=null;var _0x34e426=null;if(_0x126bcb[_0xe447('0x35')]['id']){delete _0x126bcb['body']['id'];}if(_0x126bcb[_0xe447('0x35')][_0xe447('0x80')]){_0x34e426=path['join'](config[_0xe447('0x81')],_0xe447('0x82'),util['format'](_0xe447('0x83'),Date['now']()));_0x126bcb['body'][_0xe447('0x84')]=_0x34e426;}return db[_0xe447('0x3b')][_0xe447('0x4f')]({'where':{'id':_0x126bcb[_0xe447('0x44')]['id']},'include':[{'model':db[_0xe447('0x65')],'as':'Messages','include':[{'model':db['User'],'as':_0xe447('0x85')}]}]})['then'](handleEntityNotFound(_0xf1ad6e,null))[_0xe447('0x1a')](saveUpdates(_0x126bcb['body'],null))[_0xe447('0x1a')](function(_0x53670e){if(_0x53670e){_0x105e04=_0x53670e;return db[_0xe447('0x52')][_0xe447('0x4f')]({'where':{'id':_0x105e04[_0xe447('0x53')]}});}})[_0xe447('0x1a')](function(_0x24a92e){if(_0x24a92e){_0x117176=_0x24a92e;return db[_0xe447('0x86')][_0xe447('0x4f')]({'where':{'id':_0x105e04[_0xe447('0x87')]}});}})[_0xe447('0x1a')](function(_0x166a8c){if(_0x166a8c){if(_0x34e426){var _0x1f8a1f=null;for(var _0x972d28=0x1;_0x972d28<_0x105e04['Messages'][_0xe447('0x4b')];++_0x972d28){_0x1f8a1f=_0x105e04[_0xe447('0x88')][_0x972d28];var _0x22f395=_0x1f8a1f['UserId']?util[_0xe447('0x89')](_0xe447('0x8a'),_0x117176[_0xe447('0x8b')],_0x1f8a1f[_0xe447('0x8c')]):'System';var _0x3bd527=_0x126bcb[_0xe447('0x35')][_0xe447('0x8d')]||util[_0xe447('0x89')](_0xe447('0x8a'),_0xe447('0x8e'),_0x1f8a1f[_0xe447('0x87')]);switch(_0x117176[_0xe447('0x8f')]){case _0xe447('0x90'):_0x22f395=_0x1f8a1f[_0xe447('0x8c')]?util[_0xe447('0x89')](_0xe447('0x8a'),_0x117176[_0xe447('0x8b')],_0x1f8a1f[_0xe447('0x8c')]):_0xe447('0x91');break;case'agent_alias':_0x22f395=_0x1f8a1f['UserId']?_0x1f8a1f[_0xe447('0x85')][_0xe447('0x92')]||_0x1f8a1f['User'][_0xe447('0x93')]:'System';break;case'agent_fullname':_0x22f395=_0x1f8a1f[_0xe447('0x8c')]?_0x1f8a1f[_0xe447('0x85')]['fullname']:_0xe447('0x91');break;default:_0x22f395=_0x1f8a1f[_0xe447('0x8c')]?util['format'](_0xe447('0x8a'),_0x117176[_0xe447('0x8b')],_0x1f8a1f['UserId']):'System';}var _0x364c85=util['format']('[%s]\x20%s:\x20%s\x0a',moment(_0x1f8a1f[_0xe447('0x94')])[_0xe447('0x89')](_0xe447('0x95')),_0x1f8a1f[_0xe447('0x96')]==='in'?_0x3bd527:_0x22f395,_0x1f8a1f[_0xe447('0x35')]);if(!_0x1f8a1f[_0xe447('0x97')]){fs['appendFileSync'](_0x34e426,_0x364c85);}}return db[_0xe447('0x98')][_0xe447('0x76')]({'where':{'service':!![]},'include':[{'model':db[_0xe447('0x99')],'as':_0xe447('0x9a'),'raw':!![],'include':[{'model':db[_0xe447('0x9b')],'as':_0xe447('0x9b'),'raw':!![]}]}]});}}})['then'](function(_0x4d1c8c){if(!_0x4d1c8c||!_0x4d1c8c[_0xe447('0x9a')]||!_0x126bcb[_0xe447('0x35')])return _0x105e04;var _0xb69fbc=_0x4d1c8c[_0xe447('0x9c')]();return respondWithRpcPromise('SendMail',_0xe447('0x9d'),{'account':_0xb69fbc,'message':{'from':util[_0xe447('0x89')](_0xe447('0x9e'),_0x4d1c8c['name'],_0x4d1c8c[_0xe447('0x57')]||_0x4d1c8c['Smtp'][_0xe447('0x43')]),'to':_0x126bcb['body'][_0xe447('0x80')],'subject':_0xe447('0x9f'),'text':util[_0xe447('0x89')](_0xe447('0xa0'),_0x126bcb[_0xe447('0x35')][_0xe447('0x80')]),'attachments':[{'path':_0x34e426}]}})[_0xe447('0x1a')](function(){return _0x105e04;})[_0xe447('0x24')](function(_0x2f0158){logger[_0xe447('0x21')](_0x2f0158);});})[_0xe447('0x1a')](respondWithStatusCode(_0xf1ad6e,0xc8))[_0xe447('0x24')](handleError(_0xf1ad6e,null));};exports[_0xe447('0xa1')]=function(_0x2d962b,_0x26f99c){return db[_0xe447('0x65')]['find']({'where':{'id':_0x2d962b[_0xe447('0x44')]['id']}})[_0xe447('0x1a')](handleEntityNotFound(_0x26f99c,null))[_0xe447('0x1a')](function(_0x689e93){if(_0x689e93){return _0x689e93[_0xe447('0xa1')](_0x2d962b[_0xe447('0x35')][_0xe447('0xa2')],_[_0xe447('0xa3')](_0x2d962b[_0xe447('0x35')],[_0xe447('0xa2'),'id'])||{});}})[_0xe447('0x1a')](respondWithResult(_0x26f99c,null))[_0xe447('0x24')](handleError(_0x26f99c,null));};exports[_0xe447('0xa4')]=function(_0x808e5e,_0x2e3f77){var _0x5cf7ba={'raw':![],'where':{}};var _0x3c1d05={};var _0x22928b={'count':0x0,'rows':[]};return db[_0xe447('0x3b')]['findOne']({'where':{'id':_0x808e5e[_0xe447('0x44')]['id']}})['then'](handleEntityNotFound(_0x2e3f77,null))[_0xe447('0x1a')](function(_0x4ca406){if(_0x4ca406){_0x3c1d05[_0xe447('0x45')]=_['keys'](db[_0xe447('0x65')][_0xe447('0x3c')]);_0x3c1d05[_0xe447('0x42')]=_[_0xe447('0x46')](_0x808e5e['query']);_0x3c1d05[_0xe447('0x47')]=_[_0xe447('0x49')](_0x3c1d05['model'],_0x3c1d05[_0xe447('0x42')]);_0x5cf7ba[_0xe447('0x48')]=_[_0xe447('0x49')](_0x3c1d05['model'],qs[_0xe447('0x4a')](_0x808e5e['query']['fields']));_0x5cf7ba[_0xe447('0x48')]=_0x5cf7ba[_0xe447('0x48')][_0xe447('0x4b')]?_0x5cf7ba[_0xe447('0x48')]:_0x3c1d05[_0xe447('0x45')];if(!_0x808e5e[_0xe447('0x42')][_0xe447('0xa5')](_0xe447('0xa6'))){_0x5cf7ba['limit']=qs[_0xe447('0x2b')](_0x808e5e[_0xe447('0x42')][_0xe447('0x2b')]);_0x5cf7ba[_0xe447('0x29')]=qs[_0xe447('0x29')](_0x808e5e[_0xe447('0x42')][_0xe447('0x29')]);}_0x5cf7ba[_0xe447('0xa7')]=qs[_0xe447('0xa8')](_0x808e5e[_0xe447('0x42')][_0xe447('0xa8')]);_0x5cf7ba[_0xe447('0xa9')]=qs[_0xe447('0x47')](_[_0xe447('0xaa')](_0x808e5e[_0xe447('0x42')],_0x3c1d05[_0xe447('0x47')]));_0x5cf7ba[_0xe447('0xa9')][_0xe447('0xab')]=_0x4ca406['id'];if(_0x808e5e[_0xe447('0x42')][_0xe447('0xac')]){_0x5cf7ba[_0xe447('0xa9')]=_[_0xe447('0x34')](_0x5cf7ba[_0xe447('0xa9')],{'$or':_[_0xe447('0x3a')](_0x5cf7ba['attributes'],function(_0x268429){var _0x1116fb={};_0x1116fb[_0x268429]={'$like':'%'+_0x808e5e['query'][_0xe447('0xac')]+'%'};return _0x1116fb;})});}if(_0x808e5e[_0xe447('0x42')][_0xe447('0xad')]){var _0x19f1fa=_0x808e5e[_0xe447('0x42')][_0xe447('0xad')][_0xe447('0xae')](',');var _0x5c9113={};_0x5c9113[_0x19f1fa[0x0]]={'$gte':moment(_0x19f1fa[0x1])[_0xe447('0x89')]('YYYY-MM-DD\x20HH:mm:ss')};_0x5cf7ba[_0xe447('0xa9')]=_[_0xe447('0x34')](_0x5cf7ba[_0xe447('0xa9')],_0x5c9113);}_0x5cf7ba=_[_0xe447('0x34')]({},_0x5cf7ba,_0x808e5e[_0xe447('0x4e')]);return db[_0xe447('0x65')][_0xe447('0x2c')]({'where':_0x5cf7ba[_0xe447('0xa9')]})[_0xe447('0x1a')](function(_0x513a84){_0x22928b[_0xe447('0x2c')]=_0x513a84;if(_0x808e5e[_0xe447('0x42')][_0xe447('0x4c')]){_0x5cf7ba[_0xe447('0x4d')]=[{'all':!![]}];}return db[_0xe447('0x65')][_0xe447('0x40')](_0x5cf7ba);})[_0xe447('0x1a')](function(_0x50ccdd){_0x22928b[_0xe447('0xaf')]=_0x50ccdd;return _0x22928b;});}})['then'](respondWithFilteredResult(_0x2e3f77,_0x5cf7ba))[_0xe447('0x24')](handleError(_0x2e3f77,null));};exports['getMyMessages']=function(_0xd51aa,_0x4de4e9){var _0x2d4397={'where':{}},_0x2e580f={},_0x1c6833={'count':0x0,'rows':[]};return db['ChatInteraction'][_0xe447('0x76')]({'where':{'id':_0xd51aa['params']['id']}})[_0xe447('0x1a')](handleEntityNotFound(_0x4de4e9,null))[_0xe447('0x1a')](function(_0x6561bf){if(_0x6561bf){_0x2e580f['model']=_['keys'](db[_0xe447('0x65')][_0xe447('0x3c')]);_0x2e580f[_0xe447('0x42')]=_['keys'](_0xd51aa['query']);_0x2e580f[_0xe447('0x47')]=_[_0xe447('0x49')](_0x2e580f[_0xe447('0x45')],_0x2e580f[_0xe447('0x42')]);_0x2d4397[_0xe447('0x48')]=_[_0xe447('0x49')](_0x2e580f[_0xe447('0x45')],qs[_0xe447('0x4a')](_0xd51aa['query'][_0xe447('0x4a')]));_0x2d4397['attributes']=_0x2d4397[_0xe447('0x48')][_0xe447('0x4b')]?_0x2d4397[_0xe447('0x48')]:_0x2e580f['model'];if(!_0xd51aa[_0xe447('0x42')][_0xe447('0xa5')](_0xe447('0xa6'))){_0x2d4397[_0xe447('0x2b')]=qs[_0xe447('0x2b')](_0xd51aa[_0xe447('0x42')][_0xe447('0x2b')]);_0x2d4397[_0xe447('0x29')]=qs[_0xe447('0x29')](_0xd51aa['query'][_0xe447('0x29')]);}_0x2d4397[_0xe447('0xa7')]=qs[_0xe447('0xa8')](_0xd51aa[_0xe447('0x42')][_0xe447('0xa8')]);_0x2d4397['where']=qs[_0xe447('0x47')](_['pick'](_0xd51aa['query'],_0x2e580f[_0xe447('0x47')]));_0x2d4397[_0xe447('0xa9')]['ChatInteractionId']=_0x6561bf['id'];if(_0xd51aa[_0xe447('0x42')][_0xe447('0xac')]){_0x2d4397[_0xe447('0xa9')]=_[_0xe447('0x34')](_0x2d4397[_0xe447('0xa9')],{'$or':_['map'](_0x2d4397['attributes'],function(_0x1b6c8a){var _0x18a04b={};_0x18a04b[_0x1b6c8a]={'$like':'%'+_0xd51aa[_0xe447('0x42')][_0xe447('0xac')]+'%'};return _0x18a04b;})});}_0x2d4397['where'][_0xe447('0x97')]=![];if(_0xd51aa[_0xe447('0x42')]['id']){_0x2d4397[_0xe447('0xa9')]['id']={'$gt':_0xd51aa[_0xe447('0x42')]['id']};}_0x2d4397=_['merge']({},_0x2d4397,_0xd51aa[_0xe447('0x4e')]);return db[_0xe447('0x65')]['count']({'where':_0x2d4397['where']})[_0xe447('0x1a')](function(_0x1e96c7){_0x1c6833[_0xe447('0x2c')]=_0x1e96c7;_0x2d4397[_0xe447('0x4d')]=[];if(_0xd51aa[_0xe447('0x42')][_0xe447('0xb0')]){_0x2d4397['include'][_0xe447('0xb1')]({'model':db[_0xe447('0x85')],'as':'User','attributes':['id','fullname','alias']});}if(_0xd51aa[_0xe447('0x42')]['includeAll']){_0x2d4397[_0xe447('0x4d')]=[{'all':!![]}];}return db[_0xe447('0x65')]['findAll'](_0x2d4397);})['then'](function(_0x5805c4){_0x1c6833[_0xe447('0xaf')]=_0x5805c4;return _0x1c6833;});}})[_0xe447('0x1a')](respondWithFilteredResult(_0x4de4e9,_0x2d4397))[_0xe447('0x24')](handleError(_0x4de4e9,null));};exports[_0xe447('0xb2')]=function(_0x765b62,_0x2834e8){return db[_0xe447('0x3b')][_0xe447('0x4f')]({'where':{'id':_0x765b62[_0xe447('0x44')]['id']}})[_0xe447('0x1a')](handleEntityNotFound(_0x2834e8,null))[_0xe447('0x1a')](function(_0x27d55d){if(_0x27d55d){return _0x27d55d[_0xe447('0xb3')](_0x765b62[_0xe447('0x35')][_0xe447('0xa2')],_[_0xe447('0xa3')](_0x765b62[_0xe447('0x35')],['ids','id'])||{})['spread'](function(){return db[_0xe447('0xb4')][_0xe447('0x40')]({'attributes':['id','name','color'],'where':{'id':_0x765b62['body'][_0xe447('0xa2')]}});})[_0xe447('0x1a')](function(_0x567ed6){socket['emit']('chatInteractionTags:save',{'id':Number(_0x765b62['params']['id']),'tags':_0x567ed6||[]});return{'id':Number(_0x765b62[_0xe447('0x44')]['id']),'tags':_0x567ed6||[]};});}})[_0xe447('0x1a')](respondWithResult(_0x2834e8,null))[_0xe447('0x24')](handleError(_0x2834e8,null));};exports[_0xe447('0xb5')]=function(_0x2ac63b,_0x1fa7ca){return db[_0xe447('0x3b')]['find']({'where':{'id':_0x2ac63b['params']['id']}})['then'](handleEntityNotFound(_0x1fa7ca,null))[_0xe447('0x1a')](function(_0x7eeef2){if(_0x7eeef2){return _0x7eeef2[_0xe447('0xb5')](_0x2ac63b[_0xe447('0x42')][_0xe447('0xa2')]);}})[_0xe447('0x1a')](respondWithStatusCode(_0x1fa7ca,null))[_0xe447('0x24')](handleError(_0x1fa7ca,null));};exports[_0xe447('0x7e')]=function(_0x4b45a6,_0x59b75c){var _0x2dd546=moment()['unix']()[_0xe447('0xb6')]();var _0x18f47b=path[_0xe447('0x7b')](config[_0xe447('0x81')],_0xe447('0xb7'),_0xe447('0xb8'),_0xe447('0xb9'));var _0x1958dd=path[_0xe447('0x7b')](config[_0xe447('0x81')],_0xe447('0xb7'),_0xe447('0xb8'),'attachments');var _0x6b0ff5=path[_0xe447('0x7b')](_0x18f47b,_0x2dd546);var _0x46891c=util[_0xe447('0x89')](_0xe447('0xba'),_0x4b45a6[_0xe447('0x44')]['id'],_0x2dd546);var _0x34eafb=path[_0xe447('0x7b')](_0x18f47b,_0x46891c);var _0x29adb2=[];_0x29adb2['push']({'model':db[_0xe447('0x85')],'as':_0xe447('0x85'),'attributes':['id',_0xe447('0x93')],'raw':!![]});_0x29adb2[_0xe447('0xb1')]({'model':db['CmContact'],'as':_0xe447('0xbb'),'attributes':['id',_0xe447('0xbc'),'lastName'],'raw':!![]});if(_0x4b45a6[_0xe447('0x42')][_0xe447('0xbd')]){_0x29adb2[_0xe447('0xb1')]({'model':db['Attachment'],'as':_0xe447('0x78'),'raw':!![]});}var _0x1ac4ef=[{'model':db[_0xe447('0x65')],'as':_0xe447('0x88'),'attributes':['id',_0xe447('0x35'),_0xe447('0x94'),_0xe447('0x96'),_0xe447('0x97'),_0xe447('0xbe')],'include':_0x29adb2}];_0x1ac4ef[_0xe447('0xb1')]({'model':db['ChatWebsite'],'as':_0xe447('0xbf'),'attributes':['id',_0xe447('0x31')]});_0x1ac4ef[_0xe447('0xb1')]({'model':db[_0xe447('0x85')],'as':_0xe447('0xc0'),'attributes':['id','fullname']});return db[_0xe447('0x3b')]['find']({'where':{'id':_0x4b45a6[_0xe447('0x44')]['id']},'include':_0x1ac4ef})[_0xe447('0x1a')](handleEntityNotFound(_0x59b75c,null))['then'](function(_0x2fa7d9){if(_0x2fa7d9){var _0x3dc96e=_0x2fa7d9['get']({'plain':!![]});fs['mkdirSync'](_0x6b0ff5);var _0x23ce05={'channel':_0xe447('0xc1'),'account':_0x3dc96e[_0xe447('0xbf')][_0xe447('0x31')],'agent':_0x3dc96e['Owner']?_0x3dc96e[_0xe447('0xc0')][_0xe447('0x93')]:_0xe447('0xc2'),'createdAt':moment(_0x3dc96e[_0xe447('0x94')])['format'](_0xe447('0xc3'))[_0xe447('0xb6')](),'closedAt':_0x3dc96e[_0xe447('0x6c')]?moment(_0x3dc96e[_0xe447('0xc4')])[_0xe447('0x89')](_0xe447('0xc3'))[_0xe447('0xb6')]():'','disposition':_0x3dc96e[_0xe447('0x6d')],'chatInfo':{'browser':_0x3dc96e[_0xe447('0xc5')],'os':_0x3dc96e[_0xe447('0xc6')],'referer':_0x3dc96e[_0xe447('0xc7')],'customerIp':_0x3dc96e['customerIp'],'customerPort':_0x3dc96e[_0xe447('0xc8')]?_0x3dc96e[_0xe447('0xc8')]:_0xe447('0xc2')},'messages':_(_0x3dc96e[_0xe447('0x88')])[_0xe447('0xc9')]()[_0xe447('0xac')]({'secret':![]})[_0xe447('0x3a')](function(_0x172036){if(_0x172036['Attachment']){var _0x230e9a=path[_0xe447('0x7b')](_0x1958dd,_0x172036[_0xe447('0x78')][_0xe447('0x71')]);if(fs[_0xe447('0xca')](_0x230e9a)){fs[_0xe447('0xcb')](_0x230e9a)['pipe'](fs[_0xe447('0xcc')](path[_0xe447('0x7b')](_0x6b0ff5,_0x172036[_0xe447('0x78')][_0xe447('0x71')])));}}return{'date':moment(_0x172036[_0xe447('0x94')])[_0xe447('0x89')]('YYYY-MM-DD\x20HH:mm:ss')[_0xe447('0xb6')](),'sender':_0x172036[_0xe447('0x96')]===_0xe447('0x64')?_0x172036[_0xe447('0x85')]?_0x172036[_0xe447('0x85')]['fullname']:_0xe447('0x91'):_0x172036['Contact'][_0xe447('0xbc')]+(_0x172036[_0xe447('0xbb')][_0xe447('0xcd')]?'\x20'+_0x172036['Contact'][_0xe447('0xcd')]:''),'body':_0x172036[_0xe447('0x78')]?_0x172036[_0xe447('0x78')][_0xe447('0x71')]:_0x172036['body'],'direction':_0x172036[_0xe447('0x96')]===_0xe447('0x64')?'A':'C','secret':_0x172036['secret'],'read':_0x172036['read'],'attachment':_0x172036['Attachment']};})['value']()};return ejs[_0xe447('0xce')](path[_0xe447('0x7b')](config[_0xe447('0x81')],'server',_0xe447('0xcf'),_0xe447('0xd0')),{'interaction':_0x23ce05})[_0xe447('0x1a')](function(_0x4f52a6){var _0x9ad498=path['join'](_0x6b0ff5,_0xe447('0xd1')+_0x3dc96e['id']+'-'+_0x2dd546+_0xe447('0xd2'));var _0x90bc5d={'path':_0x9ad498,'channel':'Chat','interactionId':_0x3dc96e['id']};return pdf[_0xe447('0xd3')](_0x4f52a6,_0x90bc5d);})['then'](function(){return new Promise(function(_0xabd564,_0x33a593){zipdir(_0x6b0ff5,{'saveTo':_0x34eafb},function(_0x35201d,_0x2a6a01){if(_0x35201d)return _0x33a593(_0x35201d);return _0xabd564(_0x2a6a01);});})[_0xe447('0x1a')](function(){return new BPromise(function(_0x4ce283,_0x5253b0){rimraf(_0x6b0ff5,function(_0x1f4bd4){if(_0x1f4bd4)_0x5253b0(_0x1f4bd4);return _0x4ce283();});});})[_0xe447('0x1a')](function(){return _0x59b75c[_0xe447('0x7e')](_0x34eafb,_0x46891c,function(_0x305035){if(_0x305035){logger[_0xe447('0x21')](_0xe447('0xd4'),_0x305035);}else{fs[_0xe447('0xd5')](_0x34eafb);}});});});}else{return _0x59b75c[_0xe447('0x25')](0xc8);}})[_0xe447('0x24')](handleError(_0x59b75c,null));};
\ No newline at end of file
+var _0xbf5b=['unlinkSync','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','ejs','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/environment','../../mysqldb','redis','socket.io-emitter','./chatInteraction.socket','jayson/promise','client','http','request','then','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','ChatInteraction,\x20%s,\x20%s','message','info','result','catch','sendStatus','end','status','json','offset','undefined','limit','count','Content-Range','destroy','stack','name','render','merge','body','contact','agent','interaction','account','map','ChatInteraction','rawAttributes','fieldName','type','key','getOptions','findAll','query','user','show','params','model','keys','filters','intersection','attributes','length','includeAll','options','find','create','describe','findOne','ChatWebsite','ChatWebsiteId','vidaooApiKey','vidaooMetadata','fullname','email','POST','vidaooTopic','isNull','vidaooNote','parse','metadata','Sequelize','ValidationError','Error\x20in\x20conversion\x20vidaooMetadata','Error\x20in\x20Vidaoo\x20configuration','join_url','out','ChatMessage','Unable\x20to\x20create\x20Vidaoo\x20session','CmContact','abandon','UserId','Interaction\x20already\x20assigned','update','AbandonInteraction','attachmentUpload','file','originalname','basename','filename','mimetype','Attachment','Unauthorized','attachId','ChatOfflineMessageId','join','root','server/files/attachments/','download','close','mailTranscript','format','transcript-%s.txt','pathTranscript','User','Messages','%s%d','agentAlias','System','customer','Visitor','ContactId','agentIdentifier','agent_alias','alias','createdAt','MailAccount','CloudProvider','Smtp','getSmtpOptions','sendMail','Mail\x20Transcript','addMessage','ids','getMessages','fields','hasOwnProperty','nolimit','order','sort','where','pick','ChatInteractionId','filter','$gte','split','YYYY-MM-DD\x20HH:mm:ss','include','rows','getMyMessages','secret','includeAgent','push','addTags','setTags','spread','Tag','color','emit','chatInteractionTags:save','removeTags','unix','toString','server','files','attachments','firstName','read','Account','Owner','get','mkdirSync','Chat','closed','closedAt','disposition','osName','customerIp','customerPort','N.A.','tail','createReadStream','pipe','createWriteStream','Contact','lastName','direction','value','views','downloadInteraction.ejs','transcript-','.pdf','createPdfFromHTML'];(function(_0x4a3a9a,_0x21d963){var _0x5805b6=function(_0x393d6e){while(--_0x393d6e){_0x4a3a9a['push'](_0x4a3a9a['shift']());}};_0x5805b6(++_0x21d963);}(_0xbf5b,0x193));var _0xbbf5=function(_0x47fd36,_0x41535d){_0x47fd36=_0x47fd36-0x0;var _0x21a0fc=_0xbf5b[_0x47fd36];return _0x21a0fc;};'use strict';var rimraf=require(_0xbbf5('0x0'));var zipdir=require(_0xbbf5('0x1'));var rp=require(_0xbbf5('0x2'));var moment=require(_0xbbf5('0x3'));var BPromise=require(_0xbbf5('0x4'));var Mustache=require(_0xbbf5('0x5'));var util=require(_0xbbf5('0x6'));var path=require(_0xbbf5('0x7'));var ejs=require(_0xbbf5('0x8'));var fs=require('fs');var _=require('lodash');var Redis=require('ioredis');var interaction=require(_0xbbf5('0x9'));var qs=require(_0xbbf5('0xa'));var pdf=require(_0xbbf5('0xb'));var logger=require('../../config/logger')('api');var config=require(_0xbbf5('0xc'));var db=require(_0xbbf5('0xd'))['db'];config[_0xbbf5('0xe')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xbbf5('0xf'))(new Redis(config['redis']));require(_0xbbf5('0x10'))['register'](socket);var jayson=require(_0xbbf5('0x11'));var client=jayson[_0xbbf5('0x12')][_0xbbf5('0x13')]({'port':0x232b});var client9004=jayson['client'][_0xbbf5('0x13')]({'port':0x232c});function respondWithRpcPromise(_0x328ada,_0x4117e6,_0xa36601,_0x85052d){return new BPromise(function(_0x652060,_0x9ce373){var _0x47deea=_0x85052d||client;return _0x47deea[_0xbbf5('0x14')](_0x328ada,_0xa36601)[_0xbbf5('0x15')](function(_0x2c4ad8){logger['info']('ChatInteraction,\x20%s,\x20%s',_0x4117e6,'request\x20sent');logger[_0xbbf5('0x16')](_0xbbf5('0x17'),_0x4117e6,_0xbbf5('0x18'),JSON[_0xbbf5('0x19')](_0x2c4ad8));if(_0x2c4ad8['error']){if(_0x2c4ad8[_0xbbf5('0x1a')][_0xbbf5('0x1b')]===0x1f4){logger['error'](_0xbbf5('0x1c'),_0x4117e6,_0x2c4ad8[_0xbbf5('0x1a')][_0xbbf5('0x1d')]);return _0x9ce373(_0x2c4ad8['error'][_0xbbf5('0x1d')]);}logger['error']('ChatInteraction,\x20%s,\x20%s',_0x4117e6,_0x2c4ad8[_0xbbf5('0x1a')][_0xbbf5('0x1d')]);return _0x652060(_0x2c4ad8['error'][_0xbbf5('0x1d')]);}else{logger[_0xbbf5('0x1e')]('ChatInteraction,\x20%s,\x20%s',_0x4117e6,'request\x20sent');_0x652060(_0x2c4ad8[_0xbbf5('0x1f')][_0xbbf5('0x1d')]);}})[_0xbbf5('0x20')](function(_0x108e25){logger[_0xbbf5('0x1a')](_0xbbf5('0x1c'),_0x4117e6,_0x108e25);_0x9ce373(_0x108e25);});});}function respondWithStatusCode(_0x18f8d5,_0x38a9df){_0x38a9df=_0x38a9df||0xcc;return function(_0x191f55){if(_0x191f55){return _0x18f8d5[_0xbbf5('0x21')](_0x38a9df);}return _0x18f8d5['status'](_0x38a9df)[_0xbbf5('0x22')]();};}function respondWithResult(_0xd4e58d,_0x430365){_0x430365=_0x430365||0xc8;return function(_0x2e1cc0){if(_0x2e1cc0){return _0xd4e58d[_0xbbf5('0x23')](_0x430365)[_0xbbf5('0x24')](_0x2e1cc0);}};}function respondWithFilteredResult(_0x34fc6f,_0xc831cf){return function(_0x532cce){if(_0x532cce){var _0x4d4e42=typeof _0xc831cf[_0xbbf5('0x25')]===_0xbbf5('0x26')&&typeof _0xc831cf[_0xbbf5('0x27')]==='undefined';var _0x1875d0=_0x532cce['count'];var _0x106f0d=_0x4d4e42?0x0:_0xc831cf[_0xbbf5('0x25')];var _0x48aa67=_0x4d4e42?_0x532cce[_0xbbf5('0x28')]:_0xc831cf[_0xbbf5('0x25')]+_0xc831cf[_0xbbf5('0x27')];var _0xfe14d4;if(_0x48aa67>=_0x1875d0){_0x48aa67=_0x1875d0;_0xfe14d4=0xc8;}else{_0xfe14d4=0xce;}_0x34fc6f['status'](_0xfe14d4);return _0x34fc6f['set'](_0xbbf5('0x29'),_0x106f0d+'-'+_0x48aa67+'/'+_0x1875d0)['json'](_0x532cce);}return null;};}function saveUpdates(_0x3a24af){return function(_0x47af38){if(_0x47af38){return _0x47af38['update'](_0x3a24af)[_0xbbf5('0x15')](function(_0x587dcb){return _0x587dcb;});}return null;};}function removeEntity(_0x2c39e4){return function(_0x3e9a72){if(_0x3e9a72){return _0x3e9a72[_0xbbf5('0x2a')]()[_0xbbf5('0x15')](function(){_0x2c39e4[_0xbbf5('0x23')](0xcc)[_0xbbf5('0x22')]();});}};}function handleEntityNotFound(_0x43e429){return function(_0x1cacbc){if(!_0x1cacbc){_0x43e429[_0xbbf5('0x21')](0x194);}return _0x1cacbc;};}function handleError(_0x929dc6,_0x1e9a54){_0x1e9a54=_0x1e9a54||0x1f4;return function(_0x58a5b5){logger[_0xbbf5('0x1a')](_0x58a5b5[_0xbbf5('0x2b')]);if(_0x58a5b5['name']){delete _0x58a5b5[_0xbbf5('0x2c')];}_0x929dc6[_0xbbf5('0x23')](_0x1e9a54)['send'](_0x58a5b5);};}function getMustacheRender(_0x2c4126,_0x2f92da){return Mustache[_0xbbf5('0x2d')](_0x2c4126,_[_0xbbf5('0x2e')](_0x2f92da[_0xbbf5('0x2f')],{'contact':_0x2f92da[_0xbbf5('0x30')],'message':_0x2f92da[_0xbbf5('0x1d')],'agent':_0x2f92da[_0xbbf5('0x31')],'interaction':_0x2f92da[_0xbbf5('0x32')],'account':_0x2f92da[_0xbbf5('0x33')]}))||'';}exports['index']=function(_0x4de97d,_0x294935){var _0x2132fb={};var _0x3d6c8c=_[_0xbbf5('0x34')](db[_0xbbf5('0x35')][_0xbbf5('0x36')],function(_0x5bbff1){return{'name':_0x5bbff1[_0xbbf5('0x37')],'type':_0x5bbff1[_0xbbf5('0x38')][_0xbbf5('0x39')]};});_0x2132fb=qs[_0xbbf5('0x3a')](_0x3d6c8c,_0x4de97d);return interaction[_0xbbf5('0x3b')]('chat',_0x4de97d[_0xbbf5('0x3c')],_0x4de97d[_0xbbf5('0x3d')],_0x2132fb,_0x3d6c8c)[_0xbbf5('0x15')](respondWithFilteredResult(_0x294935,_0x2132fb))[_0xbbf5('0x20')](handleError(_0x294935,null));};exports[_0xbbf5('0x3e')]=function(_0x55903a,_0x29a7cd){var _0x336abb={'raw':![],'where':{'id':_0x55903a[_0xbbf5('0x3f')]['id']}},_0x5c890c={};_0x5c890c[_0xbbf5('0x40')]=_[_0xbbf5('0x41')](db[_0xbbf5('0x35')][_0xbbf5('0x36')]);_0x5c890c['query']=_[_0xbbf5('0x41')](_0x55903a[_0xbbf5('0x3c')]);_0x5c890c[_0xbbf5('0x42')]=_[_0xbbf5('0x43')](_0x5c890c[_0xbbf5('0x40')],_0x5c890c[_0xbbf5('0x3c')]);_0x336abb[_0xbbf5('0x44')]=_[_0xbbf5('0x43')](_0x5c890c['model'],qs['fields'](_0x55903a[_0xbbf5('0x3c')]['fields']));_0x336abb[_0xbbf5('0x44')]=_0x336abb[_0xbbf5('0x44')][_0xbbf5('0x45')]?_0x336abb[_0xbbf5('0x44')]:_0x5c890c['model'];if(_0x55903a[_0xbbf5('0x3c')][_0xbbf5('0x46')]){_0x336abb['include']=[{'all':!![]}];}_0x336abb=_[_0xbbf5('0x2e')]({},_0x336abb,_0x55903a[_0xbbf5('0x47')]);return db[_0xbbf5('0x35')][_0xbbf5('0x48')](_0x336abb)[_0xbbf5('0x15')](handleEntityNotFound(_0x29a7cd,null))['then'](respondWithResult(_0x29a7cd,null))[_0xbbf5('0x20')](handleError(_0x29a7cd,null));};exports[_0xbbf5('0x49')]=function(_0x80f2a2,_0x534588){return db['ChatInteraction'][_0xbbf5('0x49')](_0x80f2a2[_0xbbf5('0x2f')],{})[_0xbbf5('0x15')](respondWithResult(_0x534588,0xc9))[_0xbbf5('0x20')](handleError(_0x534588,null));};exports['update']=function(_0x2ff8eb,_0x46a403){if(_0x2ff8eb[_0xbbf5('0x2f')]['id']){delete _0x2ff8eb[_0xbbf5('0x2f')]['id'];}return db[_0xbbf5('0x35')]['find']({'where':{'id':_0x2ff8eb[_0xbbf5('0x3f')]['id']}})[_0xbbf5('0x15')](handleEntityNotFound(_0x46a403,null))[_0xbbf5('0x15')](saveUpdates(_0x2ff8eb['body'],null))[_0xbbf5('0x15')](respondWithResult(_0x46a403,null))[_0xbbf5('0x20')](handleError(_0x46a403,null));};exports[_0xbbf5('0x2a')]=function(_0x5950bd,_0x2619e5){return db[_0xbbf5('0x35')][_0xbbf5('0x48')]({'where':{'id':_0x5950bd[_0xbbf5('0x3f')]['id']}})[_0xbbf5('0x15')](handleEntityNotFound(_0x2619e5,null))[_0xbbf5('0x15')](removeEntity(_0x2619e5,null))['catch'](handleError(_0x2619e5,null));};exports['describe']=function(_0x547ead,_0x1b85a9){return db[_0xbbf5('0x35')][_0xbbf5('0x4a')]()[_0xbbf5('0x15')](respondWithResult(_0x1b85a9,null))['catch'](handleError(_0x1b85a9,null));};exports['createVidaooSession']=function(_0x5ba428,_0x1f79ee){var _0x4318fa=_0x5ba428[_0xbbf5('0x3f')]['id'];var _0x750998;var _0x9ec7f7;var _0x3437c3;return db['ChatInteraction'][_0xbbf5('0x4b')]({'where':{'id':_0x4318fa}})[_0xbbf5('0x15')](function(_0x2716fe){_0x750998=_0x2716fe;return db[_0xbbf5('0x4c')]['findOne']({'where':{'id':_0x2716fe[_0xbbf5('0x4d')]},'attributes':['id',_0xbbf5('0x4e'),'vidaooEscalation','vidaooTopic','vidaooNote',_0xbbf5('0x4f')],'raw':!![]});})[_0xbbf5('0x15')](function(_0x17a83f){if(_0x17a83f&&_0x17a83f[_0xbbf5('0x4e')]&&_0x17a83f['vidaooEscalation']){_0x9ec7f7=_0x17a83f;var _0x340e41={'interaction':{'id':_0x4318fa},'agent':{'id':_0x5ba428[_0xbbf5('0x3d')]['id'],'name':_0x5ba428[_0xbbf5('0x3d')][_0xbbf5('0x2c')],'fullname':_0x5ba428[_0xbbf5('0x3d')][_0xbbf5('0x50')],'email':_0x5ba428['user'][_0xbbf5('0x51')]},'contact':_0x5ba428[_0xbbf5('0x2f')]['contact'],'account':_0x5ba428['body'][_0xbbf5('0x33')]};var _0x386c0f={'rejectUnauthorized':![],'method':_0xbbf5('0x52'),'url':'https://api-vidaoo.xcally.com/api/v1/meetings','headers':{'X-APIKEY':_0x17a83f[_0xbbf5('0x4e')]},'body':{'duration':null,'scheduledAt':null,'participants':[_0x5ba428[_0xbbf5('0x3d')][_0xbbf5('0x51')]],'buttons':null,'topic':_0x9ec7f7[_0xbbf5('0x53')],'note':_[_0xbbf5('0x54')](_0x9ec7f7[_0xbbf5('0x55')])?null:getMustacheRender(_0x9ec7f7[_0xbbf5('0x55')],_0x340e41),'metadata':null},'redirect':'follow','json':!![]};try{if(!_[_0xbbf5('0x54')](_0x9ec7f7[_0xbbf5('0x4f')])){var _0x3ab44e=getMustacheRender(_0x9ec7f7[_0xbbf5('0x4f')],_0x340e41);var _0x234b61=JSON[_0xbbf5('0x56')](_0x3ab44e);_0x386c0f[_0xbbf5('0x2f')][_0xbbf5('0x57')]=_0x234b61;}}catch(_0x358dbd){throw new db[(_0xbbf5('0x58'))][(_0xbbf5('0x59'))](_0xbbf5('0x5a'));}return rp(_0x386c0f);}else{throw new db['Sequelize']['ValidationError'](_0xbbf5('0x5b'));}})[_0xbbf5('0x15')](function(_0x426894){_0x3437c3=_0x426894;if(_0x3437c3['id']){var _0x2ce428={'body':_0x3437c3[_0xbbf5('0x5c')],'ChatWebsiteId':_0x9ec7f7['id'],'ChatInteractionId':_0x750998['id'],'direction':_0xbbf5('0x5d'),'UserId':_0x5ba428['user']['id']};return db[_0xbbf5('0x5e')]['create'](_0x2ce428,{});}else{throw new db[(_0xbbf5('0x58'))][(_0xbbf5('0x59'))](_0xbbf5('0x5f'));}})[_0xbbf5('0x15')](function(){return _0x750998['updateAttributes']({'vidaooSessionId':_0x3437c3['id']});})['then'](respondWithResult(_0x1f79ee,null))['catch'](handleError(_0x1f79ee,null));};exports['customUpdate']=function(_0x42c3d6,_0x555f0b){if(_0x42c3d6[_0xbbf5('0x2f')]['id']){delete _0x42c3d6[_0xbbf5('0x2f')]['id'];}return db['ChatInteraction'][_0xbbf5('0x48')]({'where':{'id':_0x42c3d6[_0xbbf5('0x3f')]['id']},'include':[{'model':db[_0xbbf5('0x60')],'as':'Contact'}]})[_0xbbf5('0x15')](handleEntityNotFound(_0x555f0b,null))[_0xbbf5('0x15')](saveUpdates(_0x42c3d6['body'],null))[_0xbbf5('0x15')](respondWithResult(_0x555f0b,null))[_0xbbf5('0x20')](handleError(_0x555f0b,null));};exports['abandon']=function(_0x2b06ae,_0x3a021b){if(_0x2b06ae[_0xbbf5('0x2f')]['id']){delete _0x2b06ae['body']['id'];}return db[_0xbbf5('0x35')][_0xbbf5('0x48')]({'where':{'id':_0x2b06ae['params']['id']}})['then'](function(_0xefc17d){if(!_0xefc17d){logger[_0xbbf5('0x1a')]('abandonInteraction,\x20%s,\x20%s,\x20%s',_0xbbf5('0x61'),0x194,'entity\x20not\x20found');_0x3a021b[_0xbbf5('0x21')](0x194);}else{if(_0xefc17d[_0xbbf5('0x62')]){throw new db[(_0xbbf5('0x58'))][(_0xbbf5('0x59'))](_0xbbf5('0x63'));}}return _0xefc17d;})[_0xbbf5('0x15')](function(_0x2834b6){if(_0x2834b6){return _0x2834b6[_0xbbf5('0x64')]({'closed':_0x2b06ae[_0xbbf5('0x2f')]['closed'],'disposition':_0x2b06ae[_0xbbf5('0x2f')]['disposition']})['then'](function(_0x2a5b23){return _0x2a5b23;});}})[_0xbbf5('0x15')](function(){return respondWithRpcPromise(_0xbbf5('0x65'),'abandon',_0x2b06ae[_0xbbf5('0x2f')],client9004);})[_0xbbf5('0x15')](respondWithResult(_0x3a021b,null))[_0xbbf5('0x20')](handleError(_0x3a021b,null));};exports[_0xbbf5('0x66')]=function(_0x44c452,_0x392565){_0x44c452[_0xbbf5('0x2f')][_0xbbf5('0x2c')]=_0x44c452[_0xbbf5('0x67')][_0xbbf5('0x68')];_0x44c452[_0xbbf5('0x2f')][_0xbbf5('0x69')]=_0x44c452[_0xbbf5('0x67')][_0xbbf5('0x6a')];_0x44c452[_0xbbf5('0x2f')][_0xbbf5('0x38')]=_0x44c452['file'][_0xbbf5('0x6b')];return db[_0xbbf5('0x6c')][_0xbbf5('0x49')](_0x44c452[_0xbbf5('0x2f')])[_0xbbf5('0x15')](respondWithResult(_0x392565,0xc9))[_0xbbf5('0x20')](handleError(_0x392565,null));};exports['attachmentDownload']=function(_0x3f84f0,_0x57b008){return db[_0xbbf5('0x35')][_0xbbf5('0x4b')]({'where':{'id':_0x3f84f0[_0xbbf5('0x3f')]['id']},'raw':!![]})[_0xbbf5('0x15')](handleEntityNotFound(_0x57b008,null))['then'](function(_0x4c646b){if(_0x4c646b){if(_0x4c646b['closed']){return _0x57b008[_0xbbf5('0x23')](0x193)[_0xbbf5('0x24')]({'status':0x193,'message':_0xbbf5('0x6d')});}return db['Attachment'][_0xbbf5('0x4b')]({'where':{'id':_0x3f84f0[_0xbbf5('0x3c')][_0xbbf5('0x6e')]},'raw':!![]})[_0xbbf5('0x15')](handleEntityNotFound(_0x57b008,null));}})[_0xbbf5('0x15')](function(_0x417d4d){if(_0x417d4d){var _0x32f8f2=_0x417d4d[_0xbbf5('0x6f')]!==null;var _0x401879=path[_0xbbf5('0x70')](config[_0xbbf5('0x71')],_0xbbf5('0x72'));if(_0x32f8f2){_0x401879=path[_0xbbf5('0x70')](_0x401879,'offline-chat/');}var _0x55a138=path[_0xbbf5('0x70')](_0x401879,_0x417d4d['basename']);return _0x57b008[_0xbbf5('0x73')](_0x55a138);}})[_0xbbf5('0x20')](handleError(_0x57b008,null));};exports[_0xbbf5('0x74')]=function(_0x3d2a1e,_0xb0c46d){var _0x19670b=null;var _0x329862=null;var _0x5ab3c=null;if(_0x3d2a1e['body']['id']){delete _0x3d2a1e[_0xbbf5('0x2f')]['id'];}if(_0x3d2a1e[_0xbbf5('0x2f')][_0xbbf5('0x75')]){_0x5ab3c=path[_0xbbf5('0x70')](config['root'],'server/files/chat/upload/',util[_0xbbf5('0x76')](_0xbbf5('0x77'),Date['now']()));_0x3d2a1e['body'][_0xbbf5('0x78')]=_0x5ab3c;}return db[_0xbbf5('0x35')][_0xbbf5('0x48')]({'where':{'id':_0x3d2a1e['params']['id']},'include':[{'model':db[_0xbbf5('0x5e')],'as':'Messages','include':[{'model':db[_0xbbf5('0x79')],'as':'User'}]}]})[_0xbbf5('0x15')](handleEntityNotFound(_0xb0c46d,null))[_0xbbf5('0x15')](saveUpdates(_0x3d2a1e[_0xbbf5('0x2f')],null))[_0xbbf5('0x15')](function(_0x407adf){if(_0x407adf){_0x19670b=_0x407adf;return db[_0xbbf5('0x4c')][_0xbbf5('0x48')]({'where':{'id':_0x19670b['ChatWebsiteId']}});}})[_0xbbf5('0x15')](function(_0x5f04fa){if(_0x5f04fa){_0x329862=_0x5f04fa;return db['CmContact'][_0xbbf5('0x48')]({'where':{'id':_0x19670b['ContactId']}});}})['then'](function(_0x2f836f){if(_0x2f836f){if(_0x5ab3c){var _0x1dc044=null;for(var _0x5566d0=0x1;_0x5566d0<_0x19670b[_0xbbf5('0x7a')][_0xbbf5('0x45')];++_0x5566d0){_0x1dc044=_0x19670b[_0xbbf5('0x7a')][_0x5566d0];var _0x54f5a1=_0x1dc044[_0xbbf5('0x62')]?util[_0xbbf5('0x76')](_0xbbf5('0x7b'),_0x329862[_0xbbf5('0x7c')],_0x1dc044[_0xbbf5('0x62')]):_0xbbf5('0x7d');var _0x2fa5ca=_0x3d2a1e[_0xbbf5('0x2f')][_0xbbf5('0x7e')]||util[_0xbbf5('0x76')](_0xbbf5('0x7b'),_0xbbf5('0x7f'),_0x1dc044[_0xbbf5('0x80')]);switch(_0x329862[_0xbbf5('0x81')]){case'website_alias':_0x54f5a1=_0x1dc044[_0xbbf5('0x62')]?util[_0xbbf5('0x76')]('%s%d',_0x329862['agentAlias'],_0x1dc044[_0xbbf5('0x62')]):'System';break;case _0xbbf5('0x82'):_0x54f5a1=_0x1dc044[_0xbbf5('0x62')]?_0x1dc044['User'][_0xbbf5('0x83')]||_0x1dc044[_0xbbf5('0x79')][_0xbbf5('0x50')]:_0xbbf5('0x7d');break;case'agent_fullname':_0x54f5a1=_0x1dc044['UserId']?_0x1dc044['User'][_0xbbf5('0x50')]:_0xbbf5('0x7d');break;default:_0x54f5a1=_0x1dc044[_0xbbf5('0x62')]?util[_0xbbf5('0x76')](_0xbbf5('0x7b'),_0x329862[_0xbbf5('0x7c')],_0x1dc044['UserId']):_0xbbf5('0x7d');}var _0x2caa66=util[_0xbbf5('0x76')]('[%s]\x20%s:\x20%s\x0a',moment(_0x1dc044[_0xbbf5('0x84')])[_0xbbf5('0x76')]('MM/DD/YYYY\x20HH:mm:ss'),_0x1dc044['direction']==='in'?_0x2fa5ca:_0x54f5a1,_0x1dc044[_0xbbf5('0x2f')]);if(!_0x1dc044['secret']){fs['appendFileSync'](_0x5ab3c,_0x2caa66);}}return db[_0xbbf5('0x85')][_0xbbf5('0x4b')]({'where':{'service':!![]},'include':[{'model':db['MailServerOut'],'as':'Smtp','raw':!![],'include':[{'model':db[_0xbbf5('0x86')],'as':'CloudProvider','raw':!![]}]}]});}}})[_0xbbf5('0x15')](function(_0x33054a){if(!_0x33054a||!_0x33054a[_0xbbf5('0x87')]||!_0x3d2a1e['body'])return _0x19670b;var _0x1f4856=_0x33054a[_0xbbf5('0x88')]();return respondWithRpcPromise('SendMail',_0xbbf5('0x89'),{'account':_0x1f4856,'message':{'from':util['format']('\x22%s\x22\x20<%s>',_0x33054a[_0xbbf5('0x2c')],_0x33054a[_0xbbf5('0x51')]||_0x33054a[_0xbbf5('0x87')][_0xbbf5('0x3d')]),'to':_0x3d2a1e['body'][_0xbbf5('0x75')],'subject':_0xbbf5('0x8a'),'text':util[_0xbbf5('0x76')]('Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a',_0x3d2a1e[_0xbbf5('0x2f')][_0xbbf5('0x75')]),'attachments':[{'path':_0x5ab3c}]}})[_0xbbf5('0x15')](function(){return _0x19670b;})[_0xbbf5('0x20')](function(_0x5b617d){logger[_0xbbf5('0x1a')](_0x5b617d);});})[_0xbbf5('0x15')](respondWithStatusCode(_0xb0c46d,0xc8))[_0xbbf5('0x20')](handleError(_0xb0c46d,null));};exports[_0xbbf5('0x8b')]=function(_0x8133e3,_0x35c26f){return db[_0xbbf5('0x5e')][_0xbbf5('0x48')]({'where':{'id':_0x8133e3[_0xbbf5('0x3f')]['id']}})[_0xbbf5('0x15')](handleEntityNotFound(_0x35c26f,null))[_0xbbf5('0x15')](function(_0x4b1e71){if(_0x4b1e71){return _0x4b1e71[_0xbbf5('0x8b')](_0x8133e3['body'][_0xbbf5('0x8c')],_['omit'](_0x8133e3['body'],[_0xbbf5('0x8c'),'id'])||{});}})[_0xbbf5('0x15')](respondWithResult(_0x35c26f,null))[_0xbbf5('0x20')](handleError(_0x35c26f,null));};exports[_0xbbf5('0x8d')]=function(_0xe8933c,_0x155520){var _0x5bb210={'raw':![],'where':{}};var _0x34ca36={};var _0x54c38f={'count':0x0,'rows':[]};return db[_0xbbf5('0x35')][_0xbbf5('0x4b')]({'where':{'id':_0xe8933c['params']['id']}})[_0xbbf5('0x15')](handleEntityNotFound(_0x155520,null))['then'](function(_0x21a645){if(_0x21a645){_0x34ca36[_0xbbf5('0x40')]=_[_0xbbf5('0x41')](db[_0xbbf5('0x5e')]['rawAttributes']);_0x34ca36[_0xbbf5('0x3c')]=_[_0xbbf5('0x41')](_0xe8933c['query']);_0x34ca36[_0xbbf5('0x42')]=_[_0xbbf5('0x43')](_0x34ca36[_0xbbf5('0x40')],_0x34ca36[_0xbbf5('0x3c')]);_0x5bb210[_0xbbf5('0x44')]=_['intersection'](_0x34ca36['model'],qs[_0xbbf5('0x8e')](_0xe8933c[_0xbbf5('0x3c')]['fields']));_0x5bb210[_0xbbf5('0x44')]=_0x5bb210[_0xbbf5('0x44')][_0xbbf5('0x45')]?_0x5bb210[_0xbbf5('0x44')]:_0x34ca36[_0xbbf5('0x40')];if(!_0xe8933c[_0xbbf5('0x3c')][_0xbbf5('0x8f')](_0xbbf5('0x90'))){_0x5bb210[_0xbbf5('0x27')]=qs[_0xbbf5('0x27')](_0xe8933c['query'][_0xbbf5('0x27')]);_0x5bb210[_0xbbf5('0x25')]=qs[_0xbbf5('0x25')](_0xe8933c[_0xbbf5('0x3c')][_0xbbf5('0x25')]);}_0x5bb210[_0xbbf5('0x91')]=qs[_0xbbf5('0x92')](_0xe8933c[_0xbbf5('0x3c')]['sort']);_0x5bb210[_0xbbf5('0x93')]=qs['filters'](_[_0xbbf5('0x94')](_0xe8933c[_0xbbf5('0x3c')],_0x34ca36[_0xbbf5('0x42')]));_0x5bb210[_0xbbf5('0x93')][_0xbbf5('0x95')]=_0x21a645['id'];if(_0xe8933c[_0xbbf5('0x3c')][_0xbbf5('0x96')]){_0x5bb210[_0xbbf5('0x93')]=_[_0xbbf5('0x2e')](_0x5bb210[_0xbbf5('0x93')],{'$or':_[_0xbbf5('0x34')](_0x5bb210[_0xbbf5('0x44')],function(_0x274e7e){var _0x4ceced={};_0x4ceced[_0x274e7e]={'$like':'%'+_0xe8933c[_0xbbf5('0x3c')][_0xbbf5('0x96')]+'%'};return _0x4ceced;})});}if(_0xe8933c[_0xbbf5('0x3c')]['$gte']){var _0x3cf109=_0xe8933c[_0xbbf5('0x3c')][_0xbbf5('0x97')][_0xbbf5('0x98')](',');var _0x334ddd={};_0x334ddd[_0x3cf109[0x0]]={'$gte':moment(_0x3cf109[0x1])[_0xbbf5('0x76')](_0xbbf5('0x99'))};_0x5bb210[_0xbbf5('0x93')]=_[_0xbbf5('0x2e')](_0x5bb210['where'],_0x334ddd);}_0x5bb210=_['merge']({},_0x5bb210,_0xe8933c[_0xbbf5('0x47')]);return db[_0xbbf5('0x5e')][_0xbbf5('0x28')]({'where':_0x5bb210['where']})[_0xbbf5('0x15')](function(_0x5587a7){_0x54c38f[_0xbbf5('0x28')]=_0x5587a7;if(_0xe8933c[_0xbbf5('0x3c')][_0xbbf5('0x46')]){_0x5bb210[_0xbbf5('0x9a')]=[{'all':!![]}];}return db[_0xbbf5('0x5e')][_0xbbf5('0x3b')](_0x5bb210);})[_0xbbf5('0x15')](function(_0x134f8e){_0x54c38f[_0xbbf5('0x9b')]=_0x134f8e;return _0x54c38f;});}})[_0xbbf5('0x15')](respondWithFilteredResult(_0x155520,_0x5bb210))[_0xbbf5('0x20')](handleError(_0x155520,null));};exports[_0xbbf5('0x9c')]=function(_0x53d1d9,_0xc4cc9d){var _0x5e163c={'where':{}},_0x166271={},_0x5ae9b3={'count':0x0,'rows':[]};return db[_0xbbf5('0x35')]['findOne']({'where':{'id':_0x53d1d9[_0xbbf5('0x3f')]['id']}})[_0xbbf5('0x15')](handleEntityNotFound(_0xc4cc9d,null))[_0xbbf5('0x15')](function(_0x40684c){if(_0x40684c){_0x166271[_0xbbf5('0x40')]=_[_0xbbf5('0x41')](db[_0xbbf5('0x5e')]['rawAttributes']);_0x166271[_0xbbf5('0x3c')]=_[_0xbbf5('0x41')](_0x53d1d9[_0xbbf5('0x3c')]);_0x166271[_0xbbf5('0x42')]=_['intersection'](_0x166271[_0xbbf5('0x40')],_0x166271[_0xbbf5('0x3c')]);_0x5e163c[_0xbbf5('0x44')]=_[_0xbbf5('0x43')](_0x166271[_0xbbf5('0x40')],qs['fields'](_0x53d1d9['query']['fields']));_0x5e163c[_0xbbf5('0x44')]=_0x5e163c[_0xbbf5('0x44')][_0xbbf5('0x45')]?_0x5e163c[_0xbbf5('0x44')]:_0x166271[_0xbbf5('0x40')];if(!_0x53d1d9[_0xbbf5('0x3c')][_0xbbf5('0x8f')](_0xbbf5('0x90'))){_0x5e163c[_0xbbf5('0x27')]=qs[_0xbbf5('0x27')](_0x53d1d9[_0xbbf5('0x3c')][_0xbbf5('0x27')]);_0x5e163c['offset']=qs[_0xbbf5('0x25')](_0x53d1d9[_0xbbf5('0x3c')][_0xbbf5('0x25')]);}_0x5e163c[_0xbbf5('0x91')]=qs[_0xbbf5('0x92')](_0x53d1d9[_0xbbf5('0x3c')][_0xbbf5('0x92')]);_0x5e163c[_0xbbf5('0x93')]=qs['filters'](_['pick'](_0x53d1d9[_0xbbf5('0x3c')],_0x166271[_0xbbf5('0x42')]));_0x5e163c[_0xbbf5('0x93')][_0xbbf5('0x95')]=_0x40684c['id'];if(_0x53d1d9[_0xbbf5('0x3c')][_0xbbf5('0x96')]){_0x5e163c['where']=_[_0xbbf5('0x2e')](_0x5e163c[_0xbbf5('0x93')],{'$or':_[_0xbbf5('0x34')](_0x5e163c['attributes'],function(_0x307318){var _0x1af612={};_0x1af612[_0x307318]={'$like':'%'+_0x53d1d9[_0xbbf5('0x3c')][_0xbbf5('0x96')]+'%'};return _0x1af612;})});}_0x5e163c[_0xbbf5('0x93')][_0xbbf5('0x9d')]=![];if(_0x53d1d9[_0xbbf5('0x3c')]['id']){_0x5e163c['where']['id']={'$gt':_0x53d1d9[_0xbbf5('0x3c')]['id']};}_0x5e163c=_[_0xbbf5('0x2e')]({},_0x5e163c,_0x53d1d9[_0xbbf5('0x47')]);return db['ChatMessage'][_0xbbf5('0x28')]({'where':_0x5e163c[_0xbbf5('0x93')]})['then'](function(_0x2b00b6){_0x5ae9b3['count']=_0x2b00b6;_0x5e163c[_0xbbf5('0x9a')]=[];if(_0x53d1d9[_0xbbf5('0x3c')][_0xbbf5('0x9e')]){_0x5e163c[_0xbbf5('0x9a')][_0xbbf5('0x9f')]({'model':db[_0xbbf5('0x79')],'as':_0xbbf5('0x79'),'attributes':['id',_0xbbf5('0x50'),_0xbbf5('0x83')]});}if(_0x53d1d9[_0xbbf5('0x3c')]['includeAll']){_0x5e163c[_0xbbf5('0x9a')]=[{'all':!![]}];}return db[_0xbbf5('0x5e')][_0xbbf5('0x3b')](_0x5e163c);})[_0xbbf5('0x15')](function(_0x56f697){_0x5ae9b3[_0xbbf5('0x9b')]=_0x56f697;return _0x5ae9b3;});}})[_0xbbf5('0x15')](respondWithFilteredResult(_0xc4cc9d,_0x5e163c))[_0xbbf5('0x20')](handleError(_0xc4cc9d,null));};exports[_0xbbf5('0xa0')]=function(_0x552d4c,_0x3a923e){return db[_0xbbf5('0x35')][_0xbbf5('0x48')]({'where':{'id':_0x552d4c[_0xbbf5('0x3f')]['id']}})[_0xbbf5('0x15')](handleEntityNotFound(_0x3a923e,null))[_0xbbf5('0x15')](function(_0x6159e8){if(_0x6159e8){return _0x6159e8[_0xbbf5('0xa1')](_0x552d4c[_0xbbf5('0x2f')][_0xbbf5('0x8c')],_['omit'](_0x552d4c['body'],[_0xbbf5('0x8c'),'id'])||{})[_0xbbf5('0xa2')](function(){return db[_0xbbf5('0xa3')]['findAll']({'attributes':['id',_0xbbf5('0x2c'),_0xbbf5('0xa4')],'where':{'id':_0x552d4c[_0xbbf5('0x2f')][_0xbbf5('0x8c')]}});})[_0xbbf5('0x15')](function(_0x2ac4e7){socket[_0xbbf5('0xa5')](_0xbbf5('0xa6'),{'id':Number(_0x552d4c['params']['id']),'tags':_0x2ac4e7||[]});return{'id':Number(_0x552d4c[_0xbbf5('0x3f')]['id']),'tags':_0x2ac4e7||[]};});}})[_0xbbf5('0x15')](respondWithResult(_0x3a923e,null))[_0xbbf5('0x20')](handleError(_0x3a923e,null));};exports[_0xbbf5('0xa7')]=function(_0x243a4c,_0x2a3009){return db[_0xbbf5('0x35')][_0xbbf5('0x48')]({'where':{'id':_0x243a4c[_0xbbf5('0x3f')]['id']}})[_0xbbf5('0x15')](handleEntityNotFound(_0x2a3009,null))['then'](function(_0x35a7a1){if(_0x35a7a1){return _0x35a7a1[_0xbbf5('0xa7')](_0x243a4c[_0xbbf5('0x3c')]['ids']);}})[_0xbbf5('0x15')](respondWithStatusCode(_0x2a3009,null))[_0xbbf5('0x20')](handleError(_0x2a3009,null));};exports['download']=function(_0x1d4188,_0x57c8b3){var _0x4ddb05=moment()[_0xbbf5('0xa8')]()[_0xbbf5('0xa9')]();var _0x252c44=path[_0xbbf5('0x70')](config[_0xbbf5('0x71')],_0xbbf5('0xaa'),_0xbbf5('0xab'),'tmp');var _0x3330c4=path[_0xbbf5('0x70')](config[_0xbbf5('0x71')],'server',_0xbbf5('0xab'),_0xbbf5('0xac'));var _0x31116d=path[_0xbbf5('0x70')](_0x252c44,_0x4ddb05);var _0x2084ad=util[_0xbbf5('0x76')]('transcript-%d-%s.zip',_0x1d4188[_0xbbf5('0x3f')]['id'],_0x4ddb05);var _0x469307=path[_0xbbf5('0x70')](_0x252c44,_0x2084ad);var _0x4a0fe0=[];_0x4a0fe0[_0xbbf5('0x9f')]({'model':db[_0xbbf5('0x79')],'as':'User','attributes':['id',_0xbbf5('0x50')],'raw':!![]});_0x4a0fe0[_0xbbf5('0x9f')]({'model':db[_0xbbf5('0x60')],'as':'Contact','attributes':['id',_0xbbf5('0xad'),'lastName'],'raw':!![]});if(_0x1d4188[_0xbbf5('0x3c')][_0xbbf5('0xac')]){_0x4a0fe0[_0xbbf5('0x9f')]({'model':db[_0xbbf5('0x6c')],'as':_0xbbf5('0x6c'),'raw':!![]});}var _0x4c6585=[{'model':db[_0xbbf5('0x5e')],'as':_0xbbf5('0x7a'),'attributes':['id',_0xbbf5('0x2f'),_0xbbf5('0x84'),'direction',_0xbbf5('0x9d'),_0xbbf5('0xae')],'include':_0x4a0fe0}];_0x4c6585['push']({'model':db['ChatWebsite'],'as':_0xbbf5('0xaf'),'attributes':['id','name']});_0x4c6585[_0xbbf5('0x9f')]({'model':db[_0xbbf5('0x79')],'as':_0xbbf5('0xb0'),'attributes':['id',_0xbbf5('0x50')]});return db[_0xbbf5('0x35')][_0xbbf5('0x48')]({'where':{'id':_0x1d4188['params']['id']},'include':_0x4c6585})['then'](handleEntityNotFound(_0x57c8b3,null))[_0xbbf5('0x15')](function(_0x1c7592){if(_0x1c7592){var _0x212223=_0x1c7592[_0xbbf5('0xb1')]({'plain':!![]});fs[_0xbbf5('0xb2')](_0x31116d);var _0x5efcdd={'channel':_0xbbf5('0xb3'),'account':_0x212223['Account'][_0xbbf5('0x2c')],'agent':_0x212223[_0xbbf5('0xb0')]?_0x212223['Owner']['fullname']:'N.A.','createdAt':moment(_0x212223['createdAt'])[_0xbbf5('0x76')](_0xbbf5('0x99'))['toString'](),'closedAt':_0x212223[_0xbbf5('0xb4')]?moment(_0x212223[_0xbbf5('0xb5')])['format']('YYYY-MM-DD\x20HH:mm:ss')[_0xbbf5('0xa9')]():'','disposition':_0x212223[_0xbbf5('0xb6')],'chatInfo':{'browser':_0x212223['browserName'],'os':_0x212223[_0xbbf5('0xb7')],'referer':_0x212223['referer'],'customerIp':_0x212223[_0xbbf5('0xb8')],'customerPort':_0x212223[_0xbbf5('0xb9')]?_0x212223[_0xbbf5('0xb9')]:_0xbbf5('0xba')},'messages':_(_0x212223[_0xbbf5('0x7a')])[_0xbbf5('0xbb')]()[_0xbbf5('0x96')]({'secret':![]})[_0xbbf5('0x34')](function(_0x4b73da){if(_0x4b73da['Attachment']){var _0x45c035=path[_0xbbf5('0x70')](_0x3330c4,_0x4b73da[_0xbbf5('0x6c')][_0xbbf5('0x69')]);if(fs['existsSync'](_0x45c035)){fs[_0xbbf5('0xbc')](_0x45c035)[_0xbbf5('0xbd')](fs[_0xbbf5('0xbe')](path[_0xbbf5('0x70')](_0x31116d,_0x4b73da[_0xbbf5('0x6c')]['basename'])));}}return{'date':moment(_0x4b73da[_0xbbf5('0x84')])[_0xbbf5('0x76')](_0xbbf5('0x99'))[_0xbbf5('0xa9')](),'sender':_0x4b73da['direction']==='out'?_0x4b73da[_0xbbf5('0x79')]?_0x4b73da[_0xbbf5('0x79')][_0xbbf5('0x50')]:_0xbbf5('0x7d'):_0x4b73da[_0xbbf5('0xbf')]['firstName']+(_0x4b73da['Contact'][_0xbbf5('0xc0')]?'\x20'+_0x4b73da['Contact'][_0xbbf5('0xc0')]:''),'body':_0x4b73da['Attachment']?_0x4b73da[_0xbbf5('0x6c')][_0xbbf5('0x69')]:_0x4b73da['body'],'direction':_0x4b73da[_0xbbf5('0xc1')]===_0xbbf5('0x5d')?'A':'C','secret':_0x4b73da['secret'],'read':_0x4b73da[_0xbbf5('0xae')],'attachment':_0x4b73da[_0xbbf5('0x6c')]};})[_0xbbf5('0xc2')]()};return ejs['renderFile'](path[_0xbbf5('0x70')](config[_0xbbf5('0x71')],_0xbbf5('0xaa'),_0xbbf5('0xc3'),_0xbbf5('0xc4')),{'interaction':_0x5efcdd})[_0xbbf5('0x15')](function(_0x15d7e7){var _0xbf0523=path[_0xbbf5('0x70')](_0x31116d,_0xbbf5('0xc5')+_0x212223['id']+'-'+_0x4ddb05+_0xbbf5('0xc6'));var _0x3a80b6={'path':_0xbf0523,'channel':_0xbbf5('0xb3'),'interactionId':_0x212223['id']};return pdf[_0xbbf5('0xc7')](_0x15d7e7,_0x3a80b6);})[_0xbbf5('0x15')](function(){return new Promise(function(_0x1ba24c,_0x2736be){zipdir(_0x31116d,{'saveTo':_0x469307},function(_0x4363d2,_0xdc0629){if(_0x4363d2)return _0x2736be(_0x4363d2);return _0x1ba24c(_0xdc0629);});})[_0xbbf5('0x15')](function(){return new BPromise(function(_0x48fce0,_0x5860a8){rimraf(_0x31116d,function(_0x319b0f){if(_0x319b0f)_0x5860a8(_0x319b0f);return _0x48fce0();});});})[_0xbbf5('0x15')](function(){return _0x57c8b3[_0xbbf5('0x73')](_0x469307,_0x2084ad,function(_0x504b03){if(_0x504b03){logger[_0xbbf5('0x1a')]('err',_0x504b03);}else{fs[_0xbbf5('0xc8')](_0x469307);}});});});}else{return _0x57c8b3[_0xbbf5('0x21')](0xc8);}})[_0xbbf5('0x20')](handleError(_0x57c8b3,null));};
\ No newline at end of file