Built motion from commit (unavailable).|2.5.27
[motion2.git] / server / api / chatInteraction / chatInteraction.controller.js
index adc0a01..9aa198a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x9c44=['now','pathTranscript','Messages','CmContact','format','%s%d','agentAlias','System','Visitor','agentIdentifier','website_alias','agent_alias','alias','fullname','agent_fullname','[%s]\x20%s:\x20%s\x0a','MM/DD/YYYY\x20HH:mm:ss','direction','secret','appendFileSync','MailAccount','MailServerOut','Smtp','service','host','port','secure','authentication','auth','SendMail','\x22%s\x22\x20<%s>','email','Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a','ids','omit','getMessages','hasOwnProperty','YYYY-MM-DD\x20HH:mm:ss','findAll','getMyMessages','includeAgent','addTags','spread','emit','chatInteractionTags:save','removeTags','files','server','transcript-%d-%s.zip','firstName','lastName','attachments','Owner','get','mkdirSync','10px','<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>','%s\x20#%d','Chat','YYYY-MM-DD','N.A.','closedAt','browserName','osName','referer','customerIp','customerPort','tail','existsSync','pipe','renderFile','views','toFile','transcript-','.pdf','log','err','unlinkSync','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','path','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/license/util','../../mysqldb','defaults','redis','socket.io-emitter','./chatInteraction.socket','register','jayson/promise','client','http','request','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','end','status','json','count','offset','limit','apply','reject','update','destroy','then','stack','name','send','Users','map','TagIds','Tags','split','forEach','push','index','ChatInteraction','rawAttributes','fieldName','model','query','filters','intersection','attributes','fields','length','nolimit','sort','where','pick','field','tools_tags','select','u.id','u.fullname','ui.ChatInteractionId','user_has_chat_interactions','left_join','users','u.id\x20=\x20ui.UserId','from','chat_interactions','cm_contacts','o.id\x20=\x20i.UserId','a.id\x20=\x20i.ChatWebsiteId','me.ChatInteractionId\x20=\x20i.id','chat_interaction_has_tags','it.ChatInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','sqlOperator','conditions','find','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','$substring','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?','ContactId','buildExpression','text','start','Tag','User','operator','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','type','body','keys','some','isEmpty','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','isArray','tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','filter','replace','isNumeric','i.id\x20LIKE\x20?','getFullTextValue','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','Sequelize','QueryTypes','SELECT','i.id','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','order','contactName','DESC','resolve','ChatWebsiteId','i.ChatWebsiteId\x20IS\x20NOT\x20NULL','i.ChatWebsiteId\x20IS\x20NULL','i.ChatWebsiteId\x20IN\x20?','sequelize','toString','keyBy','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.*','c.firstName','Contact.firstName','Contact.lastName','c.email','Contact.email','Contact.phone','c.mobile','c.fax','Contact.fax','o.internal','Owner.internal','ChatInteractionId','rows','show','params','includeAll','include','merge','options','create','describe','createVidaooSession','ChatWebsite','vidaooApiKey','vidaooEscalation','MotionCWB:','follow','Error\x20in\x20Vidaoo\x20configuration','join_url','out','user','ChatMessage','ValidationError','Unable\x20to\x20create\x20Vidaoo\x20session','updateAttributes','customUpdate','abandon','entity\x20not\x20found','sendStatus','disposition','AbandonInteraction','attachmentUpload','file','filename','Attachment','attachmentDownload','findOne','closed','attachId','download','join','root','basename','mailTranscript','server/files/chat/upload/','transcript-%s.txt'];(function(_0x4b9492,_0x57309e){var _0x528c5d=function(_0x2672d0){while(--_0x2672d0){_0x4b9492['push'](_0x4b9492['shift']());}};_0x528c5d(++_0x57309e);}(_0x9c44,0x178));var _0x49c4=function(_0x15bc81,_0x4d4f77){_0x15bc81=_0x15bc81-0x0;var _0x59440e=_0x9c44[_0x15bc81];return _0x59440e;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x49c4('0x0'));var zipdir=require(_0x49c4('0x1'));var jsonpatch=require(_0x49c4('0x2'));var rp=require(_0x49c4('0x3'));var moment=require(_0x49c4('0x4'));var BPromise=require(_0x49c4('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0x49c4('0x6'));var sox=require('sox');var csv=require(_0x49c4('0x7'));var ejs=require(_0x49c4('0x8'));var fs=require('fs');var _=require(_0x49c4('0x9'));var squel=require(_0x49c4('0xa'));var crypto=require(_0x49c4('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x49c4('0xc'));var toCsv=require(_0x49c4('0x7'));var querystring=require(_0x49c4('0xd'));var Papa=require(_0x49c4('0xe'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x49c4('0xf'));var as=require(_0x49c4('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x49c4('0x11'))(_0x49c4('0x12'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x49c4('0x13'));var db=require(_0x49c4('0x14'))['db'];config['redis']=_[_0x49c4('0x15')](config[_0x49c4('0x16')],{'host':'localhost','port':0x18eb});var socket=require(_0x49c4('0x17'))(new Redis(config[_0x49c4('0x16')]));require(_0x49c4('0x18'))[_0x49c4('0x19')](socket);var jayson=require(_0x49c4('0x1a'));var client=jayson[_0x49c4('0x1b')][_0x49c4('0x1c')]({'port':0x232b});var client9004=jayson[_0x49c4('0x1b')]['http']({'port':0x232c});function respondWithRpcPromise(_0x3acd06,_0x141003,_0x13a2db,_0x81e831){return new BPromise(function(_0x2abc78,_0x53e3a2){var _0x44e607=_0x81e831||client;return _0x44e607[_0x49c4('0x1d')](_0x3acd06,_0x13a2db)['then'](function(_0x512650){logger[_0x49c4('0x1e')](_0x49c4('0x1f'),_0x141003,_0x49c4('0x20'));logger['debug'](_0x49c4('0x21'),_0x141003,'request\x20sent',JSON[_0x49c4('0x22')](_0x512650));if(_0x512650[_0x49c4('0x23')]){if(_0x512650[_0x49c4('0x23')][_0x49c4('0x24')]===0x1f4){logger[_0x49c4('0x23')](_0x49c4('0x1f'),_0x141003,_0x512650[_0x49c4('0x23')][_0x49c4('0x25')]);return _0x53e3a2(_0x512650[_0x49c4('0x23')]['message']);}logger['error']('ChatInteraction,\x20%s,\x20%s',_0x141003,_0x512650[_0x49c4('0x23')]['message']);return _0x2abc78(_0x512650['error'][_0x49c4('0x25')]);}else{logger[_0x49c4('0x1e')](_0x49c4('0x1f'),_0x141003,_0x49c4('0x20'));_0x2abc78(_0x512650['result']['message']);}})[_0x49c4('0x26')](function(_0x9cb797){logger['error'](_0x49c4('0x1f'),_0x141003,_0x9cb797);_0x53e3a2(_0x9cb797);});});}function respondWithStatusCode(_0x43e014,_0x210159){_0x210159=_0x210159||0xcc;return function(_0xa7a826){if(_0xa7a826){return _0x43e014['sendStatus'](_0x210159);}return _0x43e014['status'](_0x210159)[_0x49c4('0x27')]();};}function respondWithResult(_0x53c199,_0x3800b7){_0x3800b7=_0x3800b7||0xc8;return function(_0x3852b2){if(_0x3852b2){return _0x53c199[_0x49c4('0x28')](_0x3800b7)[_0x49c4('0x29')](_0x3852b2);}};}function respondWithFilteredResult(_0x5987ae,_0x889909){return function(_0x2b2793){if(_0x2b2793){var _0x46e04d=_0x2b2793[_0x49c4('0x2a')],_0x4f28a2=_0x889909[_0x49c4('0x2b')],_0x6329b3=_0x889909[_0x49c4('0x2b')]+_0x889909[_0x49c4('0x2c')],_0x29f835;if(_0x6329b3>=_0x46e04d){_0x6329b3=_0x46e04d;_0x29f835=0xc8;}else{_0x29f835=0xce;}_0x5987ae[_0x49c4('0x28')](_0x29f835);return _0x5987ae['set']('Content-Range',_0x4f28a2+'-'+_0x6329b3+'/'+_0x46e04d)['json'](_0x2b2793);}return null;};}function patchUpdates(_0x134928){return function(_0x7ee704){try{jsonpatch[_0x49c4('0x2d')](_0x7ee704,_0x134928,!![]);}catch(_0x27e467){return BPromise[_0x49c4('0x2e')](_0x27e467);}return _0x7ee704['save']();};}function saveUpdates(_0x38ad77,_0x116eb4){return function(_0x2e7a69){if(_0x2e7a69){return _0x2e7a69[_0x49c4('0x2f')](_0x38ad77)['then'](function(_0x57a29c){return _0x57a29c;});}return null;};}function removeEntity(_0xce57ef,_0x9a1bed){return function(_0x167efe){if(_0x167efe){return _0x167efe[_0x49c4('0x30')]()[_0x49c4('0x31')](function(){_0xce57ef['status'](0xcc)[_0x49c4('0x27')]();});}};}function handleEntityNotFound(_0x84c621,_0x1bfa0f){return function(_0x512d02){if(!_0x512d02){_0x84c621['sendStatus'](0x194);}return _0x512d02;};}function handleError(_0x85dce2,_0x1991e9){_0x1991e9=_0x1991e9||0x1f4;return function(_0x3bec0a){logger[_0x49c4('0x23')](_0x3bec0a[_0x49c4('0x32')]);if(_0x3bec0a[_0x49c4('0x33')]){delete _0x3bec0a[_0x49c4('0x33')];}_0x85dce2[_0x49c4('0x28')](_0x1991e9)[_0x49c4('0x34')](_0x3bec0a);};}function getInteractionUsers(_0x4e0209,_0x2d34ca){return new BPromise(function(_0x5b96df,_0xdda586){try{if(_0x2d34ca[_0x4e0209['id']]){_0x4e0209[_0x49c4('0x35')]=_[_0x49c4('0x36')](_0x2d34ca[_0x4e0209['id']],function(_0x1c2830){return{'id':_0x1c2830['id'],'fullname':_0x1c2830['fullname']};});}}catch(_0x335f0c){_0xdda586(_0x335f0c);}_0x5b96df(_0x4e0209);});}function getInteractionTags(_0x31f3ff,_0x1c910a){return new BPromise(function(_0x4e913a,_0x3b4feb){try{if(_0x31f3ff[_0x49c4('0x37')]){_0x31f3ff[_0x49c4('0x38')]=[];_0x31f3ff[_0x49c4('0x37')][_0x49c4('0x39')](',')[_0x49c4('0x3a')](function(_0x143916){_0x31f3ff[_0x49c4('0x38')][_0x49c4('0x3b')](_0x1c910a[_0x143916]);});}delete _0x31f3ff[_0x49c4('0x37')];}catch(_0x1e506a){_0x3b4feb(_0x1e506a);}_0x4e913a(_0x31f3ff);});}function updateChatInteraction(_0x4e0663,_0x2d2510,_0x20cd21){return new BPromise(function(_0x32b172,_0x23aa32){return getInteractionUsers(_0x4e0663,_0x20cd21)[_0x49c4('0x31')](function(_0x29dd5d){return getInteractionTags(_0x29dd5d,_0x2d2510);})[_0x49c4('0x31')](function(_0xc9722b){_0x32b172(_0xc9722b);})[_0x49c4('0x26')](function(_0x2668ed){_0x23aa32(_0x2668ed);});});}exports[_0x49c4('0x3c')]=function(_0xa3d59e,_0x326142){var _0x4e38bc={},_0x212366={},_0x49829e={'count':0x0,'rows':[]};var _0x104efb=_[_0x49c4('0x36')](db[_0x49c4('0x3d')][_0x49c4('0x3e')],function(_0x239327){return{'name':_0x239327[_0x49c4('0x3f')],'type':_0x239327['type']['key']};});_0x212366[_0x49c4('0x40')]=_[_0x49c4('0x36')](_0x104efb,_0x49c4('0x33'));_0x212366[_0x49c4('0x41')]=_['keys'](_0xa3d59e[_0x49c4('0x41')]);_0x212366[_0x49c4('0x42')]=_[_0x49c4('0x43')](_0x212366[_0x49c4('0x40')],_0x212366[_0x49c4('0x41')]);_0x4e38bc[_0x49c4('0x44')]=_[_0x49c4('0x43')](_0x212366[_0x49c4('0x40')],qs[_0x49c4('0x45')](_0xa3d59e['query'][_0x49c4('0x45')]));_0x4e38bc['attributes']=_0x4e38bc[_0x49c4('0x44')][_0x49c4('0x46')]?_0x4e38bc[_0x49c4('0x44')]:_0x212366[_0x49c4('0x40')];if(!_0xa3d59e[_0x49c4('0x41')]['hasOwnProperty'](_0x49c4('0x47'))){_0x4e38bc[_0x49c4('0x2c')]=qs[_0x49c4('0x2c')](_0xa3d59e[_0x49c4('0x41')][_0x49c4('0x2c')]);_0x4e38bc[_0x49c4('0x2b')]=qs[_0x49c4('0x2b')](_0xa3d59e['query'][_0x49c4('0x2b')]);}_0x4e38bc['order']=qs[_0x49c4('0x48')](_0xa3d59e[_0x49c4('0x41')][_0x49c4('0x48')]);_0x4e38bc[_0x49c4('0x49')]=qs[_0x49c4('0x42')](_[_0x49c4('0x4a')](_0xa3d59e[_0x49c4('0x41')],_0x212366['filters']),_0x104efb);var _0x3b731f=[];var _0x3feaf0=squel['select']()[_0x49c4('0x4b')]('id')[_0x49c4('0x4b')](_0x49c4('0x33'))[_0x49c4('0x4b')]('color')['from'](_0x49c4('0x4c'));var _0x4e8221=squel[_0x49c4('0x4d')]()[_0x49c4('0x4b')](_0x49c4('0x4e'))[_0x49c4('0x4b')](_0x49c4('0x4f'))[_0x49c4('0x4b')](_0x49c4('0x50'))['from'](_0x49c4('0x51'),'ui')[_0x49c4('0x52')](_0x49c4('0x53'),'u',_0x49c4('0x54'));var _0x17ef75=squel[_0x49c4('0x4d')]()[_0x49c4('0x55')](_0x49c4('0x56'),'i')[_0x49c4('0x52')](_0x49c4('0x57'),'c','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL')['left_join'](_0x49c4('0x53'),'o',_0x49c4('0x58'))['left_join']('chat_websites','a',_0x49c4('0x59'))['left_join']('chat_messages','me',_0x49c4('0x5a'))[_0x49c4('0x52')](_0x49c4('0x5b'),'it',_0x49c4('0x5c'))[_0x49c4('0x52')](_0x49c4('0x4c'),'t',_0x49c4('0x5d'));var _0x50798e=squel[_0x49c4('0x5e')]();var _0xcc6a2b=[];var _0x207572=squel[_0x49c4('0x5e')]();var _0x73840f;if(_0xa3d59e[_0x49c4('0x41')]['search']){_0x73840f=as['parseSearch'](_0xa3d59e[_0x49c4('0x41')][_0x49c4('0x5f')]);var _0x2a6308=_0x73840f[_0x49c4('0x60')];for(var _0x23288e=0x0;_0x23288e<_0x73840f[_0x49c4('0x61')][_0x49c4('0x46')];_0x23288e++){var _0x58dc5f=_0x73840f[_0x49c4('0x61')][_0x23288e];var _0x33c9a6='i';var _0x4ba4eb=_[_0x49c4('0x62')](_0x104efb,['name',_0x58dc5f[_0x49c4('0x4b')]]);if(!_0x4ba4eb){switch(_0x58dc5f[_0x49c4('0x4b')]){case _0x49c4('0x63'):if(_0x58dc5f[_0x49c4('0x64')]==0x1){_0x17ef75[_0x49c4('0x65')]('`'+_0x58dc5f[_0x49c4('0x4b')]+_0x49c4('0x66'));}else{_0x17ef75[_0x49c4('0x65')]('`'+_0x58dc5f['field']+_0x49c4('0x67'));}break;case _0x49c4('0x68'):if(_0x58dc5f['operator']===_0x49c4('0x69')){if(_0x58dc5f[_0x49c4('0x64')]['split']('\x20')[_0x49c4('0x46')]>0x1){_0x50798e[_0x2a6308](_0x49c4('0x6a'),qs['getFullTextValue'](_0x58dc5f['value']),null);}else{var _0x589484='%'+_0x58dc5f['value']+'%';_0x50798e[_0x2a6308](_0x49c4('0x6b'),_0x589484,_0x589484,_0x589484);}}else{_0x4ba4eb=_['find'](_0x104efb,[_0x49c4('0x33'),_0x49c4('0x6c')]);_0x58dc5f['field']=_0x49c4('0x6c');_0x3feb0b=as[_0x49c4('0x6d')](_0x33c9a6,_0x4ba4eb['type'],_0x58dc5f);_0x50798e[_0x2a6308](_0x3feb0b[_0x49c4('0x6e')],_0x3feb0b[_0x49c4('0x64')][_0x49c4('0x6f')],_0x3feb0b[_0x49c4('0x64')]['end']);}break;case _0x49c4('0x70'):var _0x16d0e1=_0x58dc5f[_0x49c4('0x64')][_0x49c4('0x39')](',')['map'](function(_0x617e2f){return Number(_0x617e2f);});_0x16d0e1['forEach'](function(_0x568457){_0x207572['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x568457+',%');});_0xcc6a2b=_['union'](_0xcc6a2b,_0x16d0e1);break;case _0x49c4('0x71'):if(_0x58dc5f[_0x49c4('0x72')]===_0x49c4('0x69')){_0x50798e[_0x2a6308](_0x49c4('0x73'),'%'+_0x58dc5f['value']+'%',null);}else{_0x4ba4eb=_['find'](_0x104efb,[_0x49c4('0x33'),_0x49c4('0x74')]);_0x58dc5f[_0x49c4('0x4b')]=_0x49c4('0x74');_0x3feb0b=as[_0x49c4('0x6d')](_0x33c9a6,_0x4ba4eb[_0x49c4('0x75')],_0x58dc5f);_0x50798e[_0x2a6308](_0x3feb0b[_0x49c4('0x6e')],_0x3feb0b[_0x49c4('0x64')]['start'],_0x3feb0b[_0x49c4('0x64')]['end']);}break;case _0x49c4('0x76'):_0x3feb0b=as[_0x49c4('0x6d')]('me',null,_0x58dc5f);_0x50798e[_0x2a6308](_0x3feb0b[_0x49c4('0x6e')],_0x3feb0b[_0x49c4('0x64')][_0x49c4('0x6f')],_0x3feb0b[_0x49c4('0x64')][_0x49c4('0x27')]);break;}}else{var _0x3feb0b=as[_0x49c4('0x6d')](_0x33c9a6,_0x4ba4eb[_0x49c4('0x75')],_0x58dc5f);_0x50798e[_0x2a6308](_0x3feb0b[_0x49c4('0x6e')],_0x3feb0b[_0x49c4('0x64')][_0x49c4('0x6f')],_0x3feb0b[_0x49c4('0x64')][_0x49c4('0x27')]);}}}else{var _0x453cf2=_(_0xa3d59e[_0x49c4('0x41')])[_0x49c4('0x77')]()['map'](function(_0x5ec201){return _[_0x49c4('0x78')](_0x104efb,[_0x49c4('0x33'),_0x5ec201])?_0x5ec201:undefined;})['compact']()[_0x49c4('0x64')]();if(!_[_0x49c4('0x79')](_0x453cf2)){_0x453cf2[_0x49c4('0x3a')](function(_0x16e7b1){if(_0x16e7b1==='ChatWebsiteId'){_0x17ef75['where']('i.ChatWebsiteId\x20IN\x20?',[][_0x49c4('0x7a')](_0xa3d59e[_0x49c4('0x41')][_0x16e7b1]));}else if(_0x16e7b1===_0x49c4('0x7b')){var _0x2f4289=JSON[_0x49c4('0x7c')](_0xa3d59e[_0x49c4('0x41')][_0x16e7b1])[_0x49c4('0x7d')];var _0x3692a4=JSON[_0x49c4('0x7c')](_0xa3d59e['query'][_0x16e7b1])[_0x49c4('0x7e')];_0x17ef75[_0x49c4('0x49')](_0x49c4('0x7f'),_0x2f4289,_0x3692a4);}else{if(_0xa3d59e['query'][_0x16e7b1]===_0x49c4('0x80')){_0x17ef75[_0x49c4('0x49')]('i.'+_0x16e7b1+_0x49c4('0x81'));}else{_0x17ef75[_0x49c4('0x49')]('i.'+_0x16e7b1+_0x49c4('0x82'),_0xa3d59e[_0x49c4('0x41')][_0x16e7b1]);}}});}if(_0xa3d59e[_0x49c4('0x41')][_0x49c4('0x83')]){if(_0xa3d59e['query'][_0x49c4('0x83')]==0x1){_0x17ef75[_0x49c4('0x65')](_0x49c4('0x84'));}else{_0x17ef75[_0x49c4('0x65')](_0x49c4('0x85'));}}if(_0xa3d59e['query']['tag']){_0xcc6a2b=_[_0x49c4('0x86')](_0xa3d59e['query'][_0x49c4('0x87')])?_0xa3d59e['query'][_0x49c4('0x87')]:new Array(_0xa3d59e[_0x49c4('0x41')][_0x49c4('0x87')]);_0xcc6a2b[_0x49c4('0x3a')](function(_0x4eb9f7){_0x207572['or'](_0x49c4('0x88'),'%,'+_0x4eb9f7+',%');});}if(_0xa3d59e[_0x49c4('0x41')][_0x49c4('0x89')]){var _0x42e19a=_0xa3d59e[_0x49c4('0x41')][_0x49c4('0x89')][_0x49c4('0x8a')]('\x5c','\x5c\x5c')[_0x49c4('0x8a')](/'/g,'\x27\x27');if(qs[_0x49c4('0x8b')](_0x42e19a)){_0x50798e['or'](_0x49c4('0x8c'),_0x42e19a+'%');}else{_0x50798e['or']('MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x49c4('0x8d')](_0x42e19a))['or'](_0x49c4('0x8e'),_0x42e19a+'%');}}}_0x17ef75['where'](_0x50798e);_0x17ef75[_0x49c4('0x8f')]('i.id');var _0x1e6644={'type':db[_0x49c4('0x90')][_0x49c4('0x91')][_0x49c4('0x92')],'raw':!![]};var _0x2c32c0=_0x17ef75['clone']();_0x2c32c0[_0x49c4('0x4b')](_0x49c4('0x93'));_0x2c32c0['field'](_0x49c4('0x94'),_0x49c4('0x63'));if(_0x4e38bc['order']){_0x4e38bc[_0x49c4('0x95')][_0x49c4('0x3a')](function(_0x57b137){var _0x37fef1=_0x57b137[0x0]===_0x49c4('0x96')?_0x57b137[0x0]:'i.'+_0x57b137[0x0];_0x17ef75[_0x49c4('0x95')](_0x37fef1,_0x57b137[0x1]===_0x49c4('0x97')?![]:!![]);});}if(!_['isEmpty'](_0xcc6a2b)){_0x17ef75[_0x49c4('0x65')](_0x207572);_0x2c32c0[_0x49c4('0x49')]('t.id\x20IN\x20?',_0xcc6a2b);}BPromise[_0x49c4('0x98')]()['then'](function(){if(!_0x73840f){if(_0xa3d59e['query'][_0x49c4('0x99')]||_0xa3d59e['query']['journey'])return;_0x2c32c0[_0x49c4('0x49')](_0x49c4('0x9a'));_0x17ef75['where'](_0x49c4('0x9a'));return;}return _0xa3d59e['user']['getChatWebsites']({'attributes':['id'],'raw':!![]})['then'](function(_0x10d107){if(_[_0x49c4('0x79')](_0x10d107)){_0x2c32c0[_0x49c4('0x49')](_0x49c4('0x9b'));_0x17ef75['where']('i.ChatWebsiteId\x20IS\x20NULL');}else{_0x2c32c0[_0x49c4('0x49')]('i.ChatWebsiteId\x20IN\x20?',_[_0x49c4('0x36')](_0x10d107,'id'));_0x17ef75['where'](_0x49c4('0x9c'),_[_0x49c4('0x36')](_0x10d107,'id'));}});})[_0x49c4('0x31')](function(){db[_0x49c4('0x9d')][_0x49c4('0x41')](_0x2c32c0[_0x49c4('0x9e')](),_0x1e6644)[_0x49c4('0x31')](function(_0x5bb0e9){_0x49829e[_0x49c4('0x2a')]=_0x5bb0e9[_0x49c4('0x46')];if(_0x49829e[_0x49c4('0x2a')]===0x0)return[];return db[_0x49c4('0x9d')][_0x49c4('0x41')](_0x3feaf0['toString'](),_0x1e6644)[_0x49c4('0x31')](function(_0x1bf931){_0x3b731f=_[_0x49c4('0x9f')](_0x1bf931,'id');_0x1e6644=_['merge'](_0x1e6644,{'model':db['ChatInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0xa3d59e[_0x49c4('0x41')][_0x49c4('0x45')]){_0x4e38bc[_0x49c4('0x44')][_0x49c4('0x3a')](function(_0x432b71){_0x17ef75['field']('i.'+_0x432b71);});}else{_0x17ef75[_0x49c4('0x4b')](_0x49c4('0x94'),_0x49c4('0x63'));_0x17ef75[_0x49c4('0x4b')]('a.key','Account.key');_0x17ef75[_0x49c4('0x4b')](_0x49c4('0xa0'),_0x49c4('0xa1'));_0x17ef75[_0x49c4('0x4b')](_0x49c4('0xa2'),'contactName');_0x17ef75[_0x49c4('0x4b')](_0x49c4('0xa3'));_0x17ef75[_0x49c4('0x4b')](_0x49c4('0xa4'),_0x49c4('0xa5'));_0x17ef75[_0x49c4('0x4b')]('c.lastName',_0x49c4('0xa6'));_0x17ef75[_0x49c4('0x4b')](_0x49c4('0xa7'),_0x49c4('0xa8'));_0x17ef75['field']('c.phone',_0x49c4('0xa9'));_0x17ef75['field'](_0x49c4('0xaa'),'Contact.mobile');_0x17ef75[_0x49c4('0x4b')](_0x49c4('0xab'),_0x49c4('0xac'));_0x17ef75[_0x49c4('0x4b')]('o.fullname','Owner.fullname');_0x17ef75[_0x49c4('0x4b')](_0x49c4('0xad'),_0x49c4('0xae'));_0x17ef75['field']('GROUP_CONCAT(DISTINCT\x20t.id)',_0x49c4('0x37'));}if(_0x4e38bc['limit'])_0x17ef75['limit'](_0x4e38bc[_0x49c4('0x2c')]);if(_0x4e38bc['offset'])_0x17ef75[_0x49c4('0x2b')](_0x4e38bc[_0x49c4('0x2b')]);return db['sequelize'][_0x49c4('0x41')](_0x17ef75[_0x49c4('0x9e')](),_0x1e6644);})['then'](function(_0x5428a9){_0x4e8221[_0x49c4('0x49')]('ui.ChatInteractionId\x20IN\x20?',_[_0x49c4('0x36')](_0x5428a9,'id'));return db[_0x49c4('0x9d')][_0x49c4('0x41')](_0x4e8221[_0x49c4('0x9e')](),_0x1e6644)[_0x49c4('0x31')](function(_0x4483fc){var _0x2ecc6d=_['groupBy'](_0x4483fc,_0x49c4('0xaf'));var _0x12afa1=[];_0x5428a9[_0x49c4('0x3a')](function(_0xcc42bf){_0x12afa1[_0x49c4('0x3b')](updateChatInteraction(_0xcc42bf,_0x3b731f,_0x2ecc6d));});return BPromise['all'](_0x12afa1);});});})[_0x49c4('0x31')](function(_0x59ccfc){_0x49829e[_0x49c4('0xb0')]=_0x59ccfc;return _0x49829e;})[_0x49c4('0x31')](respondWithFilteredResult(_0x326142,_0x4e38bc));})[_0x49c4('0x26')](handleError(_0x326142,null));};exports[_0x49c4('0xb1')]=function(_0x5acbf7,_0x293e47){var _0x139696={'raw':![],'where':{'id':_0x5acbf7[_0x49c4('0xb2')]['id']}},_0x312b02={};_0x312b02[_0x49c4('0x40')]=_[_0x49c4('0x77')](db['ChatInteraction'][_0x49c4('0x3e')]);_0x312b02['query']=_[_0x49c4('0x77')](_0x5acbf7[_0x49c4('0x41')]);_0x312b02[_0x49c4('0x42')]=_[_0x49c4('0x43')](_0x312b02['model'],_0x312b02[_0x49c4('0x41')]);_0x139696[_0x49c4('0x44')]=_['intersection'](_0x312b02[_0x49c4('0x40')],qs[_0x49c4('0x45')](_0x5acbf7['query']['fields']));_0x139696[_0x49c4('0x44')]=_0x139696[_0x49c4('0x44')][_0x49c4('0x46')]?_0x139696[_0x49c4('0x44')]:_0x312b02[_0x49c4('0x40')];if(_0x5acbf7[_0x49c4('0x41')][_0x49c4('0xb3')]){_0x139696[_0x49c4('0xb4')]=[{'all':!![]}];}_0x139696=_[_0x49c4('0xb5')]({},_0x139696,_0x5acbf7[_0x49c4('0xb6')]);return db[_0x49c4('0x3d')]['find'](_0x139696)['then'](handleEntityNotFound(_0x293e47,null))[_0x49c4('0x31')](respondWithResult(_0x293e47,null))[_0x49c4('0x26')](handleError(_0x293e47,null));};exports[_0x49c4('0xb7')]=function(_0x5be042,_0x1276bf){return db[_0x49c4('0x3d')]['create'](_0x5be042[_0x49c4('0x76')],{})['then'](respondWithResult(_0x1276bf,0xc9))[_0x49c4('0x26')](handleError(_0x1276bf,null));};exports[_0x49c4('0x2f')]=function(_0x2adf4f,_0x941b9d){if(_0x2adf4f['body']['id']){delete _0x2adf4f[_0x49c4('0x76')]['id'];}return db[_0x49c4('0x3d')][_0x49c4('0x62')]({'where':{'id':_0x2adf4f[_0x49c4('0xb2')]['id']}})[_0x49c4('0x31')](handleEntityNotFound(_0x941b9d,null))['then'](saveUpdates(_0x2adf4f['body'],null))['then'](respondWithResult(_0x941b9d,null))[_0x49c4('0x26')](handleError(_0x941b9d,null));};exports[_0x49c4('0x30')]=function(_0x228bbb,_0x32f8f9){return db[_0x49c4('0x3d')]['find']({'where':{'id':_0x228bbb[_0x49c4('0xb2')]['id']}})[_0x49c4('0x31')](handleEntityNotFound(_0x32f8f9,null))[_0x49c4('0x31')](removeEntity(_0x32f8f9,null))[_0x49c4('0x26')](handleError(_0x32f8f9,null));};exports['describe']=function(_0x26ddfc,_0x5bfccd){return db[_0x49c4('0x3d')][_0x49c4('0xb8')]()[_0x49c4('0x31')](respondWithResult(_0x5bfccd,null))['catch'](handleError(_0x5bfccd,null));};exports[_0x49c4('0xb9')]=function(_0x9b622d,_0x2b596d){var _0x494c7f=_0x9b622d[_0x49c4('0xb2')]['id'];var _0x11f47f;var _0xa1954a;var _0x56341f;return db[_0x49c4('0x3d')]['findOne']({'where':{'id':_0x494c7f}})['then'](function(_0x2c2c7c){_0x11f47f=_0x2c2c7c;return db[_0x49c4('0xba')]['findOne']({'where':{'id':_0x2c2c7c[_0x49c4('0x99')]},'attributes':['id',_0x49c4('0xbb'),_0x49c4('0xbc')],'raw':!![]});})[_0x49c4('0x31')](function(_0x10f5fc){if(_0x10f5fc&&_0x10f5fc[_0x49c4('0xbb')]&&_0x10f5fc[_0x49c4('0xbc')]){_0xa1954a=_0x10f5fc;var _0x219133={'rejectUnauthorized':![],'method':'POST','uri':'https://api-vidaoo.xcally.com/api/v1/sessions','headers':{'X-APIKEY':_0x10f5fc[_0x49c4('0xbb')]},'body':{'name':_0x49c4('0xbd')+_0x494c7f},'redirect':_0x49c4('0xbe'),'json':!![]};return rp(_0x219133);}else{throw new db['Sequelize']['ValidationError'](_0x49c4('0xbf'));}})[_0x49c4('0x31')](function(_0xd979f7){_0x56341f=_0xd979f7;if(_0x56341f['id']){var _0x45aeeb={'body':_0x56341f[_0x49c4('0xc0')],'ChatWebsiteId':_0xa1954a['id'],'ChatInteractionId':_0x11f47f['id'],'direction':_0x49c4('0xc1'),'UserId':_0x9b622d[_0x49c4('0xc2')]['id']};return db[_0x49c4('0xc3')][_0x49c4('0xb7')](_0x45aeeb,{});}else{throw new db[(_0x49c4('0x90'))][(_0x49c4('0xc4'))](_0x49c4('0xc5'));}})[_0x49c4('0x31')](function(){return _0x11f47f[_0x49c4('0xc6')]({'vidaooSessionId':_0x56341f['id']});})['then'](respondWithResult(_0x2b596d,null))[_0x49c4('0x26')](handleError(_0x2b596d,null));};exports[_0x49c4('0xc7')]=function(_0x18a401,_0x318aaf){if(_0x18a401['body']['id']){delete _0x18a401['body']['id'];}return db[_0x49c4('0x3d')]['find']({'where':{'id':_0x18a401[_0x49c4('0xb2')]['id']}})[_0x49c4('0x31')](handleEntityNotFound(_0x318aaf,null))[_0x49c4('0x31')](saveUpdates(_0x18a401[_0x49c4('0x76')],null))[_0x49c4('0x31')](respondWithResult(_0x318aaf,null))[_0x49c4('0x26')](handleError(_0x318aaf,null));};exports[_0x49c4('0xc8')]=function(_0xe9e187,_0x31ba95,_0x1c12f6){if(_0xe9e187[_0x49c4('0x76')]['id']){delete _0xe9e187[_0x49c4('0x76')]['id'];}return db['ChatInteraction'][_0x49c4('0x62')]({'where':{'id':_0xe9e187[_0x49c4('0xb2')]['id']}})[_0x49c4('0x31')](function(_0x5dd6a1){if(!_0x5dd6a1){logger[_0x49c4('0x23')]('abandonInteraction,\x20%s,\x20%s,\x20%s',_0x49c4('0xc8'),0x194,_0x49c4('0xc9'));_0x31ba95[_0x49c4('0xca')](0x194);}else{if(_0x5dd6a1[_0x49c4('0x74')]){throw new db['Sequelize'][(_0x49c4('0xc4'))]('Interaction\x20already\x20assigned');}}return _0x5dd6a1;})['then'](function(_0xb7cfbb){if(_0xb7cfbb){return _0xb7cfbb[_0x49c4('0x2f')]({'closed':_0xe9e187[_0x49c4('0x76')]['closed'],'disposition':_0xe9e187['body'][_0x49c4('0xcb')]})[_0x49c4('0x31')](function(_0x2d3845){return _0x2d3845;});}})[_0x49c4('0x31')](function(_0x230705){return respondWithRpcPromise(_0x49c4('0xcc'),_0x49c4('0xc8'),_0xe9e187[_0x49c4('0x76')],client9004);})[_0x49c4('0x31')](respondWithResult(_0x31ba95,null))['catch'](handleError(_0x31ba95,null));};exports[_0x49c4('0xcd')]=function(_0x1aad10,_0x5d9bcb,_0x599763){_0x1aad10[_0x49c4('0x76')]['name']=_0x1aad10[_0x49c4('0xce')]['originalname'];_0x1aad10[_0x49c4('0x76')]['basename']=_0x1aad10[_0x49c4('0xce')][_0x49c4('0xcf')];_0x1aad10[_0x49c4('0x76')][_0x49c4('0x75')]=_0x1aad10['file']['mimetype'];return db[_0x49c4('0xd0')][_0x49c4('0xb7')](_0x1aad10[_0x49c4('0x76')])['then'](respondWithResult(_0x5d9bcb,0xc9))[_0x49c4('0x26')](handleError(_0x5d9bcb,null));};exports[_0x49c4('0xd1')]=function(_0x5ae29d,_0x5f2411,_0x43ca05){return db[_0x49c4('0x3d')][_0x49c4('0xd2')]({'where':{'id':_0x5ae29d['params']['id']},'raw':!![]})[_0x49c4('0x31')](handleEntityNotFound(_0x5f2411,null))[_0x49c4('0x31')](function(_0x278225){if(_0x278225){if(_0x278225[_0x49c4('0xd3')]){return _0x5f2411['status'](0x193)[_0x49c4('0x29')]({'status':0x193,'message':'Unauthorized'});}return db['Attachment'][_0x49c4('0xd2')]({'where':{'id':_0x5ae29d[_0x49c4('0x41')][_0x49c4('0xd4')]},'raw':!![]})[_0x49c4('0x31')](handleEntityNotFound(_0x5f2411,null));}})['then'](function(_0x32b6e4){if(_0x32b6e4){return _0x5f2411[_0x49c4('0xd5')](path[_0x49c4('0xd6')](config[_0x49c4('0xd7')],'server/files/attachments/',_0x32b6e4[_0x49c4('0xd8')]));}})['catch'](handleError(_0x5f2411,null));};exports['close']=function(_0x29f48d,_0x10d108){var _0x1311d4=null;var _0x56a631=null;var _0x336853=null;var _0x4a874a=null;if(_0x29f48d[_0x49c4('0x76')]['id']){delete _0x29f48d[_0x49c4('0x76')]['id'];}if(_0x29f48d[_0x49c4('0x76')][_0x49c4('0xd9')]){_0x4a874a=path[_0x49c4('0xd6')](config[_0x49c4('0xd7')],_0x49c4('0xda'),util['format'](_0x49c4('0xdb'),Date[_0x49c4('0xdc')]()));_0x29f48d[_0x49c4('0x76')][_0x49c4('0xdd')]=_0x4a874a;}return db['ChatInteraction']['find']({'where':{'id':_0x29f48d['params']['id']},'include':[{'model':db[_0x49c4('0xc3')],'as':_0x49c4('0xde'),'include':[{'model':db[_0x49c4('0x71')],'as':_0x49c4('0x71')}]}]})[_0x49c4('0x31')](handleEntityNotFound(_0x10d108,null))[_0x49c4('0x31')](saveUpdates(_0x29f48d[_0x49c4('0x76')],null))['then'](function(_0xc644de){if(_0xc644de){_0x1311d4=_0xc644de;return db[_0x49c4('0xba')]['find']({'where':{'id':_0x1311d4['ChatWebsiteId']}});}})['then'](function(_0x8395b0){if(_0x8395b0){_0x336853=_0x8395b0;return db[_0x49c4('0xdf')][_0x49c4('0x62')]({'where':{'id':_0x1311d4[_0x49c4('0x6c')]}});}})[_0x49c4('0x31')](function(_0x1480d3){if(_0x1480d3){_0x56a631=_0x1480d3;if(_0x4a874a){var _0x2f36c6=null;for(var _0x5039fc=0x1;_0x5039fc<_0x1311d4[_0x49c4('0xde')][_0x49c4('0x46')];++_0x5039fc){_0x2f36c6=_0x1311d4[_0x49c4('0xde')][_0x5039fc];var _0x2f018d=_0x2f36c6['UserId']?util[_0x49c4('0xe0')](_0x49c4('0xe1'),_0x336853[_0x49c4('0xe2')],_0x2f36c6[_0x49c4('0x74')]):_0x49c4('0xe3');var _0x4f6a04=_0x29f48d[_0x49c4('0x76')]['customer']||util['format'](_0x49c4('0xe1'),_0x49c4('0xe4'),_0x2f36c6[_0x49c4('0x6c')]);switch(_0x336853[_0x49c4('0xe5')]){case _0x49c4('0xe6'):_0x2f018d=_0x2f36c6['UserId']?util[_0x49c4('0xe0')](_0x49c4('0xe1'),_0x336853[_0x49c4('0xe2')],_0x2f36c6['UserId']):_0x49c4('0xe3');break;case _0x49c4('0xe7'):_0x2f018d=_0x2f36c6['UserId']?_0x2f36c6[_0x49c4('0x71')][_0x49c4('0xe8')]||_0x2f36c6[_0x49c4('0x71')][_0x49c4('0xe9')]:_0x49c4('0xe3');break;case _0x49c4('0xea'):_0x2f018d=_0x2f36c6[_0x49c4('0x74')]?_0x2f36c6['User'][_0x49c4('0xe9')]:_0x49c4('0xe3');break;default:_0x2f018d=_0x2f36c6[_0x49c4('0x74')]?util[_0x49c4('0xe0')](_0x49c4('0xe1'),_0x336853['agentAlias'],_0x2f36c6[_0x49c4('0x74')]):_0x49c4('0xe3');}var _0x28b1d0=util[_0x49c4('0xe0')](_0x49c4('0xeb'),moment(_0x2f36c6['createdAt'])[_0x49c4('0xe0')](_0x49c4('0xec')),_0x2f36c6[_0x49c4('0xed')]==='in'?_0x4f6a04:_0x2f018d,_0x2f36c6[_0x49c4('0x76')]);if(!_0x2f36c6[_0x49c4('0xee')]){fs[_0x49c4('0xef')](_0x4a874a,_0x28b1d0);}}return db[_0x49c4('0xf0')][_0x49c4('0xd2')]({'where':{'service':!![]},'include':[{'model':db[_0x49c4('0xf1')],'as':_0x49c4('0xf2'),'raw':!![]}]});}}})['then'](function(_0x2d3211){if(_0x2d3211&&_0x2d3211[_0x49c4('0xf2')]&&_0x29f48d[_0x49c4('0x76')]){var _0x1745f8={'tls':{'rejectUnauthorized':![]}};if(_0x2d3211[_0x49c4('0xf2')]['service']){_0x1745f8['service']=_0x2d3211[_0x49c4('0xf2')][_0x49c4('0xf3')];}else{_0x1745f8[_0x49c4('0xf4')]=_0x2d3211[_0x49c4('0xf2')][_0x49c4('0xf4')];_0x1745f8[_0x49c4('0xf5')]=_0x2d3211['Smtp'][_0x49c4('0xf5')];_0x1745f8[_0x49c4('0xf6')]=_0x2d3211['Smtp'][_0x49c4('0xf6')];}if(_0x2d3211['Smtp'][_0x49c4('0xf7')]){_0x1745f8[_0x49c4('0xf8')]={'user':_0x2d3211[_0x49c4('0xf2')]['user'],'pass':_0x2d3211[_0x49c4('0xf2')]['pass']};}return respondWithRpcPromise(_0x49c4('0xf9'),'sendMail',{'account':_0x1745f8,'message':{'from':util['format'](_0x49c4('0xfa'),_0x2d3211[_0x49c4('0x33')],_0x2d3211[_0x49c4('0xfb')]||_0x2d3211[_0x49c4('0xf2')][_0x49c4('0xc2')]),'to':_0x29f48d[_0x49c4('0x76')]['mailTranscript'],'subject':'Mail\x20Transcript','text':util[_0x49c4('0xe0')](_0x49c4('0xfc'),_0x29f48d[_0x49c4('0x76')][_0x49c4('0xd9')]),'attachments':[{'path':_0x4a874a}]}})[_0x49c4('0x31')](function(){return _0x1311d4;})[_0x49c4('0x26')](function(_0x277d6c){console['error'](_0x277d6c);});}else{return _0x1311d4;}})['then'](respondWithStatusCode(_0x10d108,0xc8))['catch'](handleError(_0x10d108,null));};exports['addMessage']=function(_0x2cf3bb,_0x479203,_0x3759c7){return db[_0x49c4('0xc3')][_0x49c4('0x62')]({'where':{'id':_0x2cf3bb['params']['id']}})['then'](handleEntityNotFound(_0x479203,null))[_0x49c4('0x31')](function(_0x50088b){if(_0x50088b){return _0x50088b['addMessage'](_0x2cf3bb[_0x49c4('0x76')][_0x49c4('0xfd')],_[_0x49c4('0xfe')](_0x2cf3bb[_0x49c4('0x76')],[_0x49c4('0xfd'),'id'])||{});}})[_0x49c4('0x31')](respondWithResult(_0x479203,null))['catch'](handleError(_0x479203,null));};exports[_0x49c4('0xff')]=function(_0xb0726,_0x234848,_0x5730aa){var _0x3f8ab0={'raw':![],'where':{}};var _0x40ea3d={};var _0x18ca8d={'count':0x0,'rows':[]};return db[_0x49c4('0x3d')][_0x49c4('0xd2')]({'where':{'id':_0xb0726[_0x49c4('0xb2')]['id']}})[_0x49c4('0x31')](handleEntityNotFound(_0x234848,null))[_0x49c4('0x31')](function(_0x4861df){if(_0x4861df){_0x40ea3d[_0x49c4('0x40')]=_[_0x49c4('0x77')](db[_0x49c4('0xc3')][_0x49c4('0x3e')]);_0x40ea3d[_0x49c4('0x41')]=_[_0x49c4('0x77')](_0xb0726['query']);_0x40ea3d[_0x49c4('0x42')]=_[_0x49c4('0x43')](_0x40ea3d[_0x49c4('0x40')],_0x40ea3d[_0x49c4('0x41')]);_0x3f8ab0[_0x49c4('0x44')]=_[_0x49c4('0x43')](_0x40ea3d[_0x49c4('0x40')],qs[_0x49c4('0x45')](_0xb0726[_0x49c4('0x41')][_0x49c4('0x45')]));_0x3f8ab0[_0x49c4('0x44')]=_0x3f8ab0[_0x49c4('0x44')][_0x49c4('0x46')]?_0x3f8ab0[_0x49c4('0x44')]:_0x40ea3d['model'];if(!_0xb0726['query'][_0x49c4('0x100')](_0x49c4('0x47'))){_0x3f8ab0['limit']=qs['limit'](_0xb0726[_0x49c4('0x41')]['limit']);_0x3f8ab0[_0x49c4('0x2b')]=qs[_0x49c4('0x2b')](_0xb0726[_0x49c4('0x41')][_0x49c4('0x2b')]);}_0x3f8ab0[_0x49c4('0x95')]=qs[_0x49c4('0x48')](_0xb0726[_0x49c4('0x41')][_0x49c4('0x48')]);_0x3f8ab0['where']=qs[_0x49c4('0x42')](_[_0x49c4('0x4a')](_0xb0726[_0x49c4('0x41')],_0x40ea3d[_0x49c4('0x42')]));_0x3f8ab0[_0x49c4('0x49')]['ChatInteractionId']=_0x4861df['id'];if(_0xb0726[_0x49c4('0x41')][_0x49c4('0x89')]){_0x3f8ab0['where']=_[_0x49c4('0xb5')](_0x3f8ab0[_0x49c4('0x49')],{'$or':_['map'](_0x3f8ab0[_0x49c4('0x44')],function(_0x3119a5){var _0x107f65={};_0x107f65[_0x3119a5]={'$like':'%'+_0xb0726['query'][_0x49c4('0x89')]+'%'};return _0x107f65;})});}if(_0xb0726[_0x49c4('0x41')][_0x49c4('0x7d')]){var _0x3d6a36=_0xb0726['query'][_0x49c4('0x7d')]['split'](',');var _0x3508b7={};_0x3508b7[_0x3d6a36[0x0]]={'$gte':moment(_0x3d6a36[0x1])[_0x49c4('0xe0')](_0x49c4('0x101'))};_0x3f8ab0[_0x49c4('0x49')]=_['merge'](_0x3f8ab0[_0x49c4('0x49')],_0x3508b7);}_0x3f8ab0=_[_0x49c4('0xb5')]({},_0x3f8ab0,_0xb0726[_0x49c4('0xb6')]);return db[_0x49c4('0xc3')][_0x49c4('0x2a')]({'where':_0x3f8ab0[_0x49c4('0x49')]})['then'](function(_0x48d4d1){_0x18ca8d[_0x49c4('0x2a')]=_0x48d4d1;if(_0xb0726[_0x49c4('0x41')][_0x49c4('0xb3')]){_0x3f8ab0[_0x49c4('0xb4')]=[{'all':!![]}];}return db[_0x49c4('0xc3')][_0x49c4('0x102')](_0x3f8ab0);})[_0x49c4('0x31')](function(_0x45fc33){_0x18ca8d[_0x49c4('0xb0')]=_0x45fc33;return _0x18ca8d;});}})[_0x49c4('0x31')](respondWithFilteredResult(_0x234848,_0x3f8ab0))[_0x49c4('0x26')](handleError(_0x234848,null));};exports[_0x49c4('0x103')]=function(_0x527c76,_0x3a7742,_0x312f87){var _0x491203={'where':{}},_0x154017={},_0x5adc01={'count':0x0,'rows':[]};return db[_0x49c4('0x3d')][_0x49c4('0xd2')]({'where':{'id':_0x527c76['params']['id']}})[_0x49c4('0x31')](handleEntityNotFound(_0x3a7742,null))[_0x49c4('0x31')](function(_0x15fa38){if(_0x15fa38){_0x154017[_0x49c4('0x40')]=_[_0x49c4('0x77')](db['ChatMessage'][_0x49c4('0x3e')]);_0x154017['query']=_[_0x49c4('0x77')](_0x527c76[_0x49c4('0x41')]);_0x154017[_0x49c4('0x42')]=_['intersection'](_0x154017[_0x49c4('0x40')],_0x154017[_0x49c4('0x41')]);_0x491203[_0x49c4('0x44')]=_['intersection'](_0x154017['model'],qs[_0x49c4('0x45')](_0x527c76[_0x49c4('0x41')][_0x49c4('0x45')]));_0x491203[_0x49c4('0x44')]=_0x491203[_0x49c4('0x44')][_0x49c4('0x46')]?_0x491203['attributes']:_0x154017['model'];if(!_0x527c76['query'][_0x49c4('0x100')](_0x49c4('0x47'))){_0x491203[_0x49c4('0x2c')]=qs[_0x49c4('0x2c')](_0x527c76['query'][_0x49c4('0x2c')]);_0x491203[_0x49c4('0x2b')]=qs[_0x49c4('0x2b')](_0x527c76[_0x49c4('0x41')][_0x49c4('0x2b')]);}_0x491203[_0x49c4('0x95')]=qs[_0x49c4('0x48')](_0x527c76[_0x49c4('0x41')][_0x49c4('0x48')]);_0x491203[_0x49c4('0x49')]=qs[_0x49c4('0x42')](_['pick'](_0x527c76[_0x49c4('0x41')],_0x154017['filters']));_0x491203[_0x49c4('0x49')][_0x49c4('0xaf')]=_0x15fa38['id'];if(_0x527c76[_0x49c4('0x41')][_0x49c4('0x89')]){_0x491203['where']=_[_0x49c4('0xb5')](_0x491203['where'],{'$or':_['map'](_0x491203['attributes'],function(_0x31662d){var _0x3cea2={};_0x3cea2[_0x31662d]={'$like':'%'+_0x527c76[_0x49c4('0x41')]['filter']+'%'};return _0x3cea2;})});}_0x491203[_0x49c4('0x49')]['secret']=![];if(_0x527c76[_0x49c4('0x41')]['id']){_0x491203[_0x49c4('0x49')]['id']={'$gt':_0x527c76[_0x49c4('0x41')]['id']};}_0x491203=_['merge']({},_0x491203,_0x527c76[_0x49c4('0xb6')]);return db[_0x49c4('0xc3')][_0x49c4('0x2a')]({'where':_0x491203[_0x49c4('0x49')]})[_0x49c4('0x31')](function(_0x5dbd6d){_0x5adc01[_0x49c4('0x2a')]=_0x5dbd6d;_0x491203[_0x49c4('0xb4')]=[];if(_0x527c76[_0x49c4('0x41')][_0x49c4('0x104')]){_0x491203['include']['push']({'model':db[_0x49c4('0x71')],'as':_0x49c4('0x71'),'attributes':['id','fullname',_0x49c4('0xe8')]});}if(_0x527c76[_0x49c4('0x41')][_0x49c4('0xb3')]){_0x491203[_0x49c4('0xb4')]=[{'all':!![]}];}return db['ChatMessage'][_0x49c4('0x102')](_0x491203);})[_0x49c4('0x31')](function(_0x5335f9){_0x5adc01['rows']=_0x5335f9;return _0x5adc01;});}})[_0x49c4('0x31')](respondWithFilteredResult(_0x3a7742,_0x491203))[_0x49c4('0x26')](handleError(_0x3a7742,null));};exports[_0x49c4('0x105')]=function(_0x56fe72,_0x1241b6,_0x5ee9f1){return db[_0x49c4('0x3d')]['find']({'where':{'id':_0x56fe72[_0x49c4('0xb2')]['id']}})[_0x49c4('0x31')](handleEntityNotFound(_0x1241b6,null))[_0x49c4('0x31')](function(_0x13e8e2){if(_0x13e8e2){return _0x13e8e2['setTags'](_0x56fe72['body']['ids'],_[_0x49c4('0xfe')](_0x56fe72[_0x49c4('0x76')],[_0x49c4('0xfd'),'id'])||{})[_0x49c4('0x106')](function(){return db['Tag']['findAll']({'attributes':['id',_0x49c4('0x33'),'color'],'where':{'id':_0x56fe72[_0x49c4('0x76')][_0x49c4('0xfd')]}});})['then'](function(_0x369982){socket[_0x49c4('0x107')](_0x49c4('0x108'),{'id':Number(_0x56fe72['params']['id']),'tags':_0x369982||[]});return{'id':Number(_0x56fe72[_0x49c4('0xb2')]['id']),'tags':_0x369982||[]};});}})[_0x49c4('0x31')](respondWithResult(_0x1241b6,null))[_0x49c4('0x26')](handleError(_0x1241b6,null));};exports['removeTags']=function(_0x3eacc1,_0x35b8e9,_0x5f4d4e){return db[_0x49c4('0x3d')][_0x49c4('0x62')]({'where':{'id':_0x3eacc1['params']['id']}})[_0x49c4('0x31')](handleEntityNotFound(_0x35b8e9,null))[_0x49c4('0x31')](function(_0xc58a9e){if(_0xc58a9e){return _0xc58a9e[_0x49c4('0x109')](_0x3eacc1[_0x49c4('0x41')]['ids']);}})[_0x49c4('0x31')](respondWithStatusCode(_0x35b8e9,null))[_0x49c4('0x26')](handleError(_0x35b8e9,null));};exports['download']=function(_0x5a4b35,_0x31f0d4){var _0x1ddf3d=moment()['unix']()[_0x49c4('0x9e')]();var _0x55bb71=path[_0x49c4('0xd6')](config[_0x49c4('0xd7')],'server',_0x49c4('0x10a'),'tmp');var _0x1742e4=path[_0x49c4('0xd6')](config['root'],_0x49c4('0x10b'),_0x49c4('0x10a'),'attachments');var _0x5bb5ac=path[_0x49c4('0xd6')](_0x55bb71,_0x1ddf3d);var _0x30ade5=util[_0x49c4('0xe0')](_0x49c4('0x10c'),_0x5a4b35[_0x49c4('0xb2')]['id'],_0x1ddf3d);var _0x5b0f2c=path[_0x49c4('0xd6')](_0x55bb71,_0x30ade5);var _0x40afb8=[];_0x40afb8[_0x49c4('0x3b')]({'model':db[_0x49c4('0x71')],'as':_0x49c4('0x71'),'attributes':['id','fullname'],'raw':!![]});_0x40afb8[_0x49c4('0x3b')]({'model':db[_0x49c4('0xdf')],'as':_0x49c4('0x68'),'attributes':['id',_0x49c4('0x10d'),_0x49c4('0x10e')],'raw':!![]});if(_0x5a4b35[_0x49c4('0x41')][_0x49c4('0x10f')]){_0x40afb8[_0x49c4('0x3b')]({'model':db['Attachment'],'as':_0x49c4('0xd0'),'raw':!![]});}var _0x1661eb=[{'model':db[_0x49c4('0xc3')],'as':'Messages','attributes':['id','body',_0x49c4('0x7b'),'direction',_0x49c4('0xee'),_0x49c4('0x83')],'include':_0x40afb8}];_0x1661eb[_0x49c4('0x3b')]({'model':db[_0x49c4('0xba')],'as':'Account','attributes':['id',_0x49c4('0x33')]});_0x1661eb[_0x49c4('0x3b')]({'model':db[_0x49c4('0x71')],'as':_0x49c4('0x110'),'attributes':['id','fullname']});return db[_0x49c4('0x3d')][_0x49c4('0x62')]({'where':{'id':_0x5a4b35['params']['id']},'include':_0x1661eb})[_0x49c4('0x31')](handleEntityNotFound(_0x31f0d4,null))[_0x49c4('0x31')](function(_0x1f2d93){if(_0x1f2d93){var _0x72eab6=_0x1f2d93[_0x49c4('0x111')]({'plain':!![]});fs[_0x49c4('0x112')](_0x5bb5ac);var _0x2de85a={'format':'A4','border':_0x49c4('0x113'),'header':{'height':'40px','contents':{'first':'<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>'}},'footer':{'height':'30px','contents':{'default':util[_0x49c4('0xe0')](_0x49c4('0x114'),util[_0x49c4('0xe0')](_0x49c4('0x115'),_0x49c4('0x116'),_0x72eab6['id']),moment()['format'](_0x49c4('0x117'))[_0x49c4('0x9e')]())}}};var _0x9786bf={'channel':_0x49c4('0x116'),'account':_0x72eab6['Account']['name'],'agent':_0x72eab6[_0x49c4('0x110')]?_0x72eab6[_0x49c4('0x110')][_0x49c4('0xe9')]:_0x49c4('0x118'),'createdAt':moment(_0x72eab6[_0x49c4('0x7b')])[_0x49c4('0xe0')]('YYYY-MM-DD\x20HH:mm:ss')['toString'](),'closedAt':_0x72eab6[_0x49c4('0xd3')]?moment(_0x72eab6[_0x49c4('0x119')])[_0x49c4('0xe0')](_0x49c4('0x101'))[_0x49c4('0x9e')]():'','disposition':_0x72eab6['disposition'],'chatInfo':{'browser':_0x72eab6[_0x49c4('0x11a')],'os':_0x72eab6[_0x49c4('0x11b')],'referer':_0x72eab6[_0x49c4('0x11c')],'customerIp':_0x72eab6[_0x49c4('0x11d')],'customerPort':_0x72eab6[_0x49c4('0x11e')]?_0x72eab6[_0x49c4('0x11e')]:_0x49c4('0x118')},'messages':_(_0x72eab6[_0x49c4('0xde')])[_0x49c4('0x11f')]()['filter']({'secret':![]})[_0x49c4('0x36')](function(_0x37c856){if(_0x37c856[_0x49c4('0xd0')]){var _0x3bd15b=path[_0x49c4('0xd6')](_0x1742e4,_0x37c856['Attachment'][_0x49c4('0xd8')]);if(fs[_0x49c4('0x120')](_0x3bd15b)){fs['createReadStream'](_0x3bd15b)[_0x49c4('0x121')](fs['createWriteStream'](path[_0x49c4('0xd6')](_0x5bb5ac,_0x37c856['Attachment'][_0x49c4('0xd8')])));}}return{'date':moment(_0x37c856[_0x49c4('0x7b')])['format'](_0x49c4('0x101'))['toString'](),'sender':_0x37c856[_0x49c4('0xed')]===_0x49c4('0xc1')?_0x37c856[_0x49c4('0x71')]?_0x37c856[_0x49c4('0x71')][_0x49c4('0xe9')]:'System':_0x37c856[_0x49c4('0x68')][_0x49c4('0x10d')]+(_0x37c856[_0x49c4('0x68')][_0x49c4('0x10e')]?'\x20'+_0x37c856[_0x49c4('0x68')][_0x49c4('0x10e')]:''),'body':_0x37c856[_0x49c4('0xd0')]?_0x37c856[_0x49c4('0xd0')]['basename']:_0x37c856[_0x49c4('0x76')],'direction':_0x37c856[_0x49c4('0xed')]===_0x49c4('0xc1')?'A':'C','secret':_0x37c856[_0x49c4('0xee')],'read':_0x37c856[_0x49c4('0x83')],'attachment':_0x37c856[_0x49c4('0xd0')]};})[_0x49c4('0x64')]()};return ejs[_0x49c4('0x122')](path[_0x49c4('0xd6')](config[_0x49c4('0xd7')],_0x49c4('0x10b'),_0x49c4('0x123'),'downloadInteraction.html'),{'interaction':_0x9786bf})[_0x49c4('0x31')](function(_0x48c273){return new BPromise(function(_0xfcad6e,_0x148f17){pdf[_0x49c4('0xb7')](_0x48c273,_0x2de85a)[_0x49c4('0x124')](path[_0x49c4('0xd6')](_0x5bb5ac,_0x49c4('0x125')+_0x72eab6['id']+'-'+_0x1ddf3d+_0x49c4('0x126')),function(_0x327fdc,_0x1aca63){if(_0x327fdc)return _0x148f17(_0x327fdc);_0xfcad6e(_0x1aca63);});});})[_0x49c4('0x31')](function(){return new BPromise(function(_0x33ce23,_0x4595cc){zipdir(_0x5bb5ac,{'saveTo':_0x5b0f2c},function(_0x23f445,_0x293270){if(_0x23f445)return _0x4595cc(_0x23f445);return _0x33ce23(_0x293270);});})[_0x49c4('0x31')](function(){return new BPromise(function(_0x4a84df,_0x464821){rimraf(_0x5bb5ac,function(_0x519487){if(_0x519487)_0x464821(_0x519487);return _0x4a84df();});});})['then'](function(){return _0x31f0d4[_0x49c4('0xd5')](_0x5b0f2c,_0x30ade5,function(_0x48b98e){if(_0x48b98e){console[_0x49c4('0x127')](_0x49c4('0x128'),_0x48b98e);}else{fs[_0x49c4('0x129')](_0x5b0f2c);}});});});}else{return _0x31f0d4[_0x49c4('0xca')](0xc8);}})[_0x49c4('0x26')](handleError(_0x31f0d4,null));};
\ No newline at end of file
+var _0x5beb=['`unreadMessages`\x20>\x200','tag','isArray','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','filter','replace','isNumeric','i.id\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages','order','DESC','resolve','i.ChatWebsiteId\x20IS\x20NOT\x20NULL','user','getChatWebsites','role','sequelize','toString','keyBy','merge','a.key','Account.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.*','c.firstName','c.lastName','Contact.lastName','c.email','Contact.email','Contact.phone','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.ChatInteractionId\x20IN\x20?','groupBy','ChatInteractionId','all','rows','show','params','includeAll','include','options','create','body','destroy','describe','createVidaooSession','findOne','ChatWebsite','vidaooApiKey','vidaooEscalation','https://api-vidaoo.xcally.com/api/v1/sessions','MotionCWB:','follow','Sequelize','ValidationError','out','Unable\x20to\x20create\x20Vidaoo\x20session','customUpdate','CmContact','Contact','abandon','Interaction\x20already\x20assigned','closed','disposition','attachmentUpload','originalname','basename','file','filename','mimetype','Attachment','attachmentDownload','attachId','ChatOfflineMessageId','join','root','server/files/attachments/','offline-chat/','download','close','server/files/chat/upload/','transcript-%s.txt','now','ChatMessage','Messages','format','%s%d','agentAlias','System','customer','Visitor','website_alias','agent_alias','alias','agent_fullname','MM/DD/YYYY\x20HH:mm:ss','direction','secret','MailAccount','MailServerOut','Smtp','service','host','port','secure','auth','pass','SendMail','sendMail','\x22%s\x22\x20<%s>','email','mailTranscript','Mail\x20Transcript','addMessage','ids','omit','getMessages','nolimit','$gte','YYYY-MM-DD\x20HH:mm:ss','findAll','hasOwnProperty','includeAgent','spread','color','emit','removeTags','unix','server','files','tmp','transcript-%d-%s.zip','firstName','attachments','Account','get','Chat','Owner','N.A.','closedAt','osName','referer','customerIp','customerPort','tail','existsSync','createReadStream','pipe','createWriteStream','lastName','renderFile','views','downloadInteraction.html','.pdf','log','err','eml-format','rimraf','fast-json-patch','moment','mustache','util','path','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/export/pdf','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','socket.io-emitter','./chatInteraction.socket','register','jayson/promise','http','request','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','debug','error','message','result','catch','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','update','then','stack','name','send','Users','map','fullname','TagIds','Tags','push','index','ChatInteraction','rawAttributes','fieldName','type','model','query','keys','intersection','attributes','fields','length','sort','where','pick','filters','select','field','tools_tags','u.id','ui.ChatInteractionId','from','user_has_chat_interactions','users','u.id\x20=\x20ui.UserId','chat_interactions','left_join','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','chat_websites','a.id\x20=\x20i.ChatWebsiteId','chat_interaction_has_tags','it.ChatInteractionId\x20=\x20i.id','expr','search','sqlOperator','conditions','find','value','having','`\x20>\x200','operator','$substring','split','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','Tag','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','buildExpression','start','text','some','compact','isEmpty','forEach','ChatWebsiteId','i.ChatWebsiteId\x20IN\x20?','createdAt','parse','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200'];(function(_0xbc8e6f,_0xbc133d){var _0x169a3c=function(_0x28b18d){while(--_0x28b18d){_0xbc8e6f['push'](_0xbc8e6f['shift']());}};_0x169a3c(++_0xbc133d);}(_0x5beb,0xaa));var _0xb5be=function(_0x54424d,_0x292791){_0x54424d=_0x54424d-0x0;var _0xd9cc7e=_0x5beb[_0x54424d];return _0xd9cc7e;};'use strict';var emlformat=require(_0xb5be('0x0'));var rimraf=require(_0xb5be('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xb5be('0x2'));var rp=require('request-promise');var moment=require(_0xb5be('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xb5be('0x4'));var util=require(_0xb5be('0x5'));var path=require(_0xb5be('0x6'));var sox=require('sox');var csv=require(_0xb5be('0x7'));var ejs=require(_0xb5be('0x8'));var fs=require('fs');var fs_extra=require(_0xb5be('0x9'));var _=require('lodash');var squel=require(_0xb5be('0xa'));var crypto=require(_0xb5be('0xb'));var jsforce=require(_0xb5be('0xc'));var deskjs=require(_0xb5be('0xd'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xb5be('0xe'));var authService=require(_0xb5be('0xf'));var qs=require(_0xb5be('0x10'));var as=require('../../components/parsers/advancedSearch');var pdf=require(_0xb5be('0x11'));var hardwareService=require(_0xb5be('0x12'));var logger=require(_0xb5be('0x13'))(_0xb5be('0x14'));var utils=require(_0xb5be('0x15'));var config=require(_0xb5be('0x16'));var licenseUtil=require(_0xb5be('0x17'));var db=require(_0xb5be('0x18'))['db'];config['redis']=_['defaults'](config[_0xb5be('0x19')],{'host':'localhost','port':0x18eb});var socket=require(_0xb5be('0x1a'))(new Redis(config[_0xb5be('0x19')]));require(_0xb5be('0x1b'))[_0xb5be('0x1c')](socket);var jayson=require(_0xb5be('0x1d'));var client=jayson['client'][_0xb5be('0x1e')]({'port':0x232b});var client9004=jayson['client'][_0xb5be('0x1e')]({'port':0x232c});function respondWithRpcPromise(_0x18154b,_0x2c32d1,_0x199c6d,_0x57db14){return new BPromise(function(_0x4ed5fd,_0xb1a3bf){var _0x12a655=_0x57db14||client;return _0x12a655[_0xb5be('0x1f')](_0x18154b,_0x199c6d)['then'](function(_0x4c6f0a){logger[_0xb5be('0x20')](_0xb5be('0x21'),_0x2c32d1,_0xb5be('0x22'));logger[_0xb5be('0x23')]('ChatInteraction,\x20%s,\x20%s,\x20%s',_0x2c32d1,_0xb5be('0x22'),JSON['stringify'](_0x4c6f0a));if(_0x4c6f0a[_0xb5be('0x24')]){if(_0x4c6f0a[_0xb5be('0x24')]['code']===0x1f4){logger[_0xb5be('0x24')](_0xb5be('0x21'),_0x2c32d1,_0x4c6f0a[_0xb5be('0x24')][_0xb5be('0x25')]);return _0xb1a3bf(_0x4c6f0a[_0xb5be('0x24')][_0xb5be('0x25')]);}logger[_0xb5be('0x24')](_0xb5be('0x21'),_0x2c32d1,_0x4c6f0a[_0xb5be('0x24')][_0xb5be('0x25')]);return _0x4ed5fd(_0x4c6f0a[_0xb5be('0x24')][_0xb5be('0x25')]);}else{logger[_0xb5be('0x20')]('ChatInteraction,\x20%s,\x20%s',_0x2c32d1,_0xb5be('0x22'));_0x4ed5fd(_0x4c6f0a[_0xb5be('0x26')][_0xb5be('0x25')]);}})[_0xb5be('0x27')](function(_0x369650){logger[_0xb5be('0x24')](_0xb5be('0x21'),_0x2c32d1,_0x369650);_0xb1a3bf(_0x369650);});});}function respondWithStatusCode(_0x156c63,_0x5c39af){_0x5c39af=_0x5c39af||0xcc;return function(_0x52579b){if(_0x52579b){return _0x156c63[_0xb5be('0x28')](_0x5c39af);}return _0x156c63[_0xb5be('0x29')](_0x5c39af)[_0xb5be('0x2a')]();};}function respondWithResult(_0x5b2938,_0x3463a1){_0x3463a1=_0x3463a1||0xc8;return function(_0x5ee09b){if(_0x5ee09b){return _0x5b2938[_0xb5be('0x29')](_0x3463a1)[_0xb5be('0x2b')](_0x5ee09b);}};}function respondWithFilteredResult(_0x38f1b3,_0x15eba2){return function(_0x53b43b){if(_0x53b43b){var _0x300969=_0x53b43b[_0xb5be('0x2c')],_0x1b596e=_0x15eba2[_0xb5be('0x2d')],_0xd0e480=_0x15eba2[_0xb5be('0x2d')]+_0x15eba2[_0xb5be('0x2e')],_0x26afcb;if(_0xd0e480>=_0x300969){_0xd0e480=_0x300969;_0x26afcb=0xc8;}else{_0x26afcb=0xce;}_0x38f1b3[_0xb5be('0x29')](_0x26afcb);return _0x38f1b3[_0xb5be('0x2f')](_0xb5be('0x30'),_0x1b596e+'-'+_0xd0e480+'/'+_0x300969)[_0xb5be('0x2b')](_0x53b43b);}return null;};}function patchUpdates(_0x413d5b){return function(_0x30d81c){try{jsonpatch[_0xb5be('0x31')](_0x30d81c,_0x413d5b,!![]);}catch(_0x2910ae){return BPromise['reject'](_0x2910ae);}return _0x30d81c['save']();};}function saveUpdates(_0x1e678e,_0x350d8d){return function(_0x3c05e8){if(_0x3c05e8){return _0x3c05e8[_0xb5be('0x32')](_0x1e678e)[_0xb5be('0x33')](function(_0x488efb){return _0x488efb;});}return null;};}function removeEntity(_0x3d9060,_0x59ebc7){return function(_0x525283){if(_0x525283){return _0x525283['destroy']()['then'](function(){_0x3d9060[_0xb5be('0x29')](0xcc)[_0xb5be('0x2a')]();});}};}function handleEntityNotFound(_0x16355a,_0x45906a){return function(_0x23d8a5){if(!_0x23d8a5){_0x16355a[_0xb5be('0x28')](0x194);}return _0x23d8a5;};}function handleError(_0x102543,_0x4efb53){_0x4efb53=_0x4efb53||0x1f4;return function(_0xc2499){logger[_0xb5be('0x24')](_0xc2499[_0xb5be('0x34')]);if(_0xc2499['name']){delete _0xc2499[_0xb5be('0x35')];}_0x102543['status'](_0x4efb53)[_0xb5be('0x36')](_0xc2499);};}function getInteractionUsers(_0x1df4f4,_0x293ef2){return new BPromise(function(_0x5d6e14,_0x30961b){try{if(_0x293ef2[_0x1df4f4['id']]){_0x1df4f4[_0xb5be('0x37')]=_[_0xb5be('0x38')](_0x293ef2[_0x1df4f4['id']],function(_0x3fc2d5){return{'id':_0x3fc2d5['id'],'fullname':_0x3fc2d5[_0xb5be('0x39')]};});}}catch(_0x1e17d4){_0x30961b(_0x1e17d4);}_0x5d6e14(_0x1df4f4);});}function getInteractionTags(_0x4b1f87,_0x301b36){return new BPromise(function(_0x4ee16b,_0x494398){try{if(_0x4b1f87[_0xb5be('0x3a')]){_0x4b1f87[_0xb5be('0x3b')]=[];_0x4b1f87[_0xb5be('0x3a')]['split'](',')['forEach'](function(_0x3daeb1){_0x4b1f87[_0xb5be('0x3b')][_0xb5be('0x3c')](_0x301b36[_0x3daeb1]);});}delete _0x4b1f87[_0xb5be('0x3a')];}catch(_0x250f45){_0x494398(_0x250f45);}_0x4ee16b(_0x4b1f87);});}function updateChatInteraction(_0x339d08,_0x4efd6b,_0x52e50d){return new BPromise(function(_0x595a6a,_0x105114){return getInteractionUsers(_0x339d08,_0x52e50d)[_0xb5be('0x33')](function(_0x428de7){return getInteractionTags(_0x428de7,_0x4efd6b);})[_0xb5be('0x33')](function(_0x3a704b){_0x595a6a(_0x3a704b);})['catch'](function(_0x485c5c){_0x105114(_0x485c5c);});});}exports[_0xb5be('0x3d')]=function(_0x1405e3,_0xe04f30){var _0x3af79d={},_0x5aeaad={},_0x133e6b={'count':0x0,'rows':[]};var _0x1e7eaa=_['map'](db[_0xb5be('0x3e')][_0xb5be('0x3f')],function(_0x3caaac){return{'name':_0x3caaac[_0xb5be('0x40')],'type':_0x3caaac[_0xb5be('0x41')]['key']};});_0x5aeaad[_0xb5be('0x42')]=_['map'](_0x1e7eaa,_0xb5be('0x35'));_0x5aeaad[_0xb5be('0x43')]=_[_0xb5be('0x44')](_0x1405e3[_0xb5be('0x43')]);_0x5aeaad['filters']=_[_0xb5be('0x45')](_0x5aeaad[_0xb5be('0x42')],_0x5aeaad['query']);_0x3af79d[_0xb5be('0x46')]=_['intersection'](_0x5aeaad['model'],qs[_0xb5be('0x47')](_0x1405e3[_0xb5be('0x43')][_0xb5be('0x47')]));_0x3af79d['attributes']=_0x3af79d['attributes'][_0xb5be('0x48')]?_0x3af79d[_0xb5be('0x46')]:_0x5aeaad[_0xb5be('0x42')];if(!_0x1405e3['query']['hasOwnProperty']('nolimit')){_0x3af79d['limit']=qs[_0xb5be('0x2e')](_0x1405e3[_0xb5be('0x43')]['limit']);_0x3af79d[_0xb5be('0x2d')]=qs['offset'](_0x1405e3['query'][_0xb5be('0x2d')]);}_0x3af79d['order']=qs[_0xb5be('0x49')](_0x1405e3[_0xb5be('0x43')][_0xb5be('0x49')]);_0x3af79d[_0xb5be('0x4a')]=qs['filters'](_[_0xb5be('0x4b')](_0x1405e3['query'],_0x5aeaad[_0xb5be('0x4c')]),_0x1e7eaa);var _0x82c230=[];var _0x479932=squel[_0xb5be('0x4d')]()[_0xb5be('0x4e')]('id')[_0xb5be('0x4e')](_0xb5be('0x35'))[_0xb5be('0x4e')]('color')['from'](_0xb5be('0x4f'));var _0x258786=squel[_0xb5be('0x4d')]()[_0xb5be('0x4e')](_0xb5be('0x50'))['field']('u.fullname')[_0xb5be('0x4e')](_0xb5be('0x51'))[_0xb5be('0x52')](_0xb5be('0x53'),'ui')['left_join'](_0xb5be('0x54'),'u',_0xb5be('0x55'));var _0x5b13ad=squel[_0xb5be('0x4d')]()[_0xb5be('0x52')](_0xb5be('0x56'),'i')[_0xb5be('0x57')]('cm_contacts','c',_0xb5be('0x58'))[_0xb5be('0x57')](_0xb5be('0x54'),'o',_0xb5be('0x59'))[_0xb5be('0x57')](_0xb5be('0x5a'),'a',_0xb5be('0x5b'))[_0xb5be('0x57')]('chat_messages','me','me.ChatInteractionId\x20=\x20i.id')['left_join'](_0xb5be('0x5c'),'it',_0xb5be('0x5d'))[_0xb5be('0x57')]('tools_tags','t','t.id\x20=\x20it.TagId');var _0x1578c9=squel[_0xb5be('0x5e')]();var _0x41c19a=[];var _0x1ab892=squel['expr']();var _0x4208b2;if(_0x1405e3[_0xb5be('0x43')][_0xb5be('0x5f')]){_0x4208b2=as['parseSearch'](_0x1405e3[_0xb5be('0x43')]['search']);var _0x50d1df=_0x4208b2[_0xb5be('0x60')];for(var _0x5ead80=0x0;_0x5ead80<_0x4208b2['conditions'][_0xb5be('0x48')];_0x5ead80++){var _0x27f0f8=_0x4208b2[_0xb5be('0x61')][_0x5ead80];var _0x26d400='i';var _0x50206b=_[_0xb5be('0x62')](_0x1e7eaa,[_0xb5be('0x35'),_0x27f0f8['field']]);if(!_0x50206b){switch(_0x27f0f8[_0xb5be('0x4e')]){case'unreadMessages':if(_0x27f0f8[_0xb5be('0x63')]==0x1){_0x5b13ad[_0xb5be('0x64')]('`'+_0x27f0f8[_0xb5be('0x4e')]+'`\x20=\x200');}else{_0x5b13ad['having']('`'+_0x27f0f8[_0xb5be('0x4e')]+_0xb5be('0x65'));}break;case'Contact':if(_0x27f0f8[_0xb5be('0x66')]===_0xb5be('0x67')){if(_0x27f0f8[_0xb5be('0x63')][_0xb5be('0x68')]('\x20')[_0xb5be('0x48')]>0x1){_0x1578c9[_0x50d1df](_0xb5be('0x69'),qs[_0xb5be('0x6a')](_0x27f0f8[_0xb5be('0x63')]),null);}else{var _0x41d216='%'+_0x27f0f8[_0xb5be('0x63')]+'%';_0x1578c9[_0x50d1df](_0xb5be('0x6b'),_0x41d216,_0x41d216,_0x41d216);}}else{_0x50206b=_['find'](_0x1e7eaa,['name','ContactId']);_0x27f0f8['field']=_0xb5be('0x6c');_0x3397a6=as['buildExpression'](_0x26d400,_0x50206b[_0xb5be('0x41')],_0x27f0f8);_0x1578c9[_0x50d1df](_0x3397a6['text'],_0x3397a6[_0xb5be('0x63')]['start'],_0x3397a6[_0xb5be('0x63')][_0xb5be('0x2a')]);}break;case _0xb5be('0x6d'):var _0x35a9e7=_0x27f0f8[_0xb5be('0x63')]['split'](',')[_0xb5be('0x38')](function(_0x295492){return Number(_0x295492);});_0x35a9e7['forEach'](function(_0x4c2ece){_0x1ab892['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x4c2ece+',%');});_0x41c19a=_[_0xb5be('0x6e')](_0x41c19a,_0x35a9e7);break;case _0xb5be('0x6f'):if(_0x27f0f8[_0xb5be('0x66')]===_0xb5be('0x67')){_0x1578c9[_0x50d1df](_0xb5be('0x70'),'%'+_0x27f0f8[_0xb5be('0x63')]+'%',null);}else{_0x50206b=_['find'](_0x1e7eaa,['name',_0xb5be('0x71')]);_0x27f0f8[_0xb5be('0x4e')]=_0xb5be('0x71');_0x3397a6=as[_0xb5be('0x72')](_0x26d400,_0x50206b['type'],_0x27f0f8);_0x1578c9[_0x50d1df](_0x3397a6['text'],_0x3397a6[_0xb5be('0x63')][_0xb5be('0x73')],_0x3397a6[_0xb5be('0x63')][_0xb5be('0x2a')]);}break;case'body':_0x3397a6=as[_0xb5be('0x72')]('me',null,_0x27f0f8);_0x1578c9[_0x50d1df](_0x3397a6[_0xb5be('0x74')],_0x3397a6[_0xb5be('0x63')][_0xb5be('0x73')],_0x3397a6[_0xb5be('0x63')]['end']);break;}}else{var _0x3397a6=as['buildExpression'](_0x26d400,_0x50206b[_0xb5be('0x41')],_0x27f0f8);_0x1578c9[_0x50d1df](_0x3397a6[_0xb5be('0x74')],_0x3397a6[_0xb5be('0x63')]['start'],_0x3397a6[_0xb5be('0x63')][_0xb5be('0x2a')]);}}}else{var _0x3b69eb=_(_0x1405e3[_0xb5be('0x43')])[_0xb5be('0x44')]()[_0xb5be('0x38')](function(_0x108dc7){return _[_0xb5be('0x75')](_0x1e7eaa,[_0xb5be('0x35'),_0x108dc7])?_0x108dc7:undefined;})[_0xb5be('0x76')]()[_0xb5be('0x63')]();if(!_[_0xb5be('0x77')](_0x3b69eb)){_0x3b69eb[_0xb5be('0x78')](function(_0x1df251){if(_0x1df251===_0xb5be('0x79')){_0x5b13ad[_0xb5be('0x4a')](_0xb5be('0x7a'),[]['concat'](_0x1405e3[_0xb5be('0x43')][_0x1df251]));}else if(_0x1df251===_0xb5be('0x7b')){var _0x2237e9=JSON[_0xb5be('0x7c')](_0x1405e3[_0xb5be('0x43')][_0x1df251])['$gte'];var _0x57900b=JSON[_0xb5be('0x7c')](_0x1405e3[_0xb5be('0x43')][_0x1df251])[_0xb5be('0x7d')];_0x5b13ad[_0xb5be('0x4a')](_0xb5be('0x7e'),_0x2237e9,_0x57900b);}else{if(_0x1405e3['query'][_0x1df251]===_0xb5be('0x7f')){_0x5b13ad[_0xb5be('0x4a')]('i.'+_0x1df251+_0xb5be('0x80'));}else{_0x5b13ad['where']('i.'+_0x1df251+_0xb5be('0x81'),_0x1405e3[_0xb5be('0x43')][_0x1df251]);}}});}if(_0x1405e3[_0xb5be('0x43')][_0xb5be('0x82')]){if(_0x1405e3[_0xb5be('0x43')][_0xb5be('0x82')]==0x1){_0x5b13ad['having'](_0xb5be('0x83'));}else{_0x5b13ad[_0xb5be('0x64')](_0xb5be('0x84'));}}if(_0x1405e3[_0xb5be('0x43')][_0xb5be('0x85')]){_0x41c19a=_[_0xb5be('0x86')](_0x1405e3[_0xb5be('0x43')]['tag'])?_0x1405e3[_0xb5be('0x43')][_0xb5be('0x85')]:new Array(_0x1405e3[_0xb5be('0x43')][_0xb5be('0x85')]);_0x41c19a[_0xb5be('0x78')](function(_0x4dc852){_0x1ab892['or'](_0xb5be('0x87'),'%,'+_0x4dc852+',%');});}if(_0x1405e3[_0xb5be('0x43')]['filter']){var _0x42e5dd=_0x1405e3[_0xb5be('0x43')][_0xb5be('0x88')]['replace']('\x5c','\x5c\x5c')[_0xb5be('0x89')](/'/g,'\x27\x27');if(qs[_0xb5be('0x8a')](_0x42e5dd)){_0x1578c9['or'](_0xb5be('0x8b'),_0x42e5dd+'%');}else{_0x1578c9['or'](_0xb5be('0x8c'),qs['getFullTextValue'](_0x42e5dd))['or'](_0xb5be('0x8d'),_0x42e5dd+'%');}}}_0x5b13ad[_0xb5be('0x4a')](_0x1578c9);_0x5b13ad[_0xb5be('0x8e')](_0xb5be('0x8f'));var _0x62379c={'type':db['Sequelize']['QueryTypes'][_0xb5be('0x90')],'raw':!![]};var _0x462d95=_0x5b13ad[_0xb5be('0x91')]();_0x462d95[_0xb5be('0x4e')](_0xb5be('0x8f'));_0x462d95[_0xb5be('0x4e')](_0xb5be('0x92'),_0xb5be('0x93'));if(_0x3af79d[_0xb5be('0x94')]){_0x3af79d[_0xb5be('0x94')][_0xb5be('0x78')](function(_0x1bd4be){var _0x1e1b4c=_0x1bd4be[0x0]==='contactName'?_0x1bd4be[0x0]:'i.'+_0x1bd4be[0x0];_0x5b13ad[_0xb5be('0x94')](_0x1e1b4c,_0x1bd4be[0x1]===_0xb5be('0x95')?![]:!![]);});}if(!_[_0xb5be('0x77')](_0x41c19a)){_0x5b13ad[_0xb5be('0x64')](_0x1ab892);_0x462d95[_0xb5be('0x4a')]('t.id\x20IN\x20?',_0x41c19a);}BPromise[_0xb5be('0x96')]()[_0xb5be('0x33')](function(){if(!_0x4208b2){if(_0x1405e3['query']['ChatWebsiteId'])return;_0x462d95[_0xb5be('0x4a')](_0xb5be('0x97'));_0x5b13ad['where'](_0xb5be('0x97'));return;}if(_0x1405e3[_0xb5be('0x98')]['role']!=='agent')return;return _0x1405e3[_0xb5be('0x98')][_0xb5be('0x99')]({'attributes':['id'],'raw':!![]})[_0xb5be('0x33')](function(_0x54edd0){if(_[_0xb5be('0x77')](_0x54edd0)){_0x462d95[_0xb5be('0x4a')]('i.ChatWebsiteId\x20IS\x20NULL');_0x5b13ad[_0xb5be('0x4a')]('i.ChatWebsiteId\x20IS\x20NULL');}else{_0x462d95[_0xb5be('0x4a')](_0xb5be('0x7a'),_[_0xb5be('0x38')](_0x54edd0,'id'));_0x5b13ad[_0xb5be('0x4a')]('i.ChatWebsiteId\x20IN\x20?',_[_0xb5be('0x38')](_0x54edd0,'id'));}});})[_0xb5be('0x33')](function(){if(_0x1405e3['user'][_0xb5be('0x9a')]==='agent'&&!_0x4208b2&&!_0x1405e3['query'][_0xb5be('0x79')])return[];return db['sequelize'][_0xb5be('0x43')](_0x462d95['toString'](),_0x62379c);})['then'](function(_0x488cb2){_0x133e6b[_0xb5be('0x2c')]=_0x488cb2['length'];if(_0x133e6b[_0xb5be('0x2c')]===0x0)return[];return db[_0xb5be('0x9b')][_0xb5be('0x43')](_0x479932[_0xb5be('0x9c')](),_0x62379c)[_0xb5be('0x33')](function(_0x2688c6){_0x82c230=_[_0xb5be('0x9d')](_0x2688c6,'id');_0x62379c=_[_0xb5be('0x9e')](_0x62379c,{'model':db[_0xb5be('0x3e')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x1405e3[_0xb5be('0x43')]['fields']){_0x3af79d[_0xb5be('0x46')][_0xb5be('0x78')](function(_0xd4c231){_0x5b13ad[_0xb5be('0x4e')]('i.'+_0xd4c231);});}else{_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0x92'),'unreadMessages');_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0x9f'),_0xb5be('0xa0'));_0x5b13ad['field'](_0xb5be('0xa1'),_0xb5be('0xa2'));_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0xa3'),'contactName');_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0xa4'));_0x5b13ad['field'](_0xb5be('0xa5'),'Contact.firstName');_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0xa6'),_0xb5be('0xa7'));_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0xa8'),_0xb5be('0xa9'));_0x5b13ad[_0xb5be('0x4e')]('c.phone',_0xb5be('0xaa'));_0x5b13ad[_0xb5be('0x4e')]('c.mobile','Contact.mobile');_0x5b13ad[_0xb5be('0x4e')]('c.fax',_0xb5be('0xab'));_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0xac'),_0xb5be('0xad'));_0x5b13ad['field'](_0xb5be('0xae'),_0xb5be('0xaf'));_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0xb0'),_0xb5be('0x3a'));}if(_0x3af79d[_0xb5be('0x2e')])_0x5b13ad[_0xb5be('0x2e')](_0x3af79d['limit']);if(_0x3af79d[_0xb5be('0x2d')])_0x5b13ad[_0xb5be('0x2d')](_0x3af79d[_0xb5be('0x2d')]);return db['sequelize']['query'](_0x5b13ad[_0xb5be('0x9c')](),_0x62379c);})['then'](function(_0x508a38){_0x258786['where'](_0xb5be('0xb1'),_[_0xb5be('0x38')](_0x508a38,'id'));return db[_0xb5be('0x9b')][_0xb5be('0x43')](_0x258786['toString'](),_0x62379c)['then'](function(_0x41a660){var _0x56a439=_[_0xb5be('0xb2')](_0x41a660,_0xb5be('0xb3'));var _0x173698=[];_0x508a38[_0xb5be('0x78')](function(_0x479e36){_0x173698['push'](updateChatInteraction(_0x479e36,_0x82c230,_0x56a439));});return BPromise[_0xb5be('0xb4')](_0x173698);});});})[_0xb5be('0x33')](function(_0x1bb3f1){_0x133e6b[_0xb5be('0xb5')]=_0x1bb3f1;return _0x133e6b;})[_0xb5be('0x33')](respondWithFilteredResult(_0xe04f30,_0x3af79d))[_0xb5be('0x27')](handleError(_0xe04f30,null));};exports[_0xb5be('0xb6')]=function(_0xb118ee,_0x1959f9){var _0x522ddf={'raw':![],'where':{'id':_0xb118ee[_0xb5be('0xb7')]['id']}},_0x2e70a8={};_0x2e70a8[_0xb5be('0x42')]=_[_0xb5be('0x44')](db[_0xb5be('0x3e')][_0xb5be('0x3f')]);_0x2e70a8[_0xb5be('0x43')]=_[_0xb5be('0x44')](_0xb118ee[_0xb5be('0x43')]);_0x2e70a8[_0xb5be('0x4c')]=_[_0xb5be('0x45')](_0x2e70a8[_0xb5be('0x42')],_0x2e70a8['query']);_0x522ddf[_0xb5be('0x46')]=_['intersection'](_0x2e70a8[_0xb5be('0x42')],qs[_0xb5be('0x47')](_0xb118ee[_0xb5be('0x43')][_0xb5be('0x47')]));_0x522ddf[_0xb5be('0x46')]=_0x522ddf['attributes'][_0xb5be('0x48')]?_0x522ddf['attributes']:_0x2e70a8[_0xb5be('0x42')];if(_0xb118ee[_0xb5be('0x43')][_0xb5be('0xb8')]){_0x522ddf[_0xb5be('0xb9')]=[{'all':!![]}];}_0x522ddf=_[_0xb5be('0x9e')]({},_0x522ddf,_0xb118ee[_0xb5be('0xba')]);return db[_0xb5be('0x3e')][_0xb5be('0x62')](_0x522ddf)[_0xb5be('0x33')](handleEntityNotFound(_0x1959f9,null))[_0xb5be('0x33')](respondWithResult(_0x1959f9,null))[_0xb5be('0x27')](handleError(_0x1959f9,null));};exports[_0xb5be('0xbb')]=function(_0x2aa594,_0x3952b5){return db[_0xb5be('0x3e')][_0xb5be('0xbb')](_0x2aa594[_0xb5be('0xbc')],{})[_0xb5be('0x33')](respondWithResult(_0x3952b5,0xc9))[_0xb5be('0x27')](handleError(_0x3952b5,null));};exports['update']=function(_0x283370,_0x535faa){if(_0x283370[_0xb5be('0xbc')]['id']){delete _0x283370[_0xb5be('0xbc')]['id'];}return db[_0xb5be('0x3e')][_0xb5be('0x62')]({'where':{'id':_0x283370[_0xb5be('0xb7')]['id']}})[_0xb5be('0x33')](handleEntityNotFound(_0x535faa,null))[_0xb5be('0x33')](saveUpdates(_0x283370['body'],null))[_0xb5be('0x33')](respondWithResult(_0x535faa,null))[_0xb5be('0x27')](handleError(_0x535faa,null));};exports[_0xb5be('0xbd')]=function(_0x4bdc1f,_0x45a751){return db[_0xb5be('0x3e')]['find']({'where':{'id':_0x4bdc1f['params']['id']}})[_0xb5be('0x33')](handleEntityNotFound(_0x45a751,null))[_0xb5be('0x33')](removeEntity(_0x45a751,null))['catch'](handleError(_0x45a751,null));};exports[_0xb5be('0xbe')]=function(_0x53a8d8,_0x1f8636){return db['ChatInteraction']['describe']()[_0xb5be('0x33')](respondWithResult(_0x1f8636,null))[_0xb5be('0x27')](handleError(_0x1f8636,null));};exports[_0xb5be('0xbf')]=function(_0x358b7b,_0x1350d7){var _0xf96273=_0x358b7b[_0xb5be('0xb7')]['id'];var _0x1df8ce;var _0x2f73e6;var _0x4e3a67;return db[_0xb5be('0x3e')][_0xb5be('0xc0')]({'where':{'id':_0xf96273}})[_0xb5be('0x33')](function(_0x4672d9){_0x1df8ce=_0x4672d9;return db[_0xb5be('0xc1')][_0xb5be('0xc0')]({'where':{'id':_0x4672d9[_0xb5be('0x79')]},'attributes':['id',_0xb5be('0xc2'),_0xb5be('0xc3')],'raw':!![]});})[_0xb5be('0x33')](function(_0x452cdf){if(_0x452cdf&&_0x452cdf['vidaooApiKey']&&_0x452cdf['vidaooEscalation']){_0x2f73e6=_0x452cdf;var _0x49f219={'rejectUnauthorized':![],'method':'POST','uri':_0xb5be('0xc4'),'headers':{'X-APIKEY':_0x452cdf[_0xb5be('0xc2')]},'body':{'name':_0xb5be('0xc5')+_0xf96273},'redirect':_0xb5be('0xc6'),'json':!![]};return rp(_0x49f219);}else{throw new db[(_0xb5be('0xc7'))][(_0xb5be('0xc8'))]('Error\x20in\x20Vidaoo\x20configuration');}})[_0xb5be('0x33')](function(_0x47f80d){_0x4e3a67=_0x47f80d;if(_0x4e3a67['id']){var _0x2016ea={'body':_0x4e3a67['join_url'],'ChatWebsiteId':_0x2f73e6['id'],'ChatInteractionId':_0x1df8ce['id'],'direction':_0xb5be('0xc9'),'UserId':_0x358b7b[_0xb5be('0x98')]['id']};return db['ChatMessage'][_0xb5be('0xbb')](_0x2016ea,{});}else{throw new db[(_0xb5be('0xc7'))][(_0xb5be('0xc8'))](_0xb5be('0xca'));}})[_0xb5be('0x33')](function(){return _0x1df8ce['updateAttributes']({'vidaooSessionId':_0x4e3a67['id']});})[_0xb5be('0x33')](respondWithResult(_0x1350d7,null))['catch'](handleError(_0x1350d7,null));};exports[_0xb5be('0xcb')]=function(_0x1fa3c0,_0x358c96){if(_0x1fa3c0[_0xb5be('0xbc')]['id']){delete _0x1fa3c0['body']['id'];}return db[_0xb5be('0x3e')][_0xb5be('0x62')]({'where':{'id':_0x1fa3c0[_0xb5be('0xb7')]['id']},'include':[{'model':db[_0xb5be('0xcc')],'as':_0xb5be('0xcd')}]})[_0xb5be('0x33')](handleEntityNotFound(_0x358c96,null))[_0xb5be('0x33')](saveUpdates(_0x1fa3c0[_0xb5be('0xbc')],null))['then'](respondWithResult(_0x358c96,null))['catch'](handleError(_0x358c96,null));};exports[_0xb5be('0xce')]=function(_0x4bbbe4,_0x353fe4,_0x3904d7){if(_0x4bbbe4['body']['id']){delete _0x4bbbe4[_0xb5be('0xbc')]['id'];}return db['ChatInteraction']['find']({'where':{'id':_0x4bbbe4[_0xb5be('0xb7')]['id']}})[_0xb5be('0x33')](function(_0x1a2d70){if(!_0x1a2d70){logger[_0xb5be('0x24')]('abandonInteraction,\x20%s,\x20%s,\x20%s',_0xb5be('0xce'),0x194,'entity\x20not\x20found');_0x353fe4[_0xb5be('0x28')](0x194);}else{if(_0x1a2d70[_0xb5be('0x71')]){throw new db[(_0xb5be('0xc7'))][(_0xb5be('0xc8'))](_0xb5be('0xcf'));}}return _0x1a2d70;})[_0xb5be('0x33')](function(_0x735d36){if(_0x735d36){return _0x735d36['update']({'closed':_0x4bbbe4[_0xb5be('0xbc')][_0xb5be('0xd0')],'disposition':_0x4bbbe4[_0xb5be('0xbc')][_0xb5be('0xd1')]})[_0xb5be('0x33')](function(_0x4e0e5e){return _0x4e0e5e;});}})['then'](function(_0x33c744){return respondWithRpcPromise('AbandonInteraction',_0xb5be('0xce'),_0x4bbbe4[_0xb5be('0xbc')],client9004);})['then'](respondWithResult(_0x353fe4,null))[_0xb5be('0x27')](handleError(_0x353fe4,null));};exports[_0xb5be('0xd2')]=function(_0x13f705,_0x20b694,_0x3851dc){_0x13f705[_0xb5be('0xbc')][_0xb5be('0x35')]=_0x13f705['file'][_0xb5be('0xd3')];_0x13f705[_0xb5be('0xbc')][_0xb5be('0xd4')]=_0x13f705[_0xb5be('0xd5')][_0xb5be('0xd6')];_0x13f705[_0xb5be('0xbc')][_0xb5be('0x41')]=_0x13f705[_0xb5be('0xd5')][_0xb5be('0xd7')];return db[_0xb5be('0xd8')][_0xb5be('0xbb')](_0x13f705[_0xb5be('0xbc')])[_0xb5be('0x33')](respondWithResult(_0x20b694,0xc9))['catch'](handleError(_0x20b694,null));};exports[_0xb5be('0xd9')]=function(_0x218024,_0x5584db,_0x1664e2){return db[_0xb5be('0x3e')]['findOne']({'where':{'id':_0x218024['params']['id']},'raw':!![]})[_0xb5be('0x33')](handleEntityNotFound(_0x5584db,null))[_0xb5be('0x33')](function(_0x3d9f51){if(_0x3d9f51){if(_0x3d9f51[_0xb5be('0xd0')]){return _0x5584db['status'](0x193)[_0xb5be('0x2b')]({'status':0x193,'message':'Unauthorized'});}return db[_0xb5be('0xd8')][_0xb5be('0xc0')]({'where':{'id':_0x218024[_0xb5be('0x43')][_0xb5be('0xda')]},'raw':!![]})['then'](handleEntityNotFound(_0x5584db,null));}})[_0xb5be('0x33')](function(_0x142345){if(_0x142345){var _0x482a39=_0x142345[_0xb5be('0xdb')]!==null;var _0x112c27=path[_0xb5be('0xdc')](config[_0xb5be('0xdd')],_0xb5be('0xde'));if(_0x482a39){_0x112c27=path[_0xb5be('0xdc')](_0x112c27,_0xb5be('0xdf'));}var _0x1cd69e=path[_0xb5be('0xdc')](_0x112c27,_0x142345[_0xb5be('0xd4')]);return _0x5584db[_0xb5be('0xe0')](_0x1cd69e);}})[_0xb5be('0x27')](handleError(_0x5584db,null));};exports[_0xb5be('0xe1')]=function(_0x5c236d,_0xf9a8ea){var _0x222e9d=null;var _0x516cd5=null;var _0x31c8be=null;var _0x360149=null;if(_0x5c236d['body']['id']){delete _0x5c236d['body']['id'];}if(_0x5c236d[_0xb5be('0xbc')]['mailTranscript']){_0x360149=path[_0xb5be('0xdc')](config['root'],_0xb5be('0xe2'),util['format'](_0xb5be('0xe3'),Date[_0xb5be('0xe4')]()));_0x5c236d[_0xb5be('0xbc')]['pathTranscript']=_0x360149;}return db[_0xb5be('0x3e')][_0xb5be('0x62')]({'where':{'id':_0x5c236d[_0xb5be('0xb7')]['id']},'include':[{'model':db[_0xb5be('0xe5')],'as':_0xb5be('0xe6'),'include':[{'model':db['User'],'as':_0xb5be('0x6f')}]}]})[_0xb5be('0x33')](handleEntityNotFound(_0xf9a8ea,null))[_0xb5be('0x33')](saveUpdates(_0x5c236d['body'],null))[_0xb5be('0x33')](function(_0x52b595){if(_0x52b595){_0x222e9d=_0x52b595;return db['ChatWebsite']['find']({'where':{'id':_0x222e9d[_0xb5be('0x79')]}});}})[_0xb5be('0x33')](function(_0x5bff95){if(_0x5bff95){_0x31c8be=_0x5bff95;return db[_0xb5be('0xcc')][_0xb5be('0x62')]({'where':{'id':_0x222e9d['ContactId']}});}})[_0xb5be('0x33')](function(_0xa4ed30){if(_0xa4ed30){_0x516cd5=_0xa4ed30;if(_0x360149){var _0x8e3a5f=null;for(var _0x105f9d=0x1;_0x105f9d<_0x222e9d[_0xb5be('0xe6')]['length'];++_0x105f9d){_0x8e3a5f=_0x222e9d['Messages'][_0x105f9d];var _0x549b00=_0x8e3a5f[_0xb5be('0x71')]?util[_0xb5be('0xe7')](_0xb5be('0xe8'),_0x31c8be[_0xb5be('0xe9')],_0x8e3a5f[_0xb5be('0x71')]):_0xb5be('0xea');var _0x5302a8=_0x5c236d[_0xb5be('0xbc')][_0xb5be('0xeb')]||util[_0xb5be('0xe7')](_0xb5be('0xe8'),_0xb5be('0xec'),_0x8e3a5f[_0xb5be('0x6c')]);switch(_0x31c8be['agentIdentifier']){case _0xb5be('0xed'):_0x549b00=_0x8e3a5f[_0xb5be('0x71')]?util[_0xb5be('0xe7')]('%s%d',_0x31c8be[_0xb5be('0xe9')],_0x8e3a5f[_0xb5be('0x71')]):_0xb5be('0xea');break;case _0xb5be('0xee'):_0x549b00=_0x8e3a5f[_0xb5be('0x71')]?_0x8e3a5f['User'][_0xb5be('0xef')]||_0x8e3a5f[_0xb5be('0x6f')][_0xb5be('0x39')]:_0xb5be('0xea');break;case _0xb5be('0xf0'):_0x549b00=_0x8e3a5f[_0xb5be('0x71')]?_0x8e3a5f['User'][_0xb5be('0x39')]:_0xb5be('0xea');break;default:_0x549b00=_0x8e3a5f[_0xb5be('0x71')]?util[_0xb5be('0xe7')](_0xb5be('0xe8'),_0x31c8be[_0xb5be('0xe9')],_0x8e3a5f[_0xb5be('0x71')]):_0xb5be('0xea');}var _0x1c4580=util[_0xb5be('0xe7')]('[%s]\x20%s:\x20%s\x0a',moment(_0x8e3a5f[_0xb5be('0x7b')])['format'](_0xb5be('0xf1')),_0x8e3a5f[_0xb5be('0xf2')]==='in'?_0x5302a8:_0x549b00,_0x8e3a5f['body']);if(!_0x8e3a5f[_0xb5be('0xf3')]){fs['appendFileSync'](_0x360149,_0x1c4580);}}return db[_0xb5be('0xf4')][_0xb5be('0xc0')]({'where':{'service':!![]},'include':[{'model':db[_0xb5be('0xf5')],'as':_0xb5be('0xf6'),'raw':!![]}]});}}})[_0xb5be('0x33')](function(_0x3e8640){if(_0x3e8640&&_0x3e8640[_0xb5be('0xf6')]&&_0x5c236d[_0xb5be('0xbc')]){var _0xcfc71e={'tls':{'rejectUnauthorized':![]}};if(_0x3e8640[_0xb5be('0xf6')][_0xb5be('0xf7')]){_0xcfc71e[_0xb5be('0xf7')]=_0x3e8640['Smtp']['service'];}else{_0xcfc71e[_0xb5be('0xf8')]=_0x3e8640[_0xb5be('0xf6')][_0xb5be('0xf8')];_0xcfc71e[_0xb5be('0xf9')]=_0x3e8640[_0xb5be('0xf6')]['port'];_0xcfc71e[_0xb5be('0xfa')]=_0x3e8640[_0xb5be('0xf6')][_0xb5be('0xfa')];}if(_0x3e8640['Smtp']['authentication']){_0xcfc71e[_0xb5be('0xfb')]={'user':_0x3e8640[_0xb5be('0xf6')][_0xb5be('0x98')],'pass':_0x3e8640[_0xb5be('0xf6')][_0xb5be('0xfc')]};}return respondWithRpcPromise(_0xb5be('0xfd'),_0xb5be('0xfe'),{'account':_0xcfc71e,'message':{'from':util[_0xb5be('0xe7')](_0xb5be('0xff'),_0x3e8640[_0xb5be('0x35')],_0x3e8640[_0xb5be('0x100')]||_0x3e8640[_0xb5be('0xf6')][_0xb5be('0x98')]),'to':_0x5c236d['body'][_0xb5be('0x101')],'subject':_0xb5be('0x102'),'text':util['format']('Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a',_0x5c236d[_0xb5be('0xbc')][_0xb5be('0x101')]),'attachments':[{'path':_0x360149}]}})[_0xb5be('0x33')](function(){return _0x222e9d;})[_0xb5be('0x27')](function(_0xc631dd){console[_0xb5be('0x24')](_0xc631dd);});}else{return _0x222e9d;}})[_0xb5be('0x33')](respondWithStatusCode(_0xf9a8ea,0xc8))[_0xb5be('0x27')](handleError(_0xf9a8ea,null));};exports[_0xb5be('0x103')]=function(_0x8d8cc6,_0x4824ee,_0x15721a){return db[_0xb5be('0xe5')]['find']({'where':{'id':_0x8d8cc6[_0xb5be('0xb7')]['id']}})['then'](handleEntityNotFound(_0x4824ee,null))[_0xb5be('0x33')](function(_0x1da38a){if(_0x1da38a){return _0x1da38a[_0xb5be('0x103')](_0x8d8cc6[_0xb5be('0xbc')][_0xb5be('0x104')],_[_0xb5be('0x105')](_0x8d8cc6[_0xb5be('0xbc')],['ids','id'])||{});}})[_0xb5be('0x33')](respondWithResult(_0x4824ee,null))[_0xb5be('0x27')](handleError(_0x4824ee,null));};exports[_0xb5be('0x106')]=function(_0x25b180,_0x378823,_0x48d634){var _0x35eeb6={'raw':![],'where':{}};var _0x2db877={};var _0x267784={'count':0x0,'rows':[]};return db[_0xb5be('0x3e')]['findOne']({'where':{'id':_0x25b180[_0xb5be('0xb7')]['id']}})['then'](handleEntityNotFound(_0x378823,null))[_0xb5be('0x33')](function(_0x359e08){if(_0x359e08){_0x2db877[_0xb5be('0x42')]=_[_0xb5be('0x44')](db[_0xb5be('0xe5')][_0xb5be('0x3f')]);_0x2db877['query']=_[_0xb5be('0x44')](_0x25b180[_0xb5be('0x43')]);_0x2db877[_0xb5be('0x4c')]=_[_0xb5be('0x45')](_0x2db877[_0xb5be('0x42')],_0x2db877['query']);_0x35eeb6[_0xb5be('0x46')]=_[_0xb5be('0x45')](_0x2db877[_0xb5be('0x42')],qs[_0xb5be('0x47')](_0x25b180[_0xb5be('0x43')][_0xb5be('0x47')]));_0x35eeb6[_0xb5be('0x46')]=_0x35eeb6[_0xb5be('0x46')][_0xb5be('0x48')]?_0x35eeb6[_0xb5be('0x46')]:_0x2db877[_0xb5be('0x42')];if(!_0x25b180['query']['hasOwnProperty'](_0xb5be('0x107'))){_0x35eeb6[_0xb5be('0x2e')]=qs[_0xb5be('0x2e')](_0x25b180[_0xb5be('0x43')][_0xb5be('0x2e')]);_0x35eeb6[_0xb5be('0x2d')]=qs[_0xb5be('0x2d')](_0x25b180[_0xb5be('0x43')][_0xb5be('0x2d')]);}_0x35eeb6[_0xb5be('0x94')]=qs[_0xb5be('0x49')](_0x25b180['query'][_0xb5be('0x49')]);_0x35eeb6['where']=qs[_0xb5be('0x4c')](_['pick'](_0x25b180['query'],_0x2db877[_0xb5be('0x4c')]));_0x35eeb6[_0xb5be('0x4a')][_0xb5be('0xb3')]=_0x359e08['id'];if(_0x25b180[_0xb5be('0x43')]['filter']){_0x35eeb6[_0xb5be('0x4a')]=_[_0xb5be('0x9e')](_0x35eeb6[_0xb5be('0x4a')],{'$or':_[_0xb5be('0x38')](_0x35eeb6['attributes'],function(_0x504426){var _0x185e92={};_0x185e92[_0x504426]={'$like':'%'+_0x25b180[_0xb5be('0x43')][_0xb5be('0x88')]+'%'};return _0x185e92;})});}if(_0x25b180[_0xb5be('0x43')]['$gte']){var _0x4ceb9b=_0x25b180[_0xb5be('0x43')][_0xb5be('0x108')]['split'](',');var _0x4518c4={};_0x4518c4[_0x4ceb9b[0x0]]={'$gte':moment(_0x4ceb9b[0x1])[_0xb5be('0xe7')](_0xb5be('0x109'))};_0x35eeb6[_0xb5be('0x4a')]=_[_0xb5be('0x9e')](_0x35eeb6[_0xb5be('0x4a')],_0x4518c4);}_0x35eeb6=_[_0xb5be('0x9e')]({},_0x35eeb6,_0x25b180['options']);return db[_0xb5be('0xe5')][_0xb5be('0x2c')]({'where':_0x35eeb6[_0xb5be('0x4a')]})['then'](function(_0x441d66){_0x267784[_0xb5be('0x2c')]=_0x441d66;if(_0x25b180[_0xb5be('0x43')][_0xb5be('0xb8')]){_0x35eeb6['include']=[{'all':!![]}];}return db[_0xb5be('0xe5')][_0xb5be('0x10a')](_0x35eeb6);})[_0xb5be('0x33')](function(_0x573d68){_0x267784[_0xb5be('0xb5')]=_0x573d68;return _0x267784;});}})[_0xb5be('0x33')](respondWithFilteredResult(_0x378823,_0x35eeb6))[_0xb5be('0x27')](handleError(_0x378823,null));};exports['getMyMessages']=function(_0x252379,_0x5b684f,_0x3efde1){var _0x2ff2bf={'where':{}},_0xc34b7={},_0x54d1d4={'count':0x0,'rows':[]};return db[_0xb5be('0x3e')][_0xb5be('0xc0')]({'where':{'id':_0x252379['params']['id']}})['then'](handleEntityNotFound(_0x5b684f,null))['then'](function(_0x45695b){if(_0x45695b){_0xc34b7[_0xb5be('0x42')]=_[_0xb5be('0x44')](db[_0xb5be('0xe5')][_0xb5be('0x3f')]);_0xc34b7[_0xb5be('0x43')]=_[_0xb5be('0x44')](_0x252379[_0xb5be('0x43')]);_0xc34b7[_0xb5be('0x4c')]=_['intersection'](_0xc34b7[_0xb5be('0x42')],_0xc34b7[_0xb5be('0x43')]);_0x2ff2bf[_0xb5be('0x46')]=_['intersection'](_0xc34b7[_0xb5be('0x42')],qs[_0xb5be('0x47')](_0x252379['query'][_0xb5be('0x47')]));_0x2ff2bf[_0xb5be('0x46')]=_0x2ff2bf[_0xb5be('0x46')][_0xb5be('0x48')]?_0x2ff2bf[_0xb5be('0x46')]:_0xc34b7[_0xb5be('0x42')];if(!_0x252379['query'][_0xb5be('0x10b')](_0xb5be('0x107'))){_0x2ff2bf[_0xb5be('0x2e')]=qs[_0xb5be('0x2e')](_0x252379['query'][_0xb5be('0x2e')]);_0x2ff2bf[_0xb5be('0x2d')]=qs[_0xb5be('0x2d')](_0x252379[_0xb5be('0x43')][_0xb5be('0x2d')]);}_0x2ff2bf[_0xb5be('0x94')]=qs[_0xb5be('0x49')](_0x252379[_0xb5be('0x43')][_0xb5be('0x49')]);_0x2ff2bf[_0xb5be('0x4a')]=qs[_0xb5be('0x4c')](_[_0xb5be('0x4b')](_0x252379[_0xb5be('0x43')],_0xc34b7[_0xb5be('0x4c')]));_0x2ff2bf[_0xb5be('0x4a')][_0xb5be('0xb3')]=_0x45695b['id'];if(_0x252379[_0xb5be('0x43')][_0xb5be('0x88')]){_0x2ff2bf['where']=_[_0xb5be('0x9e')](_0x2ff2bf[_0xb5be('0x4a')],{'$or':_[_0xb5be('0x38')](_0x2ff2bf[_0xb5be('0x46')],function(_0x1837b7){var _0x3a101e={};_0x3a101e[_0x1837b7]={'$like':'%'+_0x252379[_0xb5be('0x43')][_0xb5be('0x88')]+'%'};return _0x3a101e;})});}_0x2ff2bf[_0xb5be('0x4a')][_0xb5be('0xf3')]=![];if(_0x252379['query']['id']){_0x2ff2bf['where']['id']={'$gt':_0x252379[_0xb5be('0x43')]['id']};}_0x2ff2bf=_[_0xb5be('0x9e')]({},_0x2ff2bf,_0x252379['options']);return db['ChatMessage'][_0xb5be('0x2c')]({'where':_0x2ff2bf['where']})[_0xb5be('0x33')](function(_0xc3843){_0x54d1d4[_0xb5be('0x2c')]=_0xc3843;_0x2ff2bf[_0xb5be('0xb9')]=[];if(_0x252379['query'][_0xb5be('0x10c')]){_0x2ff2bf[_0xb5be('0xb9')][_0xb5be('0x3c')]({'model':db[_0xb5be('0x6f')],'as':'User','attributes':['id',_0xb5be('0x39'),_0xb5be('0xef')]});}if(_0x252379[_0xb5be('0x43')][_0xb5be('0xb8')]){_0x2ff2bf[_0xb5be('0xb9')]=[{'all':!![]}];}return db[_0xb5be('0xe5')][_0xb5be('0x10a')](_0x2ff2bf);})[_0xb5be('0x33')](function(_0x4344b8){_0x54d1d4[_0xb5be('0xb5')]=_0x4344b8;return _0x54d1d4;});}})[_0xb5be('0x33')](respondWithFilteredResult(_0x5b684f,_0x2ff2bf))[_0xb5be('0x27')](handleError(_0x5b684f,null));};exports['addTags']=function(_0x33f586,_0x514455,_0x3607c2){return db[_0xb5be('0x3e')]['find']({'where':{'id':_0x33f586[_0xb5be('0xb7')]['id']}})[_0xb5be('0x33')](handleEntityNotFound(_0x514455,null))[_0xb5be('0x33')](function(_0x2a3176){if(_0x2a3176){return _0x2a3176['setTags'](_0x33f586['body'][_0xb5be('0x104')],_['omit'](_0x33f586[_0xb5be('0xbc')],[_0xb5be('0x104'),'id'])||{})[_0xb5be('0x10d')](function(){return db[_0xb5be('0x6d')][_0xb5be('0x10a')]({'attributes':['id',_0xb5be('0x35'),_0xb5be('0x10e')],'where':{'id':_0x33f586['body'][_0xb5be('0x104')]}});})[_0xb5be('0x33')](function(_0x1184b0){socket[_0xb5be('0x10f')]('chatInteractionTags:save',{'id':Number(_0x33f586[_0xb5be('0xb7')]['id']),'tags':_0x1184b0||[]});return{'id':Number(_0x33f586['params']['id']),'tags':_0x1184b0||[]};});}})[_0xb5be('0x33')](respondWithResult(_0x514455,null))[_0xb5be('0x27')](handleError(_0x514455,null));};exports[_0xb5be('0x110')]=function(_0x28a3b9,_0x12ba53,_0x323b00){return db[_0xb5be('0x3e')]['find']({'where':{'id':_0x28a3b9[_0xb5be('0xb7')]['id']}})['then'](handleEntityNotFound(_0x12ba53,null))[_0xb5be('0x33')](function(_0x68f992){if(_0x68f992){return _0x68f992[_0xb5be('0x110')](_0x28a3b9['query'][_0xb5be('0x104')]);}})[_0xb5be('0x33')](respondWithStatusCode(_0x12ba53,null))[_0xb5be('0x27')](handleError(_0x12ba53,null));};exports[_0xb5be('0xe0')]=function(_0x2caeae,_0x436308){var _0x4ed9c7=moment()[_0xb5be('0x111')]()['toString']();var _0x51245c=path[_0xb5be('0xdc')](config[_0xb5be('0xdd')],_0xb5be('0x112'),_0xb5be('0x113'),_0xb5be('0x114'));var _0x3efb7d=path[_0xb5be('0xdc')](config[_0xb5be('0xdd')],_0xb5be('0x112'),'files','attachments');var _0x1326f2=path[_0xb5be('0xdc')](_0x51245c,_0x4ed9c7);var _0x277895=util[_0xb5be('0xe7')](_0xb5be('0x115'),_0x2caeae[_0xb5be('0xb7')]['id'],_0x4ed9c7);var _0x313053=path['join'](_0x51245c,_0x277895);var _0x467938=[];_0x467938[_0xb5be('0x3c')]({'model':db[_0xb5be('0x6f')],'as':_0xb5be('0x6f'),'attributes':['id',_0xb5be('0x39')],'raw':!![]});_0x467938[_0xb5be('0x3c')]({'model':db['CmContact'],'as':_0xb5be('0xcd'),'attributes':['id',_0xb5be('0x116'),'lastName'],'raw':!![]});if(_0x2caeae[_0xb5be('0x43')][_0xb5be('0x117')]){_0x467938['push']({'model':db[_0xb5be('0xd8')],'as':'Attachment','raw':!![]});}var _0x2359e7=[{'model':db[_0xb5be('0xe5')],'as':_0xb5be('0xe6'),'attributes':['id',_0xb5be('0xbc'),_0xb5be('0x7b'),_0xb5be('0xf2'),_0xb5be('0xf3'),_0xb5be('0x82')],'include':_0x467938}];_0x2359e7['push']({'model':db[_0xb5be('0xc1')],'as':_0xb5be('0x118'),'attributes':['id',_0xb5be('0x35')]});_0x2359e7[_0xb5be('0x3c')]({'model':db[_0xb5be('0x6f')],'as':'Owner','attributes':['id',_0xb5be('0x39')]});return db[_0xb5be('0x3e')][_0xb5be('0x62')]({'where':{'id':_0x2caeae[_0xb5be('0xb7')]['id']},'include':_0x2359e7})[_0xb5be('0x33')](handleEntityNotFound(_0x436308,null))[_0xb5be('0x33')](function(_0x7828ce){if(_0x7828ce){var _0x1359a5=_0x7828ce[_0xb5be('0x119')]({'plain':!![]});fs['mkdirSync'](_0x1326f2);var _0x2ba3f3={'channel':_0xb5be('0x11a'),'account':_0x1359a5['Account'][_0xb5be('0x35')],'agent':_0x1359a5[_0xb5be('0x11b')]?_0x1359a5[_0xb5be('0x11b')][_0xb5be('0x39')]:_0xb5be('0x11c'),'createdAt':moment(_0x1359a5[_0xb5be('0x7b')])['format'](_0xb5be('0x109'))[_0xb5be('0x9c')](),'closedAt':_0x1359a5[_0xb5be('0xd0')]?moment(_0x1359a5[_0xb5be('0x11d')])[_0xb5be('0xe7')]('YYYY-MM-DD\x20HH:mm:ss')[_0xb5be('0x9c')]():'','disposition':_0x1359a5[_0xb5be('0xd1')],'chatInfo':{'browser':_0x1359a5['browserName'],'os':_0x1359a5[_0xb5be('0x11e')],'referer':_0x1359a5[_0xb5be('0x11f')],'customerIp':_0x1359a5[_0xb5be('0x120')],'customerPort':_0x1359a5[_0xb5be('0x121')]?_0x1359a5[_0xb5be('0x121')]:_0xb5be('0x11c')},'messages':_(_0x1359a5[_0xb5be('0xe6')])[_0xb5be('0x122')]()[_0xb5be('0x88')]({'secret':![]})['map'](function(_0x56ba91){if(_0x56ba91[_0xb5be('0xd8')]){var _0x47f814=path[_0xb5be('0xdc')](_0x3efb7d,_0x56ba91[_0xb5be('0xd8')][_0xb5be('0xd4')]);if(fs[_0xb5be('0x123')](_0x47f814)){fs[_0xb5be('0x124')](_0x47f814)[_0xb5be('0x125')](fs[_0xb5be('0x126')](path[_0xb5be('0xdc')](_0x1326f2,_0x56ba91[_0xb5be('0xd8')][_0xb5be('0xd4')])));}}return{'date':moment(_0x56ba91[_0xb5be('0x7b')])[_0xb5be('0xe7')](_0xb5be('0x109'))[_0xb5be('0x9c')](),'sender':_0x56ba91[_0xb5be('0xf2')]==='out'?_0x56ba91[_0xb5be('0x6f')]?_0x56ba91[_0xb5be('0x6f')][_0xb5be('0x39')]:'System':_0x56ba91[_0xb5be('0xcd')]['firstName']+(_0x56ba91[_0xb5be('0xcd')][_0xb5be('0x127')]?'\x20'+_0x56ba91[_0xb5be('0xcd')]['lastName']:''),'body':_0x56ba91[_0xb5be('0xd8')]?_0x56ba91['Attachment'][_0xb5be('0xd4')]:_0x56ba91[_0xb5be('0xbc')],'direction':_0x56ba91[_0xb5be('0xf2')]===_0xb5be('0xc9')?'A':'C','secret':_0x56ba91['secret'],'read':_0x56ba91[_0xb5be('0x82')],'attachment':_0x56ba91[_0xb5be('0xd8')]};})[_0xb5be('0x63')]()};return ejs[_0xb5be('0x128')](path[_0xb5be('0xdc')](config[_0xb5be('0xdd')],_0xb5be('0x112'),_0xb5be('0x129'),_0xb5be('0x12a')),{'interaction':_0x2ba3f3})['then'](function(_0xe4652f){var _0x9431a5=path[_0xb5be('0xdc')](_0x1326f2,'transcript-'+_0x1359a5['id']+'-'+_0x4ed9c7+_0xb5be('0x12b'));var _0x5dca47={'path':_0x9431a5,'channel':_0xb5be('0x11a'),'interactionId':_0x1359a5['id']};return pdf['createPdfFromHTML'](_0xe4652f,_0x5dca47);})[_0xb5be('0x33')](function(){return new BPromise(function(_0x399ac6,_0x52a6ea){zipdir(_0x1326f2,{'saveTo':_0x313053},function(_0x3f941b,_0x1e3784){if(_0x3f941b)return _0x52a6ea(_0x3f941b);return _0x399ac6(_0x1e3784);});})[_0xb5be('0x33')](function(){return new BPromise(function(_0x43b32c,_0x1ab2a1){rimraf(_0x1326f2,function(_0x5374b3){if(_0x5374b3)_0x1ab2a1(_0x5374b3);return _0x43b32c();});});})['then'](function(){return _0x436308['download'](_0x313053,_0x277895,function(_0xe7e31c){if(_0xe7e31c){console[_0xb5be('0x12c')](_0xb5be('0x12d'),_0xe7e31c);}else{fs['unlinkSync'](_0x313053);}});});});}else{return _0x436308[_0xb5be('0x28')](0xc8);}})[_0xb5be('0x27')](handleError(_0x436308,null));};
\ No newline at end of file