Built motion from commit d1eab355.|2.6.28
[motion2.git] / server / api / chatInteraction / chatInteraction.controller.js
index 9147f62..5b4cde8 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x52f2=['update','stack','name','send','render','merge','contact','agent','index','map','ChatInteraction','fieldName','type','key','chat','query','user','show','model','keys','rawAttributes','filters','intersection','attributes','fields','includeAll','include','options','find','create','body','params','destroy','describe','createVidaooSession','findOne','ChatWebsiteId','vidaooEscalation','vidaooTopic','vidaooMetadata','vidaooApiKey','fullname','email','https://api-vidaoo.xcally.com/api/v1/meetings','isNull','vidaooNote','parse','metadata','Sequelize','Error\x20in\x20conversion\x20vidaooMetadata','ValidationError','join_url','ChatMessage','CmContact','Contact','abandon','abandonInteraction,\x20%s,\x20%s,\x20%s','entity\x20not\x20found','UserId','Interaction\x20already\x20assigned','closed','file','filename','mimetype','Attachment','attachmentDownload','Unauthorized','attachId','ChatOfflineMessageId','join','basename','download','close','mailTranscript','root','format','transcript-%s.txt','now','pathTranscript','User','Messages','length','agentAlias','System','customer','%s%d','ContactId','agent_fullname','[%s]\x20%s:\x20%s\x0a','createdAt','direction','secret','appendFileSync','MailAccount','MailServerOut','Smtp','getSmtpOptions','sendMail','\x22%s\x22\x20<%s>','addMessage','ids','omit','nolimit','order','sort','where','pick','ChatInteractionId','filter','$gte','split','YYYY-MM-DD\x20HH:mm:ss','findAll','rows','getMyMessages','hasOwnProperty','includeAgent','push','alias','addTags','setTags','spread','Tag','color','emit','removeTags','unix','toString','server','files','tmp','attachments','lastName','read','ChatWebsite','Account','Owner','get','mkdirSync','Chat','N.A.','closedAt','disposition','browserName','osName','referer','customerIp','customerPort','tail','createReadStream','pipe','out','firstName','value','views','downloadInteraction.ejs','transcript-','.pdf','createPdfFromHTML','err','unlinkSync','zip-dir','moment','bluebird','mustache','util','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../config/logger','api','../../config/environment','redis','defaults','localhost','./chatInteraction.socket','register','jayson/promise','client','http','request','then','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','ChatInteraction,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','json','offset','limit','undefined','count','set'];(function(_0xa3d443,_0x121b37){var _0x489486=function(_0x16ecd1){while(--_0x16ecd1){_0xa3d443['push'](_0xa3d443['shift']());}};_0x489486(++_0x121b37);}(_0x52f2,0x16b));var _0x252f=function(_0x9aada2,_0xd2d349){_0x9aada2=_0x9aada2-0x0;var _0x196dff=_0x52f2[_0x9aada2];return _0x196dff;};'use strict';var rimraf=require('rimraf');var zipdir=require(_0x252f('0x0'));var rp=require('request-promise');var moment=require(_0x252f('0x1'));var BPromise=require(_0x252f('0x2'));var Mustache=require(_0x252f('0x3'));var util=require(_0x252f('0x4'));var path=require('path');var ejs=require('ejs');var fs=require('fs');var _=require(_0x252f('0x5'));var Redis=require(_0x252f('0x6'));var interaction=require(_0x252f('0x7'));var qs=require(_0x252f('0x8'));var pdf=require('../../components/export/pdf');var logger=require(_0x252f('0x9'))(_0x252f('0xa'));var config=require(_0x252f('0xb'));var db=require('../../mysqldb')['db'];config[_0x252f('0xc')]=_[_0x252f('0xd')](config[_0x252f('0xc')],{'host':_0x252f('0xe'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x252f('0xc')]));require(_0x252f('0xf'))[_0x252f('0x10')](socket);var jayson=require(_0x252f('0x11'));var client=jayson[_0x252f('0x12')][_0x252f('0x13')]({'port':0x232b});var client9004=jayson['client'][_0x252f('0x13')]({'port':0x232c});function respondWithRpcPromise(_0x54c569,_0x2487cf,_0x240724,_0x1d6059){return new BPromise(function(_0xbc81a,_0x44da4e){var _0x1caae9=_0x1d6059||client;return _0x1caae9[_0x252f('0x14')](_0x54c569,_0x240724)[_0x252f('0x15')](function(_0x3e8db6){logger['info']('ChatInteraction,\x20%s,\x20%s',_0x2487cf,_0x252f('0x16'));logger[_0x252f('0x17')](_0x252f('0x18'),_0x2487cf,_0x252f('0x16'),JSON[_0x252f('0x19')](_0x3e8db6));if(_0x3e8db6[_0x252f('0x1a')]){if(_0x3e8db6['error'][_0x252f('0x1b')]===0x1f4){logger['error'](_0x252f('0x1c'),_0x2487cf,_0x3e8db6[_0x252f('0x1a')][_0x252f('0x1d')]);return _0x44da4e(_0x3e8db6['error'][_0x252f('0x1d')]);}logger[_0x252f('0x1a')](_0x252f('0x1c'),_0x2487cf,_0x3e8db6[_0x252f('0x1a')]['message']);return _0xbc81a(_0x3e8db6[_0x252f('0x1a')][_0x252f('0x1d')]);}else{logger['info'](_0x252f('0x1c'),_0x2487cf,'request\x20sent');_0xbc81a(_0x3e8db6[_0x252f('0x1e')]['message']);}})[_0x252f('0x1f')](function(_0x578f73){logger[_0x252f('0x1a')](_0x252f('0x1c'),_0x2487cf,_0x578f73);_0x44da4e(_0x578f73);});});}function respondWithStatusCode(_0xfd680f,_0x1339e4){_0x1339e4=_0x1339e4||0xcc;return function(_0xd94eeb){if(_0xd94eeb){return _0xfd680f[_0x252f('0x20')](_0x1339e4);}return _0xfd680f[_0x252f('0x21')](_0x1339e4)[_0x252f('0x22')]();};}function respondWithResult(_0x145199,_0x52e810){_0x52e810=_0x52e810||0xc8;return function(_0x484169){if(_0x484169){return _0x145199[_0x252f('0x21')](_0x52e810)[_0x252f('0x23')](_0x484169);}};}function respondWithFilteredResult(_0x5a2b37,_0x1ab2d7){return function(_0x1916f6){if(_0x1916f6){var _0x286ae0=typeof _0x1ab2d7[_0x252f('0x24')]==='undefined'&&typeof _0x1ab2d7[_0x252f('0x25')]===_0x252f('0x26');var _0x32b1e8=_0x1916f6[_0x252f('0x27')];var _0x4649a6=_0x286ae0?0x0:_0x1ab2d7[_0x252f('0x24')];var _0xcea077=_0x286ae0?_0x1916f6[_0x252f('0x27')]:_0x1ab2d7[_0x252f('0x24')]+_0x1ab2d7[_0x252f('0x25')];var _0x50c773;if(_0xcea077>=_0x32b1e8){_0xcea077=_0x32b1e8;_0x50c773=0xc8;}else{_0x50c773=0xce;}_0x5a2b37[_0x252f('0x21')](_0x50c773);return _0x5a2b37[_0x252f('0x28')]('Content-Range',_0x4649a6+'-'+_0xcea077+'/'+_0x32b1e8)[_0x252f('0x23')](_0x1916f6);}return null;};}function saveUpdates(_0xa75d72){return function(_0x54a958){if(_0x54a958){return _0x54a958[_0x252f('0x29')](_0xa75d72)[_0x252f('0x15')](function(_0x56006c){return _0x56006c;});}return null;};}function removeEntity(_0x21f960){return function(_0x8fd69a){if(_0x8fd69a){return _0x8fd69a['destroy']()[_0x252f('0x15')](function(){_0x21f960[_0x252f('0x21')](0xcc)['end']();});}};}function handleEntityNotFound(_0x48974c){return function(_0x4bd72f){if(!_0x4bd72f){_0x48974c[_0x252f('0x20')](0x194);}return _0x4bd72f;};}function handleError(_0x431955,_0x52fc83){_0x52fc83=_0x52fc83||0x1f4;return function(_0x3e8605){logger[_0x252f('0x1a')](_0x3e8605[_0x252f('0x2a')]);if(_0x3e8605[_0x252f('0x2b')]){delete _0x3e8605['name'];}_0x431955[_0x252f('0x21')](_0x52fc83)[_0x252f('0x2c')](_0x3e8605);};}function getMustacheRender(_0x5a0b48,_0x2ac684){return Mustache[_0x252f('0x2d')](_0x5a0b48,_[_0x252f('0x2e')](_0x2ac684['body'],{'contact':_0x2ac684[_0x252f('0x2f')],'message':_0x2ac684[_0x252f('0x1d')],'agent':_0x2ac684[_0x252f('0x30')],'interaction':_0x2ac684['interaction'],'account':_0x2ac684['account']}))||'';}exports[_0x252f('0x31')]=function(_0x4592ce,_0x1ddb21){var _0x510368={};var _0x200d06=_[_0x252f('0x32')](db[_0x252f('0x33')]['rawAttributes'],function(_0x147dcc){return{'name':_0x147dcc[_0x252f('0x34')],'type':_0x147dcc[_0x252f('0x35')][_0x252f('0x36')]};});_0x510368=qs['getOptions'](_0x200d06,_0x4592ce);return interaction['findAll'](_0x252f('0x37'),_0x4592ce[_0x252f('0x38')],_0x4592ce[_0x252f('0x39')],_0x510368,_0x200d06)[_0x252f('0x15')](respondWithFilteredResult(_0x1ddb21,_0x510368))[_0x252f('0x1f')](handleError(_0x1ddb21,null));};exports[_0x252f('0x3a')]=function(_0xf5973c,_0x38e393){var _0x563161={'raw':![],'where':{'id':_0xf5973c['params']['id']}},_0x259a39={};_0x259a39[_0x252f('0x3b')]=_[_0x252f('0x3c')](db[_0x252f('0x33')][_0x252f('0x3d')]);_0x259a39[_0x252f('0x38')]=_[_0x252f('0x3c')](_0xf5973c[_0x252f('0x38')]);_0x259a39[_0x252f('0x3e')]=_[_0x252f('0x3f')](_0x259a39['model'],_0x259a39['query']);_0x563161[_0x252f('0x40')]=_[_0x252f('0x3f')](_0x259a39['model'],qs[_0x252f('0x41')](_0xf5973c['query'][_0x252f('0x41')]));_0x563161[_0x252f('0x40')]=_0x563161[_0x252f('0x40')]['length']?_0x563161[_0x252f('0x40')]:_0x259a39[_0x252f('0x3b')];if(_0xf5973c['query'][_0x252f('0x42')]){_0x563161[_0x252f('0x43')]=[{'all':!![]}];}_0x563161=_[_0x252f('0x2e')]({},_0x563161,_0xf5973c[_0x252f('0x44')]);return db['ChatInteraction'][_0x252f('0x45')](_0x563161)[_0x252f('0x15')](handleEntityNotFound(_0x38e393,null))['then'](respondWithResult(_0x38e393,null))[_0x252f('0x1f')](handleError(_0x38e393,null));};exports[_0x252f('0x46')]=function(_0xb10a0b,_0x3af9a9){return db[_0x252f('0x33')][_0x252f('0x46')](_0xb10a0b[_0x252f('0x47')],{})['then'](respondWithResult(_0x3af9a9,0xc9))[_0x252f('0x1f')](handleError(_0x3af9a9,null));};exports['update']=function(_0x321d6f,_0x5a33ec){if(_0x321d6f[_0x252f('0x47')]['id']){delete _0x321d6f['body']['id'];}return db[_0x252f('0x33')][_0x252f('0x45')]({'where':{'id':_0x321d6f[_0x252f('0x48')]['id']}})[_0x252f('0x15')](handleEntityNotFound(_0x5a33ec,null))[_0x252f('0x15')](saveUpdates(_0x321d6f[_0x252f('0x47')],null))['then'](respondWithResult(_0x5a33ec,null))[_0x252f('0x1f')](handleError(_0x5a33ec,null));};exports[_0x252f('0x49')]=function(_0x45724b,_0x548f06){return db['ChatInteraction']['find']({'where':{'id':_0x45724b[_0x252f('0x48')]['id']}})[_0x252f('0x15')](handleEntityNotFound(_0x548f06,null))[_0x252f('0x15')](removeEntity(_0x548f06,null))['catch'](handleError(_0x548f06,null));};exports[_0x252f('0x4a')]=function(_0x51ef3b,_0x4fbf88){return db[_0x252f('0x33')][_0x252f('0x4a')]()[_0x252f('0x15')](respondWithResult(_0x4fbf88,null))['catch'](handleError(_0x4fbf88,null));};exports[_0x252f('0x4b')]=function(_0x1da66b,_0x5571da){var _0x1f0c1e=_0x1da66b['params']['id'];var _0x2f1df8;var _0x5df2c0;var _0x337ba9;return db['ChatInteraction'][_0x252f('0x4c')]({'where':{'id':_0x1f0c1e}})[_0x252f('0x15')](function(_0x3de19b){_0x2f1df8=_0x3de19b;return db['ChatWebsite'][_0x252f('0x4c')]({'where':{'id':_0x3de19b[_0x252f('0x4d')]},'attributes':['id','vidaooApiKey',_0x252f('0x4e'),_0x252f('0x4f'),'vidaooNote',_0x252f('0x50')],'raw':!![]});})[_0x252f('0x15')](function(_0x244a99){if(_0x244a99&&_0x244a99[_0x252f('0x51')]&&_0x244a99['vidaooEscalation']){_0x5df2c0=_0x244a99;var _0x1ac587={'interaction':{'id':_0x1f0c1e},'agent':{'id':_0x1da66b[_0x252f('0x39')]['id'],'name':_0x1da66b[_0x252f('0x39')][_0x252f('0x2b')],'fullname':_0x1da66b[_0x252f('0x39')][_0x252f('0x52')],'email':_0x1da66b[_0x252f('0x39')][_0x252f('0x53')]},'contact':_0x1da66b[_0x252f('0x47')]['contact'],'account':_0x1da66b[_0x252f('0x47')]['account']};var _0x5e24bb={'rejectUnauthorized':![],'method':'POST','url':_0x252f('0x54'),'headers':{'X-APIKEY':_0x244a99[_0x252f('0x51')]},'body':{'duration':null,'scheduledAt':null,'participants':[_0x1da66b['user']['email']],'buttons':null,'topic':_0x5df2c0[_0x252f('0x4f')],'note':_[_0x252f('0x55')](_0x5df2c0[_0x252f('0x56')])?null:getMustacheRender(_0x5df2c0[_0x252f('0x56')],_0x1ac587),'metadata':null},'redirect':'follow','json':!![]};try{if(!_['isNull'](_0x5df2c0['vidaooMetadata'])){var _0x40b15d=getMustacheRender(_0x5df2c0[_0x252f('0x50')],_0x1ac587);var _0x1e520e=JSON[_0x252f('0x57')](_0x40b15d);_0x5e24bb[_0x252f('0x47')][_0x252f('0x58')]=_0x1e520e;}}catch(_0x13a5b0){throw new db[(_0x252f('0x59'))]['ValidationError'](_0x252f('0x5a'));}return rp(_0x5e24bb);}else{throw new db['Sequelize'][(_0x252f('0x5b'))]('Error\x20in\x20Vidaoo\x20configuration');}})[_0x252f('0x15')](function(_0x44d7a2){_0x337ba9=_0x44d7a2;if(_0x337ba9['id']){var _0x543e51={'body':_0x337ba9[_0x252f('0x5c')],'ChatWebsiteId':_0x5df2c0['id'],'ChatInteractionId':_0x2f1df8['id'],'direction':'out','UserId':_0x1da66b[_0x252f('0x39')]['id']};return db[_0x252f('0x5d')][_0x252f('0x46')](_0x543e51,{});}else{throw new db[(_0x252f('0x59'))][(_0x252f('0x5b'))]('Unable\x20to\x20create\x20Vidaoo\x20session');}})[_0x252f('0x15')](function(){return _0x2f1df8['updateAttributes']({'vidaooSessionId':_0x337ba9['id']});})['then'](respondWithResult(_0x5571da,null))[_0x252f('0x1f')](handleError(_0x5571da,null));};exports['customUpdate']=function(_0x3d1f6a,_0x20fa60){if(_0x3d1f6a['body']['id']){delete _0x3d1f6a[_0x252f('0x47')]['id'];}return db[_0x252f('0x33')][_0x252f('0x45')]({'where':{'id':_0x3d1f6a[_0x252f('0x48')]['id']},'include':[{'model':db[_0x252f('0x5e')],'as':_0x252f('0x5f')}]})[_0x252f('0x15')](handleEntityNotFound(_0x20fa60,null))[_0x252f('0x15')](saveUpdates(_0x3d1f6a[_0x252f('0x47')],null))[_0x252f('0x15')](respondWithResult(_0x20fa60,null))[_0x252f('0x1f')](handleError(_0x20fa60,null));};exports[_0x252f('0x60')]=function(_0x293723,_0x29d904){if(_0x293723[_0x252f('0x47')]['id']){delete _0x293723['body']['id'];}return db[_0x252f('0x33')][_0x252f('0x45')]({'where':{'id':_0x293723['params']['id']}})[_0x252f('0x15')](function(_0x22e4dc){if(!_0x22e4dc){logger[_0x252f('0x1a')](_0x252f('0x61'),_0x252f('0x60'),0x194,_0x252f('0x62'));_0x29d904[_0x252f('0x20')](0x194);}else{if(_0x22e4dc[_0x252f('0x63')]){throw new db[(_0x252f('0x59'))][(_0x252f('0x5b'))](_0x252f('0x64'));}}return _0x22e4dc;})[_0x252f('0x15')](function(_0x4e8f0e){if(_0x4e8f0e){return _0x4e8f0e[_0x252f('0x29')]({'closed':_0x293723['body'][_0x252f('0x65')],'disposition':_0x293723[_0x252f('0x47')]['disposition']})[_0x252f('0x15')](function(_0x3b6362){return _0x3b6362;});}})[_0x252f('0x15')](function(){return respondWithRpcPromise('AbandonInteraction',_0x252f('0x60'),_0x293723[_0x252f('0x47')],client9004);})['then'](respondWithResult(_0x29d904,null))[_0x252f('0x1f')](handleError(_0x29d904,null));};exports['attachmentUpload']=function(_0x842418,_0x515d5d){_0x842418[_0x252f('0x47')][_0x252f('0x2b')]=_0x842418[_0x252f('0x66')]['originalname'];_0x842418[_0x252f('0x47')]['basename']=_0x842418[_0x252f('0x66')][_0x252f('0x67')];_0x842418['body'][_0x252f('0x35')]=_0x842418[_0x252f('0x66')][_0x252f('0x68')];return db[_0x252f('0x69')][_0x252f('0x46')](_0x842418[_0x252f('0x47')])['then'](respondWithResult(_0x515d5d,0xc9))[_0x252f('0x1f')](handleError(_0x515d5d,null));};exports[_0x252f('0x6a')]=function(_0x32ff64,_0x7efec0){return db[_0x252f('0x33')][_0x252f('0x4c')]({'where':{'id':_0x32ff64['params']['id']},'raw':!![]})[_0x252f('0x15')](handleEntityNotFound(_0x7efec0,null))['then'](function(_0x2e559b){if(_0x2e559b){if(_0x2e559b[_0x252f('0x65')]){return _0x7efec0[_0x252f('0x21')](0x193)['json']({'status':0x193,'message':_0x252f('0x6b')});}return db[_0x252f('0x69')]['findOne']({'where':{'id':_0x32ff64[_0x252f('0x38')][_0x252f('0x6c')]},'raw':!![]})[_0x252f('0x15')](handleEntityNotFound(_0x7efec0,null));}})[_0x252f('0x15')](function(_0xd05024){if(_0xd05024){var _0x4ac8ed=_0xd05024[_0x252f('0x6d')]!==null;var _0x4aed6a=path[_0x252f('0x6e')](config['root'],'server/files/attachments/');if(_0x4ac8ed){_0x4aed6a=path[_0x252f('0x6e')](_0x4aed6a,'offline-chat/');}var _0x1a29df=path[_0x252f('0x6e')](_0x4aed6a,_0xd05024[_0x252f('0x6f')]);return _0x7efec0[_0x252f('0x70')](_0x1a29df);}})['catch'](handleError(_0x7efec0,null));};exports[_0x252f('0x71')]=function(_0xa2d280,_0x20376c){var _0x5ec61f=null;var _0x4a815f=null;var _0xe7431b=null;if(_0xa2d280[_0x252f('0x47')]['id']){delete _0xa2d280[_0x252f('0x47')]['id'];}if(_0xa2d280[_0x252f('0x47')][_0x252f('0x72')]){_0xe7431b=path[_0x252f('0x6e')](config[_0x252f('0x73')],'server/files/chat/upload/',util[_0x252f('0x74')](_0x252f('0x75'),Date[_0x252f('0x76')]()));_0xa2d280['body'][_0x252f('0x77')]=_0xe7431b;}return db['ChatInteraction']['find']({'where':{'id':_0xa2d280[_0x252f('0x48')]['id']},'include':[{'model':db['ChatMessage'],'as':'Messages','include':[{'model':db[_0x252f('0x78')],'as':_0x252f('0x78')}]}]})[_0x252f('0x15')](handleEntityNotFound(_0x20376c,null))[_0x252f('0x15')](saveUpdates(_0xa2d280['body'],null))[_0x252f('0x15')](function(_0x2a16b0){if(_0x2a16b0){_0x5ec61f=_0x2a16b0;return db['ChatWebsite'][_0x252f('0x45')]({'where':{'id':_0x5ec61f['ChatWebsiteId']}});}})[_0x252f('0x15')](function(_0x2291fe){if(_0x2291fe){_0x4a815f=_0x2291fe;return db[_0x252f('0x5e')][_0x252f('0x45')]({'where':{'id':_0x5ec61f['ContactId']}});}})[_0x252f('0x15')](function(_0x2fd6f0){if(_0x2fd6f0){if(_0xe7431b){var _0x1e022f=null;for(var _0x18aa9c=0x1;_0x18aa9c<_0x5ec61f[_0x252f('0x79')][_0x252f('0x7a')];++_0x18aa9c){_0x1e022f=_0x5ec61f[_0x252f('0x79')][_0x18aa9c];var _0x33c37c=_0x1e022f[_0x252f('0x63')]?util[_0x252f('0x74')]('%s%d',_0x4a815f[_0x252f('0x7b')],_0x1e022f[_0x252f('0x63')]):_0x252f('0x7c');var _0x2741b9=_0xa2d280[_0x252f('0x47')][_0x252f('0x7d')]||util['format'](_0x252f('0x7e'),'Visitor',_0x1e022f[_0x252f('0x7f')]);switch(_0x4a815f['agentIdentifier']){case'website_alias':_0x33c37c=_0x1e022f[_0x252f('0x63')]?util[_0x252f('0x74')](_0x252f('0x7e'),_0x4a815f['agentAlias'],_0x1e022f[_0x252f('0x63')]):_0x252f('0x7c');break;case'agent_alias':_0x33c37c=_0x1e022f[_0x252f('0x63')]?_0x1e022f['User']['alias']||_0x1e022f[_0x252f('0x78')][_0x252f('0x52')]:_0x252f('0x7c');break;case _0x252f('0x80'):_0x33c37c=_0x1e022f[_0x252f('0x63')]?_0x1e022f['User'][_0x252f('0x52')]:_0x252f('0x7c');break;default:_0x33c37c=_0x1e022f['UserId']?util[_0x252f('0x74')](_0x252f('0x7e'),_0x4a815f['agentAlias'],_0x1e022f[_0x252f('0x63')]):_0x252f('0x7c');}var _0x3a207e=util[_0x252f('0x74')](_0x252f('0x81'),moment(_0x1e022f[_0x252f('0x82')])[_0x252f('0x74')]('MM/DD/YYYY\x20HH:mm:ss'),_0x1e022f[_0x252f('0x83')]==='in'?_0x2741b9:_0x33c37c,_0x1e022f[_0x252f('0x47')]);if(!_0x1e022f[_0x252f('0x84')]){fs[_0x252f('0x85')](_0xe7431b,_0x3a207e);}}return db[_0x252f('0x86')][_0x252f('0x4c')]({'where':{'service':!![]},'include':[{'model':db[_0x252f('0x87')],'as':_0x252f('0x88'),'raw':!![],'include':[{'model':db['CloudProvider'],'as':'CloudProvider','raw':!![]}]}]});}}})[_0x252f('0x15')](function(_0xe42d5){if(!_0xe42d5||!_0xe42d5['Smtp']||!_0xa2d280[_0x252f('0x47')])return _0x5ec61f;var _0x55d4b7=_0xe42d5[_0x252f('0x89')]();return respondWithRpcPromise('SendMail',_0x252f('0x8a'),{'account':_0x55d4b7,'message':{'from':util['format'](_0x252f('0x8b'),_0xe42d5[_0x252f('0x2b')],_0xe42d5[_0x252f('0x53')]||_0xe42d5[_0x252f('0x88')][_0x252f('0x39')]),'to':_0xa2d280[_0x252f('0x47')]['mailTranscript'],'subject':'Mail\x20Transcript','text':util['format']('Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a',_0xa2d280[_0x252f('0x47')]['mailTranscript']),'attachments':[{'path':_0xe7431b}]}})[_0x252f('0x15')](function(){return _0x5ec61f;})[_0x252f('0x1f')](function(_0x4178b7){logger[_0x252f('0x1a')](_0x4178b7);});})[_0x252f('0x15')](respondWithStatusCode(_0x20376c,0xc8))['catch'](handleError(_0x20376c,null));};exports['addMessage']=function(_0x112c9a,_0x5109af){return db[_0x252f('0x5d')][_0x252f('0x45')]({'where':{'id':_0x112c9a[_0x252f('0x48')]['id']}})[_0x252f('0x15')](handleEntityNotFound(_0x5109af,null))[_0x252f('0x15')](function(_0x3b7fbf){if(_0x3b7fbf){return _0x3b7fbf[_0x252f('0x8c')](_0x112c9a[_0x252f('0x47')][_0x252f('0x8d')],_[_0x252f('0x8e')](_0x112c9a[_0x252f('0x47')],[_0x252f('0x8d'),'id'])||{});}})[_0x252f('0x15')](respondWithResult(_0x5109af,null))[_0x252f('0x1f')](handleError(_0x5109af,null));};exports['getMessages']=function(_0x58de24,_0x8b464a){var _0x28644b={'raw':![],'where':{}};var _0x1cc4fa={};var _0x245faa={'count':0x0,'rows':[]};return db[_0x252f('0x33')][_0x252f('0x4c')]({'where':{'id':_0x58de24[_0x252f('0x48')]['id']}})[_0x252f('0x15')](handleEntityNotFound(_0x8b464a,null))[_0x252f('0x15')](function(_0x328dbd){if(_0x328dbd){_0x1cc4fa[_0x252f('0x3b')]=_[_0x252f('0x3c')](db['ChatMessage'][_0x252f('0x3d')]);_0x1cc4fa[_0x252f('0x38')]=_['keys'](_0x58de24[_0x252f('0x38')]);_0x1cc4fa[_0x252f('0x3e')]=_['intersection'](_0x1cc4fa[_0x252f('0x3b')],_0x1cc4fa[_0x252f('0x38')]);_0x28644b[_0x252f('0x40')]=_[_0x252f('0x3f')](_0x1cc4fa[_0x252f('0x3b')],qs['fields'](_0x58de24[_0x252f('0x38')][_0x252f('0x41')]));_0x28644b[_0x252f('0x40')]=_0x28644b[_0x252f('0x40')][_0x252f('0x7a')]?_0x28644b[_0x252f('0x40')]:_0x1cc4fa[_0x252f('0x3b')];if(!_0x58de24[_0x252f('0x38')]['hasOwnProperty'](_0x252f('0x8f'))){_0x28644b[_0x252f('0x25')]=qs[_0x252f('0x25')](_0x58de24[_0x252f('0x38')][_0x252f('0x25')]);_0x28644b['offset']=qs[_0x252f('0x24')](_0x58de24['query'][_0x252f('0x24')]);}_0x28644b[_0x252f('0x90')]=qs['sort'](_0x58de24[_0x252f('0x38')][_0x252f('0x91')]);_0x28644b[_0x252f('0x92')]=qs[_0x252f('0x3e')](_[_0x252f('0x93')](_0x58de24['query'],_0x1cc4fa[_0x252f('0x3e')]));_0x28644b[_0x252f('0x92')][_0x252f('0x94')]=_0x328dbd['id'];if(_0x58de24[_0x252f('0x38')][_0x252f('0x95')]){_0x28644b[_0x252f('0x92')]=_[_0x252f('0x2e')](_0x28644b[_0x252f('0x92')],{'$or':_[_0x252f('0x32')](_0x28644b[_0x252f('0x40')],function(_0x5405dd){var _0x4441a2={};_0x4441a2[_0x5405dd]={'$like':'%'+_0x58de24[_0x252f('0x38')]['filter']+'%'};return _0x4441a2;})});}if(_0x58de24[_0x252f('0x38')][_0x252f('0x96')]){var _0x3f56ac=_0x58de24[_0x252f('0x38')][_0x252f('0x96')][_0x252f('0x97')](',');var _0x19ed10={};_0x19ed10[_0x3f56ac[0x0]]={'$gte':moment(_0x3f56ac[0x1])['format'](_0x252f('0x98'))};_0x28644b['where']=_[_0x252f('0x2e')](_0x28644b[_0x252f('0x92')],_0x19ed10);}_0x28644b=_['merge']({},_0x28644b,_0x58de24[_0x252f('0x44')]);return db[_0x252f('0x5d')][_0x252f('0x27')]({'where':_0x28644b['where']})[_0x252f('0x15')](function(_0x327441){_0x245faa['count']=_0x327441;if(_0x58de24['query']['includeAll']){_0x28644b['include']=[{'all':!![]}];}return db['ChatMessage'][_0x252f('0x99')](_0x28644b);})[_0x252f('0x15')](function(_0x186815){_0x245faa[_0x252f('0x9a')]=_0x186815;return _0x245faa;});}})[_0x252f('0x15')](respondWithFilteredResult(_0x8b464a,_0x28644b))[_0x252f('0x1f')](handleError(_0x8b464a,null));};exports[_0x252f('0x9b')]=function(_0x21cac0,_0x2e6e08){var _0x2f228c={'where':{}},_0x5c454b={},_0x10cbc4={'count':0x0,'rows':[]};return db[_0x252f('0x33')][_0x252f('0x4c')]({'where':{'id':_0x21cac0[_0x252f('0x48')]['id']}})[_0x252f('0x15')](handleEntityNotFound(_0x2e6e08,null))[_0x252f('0x15')](function(_0x477eb3){if(_0x477eb3){_0x5c454b['model']=_[_0x252f('0x3c')](db[_0x252f('0x5d')][_0x252f('0x3d')]);_0x5c454b[_0x252f('0x38')]=_[_0x252f('0x3c')](_0x21cac0['query']);_0x5c454b['filters']=_[_0x252f('0x3f')](_0x5c454b[_0x252f('0x3b')],_0x5c454b[_0x252f('0x38')]);_0x2f228c[_0x252f('0x40')]=_[_0x252f('0x3f')](_0x5c454b[_0x252f('0x3b')],qs[_0x252f('0x41')](_0x21cac0['query']['fields']));_0x2f228c[_0x252f('0x40')]=_0x2f228c[_0x252f('0x40')][_0x252f('0x7a')]?_0x2f228c[_0x252f('0x40')]:_0x5c454b[_0x252f('0x3b')];if(!_0x21cac0['query'][_0x252f('0x9c')](_0x252f('0x8f'))){_0x2f228c['limit']=qs[_0x252f('0x25')](_0x21cac0[_0x252f('0x38')][_0x252f('0x25')]);_0x2f228c[_0x252f('0x24')]=qs[_0x252f('0x24')](_0x21cac0['query'][_0x252f('0x24')]);}_0x2f228c[_0x252f('0x90')]=qs[_0x252f('0x91')](_0x21cac0['query'][_0x252f('0x91')]);_0x2f228c[_0x252f('0x92')]=qs[_0x252f('0x3e')](_[_0x252f('0x93')](_0x21cac0['query'],_0x5c454b[_0x252f('0x3e')]));_0x2f228c[_0x252f('0x92')][_0x252f('0x94')]=_0x477eb3['id'];if(_0x21cac0[_0x252f('0x38')][_0x252f('0x95')]){_0x2f228c[_0x252f('0x92')]=_[_0x252f('0x2e')](_0x2f228c['where'],{'$or':_[_0x252f('0x32')](_0x2f228c[_0x252f('0x40')],function(_0x47ed1b){var _0x1b5e17={};_0x1b5e17[_0x47ed1b]={'$like':'%'+_0x21cac0[_0x252f('0x38')][_0x252f('0x95')]+'%'};return _0x1b5e17;})});}_0x2f228c['where'][_0x252f('0x84')]=![];if(_0x21cac0['query']['id']){_0x2f228c['where']['id']={'$gt':_0x21cac0[_0x252f('0x38')]['id']};}_0x2f228c=_[_0x252f('0x2e')]({},_0x2f228c,_0x21cac0[_0x252f('0x44')]);return db[_0x252f('0x5d')]['count']({'where':_0x2f228c['where']})[_0x252f('0x15')](function(_0x5978ba){_0x10cbc4[_0x252f('0x27')]=_0x5978ba;_0x2f228c['include']=[];if(_0x21cac0[_0x252f('0x38')][_0x252f('0x9d')]){_0x2f228c['include'][_0x252f('0x9e')]({'model':db[_0x252f('0x78')],'as':_0x252f('0x78'),'attributes':['id',_0x252f('0x52'),_0x252f('0x9f')]});}if(_0x21cac0[_0x252f('0x38')][_0x252f('0x42')]){_0x2f228c[_0x252f('0x43')]=[{'all':!![]}];}return db['ChatMessage'][_0x252f('0x99')](_0x2f228c);})[_0x252f('0x15')](function(_0x50171c){_0x10cbc4['rows']=_0x50171c;return _0x10cbc4;});}})['then'](respondWithFilteredResult(_0x2e6e08,_0x2f228c))[_0x252f('0x1f')](handleError(_0x2e6e08,null));};exports[_0x252f('0xa0')]=function(_0x392b5f,_0xc9ab90){return db[_0x252f('0x33')]['find']({'where':{'id':_0x392b5f[_0x252f('0x48')]['id']}})[_0x252f('0x15')](handleEntityNotFound(_0xc9ab90,null))[_0x252f('0x15')](function(_0x202ab3){if(_0x202ab3){return _0x202ab3[_0x252f('0xa1')](_0x392b5f[_0x252f('0x47')][_0x252f('0x8d')],_['omit'](_0x392b5f[_0x252f('0x47')],[_0x252f('0x8d'),'id'])||{})[_0x252f('0xa2')](function(){return db[_0x252f('0xa3')]['findAll']({'attributes':['id',_0x252f('0x2b'),_0x252f('0xa4')],'where':{'id':_0x392b5f['body']['ids']}});})['then'](function(_0x50284d){socket[_0x252f('0xa5')]('chatInteractionTags:save',{'id':Number(_0x392b5f['params']['id']),'tags':_0x50284d||[]});return{'id':Number(_0x392b5f[_0x252f('0x48')]['id']),'tags':_0x50284d||[]};});}})[_0x252f('0x15')](respondWithResult(_0xc9ab90,null))['catch'](handleError(_0xc9ab90,null));};exports[_0x252f('0xa6')]=function(_0x32d409,_0x457d78){return db['ChatInteraction'][_0x252f('0x45')]({'where':{'id':_0x32d409['params']['id']}})['then'](handleEntityNotFound(_0x457d78,null))['then'](function(_0x438cf0){if(_0x438cf0){return _0x438cf0[_0x252f('0xa6')](_0x32d409['query'][_0x252f('0x8d')]);}})[_0x252f('0x15')](respondWithStatusCode(_0x457d78,null))['catch'](handleError(_0x457d78,null));};exports[_0x252f('0x70')]=function(_0x501524,_0x19481d){var _0x1419a9=moment()[_0x252f('0xa7')]()[_0x252f('0xa8')]();var _0x5a4827=path[_0x252f('0x6e')](config[_0x252f('0x73')],_0x252f('0xa9'),_0x252f('0xaa'),_0x252f('0xab'));var _0x29de57=path[_0x252f('0x6e')](config['root'],_0x252f('0xa9'),'files',_0x252f('0xac'));var _0x192d2f=path[_0x252f('0x6e')](_0x5a4827,_0x1419a9);var _0x1d0baa=util['format']('transcript-%d-%s.zip',_0x501524[_0x252f('0x48')]['id'],_0x1419a9);var _0x3fdc34=path['join'](_0x5a4827,_0x1d0baa);var _0xdae8dd=[];_0xdae8dd[_0x252f('0x9e')]({'model':db[_0x252f('0x78')],'as':_0x252f('0x78'),'attributes':['id',_0x252f('0x52')],'raw':!![]});_0xdae8dd[_0x252f('0x9e')]({'model':db[_0x252f('0x5e')],'as':_0x252f('0x5f'),'attributes':['id','firstName',_0x252f('0xad')],'raw':!![]});if(_0x501524[_0x252f('0x38')][_0x252f('0xac')]){_0xdae8dd[_0x252f('0x9e')]({'model':db[_0x252f('0x69')],'as':_0x252f('0x69'),'raw':!![]});}var _0x1ed94c=[{'model':db[_0x252f('0x5d')],'as':_0x252f('0x79'),'attributes':['id',_0x252f('0x47'),'createdAt',_0x252f('0x83'),_0x252f('0x84'),_0x252f('0xae')],'include':_0xdae8dd}];_0x1ed94c[_0x252f('0x9e')]({'model':db[_0x252f('0xaf')],'as':_0x252f('0xb0'),'attributes':['id','name']});_0x1ed94c[_0x252f('0x9e')]({'model':db[_0x252f('0x78')],'as':_0x252f('0xb1'),'attributes':['id',_0x252f('0x52')]});return db[_0x252f('0x33')][_0x252f('0x45')]({'where':{'id':_0x501524[_0x252f('0x48')]['id']},'include':_0x1ed94c})[_0x252f('0x15')](handleEntityNotFound(_0x19481d,null))[_0x252f('0x15')](function(_0x11e1cb){if(_0x11e1cb){var _0x32d13f=_0x11e1cb[_0x252f('0xb2')]({'plain':!![]});fs[_0x252f('0xb3')](_0x192d2f);var _0x4272e0={'channel':_0x252f('0xb4'),'account':_0x32d13f[_0x252f('0xb0')][_0x252f('0x2b')],'agent':_0x32d13f[_0x252f('0xb1')]?_0x32d13f['Owner'][_0x252f('0x52')]:_0x252f('0xb5'),'createdAt':moment(_0x32d13f[_0x252f('0x82')])[_0x252f('0x74')](_0x252f('0x98'))[_0x252f('0xa8')](),'closedAt':_0x32d13f[_0x252f('0x65')]?moment(_0x32d13f[_0x252f('0xb6')])[_0x252f('0x74')]('YYYY-MM-DD\x20HH:mm:ss')[_0x252f('0xa8')]():'','disposition':_0x32d13f[_0x252f('0xb7')],'chatInfo':{'browser':_0x32d13f[_0x252f('0xb8')],'os':_0x32d13f[_0x252f('0xb9')],'referer':_0x32d13f[_0x252f('0xba')],'customerIp':_0x32d13f[_0x252f('0xbb')],'customerPort':_0x32d13f[_0x252f('0xbc')]?_0x32d13f[_0x252f('0xbc')]:_0x252f('0xb5')},'messages':_(_0x32d13f[_0x252f('0x79')])[_0x252f('0xbd')]()['filter']({'secret':![]})['map'](function(_0x3a0478){if(_0x3a0478[_0x252f('0x69')]){var _0x19e895=path[_0x252f('0x6e')](_0x29de57,_0x3a0478[_0x252f('0x69')][_0x252f('0x6f')]);if(fs['existsSync'](_0x19e895)){fs[_0x252f('0xbe')](_0x19e895)[_0x252f('0xbf')](fs['createWriteStream'](path[_0x252f('0x6e')](_0x192d2f,_0x3a0478['Attachment'][_0x252f('0x6f')])));}}return{'date':moment(_0x3a0478[_0x252f('0x82')])[_0x252f('0x74')](_0x252f('0x98'))[_0x252f('0xa8')](),'sender':_0x3a0478[_0x252f('0x83')]===_0x252f('0xc0')?_0x3a0478[_0x252f('0x78')]?_0x3a0478[_0x252f('0x78')][_0x252f('0x52')]:_0x252f('0x7c'):_0x3a0478[_0x252f('0x5f')][_0x252f('0xc1')]+(_0x3a0478[_0x252f('0x5f')][_0x252f('0xad')]?'\x20'+_0x3a0478[_0x252f('0x5f')][_0x252f('0xad')]:''),'body':_0x3a0478[_0x252f('0x69')]?_0x3a0478[_0x252f('0x69')][_0x252f('0x6f')]:_0x3a0478[_0x252f('0x47')],'direction':_0x3a0478[_0x252f('0x83')]===_0x252f('0xc0')?'A':'C','secret':_0x3a0478[_0x252f('0x84')],'read':_0x3a0478[_0x252f('0xae')],'attachment':_0x3a0478[_0x252f('0x69')]};})[_0x252f('0xc2')]()};return ejs['renderFile'](path[_0x252f('0x6e')](config[_0x252f('0x73')],_0x252f('0xa9'),_0x252f('0xc3'),_0x252f('0xc4')),{'interaction':_0x4272e0})[_0x252f('0x15')](function(_0x328d7a){var _0x59858b=path[_0x252f('0x6e')](_0x192d2f,_0x252f('0xc5')+_0x32d13f['id']+'-'+_0x1419a9+_0x252f('0xc6'));var _0x4c9daf={'path':_0x59858b,'channel':_0x252f('0xb4'),'interactionId':_0x32d13f['id']};return pdf[_0x252f('0xc7')](_0x328d7a,_0x4c9daf);})[_0x252f('0x15')](function(){return new Promise(function(_0x58d465,_0xf4423a){zipdir(_0x192d2f,{'saveTo':_0x3fdc34},function(_0x4b9e5c,_0x12fbe7){if(_0x4b9e5c)return _0xf4423a(_0x4b9e5c);return _0x58d465(_0x12fbe7);});})['then'](function(){return new BPromise(function(_0x2867f7,_0x13ba73){rimraf(_0x192d2f,function(_0xeb9fb4){if(_0xeb9fb4)_0x13ba73(_0xeb9fb4);return _0x2867f7();});});})[_0x252f('0x15')](function(){return _0x19481d[_0x252f('0x70')](_0x3fdc34,_0x1d0baa,function(_0x4ed3ab){if(_0x4ed3ab){logger[_0x252f('0x1a')](_0x252f('0xc8'),_0x4ed3ab);}else{fs[_0x252f('0xc9')](_0x3fdc34);}});});});}else{return _0x19481d[_0x252f('0x20')](0xc8);}})[_0x252f('0x1f')](handleError(_0x19481d,null));};
\ No newline at end of file
+var _0x1c5e=['file','originalname','basename','filename','type','mimetype','closed','Unauthorized','Attachment','attachId','ChatOfflineMessageId','join','root','server/files/attachments/','download','close','mailTranscript','server/files/chat/upload/','transcript-%s.txt','now','pathTranscript','ChatMessage','Messages','User','ContactId','%s%d','agentAlias','System','customer','format','Visitor','agentIdentifier','website_alias','agent_alias','alias','agent_fullname','createdAt','MM/DD/YYYY\x20HH:mm:ss','direction','secret','appendFileSync','MailServerOut','Smtp','CloudProvider','getSmtpOptions','\x22%s\x22\x20<%s>','Mail\x20Transcript','Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a','addMessage','omit','ids','getMessages','keys','nolimit','order','sort','where','pick','ChatInteractionId','filter','map','$gte','getMyMessages','hasOwnProperty','includeAgent','push','spread','Tag','color','emit','removeTags','unix','toString','server','files','tmp','attachments','firstName','lastName','read','Account','Owner','get','mkdirSync','N.A.','YYYY-MM-DD\x20HH:mm:ss','closedAt','browserName','osName','referer','customerIp','customerPort','tail','pipe','createWriteStream','renderFile','views','downloadInteraction.ejs','transcript-','.pdf','Chat','createPdfFromHTML','err','unlinkSync','rimraf','zip-dir','request-promise','bluebird','util','path','ejs','lodash','ioredis','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./chatInteraction.socket','jayson/promise','http','request','then','info','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','ChatInteraction,\x20%s,\x20%s','message','result','sendStatus','status','json','offset','limit','undefined','count','set','Content-Range','update','destroy','end','stack','name','send','render','contact','agent','interaction','account','index','rawAttributes','fieldName','key','getOptions','findAll','chat','catch','show','model','ChatInteraction','query','filters','intersection','attributes','fields','length','includeAll','include','merge','options','create','body','params','find','describe','createVidaooSession','findOne','ChatWebsite','ChatWebsiteId','vidaooApiKey','vidaooEscalation','vidaooTopic','vidaooMetadata','user','fullname','email','POST','https://api-vidaoo.xcally.com/api/v1/meetings','isNull','vidaooNote','follow','parse','metadata','Sequelize','ValidationError','Error\x20in\x20conversion\x20vidaooMetadata','Error\x20in\x20Vidaoo\x20configuration','join_url','out','Unable\x20to\x20create\x20Vidaoo\x20session','customUpdate','CmContact','Contact','abandonInteraction,\x20%s,\x20%s,\x20%s','entity\x20not\x20found','UserId','Interaction\x20already\x20assigned','disposition','AbandonInteraction','abandon'];(function(_0x1c098c,_0x26572d){var _0x866a83=function(_0x36e84b){while(--_0x36e84b){_0x1c098c['push'](_0x1c098c['shift']());}};_0x866a83(++_0x26572d);}(_0x1c5e,0x141));var _0xe1c5=function(_0x1c8c2f,_0x1d99fe){_0x1c8c2f=_0x1c8c2f-0x0;var _0x24fa67=_0x1c5e[_0x1c8c2f];return _0x24fa67;};'use strict';var rimraf=require(_0xe1c5('0x0'));var zipdir=require(_0xe1c5('0x1'));var rp=require(_0xe1c5('0x2'));var moment=require('moment');var BPromise=require(_0xe1c5('0x3'));var Mustache=require('mustache');var util=require(_0xe1c5('0x4'));var path=require(_0xe1c5('0x5'));var ejs=require(_0xe1c5('0x6'));var fs=require('fs');var _=require(_0xe1c5('0x7'));var Redis=require(_0xe1c5('0x8'));var interaction=require('../../components/interaction/service');var qs=require(_0xe1c5('0x9'));var pdf=require(_0xe1c5('0xa'));var logger=require(_0xe1c5('0xb'))(_0xe1c5('0xc'));var config=require(_0xe1c5('0xd'));var db=require(_0xe1c5('0xe'))['db'];config[_0xe1c5('0xf')]=_[_0xe1c5('0x10')](config['redis'],{'host':_0xe1c5('0x11'),'port':0x18eb});var socket=require(_0xe1c5('0x12'))(new Redis(config['redis']));require(_0xe1c5('0x13'))['register'](socket);var jayson=require(_0xe1c5('0x14'));var client=jayson['client'][_0xe1c5('0x15')]({'port':0x232b});var client9004=jayson['client']['http']({'port':0x232c});function respondWithRpcPromise(_0x3c5001,_0x61adc1,_0x3a0b98,_0x1c5ecf){return new BPromise(function(_0x1bfc69,_0x28f153){var _0x5d0fdd=_0x1c5ecf||client;return _0x5d0fdd[_0xe1c5('0x16')](_0x3c5001,_0x3a0b98)[_0xe1c5('0x17')](function(_0x4617c6){logger[_0xe1c5('0x18')]('ChatInteraction,\x20%s,\x20%s',_0x61adc1,'request\x20sent');logger['debug'](_0xe1c5('0x19'),_0x61adc1,'request\x20sent',JSON[_0xe1c5('0x1a')](_0x4617c6));if(_0x4617c6['error']){if(_0x4617c6[_0xe1c5('0x1b')][_0xe1c5('0x1c')]===0x1f4){logger[_0xe1c5('0x1b')](_0xe1c5('0x1d'),_0x61adc1,_0x4617c6[_0xe1c5('0x1b')][_0xe1c5('0x1e')]);return _0x28f153(_0x4617c6[_0xe1c5('0x1b')][_0xe1c5('0x1e')]);}logger[_0xe1c5('0x1b')](_0xe1c5('0x1d'),_0x61adc1,_0x4617c6[_0xe1c5('0x1b')]['message']);return _0x1bfc69(_0x4617c6[_0xe1c5('0x1b')][_0xe1c5('0x1e')]);}else{logger[_0xe1c5('0x18')]('ChatInteraction,\x20%s,\x20%s',_0x61adc1,'request\x20sent');_0x1bfc69(_0x4617c6[_0xe1c5('0x1f')][_0xe1c5('0x1e')]);}})['catch'](function(_0x227cf3){logger[_0xe1c5('0x1b')]('ChatInteraction,\x20%s,\x20%s',_0x61adc1,_0x227cf3);_0x28f153(_0x227cf3);});});}function respondWithStatusCode(_0x3b727d,_0x40e9b7){_0x40e9b7=_0x40e9b7||0xcc;return function(_0x416f2d){if(_0x416f2d){return _0x3b727d[_0xe1c5('0x20')](_0x40e9b7);}return _0x3b727d[_0xe1c5('0x21')](_0x40e9b7)['end']();};}function respondWithResult(_0x23a62f,_0x150fee){_0x150fee=_0x150fee||0xc8;return function(_0x596fda){if(_0x596fda){return _0x23a62f['status'](_0x150fee)[_0xe1c5('0x22')](_0x596fda);}};}function respondWithFilteredResult(_0x2a4419,_0x5057e2){return function(_0x53a902){if(_0x53a902){var _0xfa83c3=typeof _0x5057e2[_0xe1c5('0x23')]==='undefined'&&typeof _0x5057e2[_0xe1c5('0x24')]===_0xe1c5('0x25');var _0x159be3=_0x53a902[_0xe1c5('0x26')];var _0x31fd80=_0xfa83c3?0x0:_0x5057e2[_0xe1c5('0x23')];var _0x1dc9cd=_0xfa83c3?_0x53a902[_0xe1c5('0x26')]:_0x5057e2[_0xe1c5('0x23')]+_0x5057e2[_0xe1c5('0x24')];var _0x2d4a19;if(_0x1dc9cd>=_0x159be3){_0x1dc9cd=_0x159be3;_0x2d4a19=0xc8;}else{_0x2d4a19=0xce;}_0x2a4419['status'](_0x2d4a19);return _0x2a4419[_0xe1c5('0x27')](_0xe1c5('0x28'),_0x31fd80+'-'+_0x1dc9cd+'/'+_0x159be3)[_0xe1c5('0x22')](_0x53a902);}return null;};}function saveUpdates(_0x1f8436){return function(_0x5129eb){if(_0x5129eb){return _0x5129eb[_0xe1c5('0x29')](_0x1f8436)[_0xe1c5('0x17')](function(_0xa22482){return _0xa22482;});}return null;};}function removeEntity(_0x4450f6){return function(_0x4b7163){if(_0x4b7163){return _0x4b7163[_0xe1c5('0x2a')]()[_0xe1c5('0x17')](function(){_0x4450f6[_0xe1c5('0x21')](0xcc)[_0xe1c5('0x2b')]();});}};}function handleEntityNotFound(_0x381775){return function(_0x25427e){if(!_0x25427e){_0x381775[_0xe1c5('0x20')](0x194);}return _0x25427e;};}function handleError(_0x15486a,_0x24e46b){_0x24e46b=_0x24e46b||0x1f4;return function(_0x50214c){logger[_0xe1c5('0x1b')](_0x50214c[_0xe1c5('0x2c')]);if(_0x50214c[_0xe1c5('0x2d')]){delete _0x50214c[_0xe1c5('0x2d')];}_0x15486a[_0xe1c5('0x21')](_0x24e46b)[_0xe1c5('0x2e')](_0x50214c);};}function getMustacheRender(_0x5937c2,_0x386618){return Mustache[_0xe1c5('0x2f')](_0x5937c2,_['merge'](_0x386618['body'],{'contact':_0x386618[_0xe1c5('0x30')],'message':_0x386618[_0xe1c5('0x1e')],'agent':_0x386618[_0xe1c5('0x31')],'interaction':_0x386618[_0xe1c5('0x32')],'account':_0x386618[_0xe1c5('0x33')]}))||'';}exports[_0xe1c5('0x34')]=function(_0x27616f,_0x295f1f){var _0x22d8a4={};var _0x3e48cf=_['map'](db['ChatInteraction'][_0xe1c5('0x35')],function(_0x23519c){return{'name':_0x23519c[_0xe1c5('0x36')],'type':_0x23519c['type'][_0xe1c5('0x37')]};});_0x22d8a4=qs[_0xe1c5('0x38')](_0x3e48cf,_0x27616f);return interaction[_0xe1c5('0x39')](_0xe1c5('0x3a'),_0x27616f['query'],_0x27616f['user'],_0x22d8a4,_0x3e48cf)[_0xe1c5('0x17')](respondWithFilteredResult(_0x295f1f,_0x22d8a4))[_0xe1c5('0x3b')](handleError(_0x295f1f,null));};exports[_0xe1c5('0x3c')]=function(_0x2eb0c0,_0x3bfa87){var _0x50949f={'raw':![],'where':{'id':_0x2eb0c0['params']['id']}},_0x4d795d={};_0x4d795d[_0xe1c5('0x3d')]=_['keys'](db[_0xe1c5('0x3e')][_0xe1c5('0x35')]);_0x4d795d['query']=_['keys'](_0x2eb0c0[_0xe1c5('0x3f')]);_0x4d795d[_0xe1c5('0x40')]=_[_0xe1c5('0x41')](_0x4d795d['model'],_0x4d795d['query']);_0x50949f[_0xe1c5('0x42')]=_[_0xe1c5('0x41')](_0x4d795d['model'],qs[_0xe1c5('0x43')](_0x2eb0c0[_0xe1c5('0x3f')][_0xe1c5('0x43')]));_0x50949f[_0xe1c5('0x42')]=_0x50949f[_0xe1c5('0x42')][_0xe1c5('0x44')]?_0x50949f[_0xe1c5('0x42')]:_0x4d795d['model'];if(_0x2eb0c0['query'][_0xe1c5('0x45')]){_0x50949f[_0xe1c5('0x46')]=[{'all':!![]}];}_0x50949f=_[_0xe1c5('0x47')]({},_0x50949f,_0x2eb0c0[_0xe1c5('0x48')]);return db[_0xe1c5('0x3e')]['find'](_0x50949f)[_0xe1c5('0x17')](handleEntityNotFound(_0x3bfa87,null))[_0xe1c5('0x17')](respondWithResult(_0x3bfa87,null))[_0xe1c5('0x3b')](handleError(_0x3bfa87,null));};exports[_0xe1c5('0x49')]=function(_0x5a4bd7,_0x46ab67){return db[_0xe1c5('0x3e')][_0xe1c5('0x49')](_0x5a4bd7[_0xe1c5('0x4a')],{})[_0xe1c5('0x17')](respondWithResult(_0x46ab67,0xc9))[_0xe1c5('0x3b')](handleError(_0x46ab67,null));};exports['update']=function(_0x5333d8,_0xf837bf){if(_0x5333d8[_0xe1c5('0x4a')]['id']){delete _0x5333d8[_0xe1c5('0x4a')]['id'];}return db['ChatInteraction']['find']({'where':{'id':_0x5333d8[_0xe1c5('0x4b')]['id']}})['then'](handleEntityNotFound(_0xf837bf,null))[_0xe1c5('0x17')](saveUpdates(_0x5333d8[_0xe1c5('0x4a')],null))['then'](respondWithResult(_0xf837bf,null))[_0xe1c5('0x3b')](handleError(_0xf837bf,null));};exports['destroy']=function(_0x14a5d2,_0x113a61){return db['ChatInteraction'][_0xe1c5('0x4c')]({'where':{'id':_0x14a5d2[_0xe1c5('0x4b')]['id']}})[_0xe1c5('0x17')](handleEntityNotFound(_0x113a61,null))[_0xe1c5('0x17')](removeEntity(_0x113a61,null))[_0xe1c5('0x3b')](handleError(_0x113a61,null));};exports[_0xe1c5('0x4d')]=function(_0x1ac20a,_0x35562a){return db[_0xe1c5('0x3e')][_0xe1c5('0x4d')]()[_0xe1c5('0x17')](respondWithResult(_0x35562a,null))[_0xe1c5('0x3b')](handleError(_0x35562a,null));};exports[_0xe1c5('0x4e')]=function(_0x423ec4,_0x18c0f2){var _0x43ca42=_0x423ec4[_0xe1c5('0x4b')]['id'];var _0x2feef1;var _0xccfc66;var _0x409ed5;return db[_0xe1c5('0x3e')][_0xe1c5('0x4f')]({'where':{'id':_0x43ca42}})[_0xe1c5('0x17')](function(_0xccd9d4){_0x2feef1=_0xccd9d4;return db[_0xe1c5('0x50')][_0xe1c5('0x4f')]({'where':{'id':_0xccd9d4[_0xe1c5('0x51')]},'attributes':['id',_0xe1c5('0x52'),_0xe1c5('0x53'),_0xe1c5('0x54'),'vidaooNote',_0xe1c5('0x55')],'raw':!![]});})[_0xe1c5('0x17')](function(_0x1a4adc){if(_0x1a4adc&&_0x1a4adc[_0xe1c5('0x52')]&&_0x1a4adc[_0xe1c5('0x53')]){_0xccfc66=_0x1a4adc;var _0xf42583={'interaction':{'id':_0x43ca42},'agent':{'id':_0x423ec4[_0xe1c5('0x56')]['id'],'name':_0x423ec4[_0xe1c5('0x56')]['name'],'fullname':_0x423ec4[_0xe1c5('0x56')][_0xe1c5('0x57')],'email':_0x423ec4[_0xe1c5('0x56')][_0xe1c5('0x58')]},'contact':_0x423ec4[_0xe1c5('0x4a')][_0xe1c5('0x30')],'account':_0x423ec4[_0xe1c5('0x4a')][_0xe1c5('0x33')]};var _0x2cb630={'rejectUnauthorized':![],'method':_0xe1c5('0x59'),'url':_0xe1c5('0x5a'),'headers':{'X-APIKEY':_0x1a4adc[_0xe1c5('0x52')]},'body':{'duration':null,'scheduledAt':null,'participants':[_0x423ec4[_0xe1c5('0x56')][_0xe1c5('0x58')]],'buttons':null,'topic':_0xccfc66[_0xe1c5('0x54')],'note':_[_0xe1c5('0x5b')](_0xccfc66[_0xe1c5('0x5c')])?null:getMustacheRender(_0xccfc66['vidaooNote'],_0xf42583),'metadata':null},'redirect':_0xe1c5('0x5d'),'json':!![]};try{if(!_[_0xe1c5('0x5b')](_0xccfc66[_0xe1c5('0x55')])){var _0x43e61d=getMustacheRender(_0xccfc66[_0xe1c5('0x55')],_0xf42583);var _0x3fc8f3=JSON[_0xe1c5('0x5e')](_0x43e61d);_0x2cb630[_0xe1c5('0x4a')][_0xe1c5('0x5f')]=_0x3fc8f3;}}catch(_0x833698){throw new db[(_0xe1c5('0x60'))][(_0xe1c5('0x61'))](_0xe1c5('0x62'));}return rp(_0x2cb630);}else{throw new db[(_0xe1c5('0x60'))]['ValidationError'](_0xe1c5('0x63'));}})[_0xe1c5('0x17')](function(_0x12313c){_0x409ed5=_0x12313c;if(_0x409ed5['id']){var _0x4cb1de={'body':_0x409ed5[_0xe1c5('0x64')],'ChatWebsiteId':_0xccfc66['id'],'ChatInteractionId':_0x2feef1['id'],'direction':_0xe1c5('0x65'),'UserId':_0x423ec4[_0xe1c5('0x56')]['id']};return db['ChatMessage']['create'](_0x4cb1de,{});}else{throw new db['Sequelize'][(_0xe1c5('0x61'))](_0xe1c5('0x66'));}})[_0xe1c5('0x17')](function(){return _0x2feef1['updateAttributes']({'vidaooSessionId':_0x409ed5['id']});})[_0xe1c5('0x17')](respondWithResult(_0x18c0f2,null))[_0xe1c5('0x3b')](handleError(_0x18c0f2,null));};exports[_0xe1c5('0x67')]=function(_0x8b1a66,_0x1a8f55){if(_0x8b1a66[_0xe1c5('0x4a')]['id']){delete _0x8b1a66[_0xe1c5('0x4a')]['id'];}return db[_0xe1c5('0x3e')][_0xe1c5('0x4c')]({'where':{'id':_0x8b1a66[_0xe1c5('0x4b')]['id']},'include':[{'model':db[_0xe1c5('0x68')],'as':_0xe1c5('0x69')}]})[_0xe1c5('0x17')](handleEntityNotFound(_0x1a8f55,null))[_0xe1c5('0x17')](saveUpdates(_0x8b1a66[_0xe1c5('0x4a')],null))[_0xe1c5('0x17')](respondWithResult(_0x1a8f55,null))[_0xe1c5('0x3b')](handleError(_0x1a8f55,null));};exports['abandon']=function(_0x5b9d3e,_0x1afc3f){if(_0x5b9d3e[_0xe1c5('0x4a')]['id']){delete _0x5b9d3e[_0xe1c5('0x4a')]['id'];}return db['ChatInteraction'][_0xe1c5('0x4c')]({'where':{'id':_0x5b9d3e[_0xe1c5('0x4b')]['id']}})[_0xe1c5('0x17')](function(_0xad7104){if(!_0xad7104){logger[_0xe1c5('0x1b')](_0xe1c5('0x6a'),'abandon',0x194,_0xe1c5('0x6b'));_0x1afc3f[_0xe1c5('0x20')](0x194);}else{if(_0xad7104[_0xe1c5('0x6c')]){throw new db['Sequelize']['ValidationError'](_0xe1c5('0x6d'));}}return _0xad7104;})[_0xe1c5('0x17')](function(_0x4e7a16){if(_0x4e7a16){return _0x4e7a16[_0xe1c5('0x29')]({'closed':_0x5b9d3e[_0xe1c5('0x4a')]['closed'],'disposition':_0x5b9d3e[_0xe1c5('0x4a')][_0xe1c5('0x6e')]})['then'](function(_0x9a4408){return _0x9a4408;});}})['then'](function(){return respondWithRpcPromise(_0xe1c5('0x6f'),_0xe1c5('0x70'),_0x5b9d3e[_0xe1c5('0x4a')],client9004);})[_0xe1c5('0x17')](respondWithResult(_0x1afc3f,null))['catch'](handleError(_0x1afc3f,null));};exports['attachmentUpload']=function(_0x38c8bb,_0x5211e3){_0x38c8bb[_0xe1c5('0x4a')][_0xe1c5('0x2d')]=_0x38c8bb[_0xe1c5('0x71')][_0xe1c5('0x72')];_0x38c8bb[_0xe1c5('0x4a')][_0xe1c5('0x73')]=_0x38c8bb[_0xe1c5('0x71')][_0xe1c5('0x74')];_0x38c8bb[_0xe1c5('0x4a')][_0xe1c5('0x75')]=_0x38c8bb[_0xe1c5('0x71')][_0xe1c5('0x76')];return db['Attachment']['create'](_0x38c8bb[_0xe1c5('0x4a')])['then'](respondWithResult(_0x5211e3,0xc9))[_0xe1c5('0x3b')](handleError(_0x5211e3,null));};exports['attachmentDownload']=function(_0x2dac9c,_0x440455){return db[_0xe1c5('0x3e')][_0xe1c5('0x4f')]({'where':{'id':_0x2dac9c[_0xe1c5('0x4b')]['id']},'raw':!![]})['then'](handleEntityNotFound(_0x440455,null))['then'](function(_0x3455f6){if(_0x3455f6){if(_0x3455f6[_0xe1c5('0x77')]){return _0x440455[_0xe1c5('0x21')](0x193)[_0xe1c5('0x22')]({'status':0x193,'message':_0xe1c5('0x78')});}return db[_0xe1c5('0x79')][_0xe1c5('0x4f')]({'where':{'id':_0x2dac9c[_0xe1c5('0x3f')][_0xe1c5('0x7a')]},'raw':!![]})['then'](handleEntityNotFound(_0x440455,null));}})[_0xe1c5('0x17')](function(_0x8b5907){if(_0x8b5907){var _0x24dcae=_0x8b5907[_0xe1c5('0x7b')]!==null;var _0x3e1736=path[_0xe1c5('0x7c')](config[_0xe1c5('0x7d')],_0xe1c5('0x7e'));if(_0x24dcae){_0x3e1736=path[_0xe1c5('0x7c')](_0x3e1736,'offline-chat/');}var _0x2759c3=path[_0xe1c5('0x7c')](_0x3e1736,_0x8b5907['basename']);return _0x440455[_0xe1c5('0x7f')](_0x2759c3);}})[_0xe1c5('0x3b')](handleError(_0x440455,null));};exports[_0xe1c5('0x80')]=function(_0x2cd61a,_0x3cbe48){var _0x42c57f=null;var _0x23b7e1=null;var _0x111df3=null;if(_0x2cd61a[_0xe1c5('0x4a')]['id']){delete _0x2cd61a['body']['id'];}if(_0x2cd61a[_0xe1c5('0x4a')][_0xe1c5('0x81')]){_0x111df3=path[_0xe1c5('0x7c')](config[_0xe1c5('0x7d')],_0xe1c5('0x82'),util['format'](_0xe1c5('0x83'),Date[_0xe1c5('0x84')]()));_0x2cd61a['body'][_0xe1c5('0x85')]=_0x111df3;}return db[_0xe1c5('0x3e')][_0xe1c5('0x4c')]({'where':{'id':_0x2cd61a['params']['id']},'include':[{'model':db[_0xe1c5('0x86')],'as':_0xe1c5('0x87'),'include':[{'model':db[_0xe1c5('0x88')],'as':_0xe1c5('0x88')}]}]})['then'](handleEntityNotFound(_0x3cbe48,null))[_0xe1c5('0x17')](saveUpdates(_0x2cd61a[_0xe1c5('0x4a')],null))[_0xe1c5('0x17')](function(_0x26bfa4){if(_0x26bfa4){_0x42c57f=_0x26bfa4;return db[_0xe1c5('0x50')][_0xe1c5('0x4c')]({'where':{'id':_0x42c57f[_0xe1c5('0x51')]}});}})[_0xe1c5('0x17')](function(_0x9d16fa){if(_0x9d16fa){_0x23b7e1=_0x9d16fa;return db[_0xe1c5('0x68')][_0xe1c5('0x4c')]({'where':{'id':_0x42c57f[_0xe1c5('0x89')]}});}})[_0xe1c5('0x17')](function(_0x4771cf){if(_0x4771cf){if(_0x111df3){var _0x2ac4aa=null;for(var _0x2d7e37=0x1;_0x2d7e37<_0x42c57f[_0xe1c5('0x87')][_0xe1c5('0x44')];++_0x2d7e37){_0x2ac4aa=_0x42c57f['Messages'][_0x2d7e37];var _0x471ad8=_0x2ac4aa['UserId']?util['format'](_0xe1c5('0x8a'),_0x23b7e1[_0xe1c5('0x8b')],_0x2ac4aa['UserId']):_0xe1c5('0x8c');var _0x208d50=_0x2cd61a[_0xe1c5('0x4a')][_0xe1c5('0x8d')]||util[_0xe1c5('0x8e')]('%s%d',_0xe1c5('0x8f'),_0x2ac4aa[_0xe1c5('0x89')]);switch(_0x23b7e1[_0xe1c5('0x90')]){case _0xe1c5('0x91'):_0x471ad8=_0x2ac4aa[_0xe1c5('0x6c')]?util[_0xe1c5('0x8e')](_0xe1c5('0x8a'),_0x23b7e1[_0xe1c5('0x8b')],_0x2ac4aa[_0xe1c5('0x6c')]):_0xe1c5('0x8c');break;case _0xe1c5('0x92'):_0x471ad8=_0x2ac4aa['UserId']?_0x2ac4aa[_0xe1c5('0x88')][_0xe1c5('0x93')]||_0x2ac4aa[_0xe1c5('0x88')][_0xe1c5('0x57')]:'System';break;case _0xe1c5('0x94'):_0x471ad8=_0x2ac4aa[_0xe1c5('0x6c')]?_0x2ac4aa[_0xe1c5('0x88')]['fullname']:'System';break;default:_0x471ad8=_0x2ac4aa[_0xe1c5('0x6c')]?util[_0xe1c5('0x8e')](_0xe1c5('0x8a'),_0x23b7e1[_0xe1c5('0x8b')],_0x2ac4aa[_0xe1c5('0x6c')]):_0xe1c5('0x8c');}var _0x2a7baa=util['format']('[%s]\x20%s:\x20%s\x0a',moment(_0x2ac4aa[_0xe1c5('0x95')])[_0xe1c5('0x8e')](_0xe1c5('0x96')),_0x2ac4aa[_0xe1c5('0x97')]==='in'?_0x208d50:_0x471ad8,_0x2ac4aa[_0xe1c5('0x4a')]);if(!_0x2ac4aa[_0xe1c5('0x98')]){fs[_0xe1c5('0x99')](_0x111df3,_0x2a7baa);}}return db['MailAccount']['findOne']({'where':{'service':!![]},'include':[{'model':db[_0xe1c5('0x9a')],'as':_0xe1c5('0x9b'),'raw':!![],'include':[{'model':db['CloudProvider'],'as':_0xe1c5('0x9c'),'raw':!![]}]}]});}}})[_0xe1c5('0x17')](function(_0x275a37){if(!_0x275a37||!_0x275a37[_0xe1c5('0x9b')]||!_0x2cd61a[_0xe1c5('0x4a')])return _0x42c57f;var _0x111adf=_0x275a37[_0xe1c5('0x9d')]();return respondWithRpcPromise('SendMail','sendMail',{'account':_0x111adf,'message':{'from':util[_0xe1c5('0x8e')](_0xe1c5('0x9e'),_0x275a37[_0xe1c5('0x2d')],_0x275a37[_0xe1c5('0x58')]||_0x275a37[_0xe1c5('0x9b')]['user']),'to':_0x2cd61a['body'][_0xe1c5('0x81')],'subject':_0xe1c5('0x9f'),'text':util[_0xe1c5('0x8e')](_0xe1c5('0xa0'),_0x2cd61a[_0xe1c5('0x4a')][_0xe1c5('0x81')]),'attachments':[{'path':_0x111df3}]}})[_0xe1c5('0x17')](function(){return _0x42c57f;})[_0xe1c5('0x3b')](function(_0x162121){logger[_0xe1c5('0x1b')](_0x162121);});})[_0xe1c5('0x17')](respondWithStatusCode(_0x3cbe48,0xc8))['catch'](handleError(_0x3cbe48,null));};exports[_0xe1c5('0xa1')]=function(_0x27dac5,_0x5c64ef){return db[_0xe1c5('0x86')][_0xe1c5('0x4c')]({'where':{'id':_0x27dac5[_0xe1c5('0x4b')]['id']}})['then'](handleEntityNotFound(_0x5c64ef,null))[_0xe1c5('0x17')](function(_0x461f09){if(_0x461f09){return _0x461f09[_0xe1c5('0xa1')](_0x27dac5['body']['ids'],_[_0xe1c5('0xa2')](_0x27dac5[_0xe1c5('0x4a')],[_0xe1c5('0xa3'),'id'])||{});}})[_0xe1c5('0x17')](respondWithResult(_0x5c64ef,null))['catch'](handleError(_0x5c64ef,null));};exports[_0xe1c5('0xa4')]=function(_0x4df487,_0x1ee4f1){var _0x50725d={'raw':![],'where':{}};var _0x472761={};var _0x4bebec={'count':0x0,'rows':[]};return db[_0xe1c5('0x3e')]['findOne']({'where':{'id':_0x4df487['params']['id']}})[_0xe1c5('0x17')](handleEntityNotFound(_0x1ee4f1,null))[_0xe1c5('0x17')](function(_0x515d8f){if(_0x515d8f){_0x472761[_0xe1c5('0x3d')]=_[_0xe1c5('0xa5')](db[_0xe1c5('0x86')][_0xe1c5('0x35')]);_0x472761['query']=_[_0xe1c5('0xa5')](_0x4df487[_0xe1c5('0x3f')]);_0x472761[_0xe1c5('0x40')]=_['intersection'](_0x472761[_0xe1c5('0x3d')],_0x472761[_0xe1c5('0x3f')]);_0x50725d[_0xe1c5('0x42')]=_[_0xe1c5('0x41')](_0x472761[_0xe1c5('0x3d')],qs[_0xe1c5('0x43')](_0x4df487[_0xe1c5('0x3f')][_0xe1c5('0x43')]));_0x50725d[_0xe1c5('0x42')]=_0x50725d[_0xe1c5('0x42')][_0xe1c5('0x44')]?_0x50725d['attributes']:_0x472761['model'];if(!_0x4df487['query']['hasOwnProperty'](_0xe1c5('0xa6'))){_0x50725d[_0xe1c5('0x24')]=qs[_0xe1c5('0x24')](_0x4df487[_0xe1c5('0x3f')][_0xe1c5('0x24')]);_0x50725d['offset']=qs[_0xe1c5('0x23')](_0x4df487[_0xe1c5('0x3f')][_0xe1c5('0x23')]);}_0x50725d[_0xe1c5('0xa7')]=qs[_0xe1c5('0xa8')](_0x4df487[_0xe1c5('0x3f')]['sort']);_0x50725d[_0xe1c5('0xa9')]=qs['filters'](_[_0xe1c5('0xaa')](_0x4df487[_0xe1c5('0x3f')],_0x472761[_0xe1c5('0x40')]));_0x50725d[_0xe1c5('0xa9')][_0xe1c5('0xab')]=_0x515d8f['id'];if(_0x4df487[_0xe1c5('0x3f')][_0xe1c5('0xac')]){_0x50725d['where']=_[_0xe1c5('0x47')](_0x50725d[_0xe1c5('0xa9')],{'$or':_[_0xe1c5('0xad')](_0x50725d[_0xe1c5('0x42')],function(_0x2b74f2){var _0x14fd86={};_0x14fd86[_0x2b74f2]={'$like':'%'+_0x4df487[_0xe1c5('0x3f')]['filter']+'%'};return _0x14fd86;})});}if(_0x4df487[_0xe1c5('0x3f')]['$gte']){var _0x51ebe6=_0x4df487[_0xe1c5('0x3f')][_0xe1c5('0xae')]['split'](',');var _0x4557d0={};_0x4557d0[_0x51ebe6[0x0]]={'$gte':moment(_0x51ebe6[0x1])[_0xe1c5('0x8e')]('YYYY-MM-DD\x20HH:mm:ss')};_0x50725d[_0xe1c5('0xa9')]=_[_0xe1c5('0x47')](_0x50725d[_0xe1c5('0xa9')],_0x4557d0);}_0x50725d=_[_0xe1c5('0x47')]({},_0x50725d,_0x4df487[_0xe1c5('0x48')]);return db[_0xe1c5('0x86')][_0xe1c5('0x26')]({'where':_0x50725d['where']})['then'](function(_0x4483c8){_0x4bebec[_0xe1c5('0x26')]=_0x4483c8;if(_0x4df487[_0xe1c5('0x3f')][_0xe1c5('0x45')]){_0x50725d[_0xe1c5('0x46')]=[{'all':!![]}];}return db['ChatMessage'][_0xe1c5('0x39')](_0x50725d);})[_0xe1c5('0x17')](function(_0x2205ee){_0x4bebec['rows']=_0x2205ee;return _0x4bebec;});}})[_0xe1c5('0x17')](respondWithFilteredResult(_0x1ee4f1,_0x50725d))['catch'](handleError(_0x1ee4f1,null));};exports[_0xe1c5('0xaf')]=function(_0x12a6db,_0x30bf74){var _0x3b6fdd={'where':{}},_0x28d3ee={},_0x410091={'count':0x0,'rows':[]};return db[_0xe1c5('0x3e')][_0xe1c5('0x4f')]({'where':{'id':_0x12a6db[_0xe1c5('0x4b')]['id']}})['then'](handleEntityNotFound(_0x30bf74,null))[_0xe1c5('0x17')](function(_0x4a36ad){if(_0x4a36ad){_0x28d3ee['model']=_[_0xe1c5('0xa5')](db[_0xe1c5('0x86')][_0xe1c5('0x35')]);_0x28d3ee[_0xe1c5('0x3f')]=_[_0xe1c5('0xa5')](_0x12a6db['query']);_0x28d3ee[_0xe1c5('0x40')]=_[_0xe1c5('0x41')](_0x28d3ee[_0xe1c5('0x3d')],_0x28d3ee[_0xe1c5('0x3f')]);_0x3b6fdd['attributes']=_[_0xe1c5('0x41')](_0x28d3ee[_0xe1c5('0x3d')],qs[_0xe1c5('0x43')](_0x12a6db[_0xe1c5('0x3f')][_0xe1c5('0x43')]));_0x3b6fdd[_0xe1c5('0x42')]=_0x3b6fdd[_0xe1c5('0x42')]['length']?_0x3b6fdd[_0xe1c5('0x42')]:_0x28d3ee[_0xe1c5('0x3d')];if(!_0x12a6db[_0xe1c5('0x3f')][_0xe1c5('0xb0')]('nolimit')){_0x3b6fdd['limit']=qs[_0xe1c5('0x24')](_0x12a6db[_0xe1c5('0x3f')][_0xe1c5('0x24')]);_0x3b6fdd[_0xe1c5('0x23')]=qs[_0xe1c5('0x23')](_0x12a6db[_0xe1c5('0x3f')][_0xe1c5('0x23')]);}_0x3b6fdd[_0xe1c5('0xa7')]=qs[_0xe1c5('0xa8')](_0x12a6db[_0xe1c5('0x3f')]['sort']);_0x3b6fdd[_0xe1c5('0xa9')]=qs[_0xe1c5('0x40')](_[_0xe1c5('0xaa')](_0x12a6db['query'],_0x28d3ee[_0xe1c5('0x40')]));_0x3b6fdd[_0xe1c5('0xa9')][_0xe1c5('0xab')]=_0x4a36ad['id'];if(_0x12a6db[_0xe1c5('0x3f')]['filter']){_0x3b6fdd[_0xe1c5('0xa9')]=_[_0xe1c5('0x47')](_0x3b6fdd[_0xe1c5('0xa9')],{'$or':_['map'](_0x3b6fdd['attributes'],function(_0x542326){var _0x28f1c9={};_0x28f1c9[_0x542326]={'$like':'%'+_0x12a6db[_0xe1c5('0x3f')][_0xe1c5('0xac')]+'%'};return _0x28f1c9;})});}_0x3b6fdd[_0xe1c5('0xa9')][_0xe1c5('0x98')]=![];if(_0x12a6db[_0xe1c5('0x3f')]['id']){_0x3b6fdd[_0xe1c5('0xa9')]['id']={'$gt':_0x12a6db[_0xe1c5('0x3f')]['id']};}_0x3b6fdd=_[_0xe1c5('0x47')]({},_0x3b6fdd,_0x12a6db[_0xe1c5('0x48')]);return db[_0xe1c5('0x86')]['count']({'where':_0x3b6fdd['where']})[_0xe1c5('0x17')](function(_0x4f330f){_0x410091[_0xe1c5('0x26')]=_0x4f330f;_0x3b6fdd[_0xe1c5('0x46')]=[];if(_0x12a6db[_0xe1c5('0x3f')][_0xe1c5('0xb1')]){_0x3b6fdd['include'][_0xe1c5('0xb2')]({'model':db[_0xe1c5('0x88')],'as':_0xe1c5('0x88'),'attributes':['id',_0xe1c5('0x57'),_0xe1c5('0x93')]});}if(_0x12a6db[_0xe1c5('0x3f')][_0xe1c5('0x45')]){_0x3b6fdd[_0xe1c5('0x46')]=[{'all':!![]}];}return db['ChatMessage']['findAll'](_0x3b6fdd);})[_0xe1c5('0x17')](function(_0x3bea6b){_0x410091['rows']=_0x3bea6b;return _0x410091;});}})[_0xe1c5('0x17')](respondWithFilteredResult(_0x30bf74,_0x3b6fdd))[_0xe1c5('0x3b')](handleError(_0x30bf74,null));};exports['addTags']=function(_0x270b26,_0x252dc6){return db['ChatInteraction']['find']({'where':{'id':_0x270b26[_0xe1c5('0x4b')]['id']}})[_0xe1c5('0x17')](handleEntityNotFound(_0x252dc6,null))['then'](function(_0x466178){if(_0x466178){return _0x466178['setTags'](_0x270b26['body'][_0xe1c5('0xa3')],_[_0xe1c5('0xa2')](_0x270b26[_0xe1c5('0x4a')],[_0xe1c5('0xa3'),'id'])||{})[_0xe1c5('0xb3')](function(){return db[_0xe1c5('0xb4')][_0xe1c5('0x39')]({'attributes':['id',_0xe1c5('0x2d'),_0xe1c5('0xb5')],'where':{'id':_0x270b26[_0xe1c5('0x4a')][_0xe1c5('0xa3')]}});})[_0xe1c5('0x17')](function(_0x45a17f){socket[_0xe1c5('0xb6')]('chatInteractionTags:save',{'id':Number(_0x270b26[_0xe1c5('0x4b')]['id']),'tags':_0x45a17f||[]});return{'id':Number(_0x270b26[_0xe1c5('0x4b')]['id']),'tags':_0x45a17f||[]};});}})[_0xe1c5('0x17')](respondWithResult(_0x252dc6,null))[_0xe1c5('0x3b')](handleError(_0x252dc6,null));};exports[_0xe1c5('0xb7')]=function(_0x12a915,_0x2cf998){return db[_0xe1c5('0x3e')][_0xe1c5('0x4c')]({'where':{'id':_0x12a915[_0xe1c5('0x4b')]['id']}})[_0xe1c5('0x17')](handleEntityNotFound(_0x2cf998,null))[_0xe1c5('0x17')](function(_0x36da1f){if(_0x36da1f){return _0x36da1f[_0xe1c5('0xb7')](_0x12a915['query']['ids']);}})[_0xe1c5('0x17')](respondWithStatusCode(_0x2cf998,null))[_0xe1c5('0x3b')](handleError(_0x2cf998,null));};exports['download']=function(_0x158898,_0x2bb4bc){var _0x80608f=moment()[_0xe1c5('0xb8')]()[_0xe1c5('0xb9')]();var _0x49ce6d=path['join'](config['root'],_0xe1c5('0xba'),_0xe1c5('0xbb'),_0xe1c5('0xbc'));var _0x2c091a=path[_0xe1c5('0x7c')](config[_0xe1c5('0x7d')],_0xe1c5('0xba'),_0xe1c5('0xbb'),_0xe1c5('0xbd'));var _0x1ef9a4=path[_0xe1c5('0x7c')](_0x49ce6d,_0x80608f);var _0x1ce1e8=util[_0xe1c5('0x8e')]('transcript-%d-%s.zip',_0x158898[_0xe1c5('0x4b')]['id'],_0x80608f);var _0x2e2838=path[_0xe1c5('0x7c')](_0x49ce6d,_0x1ce1e8);var _0xbfd735=[];_0xbfd735[_0xe1c5('0xb2')]({'model':db[_0xe1c5('0x88')],'as':_0xe1c5('0x88'),'attributes':['id',_0xe1c5('0x57')],'raw':!![]});_0xbfd735[_0xe1c5('0xb2')]({'model':db['CmContact'],'as':_0xe1c5('0x69'),'attributes':['id',_0xe1c5('0xbe'),_0xe1c5('0xbf')],'raw':!![]});if(_0x158898[_0xe1c5('0x3f')][_0xe1c5('0xbd')]){_0xbfd735['push']({'model':db[_0xe1c5('0x79')],'as':_0xe1c5('0x79'),'raw':!![]});}var _0x131e66=[{'model':db[_0xe1c5('0x86')],'as':_0xe1c5('0x87'),'attributes':['id',_0xe1c5('0x4a'),_0xe1c5('0x95'),_0xe1c5('0x97'),_0xe1c5('0x98'),_0xe1c5('0xc0')],'include':_0xbfd735}];_0x131e66[_0xe1c5('0xb2')]({'model':db[_0xe1c5('0x50')],'as':_0xe1c5('0xc1'),'attributes':['id',_0xe1c5('0x2d')]});_0x131e66[_0xe1c5('0xb2')]({'model':db[_0xe1c5('0x88')],'as':_0xe1c5('0xc2'),'attributes':['id','fullname']});return db[_0xe1c5('0x3e')]['find']({'where':{'id':_0x158898[_0xe1c5('0x4b')]['id']},'include':_0x131e66})[_0xe1c5('0x17')](handleEntityNotFound(_0x2bb4bc,null))[_0xe1c5('0x17')](function(_0x5a69c1){if(_0x5a69c1){var _0x5b7efc=_0x5a69c1[_0xe1c5('0xc3')]({'plain':!![]});fs[_0xe1c5('0xc4')](_0x1ef9a4);var _0x1f36a2={'channel':'Chat','account':_0x5b7efc[_0xe1c5('0xc1')][_0xe1c5('0x2d')],'agent':_0x5b7efc['Owner']?_0x5b7efc[_0xe1c5('0xc2')][_0xe1c5('0x57')]:_0xe1c5('0xc5'),'createdAt':moment(_0x5b7efc['createdAt'])['format'](_0xe1c5('0xc6'))[_0xe1c5('0xb9')](),'closedAt':_0x5b7efc[_0xe1c5('0x77')]?moment(_0x5b7efc[_0xe1c5('0xc7')])[_0xe1c5('0x8e')](_0xe1c5('0xc6'))[_0xe1c5('0xb9')]():'','disposition':_0x5b7efc[_0xe1c5('0x6e')],'chatInfo':{'browser':_0x5b7efc[_0xe1c5('0xc8')],'os':_0x5b7efc[_0xe1c5('0xc9')],'referer':_0x5b7efc[_0xe1c5('0xca')],'customerIp':_0x5b7efc[_0xe1c5('0xcb')],'customerPort':_0x5b7efc[_0xe1c5('0xcc')]?_0x5b7efc[_0xe1c5('0xcc')]:_0xe1c5('0xc5')},'messages':_(_0x5b7efc[_0xe1c5('0x87')])[_0xe1c5('0xcd')]()[_0xe1c5('0xac')]({'secret':![]})['map'](function(_0x16b351){if(_0x16b351[_0xe1c5('0x79')]){var _0x136d58=path[_0xe1c5('0x7c')](_0x2c091a,_0x16b351[_0xe1c5('0x79')]['basename']);if(fs['existsSync'](_0x136d58)){fs['createReadStream'](_0x136d58)[_0xe1c5('0xce')](fs[_0xe1c5('0xcf')](path['join'](_0x1ef9a4,_0x16b351['Attachment']['basename'])));}}return{'date':moment(_0x16b351[_0xe1c5('0x95')])[_0xe1c5('0x8e')](_0xe1c5('0xc6'))['toString'](),'sender':_0x16b351[_0xe1c5('0x97')]===_0xe1c5('0x65')?_0x16b351[_0xe1c5('0x88')]?_0x16b351[_0xe1c5('0x88')]['fullname']:_0xe1c5('0x8c'):_0x16b351['Contact'][_0xe1c5('0xbe')]+(_0x16b351['Contact'][_0xe1c5('0xbf')]?'\x20'+_0x16b351[_0xe1c5('0x69')]['lastName']:''),'body':_0x16b351['Attachment']?_0x16b351[_0xe1c5('0x79')][_0xe1c5('0x73')]:_0x16b351[_0xe1c5('0x4a')],'direction':_0x16b351[_0xe1c5('0x97')]==='out'?'A':'C','secret':_0x16b351[_0xe1c5('0x98')],'read':_0x16b351['read'],'attachment':_0x16b351[_0xe1c5('0x79')]};})['value']()};return ejs[_0xe1c5('0xd0')](path['join'](config[_0xe1c5('0x7d')],_0xe1c5('0xba'),_0xe1c5('0xd1'),_0xe1c5('0xd2')),{'interaction':_0x1f36a2})['then'](function(_0x2fb43f){var _0x1531ec=path[_0xe1c5('0x7c')](_0x1ef9a4,_0xe1c5('0xd3')+_0x5b7efc['id']+'-'+_0x80608f+_0xe1c5('0xd4'));var _0x2e53db={'path':_0x1531ec,'channel':_0xe1c5('0xd5'),'interactionId':_0x5b7efc['id']};return pdf[_0xe1c5('0xd6')](_0x2fb43f,_0x2e53db);})[_0xe1c5('0x17')](function(){return new Promise(function(_0x2bed32,_0x26509a){zipdir(_0x1ef9a4,{'saveTo':_0x2e2838},function(_0x37e484,_0x1493da){if(_0x37e484)return _0x26509a(_0x37e484);return _0x2bed32(_0x1493da);});})['then'](function(){return new BPromise(function(_0x417fa9,_0x495826){rimraf(_0x1ef9a4,function(_0x5309cd){if(_0x5309cd)_0x495826(_0x5309cd);return _0x417fa9();});});})[_0xe1c5('0x17')](function(){return _0x2bb4bc[_0xe1c5('0x7f')](_0x2e2838,_0x1ce1e8,function(_0x2bcb78){if(_0x2bcb78){logger[_0xe1c5('0x1b')](_0xe1c5('0xd7'),_0x2bcb78);}else{fs[_0xe1c5('0xd8')](_0x2e2838);}});});});}else{return _0x2bb4bc['sendStatus'](0xc8);}})['catch'](handleError(_0x2bb4bc,null));};
\ No newline at end of file