Built motion from commit e02f907f.|2.6.14
[motion2.git] / server / api / chatInteraction / chatInteraction.controller.js
index 3813d7e..9ce65b0 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x8ec7=['host','port','secure','auth','pass','sendMail','\x22%s\x22\x20<%s>','mailTranscript','Mail\x20Transcript','addMessage','ids','omit','getMessages','hasOwnProperty','ChatInteractionId','YYYY-MM-DD\x20HH:mm:ss','options','include','rows','getMyMessages','includeAgent','findAll','addTags','setTags','spread','color','emit','chatInteractionTags:save','removeTags','unix','root','server','files','tmp','attachments','transcript-%d-%s.zip','Contact','firstName','lastName','direction','Account','Owner','get','mkdirSync','10px','40px','<div\x20class=\x22header\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<h5>Interaction\x20Transcript</h5>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','<hr\x20class=\x22separator\x22/>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22footer\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22left\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22center\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>{{page}}/{{pages}}</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22right\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','YYYY-MM-DD','N.A.','disposition','browserName','osName','referer','customerIp','customerPort','tail','pipe','views','toFile','transcript-','.pdf','log','html-pdf','rimraf','zip-dir','request-promise','moment','bluebird','path','sox','to-csv','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','jayson/promise','client','http','request','then','info','ChatInteraction,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','ChatInteraction,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','count','offset','limit','set','json','apply','reject','save','update','destroy','stack','name','send','Users','map','fullname','TagIds','Tags','forEach','push','index','ChatInteraction','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','nolimit','order','sort','pick','select','field','from','tools_tags','u.fullname','ui.ChatInteractionId','user_has_chat_interactions','left_join','users','chat_interactions','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','chat_websites','a.id\x20=\x20i.ChatWebsiteId','chat_messages','me.ChatInteractionId\x20=\x20i.id','chat_interaction_has_tags','it.ChatInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','parseSearch','search','conditions','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','operator','$substring','split','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','find','ContactId','text','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','buildExpression','some','compact','isEmpty','i.ChatWebsiteId\x20IN\x20?','concat','createdAt','parse','$gte','where','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','isNumeric','i.id\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','DESC','t.id\x20IN\x20?','resolve','ChatWebsiteId','i.ChatWebsiteId\x20IS\x20NOT\x20NULL','user','role','agent','i.ChatWebsiteId\x20IS\x20NULL','sequelize','toString','keyBy','a.key','a.mandatoryDisposition','Account.mandatoryDisposition','CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','i.*','Contact.firstName','c.lastName','Contact.lastName','c.email','Contact.email','Contact.phone','c.mobile','Contact.mobile','c.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','groupBy','all','show','params','keys','includeAll','merge','body','describe','createVidaooSession','findOne','vidaooApiKey','vidaooEscalation','POST','https://api-vidaoo.xcally.com/api/v1/sessions','MotionCWB:','follow','Sequelize','ValidationError','Error\x20in\x20Vidaoo\x20configuration','out','ChatMessage','create','Unable\x20to\x20create\x20Vidaoo\x20session','updateAttributes','abandon','Interaction\x20already\x20assigned','closed','AbandonInteraction','attachmentUpload','file','basename','Attachment','attachmentDownload','Unauthorized','attachId','download','join','server/files/attachments/','close','format','now','Messages','User','ChatWebsite','CmContact','%s%d','agentAlias','System','customer','Visitor','agentIdentifier','website_alias','agent_alias','alias','[%s]\x20%s:\x20%s\x0a','MM/DD/YYYY\x20HH:mm:ss','secret','appendFileSync','MailAccount','MailServerOut','Smtp','service'];(function(_0xa464c9,_0x7c86d8){var _0x3d73c4=function(_0x5c2056){while(--_0x5c2056){_0xa464c9['push'](_0xa464c9['shift']());}};_0x3d73c4(++_0x7c86d8);}(_0x8ec7,0x176));var _0x78ec=function(_0x502c7d,_0x2f1285){_0x502c7d=_0x502c7d-0x0;var _0x30b7ed=_0x8ec7[_0x502c7d];return _0x30b7ed;};'use strict';var pdf=require(_0x78ec('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x78ec('0x1'));var zipdir=require(_0x78ec('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x78ec('0x3'));var moment=require(_0x78ec('0x4'));var BPromise=require(_0x78ec('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0x78ec('0x6'));var sox=require(_0x78ec('0x7'));var csv=require(_0x78ec('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x78ec('0x9'));var crypto=require(_0x78ec('0xa'));var jsforce=require(_0x78ec('0xb'));var deskjs=require(_0x78ec('0xc'));var toCsv=require('to-csv');var querystring=require(_0x78ec('0xd'));var Papa=require(_0x78ec('0xe'));var Redis=require(_0x78ec('0xf'));var authService=require(_0x78ec('0x10'));var qs=require(_0x78ec('0x11'));var as=require(_0x78ec('0x12'));var hardwareService=require(_0x78ec('0x13'));var logger=require('../../config/logger')(_0x78ec('0x14'));var utils=require(_0x78ec('0x15'));var config=require(_0x78ec('0x16'));var licenseUtil=require(_0x78ec('0x17'));var db=require(_0x78ec('0x18'))['db'];config[_0x78ec('0x19')]=_['defaults'](config[_0x78ec('0x19')],{'host':_0x78ec('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x78ec('0x19')]));require('./chatInteraction.socket')['register'](socket);var jayson=require(_0x78ec('0x1b'));var client=jayson[_0x78ec('0x1c')][_0x78ec('0x1d')]({'port':0x232b});var client9004=jayson[_0x78ec('0x1c')]['http']({'port':0x232c});function respondWithRpcPromise(_0x5b1a94,_0x5664b0,_0x289abb,_0x5b6909){return new BPromise(function(_0x1d8857,_0x28fa17){var _0x36f605=_0x5b6909||client;return _0x36f605[_0x78ec('0x1e')](_0x5b1a94,_0x289abb)[_0x78ec('0x1f')](function(_0x34583e){logger[_0x78ec('0x20')]('ChatInteraction,\x20%s,\x20%s',_0x5664b0,'request\x20sent');logger['debug'](_0x78ec('0x21'),_0x5664b0,_0x78ec('0x22'),JSON[_0x78ec('0x23')](_0x34583e));if(_0x34583e['error']){if(_0x34583e[_0x78ec('0x24')][_0x78ec('0x25')]===0x1f4){logger['error'](_0x78ec('0x26'),_0x5664b0,_0x34583e[_0x78ec('0x24')][_0x78ec('0x27')]);return _0x28fa17(_0x34583e[_0x78ec('0x24')]['message']);}logger[_0x78ec('0x24')]('ChatInteraction,\x20%s,\x20%s',_0x5664b0,_0x34583e[_0x78ec('0x24')][_0x78ec('0x27')]);return _0x1d8857(_0x34583e['error'][_0x78ec('0x27')]);}else{logger[_0x78ec('0x20')](_0x78ec('0x26'),_0x5664b0,_0x78ec('0x22'));_0x1d8857(_0x34583e[_0x78ec('0x28')][_0x78ec('0x27')]);}})[_0x78ec('0x29')](function(_0x54f3e0){logger['error'](_0x78ec('0x26'),_0x5664b0,_0x54f3e0);_0x28fa17(_0x54f3e0);});});}function respondWithStatusCode(_0x54f170,_0x52ddfe){_0x52ddfe=_0x52ddfe||0xcc;return function(_0x1d1622){if(_0x1d1622){return _0x54f170[_0x78ec('0x2a')](_0x52ddfe);}return _0x54f170[_0x78ec('0x2b')](_0x52ddfe)[_0x78ec('0x2c')]();};}function respondWithResult(_0x590aae,_0x204db0){_0x204db0=_0x204db0||0xc8;return function(_0x2df14e){if(_0x2df14e){return _0x590aae['status'](_0x204db0)['json'](_0x2df14e);}};}function respondWithFilteredResult(_0x50118d,_0xced641){return function(_0x3f63ae){if(_0x3f63ae){var _0x40b93e=_0x3f63ae[_0x78ec('0x2d')],_0x44c2c5=_0xced641[_0x78ec('0x2e')],_0x797e7d=_0xced641[_0x78ec('0x2e')]+_0xced641[_0x78ec('0x2f')],_0x4a422c;if(_0x797e7d>=_0x40b93e){_0x797e7d=_0x40b93e;_0x4a422c=0xc8;}else{_0x4a422c=0xce;}_0x50118d[_0x78ec('0x2b')](_0x4a422c);return _0x50118d[_0x78ec('0x30')]('Content-Range',_0x44c2c5+'-'+_0x797e7d+'/'+_0x40b93e)[_0x78ec('0x31')](_0x3f63ae);}return null;};}function patchUpdates(_0x5c1f6e){return function(_0x247cb4){try{jsonpatch[_0x78ec('0x32')](_0x247cb4,_0x5c1f6e,!![]);}catch(_0x2ccfa5){return BPromise[_0x78ec('0x33')](_0x2ccfa5);}return _0x247cb4[_0x78ec('0x34')]();};}function saveUpdates(_0x37cbe2,_0x620342){return function(_0x4a1e72){if(_0x4a1e72){return _0x4a1e72[_0x78ec('0x35')](_0x37cbe2)[_0x78ec('0x1f')](function(_0x4c98d5){return _0x4c98d5;});}return null;};}function removeEntity(_0x3c0a68,_0x1ac940){return function(_0x5999b9){if(_0x5999b9){return _0x5999b9[_0x78ec('0x36')]()[_0x78ec('0x1f')](function(){_0x3c0a68['status'](0xcc)[_0x78ec('0x2c')]();});}};}function handleEntityNotFound(_0x5c5904,_0x5f49d8){return function(_0x56adda){if(!_0x56adda){_0x5c5904[_0x78ec('0x2a')](0x194);}return _0x56adda;};}function handleError(_0xac8bad,_0x50669f){_0x50669f=_0x50669f||0x1f4;return function(_0x18df8e){logger[_0x78ec('0x24')](_0x18df8e[_0x78ec('0x37')]);if(_0x18df8e[_0x78ec('0x38')]){delete _0x18df8e[_0x78ec('0x38')];}_0xac8bad[_0x78ec('0x2b')](_0x50669f)[_0x78ec('0x39')](_0x18df8e);};}function getInteractionUsers(_0x3670a8,_0x488cc5){return new BPromise(function(_0x41b961,_0x5d1080){try{if(_0x488cc5[_0x3670a8['id']]){_0x3670a8[_0x78ec('0x3a')]=_[_0x78ec('0x3b')](_0x488cc5[_0x3670a8['id']],function(_0x23d49a){return{'id':_0x23d49a['id'],'fullname':_0x23d49a[_0x78ec('0x3c')]};});}}catch(_0x5b388e){_0x5d1080(_0x5b388e);}_0x41b961(_0x3670a8);});}function getInteractionTags(_0x8972de,_0x126aeb){return new BPromise(function(_0x53c6a6,_0x2ea4ac){try{if(_0x8972de[_0x78ec('0x3d')]){_0x8972de[_0x78ec('0x3e')]=[];_0x8972de[_0x78ec('0x3d')]['split'](',')[_0x78ec('0x3f')](function(_0x286750){_0x8972de[_0x78ec('0x3e')][_0x78ec('0x40')](_0x126aeb[_0x286750]);});}delete _0x8972de[_0x78ec('0x3d')];}catch(_0x3a8791){_0x2ea4ac(_0x3a8791);}_0x53c6a6(_0x8972de);});}function updateChatInteraction(_0x408983,_0x4bd2cd,_0x30e850){return new BPromise(function(_0x3a949e,_0x5a5049){return getInteractionUsers(_0x408983,_0x30e850)[_0x78ec('0x1f')](function(_0x40efc2){return getInteractionTags(_0x40efc2,_0x4bd2cd);})[_0x78ec('0x1f')](function(_0x425111){_0x3a949e(_0x425111);})[_0x78ec('0x29')](function(_0x5445e3){_0x5a5049(_0x5445e3);});});}exports[_0x78ec('0x41')]=function(_0x43eefc,_0x185e5d){var _0x50e004={},_0x5e2169={},_0x2a7a7a={'count':0x0,'rows':[]};var _0x39141f=_[_0x78ec('0x3b')](db[_0x78ec('0x42')][_0x78ec('0x43')],function(_0xef91df){return{'name':_0xef91df[_0x78ec('0x44')],'type':_0xef91df[_0x78ec('0x45')][_0x78ec('0x46')]};});_0x5e2169[_0x78ec('0x47')]=_[_0x78ec('0x3b')](_0x39141f,_0x78ec('0x38'));_0x5e2169['query']=_['keys'](_0x43eefc[_0x78ec('0x48')]);_0x5e2169[_0x78ec('0x49')]=_[_0x78ec('0x4a')](_0x5e2169[_0x78ec('0x47')],_0x5e2169[_0x78ec('0x48')]);_0x50e004[_0x78ec('0x4b')]=_[_0x78ec('0x4a')](_0x5e2169[_0x78ec('0x47')],qs[_0x78ec('0x4c')](_0x43eefc['query']['fields']));_0x50e004[_0x78ec('0x4b')]=_0x50e004[_0x78ec('0x4b')][_0x78ec('0x4d')]?_0x50e004[_0x78ec('0x4b')]:_0x5e2169[_0x78ec('0x47')];if(!_0x43eefc[_0x78ec('0x48')]['hasOwnProperty'](_0x78ec('0x4e'))){_0x50e004[_0x78ec('0x2f')]=qs['limit'](_0x43eefc[_0x78ec('0x48')]['limit']);_0x50e004[_0x78ec('0x2e')]=qs[_0x78ec('0x2e')](_0x43eefc[_0x78ec('0x48')][_0x78ec('0x2e')]);}_0x50e004[_0x78ec('0x4f')]=qs[_0x78ec('0x50')](_0x43eefc['query'][_0x78ec('0x50')]);_0x50e004['where']=qs[_0x78ec('0x49')](_[_0x78ec('0x51')](_0x43eefc[_0x78ec('0x48')],_0x5e2169[_0x78ec('0x49')]),_0x39141f);var _0x29b10d=[];var _0x449665=squel[_0x78ec('0x52')]()[_0x78ec('0x53')]('id')['field'](_0x78ec('0x38'))[_0x78ec('0x53')]('color')[_0x78ec('0x54')](_0x78ec('0x55'));var _0x3c8797=squel[_0x78ec('0x52')]()[_0x78ec('0x53')]('u.id')[_0x78ec('0x53')](_0x78ec('0x56'))[_0x78ec('0x53')](_0x78ec('0x57'))[_0x78ec('0x54')](_0x78ec('0x58'),'ui')[_0x78ec('0x59')](_0x78ec('0x5a'),'u','u.id\x20=\x20ui.UserId');var _0x1570b9=squel[_0x78ec('0x52')]()['from'](_0x78ec('0x5b'),'i')[_0x78ec('0x59')]('cm_contacts','c',_0x78ec('0x5c'))[_0x78ec('0x59')](_0x78ec('0x5a'),'o','o.id\x20=\x20i.UserId')[_0x78ec('0x59')](_0x78ec('0x5d'),'a',_0x78ec('0x5e'))[_0x78ec('0x59')](_0x78ec('0x5f'),'me',_0x78ec('0x60'))[_0x78ec('0x59')](_0x78ec('0x61'),'it',_0x78ec('0x62'))[_0x78ec('0x59')](_0x78ec('0x55'),'t',_0x78ec('0x63'));var _0x2023f5=squel['expr']();var _0x1825a7=[];var _0x5e22c9=squel[_0x78ec('0x64')]();var _0x35e88e;if(_0x43eefc['query']['search']){_0x35e88e=as[_0x78ec('0x65')](_0x43eefc[_0x78ec('0x48')][_0x78ec('0x66')]);var _0x8d1b13=_0x35e88e['sqlOperator'];for(var _0x58214c=0x0;_0x58214c<_0x35e88e['conditions'][_0x78ec('0x4d')];_0x58214c++){var _0x1404a0=_0x35e88e[_0x78ec('0x67')][_0x58214c];var _0x31836c='i';var _0x12ee1f=_['find'](_0x39141f,[_0x78ec('0x38'),_0x1404a0[_0x78ec('0x53')]]);if(!_0x12ee1f){switch(_0x1404a0['field']){case _0x78ec('0x68'):if(_0x1404a0[_0x78ec('0x69')]==0x1){_0x1570b9[_0x78ec('0x6a')]('`'+_0x1404a0[_0x78ec('0x53')]+_0x78ec('0x6b'));}else{_0x1570b9[_0x78ec('0x6a')]('`'+_0x1404a0[_0x78ec('0x53')]+_0x78ec('0x6c'));}break;case'Contact':if(_0x1404a0[_0x78ec('0x6d')]===_0x78ec('0x6e')){if(_0x1404a0[_0x78ec('0x69')][_0x78ec('0x6f')]('\x20')[_0x78ec('0x4d')]>0x1){_0x2023f5[_0x8d1b13](_0x78ec('0x70'),qs['getFullTextValue'](_0x1404a0['value']),null);}else{var _0x2a9730='%'+_0x1404a0[_0x78ec('0x69')]+'%';_0x2023f5[_0x8d1b13](_0x78ec('0x71'),_0x2a9730,_0x2a9730,_0x2a9730);}}else{_0x12ee1f=_[_0x78ec('0x72')](_0x39141f,['name','ContactId']);_0x1404a0[_0x78ec('0x53')]=_0x78ec('0x73');_0x5be2c4=as['buildExpression'](_0x31836c,_0x12ee1f['type'],_0x1404a0);_0x2023f5[_0x8d1b13](_0x5be2c4[_0x78ec('0x74')],_0x5be2c4[_0x78ec('0x69')][_0x78ec('0x75')],_0x5be2c4[_0x78ec('0x69')]['end']);}break;case _0x78ec('0x76'):var _0x65368d=_0x1404a0[_0x78ec('0x69')][_0x78ec('0x6f')](',')['map'](function(_0x5ea26d){return Number(_0x5ea26d);});_0x65368d['forEach'](function(_0xe1d816){_0x5e22c9['or'](_0x78ec('0x77'),'%,'+_0xe1d816+',%');});_0x1825a7=_['union'](_0x1825a7,_0x65368d);break;case'User':if(_0x1404a0['operator']===_0x78ec('0x6e')){_0x2023f5[_0x8d1b13](_0x78ec('0x78'),'%'+_0x1404a0[_0x78ec('0x69')]+'%',null);}else{_0x12ee1f=_[_0x78ec('0x72')](_0x39141f,[_0x78ec('0x38'),_0x78ec('0x79')]);_0x1404a0['field']=_0x78ec('0x79');_0x5be2c4=as[_0x78ec('0x7a')](_0x31836c,_0x12ee1f['type'],_0x1404a0);_0x2023f5[_0x8d1b13](_0x5be2c4[_0x78ec('0x74')],_0x5be2c4['value'][_0x78ec('0x75')],_0x5be2c4[_0x78ec('0x69')]['end']);}break;case'body':_0x5be2c4=as['buildExpression']('me',null,_0x1404a0);_0x2023f5[_0x8d1b13](_0x5be2c4[_0x78ec('0x74')],_0x5be2c4[_0x78ec('0x69')][_0x78ec('0x75')],_0x5be2c4[_0x78ec('0x69')][_0x78ec('0x2c')]);break;}}else{var _0x5be2c4=as[_0x78ec('0x7a')](_0x31836c,_0x12ee1f['type'],_0x1404a0);_0x2023f5[_0x8d1b13](_0x5be2c4[_0x78ec('0x74')],_0x5be2c4['value'][_0x78ec('0x75')],_0x5be2c4['value'][_0x78ec('0x2c')]);}}}else{var _0x2a0dd4=_(_0x43eefc['query'])['keys']()['map'](function(_0x321a66){return _[_0x78ec('0x7b')](_0x39141f,[_0x78ec('0x38'),_0x321a66])?_0x321a66:undefined;})[_0x78ec('0x7c')]()[_0x78ec('0x69')]();if(!_[_0x78ec('0x7d')](_0x2a0dd4)){_0x2a0dd4[_0x78ec('0x3f')](function(_0xbcbcc5){if(_0xbcbcc5==='ChatWebsiteId'){_0x1570b9['where'](_0x78ec('0x7e'),[][_0x78ec('0x7f')](_0x43eefc['query'][_0xbcbcc5]));}else if(_0xbcbcc5===_0x78ec('0x80')){var _0x391b42=JSON[_0x78ec('0x81')](_0x43eefc[_0x78ec('0x48')][_0xbcbcc5])[_0x78ec('0x82')];var _0x3ab7c8=JSON['parse'](_0x43eefc['query'][_0xbcbcc5])['$lte'];_0x1570b9[_0x78ec('0x83')](_0x78ec('0x84'),_0x391b42,_0x3ab7c8);}else{if(_0x43eefc[_0x78ec('0x48')][_0xbcbcc5]===_0x78ec('0x85')){_0x1570b9[_0x78ec('0x83')]('i.'+_0xbcbcc5+_0x78ec('0x86'));}else{_0x1570b9[_0x78ec('0x83')]('i.'+_0xbcbcc5+'\x20=\x20?',_0x43eefc[_0x78ec('0x48')][_0xbcbcc5]);}}});}if(_0x43eefc[_0x78ec('0x48')][_0x78ec('0x87')]){if(_0x43eefc['query'][_0x78ec('0x87')]==0x1){_0x1570b9[_0x78ec('0x6a')](_0x78ec('0x88'));}else{_0x1570b9[_0x78ec('0x6a')](_0x78ec('0x89'));}}if(_0x43eefc[_0x78ec('0x48')][_0x78ec('0x8a')]){_0x1825a7=_[_0x78ec('0x8b')](_0x43eefc[_0x78ec('0x48')][_0x78ec('0x8a')])?_0x43eefc[_0x78ec('0x48')][_0x78ec('0x8a')]:new Array(_0x43eefc[_0x78ec('0x48')][_0x78ec('0x8a')]);_0x1825a7[_0x78ec('0x3f')](function(_0x4d6d01){_0x5e22c9['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x4d6d01+',%');});}if(_0x43eefc[_0x78ec('0x48')][_0x78ec('0x8c')]){var _0x365ff8=_0x43eefc[_0x78ec('0x48')][_0x78ec('0x8c')]['replace']('\x5c','\x5c\x5c')[_0x78ec('0x8d')](/'/g,'\x27\x27');if(qs[_0x78ec('0x8e')](_0x365ff8)){_0x2023f5['or'](_0x78ec('0x8f'),_0x365ff8+'%');}else{_0x2023f5['or'](_0x78ec('0x90'),qs[_0x78ec('0x91')](_0x365ff8))['or'](_0x78ec('0x92'),_0x365ff8+'%');}}}_0x1570b9['where'](_0x2023f5);_0x1570b9[_0x78ec('0x93')](_0x78ec('0x94'));var _0x168ef2={'type':db['Sequelize'][_0x78ec('0x95')][_0x78ec('0x96')],'raw':!![]};var _0x376561=_0x1570b9[_0x78ec('0x97')]();_0x376561[_0x78ec('0x53')](_0x78ec('0x94'));_0x376561[_0x78ec('0x53')](_0x78ec('0x98'),'unreadMessages');if(_0x50e004[_0x78ec('0x4f')]){_0x50e004[_0x78ec('0x4f')][_0x78ec('0x3f')](function(_0x1c000c){var _0x48e13c=_0x1c000c[0x0]===_0x78ec('0x99')?_0x1c000c[0x0]:'i.'+_0x1c000c[0x0];_0x1570b9[_0x78ec('0x4f')](_0x48e13c,_0x1c000c[0x1]===_0x78ec('0x9a')?![]:!![]);});}if(!_['isEmpty'](_0x1825a7)){_0x1570b9[_0x78ec('0x6a')](_0x5e22c9);_0x376561[_0x78ec('0x83')](_0x78ec('0x9b'),_0x1825a7);}BPromise[_0x78ec('0x9c')]()[_0x78ec('0x1f')](function(){if(!_0x35e88e){if(_0x43eefc[_0x78ec('0x48')][_0x78ec('0x9d')])return;_0x376561[_0x78ec('0x83')]('i.ChatWebsiteId\x20IS\x20NOT\x20NULL');_0x1570b9['where'](_0x78ec('0x9e'));return;}if(_0x43eefc[_0x78ec('0x9f')][_0x78ec('0xa0')]!==_0x78ec('0xa1'))return;return _0x43eefc[_0x78ec('0x9f')]['getChatWebsites']({'attributes':['id'],'raw':!![]})[_0x78ec('0x1f')](function(_0x2f4759){if(_['isEmpty'](_0x2f4759)){_0x376561[_0x78ec('0x83')]('i.ChatWebsiteId\x20IS\x20NULL');_0x1570b9[_0x78ec('0x83')](_0x78ec('0xa2'));}else{_0x376561['where']('i.ChatWebsiteId\x20IN\x20?',_[_0x78ec('0x3b')](_0x2f4759,'id'));_0x1570b9['where'](_0x78ec('0x7e'),_['map'](_0x2f4759,'id'));}});})[_0x78ec('0x1f')](function(){if(_0x43eefc[_0x78ec('0x9f')][_0x78ec('0xa0')]===_0x78ec('0xa1')&&!_0x35e88e&&!_0x43eefc[_0x78ec('0x48')][_0x78ec('0x9d')])return[];return db[_0x78ec('0xa3')][_0x78ec('0x48')](_0x376561[_0x78ec('0xa4')](),_0x168ef2);})['then'](function(_0x16f2aa){_0x2a7a7a[_0x78ec('0x2d')]=_0x16f2aa[_0x78ec('0x4d')];if(_0x2a7a7a[_0x78ec('0x2d')]===0x0)return[];return db['sequelize'][_0x78ec('0x48')](_0x449665[_0x78ec('0xa4')](),_0x168ef2)['then'](function(_0x1347d4){_0x29b10d=_[_0x78ec('0xa5')](_0x1347d4,'id');_0x168ef2=_['merge'](_0x168ef2,{'model':db['ChatInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x43eefc['query']['fields']){_0x50e004[_0x78ec('0x4b')][_0x78ec('0x3f')](function(_0x1034b9){_0x1570b9[_0x78ec('0x53')]('i.'+_0x1034b9);});}else{_0x1570b9[_0x78ec('0x53')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x78ec('0x68'));_0x1570b9['field'](_0x78ec('0xa6'),'Account.key');_0x1570b9[_0x78ec('0x53')](_0x78ec('0xa7'),_0x78ec('0xa8'));_0x1570b9[_0x78ec('0x53')](_0x78ec('0xa9'),_0x78ec('0x99'));_0x1570b9[_0x78ec('0x53')](_0x78ec('0xaa'));_0x1570b9[_0x78ec('0x53')]('c.firstName',_0x78ec('0xab'));_0x1570b9[_0x78ec('0x53')](_0x78ec('0xac'),_0x78ec('0xad'));_0x1570b9['field'](_0x78ec('0xae'),_0x78ec('0xaf'));_0x1570b9['field']('c.phone',_0x78ec('0xb0'));_0x1570b9[_0x78ec('0x53')](_0x78ec('0xb1'),_0x78ec('0xb2'));_0x1570b9['field'](_0x78ec('0xb3'),'Contact.fax');_0x1570b9['field'](_0x78ec('0xb4'),_0x78ec('0xb5'));_0x1570b9[_0x78ec('0x53')](_0x78ec('0xb6'),_0x78ec('0xb7'));_0x1570b9[_0x78ec('0x53')](_0x78ec('0xb8'),_0x78ec('0x3d'));}if(_0x50e004[_0x78ec('0x2f')])_0x1570b9[_0x78ec('0x2f')](_0x50e004[_0x78ec('0x2f')]);if(_0x50e004[_0x78ec('0x2e')])_0x1570b9['offset'](_0x50e004[_0x78ec('0x2e')]);return db[_0x78ec('0xa3')]['query'](_0x1570b9[_0x78ec('0xa4')](),_0x168ef2);})['then'](function(_0x88ebae){_0x3c8797[_0x78ec('0x83')]('ui.ChatInteractionId\x20IN\x20?',_[_0x78ec('0x3b')](_0x88ebae,'id'));return db['sequelize'][_0x78ec('0x48')](_0x3c8797[_0x78ec('0xa4')](),_0x168ef2)[_0x78ec('0x1f')](function(_0xa5274f){var _0x3d1bcb=_[_0x78ec('0xb9')](_0xa5274f,'ChatInteractionId');var _0x4f42ed=[];_0x88ebae[_0x78ec('0x3f')](function(_0xbe4602){_0x4f42ed[_0x78ec('0x40')](updateChatInteraction(_0xbe4602,_0x29b10d,_0x3d1bcb));});return BPromise[_0x78ec('0xba')](_0x4f42ed);});});})[_0x78ec('0x1f')](function(_0x4fe328){_0x2a7a7a['rows']=_0x4fe328;return _0x2a7a7a;})[_0x78ec('0x1f')](respondWithFilteredResult(_0x185e5d,_0x50e004))[_0x78ec('0x29')](handleError(_0x185e5d,null));};exports[_0x78ec('0xbb')]=function(_0x501036,_0x476a6a){var _0x193c0c={'raw':![],'where':{'id':_0x501036[_0x78ec('0xbc')]['id']}},_0x48e124={};_0x48e124[_0x78ec('0x47')]=_['keys'](db[_0x78ec('0x42')][_0x78ec('0x43')]);_0x48e124[_0x78ec('0x48')]=_[_0x78ec('0xbd')](_0x501036['query']);_0x48e124['filters']=_['intersection'](_0x48e124[_0x78ec('0x47')],_0x48e124['query']);_0x193c0c[_0x78ec('0x4b')]=_[_0x78ec('0x4a')](_0x48e124[_0x78ec('0x47')],qs[_0x78ec('0x4c')](_0x501036[_0x78ec('0x48')][_0x78ec('0x4c')]));_0x193c0c[_0x78ec('0x4b')]=_0x193c0c[_0x78ec('0x4b')][_0x78ec('0x4d')]?_0x193c0c[_0x78ec('0x4b')]:_0x48e124[_0x78ec('0x47')];if(_0x501036[_0x78ec('0x48')][_0x78ec('0xbe')]){_0x193c0c['include']=[{'all':!![]}];}_0x193c0c=_[_0x78ec('0xbf')]({},_0x193c0c,_0x501036['options']);return db[_0x78ec('0x42')][_0x78ec('0x72')](_0x193c0c)[_0x78ec('0x1f')](handleEntityNotFound(_0x476a6a,null))[_0x78ec('0x1f')](respondWithResult(_0x476a6a,null))[_0x78ec('0x29')](handleError(_0x476a6a,null));};exports['create']=function(_0x55e527,_0x14661b){return db[_0x78ec('0x42')]['create'](_0x55e527['body'],{})['then'](respondWithResult(_0x14661b,0xc9))[_0x78ec('0x29')](handleError(_0x14661b,null));};exports[_0x78ec('0x35')]=function(_0x2256ed,_0x36dd56){if(_0x2256ed[_0x78ec('0xc0')]['id']){delete _0x2256ed[_0x78ec('0xc0')]['id'];}return db[_0x78ec('0x42')][_0x78ec('0x72')]({'where':{'id':_0x2256ed[_0x78ec('0xbc')]['id']}})['then'](handleEntityNotFound(_0x36dd56,null))[_0x78ec('0x1f')](saveUpdates(_0x2256ed[_0x78ec('0xc0')],null))[_0x78ec('0x1f')](respondWithResult(_0x36dd56,null))[_0x78ec('0x29')](handleError(_0x36dd56,null));};exports['destroy']=function(_0xd75204,_0x3648a4){return db[_0x78ec('0x42')][_0x78ec('0x72')]({'where':{'id':_0xd75204[_0x78ec('0xbc')]['id']}})[_0x78ec('0x1f')](handleEntityNotFound(_0x3648a4,null))[_0x78ec('0x1f')](removeEntity(_0x3648a4,null))[_0x78ec('0x29')](handleError(_0x3648a4,null));};exports[_0x78ec('0xc1')]=function(_0x331fbf,_0x2ea71b){return db[_0x78ec('0x42')]['describe']()[_0x78ec('0x1f')](respondWithResult(_0x2ea71b,null))[_0x78ec('0x29')](handleError(_0x2ea71b,null));};exports[_0x78ec('0xc2')]=function(_0x4f4fdd,_0x5c27be){var _0x101dcb=_0x4f4fdd[_0x78ec('0xbc')]['id'];var _0x128d03;var _0x466962;var _0xf87a1f;return db[_0x78ec('0x42')][_0x78ec('0xc3')]({'where':{'id':_0x101dcb}})['then'](function(_0x4207ba){_0x128d03=_0x4207ba;return db['ChatWebsite']['findOne']({'where':{'id':_0x4207ba[_0x78ec('0x9d')]},'attributes':['id',_0x78ec('0xc4'),_0x78ec('0xc5')],'raw':!![]});})['then'](function(_0x41273f){if(_0x41273f&&_0x41273f['vidaooApiKey']&&_0x41273f[_0x78ec('0xc5')]){_0x466962=_0x41273f;var _0x1ee3fe={'rejectUnauthorized':![],'method':_0x78ec('0xc6'),'uri':_0x78ec('0xc7'),'headers':{'X-APIKEY':_0x41273f[_0x78ec('0xc4')]},'body':{'name':_0x78ec('0xc8')+_0x101dcb},'redirect':_0x78ec('0xc9'),'json':!![]};return rp(_0x1ee3fe);}else{throw new db[(_0x78ec('0xca'))][(_0x78ec('0xcb'))](_0x78ec('0xcc'));}})[_0x78ec('0x1f')](function(_0x4e959a){_0xf87a1f=_0x4e959a;if(_0xf87a1f['id']){var _0x3d2c04={'body':_0xf87a1f['join_url'],'ChatWebsiteId':_0x466962['id'],'ChatInteractionId':_0x128d03['id'],'direction':_0x78ec('0xcd'),'UserId':_0x4f4fdd[_0x78ec('0x9f')]['id']};return db[_0x78ec('0xce')][_0x78ec('0xcf')](_0x3d2c04,{});}else{throw new db[(_0x78ec('0xca'))][(_0x78ec('0xcb'))](_0x78ec('0xd0'));}})[_0x78ec('0x1f')](function(){return _0x128d03[_0x78ec('0xd1')]({'vidaooSessionId':_0xf87a1f['id']});})[_0x78ec('0x1f')](respondWithResult(_0x5c27be,null))['catch'](handleError(_0x5c27be,null));};exports['customUpdate']=function(_0x5a95c4,_0x829cbb){if(_0x5a95c4['body']['id']){delete _0x5a95c4[_0x78ec('0xc0')]['id'];}return db['ChatInteraction'][_0x78ec('0x72')]({'where':{'id':_0x5a95c4['params']['id']}})[_0x78ec('0x1f')](handleEntityNotFound(_0x829cbb,null))['then'](saveUpdates(_0x5a95c4[_0x78ec('0xc0')],null))[_0x78ec('0x1f')](respondWithResult(_0x829cbb,null))['catch'](handleError(_0x829cbb,null));};exports[_0x78ec('0xd2')]=function(_0x2bd30f,_0x37b5a3,_0x2e224d){if(_0x2bd30f['body']['id']){delete _0x2bd30f[_0x78ec('0xc0')]['id'];}return db[_0x78ec('0x42')][_0x78ec('0x72')]({'where':{'id':_0x2bd30f['params']['id']}})['then'](function(_0xbccfbd){if(!_0xbccfbd){logger[_0x78ec('0x24')]('abandonInteraction,\x20%s,\x20%s,\x20%s',_0x78ec('0xd2'),0x194,'entity\x20not\x20found');_0x37b5a3['sendStatus'](0x194);}else{if(_0xbccfbd['UserId']){throw new db[(_0x78ec('0xca'))][(_0x78ec('0xcb'))](_0x78ec('0xd3'));}}return _0xbccfbd;})[_0x78ec('0x1f')](function(_0x54476a){if(_0x54476a){return _0x54476a[_0x78ec('0x35')]({'closed':_0x2bd30f['body'][_0x78ec('0xd4')],'disposition':_0x2bd30f['body']['disposition']})['then'](function(_0x2d97ad){return _0x2d97ad;});}})[_0x78ec('0x1f')](function(_0x213e04){return respondWithRpcPromise(_0x78ec('0xd5'),_0x78ec('0xd2'),_0x2bd30f[_0x78ec('0xc0')],client9004);})[_0x78ec('0x1f')](respondWithResult(_0x37b5a3,null))['catch'](handleError(_0x37b5a3,null));};exports[_0x78ec('0xd6')]=function(_0x9e4857,_0x16b57e,_0x875d66){_0x9e4857['body'][_0x78ec('0x38')]=_0x9e4857[_0x78ec('0xd7')]['originalname'];_0x9e4857[_0x78ec('0xc0')][_0x78ec('0xd8')]=_0x9e4857[_0x78ec('0xd7')]['filename'];_0x9e4857[_0x78ec('0xc0')][_0x78ec('0x45')]=_0x9e4857[_0x78ec('0xd7')]['mimetype'];return db[_0x78ec('0xd9')][_0x78ec('0xcf')](_0x9e4857[_0x78ec('0xc0')])['then'](respondWithResult(_0x16b57e,0xc9))[_0x78ec('0x29')](handleError(_0x16b57e,null));};exports[_0x78ec('0xda')]=function(_0x189b6a,_0x5279df,_0x5f1447){return db[_0x78ec('0x42')]['findOne']({'where':{'id':_0x189b6a[_0x78ec('0xbc')]['id']},'raw':!![]})['then'](handleEntityNotFound(_0x5279df,null))[_0x78ec('0x1f')](function(_0x535c5f){if(_0x535c5f){if(_0x535c5f[_0x78ec('0xd4')]){return _0x5279df[_0x78ec('0x2b')](0x193)['json']({'status':0x193,'message':_0x78ec('0xdb')});}return db[_0x78ec('0xd9')][_0x78ec('0xc3')]({'where':{'id':_0x189b6a[_0x78ec('0x48')][_0x78ec('0xdc')]},'raw':!![]})[_0x78ec('0x1f')](handleEntityNotFound(_0x5279df,null));}})[_0x78ec('0x1f')](function(_0x5604fe){if(_0x5604fe){return _0x5279df[_0x78ec('0xdd')](path[_0x78ec('0xde')](config['root'],_0x78ec('0xdf'),_0x5604fe[_0x78ec('0xd8')]));}})['catch'](handleError(_0x5279df,null));};exports[_0x78ec('0xe0')]=function(_0x2cbc6b,_0x15620d){var _0x49cf08=null;var _0x2cf2db=null;var _0x390133=null;var _0x344109=null;if(_0x2cbc6b[_0x78ec('0xc0')]['id']){delete _0x2cbc6b[_0x78ec('0xc0')]['id'];}if(_0x2cbc6b['body']['mailTranscript']){_0x344109=path[_0x78ec('0xde')](config['root'],'server/files/chat/upload/',util[_0x78ec('0xe1')]('transcript-%s.txt',Date[_0x78ec('0xe2')]()));_0x2cbc6b[_0x78ec('0xc0')]['pathTranscript']=_0x344109;}return db[_0x78ec('0x42')]['find']({'where':{'id':_0x2cbc6b[_0x78ec('0xbc')]['id']},'include':[{'model':db[_0x78ec('0xce')],'as':_0x78ec('0xe3'),'include':[{'model':db['User'],'as':_0x78ec('0xe4')}]}]})['then'](handleEntityNotFound(_0x15620d,null))[_0x78ec('0x1f')](saveUpdates(_0x2cbc6b['body'],null))[_0x78ec('0x1f')](function(_0x1b1f40){if(_0x1b1f40){_0x49cf08=_0x1b1f40;return db[_0x78ec('0xe5')][_0x78ec('0x72')]({'where':{'id':_0x49cf08[_0x78ec('0x9d')]}});}})[_0x78ec('0x1f')](function(_0x5dc0ee){if(_0x5dc0ee){_0x390133=_0x5dc0ee;return db[_0x78ec('0xe6')][_0x78ec('0x72')]({'where':{'id':_0x49cf08[_0x78ec('0x73')]}});}})['then'](function(_0x5c36eb){if(_0x5c36eb){_0x2cf2db=_0x5c36eb;if(_0x344109){var _0x42e0ac=null;for(var _0x2532c7=0x1;_0x2532c7<_0x49cf08[_0x78ec('0xe3')][_0x78ec('0x4d')];++_0x2532c7){_0x42e0ac=_0x49cf08[_0x78ec('0xe3')][_0x2532c7];var _0x1ce004=_0x42e0ac['UserId']?util['format'](_0x78ec('0xe7'),_0x390133[_0x78ec('0xe8')],_0x42e0ac['UserId']):_0x78ec('0xe9');var _0x3bdaa0=_0x2cbc6b[_0x78ec('0xc0')][_0x78ec('0xea')]||util['format']('%s%d',_0x78ec('0xeb'),_0x42e0ac[_0x78ec('0x73')]);switch(_0x390133[_0x78ec('0xec')]){case _0x78ec('0xed'):_0x1ce004=_0x42e0ac[_0x78ec('0x79')]?util['format'](_0x78ec('0xe7'),_0x390133[_0x78ec('0xe8')],_0x42e0ac['UserId']):'System';break;case _0x78ec('0xee'):_0x1ce004=_0x42e0ac[_0x78ec('0x79')]?_0x42e0ac[_0x78ec('0xe4')][_0x78ec('0xef')]||_0x42e0ac[_0x78ec('0xe4')]['fullname']:_0x78ec('0xe9');break;case'agent_fullname':_0x1ce004=_0x42e0ac[_0x78ec('0x79')]?_0x42e0ac['User'][_0x78ec('0x3c')]:_0x78ec('0xe9');break;default:_0x1ce004=_0x42e0ac[_0x78ec('0x79')]?util[_0x78ec('0xe1')](_0x78ec('0xe7'),_0x390133[_0x78ec('0xe8')],_0x42e0ac[_0x78ec('0x79')]):_0x78ec('0xe9');}var _0x2caae2=util[_0x78ec('0xe1')](_0x78ec('0xf0'),moment(_0x42e0ac[_0x78ec('0x80')])[_0x78ec('0xe1')](_0x78ec('0xf1')),_0x42e0ac['direction']==='in'?_0x3bdaa0:_0x1ce004,_0x42e0ac[_0x78ec('0xc0')]);if(!_0x42e0ac[_0x78ec('0xf2')]){fs[_0x78ec('0xf3')](_0x344109,_0x2caae2);}}return db[_0x78ec('0xf4')][_0x78ec('0xc3')]({'where':{'service':!![]},'include':[{'model':db[_0x78ec('0xf5')],'as':_0x78ec('0xf6'),'raw':!![]}]});}}})['then'](function(_0x37b32d){if(_0x37b32d&&_0x37b32d[_0x78ec('0xf6')]&&_0x2cbc6b[_0x78ec('0xc0')]){var _0x228957={'tls':{'rejectUnauthorized':![]}};if(_0x37b32d[_0x78ec('0xf6')][_0x78ec('0xf7')]){_0x228957[_0x78ec('0xf7')]=_0x37b32d[_0x78ec('0xf6')][_0x78ec('0xf7')];}else{_0x228957[_0x78ec('0xf8')]=_0x37b32d[_0x78ec('0xf6')]['host'];_0x228957['port']=_0x37b32d[_0x78ec('0xf6')][_0x78ec('0xf9')];_0x228957[_0x78ec('0xfa')]=_0x37b32d[_0x78ec('0xf6')]['secure'];}if(_0x37b32d[_0x78ec('0xf6')]['authentication']){_0x228957[_0x78ec('0xfb')]={'user':_0x37b32d[_0x78ec('0xf6')][_0x78ec('0x9f')],'pass':_0x37b32d[_0x78ec('0xf6')][_0x78ec('0xfc')]};}return respondWithRpcPromise('SendMail',_0x78ec('0xfd'),{'account':_0x228957,'message':{'from':util[_0x78ec('0xe1')](_0x78ec('0xfe'),_0x37b32d['name'],_0x37b32d['email']||_0x37b32d[_0x78ec('0xf6')][_0x78ec('0x9f')]),'to':_0x2cbc6b[_0x78ec('0xc0')][_0x78ec('0xff')],'subject':_0x78ec('0x100'),'text':util[_0x78ec('0xe1')]('Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a',_0x2cbc6b[_0x78ec('0xc0')][_0x78ec('0xff')]),'attachments':[{'path':_0x344109}]}})['then'](function(){return _0x49cf08;})[_0x78ec('0x29')](function(_0x403b53){console[_0x78ec('0x24')](_0x403b53);});}else{return _0x49cf08;}})['then'](respondWithStatusCode(_0x15620d,0xc8))['catch'](handleError(_0x15620d,null));};exports[_0x78ec('0x101')]=function(_0x280505,_0x2cd116,_0x49b765){return db['ChatMessage'][_0x78ec('0x72')]({'where':{'id':_0x280505[_0x78ec('0xbc')]['id']}})[_0x78ec('0x1f')](handleEntityNotFound(_0x2cd116,null))[_0x78ec('0x1f')](function(_0xcb5aa){if(_0xcb5aa){return _0xcb5aa[_0x78ec('0x101')](_0x280505[_0x78ec('0xc0')][_0x78ec('0x102')],_[_0x78ec('0x103')](_0x280505[_0x78ec('0xc0')],[_0x78ec('0x102'),'id'])||{});}})[_0x78ec('0x1f')](respondWithResult(_0x2cd116,null))['catch'](handleError(_0x2cd116,null));};exports[_0x78ec('0x104')]=function(_0x1144c7,_0x3cd582,_0x312066){var _0x4ca156={'raw':![],'where':{}};var _0xd9dce9={};var _0x56c6d4={'count':0x0,'rows':[]};return db[_0x78ec('0x42')][_0x78ec('0xc3')]({'where':{'id':_0x1144c7[_0x78ec('0xbc')]['id']}})['then'](handleEntityNotFound(_0x3cd582,null))[_0x78ec('0x1f')](function(_0x189796){if(_0x189796){_0xd9dce9[_0x78ec('0x47')]=_['keys'](db['ChatMessage'][_0x78ec('0x43')]);_0xd9dce9[_0x78ec('0x48')]=_[_0x78ec('0xbd')](_0x1144c7['query']);_0xd9dce9[_0x78ec('0x49')]=_[_0x78ec('0x4a')](_0xd9dce9['model'],_0xd9dce9[_0x78ec('0x48')]);_0x4ca156[_0x78ec('0x4b')]=_[_0x78ec('0x4a')](_0xd9dce9[_0x78ec('0x47')],qs[_0x78ec('0x4c')](_0x1144c7[_0x78ec('0x48')][_0x78ec('0x4c')]));_0x4ca156[_0x78ec('0x4b')]=_0x4ca156[_0x78ec('0x4b')]['length']?_0x4ca156[_0x78ec('0x4b')]:_0xd9dce9[_0x78ec('0x47')];if(!_0x1144c7[_0x78ec('0x48')][_0x78ec('0x105')](_0x78ec('0x4e'))){_0x4ca156['limit']=qs[_0x78ec('0x2f')](_0x1144c7[_0x78ec('0x48')][_0x78ec('0x2f')]);_0x4ca156['offset']=qs[_0x78ec('0x2e')](_0x1144c7['query'][_0x78ec('0x2e')]);}_0x4ca156[_0x78ec('0x4f')]=qs[_0x78ec('0x50')](_0x1144c7['query'][_0x78ec('0x50')]);_0x4ca156[_0x78ec('0x83')]=qs['filters'](_[_0x78ec('0x51')](_0x1144c7['query'],_0xd9dce9[_0x78ec('0x49')]));_0x4ca156[_0x78ec('0x83')][_0x78ec('0x106')]=_0x189796['id'];if(_0x1144c7[_0x78ec('0x48')][_0x78ec('0x8c')]){_0x4ca156[_0x78ec('0x83')]=_[_0x78ec('0xbf')](_0x4ca156[_0x78ec('0x83')],{'$or':_[_0x78ec('0x3b')](_0x4ca156[_0x78ec('0x4b')],function(_0x37c986){var _0x474d9e={};_0x474d9e[_0x37c986]={'$like':'%'+_0x1144c7['query'][_0x78ec('0x8c')]+'%'};return _0x474d9e;})});}if(_0x1144c7['query'][_0x78ec('0x82')]){var _0x948e6c=_0x1144c7['query'][_0x78ec('0x82')][_0x78ec('0x6f')](',');var _0x2f916a={};_0x2f916a[_0x948e6c[0x0]]={'$gte':moment(_0x948e6c[0x1])['format'](_0x78ec('0x107'))};_0x4ca156[_0x78ec('0x83')]=_[_0x78ec('0xbf')](_0x4ca156['where'],_0x2f916a);}_0x4ca156=_[_0x78ec('0xbf')]({},_0x4ca156,_0x1144c7[_0x78ec('0x108')]);return db[_0x78ec('0xce')][_0x78ec('0x2d')]({'where':_0x4ca156[_0x78ec('0x83')]})['then'](function(_0x4782de){_0x56c6d4[_0x78ec('0x2d')]=_0x4782de;if(_0x1144c7[_0x78ec('0x48')][_0x78ec('0xbe')]){_0x4ca156[_0x78ec('0x109')]=[{'all':!![]}];}return db['ChatMessage']['findAll'](_0x4ca156);})['then'](function(_0x114d2c){_0x56c6d4[_0x78ec('0x10a')]=_0x114d2c;return _0x56c6d4;});}})[_0x78ec('0x1f')](respondWithFilteredResult(_0x3cd582,_0x4ca156))[_0x78ec('0x29')](handleError(_0x3cd582,null));};exports[_0x78ec('0x10b')]=function(_0x1993fd,_0x45edce,_0x3bb8a0){var _0x2e9c64={'where':{}},_0x4db2e1={},_0x5d6357={'count':0x0,'rows':[]};return db[_0x78ec('0x42')][_0x78ec('0xc3')]({'where':{'id':_0x1993fd[_0x78ec('0xbc')]['id']}})[_0x78ec('0x1f')](handleEntityNotFound(_0x45edce,null))['then'](function(_0x27df9c){if(_0x27df9c){_0x4db2e1[_0x78ec('0x47')]=_[_0x78ec('0xbd')](db[_0x78ec('0xce')]['rawAttributes']);_0x4db2e1['query']=_[_0x78ec('0xbd')](_0x1993fd[_0x78ec('0x48')]);_0x4db2e1['filters']=_[_0x78ec('0x4a')](_0x4db2e1[_0x78ec('0x47')],_0x4db2e1[_0x78ec('0x48')]);_0x2e9c64[_0x78ec('0x4b')]=_[_0x78ec('0x4a')](_0x4db2e1[_0x78ec('0x47')],qs[_0x78ec('0x4c')](_0x1993fd[_0x78ec('0x48')]['fields']));_0x2e9c64['attributes']=_0x2e9c64[_0x78ec('0x4b')][_0x78ec('0x4d')]?_0x2e9c64['attributes']:_0x4db2e1[_0x78ec('0x47')];if(!_0x1993fd[_0x78ec('0x48')]['hasOwnProperty'](_0x78ec('0x4e'))){_0x2e9c64['limit']=qs[_0x78ec('0x2f')](_0x1993fd[_0x78ec('0x48')][_0x78ec('0x2f')]);_0x2e9c64[_0x78ec('0x2e')]=qs[_0x78ec('0x2e')](_0x1993fd[_0x78ec('0x48')][_0x78ec('0x2e')]);}_0x2e9c64[_0x78ec('0x4f')]=qs[_0x78ec('0x50')](_0x1993fd[_0x78ec('0x48')][_0x78ec('0x50')]);_0x2e9c64[_0x78ec('0x83')]=qs[_0x78ec('0x49')](_[_0x78ec('0x51')](_0x1993fd['query'],_0x4db2e1['filters']));_0x2e9c64[_0x78ec('0x83')][_0x78ec('0x106')]=_0x27df9c['id'];if(_0x1993fd[_0x78ec('0x48')][_0x78ec('0x8c')]){_0x2e9c64['where']=_[_0x78ec('0xbf')](_0x2e9c64['where'],{'$or':_[_0x78ec('0x3b')](_0x2e9c64[_0x78ec('0x4b')],function(_0x5e2e6a){var _0x531d3f={};_0x531d3f[_0x5e2e6a]={'$like':'%'+_0x1993fd[_0x78ec('0x48')][_0x78ec('0x8c')]+'%'};return _0x531d3f;})});}_0x2e9c64[_0x78ec('0x83')]['secret']=![];if(_0x1993fd[_0x78ec('0x48')]['id']){_0x2e9c64[_0x78ec('0x83')]['id']={'$gt':_0x1993fd[_0x78ec('0x48')]['id']};}_0x2e9c64=_['merge']({},_0x2e9c64,_0x1993fd[_0x78ec('0x108')]);return db[_0x78ec('0xce')][_0x78ec('0x2d')]({'where':_0x2e9c64[_0x78ec('0x83')]})[_0x78ec('0x1f')](function(_0x4cb5ce){_0x5d6357['count']=_0x4cb5ce;_0x2e9c64[_0x78ec('0x109')]=[];if(_0x1993fd['query'][_0x78ec('0x10c')]){_0x2e9c64[_0x78ec('0x109')][_0x78ec('0x40')]({'model':db[_0x78ec('0xe4')],'as':'User','attributes':['id',_0x78ec('0x3c'),_0x78ec('0xef')]});}if(_0x1993fd['query'][_0x78ec('0xbe')]){_0x2e9c64[_0x78ec('0x109')]=[{'all':!![]}];}return db[_0x78ec('0xce')][_0x78ec('0x10d')](_0x2e9c64);})['then'](function(_0x1d6b19){_0x5d6357[_0x78ec('0x10a')]=_0x1d6b19;return _0x5d6357;});}})[_0x78ec('0x1f')](respondWithFilteredResult(_0x45edce,_0x2e9c64))[_0x78ec('0x29')](handleError(_0x45edce,null));};exports[_0x78ec('0x10e')]=function(_0x5a076a,_0x37be0d,_0x142bd5){return db[_0x78ec('0x42')][_0x78ec('0x72')]({'where':{'id':_0x5a076a[_0x78ec('0xbc')]['id']}})[_0x78ec('0x1f')](handleEntityNotFound(_0x37be0d,null))[_0x78ec('0x1f')](function(_0x195fb6){if(_0x195fb6){return _0x195fb6[_0x78ec('0x10f')](_0x5a076a[_0x78ec('0xc0')][_0x78ec('0x102')],_['omit'](_0x5a076a[_0x78ec('0xc0')],['ids','id'])||{})[_0x78ec('0x110')](function(){return db[_0x78ec('0x76')][_0x78ec('0x10d')]({'attributes':['id',_0x78ec('0x38'),_0x78ec('0x111')],'where':{'id':_0x5a076a[_0x78ec('0xc0')]['ids']}});})['then'](function(_0xe029d0){socket[_0x78ec('0x112')](_0x78ec('0x113'),{'id':Number(_0x5a076a['params']['id']),'tags':_0xe029d0||[]});return{'id':Number(_0x5a076a[_0x78ec('0xbc')]['id']),'tags':_0xe029d0||[]};});}})[_0x78ec('0x1f')](respondWithResult(_0x37be0d,null))['catch'](handleError(_0x37be0d,null));};exports[_0x78ec('0x114')]=function(_0xfa9b11,_0x2b9c77,_0x34b0af){return db[_0x78ec('0x42')][_0x78ec('0x72')]({'where':{'id':_0xfa9b11[_0x78ec('0xbc')]['id']}})['then'](handleEntityNotFound(_0x2b9c77,null))[_0x78ec('0x1f')](function(_0x5e0f9e){if(_0x5e0f9e){return _0x5e0f9e['removeTags'](_0xfa9b11[_0x78ec('0x48')][_0x78ec('0x102')]);}})['then'](respondWithStatusCode(_0x2b9c77,null))[_0x78ec('0x29')](handleError(_0x2b9c77,null));};exports[_0x78ec('0xdd')]=function(_0x4956cb,_0x509414){var _0x504c55=moment()[_0x78ec('0x115')]()[_0x78ec('0xa4')]();var _0x38c637=path['join'](config[_0x78ec('0x116')],_0x78ec('0x117'),_0x78ec('0x118'),_0x78ec('0x119'));var _0x33af7=path[_0x78ec('0xde')](config[_0x78ec('0x116')],_0x78ec('0x117'),_0x78ec('0x118'),_0x78ec('0x11a'));var _0x2ebe8f=path[_0x78ec('0xde')](_0x38c637,_0x504c55);var _0x25229c=util[_0x78ec('0xe1')](_0x78ec('0x11b'),_0x4956cb['params']['id'],_0x504c55);var _0x56d9ff=path['join'](_0x38c637,_0x25229c);var _0x25a343=[];_0x25a343[_0x78ec('0x40')]({'model':db[_0x78ec('0xe4')],'as':_0x78ec('0xe4'),'attributes':['id',_0x78ec('0x3c')],'raw':!![]});_0x25a343[_0x78ec('0x40')]({'model':db[_0x78ec('0xe6')],'as':_0x78ec('0x11c'),'attributes':['id',_0x78ec('0x11d'),_0x78ec('0x11e')],'raw':!![]});if(_0x4956cb[_0x78ec('0x48')]['attachments']){_0x25a343[_0x78ec('0x40')]({'model':db[_0x78ec('0xd9')],'as':'Attachment','raw':!![]});}var _0x5e4f68=[{'model':db[_0x78ec('0xce')],'as':_0x78ec('0xe3'),'attributes':['id',_0x78ec('0xc0'),_0x78ec('0x80'),_0x78ec('0x11f'),_0x78ec('0xf2'),_0x78ec('0x87')],'include':_0x25a343}];_0x5e4f68[_0x78ec('0x40')]({'model':db['ChatWebsite'],'as':_0x78ec('0x120'),'attributes':['id',_0x78ec('0x38')]});_0x5e4f68[_0x78ec('0x40')]({'model':db[_0x78ec('0xe4')],'as':_0x78ec('0x121'),'attributes':['id',_0x78ec('0x3c')]});return db[_0x78ec('0x42')][_0x78ec('0x72')]({'where':{'id':_0x4956cb[_0x78ec('0xbc')]['id']},'include':_0x5e4f68})['then'](handleEntityNotFound(_0x509414,null))[_0x78ec('0x1f')](function(_0x5c3736){if(_0x5c3736){var _0x5aa446=_0x5c3736[_0x78ec('0x122')]({'plain':!![]});fs[_0x78ec('0x123')](_0x2ebe8f);var _0x4c7b85={'format':'A4','border':_0x78ec('0x124'),'header':{'height':_0x78ec('0x125'),'contents':{'first':_0x78ec('0x126')}},'footer':{'height':'30px','contents':{'default':util[_0x78ec('0xe1')](_0x78ec('0x127'),util[_0x78ec('0xe1')]('%s\x20#%d','Chat',_0x5aa446['id']),moment()['format'](_0x78ec('0x128'))[_0x78ec('0xa4')]())}}};var _0x212dd2={'channel':'Chat','account':_0x5aa446[_0x78ec('0x120')][_0x78ec('0x38')],'agent':_0x5aa446[_0x78ec('0x121')]?_0x5aa446[_0x78ec('0x121')][_0x78ec('0x3c')]:_0x78ec('0x129'),'createdAt':moment(_0x5aa446[_0x78ec('0x80')])[_0x78ec('0xe1')](_0x78ec('0x107'))[_0x78ec('0xa4')](),'closedAt':_0x5aa446[_0x78ec('0xd4')]?moment(_0x5aa446['closedAt'])[_0x78ec('0xe1')](_0x78ec('0x107'))['toString']():'','disposition':_0x5aa446[_0x78ec('0x12a')],'chatInfo':{'browser':_0x5aa446[_0x78ec('0x12b')],'os':_0x5aa446[_0x78ec('0x12c')],'referer':_0x5aa446[_0x78ec('0x12d')],'customerIp':_0x5aa446[_0x78ec('0x12e')],'customerPort':_0x5aa446[_0x78ec('0x12f')]?_0x5aa446[_0x78ec('0x12f')]:_0x78ec('0x129')},'messages':_(_0x5aa446[_0x78ec('0xe3')])[_0x78ec('0x130')]()['filter']({'secret':![]})[_0x78ec('0x3b')](function(_0x4861c7){if(_0x4861c7[_0x78ec('0xd9')]){var _0x5081aa=path['join'](_0x33af7,_0x4861c7[_0x78ec('0xd9')][_0x78ec('0xd8')]);if(fs['existsSync'](_0x5081aa)){fs['createReadStream'](_0x5081aa)[_0x78ec('0x131')](fs['createWriteStream'](path[_0x78ec('0xde')](_0x2ebe8f,_0x4861c7['Attachment']['basename'])));}}return{'date':moment(_0x4861c7[_0x78ec('0x80')])[_0x78ec('0xe1')]('YYYY-MM-DD\x20HH:mm:ss')['toString'](),'sender':_0x4861c7[_0x78ec('0x11f')]===_0x78ec('0xcd')?_0x4861c7[_0x78ec('0xe4')]?_0x4861c7[_0x78ec('0xe4')][_0x78ec('0x3c')]:_0x78ec('0xe9'):_0x4861c7[_0x78ec('0x11c')][_0x78ec('0x11d')]+(_0x4861c7['Contact'][_0x78ec('0x11e')]?'\x20'+_0x4861c7[_0x78ec('0x11c')][_0x78ec('0x11e')]:''),'body':_0x4861c7['Attachment']?_0x4861c7['Attachment']['basename']:_0x4861c7[_0x78ec('0xc0')],'direction':_0x4861c7[_0x78ec('0x11f')]===_0x78ec('0xcd')?'A':'C','secret':_0x4861c7[_0x78ec('0xf2')],'read':_0x4861c7[_0x78ec('0x87')],'attachment':_0x4861c7[_0x78ec('0xd9')]};})[_0x78ec('0x69')]()};return ejs['renderFile'](path[_0x78ec('0xde')](config[_0x78ec('0x116')],'server',_0x78ec('0x132'),'downloadInteraction.html'),{'interaction':_0x212dd2})[_0x78ec('0x1f')](function(_0x3da878){return new BPromise(function(_0x57b016,_0xe8f73b){pdf[_0x78ec('0xcf')](_0x3da878,_0x4c7b85)[_0x78ec('0x133')](path[_0x78ec('0xde')](_0x2ebe8f,_0x78ec('0x134')+_0x5aa446['id']+'-'+_0x504c55+_0x78ec('0x135')),function(_0x4052db,_0x22f210){if(_0x4052db)return _0xe8f73b(_0x4052db);_0x57b016(_0x22f210);});});})[_0x78ec('0x1f')](function(){return new BPromise(function(_0x395619,_0x3183d5){zipdir(_0x2ebe8f,{'saveTo':_0x56d9ff},function(_0xf51564,_0x5ec77b){if(_0xf51564)return _0x3183d5(_0xf51564);return _0x395619(_0x5ec77b);});})['then'](function(){return new BPromise(function(_0x4ebf5a,_0x3614a2){rimraf(_0x2ebe8f,function(_0x14ea96){if(_0x14ea96)_0x3614a2(_0x14ea96);return _0x4ebf5a();});});})[_0x78ec('0x1f')](function(){return _0x509414[_0x78ec('0xdd')](_0x56d9ff,_0x25229c,function(_0x533fa2){if(_0x533fa2){console[_0x78ec('0x136')]('err',_0x533fa2);}else{fs['unlinkSync'](_0x56d9ff);}});});});}else{return _0x509414['sendStatus'](0xc8);}})['catch'](handleError(_0x509414,null));};
\ No newline at end of file
+var _0xe6b0=['contact','agent','interaction','account','index','map','ChatInteraction','rawAttributes','type','key','getOptions','findAll','chat','query','user','params','model','keys','filters','intersection','fields','includeAll','include','options','find','create','update','describe','createVidaooSession','findOne','vidaooEscalation','vidaooTopic','vidaooNote','vidaooApiKey','email','POST','https://api-vidaoo.xcally.com/api/v1/meetings','isNull','follow','Sequelize','ValidationError','Error\x20in\x20conversion\x20vidaooMetadata','Error\x20in\x20Vidaoo\x20configuration','join_url','out','Unable\x20to\x20create\x20Vidaoo\x20session','updateAttributes','customUpdate','Contact','abandonInteraction,\x20%s,\x20%s,\x20%s','UserId','disposition','AbandonInteraction','abandon','attachmentUpload','originalname','filename','file','mimetype','Attachment','attachmentDownload','closed','Unauthorized','attachId','ChatOfflineMessageId','join','root','offline-chat/','download','close','server/files/chat/upload/','format','transcript-%s.txt','now','ChatMessage','Messages','User','ChatWebsiteId','ContactId','length','%s%d','agentAlias','System','customer','Visitor','website_alias','agent_alias','alias','fullname','[%s]\x20%s:\x20%s\x0a','createdAt','MM/DD/YYYY\x20HH:mm:ss','direction','secret','appendFileSync','MailAccount','MailServerOut','Smtp','CloudProvider','getSmtpOptions','sendMail','\x22%s\x22\x20<%s>','mailTranscript','Mail\x20Transcript','Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a','addMessage','omit','ids','getMessages','attributes','hasOwnProperty','nolimit','order','sort','where','ChatInteractionId','filter','$gte','split','merge','count','rows','getMyMessages','includeAgent','push','addTags','spread','Tag','color','emit','chatInteractionTags:save','removeTags','server','files','attachments','CmContact','lastName','read','ChatWebsite','Owner','mkdirSync','Chat','Account','N.A.','YYYY-MM-DD\x20HH:mm:ss','toString','closedAt','browserName','osName','referer','customerIp','customerPort','tail','existsSync','pipe','createWriteStream','basename','firstName','renderFile','views','downloadInteraction.ejs','transcript-','.pdf','createPdfFromHTML','err','unlinkSync','rimraf','zip-dir','request-promise','moment','bluebird','path','ejs','lodash','ioredis','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','jayson/promise','client','http','request','info','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','ChatInteraction,\x20%s,\x20%s','message','result','catch','status','json','undefined','limit','offset','set','Content-Range','then','destroy','end','sendStatus','name','send','render','body'];(function(_0x3bb069,_0x19acfc){var _0x276596=function(_0x56dbb2){while(--_0x56dbb2){_0x3bb069['push'](_0x3bb069['shift']());}};_0x276596(++_0x19acfc);}(_0xe6b0,0xa6));var _0x0e6b=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xe6b0[_0x3dd15e];return _0x231fd0;};'use strict';var rimraf=require(_0x0e6b('0x0'));var zipdir=require(_0x0e6b('0x1'));var rp=require(_0x0e6b('0x2'));var moment=require(_0x0e6b('0x3'));var BPromise=require(_0x0e6b('0x4'));var Mustache=require('mustache');var util=require('util');var path=require(_0x0e6b('0x5'));var ejs=require(_0x0e6b('0x6'));var fs=require('fs');var _=require(_0x0e6b('0x7'));var Redis=require(_0x0e6b('0x8'));var interaction=require('../../components/interaction/service');var qs=require(_0x0e6b('0x9'));var pdf=require(_0x0e6b('0xa'));var logger=require(_0x0e6b('0xb'))(_0x0e6b('0xc'));var config=require(_0x0e6b('0xd'));var db=require(_0x0e6b('0xe'))['db'];config[_0x0e6b('0xf')]=_[_0x0e6b('0x10')](config['redis'],{'host':_0x0e6b('0x11'),'port':0x18eb});var socket=require(_0x0e6b('0x12'))(new Redis(config[_0x0e6b('0xf')]));require('./chatInteraction.socket')['register'](socket);var jayson=require(_0x0e6b('0x13'));var client=jayson[_0x0e6b('0x14')][_0x0e6b('0x15')]({'port':0x232b});var client9004=jayson[_0x0e6b('0x14')][_0x0e6b('0x15')]({'port':0x232c});function respondWithRpcPromise(_0xb9f5a8,_0x4f6794,_0x59a42d,_0x5f41a8){return new BPromise(function(_0xa08547,_0x4fd5f6){var _0x4f6508=_0x5f41a8||client;return _0x4f6508[_0x0e6b('0x16')](_0xb9f5a8,_0x59a42d)['then'](function(_0x53209e){logger[_0x0e6b('0x17')]('ChatInteraction,\x20%s,\x20%s',_0x4f6794,_0x0e6b('0x18'));logger[_0x0e6b('0x19')](_0x0e6b('0x1a'),_0x4f6794,_0x0e6b('0x18'),JSON[_0x0e6b('0x1b')](_0x53209e));if(_0x53209e[_0x0e6b('0x1c')]){if(_0x53209e['error']['code']===0x1f4){logger['error'](_0x0e6b('0x1d'),_0x4f6794,_0x53209e[_0x0e6b('0x1c')][_0x0e6b('0x1e')]);return _0x4fd5f6(_0x53209e['error'][_0x0e6b('0x1e')]);}logger[_0x0e6b('0x1c')](_0x0e6b('0x1d'),_0x4f6794,_0x53209e[_0x0e6b('0x1c')][_0x0e6b('0x1e')]);return _0xa08547(_0x53209e[_0x0e6b('0x1c')][_0x0e6b('0x1e')]);}else{logger[_0x0e6b('0x17')](_0x0e6b('0x1d'),_0x4f6794,_0x0e6b('0x18'));_0xa08547(_0x53209e[_0x0e6b('0x1f')][_0x0e6b('0x1e')]);}})[_0x0e6b('0x20')](function(_0x214f6f){logger['error'](_0x0e6b('0x1d'),_0x4f6794,_0x214f6f);_0x4fd5f6(_0x214f6f);});});}function respondWithStatusCode(_0x1a3f04,_0x182cff){_0x182cff=_0x182cff||0xcc;return function(_0xbf0606){if(_0xbf0606){return _0x1a3f04['sendStatus'](_0x182cff);}return _0x1a3f04[_0x0e6b('0x21')](_0x182cff)['end']();};}function respondWithResult(_0x4d06e2,_0x2645fa){_0x2645fa=_0x2645fa||0xc8;return function(_0x140f2c){if(_0x140f2c){return _0x4d06e2['status'](_0x2645fa)[_0x0e6b('0x22')](_0x140f2c);}};}function respondWithFilteredResult(_0x11a99e,_0x28d173){return function(_0x48302a){if(_0x48302a){var _0x4bf6d2=typeof _0x28d173['offset']===_0x0e6b('0x23')&&typeof _0x28d173[_0x0e6b('0x24')]==='undefined';var _0x4f75c5=_0x48302a['count'];var _0x1700a7=_0x4bf6d2?0x0:_0x28d173[_0x0e6b('0x25')];var _0x2a3139=_0x4bf6d2?_0x48302a['count']:_0x28d173['offset']+_0x28d173[_0x0e6b('0x24')];var _0x1dc895;if(_0x2a3139>=_0x4f75c5){_0x2a3139=_0x4f75c5;_0x1dc895=0xc8;}else{_0x1dc895=0xce;}_0x11a99e[_0x0e6b('0x21')](_0x1dc895);return _0x11a99e[_0x0e6b('0x26')](_0x0e6b('0x27'),_0x1700a7+'-'+_0x2a3139+'/'+_0x4f75c5)[_0x0e6b('0x22')](_0x48302a);}return null;};}function saveUpdates(_0x62db5){return function(_0x38fd28){if(_0x38fd28){return _0x38fd28['update'](_0x62db5)[_0x0e6b('0x28')](function(_0x172bd3){return _0x172bd3;});}return null;};}function removeEntity(_0x5a8693){return function(_0x1d1416){if(_0x1d1416){return _0x1d1416[_0x0e6b('0x29')]()[_0x0e6b('0x28')](function(){_0x5a8693[_0x0e6b('0x21')](0xcc)[_0x0e6b('0x2a')]();});}};}function handleEntityNotFound(_0x88103e){return function(_0x4f2dd8){if(!_0x4f2dd8){_0x88103e[_0x0e6b('0x2b')](0x194);}return _0x4f2dd8;};}function handleError(_0xeafcc6,_0x715d4b){_0x715d4b=_0x715d4b||0x1f4;return function(_0x7360e0){logger[_0x0e6b('0x1c')](_0x7360e0['stack']);if(_0x7360e0['name']){delete _0x7360e0[_0x0e6b('0x2c')];}_0xeafcc6[_0x0e6b('0x21')](_0x715d4b)[_0x0e6b('0x2d')](_0x7360e0);};}function getMustacheRender(_0x1a5651,_0xb5a0fe){return Mustache[_0x0e6b('0x2e')](_0x1a5651,_['merge'](_0xb5a0fe[_0x0e6b('0x2f')],{'contact':_0xb5a0fe[_0x0e6b('0x30')],'message':_0xb5a0fe[_0x0e6b('0x1e')],'agent':_0xb5a0fe[_0x0e6b('0x31')],'interaction':_0xb5a0fe[_0x0e6b('0x32')],'account':_0xb5a0fe[_0x0e6b('0x33')]}))||'';}exports[_0x0e6b('0x34')]=function(_0x22a214,_0x302b96){var _0x2ba04c={};var _0x36b399=_[_0x0e6b('0x35')](db[_0x0e6b('0x36')][_0x0e6b('0x37')],function(_0x39f400){return{'name':_0x39f400['fieldName'],'type':_0x39f400[_0x0e6b('0x38')][_0x0e6b('0x39')]};});_0x2ba04c=qs[_0x0e6b('0x3a')](_0x36b399,_0x22a214);return interaction[_0x0e6b('0x3b')](_0x0e6b('0x3c'),_0x22a214[_0x0e6b('0x3d')],_0x22a214[_0x0e6b('0x3e')],_0x2ba04c,_0x36b399)[_0x0e6b('0x28')](respondWithFilteredResult(_0x302b96,_0x2ba04c))[_0x0e6b('0x20')](handleError(_0x302b96,null));};exports['show']=function(_0x2e3645,_0x2f37b0){var _0x38314b={'raw':![],'where':{'id':_0x2e3645[_0x0e6b('0x3f')]['id']}},_0x3c363c={};_0x3c363c[_0x0e6b('0x40')]=_[_0x0e6b('0x41')](db[_0x0e6b('0x36')]['rawAttributes']);_0x3c363c['query']=_[_0x0e6b('0x41')](_0x2e3645['query']);_0x3c363c[_0x0e6b('0x42')]=_[_0x0e6b('0x43')](_0x3c363c['model'],_0x3c363c[_0x0e6b('0x3d')]);_0x38314b['attributes']=_[_0x0e6b('0x43')](_0x3c363c['model'],qs[_0x0e6b('0x44')](_0x2e3645['query'][_0x0e6b('0x44')]));_0x38314b['attributes']=_0x38314b['attributes']['length']?_0x38314b['attributes']:_0x3c363c[_0x0e6b('0x40')];if(_0x2e3645[_0x0e6b('0x3d')][_0x0e6b('0x45')]){_0x38314b[_0x0e6b('0x46')]=[{'all':!![]}];}_0x38314b=_['merge']({},_0x38314b,_0x2e3645[_0x0e6b('0x47')]);return db[_0x0e6b('0x36')][_0x0e6b('0x48')](_0x38314b)[_0x0e6b('0x28')](handleEntityNotFound(_0x2f37b0,null))[_0x0e6b('0x28')](respondWithResult(_0x2f37b0,null))[_0x0e6b('0x20')](handleError(_0x2f37b0,null));};exports[_0x0e6b('0x49')]=function(_0x44f5bd,_0x2c79de){return db[_0x0e6b('0x36')]['create'](_0x44f5bd[_0x0e6b('0x2f')],{})['then'](respondWithResult(_0x2c79de,0xc9))['catch'](handleError(_0x2c79de,null));};exports[_0x0e6b('0x4a')]=function(_0x4f7059,_0x2e46e7){if(_0x4f7059[_0x0e6b('0x2f')]['id']){delete _0x4f7059[_0x0e6b('0x2f')]['id'];}return db[_0x0e6b('0x36')][_0x0e6b('0x48')]({'where':{'id':_0x4f7059[_0x0e6b('0x3f')]['id']}})[_0x0e6b('0x28')](handleEntityNotFound(_0x2e46e7,null))['then'](saveUpdates(_0x4f7059['body'],null))[_0x0e6b('0x28')](respondWithResult(_0x2e46e7,null))[_0x0e6b('0x20')](handleError(_0x2e46e7,null));};exports[_0x0e6b('0x29')]=function(_0x3df0c9,_0x426ac9){return db['ChatInteraction'][_0x0e6b('0x48')]({'where':{'id':_0x3df0c9[_0x0e6b('0x3f')]['id']}})['then'](handleEntityNotFound(_0x426ac9,null))['then'](removeEntity(_0x426ac9,null))[_0x0e6b('0x20')](handleError(_0x426ac9,null));};exports[_0x0e6b('0x4b')]=function(_0x4f8cc2,_0x174186){return db[_0x0e6b('0x36')][_0x0e6b('0x4b')]()['then'](respondWithResult(_0x174186,null))[_0x0e6b('0x20')](handleError(_0x174186,null));};exports[_0x0e6b('0x4c')]=function(_0x3a4aab,_0x380aa2){var _0x3be12c=_0x3a4aab[_0x0e6b('0x3f')]['id'];var _0x35c629;var _0x5249ed;var _0x3c8ed5;return db[_0x0e6b('0x36')][_0x0e6b('0x4d')]({'where':{'id':_0x3be12c}})[_0x0e6b('0x28')](function(_0x5cf9b8){_0x35c629=_0x5cf9b8;return db['ChatWebsite'][_0x0e6b('0x4d')]({'where':{'id':_0x5cf9b8['ChatWebsiteId']},'attributes':['id','vidaooApiKey',_0x0e6b('0x4e'),_0x0e6b('0x4f'),_0x0e6b('0x50'),'vidaooMetadata'],'raw':!![]});})[_0x0e6b('0x28')](function(_0x29725a){if(_0x29725a&&_0x29725a[_0x0e6b('0x51')]&&_0x29725a[_0x0e6b('0x4e')]){_0x5249ed=_0x29725a;var _0x42cf23={'interaction':{'id':_0x3be12c},'agent':{'id':_0x3a4aab[_0x0e6b('0x3e')]['id'],'name':_0x3a4aab[_0x0e6b('0x3e')][_0x0e6b('0x2c')],'fullname':_0x3a4aab['user']['fullname'],'email':_0x3a4aab['user'][_0x0e6b('0x52')]},'contact':_0x3a4aab['body']['contact'],'account':_0x3a4aab[_0x0e6b('0x2f')][_0x0e6b('0x33')]};var _0x12a54b={'rejectUnauthorized':![],'method':_0x0e6b('0x53'),'url':_0x0e6b('0x54'),'headers':{'X-APIKEY':_0x29725a[_0x0e6b('0x51')]},'body':{'duration':null,'scheduledAt':null,'participants':[_0x3a4aab[_0x0e6b('0x3e')][_0x0e6b('0x52')]],'buttons':null,'topic':_0x5249ed[_0x0e6b('0x4f')],'note':_[_0x0e6b('0x55')](_0x5249ed[_0x0e6b('0x50')])?null:getMustacheRender(_0x5249ed[_0x0e6b('0x50')],_0x42cf23),'metadata':null},'redirect':_0x0e6b('0x56'),'json':!![]};try{if(!_['isNull'](_0x5249ed['vidaooMetadata'])){var _0x1c2f68=getMustacheRender(_0x5249ed['vidaooMetadata'],_0x42cf23);var _0x16e9ba=JSON['parse'](_0x1c2f68);_0x12a54b['body']['metadata']=_0x16e9ba;}}catch(_0x70b3f7){throw new db[(_0x0e6b('0x57'))][(_0x0e6b('0x58'))](_0x0e6b('0x59'));}return rp(_0x12a54b);}else{throw new db[(_0x0e6b('0x57'))][(_0x0e6b('0x58'))](_0x0e6b('0x5a'));}})[_0x0e6b('0x28')](function(_0x1b8e53){_0x3c8ed5=_0x1b8e53;if(_0x3c8ed5['id']){var _0x1095f3={'body':_0x3c8ed5[_0x0e6b('0x5b')],'ChatWebsiteId':_0x5249ed['id'],'ChatInteractionId':_0x35c629['id'],'direction':_0x0e6b('0x5c'),'UserId':_0x3a4aab[_0x0e6b('0x3e')]['id']};return db['ChatMessage'][_0x0e6b('0x49')](_0x1095f3,{});}else{throw new db['Sequelize'][(_0x0e6b('0x58'))](_0x0e6b('0x5d'));}})[_0x0e6b('0x28')](function(){return _0x35c629[_0x0e6b('0x5e')]({'vidaooSessionId':_0x3c8ed5['id']});})[_0x0e6b('0x28')](respondWithResult(_0x380aa2,null))['catch'](handleError(_0x380aa2,null));};exports[_0x0e6b('0x5f')]=function(_0x3e1617,_0x58a758){if(_0x3e1617['body']['id']){delete _0x3e1617['body']['id'];}return db[_0x0e6b('0x36')][_0x0e6b('0x48')]({'where':{'id':_0x3e1617['params']['id']},'include':[{'model':db['CmContact'],'as':_0x0e6b('0x60')}]})[_0x0e6b('0x28')](handleEntityNotFound(_0x58a758,null))[_0x0e6b('0x28')](saveUpdates(_0x3e1617[_0x0e6b('0x2f')],null))[_0x0e6b('0x28')](respondWithResult(_0x58a758,null))[_0x0e6b('0x20')](handleError(_0x58a758,null));};exports['abandon']=function(_0x549c97,_0x659406){if(_0x549c97['body']['id']){delete _0x549c97[_0x0e6b('0x2f')]['id'];}return db[_0x0e6b('0x36')][_0x0e6b('0x48')]({'where':{'id':_0x549c97[_0x0e6b('0x3f')]['id']}})[_0x0e6b('0x28')](function(_0x111ac5){if(!_0x111ac5){logger[_0x0e6b('0x1c')](_0x0e6b('0x61'),'abandon',0x194,'entity\x20not\x20found');_0x659406[_0x0e6b('0x2b')](0x194);}else{if(_0x111ac5[_0x0e6b('0x62')]){throw new db['Sequelize'][(_0x0e6b('0x58'))]('Interaction\x20already\x20assigned');}}return _0x111ac5;})[_0x0e6b('0x28')](function(_0x23948f){if(_0x23948f){return _0x23948f[_0x0e6b('0x4a')]({'closed':_0x549c97[_0x0e6b('0x2f')]['closed'],'disposition':_0x549c97[_0x0e6b('0x2f')][_0x0e6b('0x63')]})[_0x0e6b('0x28')](function(_0x81174){return _0x81174;});}})[_0x0e6b('0x28')](function(){return respondWithRpcPromise(_0x0e6b('0x64'),_0x0e6b('0x65'),_0x549c97[_0x0e6b('0x2f')],client9004);})['then'](respondWithResult(_0x659406,null))['catch'](handleError(_0x659406,null));};exports[_0x0e6b('0x66')]=function(_0x16b0b0,_0x134b54){_0x16b0b0[_0x0e6b('0x2f')][_0x0e6b('0x2c')]=_0x16b0b0['file'][_0x0e6b('0x67')];_0x16b0b0[_0x0e6b('0x2f')]['basename']=_0x16b0b0['file'][_0x0e6b('0x68')];_0x16b0b0['body'][_0x0e6b('0x38')]=_0x16b0b0[_0x0e6b('0x69')][_0x0e6b('0x6a')];return db[_0x0e6b('0x6b')][_0x0e6b('0x49')](_0x16b0b0[_0x0e6b('0x2f')])[_0x0e6b('0x28')](respondWithResult(_0x134b54,0xc9))[_0x0e6b('0x20')](handleError(_0x134b54,null));};exports[_0x0e6b('0x6c')]=function(_0x9a6843,_0x5f2b69){return db['ChatInteraction'][_0x0e6b('0x4d')]({'where':{'id':_0x9a6843['params']['id']},'raw':!![]})[_0x0e6b('0x28')](handleEntityNotFound(_0x5f2b69,null))['then'](function(_0x349bdd){if(_0x349bdd){if(_0x349bdd[_0x0e6b('0x6d')]){return _0x5f2b69['status'](0x193)['json']({'status':0x193,'message':_0x0e6b('0x6e')});}return db[_0x0e6b('0x6b')][_0x0e6b('0x4d')]({'where':{'id':_0x9a6843['query'][_0x0e6b('0x6f')]},'raw':!![]})['then'](handleEntityNotFound(_0x5f2b69,null));}})['then'](function(_0x26848f){if(_0x26848f){var _0x41ec79=_0x26848f[_0x0e6b('0x70')]!==null;var _0x10dc1b=path[_0x0e6b('0x71')](config[_0x0e6b('0x72')],'server/files/attachments/');if(_0x41ec79){_0x10dc1b=path[_0x0e6b('0x71')](_0x10dc1b,_0x0e6b('0x73'));}var _0x51419b=path[_0x0e6b('0x71')](_0x10dc1b,_0x26848f['basename']);return _0x5f2b69[_0x0e6b('0x74')](_0x51419b);}})[_0x0e6b('0x20')](handleError(_0x5f2b69,null));};exports[_0x0e6b('0x75')]=function(_0x4d051f,_0x86a6cd){var _0x54d345=null;var _0x3ee442=null;var _0x56a6bf=null;if(_0x4d051f[_0x0e6b('0x2f')]['id']){delete _0x4d051f['body']['id'];}if(_0x4d051f[_0x0e6b('0x2f')]['mailTranscript']){_0x56a6bf=path['join'](config[_0x0e6b('0x72')],_0x0e6b('0x76'),util[_0x0e6b('0x77')](_0x0e6b('0x78'),Date[_0x0e6b('0x79')]()));_0x4d051f[_0x0e6b('0x2f')]['pathTranscript']=_0x56a6bf;}return db[_0x0e6b('0x36')]['find']({'where':{'id':_0x4d051f[_0x0e6b('0x3f')]['id']},'include':[{'model':db[_0x0e6b('0x7a')],'as':_0x0e6b('0x7b'),'include':[{'model':db[_0x0e6b('0x7c')],'as':'User'}]}]})[_0x0e6b('0x28')](handleEntityNotFound(_0x86a6cd,null))[_0x0e6b('0x28')](saveUpdates(_0x4d051f[_0x0e6b('0x2f')],null))[_0x0e6b('0x28')](function(_0x54b058){if(_0x54b058){_0x54d345=_0x54b058;return db['ChatWebsite'][_0x0e6b('0x48')]({'where':{'id':_0x54d345[_0x0e6b('0x7d')]}});}})[_0x0e6b('0x28')](function(_0x29d669){if(_0x29d669){_0x3ee442=_0x29d669;return db['CmContact'][_0x0e6b('0x48')]({'where':{'id':_0x54d345[_0x0e6b('0x7e')]}});}})[_0x0e6b('0x28')](function(_0x446690){if(_0x446690){if(_0x56a6bf){var _0x2b3b0e=null;for(var _0x3c1522=0x1;_0x3c1522<_0x54d345[_0x0e6b('0x7b')][_0x0e6b('0x7f')];++_0x3c1522){_0x2b3b0e=_0x54d345['Messages'][_0x3c1522];var _0x3d33dd=_0x2b3b0e[_0x0e6b('0x62')]?util['format'](_0x0e6b('0x80'),_0x3ee442[_0x0e6b('0x81')],_0x2b3b0e[_0x0e6b('0x62')]):_0x0e6b('0x82');var _0x52e22a=_0x4d051f[_0x0e6b('0x2f')][_0x0e6b('0x83')]||util[_0x0e6b('0x77')](_0x0e6b('0x80'),_0x0e6b('0x84'),_0x2b3b0e[_0x0e6b('0x7e')]);switch(_0x3ee442['agentIdentifier']){case _0x0e6b('0x85'):_0x3d33dd=_0x2b3b0e[_0x0e6b('0x62')]?util[_0x0e6b('0x77')](_0x0e6b('0x80'),_0x3ee442[_0x0e6b('0x81')],_0x2b3b0e['UserId']):_0x0e6b('0x82');break;case _0x0e6b('0x86'):_0x3d33dd=_0x2b3b0e[_0x0e6b('0x62')]?_0x2b3b0e[_0x0e6b('0x7c')][_0x0e6b('0x87')]||_0x2b3b0e[_0x0e6b('0x7c')][_0x0e6b('0x88')]:_0x0e6b('0x82');break;case'agent_fullname':_0x3d33dd=_0x2b3b0e[_0x0e6b('0x62')]?_0x2b3b0e[_0x0e6b('0x7c')][_0x0e6b('0x88')]:'System';break;default:_0x3d33dd=_0x2b3b0e[_0x0e6b('0x62')]?util['format']('%s%d',_0x3ee442[_0x0e6b('0x81')],_0x2b3b0e[_0x0e6b('0x62')]):_0x0e6b('0x82');}var _0x4e9a0d=util['format'](_0x0e6b('0x89'),moment(_0x2b3b0e[_0x0e6b('0x8a')])[_0x0e6b('0x77')](_0x0e6b('0x8b')),_0x2b3b0e[_0x0e6b('0x8c')]==='in'?_0x52e22a:_0x3d33dd,_0x2b3b0e[_0x0e6b('0x2f')]);if(!_0x2b3b0e[_0x0e6b('0x8d')]){fs[_0x0e6b('0x8e')](_0x56a6bf,_0x4e9a0d);}}return db[_0x0e6b('0x8f')][_0x0e6b('0x4d')]({'where':{'service':!![]},'include':[{'model':db[_0x0e6b('0x90')],'as':_0x0e6b('0x91'),'raw':!![],'include':[{'model':db[_0x0e6b('0x92')],'as':_0x0e6b('0x92'),'raw':!![]}]}]});}}})[_0x0e6b('0x28')](function(_0x426951){if(!_0x426951||!_0x426951['Smtp']||!_0x4d051f['body'])return _0x54d345;var _0x1fe61d=_0x426951[_0x0e6b('0x93')]();return respondWithRpcPromise('SendMail',_0x0e6b('0x94'),{'account':_0x1fe61d,'message':{'from':util[_0x0e6b('0x77')](_0x0e6b('0x95'),_0x426951[_0x0e6b('0x2c')],_0x426951['email']||_0x426951[_0x0e6b('0x91')][_0x0e6b('0x3e')]),'to':_0x4d051f['body'][_0x0e6b('0x96')],'subject':_0x0e6b('0x97'),'text':util[_0x0e6b('0x77')](_0x0e6b('0x98'),_0x4d051f[_0x0e6b('0x2f')][_0x0e6b('0x96')]),'attachments':[{'path':_0x56a6bf}]}})[_0x0e6b('0x28')](function(){return _0x54d345;})[_0x0e6b('0x20')](function(_0x2e4e6e){logger[_0x0e6b('0x1c')](_0x2e4e6e);});})[_0x0e6b('0x28')](respondWithStatusCode(_0x86a6cd,0xc8))[_0x0e6b('0x20')](handleError(_0x86a6cd,null));};exports[_0x0e6b('0x99')]=function(_0x2f4f06,_0x52a78c){return db[_0x0e6b('0x7a')][_0x0e6b('0x48')]({'where':{'id':_0x2f4f06[_0x0e6b('0x3f')]['id']}})[_0x0e6b('0x28')](handleEntityNotFound(_0x52a78c,null))[_0x0e6b('0x28')](function(_0x47334e){if(_0x47334e){return _0x47334e[_0x0e6b('0x99')](_0x2f4f06[_0x0e6b('0x2f')]['ids'],_[_0x0e6b('0x9a')](_0x2f4f06[_0x0e6b('0x2f')],[_0x0e6b('0x9b'),'id'])||{});}})[_0x0e6b('0x28')](respondWithResult(_0x52a78c,null))[_0x0e6b('0x20')](handleError(_0x52a78c,null));};exports[_0x0e6b('0x9c')]=function(_0x3010bb,_0x10f747){var _0x1e89d2={'raw':![],'where':{}};var _0x4cf64a={};var _0x140d5c={'count':0x0,'rows':[]};return db[_0x0e6b('0x36')][_0x0e6b('0x4d')]({'where':{'id':_0x3010bb[_0x0e6b('0x3f')]['id']}})[_0x0e6b('0x28')](handleEntityNotFound(_0x10f747,null))['then'](function(_0x1e99a4){if(_0x1e99a4){_0x4cf64a[_0x0e6b('0x40')]=_[_0x0e6b('0x41')](db[_0x0e6b('0x7a')]['rawAttributes']);_0x4cf64a[_0x0e6b('0x3d')]=_[_0x0e6b('0x41')](_0x3010bb[_0x0e6b('0x3d')]);_0x4cf64a[_0x0e6b('0x42')]=_[_0x0e6b('0x43')](_0x4cf64a[_0x0e6b('0x40')],_0x4cf64a[_0x0e6b('0x3d')]);_0x1e89d2['attributes']=_[_0x0e6b('0x43')](_0x4cf64a[_0x0e6b('0x40')],qs['fields'](_0x3010bb[_0x0e6b('0x3d')][_0x0e6b('0x44')]));_0x1e89d2[_0x0e6b('0x9d')]=_0x1e89d2[_0x0e6b('0x9d')][_0x0e6b('0x7f')]?_0x1e89d2['attributes']:_0x4cf64a[_0x0e6b('0x40')];if(!_0x3010bb[_0x0e6b('0x3d')][_0x0e6b('0x9e')](_0x0e6b('0x9f'))){_0x1e89d2[_0x0e6b('0x24')]=qs[_0x0e6b('0x24')](_0x3010bb[_0x0e6b('0x3d')][_0x0e6b('0x24')]);_0x1e89d2['offset']=qs['offset'](_0x3010bb[_0x0e6b('0x3d')][_0x0e6b('0x25')]);}_0x1e89d2[_0x0e6b('0xa0')]=qs[_0x0e6b('0xa1')](_0x3010bb[_0x0e6b('0x3d')][_0x0e6b('0xa1')]);_0x1e89d2[_0x0e6b('0xa2')]=qs[_0x0e6b('0x42')](_['pick'](_0x3010bb['query'],_0x4cf64a[_0x0e6b('0x42')]));_0x1e89d2['where'][_0x0e6b('0xa3')]=_0x1e99a4['id'];if(_0x3010bb[_0x0e6b('0x3d')][_0x0e6b('0xa4')]){_0x1e89d2[_0x0e6b('0xa2')]=_['merge'](_0x1e89d2[_0x0e6b('0xa2')],{'$or':_[_0x0e6b('0x35')](_0x1e89d2['attributes'],function(_0x104937){var _0x2cb4a8={};_0x2cb4a8[_0x104937]={'$like':'%'+_0x3010bb[_0x0e6b('0x3d')][_0x0e6b('0xa4')]+'%'};return _0x2cb4a8;})});}if(_0x3010bb[_0x0e6b('0x3d')]['$gte']){var _0x3db079=_0x3010bb[_0x0e6b('0x3d')][_0x0e6b('0xa5')][_0x0e6b('0xa6')](',');var _0x2fc275={};_0x2fc275[_0x3db079[0x0]]={'$gte':moment(_0x3db079[0x1])[_0x0e6b('0x77')]('YYYY-MM-DD\x20HH:mm:ss')};_0x1e89d2[_0x0e6b('0xa2')]=_[_0x0e6b('0xa7')](_0x1e89d2[_0x0e6b('0xa2')],_0x2fc275);}_0x1e89d2=_[_0x0e6b('0xa7')]({},_0x1e89d2,_0x3010bb[_0x0e6b('0x47')]);return db[_0x0e6b('0x7a')][_0x0e6b('0xa8')]({'where':_0x1e89d2[_0x0e6b('0xa2')]})[_0x0e6b('0x28')](function(_0x8cfc03){_0x140d5c[_0x0e6b('0xa8')]=_0x8cfc03;if(_0x3010bb[_0x0e6b('0x3d')][_0x0e6b('0x45')]){_0x1e89d2[_0x0e6b('0x46')]=[{'all':!![]}];}return db[_0x0e6b('0x7a')][_0x0e6b('0x3b')](_0x1e89d2);})['then'](function(_0x5dbae6){_0x140d5c[_0x0e6b('0xa9')]=_0x5dbae6;return _0x140d5c;});}})[_0x0e6b('0x28')](respondWithFilteredResult(_0x10f747,_0x1e89d2))[_0x0e6b('0x20')](handleError(_0x10f747,null));};exports[_0x0e6b('0xaa')]=function(_0x1fe705,_0x975797){var _0x32e089={'where':{}},_0x1c4a5d={},_0x57b07d={'count':0x0,'rows':[]};return db['ChatInteraction'][_0x0e6b('0x4d')]({'where':{'id':_0x1fe705[_0x0e6b('0x3f')]['id']}})[_0x0e6b('0x28')](handleEntityNotFound(_0x975797,null))[_0x0e6b('0x28')](function(_0x1f7320){if(_0x1f7320){_0x1c4a5d[_0x0e6b('0x40')]=_[_0x0e6b('0x41')](db[_0x0e6b('0x7a')]['rawAttributes']);_0x1c4a5d[_0x0e6b('0x3d')]=_[_0x0e6b('0x41')](_0x1fe705[_0x0e6b('0x3d')]);_0x1c4a5d[_0x0e6b('0x42')]=_[_0x0e6b('0x43')](_0x1c4a5d['model'],_0x1c4a5d[_0x0e6b('0x3d')]);_0x32e089[_0x0e6b('0x9d')]=_['intersection'](_0x1c4a5d[_0x0e6b('0x40')],qs[_0x0e6b('0x44')](_0x1fe705['query']['fields']));_0x32e089['attributes']=_0x32e089[_0x0e6b('0x9d')][_0x0e6b('0x7f')]?_0x32e089[_0x0e6b('0x9d')]:_0x1c4a5d[_0x0e6b('0x40')];if(!_0x1fe705['query'][_0x0e6b('0x9e')](_0x0e6b('0x9f'))){_0x32e089['limit']=qs[_0x0e6b('0x24')](_0x1fe705[_0x0e6b('0x3d')][_0x0e6b('0x24')]);_0x32e089[_0x0e6b('0x25')]=qs[_0x0e6b('0x25')](_0x1fe705[_0x0e6b('0x3d')]['offset']);}_0x32e089[_0x0e6b('0xa0')]=qs[_0x0e6b('0xa1')](_0x1fe705[_0x0e6b('0x3d')][_0x0e6b('0xa1')]);_0x32e089[_0x0e6b('0xa2')]=qs[_0x0e6b('0x42')](_['pick'](_0x1fe705[_0x0e6b('0x3d')],_0x1c4a5d['filters']));_0x32e089[_0x0e6b('0xa2')]['ChatInteractionId']=_0x1f7320['id'];if(_0x1fe705['query'][_0x0e6b('0xa4')]){_0x32e089['where']=_['merge'](_0x32e089[_0x0e6b('0xa2')],{'$or':_[_0x0e6b('0x35')](_0x32e089['attributes'],function(_0x201cc6){var _0x743cca={};_0x743cca[_0x201cc6]={'$like':'%'+_0x1fe705['query'][_0x0e6b('0xa4')]+'%'};return _0x743cca;})});}_0x32e089[_0x0e6b('0xa2')]['secret']=![];if(_0x1fe705[_0x0e6b('0x3d')]['id']){_0x32e089[_0x0e6b('0xa2')]['id']={'$gt':_0x1fe705[_0x0e6b('0x3d')]['id']};}_0x32e089=_[_0x0e6b('0xa7')]({},_0x32e089,_0x1fe705[_0x0e6b('0x47')]);return db['ChatMessage'][_0x0e6b('0xa8')]({'where':_0x32e089[_0x0e6b('0xa2')]})['then'](function(_0x5b79ca){_0x57b07d[_0x0e6b('0xa8')]=_0x5b79ca;_0x32e089['include']=[];if(_0x1fe705[_0x0e6b('0x3d')][_0x0e6b('0xab')]){_0x32e089[_0x0e6b('0x46')][_0x0e6b('0xac')]({'model':db['User'],'as':_0x0e6b('0x7c'),'attributes':['id',_0x0e6b('0x88'),_0x0e6b('0x87')]});}if(_0x1fe705[_0x0e6b('0x3d')]['includeAll']){_0x32e089[_0x0e6b('0x46')]=[{'all':!![]}];}return db[_0x0e6b('0x7a')][_0x0e6b('0x3b')](_0x32e089);})[_0x0e6b('0x28')](function(_0x5ce71b){_0x57b07d[_0x0e6b('0xa9')]=_0x5ce71b;return _0x57b07d;});}})[_0x0e6b('0x28')](respondWithFilteredResult(_0x975797,_0x32e089))[_0x0e6b('0x20')](handleError(_0x975797,null));};exports[_0x0e6b('0xad')]=function(_0x19097c,_0x1c7fe5){return db[_0x0e6b('0x36')][_0x0e6b('0x48')]({'where':{'id':_0x19097c['params']['id']}})[_0x0e6b('0x28')](handleEntityNotFound(_0x1c7fe5,null))[_0x0e6b('0x28')](function(_0x250e8a){if(_0x250e8a){return _0x250e8a['setTags'](_0x19097c[_0x0e6b('0x2f')][_0x0e6b('0x9b')],_['omit'](_0x19097c[_0x0e6b('0x2f')],[_0x0e6b('0x9b'),'id'])||{})[_0x0e6b('0xae')](function(){return db[_0x0e6b('0xaf')][_0x0e6b('0x3b')]({'attributes':['id','name',_0x0e6b('0xb0')],'where':{'id':_0x19097c[_0x0e6b('0x2f')][_0x0e6b('0x9b')]}});})['then'](function(_0xa6bb05){socket[_0x0e6b('0xb1')](_0x0e6b('0xb2'),{'id':Number(_0x19097c[_0x0e6b('0x3f')]['id']),'tags':_0xa6bb05||[]});return{'id':Number(_0x19097c['params']['id']),'tags':_0xa6bb05||[]};});}})[_0x0e6b('0x28')](respondWithResult(_0x1c7fe5,null))['catch'](handleError(_0x1c7fe5,null));};exports[_0x0e6b('0xb3')]=function(_0x4ffd70,_0x2a01ee){return db['ChatInteraction'][_0x0e6b('0x48')]({'where':{'id':_0x4ffd70[_0x0e6b('0x3f')]['id']}})[_0x0e6b('0x28')](handleEntityNotFound(_0x2a01ee,null))[_0x0e6b('0x28')](function(_0x2787c2){if(_0x2787c2){return _0x2787c2[_0x0e6b('0xb3')](_0x4ffd70[_0x0e6b('0x3d')][_0x0e6b('0x9b')]);}})[_0x0e6b('0x28')](respondWithStatusCode(_0x2a01ee,null))[_0x0e6b('0x20')](handleError(_0x2a01ee,null));};exports['download']=function(_0x42c15e,_0x4ae2fc){var _0xf29a32=moment()['unix']()['toString']();var _0x3505c3=path[_0x0e6b('0x71')](config[_0x0e6b('0x72')],_0x0e6b('0xb4'),_0x0e6b('0xb5'),'tmp');var _0x452d4e=path[_0x0e6b('0x71')](config[_0x0e6b('0x72')],_0x0e6b('0xb4'),_0x0e6b('0xb5'),_0x0e6b('0xb6'));var _0x373d57=path['join'](_0x3505c3,_0xf29a32);var _0x399f9d=util[_0x0e6b('0x77')]('transcript-%d-%s.zip',_0x42c15e[_0x0e6b('0x3f')]['id'],_0xf29a32);var _0x302c0f=path[_0x0e6b('0x71')](_0x3505c3,_0x399f9d);var _0x35dba6=[];_0x35dba6[_0x0e6b('0xac')]({'model':db[_0x0e6b('0x7c')],'as':_0x0e6b('0x7c'),'attributes':['id',_0x0e6b('0x88')],'raw':!![]});_0x35dba6[_0x0e6b('0xac')]({'model':db[_0x0e6b('0xb7')],'as':'Contact','attributes':['id','firstName',_0x0e6b('0xb8')],'raw':!![]});if(_0x42c15e[_0x0e6b('0x3d')][_0x0e6b('0xb6')]){_0x35dba6[_0x0e6b('0xac')]({'model':db[_0x0e6b('0x6b')],'as':_0x0e6b('0x6b'),'raw':!![]});}var _0x54719b=[{'model':db['ChatMessage'],'as':_0x0e6b('0x7b'),'attributes':['id','body',_0x0e6b('0x8a'),_0x0e6b('0x8c'),'secret',_0x0e6b('0xb9')],'include':_0x35dba6}];_0x54719b[_0x0e6b('0xac')]({'model':db[_0x0e6b('0xba')],'as':'Account','attributes':['id',_0x0e6b('0x2c')]});_0x54719b['push']({'model':db[_0x0e6b('0x7c')],'as':_0x0e6b('0xbb'),'attributes':['id','fullname']});return db[_0x0e6b('0x36')][_0x0e6b('0x48')]({'where':{'id':_0x42c15e[_0x0e6b('0x3f')]['id']},'include':_0x54719b})[_0x0e6b('0x28')](handleEntityNotFound(_0x4ae2fc,null))[_0x0e6b('0x28')](function(_0x3bc6f0){if(_0x3bc6f0){var _0x29b23d=_0x3bc6f0['get']({'plain':!![]});fs[_0x0e6b('0xbc')](_0x373d57);var _0x2a9eab={'channel':_0x0e6b('0xbd'),'account':_0x29b23d[_0x0e6b('0xbe')][_0x0e6b('0x2c')],'agent':_0x29b23d['Owner']?_0x29b23d[_0x0e6b('0xbb')][_0x0e6b('0x88')]:_0x0e6b('0xbf'),'createdAt':moment(_0x29b23d[_0x0e6b('0x8a')])[_0x0e6b('0x77')](_0x0e6b('0xc0'))[_0x0e6b('0xc1')](),'closedAt':_0x29b23d['closed']?moment(_0x29b23d[_0x0e6b('0xc2')])[_0x0e6b('0x77')](_0x0e6b('0xc0'))['toString']():'','disposition':_0x29b23d[_0x0e6b('0x63')],'chatInfo':{'browser':_0x29b23d[_0x0e6b('0xc3')],'os':_0x29b23d[_0x0e6b('0xc4')],'referer':_0x29b23d[_0x0e6b('0xc5')],'customerIp':_0x29b23d[_0x0e6b('0xc6')],'customerPort':_0x29b23d[_0x0e6b('0xc7')]?_0x29b23d[_0x0e6b('0xc7')]:_0x0e6b('0xbf')},'messages':_(_0x29b23d['Messages'])[_0x0e6b('0xc8')]()['filter']({'secret':![]})[_0x0e6b('0x35')](function(_0x38d5d6){if(_0x38d5d6['Attachment']){var _0x122cc6=path[_0x0e6b('0x71')](_0x452d4e,_0x38d5d6[_0x0e6b('0x6b')]['basename']);if(fs[_0x0e6b('0xc9')](_0x122cc6)){fs['createReadStream'](_0x122cc6)[_0x0e6b('0xca')](fs[_0x0e6b('0xcb')](path['join'](_0x373d57,_0x38d5d6['Attachment'][_0x0e6b('0xcc')])));}}return{'date':moment(_0x38d5d6[_0x0e6b('0x8a')])[_0x0e6b('0x77')]('YYYY-MM-DD\x20HH:mm:ss')[_0x0e6b('0xc1')](),'sender':_0x38d5d6['direction']==='out'?_0x38d5d6[_0x0e6b('0x7c')]?_0x38d5d6['User'][_0x0e6b('0x88')]:_0x0e6b('0x82'):_0x38d5d6[_0x0e6b('0x60')][_0x0e6b('0xcd')]+(_0x38d5d6[_0x0e6b('0x60')][_0x0e6b('0xb8')]?'\x20'+_0x38d5d6[_0x0e6b('0x60')][_0x0e6b('0xb8')]:''),'body':_0x38d5d6['Attachment']?_0x38d5d6[_0x0e6b('0x6b')][_0x0e6b('0xcc')]:_0x38d5d6[_0x0e6b('0x2f')],'direction':_0x38d5d6['direction']===_0x0e6b('0x5c')?'A':'C','secret':_0x38d5d6[_0x0e6b('0x8d')],'read':_0x38d5d6['read'],'attachment':_0x38d5d6[_0x0e6b('0x6b')]};})['value']()};return ejs[_0x0e6b('0xce')](path[_0x0e6b('0x71')](config[_0x0e6b('0x72')],_0x0e6b('0xb4'),_0x0e6b('0xcf'),_0x0e6b('0xd0')),{'interaction':_0x2a9eab})['then'](function(_0x16a991){var _0x4b13d2=path[_0x0e6b('0x71')](_0x373d57,_0x0e6b('0xd1')+_0x29b23d['id']+'-'+_0xf29a32+_0x0e6b('0xd2'));var _0x1a3646={'path':_0x4b13d2,'channel':_0x0e6b('0xbd'),'interactionId':_0x29b23d['id']};return pdf[_0x0e6b('0xd3')](_0x16a991,_0x1a3646);})[_0x0e6b('0x28')](function(){return new Promise(function(_0x4e6ec0,_0x321adf){zipdir(_0x373d57,{'saveTo':_0x302c0f},function(_0x4745b4,_0xdb776c){if(_0x4745b4)return _0x321adf(_0x4745b4);return _0x4e6ec0(_0xdb776c);});})['then'](function(){return new BPromise(function(_0x18e261,_0x335268){rimraf(_0x373d57,function(_0x36c328){if(_0x36c328)_0x335268(_0x36c328);return _0x18e261();});});})[_0x0e6b('0x28')](function(){return _0x4ae2fc[_0x0e6b('0x74')](_0x302c0f,_0x399f9d,function(_0x3aea49){if(_0x3aea49){logger['error'](_0x0e6b('0xd4'),_0x3aea49);}else{fs[_0x0e6b('0xd5')](_0x302c0f);}});});});}else{return _0x4ae2fc[_0x0e6b('0x2b')](0xc8);}})[_0x0e6b('0x20')](handleError(_0x4ae2fc,null));};
\ No newline at end of file