Built motion from commit e02f907f.|2.6.14
[motion2.git] / server / api / chatInteraction / chatInteraction.controller.js
index 1f77047..9ce65b0 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x6c76=['email','isNull','follow','Sequelize','Error\x20in\x20Vidaoo\x20configuration','out','ChatMessage','updateAttributes','customUpdate','abandon','entity\x20not\x20found','Interaction\x20already\x20assigned','AbandonInteraction','attachmentUpload','file','originalname','basename','filename','mimetype','Attachment','attachmentDownload','Unauthorized','attachId','ChatOfflineMessageId','join','server/files/attachments/','offline-chat/','download','close','mailTranscript','root','server/files/chat/upload/','format','CmContact','Messages','%s%d','System','website_alias','agentAlias','agent_alias','alias','[%s]\x20%s:\x20%s\x0a','MM/DD/YYYY\x20HH:mm:ss','direction','secret','MailAccount','MailServerOut','CloudProvider','Smtp','getSmtpOptions','SendMail','sendMail','Mail\x20Transcript','addMessage','ids','omit','getMessages','filters','$gte','YYYY-MM-DD\x20HH:mm:ss','options','findAll','getMyMessages','includeAgent','addTags','setTags','spread','chatInteractionTags:save','removeTags','server','files','tmp','transcript-%d-%s.zip','lastName','attachments','Account','Owner','mkdirSync','Chat','N.A.','closedAt','disposition','browserName','osName','referer','customerIp','customerPort','tail','existsSync','createReadStream','createWriteStream','downloadInteraction.ejs','transcript-','.pdf','createPdfFromHTML','rimraf','zip-dir','request-promise','bluebird','mustache','ejs','lodash','ioredis','../../components/parsers/qs','../../components/export/pdf','../../config/environment','../../mysqldb','redis','localhost','socket.io-emitter','register','jayson/promise','client','http','request','then','info','request\x20sent','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','message','ChatInteraction,\x20%s,\x20%s','result','catch','sendStatus','status','end','json','undefined','offset','count','limit','set','Content-Range','update','destroy','stack','name','send','render','contact','agent','interaction','account','Users','map','fullname','TagIds','split','forEach','waiting','talking','answered','unmanaged','abandoned','total','closed','UserId','index','ChatInteraction','rawAttributes','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','select','field','color','from','tools_tags','u.id','ui.ChatInteractionId','users','chat_interactions','left_join','cm_contacts','o.id\x20=\x20i.UserId','a.id\x20=\x20i.ChatWebsiteId','chat_messages','me.ChatInteractionId\x20=\x20i.id','chat_interaction_has_tags','t.id\x20=\x20it.TagId','expr','parseSearch','search','sqlOperator','conditions','find','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','operator','$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','ContactId','buildExpression','text','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','body','some','compact','isEmpty','ChatWebsiteId','i.ChatWebsiteId\x20IN\x20?','concat','createdAt','parse','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','isNumeric','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','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','t.id\x20IN\x20?','resolve','i.ChatWebsiteId\x20IS\x20NOT\x20NULL','user','role','getChatWebsites','i.ChatWebsiteId\x20IS\x20NULL','sequelize','toString','keyBy','merge','a.key','a.mandatoryDisposition','Account.mandatoryDisposition','c.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','Contact.phone','c.mobile','c.fax','o.fullname','Owner.fullname','o.internal','ChatInteractionId','push','all','rows','show','params','includeAll','include','create','describe','findOne','ChatWebsite','vidaooApiKey','vidaooEscalation','vidaooTopic','vidaooNote','vidaooMetadata','https://api-vidaoo.xcally.com/api/v1/meetings'];(function(_0x2cf2bc,_0x3558ad){var _0x4323bd=function(_0xb69d06){while(--_0xb69d06){_0x2cf2bc['push'](_0x2cf2bc['shift']());}};_0x4323bd(++_0x3558ad);}(_0x6c76,0x184));var _0x66c7=function(_0x14532a,_0x22376a){_0x14532a=_0x14532a-0x0;var _0x135ee3=_0x6c76[_0x14532a];return _0x135ee3;};'use strict';var rimraf=require(_0x66c7('0x0'));var zipdir=require(_0x66c7('0x1'));var rp=require(_0x66c7('0x2'));var moment=require('moment');var BPromise=require(_0x66c7('0x3'));var Mustache=require(_0x66c7('0x4'));var util=require('util');var path=require('path');var ejs=require(_0x66c7('0x5'));var fs=require('fs');var _=require(_0x66c7('0x6'));var squel=require('squel');var Redis=require(_0x66c7('0x7'));var qs=require(_0x66c7('0x8'));var as=require('../../components/parsers/advancedSearch');var pdf=require(_0x66c7('0x9'));var logger=require('../../config/logger')('api');var config=require(_0x66c7('0xa'));var db=require(_0x66c7('0xb'))['db'];config[_0x66c7('0xc')]=_['defaults'](config[_0x66c7('0xc')],{'host':_0x66c7('0xd'),'port':0x18eb});var socket=require(_0x66c7('0xe'))(new Redis(config[_0x66c7('0xc')]));require('./chatInteraction.socket')[_0x66c7('0xf')](socket);var jayson=require(_0x66c7('0x10'));var client=jayson[_0x66c7('0x11')][_0x66c7('0x12')]({'port':0x232b});var client9004=jayson[_0x66c7('0x11')][_0x66c7('0x12')]({'port':0x232c});function respondWithRpcPromise(_0x174717,_0x5176a3,_0x18c309,_0x760e36){return new BPromise(function(_0x35cbc2,_0xea3f56){var _0x4f6c91=_0x760e36||client;return _0x4f6c91[_0x66c7('0x13')](_0x174717,_0x18c309)[_0x66c7('0x14')](function(_0xf3b04){logger[_0x66c7('0x15')]('ChatInteraction,\x20%s,\x20%s',_0x5176a3,_0x66c7('0x16'));logger['debug'](_0x66c7('0x17'),_0x5176a3,_0x66c7('0x16'),JSON[_0x66c7('0x18')](_0xf3b04));if(_0xf3b04[_0x66c7('0x19')]){if(_0xf3b04[_0x66c7('0x19')]['code']===0x1f4){logger['error']('ChatInteraction,\x20%s,\x20%s',_0x5176a3,_0xf3b04['error'][_0x66c7('0x1a')]);return _0xea3f56(_0xf3b04[_0x66c7('0x19')]['message']);}logger['error'](_0x66c7('0x1b'),_0x5176a3,_0xf3b04[_0x66c7('0x19')][_0x66c7('0x1a')]);return _0x35cbc2(_0xf3b04[_0x66c7('0x19')]['message']);}else{logger['info'](_0x66c7('0x1b'),_0x5176a3,_0x66c7('0x16'));_0x35cbc2(_0xf3b04[_0x66c7('0x1c')][_0x66c7('0x1a')]);}})[_0x66c7('0x1d')](function(_0x75f118){logger['error'](_0x66c7('0x1b'),_0x5176a3,_0x75f118);_0xea3f56(_0x75f118);});});}function respondWithStatusCode(_0x366e9b,_0x4a2b90){_0x4a2b90=_0x4a2b90||0xcc;return function(_0x7462f1){if(_0x7462f1){return _0x366e9b[_0x66c7('0x1e')](_0x4a2b90);}return _0x366e9b[_0x66c7('0x1f')](_0x4a2b90)[_0x66c7('0x20')]();};}function respondWithResult(_0x5bfaf6,_0x2736df){_0x2736df=_0x2736df||0xc8;return function(_0x42ca37){if(_0x42ca37){return _0x5bfaf6['status'](_0x2736df)[_0x66c7('0x21')](_0x42ca37);}};}function respondWithFilteredResult(_0x11a6b9,_0x2bb86d){return function(_0x2ef6a2){if(_0x2ef6a2){var _0x2af0a3=typeof _0x2bb86d['offset']==='undefined'&&typeof _0x2bb86d['limit']===_0x66c7('0x22');var _0x542ff1=_0x2ef6a2['count'];var _0x9afd50=_0x2af0a3?0x0:_0x2bb86d[_0x66c7('0x23')];var _0x205b7e=_0x2af0a3?_0x2ef6a2[_0x66c7('0x24')]:_0x2bb86d[_0x66c7('0x23')]+_0x2bb86d[_0x66c7('0x25')];var _0x570f0d;if(_0x205b7e>=_0x542ff1){_0x205b7e=_0x542ff1;_0x570f0d=0xc8;}else{_0x570f0d=0xce;}_0x11a6b9[_0x66c7('0x1f')](_0x570f0d);return _0x11a6b9[_0x66c7('0x26')](_0x66c7('0x27'),_0x9afd50+'-'+_0x205b7e+'/'+_0x542ff1)[_0x66c7('0x21')](_0x2ef6a2);}return null;};}function saveUpdates(_0x2042ea){return function(_0x592f0e){if(_0x592f0e){return _0x592f0e[_0x66c7('0x28')](_0x2042ea)['then'](function(_0xfbd97){return _0xfbd97;});}return null;};}function removeEntity(_0x543fbf){return function(_0x296875){if(_0x296875){return _0x296875[_0x66c7('0x29')]()[_0x66c7('0x14')](function(){_0x543fbf[_0x66c7('0x1f')](0xcc)[_0x66c7('0x20')]();});}};}function handleEntityNotFound(_0x24e776){return function(_0x559ab9){if(!_0x559ab9){_0x24e776['sendStatus'](0x194);}return _0x559ab9;};}function handleError(_0x367e49,_0x12e7c6){_0x12e7c6=_0x12e7c6||0x1f4;return function(_0x827cbc){logger[_0x66c7('0x19')](_0x827cbc[_0x66c7('0x2a')]);if(_0x827cbc[_0x66c7('0x2b')]){delete _0x827cbc[_0x66c7('0x2b')];}_0x367e49[_0x66c7('0x1f')](_0x12e7c6)[_0x66c7('0x2c')](_0x827cbc);};}function getMustacheRender(_0x301495,_0x1fd460){return Mustache[_0x66c7('0x2d')](_0x301495,_['merge'](_0x1fd460['body'],{'contact':_0x1fd460[_0x66c7('0x2e')],'message':_0x1fd460[_0x66c7('0x1a')],'agent':_0x1fd460[_0x66c7('0x2f')],'interaction':_0x1fd460[_0x66c7('0x30')],'account':_0x1fd460[_0x66c7('0x31')]}))||'';}function getInteractionUsers(_0x2bf7c2,_0x21d0d3){return new BPromise(function(_0x5503c3,_0x30b90f){try{if(_0x21d0d3[_0x2bf7c2['id']]){_0x2bf7c2[_0x66c7('0x32')]=_[_0x66c7('0x33')](_0x21d0d3[_0x2bf7c2['id']],function(_0xd9e0f5){return{'id':_0xd9e0f5['id'],'fullname':_0xd9e0f5[_0x66c7('0x34')]};});}}catch(_0x324696){_0x30b90f(_0x324696);}_0x5503c3(_0x2bf7c2);});}function getInteractionTags(_0x3c8638,_0x2b3ac1){return new BPromise(function(_0x175ee7,_0x274c45){try{if(_0x3c8638[_0x66c7('0x35')]){_0x3c8638['Tags']=[];_0x3c8638['TagIds'][_0x66c7('0x36')](',')[_0x66c7('0x37')](function(_0xc63941){_0x3c8638['Tags']['push'](_0x2b3ac1[_0xc63941]);});}delete _0x3c8638[_0x66c7('0x35')];}catch(_0x96a1f5){_0x274c45(_0x96a1f5);}_0x175ee7(_0x3c8638);});}function updateChatInteraction(_0x501771,_0x2d98e4,_0x6e9796){return new BPromise(function(_0x34acf0,_0x51c92b){return getInteractionUsers(_0x501771,_0x6e9796)[_0x66c7('0x14')](function(_0x16b754){return getInteractionTags(_0x16b754,_0x2d98e4);})[_0x66c7('0x14')](function(_0x14d59c){return getStateInteraction(_0x14d59c);})[_0x66c7('0x14')](function(_0x1903fd){_0x34acf0(_0x1903fd);})[_0x66c7('0x1d')](function(_0x279d27){_0x51c92b(_0x279d27);});});}function getStateInteraction(_0x28ffe9){return new BPromise(function(_0x5f34ed){_0x28ffe9[_0x66c7('0x38')]=0x0;_0x28ffe9[_0x66c7('0x39')]=0x0;_0x28ffe9[_0x66c7('0x3a')]=0x0;_0x28ffe9[_0x66c7('0x3b')]=0x0;_0x28ffe9[_0x66c7('0x3c')]=0x0;_0x28ffe9[_0x66c7('0x3d')]=0x0;if(!_0x28ffe9[_0x66c7('0x3e')]&&!_0x28ffe9[_0x66c7('0x3f')]){_0x28ffe9[_0x66c7('0x38')]+=0x1;}if(!_0x28ffe9[_0x66c7('0x3e')]&&_0x28ffe9['UserId']){_0x28ffe9['talking']+=0x1;if(_0x28ffe9['waiting']){_0x28ffe9[_0x66c7('0x38')]-=0x1;}}if(_0x28ffe9[_0x66c7('0x3e')]&&_0x28ffe9['disposition']==='abandoned'){_0x28ffe9[_0x66c7('0x3c')]+=0x1;if(_0x28ffe9[_0x66c7('0x38')]){_0x28ffe9[_0x66c7('0x38')]-=0x1;}}else if(_0x28ffe9[_0x66c7('0x3e')]&&!_0x28ffe9[_0x66c7('0x3f')]&&_0x28ffe9['disposition']){_0x28ffe9[_0x66c7('0x3b')]+=0x1;if(_0x28ffe9['waiting']){_0x28ffe9['waiting']-=0x1;}}else if(_0x28ffe9[_0x66c7('0x3e')]&&_0x28ffe9[_0x66c7('0x3f')]){_0x28ffe9[_0x66c7('0x3a')]+=0x1;if(_0x28ffe9[_0x66c7('0x39')]){_0x28ffe9['talking']-=0x1;}}_0x28ffe9['total']+=0x1;_0x5f34ed(_0x28ffe9);});}exports[_0x66c7('0x40')]=function(_0x52506a,_0x4e0c89){var _0x1ec272={},_0x230f28={},_0x2b89e1={'count':0x0,'rows':[]};var _0x18408d=_['map'](db[_0x66c7('0x41')][_0x66c7('0x42')],function(_0x2c8ffe){return{'name':_0x2c8ffe['fieldName'],'type':_0x2c8ffe[_0x66c7('0x43')][_0x66c7('0x44')]};});_0x230f28[_0x66c7('0x45')]=_[_0x66c7('0x33')](_0x18408d,_0x66c7('0x2b'));_0x230f28[_0x66c7('0x46')]=_[_0x66c7('0x47')](_0x52506a[_0x66c7('0x46')]);_0x230f28['filters']=_[_0x66c7('0x48')](_0x230f28[_0x66c7('0x45')],_0x230f28[_0x66c7('0x46')]);_0x1ec272[_0x66c7('0x49')]=_[_0x66c7('0x48')](_0x230f28[_0x66c7('0x45')],qs[_0x66c7('0x4a')](_0x52506a[_0x66c7('0x46')][_0x66c7('0x4a')]));_0x1ec272[_0x66c7('0x49')]=_0x1ec272[_0x66c7('0x49')][_0x66c7('0x4b')]?_0x1ec272[_0x66c7('0x49')]:_0x230f28[_0x66c7('0x45')];if(!_0x52506a['query'][_0x66c7('0x4c')](_0x66c7('0x4d'))){_0x1ec272[_0x66c7('0x25')]=qs[_0x66c7('0x25')](_0x52506a['query'][_0x66c7('0x25')]);_0x1ec272[_0x66c7('0x23')]=qs['offset'](_0x52506a[_0x66c7('0x46')][_0x66c7('0x23')]);}_0x1ec272[_0x66c7('0x4e')]=qs[_0x66c7('0x4f')](_0x52506a[_0x66c7('0x46')][_0x66c7('0x4f')]);_0x1ec272[_0x66c7('0x50')]=qs['filters'](_[_0x66c7('0x51')](_0x52506a[_0x66c7('0x46')],_0x230f28['filters']),_0x18408d);var _0x127dfe=[];var _0x2617af=squel[_0x66c7('0x52')]()['field']('id')[_0x66c7('0x53')](_0x66c7('0x2b'))[_0x66c7('0x53')](_0x66c7('0x54'))[_0x66c7('0x55')](_0x66c7('0x56'));var _0x1d8313=squel[_0x66c7('0x52')]()['field'](_0x66c7('0x57'))[_0x66c7('0x53')]('u.fullname')[_0x66c7('0x53')](_0x66c7('0x58'))[_0x66c7('0x55')]('user_has_chat_interactions','ui')['left_join'](_0x66c7('0x59'),'u','u.id\x20=\x20ui.UserId');var _0x3c8fd9=squel[_0x66c7('0x52')]()[_0x66c7('0x55')](_0x66c7('0x5a'),'i')[_0x66c7('0x5b')](_0x66c7('0x5c'),'c','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL')['left_join'](_0x66c7('0x59'),'o',_0x66c7('0x5d'))['left_join']('chat_websites','a',_0x66c7('0x5e'))['left_join'](_0x66c7('0x5f'),'me',_0x66c7('0x60'))[_0x66c7('0x5b')](_0x66c7('0x61'),'it','it.ChatInteractionId\x20=\x20i.id')[_0x66c7('0x5b')](_0x66c7('0x56'),'t',_0x66c7('0x62'));var _0x2659f5=squel[_0x66c7('0x63')]();var _0x137c4f=[];var _0x4ec465=squel[_0x66c7('0x63')]();var _0x39c18e;if(_0x52506a[_0x66c7('0x46')]['search']){_0x39c18e=as[_0x66c7('0x64')](_0x52506a['query'][_0x66c7('0x65')]);var _0x45f5de=_0x39c18e[_0x66c7('0x66')];for(var _0x445af1=0x0;_0x445af1<_0x39c18e[_0x66c7('0x67')][_0x66c7('0x4b')];_0x445af1++){var _0x4b36d2=_0x39c18e[_0x66c7('0x67')][_0x445af1];var _0x2fc1c6='i';var _0x2d9069=_[_0x66c7('0x68')](_0x18408d,[_0x66c7('0x2b'),_0x4b36d2['field']]);if(!_0x2d9069){switch(_0x4b36d2[_0x66c7('0x53')]){case _0x66c7('0x69'):if(_0x4b36d2[_0x66c7('0x6a')]==0x1){_0x3c8fd9[_0x66c7('0x6b')]('`'+_0x4b36d2[_0x66c7('0x53')]+_0x66c7('0x6c'));}else{_0x3c8fd9[_0x66c7('0x6b')]('`'+_0x4b36d2[_0x66c7('0x53')]+_0x66c7('0x6d'));}break;case _0x66c7('0x6e'):if(_0x4b36d2[_0x66c7('0x6f')]===_0x66c7('0x70')){if(_0x4b36d2['value'][_0x66c7('0x36')]('\x20')[_0x66c7('0x4b')]>0x1){_0x2659f5[_0x45f5de](_0x66c7('0x71'),qs[_0x66c7('0x72')](_0x4b36d2[_0x66c7('0x6a')]),null);}else{var _0x419b49='%'+_0x4b36d2[_0x66c7('0x6a')]+'%';_0x2659f5[_0x45f5de]('c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?',_0x419b49,_0x419b49,_0x419b49);}}else{_0x2d9069=_[_0x66c7('0x68')](_0x18408d,[_0x66c7('0x2b'),_0x66c7('0x73')]);_0x4b36d2[_0x66c7('0x53')]=_0x66c7('0x73');_0xd0f389=as[_0x66c7('0x74')](_0x2fc1c6,_0x2d9069[_0x66c7('0x43')],_0x4b36d2);_0x2659f5[_0x45f5de](_0xd0f389[_0x66c7('0x75')],_0xd0f389[_0x66c7('0x6a')][_0x66c7('0x76')],_0xd0f389[_0x66c7('0x6a')][_0x66c7('0x20')]);}break;case _0x66c7('0x77'):var _0x1112ec=_0x4b36d2[_0x66c7('0x6a')][_0x66c7('0x36')](',')['map'](function(_0x16d404){return Number(_0x16d404);});_0x1112ec[_0x66c7('0x37')](function(_0x43a623){_0x4ec465['or'](_0x66c7('0x78'),'%,'+_0x43a623+',%');});_0x137c4f=_[_0x66c7('0x79')](_0x137c4f,_0x1112ec);break;case _0x66c7('0x7a'):if(_0x4b36d2[_0x66c7('0x6f')]===_0x66c7('0x70')){_0x2659f5[_0x45f5de](_0x66c7('0x7b'),'%'+_0x4b36d2[_0x66c7('0x6a')]+'%',null);}else{_0x2d9069=_[_0x66c7('0x68')](_0x18408d,[_0x66c7('0x2b'),_0x66c7('0x3f')]);_0x4b36d2[_0x66c7('0x53')]=_0x66c7('0x3f');_0xd0f389=as[_0x66c7('0x74')](_0x2fc1c6,_0x2d9069[_0x66c7('0x43')],_0x4b36d2);_0x2659f5[_0x45f5de](_0xd0f389['text'],_0xd0f389[_0x66c7('0x6a')][_0x66c7('0x76')],_0xd0f389[_0x66c7('0x6a')][_0x66c7('0x20')]);}break;case _0x66c7('0x7c'):_0xd0f389=as[_0x66c7('0x74')]('me',null,_0x4b36d2);_0x2659f5[_0x45f5de](_0xd0f389['text'],_0xd0f389['value'][_0x66c7('0x76')],_0xd0f389['value'][_0x66c7('0x20')]);break;}}else{var _0xd0f389=as[_0x66c7('0x74')](_0x2fc1c6,_0x2d9069[_0x66c7('0x43')],_0x4b36d2);_0x2659f5[_0x45f5de](_0xd0f389[_0x66c7('0x75')],_0xd0f389[_0x66c7('0x6a')][_0x66c7('0x76')],_0xd0f389[_0x66c7('0x6a')][_0x66c7('0x20')]);}}}else{var _0x35ad88=_(_0x52506a[_0x66c7('0x46')])[_0x66c7('0x47')]()['map'](function(_0x25f193){return _[_0x66c7('0x7d')](_0x18408d,[_0x66c7('0x2b'),_0x25f193])?_0x25f193:undefined;})[_0x66c7('0x7e')]()['value']();if(!_[_0x66c7('0x7f')](_0x35ad88)){_0x35ad88[_0x66c7('0x37')](function(_0x4e0a54){if(_0x4e0a54===_0x66c7('0x80')){_0x3c8fd9[_0x66c7('0x50')](_0x66c7('0x81'),[][_0x66c7('0x82')](_0x52506a[_0x66c7('0x46')][_0x4e0a54]));}else if(_0x4e0a54===_0x66c7('0x83')){var _0x580212=JSON['parse'](_0x52506a[_0x66c7('0x46')][_0x4e0a54])['$gte'];var _0x570a63=JSON[_0x66c7('0x84')](_0x52506a[_0x66c7('0x46')][_0x4e0a54])[_0x66c7('0x85')];_0x3c8fd9[_0x66c7('0x50')](_0x66c7('0x86'),_0x580212,_0x570a63);}else{if(_0x52506a[_0x66c7('0x46')][_0x4e0a54]===_0x66c7('0x87')){_0x3c8fd9[_0x66c7('0x50')]('i.'+_0x4e0a54+'\x20IS\x20NULL');}else{_0x3c8fd9[_0x66c7('0x50')]('i.'+_0x4e0a54+_0x66c7('0x88'),_0x52506a[_0x66c7('0x46')][_0x4e0a54]);}}});}if(_0x52506a[_0x66c7('0x46')][_0x66c7('0x89')]){if(_0x52506a[_0x66c7('0x46')][_0x66c7('0x89')]==0x1){_0x3c8fd9[_0x66c7('0x6b')](_0x66c7('0x8a'));}else{_0x3c8fd9[_0x66c7('0x6b')](_0x66c7('0x8b'));}}if(_0x52506a[_0x66c7('0x46')][_0x66c7('0x8c')]){_0x137c4f=_[_0x66c7('0x8d')](_0x52506a[_0x66c7('0x46')][_0x66c7('0x8c')])?_0x52506a[_0x66c7('0x46')][_0x66c7('0x8c')]:new Array(_0x52506a[_0x66c7('0x46')][_0x66c7('0x8c')]);_0x137c4f[_0x66c7('0x37')](function(_0x379dc4){_0x4ec465['or'](_0x66c7('0x78'),'%,'+_0x379dc4+',%');});}if(_0x52506a[_0x66c7('0x46')][_0x66c7('0x8e')]){var _0x46d569=_0x52506a[_0x66c7('0x46')]['filter'][_0x66c7('0x8f')]('\x5c','\x5c\x5c')[_0x66c7('0x8f')](/'/g,'\x27\x27');if(qs[_0x66c7('0x90')](_0x46d569)){_0x2659f5['or']('i.id\x20LIKE\x20?',_0x46d569+'%');}else{_0x2659f5['or'](_0x66c7('0x91'),qs[_0x66c7('0x72')](_0x46d569))['or'](_0x66c7('0x92'),_0x46d569+'%');}}}_0x3c8fd9['where'](_0x2659f5);_0x3c8fd9[_0x66c7('0x93')](_0x66c7('0x94'));var _0x3abd74={'type':db['Sequelize'][_0x66c7('0x95')][_0x66c7('0x96')],'raw':!![]};var _0x280cdc=_0x3c8fd9[_0x66c7('0x97')]();_0x280cdc['field'](_0x66c7('0x94'));_0x280cdc[_0x66c7('0x53')](_0x66c7('0x98'),_0x66c7('0x69'));if(_0x1ec272['order']){_0x1ec272['order'][_0x66c7('0x37')](function(_0x2f3f75){var _0x45ccdf=_0x2f3f75[0x0]===_0x66c7('0x99')?_0x2f3f75[0x0]:'i.'+_0x2f3f75[0x0];_0x3c8fd9[_0x66c7('0x4e')](_0x45ccdf,_0x2f3f75[0x1]==='DESC'?![]:!![]);});}if(!_[_0x66c7('0x7f')](_0x137c4f)){_0x3c8fd9[_0x66c7('0x6b')](_0x4ec465);_0x280cdc[_0x66c7('0x50')](_0x66c7('0x9a'),_0x137c4f);}BPromise[_0x66c7('0x9b')]()['then'](function(){if(!_0x39c18e){if(_0x52506a[_0x66c7('0x46')][_0x66c7('0x80')])return;_0x280cdc[_0x66c7('0x50')](_0x66c7('0x9c'));_0x3c8fd9[_0x66c7('0x50')](_0x66c7('0x9c'));return;}if(_0x52506a[_0x66c7('0x9d')][_0x66c7('0x9e')]!=='agent')return;return _0x52506a[_0x66c7('0x9d')][_0x66c7('0x9f')]({'attributes':['id'],'raw':!![]})[_0x66c7('0x14')](function(_0x574e42){if(_[_0x66c7('0x7f')](_0x574e42)){_0x280cdc[_0x66c7('0x50')](_0x66c7('0xa0'));_0x3c8fd9[_0x66c7('0x50')](_0x66c7('0xa0'));}else{_0x280cdc[_0x66c7('0x50')](_0x66c7('0x81'),_[_0x66c7('0x33')](_0x574e42,'id'));_0x3c8fd9['where'](_0x66c7('0x81'),_[_0x66c7('0x33')](_0x574e42,'id'));}});})[_0x66c7('0x14')](function(){if(_0x52506a[_0x66c7('0x9d')][_0x66c7('0x9e')]===_0x66c7('0x2f')&&!_0x39c18e&&!_0x52506a['query'][_0x66c7('0x80')])return[];return db[_0x66c7('0xa1')][_0x66c7('0x46')](_0x280cdc[_0x66c7('0xa2')](),_0x3abd74);})[_0x66c7('0x14')](function(_0x14608f){_0x2b89e1[_0x66c7('0x24')]=_0x14608f[_0x66c7('0x4b')];if(_0x2b89e1['count']===0x0)return[];return db[_0x66c7('0xa1')][_0x66c7('0x46')](_0x2617af[_0x66c7('0xa2')](),_0x3abd74)['then'](function(_0x176d9d){_0x127dfe=_[_0x66c7('0xa3')](_0x176d9d,'id');_0x3abd74=_[_0x66c7('0xa4')](_0x3abd74,{'model':db[_0x66c7('0x41')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x52506a[_0x66c7('0x46')][_0x66c7('0x4a')]){_0x1ec272[_0x66c7('0x49')]['forEach'](function(_0x315996){_0x3c8fd9['field']('i.'+_0x315996);});}else{_0x3c8fd9['field']('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages');_0x3c8fd9[_0x66c7('0x53')](_0x66c7('0xa5'),'Account.key');_0x3c8fd9['field'](_0x66c7('0xa6'),_0x66c7('0xa7'));_0x3c8fd9['field']('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',_0x66c7('0x99'));_0x3c8fd9['field']('i.*');_0x3c8fd9[_0x66c7('0x53')](_0x66c7('0xa8'),'Contact.firstName');_0x3c8fd9[_0x66c7('0x53')](_0x66c7('0xa9'),_0x66c7('0xaa'));_0x3c8fd9[_0x66c7('0x53')](_0x66c7('0xab'),_0x66c7('0xac'));_0x3c8fd9[_0x66c7('0x53')](_0x66c7('0xad'),_0x66c7('0xae'));_0x3c8fd9['field'](_0x66c7('0xaf'),'Contact.mobile');_0x3c8fd9[_0x66c7('0x53')](_0x66c7('0xb0'),'Contact.fax');_0x3c8fd9[_0x66c7('0x53')](_0x66c7('0xb1'),_0x66c7('0xb2'));_0x3c8fd9[_0x66c7('0x53')](_0x66c7('0xb3'),'Owner.internal');_0x3c8fd9[_0x66c7('0x53')]('GROUP_CONCAT(DISTINCT\x20t.id)',_0x66c7('0x35'));}if(_0x1ec272[_0x66c7('0x25')])_0x3c8fd9[_0x66c7('0x25')](_0x1ec272[_0x66c7('0x25')]);if(_0x1ec272[_0x66c7('0x23')])_0x3c8fd9[_0x66c7('0x23')](_0x1ec272[_0x66c7('0x23')]);return db['sequelize']['query'](_0x3c8fd9[_0x66c7('0xa2')](),_0x3abd74);})['then'](function(_0x4daa4e){if(_0x4daa4e['length']>0x0)_0x1d8313[_0x66c7('0x50')]('ui.ChatInteractionId\x20IN\x20?',_[_0x66c7('0x33')](_0x4daa4e,'id'));return db[_0x66c7('0xa1')][_0x66c7('0x46')](_0x1d8313['toString'](),_0x3abd74)[_0x66c7('0x14')](function(_0x5376d7){var _0x18f1d6=_['groupBy'](_0x5376d7,_0x66c7('0xb4'));var _0x248b31=[];_0x4daa4e[_0x66c7('0x37')](function(_0x3c8c2b){_0x248b31[_0x66c7('0xb5')](updateChatInteraction(_0x3c8c2b,_0x127dfe,_0x18f1d6));});return BPromise[_0x66c7('0xb6')](_0x248b31);});});})[_0x66c7('0x14')](function(_0x488f98){_0x2b89e1[_0x66c7('0xb7')]=_0x488f98;return _0x2b89e1;})['then'](respondWithFilteredResult(_0x4e0c89,_0x1ec272))['catch'](handleError(_0x4e0c89,null));};exports[_0x66c7('0xb8')]=function(_0xa18dfb,_0x12ee9f){var _0x44bbf2={'raw':![],'where':{'id':_0xa18dfb[_0x66c7('0xb9')]['id']}},_0x2cecc4={};_0x2cecc4[_0x66c7('0x45')]=_[_0x66c7('0x47')](db[_0x66c7('0x41')][_0x66c7('0x42')]);_0x2cecc4[_0x66c7('0x46')]=_[_0x66c7('0x47')](_0xa18dfb[_0x66c7('0x46')]);_0x2cecc4['filters']=_[_0x66c7('0x48')](_0x2cecc4['model'],_0x2cecc4[_0x66c7('0x46')]);_0x44bbf2[_0x66c7('0x49')]=_[_0x66c7('0x48')](_0x2cecc4[_0x66c7('0x45')],qs[_0x66c7('0x4a')](_0xa18dfb[_0x66c7('0x46')]['fields']));_0x44bbf2['attributes']=_0x44bbf2['attributes']['length']?_0x44bbf2['attributes']:_0x2cecc4[_0x66c7('0x45')];if(_0xa18dfb[_0x66c7('0x46')][_0x66c7('0xba')]){_0x44bbf2[_0x66c7('0xbb')]=[{'all':!![]}];}_0x44bbf2=_['merge']({},_0x44bbf2,_0xa18dfb['options']);return db[_0x66c7('0x41')][_0x66c7('0x68')](_0x44bbf2)['then'](handleEntityNotFound(_0x12ee9f,null))[_0x66c7('0x14')](respondWithResult(_0x12ee9f,null))[_0x66c7('0x1d')](handleError(_0x12ee9f,null));};exports['create']=function(_0x16965c,_0x2dfe01){return db[_0x66c7('0x41')][_0x66c7('0xbc')](_0x16965c['body'],{})['then'](respondWithResult(_0x2dfe01,0xc9))[_0x66c7('0x1d')](handleError(_0x2dfe01,null));};exports[_0x66c7('0x28')]=function(_0x433ce2,_0x221d44){if(_0x433ce2[_0x66c7('0x7c')]['id']){delete _0x433ce2[_0x66c7('0x7c')]['id'];}return db[_0x66c7('0x41')][_0x66c7('0x68')]({'where':{'id':_0x433ce2[_0x66c7('0xb9')]['id']}})[_0x66c7('0x14')](handleEntityNotFound(_0x221d44,null))['then'](saveUpdates(_0x433ce2[_0x66c7('0x7c')],null))[_0x66c7('0x14')](respondWithResult(_0x221d44,null))[_0x66c7('0x1d')](handleError(_0x221d44,null));};exports[_0x66c7('0x29')]=function(_0xbe4285,_0x3fb5eb){return db[_0x66c7('0x41')][_0x66c7('0x68')]({'where':{'id':_0xbe4285[_0x66c7('0xb9')]['id']}})[_0x66c7('0x14')](handleEntityNotFound(_0x3fb5eb,null))['then'](removeEntity(_0x3fb5eb,null))[_0x66c7('0x1d')](handleError(_0x3fb5eb,null));};exports[_0x66c7('0xbd')]=function(_0x140a3d,_0x42ef4c){return db[_0x66c7('0x41')][_0x66c7('0xbd')]()[_0x66c7('0x14')](respondWithResult(_0x42ef4c,null))[_0x66c7('0x1d')](handleError(_0x42ef4c,null));};exports['createVidaooSession']=function(_0x18c58a,_0x2bac63){var _0x4377f1=_0x18c58a[_0x66c7('0xb9')]['id'];var _0x13477f;var _0x433147;var _0x1caa25;return db[_0x66c7('0x41')][_0x66c7('0xbe')]({'where':{'id':_0x4377f1}})[_0x66c7('0x14')](function(_0x3259b1){_0x13477f=_0x3259b1;return db[_0x66c7('0xbf')]['findOne']({'where':{'id':_0x3259b1['ChatWebsiteId']},'attributes':['id',_0x66c7('0xc0'),_0x66c7('0xc1'),_0x66c7('0xc2'),_0x66c7('0xc3'),_0x66c7('0xc4')],'raw':!![]});})[_0x66c7('0x14')](function(_0x39fc6a){if(_0x39fc6a&&_0x39fc6a[_0x66c7('0xc0')]&&_0x39fc6a['vidaooEscalation']){_0x433147=_0x39fc6a;var _0xafdef8={'interaction':{'id':_0x4377f1},'agent':{'id':_0x18c58a[_0x66c7('0x9d')]['id'],'name':_0x18c58a['user'][_0x66c7('0x2b')],'fullname':_0x18c58a[_0x66c7('0x9d')][_0x66c7('0x34')],'email':_0x18c58a[_0x66c7('0x9d')]['email']},'contact':_0x18c58a[_0x66c7('0x7c')][_0x66c7('0x2e')],'account':_0x18c58a[_0x66c7('0x7c')][_0x66c7('0x31')]};var _0x582e85={'rejectUnauthorized':![],'method':'POST','url':_0x66c7('0xc5'),'headers':{'X-APIKEY':_0x39fc6a[_0x66c7('0xc0')]},'body':{'duration':null,'scheduledAt':null,'participants':[_0x18c58a[_0x66c7('0x9d')][_0x66c7('0xc6')]],'buttons':null,'topic':_0x433147[_0x66c7('0xc2')],'note':_[_0x66c7('0xc7')](_0x433147['vidaooNote'])?null:getMustacheRender(_0x433147[_0x66c7('0xc3')],_0xafdef8),'metadata':null},'redirect':_0x66c7('0xc8'),'json':!![]};try{if(!_[_0x66c7('0xc7')](_0x433147[_0x66c7('0xc4')])){var _0x4f9ac5=getMustacheRender(_0x433147[_0x66c7('0xc4')],_0xafdef8);var _0x4b01ee=JSON[_0x66c7('0x84')](_0x4f9ac5);_0x582e85['body']['metadata']=_0x4b01ee;}}catch(_0x1e8fb4){throw new db[(_0x66c7('0xc9'))]['ValidationError']('Error\x20in\x20conversion\x20vidaooMetadata');}return rp(_0x582e85);}else{throw new db[(_0x66c7('0xc9'))]['ValidationError'](_0x66c7('0xca'));}})[_0x66c7('0x14')](function(_0x2358e9){_0x1caa25=_0x2358e9;if(_0x1caa25['id']){var _0xba7a89={'body':_0x1caa25['join_url'],'ChatWebsiteId':_0x433147['id'],'ChatInteractionId':_0x13477f['id'],'direction':_0x66c7('0xcb'),'UserId':_0x18c58a[_0x66c7('0x9d')]['id']};return db[_0x66c7('0xcc')][_0x66c7('0xbc')](_0xba7a89,{});}else{throw new db[(_0x66c7('0xc9'))]['ValidationError']('Unable\x20to\x20create\x20Vidaoo\x20session');}})[_0x66c7('0x14')](function(){return _0x13477f[_0x66c7('0xcd')]({'vidaooSessionId':_0x1caa25['id']});})[_0x66c7('0x14')](respondWithResult(_0x2bac63,null))[_0x66c7('0x1d')](handleError(_0x2bac63,null));};exports[_0x66c7('0xce')]=function(_0x501a80,_0x290fcc){if(_0x501a80[_0x66c7('0x7c')]['id']){delete _0x501a80[_0x66c7('0x7c')]['id'];}return db[_0x66c7('0x41')][_0x66c7('0x68')]({'where':{'id':_0x501a80['params']['id']},'include':[{'model':db['CmContact'],'as':_0x66c7('0x6e')}]})[_0x66c7('0x14')](handleEntityNotFound(_0x290fcc,null))['then'](saveUpdates(_0x501a80[_0x66c7('0x7c')],null))['then'](respondWithResult(_0x290fcc,null))[_0x66c7('0x1d')](handleError(_0x290fcc,null));};exports[_0x66c7('0xcf')]=function(_0x38afc7,_0x4dc210){if(_0x38afc7[_0x66c7('0x7c')]['id']){delete _0x38afc7['body']['id'];}return db[_0x66c7('0x41')]['find']({'where':{'id':_0x38afc7[_0x66c7('0xb9')]['id']}})[_0x66c7('0x14')](function(_0x201893){if(!_0x201893){logger[_0x66c7('0x19')]('abandonInteraction,\x20%s,\x20%s,\x20%s',_0x66c7('0xcf'),0x194,_0x66c7('0xd0'));_0x4dc210['sendStatus'](0x194);}else{if(_0x201893[_0x66c7('0x3f')]){throw new db[(_0x66c7('0xc9'))]['ValidationError'](_0x66c7('0xd1'));}}return _0x201893;})[_0x66c7('0x14')](function(_0x4aadc8){if(_0x4aadc8){return _0x4aadc8[_0x66c7('0x28')]({'closed':_0x38afc7['body']['closed'],'disposition':_0x38afc7[_0x66c7('0x7c')]['disposition']})[_0x66c7('0x14')](function(_0x276cf8){return _0x276cf8;});}})['then'](function(){return respondWithRpcPromise(_0x66c7('0xd2'),'abandon',_0x38afc7[_0x66c7('0x7c')],client9004);})[_0x66c7('0x14')](respondWithResult(_0x4dc210,null))[_0x66c7('0x1d')](handleError(_0x4dc210,null));};exports[_0x66c7('0xd3')]=function(_0x54759e,_0x55781b){_0x54759e[_0x66c7('0x7c')]['name']=_0x54759e[_0x66c7('0xd4')][_0x66c7('0xd5')];_0x54759e[_0x66c7('0x7c')][_0x66c7('0xd6')]=_0x54759e[_0x66c7('0xd4')][_0x66c7('0xd7')];_0x54759e[_0x66c7('0x7c')][_0x66c7('0x43')]=_0x54759e[_0x66c7('0xd4')][_0x66c7('0xd8')];return db[_0x66c7('0xd9')][_0x66c7('0xbc')](_0x54759e[_0x66c7('0x7c')])[_0x66c7('0x14')](respondWithResult(_0x55781b,0xc9))[_0x66c7('0x1d')](handleError(_0x55781b,null));};exports[_0x66c7('0xda')]=function(_0x51f2c8,_0x2f74b6){return db['ChatInteraction']['findOne']({'where':{'id':_0x51f2c8[_0x66c7('0xb9')]['id']},'raw':!![]})[_0x66c7('0x14')](handleEntityNotFound(_0x2f74b6,null))['then'](function(_0x1ad31b){if(_0x1ad31b){if(_0x1ad31b[_0x66c7('0x3e')]){return _0x2f74b6[_0x66c7('0x1f')](0x193)[_0x66c7('0x21')]({'status':0x193,'message':_0x66c7('0xdb')});}return db['Attachment'][_0x66c7('0xbe')]({'where':{'id':_0x51f2c8[_0x66c7('0x46')][_0x66c7('0xdc')]},'raw':!![]})[_0x66c7('0x14')](handleEntityNotFound(_0x2f74b6,null));}})[_0x66c7('0x14')](function(_0x1b677c){if(_0x1b677c){var _0x53a34c=_0x1b677c[_0x66c7('0xdd')]!==null;var _0x598212=path[_0x66c7('0xde')](config['root'],_0x66c7('0xdf'));if(_0x53a34c){_0x598212=path[_0x66c7('0xde')](_0x598212,_0x66c7('0xe0'));}var _0x1f3b38=path[_0x66c7('0xde')](_0x598212,_0x1b677c['basename']);return _0x2f74b6[_0x66c7('0xe1')](_0x1f3b38);}})[_0x66c7('0x1d')](handleError(_0x2f74b6,null));};exports[_0x66c7('0xe2')]=function(_0x56c2ca,_0x22e8f7){var _0x511029=null;var _0x1dcadb=null;var _0x37aace=null;if(_0x56c2ca['body']['id']){delete _0x56c2ca[_0x66c7('0x7c')]['id'];}if(_0x56c2ca[_0x66c7('0x7c')][_0x66c7('0xe3')]){_0x37aace=path['join'](config[_0x66c7('0xe4')],_0x66c7('0xe5'),util[_0x66c7('0xe6')]('transcript-%s.txt',Date['now']()));_0x56c2ca[_0x66c7('0x7c')]['pathTranscript']=_0x37aace;}return db[_0x66c7('0x41')][_0x66c7('0x68')]({'where':{'id':_0x56c2ca['params']['id']},'include':[{'model':db[_0x66c7('0xcc')],'as':'Messages','include':[{'model':db['User'],'as':_0x66c7('0x7a')}]}]})[_0x66c7('0x14')](handleEntityNotFound(_0x22e8f7,null))[_0x66c7('0x14')](saveUpdates(_0x56c2ca['body'],null))[_0x66c7('0x14')](function(_0x3fff74){if(_0x3fff74){_0x511029=_0x3fff74;return db[_0x66c7('0xbf')][_0x66c7('0x68')]({'where':{'id':_0x511029[_0x66c7('0x80')]}});}})['then'](function(_0x2ce2c2){if(_0x2ce2c2){_0x1dcadb=_0x2ce2c2;return db[_0x66c7('0xe7')][_0x66c7('0x68')]({'where':{'id':_0x511029['ContactId']}});}})[_0x66c7('0x14')](function(_0x5d6306){if(_0x5d6306){if(_0x37aace){var _0x42119f=null;for(var _0x26894a=0x1;_0x26894a<_0x511029[_0x66c7('0xe8')][_0x66c7('0x4b')];++_0x26894a){_0x42119f=_0x511029[_0x66c7('0xe8')][_0x26894a];var _0x21b78a=_0x42119f['UserId']?util[_0x66c7('0xe6')](_0x66c7('0xe9'),_0x1dcadb['agentAlias'],_0x42119f[_0x66c7('0x3f')]):_0x66c7('0xea');var _0x196ae=_0x56c2ca[_0x66c7('0x7c')]['customer']||util[_0x66c7('0xe6')](_0x66c7('0xe9'),'Visitor',_0x42119f['ContactId']);switch(_0x1dcadb['agentIdentifier']){case _0x66c7('0xeb'):_0x21b78a=_0x42119f[_0x66c7('0x3f')]?util[_0x66c7('0xe6')](_0x66c7('0xe9'),_0x1dcadb[_0x66c7('0xec')],_0x42119f[_0x66c7('0x3f')]):'System';break;case _0x66c7('0xed'):_0x21b78a=_0x42119f[_0x66c7('0x3f')]?_0x42119f[_0x66c7('0x7a')][_0x66c7('0xee')]||_0x42119f[_0x66c7('0x7a')][_0x66c7('0x34')]:_0x66c7('0xea');break;case'agent_fullname':_0x21b78a=_0x42119f[_0x66c7('0x3f')]?_0x42119f['User'][_0x66c7('0x34')]:_0x66c7('0xea');break;default:_0x21b78a=_0x42119f['UserId']?util[_0x66c7('0xe6')](_0x66c7('0xe9'),_0x1dcadb[_0x66c7('0xec')],_0x42119f['UserId']):_0x66c7('0xea');}var _0x1c1023=util[_0x66c7('0xe6')](_0x66c7('0xef'),moment(_0x42119f[_0x66c7('0x83')])['format'](_0x66c7('0xf0')),_0x42119f[_0x66c7('0xf1')]==='in'?_0x196ae:_0x21b78a,_0x42119f[_0x66c7('0x7c')]);if(!_0x42119f[_0x66c7('0xf2')]){fs['appendFileSync'](_0x37aace,_0x1c1023);}}return db[_0x66c7('0xf3')][_0x66c7('0xbe')]({'where':{'service':!![]},'include':[{'model':db[_0x66c7('0xf4')],'as':'Smtp','raw':!![],'include':[{'model':db['CloudProvider'],'as':_0x66c7('0xf5'),'raw':!![]}]}]});}}})[_0x66c7('0x14')](function(_0x2a5aa1){if(!_0x2a5aa1||!_0x2a5aa1[_0x66c7('0xf6')]||!_0x56c2ca[_0x66c7('0x7c')])return _0x511029;var _0x8401b2=_0x2a5aa1[_0x66c7('0xf7')]();return respondWithRpcPromise(_0x66c7('0xf8'),_0x66c7('0xf9'),{'account':_0x8401b2,'message':{'from':util[_0x66c7('0xe6')]('\x22%s\x22\x20<%s>',_0x2a5aa1['name'],_0x2a5aa1[_0x66c7('0xc6')]||_0x2a5aa1[_0x66c7('0xf6')][_0x66c7('0x9d')]),'to':_0x56c2ca[_0x66c7('0x7c')][_0x66c7('0xe3')],'subject':_0x66c7('0xfa'),'text':util[_0x66c7('0xe6')]('Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a',_0x56c2ca['body'][_0x66c7('0xe3')]),'attachments':[{'path':_0x37aace}]}})[_0x66c7('0x14')](function(){return _0x511029;})[_0x66c7('0x1d')](function(_0xb53a79){logger[_0x66c7('0x19')](_0xb53a79);});})[_0x66c7('0x14')](respondWithStatusCode(_0x22e8f7,0xc8))[_0x66c7('0x1d')](handleError(_0x22e8f7,null));};exports['addMessage']=function(_0x90a5c0,_0x471565){return db[_0x66c7('0xcc')][_0x66c7('0x68')]({'where':{'id':_0x90a5c0[_0x66c7('0xb9')]['id']}})[_0x66c7('0x14')](handleEntityNotFound(_0x471565,null))[_0x66c7('0x14')](function(_0x1ab91c){if(_0x1ab91c){return _0x1ab91c[_0x66c7('0xfb')](_0x90a5c0['body'][_0x66c7('0xfc')],_[_0x66c7('0xfd')](_0x90a5c0['body'],[_0x66c7('0xfc'),'id'])||{});}})[_0x66c7('0x14')](respondWithResult(_0x471565,null))[_0x66c7('0x1d')](handleError(_0x471565,null));};exports[_0x66c7('0xfe')]=function(_0x3cbabe,_0x17389b){var _0x51beee={'raw':![],'where':{}};var _0x21681e={};var _0x4fe200={'count':0x0,'rows':[]};return db[_0x66c7('0x41')][_0x66c7('0xbe')]({'where':{'id':_0x3cbabe[_0x66c7('0xb9')]['id']}})[_0x66c7('0x14')](handleEntityNotFound(_0x17389b,null))[_0x66c7('0x14')](function(_0x4ca682){if(_0x4ca682){_0x21681e[_0x66c7('0x45')]=_[_0x66c7('0x47')](db[_0x66c7('0xcc')][_0x66c7('0x42')]);_0x21681e[_0x66c7('0x46')]=_['keys'](_0x3cbabe[_0x66c7('0x46')]);_0x21681e[_0x66c7('0xff')]=_[_0x66c7('0x48')](_0x21681e['model'],_0x21681e[_0x66c7('0x46')]);_0x51beee[_0x66c7('0x49')]=_[_0x66c7('0x48')](_0x21681e[_0x66c7('0x45')],qs[_0x66c7('0x4a')](_0x3cbabe[_0x66c7('0x46')][_0x66c7('0x4a')]));_0x51beee['attributes']=_0x51beee[_0x66c7('0x49')][_0x66c7('0x4b')]?_0x51beee[_0x66c7('0x49')]:_0x21681e[_0x66c7('0x45')];if(!_0x3cbabe[_0x66c7('0x46')]['hasOwnProperty']('nolimit')){_0x51beee[_0x66c7('0x25')]=qs[_0x66c7('0x25')](_0x3cbabe[_0x66c7('0x46')]['limit']);_0x51beee[_0x66c7('0x23')]=qs[_0x66c7('0x23')](_0x3cbabe[_0x66c7('0x46')][_0x66c7('0x23')]);}_0x51beee[_0x66c7('0x4e')]=qs[_0x66c7('0x4f')](_0x3cbabe[_0x66c7('0x46')]['sort']);_0x51beee['where']=qs[_0x66c7('0xff')](_[_0x66c7('0x51')](_0x3cbabe['query'],_0x21681e[_0x66c7('0xff')]));_0x51beee[_0x66c7('0x50')][_0x66c7('0xb4')]=_0x4ca682['id'];if(_0x3cbabe[_0x66c7('0x46')]['filter']){_0x51beee[_0x66c7('0x50')]=_[_0x66c7('0xa4')](_0x51beee['where'],{'$or':_[_0x66c7('0x33')](_0x51beee[_0x66c7('0x49')],function(_0x3c1430){var _0x4b54ed={};_0x4b54ed[_0x3c1430]={'$like':'%'+_0x3cbabe[_0x66c7('0x46')]['filter']+'%'};return _0x4b54ed;})});}if(_0x3cbabe['query'][_0x66c7('0x100')]){var _0x3cff4f=_0x3cbabe[_0x66c7('0x46')][_0x66c7('0x100')][_0x66c7('0x36')](',');var _0x24eb7f={};_0x24eb7f[_0x3cff4f[0x0]]={'$gte':moment(_0x3cff4f[0x1])[_0x66c7('0xe6')](_0x66c7('0x101'))};_0x51beee[_0x66c7('0x50')]=_[_0x66c7('0xa4')](_0x51beee[_0x66c7('0x50')],_0x24eb7f);}_0x51beee=_[_0x66c7('0xa4')]({},_0x51beee,_0x3cbabe[_0x66c7('0x102')]);return db['ChatMessage'][_0x66c7('0x24')]({'where':_0x51beee[_0x66c7('0x50')]})[_0x66c7('0x14')](function(_0x34a021){_0x4fe200[_0x66c7('0x24')]=_0x34a021;if(_0x3cbabe[_0x66c7('0x46')][_0x66c7('0xba')]){_0x51beee['include']=[{'all':!![]}];}return db[_0x66c7('0xcc')][_0x66c7('0x103')](_0x51beee);})[_0x66c7('0x14')](function(_0x11f42d){_0x4fe200[_0x66c7('0xb7')]=_0x11f42d;return _0x4fe200;});}})[_0x66c7('0x14')](respondWithFilteredResult(_0x17389b,_0x51beee))[_0x66c7('0x1d')](handleError(_0x17389b,null));};exports[_0x66c7('0x104')]=function(_0x3d4e33,_0x17cbe7){var _0x18ef7d={'where':{}},_0x4c877a={},_0x3e34ca={'count':0x0,'rows':[]};return db[_0x66c7('0x41')][_0x66c7('0xbe')]({'where':{'id':_0x3d4e33[_0x66c7('0xb9')]['id']}})[_0x66c7('0x14')](handleEntityNotFound(_0x17cbe7,null))[_0x66c7('0x14')](function(_0x555249){if(_0x555249){_0x4c877a[_0x66c7('0x45')]=_['keys'](db[_0x66c7('0xcc')][_0x66c7('0x42')]);_0x4c877a[_0x66c7('0x46')]=_[_0x66c7('0x47')](_0x3d4e33[_0x66c7('0x46')]);_0x4c877a[_0x66c7('0xff')]=_[_0x66c7('0x48')](_0x4c877a[_0x66c7('0x45')],_0x4c877a[_0x66c7('0x46')]);_0x18ef7d[_0x66c7('0x49')]=_[_0x66c7('0x48')](_0x4c877a[_0x66c7('0x45')],qs[_0x66c7('0x4a')](_0x3d4e33[_0x66c7('0x46')][_0x66c7('0x4a')]));_0x18ef7d['attributes']=_0x18ef7d['attributes'][_0x66c7('0x4b')]?_0x18ef7d['attributes']:_0x4c877a['model'];if(!_0x3d4e33['query'][_0x66c7('0x4c')]('nolimit')){_0x18ef7d['limit']=qs['limit'](_0x3d4e33['query']['limit']);_0x18ef7d[_0x66c7('0x23')]=qs[_0x66c7('0x23')](_0x3d4e33[_0x66c7('0x46')][_0x66c7('0x23')]);}_0x18ef7d[_0x66c7('0x4e')]=qs[_0x66c7('0x4f')](_0x3d4e33[_0x66c7('0x46')]['sort']);_0x18ef7d['where']=qs[_0x66c7('0xff')](_[_0x66c7('0x51')](_0x3d4e33[_0x66c7('0x46')],_0x4c877a[_0x66c7('0xff')]));_0x18ef7d[_0x66c7('0x50')][_0x66c7('0xb4')]=_0x555249['id'];if(_0x3d4e33[_0x66c7('0x46')]['filter']){_0x18ef7d[_0x66c7('0x50')]=_[_0x66c7('0xa4')](_0x18ef7d[_0x66c7('0x50')],{'$or':_[_0x66c7('0x33')](_0x18ef7d[_0x66c7('0x49')],function(_0x51cb7c){var _0x28dd5c={};_0x28dd5c[_0x51cb7c]={'$like':'%'+_0x3d4e33[_0x66c7('0x46')]['filter']+'%'};return _0x28dd5c;})});}_0x18ef7d[_0x66c7('0x50')][_0x66c7('0xf2')]=![];if(_0x3d4e33[_0x66c7('0x46')]['id']){_0x18ef7d[_0x66c7('0x50')]['id']={'$gt':_0x3d4e33[_0x66c7('0x46')]['id']};}_0x18ef7d=_['merge']({},_0x18ef7d,_0x3d4e33['options']);return db[_0x66c7('0xcc')]['count']({'where':_0x18ef7d[_0x66c7('0x50')]})[_0x66c7('0x14')](function(_0x4c707c){_0x3e34ca[_0x66c7('0x24')]=_0x4c707c;_0x18ef7d[_0x66c7('0xbb')]=[];if(_0x3d4e33[_0x66c7('0x46')][_0x66c7('0x105')]){_0x18ef7d['include'][_0x66c7('0xb5')]({'model':db[_0x66c7('0x7a')],'as':_0x66c7('0x7a'),'attributes':['id','fullname','alias']});}if(_0x3d4e33['query'][_0x66c7('0xba')]){_0x18ef7d[_0x66c7('0xbb')]=[{'all':!![]}];}return db['ChatMessage'][_0x66c7('0x103')](_0x18ef7d);})[_0x66c7('0x14')](function(_0x31158d){_0x3e34ca[_0x66c7('0xb7')]=_0x31158d;return _0x3e34ca;});}})[_0x66c7('0x14')](respondWithFilteredResult(_0x17cbe7,_0x18ef7d))[_0x66c7('0x1d')](handleError(_0x17cbe7,null));};exports[_0x66c7('0x106')]=function(_0x20babe,_0x25efcd){return db[_0x66c7('0x41')]['find']({'where':{'id':_0x20babe[_0x66c7('0xb9')]['id']}})[_0x66c7('0x14')](handleEntityNotFound(_0x25efcd,null))[_0x66c7('0x14')](function(_0x5745d1){if(_0x5745d1){return _0x5745d1[_0x66c7('0x107')](_0x20babe['body'][_0x66c7('0xfc')],_[_0x66c7('0xfd')](_0x20babe[_0x66c7('0x7c')],['ids','id'])||{})[_0x66c7('0x108')](function(){return db[_0x66c7('0x77')][_0x66c7('0x103')]({'attributes':['id','name',_0x66c7('0x54')],'where':{'id':_0x20babe[_0x66c7('0x7c')]['ids']}});})['then'](function(_0x16db46){socket['emit'](_0x66c7('0x109'),{'id':Number(_0x20babe[_0x66c7('0xb9')]['id']),'tags':_0x16db46||[]});return{'id':Number(_0x20babe[_0x66c7('0xb9')]['id']),'tags':_0x16db46||[]};});}})[_0x66c7('0x14')](respondWithResult(_0x25efcd,null))[_0x66c7('0x1d')](handleError(_0x25efcd,null));};exports[_0x66c7('0x10a')]=function(_0x36d836,_0x93b6a9){return db[_0x66c7('0x41')][_0x66c7('0x68')]({'where':{'id':_0x36d836['params']['id']}})['then'](handleEntityNotFound(_0x93b6a9,null))[_0x66c7('0x14')](function(_0x5c6101){if(_0x5c6101){return _0x5c6101['removeTags'](_0x36d836[_0x66c7('0x46')][_0x66c7('0xfc')]);}})[_0x66c7('0x14')](respondWithStatusCode(_0x93b6a9,null))[_0x66c7('0x1d')](handleError(_0x93b6a9,null));};exports[_0x66c7('0xe1')]=function(_0x321ea2,_0x29c394){var _0x2ab0b1=moment()['unix']()[_0x66c7('0xa2')]();var _0xbfa002=path[_0x66c7('0xde')](config[_0x66c7('0xe4')],_0x66c7('0x10b'),_0x66c7('0x10c'),_0x66c7('0x10d'));var _0x3761ba=path['join'](config[_0x66c7('0xe4')],_0x66c7('0x10b'),_0x66c7('0x10c'),'attachments');var _0x395cb3=path['join'](_0xbfa002,_0x2ab0b1);var _0x293766=util[_0x66c7('0xe6')](_0x66c7('0x10e'),_0x321ea2[_0x66c7('0xb9')]['id'],_0x2ab0b1);var _0x3625ea=path[_0x66c7('0xde')](_0xbfa002,_0x293766);var _0x47e832=[];_0x47e832[_0x66c7('0xb5')]({'model':db[_0x66c7('0x7a')],'as':_0x66c7('0x7a'),'attributes':['id',_0x66c7('0x34')],'raw':!![]});_0x47e832[_0x66c7('0xb5')]({'model':db[_0x66c7('0xe7')],'as':_0x66c7('0x6e'),'attributes':['id','firstName',_0x66c7('0x10f')],'raw':!![]});if(_0x321ea2[_0x66c7('0x46')][_0x66c7('0x110')]){_0x47e832[_0x66c7('0xb5')]({'model':db[_0x66c7('0xd9')],'as':_0x66c7('0xd9'),'raw':!![]});}var _0x46d1ba=[{'model':db[_0x66c7('0xcc')],'as':_0x66c7('0xe8'),'attributes':['id',_0x66c7('0x7c'),_0x66c7('0x83'),'direction',_0x66c7('0xf2'),'read'],'include':_0x47e832}];_0x46d1ba['push']({'model':db[_0x66c7('0xbf')],'as':_0x66c7('0x111'),'attributes':['id',_0x66c7('0x2b')]});_0x46d1ba[_0x66c7('0xb5')]({'model':db[_0x66c7('0x7a')],'as':_0x66c7('0x112'),'attributes':['id',_0x66c7('0x34')]});return db[_0x66c7('0x41')]['find']({'where':{'id':_0x321ea2[_0x66c7('0xb9')]['id']},'include':_0x46d1ba})[_0x66c7('0x14')](handleEntityNotFound(_0x29c394,null))['then'](function(_0x862182){if(_0x862182){var _0x37992c=_0x862182['get']({'plain':!![]});fs[_0x66c7('0x113')](_0x395cb3);var _0x288b89={'channel':_0x66c7('0x114'),'account':_0x37992c[_0x66c7('0x111')][_0x66c7('0x2b')],'agent':_0x37992c[_0x66c7('0x112')]?_0x37992c[_0x66c7('0x112')][_0x66c7('0x34')]:_0x66c7('0x115'),'createdAt':moment(_0x37992c[_0x66c7('0x83')])[_0x66c7('0xe6')](_0x66c7('0x101'))[_0x66c7('0xa2')](),'closedAt':_0x37992c[_0x66c7('0x3e')]?moment(_0x37992c[_0x66c7('0x116')])[_0x66c7('0xe6')](_0x66c7('0x101'))[_0x66c7('0xa2')]():'','disposition':_0x37992c[_0x66c7('0x117')],'chatInfo':{'browser':_0x37992c[_0x66c7('0x118')],'os':_0x37992c[_0x66c7('0x119')],'referer':_0x37992c[_0x66c7('0x11a')],'customerIp':_0x37992c[_0x66c7('0x11b')],'customerPort':_0x37992c[_0x66c7('0x11c')]?_0x37992c[_0x66c7('0x11c')]:'N.A.'},'messages':_(_0x37992c['Messages'])[_0x66c7('0x11d')]()[_0x66c7('0x8e')]({'secret':![]})[_0x66c7('0x33')](function(_0x136e37){if(_0x136e37[_0x66c7('0xd9')]){var _0x355c89=path[_0x66c7('0xde')](_0x3761ba,_0x136e37[_0x66c7('0xd9')][_0x66c7('0xd6')]);if(fs[_0x66c7('0x11e')](_0x355c89)){fs[_0x66c7('0x11f')](_0x355c89)['pipe'](fs[_0x66c7('0x120')](path[_0x66c7('0xde')](_0x395cb3,_0x136e37[_0x66c7('0xd9')][_0x66c7('0xd6')])));}}return{'date':moment(_0x136e37[_0x66c7('0x83')])['format']('YYYY-MM-DD\x20HH:mm:ss')[_0x66c7('0xa2')](),'sender':_0x136e37[_0x66c7('0xf1')]==='out'?_0x136e37[_0x66c7('0x7a')]?_0x136e37[_0x66c7('0x7a')][_0x66c7('0x34')]:'System':_0x136e37[_0x66c7('0x6e')]['firstName']+(_0x136e37[_0x66c7('0x6e')]['lastName']?'\x20'+_0x136e37[_0x66c7('0x6e')][_0x66c7('0x10f')]:''),'body':_0x136e37[_0x66c7('0xd9')]?_0x136e37['Attachment'][_0x66c7('0xd6')]:_0x136e37[_0x66c7('0x7c')],'direction':_0x136e37[_0x66c7('0xf1')]===_0x66c7('0xcb')?'A':'C','secret':_0x136e37[_0x66c7('0xf2')],'read':_0x136e37['read'],'attachment':_0x136e37['Attachment']};})[_0x66c7('0x6a')]()};return ejs['renderFile'](path[_0x66c7('0xde')](config[_0x66c7('0xe4')],_0x66c7('0x10b'),'views',_0x66c7('0x121')),{'interaction':_0x288b89})[_0x66c7('0x14')](function(_0xb321a){var _0x498a86=path['join'](_0x395cb3,_0x66c7('0x122')+_0x37992c['id']+'-'+_0x2ab0b1+_0x66c7('0x123'));var _0x438f04={'path':_0x498a86,'channel':_0x66c7('0x114'),'interactionId':_0x37992c['id']};return pdf[_0x66c7('0x124')](_0xb321a,_0x438f04);})[_0x66c7('0x14')](function(){return new Promise(function(_0x5a912b,_0x53bb0d){zipdir(_0x395cb3,{'saveTo':_0x3625ea},function(_0x555008,_0x513f44){if(_0x555008)return _0x53bb0d(_0x555008);return _0x5a912b(_0x513f44);});})[_0x66c7('0x14')](function(){return new BPromise(function(_0x159dcc,_0x2b7e3a){rimraf(_0x395cb3,function(_0xacf9a4){if(_0xacf9a4)_0x2b7e3a(_0xacf9a4);return _0x159dcc();});});})[_0x66c7('0x14')](function(){return _0x29c394[_0x66c7('0xe1')](_0x3625ea,_0x293766,function(_0x5b41d6){if(_0x5b41d6){logger[_0x66c7('0x19')]('err',_0x5b41d6);}else{fs['unlinkSync'](_0x3625ea);}});});});}else{return _0x29c394[_0x66c7('0x1e')](0xc8);}})[_0x66c7('0x1d')](handleError(_0x29c394,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