Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / chatInteraction / chatInteraction.controller.js
index f61524b..4d720c7 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xd2ea=['Smtp','CloudProvider','SendMail','sendMail','\x22%s\x22\x20<%s>','Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a','addMessage','ids','omit','getMessages','hasOwnProperty','ChatInteractionId','filter','$gte','findAll','getMyMessages','include','addTags','spread','Tag','color','emit','chatInteractionTags:save','removeTags','server','tmp','files','attachments','firstName','lastName','Account','Owner','get','mkdirSync','Chat','N.A.','YYYY-MM-DD\x20HH:mm:ss','closedAt','browserName','osName','referer','customerIp','customerPort','tail','pipe','createWriteStream','out','renderFile','views','downloadInteraction.ejs','createPdfFromHTML','unlinkSync','rimraf','zip-dir','request-promise','moment','bluebird','util','path','ejs','lodash','squel','ioredis','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../mysqldb','redis','socket.io-emitter','./chatInteraction.socket','register','client','http','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','end','json','offset','undefined','count','limit','set','update','then','destroy','name','send','render','merge','body','contact','agent','interaction','Users','map','fullname','TagIds','Tags','split','forEach','push','waiting','talking','unmanaged','total','closed','UserId','disposition','abandoned','answered','index','ChatInteraction','fieldName','type','key','model','query','keys','fields','attributes','length','nolimit','order','sort','where','filters','pick','field','from','tools_tags','select','u.id','u.fullname','ui.ChatInteractionId','user_has_chat_interactions','left_join','users','chat_interactions','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','chat_websites','chat_messages','chat_interaction_has_tags','it.ChatInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','conditions','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','operator','$substring','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','find','ContactId','buildExpression','text','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','start','some','compact','isEmpty','ChatWebsiteId','i.ChatWebsiteId\x20IN\x20?','parse','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20>\x200','isArray','tag','replace','isNumeric','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','QueryTypes','SELECT','clone','i.id','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','DESC','t.id\x20IN\x20?','resolve','i.ChatWebsiteId\x20IS\x20NOT\x20NULL','user','role','getChatWebsites','i.ChatWebsiteId\x20IS\x20NULL','sequelize','toString','keyBy','a.key','Account.key','Account.mandatoryDisposition','c.firstName','c.lastName','c.email','Contact.phone','c.fax','o.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','groupBy','all','rows','rawAttributes','intersection','options','create','params','describe','createVidaooSession','findOne','ChatWebsite','vidaooEscalation','vidaooTopic','vidaooNote','vidaooMetadata','vidaooApiKey','email','POST','https://api-vidaoo.xcally.com/api/v1/meetings','isNull','follow','metadata','Sequelize','ValidationError','Error\x20in\x20conversion\x20vidaooMetadata','join_url','ChatMessage','Unable\x20to\x20create\x20Vidaoo\x20session','updateAttributes','customUpdate','CmContact','abandon','abandonInteraction,\x20%s,\x20%s,\x20%s','entity\x20not\x20found','Interaction\x20already\x20assigned','attachmentUpload','file','originalname','filename','Attachment','attachmentDownload','attachId','ChatOfflineMessageId','root','server/files/attachments/','join','offline-chat/','basename','download','mailTranscript','server/files/chat/upload/','format','now','pathTranscript','Messages','%s%d','agentAlias','customer','Visitor','agentIdentifier','website_alias','System','agent_alias','alias','agent_fullname','[%s]\x20%s:\x20%s\x0a','createdAt','MM/DD/YYYY\x20HH:mm:ss','direction','secret','appendFileSync','MailAccount','MailServerOut'];(function(_0x3d474,_0x5f50f7){var _0xca0cca=function(_0x195368){while(--_0x195368){_0x3d474['push'](_0x3d474['shift']());}};_0xca0cca(++_0x5f50f7);}(_0xd2ea,0x15f));var _0xad2e=function(_0xd18bb,_0x4dfdb9){_0xd18bb=_0xd18bb-0x0;var _0x5e9922=_0xd2ea[_0xd18bb];return _0x5e9922;};'use strict';var rimraf=require(_0xad2e('0x0'));var zipdir=require(_0xad2e('0x1'));var rp=require(_0xad2e('0x2'));var moment=require(_0xad2e('0x3'));var BPromise=require(_0xad2e('0x4'));var Mustache=require('mustache');var util=require(_0xad2e('0x5'));var path=require(_0xad2e('0x6'));var ejs=require(_0xad2e('0x7'));var fs=require('fs');var _=require(_0xad2e('0x8'));var squel=require(_0xad2e('0x9'));var Redis=require(_0xad2e('0xa'));var qs=require(_0xad2e('0xb'));var as=require('../../components/parsers/advancedSearch');var pdf=require(_0xad2e('0xc'));var logger=require(_0xad2e('0xd'))(_0xad2e('0xe'));var config=require('../../config/environment');var db=require(_0xad2e('0xf'))['db'];config[_0xad2e('0x10')]=_['defaults'](config[_0xad2e('0x10')],{'host':'localhost','port':0x18eb});var socket=require(_0xad2e('0x11'))(new Redis(config[_0xad2e('0x10')]));require(_0xad2e('0x12'))[_0xad2e('0x13')](socket);var jayson=require('jayson/promise');var client=jayson[_0xad2e('0x14')]['http']({'port':0x232b});var client9004=jayson[_0xad2e('0x14')][_0xad2e('0x15')]({'port':0x232c});function respondWithRpcPromise(_0x433696,_0x42e2f2,_0x59a342,_0x27fb5a){return new BPromise(function(_0x59201f,_0x1a91ce){var _0x5772f0=_0x27fb5a||client;return _0x5772f0['request'](_0x433696,_0x59a342)['then'](function(_0x5c96a7){logger[_0xad2e('0x16')](_0xad2e('0x17'),_0x42e2f2,_0xad2e('0x18'));logger[_0xad2e('0x19')](_0xad2e('0x1a'),_0x42e2f2,_0xad2e('0x18'),JSON[_0xad2e('0x1b')](_0x5c96a7));if(_0x5c96a7[_0xad2e('0x1c')]){if(_0x5c96a7[_0xad2e('0x1c')][_0xad2e('0x1d')]===0x1f4){logger[_0xad2e('0x1c')](_0xad2e('0x17'),_0x42e2f2,_0x5c96a7[_0xad2e('0x1c')][_0xad2e('0x1e')]);return _0x1a91ce(_0x5c96a7[_0xad2e('0x1c')]['message']);}logger[_0xad2e('0x1c')](_0xad2e('0x17'),_0x42e2f2,_0x5c96a7['error']['message']);return _0x59201f(_0x5c96a7['error']['message']);}else{logger[_0xad2e('0x16')](_0xad2e('0x17'),_0x42e2f2,_0xad2e('0x18'));_0x59201f(_0x5c96a7[_0xad2e('0x1f')][_0xad2e('0x1e')]);}})[_0xad2e('0x20')](function(_0x29dc4f){logger[_0xad2e('0x1c')](_0xad2e('0x17'),_0x42e2f2,_0x29dc4f);_0x1a91ce(_0x29dc4f);});});}function respondWithStatusCode(_0x154d54,_0x40e1e4){_0x40e1e4=_0x40e1e4||0xcc;return function(_0x142631){if(_0x142631){return _0x154d54[_0xad2e('0x21')](_0x40e1e4);}return _0x154d54[_0xad2e('0x22')](_0x40e1e4)[_0xad2e('0x23')]();};}function respondWithResult(_0x2e1c95,_0x59630b){_0x59630b=_0x59630b||0xc8;return function(_0x2e727c){if(_0x2e727c){return _0x2e1c95[_0xad2e('0x22')](_0x59630b)[_0xad2e('0x24')](_0x2e727c);}};}function respondWithFilteredResult(_0x350c66,_0x2f9370){return function(_0x58acc8){if(_0x58acc8){var _0x1161d5=typeof _0x2f9370[_0xad2e('0x25')]===_0xad2e('0x26')&&typeof _0x2f9370['limit']===_0xad2e('0x26');var _0x5d675f=_0x58acc8[_0xad2e('0x27')];var _0x28ef72=_0x1161d5?0x0:_0x2f9370[_0xad2e('0x25')];var _0x11bfa9=_0x1161d5?_0x58acc8[_0xad2e('0x27')]:_0x2f9370[_0xad2e('0x25')]+_0x2f9370[_0xad2e('0x28')];var _0x454c04;if(_0x11bfa9>=_0x5d675f){_0x11bfa9=_0x5d675f;_0x454c04=0xc8;}else{_0x454c04=0xce;}_0x350c66[_0xad2e('0x22')](_0x454c04);return _0x350c66[_0xad2e('0x29')]('Content-Range',_0x28ef72+'-'+_0x11bfa9+'/'+_0x5d675f)[_0xad2e('0x24')](_0x58acc8);}return null;};}function saveUpdates(_0xfd2087){return function(_0x2a0dc7){if(_0x2a0dc7){return _0x2a0dc7[_0xad2e('0x2a')](_0xfd2087)[_0xad2e('0x2b')](function(_0x9b4a23){return _0x9b4a23;});}return null;};}function removeEntity(_0x409f58){return function(_0x3e3d86){if(_0x3e3d86){return _0x3e3d86[_0xad2e('0x2c')]()[_0xad2e('0x2b')](function(){_0x409f58[_0xad2e('0x22')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3099fd){return function(_0x55e1dc){if(!_0x55e1dc){_0x3099fd[_0xad2e('0x21')](0x194);}return _0x55e1dc;};}function handleError(_0x3a6419,_0x5ac436){_0x5ac436=_0x5ac436||0x1f4;return function(_0x19d0fa){logger[_0xad2e('0x1c')](_0x19d0fa['stack']);if(_0x19d0fa[_0xad2e('0x2d')]){delete _0x19d0fa[_0xad2e('0x2d')];}_0x3a6419['status'](_0x5ac436)[_0xad2e('0x2e')](_0x19d0fa);};}function getMustacheRender(_0x100b35,_0x569b9c){return Mustache[_0xad2e('0x2f')](_0x100b35,_[_0xad2e('0x30')](_0x569b9c[_0xad2e('0x31')],{'contact':_0x569b9c[_0xad2e('0x32')],'message':_0x569b9c[_0xad2e('0x1e')],'agent':_0x569b9c[_0xad2e('0x33')],'interaction':_0x569b9c[_0xad2e('0x34')],'account':_0x569b9c['account']}))||'';}function getInteractionUsers(_0x41a022,_0x5b4386){return new BPromise(function(_0x49db79,_0x161402){try{if(_0x5b4386[_0x41a022['id']]){_0x41a022[_0xad2e('0x35')]=_[_0xad2e('0x36')](_0x5b4386[_0x41a022['id']],function(_0x14d8d6){return{'id':_0x14d8d6['id'],'fullname':_0x14d8d6[_0xad2e('0x37')]};});}}catch(_0xf4ae70){_0x161402(_0xf4ae70);}_0x49db79(_0x41a022);});}function getInteractionTags(_0x4fe4f6,_0x5d6ac1){return new BPromise(function(_0x924f10,_0x4b53d6){try{if(_0x4fe4f6[_0xad2e('0x38')]){_0x4fe4f6[_0xad2e('0x39')]=[];_0x4fe4f6[_0xad2e('0x38')][_0xad2e('0x3a')](',')[_0xad2e('0x3b')](function(_0x5d55f9){_0x4fe4f6[_0xad2e('0x39')][_0xad2e('0x3c')](_0x5d6ac1[_0x5d55f9]);});}delete _0x4fe4f6['TagIds'];}catch(_0x596eee){_0x4b53d6(_0x596eee);}_0x924f10(_0x4fe4f6);});}function updateChatInteraction(_0x5ba338,_0x274fd8,_0x54dac3){return new BPromise(function(_0x5f29a5,_0x2d0018){return getInteractionUsers(_0x5ba338,_0x54dac3)[_0xad2e('0x2b')](function(_0x271a49){return getInteractionTags(_0x271a49,_0x274fd8);})[_0xad2e('0x2b')](function(_0x6f4fbc){return getStateInteraction(_0x6f4fbc);})[_0xad2e('0x2b')](function(_0x382665){_0x5f29a5(_0x382665);})['catch'](function(_0xec9e1a){_0x2d0018(_0xec9e1a);});});}function getStateInteraction(_0x341f51){return new BPromise(function(_0x46684d){_0x341f51[_0xad2e('0x3d')]=0x0;_0x341f51[_0xad2e('0x3e')]=0x0;_0x341f51['answered']=0x0;_0x341f51[_0xad2e('0x3f')]=0x0;_0x341f51['abandoned']=0x0;_0x341f51[_0xad2e('0x40')]=0x0;if(!_0x341f51[_0xad2e('0x41')]&&!_0x341f51[_0xad2e('0x42')]){_0x341f51[_0xad2e('0x3d')]+=0x1;}if(!_0x341f51[_0xad2e('0x41')]&&_0x341f51[_0xad2e('0x42')]){_0x341f51[_0xad2e('0x3e')]+=0x1;if(_0x341f51[_0xad2e('0x3d')]){_0x341f51[_0xad2e('0x3d')]-=0x1;}}if(_0x341f51[_0xad2e('0x41')]&&_0x341f51[_0xad2e('0x43')]===_0xad2e('0x44')){_0x341f51[_0xad2e('0x44')]+=0x1;if(_0x341f51[_0xad2e('0x3d')]){_0x341f51[_0xad2e('0x3d')]-=0x1;}}else if(_0x341f51[_0xad2e('0x41')]&&!_0x341f51[_0xad2e('0x42')]&&_0x341f51[_0xad2e('0x43')]){_0x341f51[_0xad2e('0x3f')]+=0x1;if(_0x341f51[_0xad2e('0x3d')]){_0x341f51['waiting']-=0x1;}}else if(_0x341f51[_0xad2e('0x41')]&&_0x341f51[_0xad2e('0x42')]){_0x341f51[_0xad2e('0x45')]+=0x1;if(_0x341f51[_0xad2e('0x3e')]){_0x341f51[_0xad2e('0x3e')]-=0x1;}}_0x341f51[_0xad2e('0x40')]+=0x1;_0x46684d(_0x341f51);});}exports[_0xad2e('0x46')]=function(_0x4c99ec,_0x15e253){var _0x579a26={},_0x1f2f49={},_0x2ad66e={'count':0x0,'rows':[]};var _0x36b103=_[_0xad2e('0x36')](db[_0xad2e('0x47')]['rawAttributes'],function(_0xf80dd8){return{'name':_0xf80dd8[_0xad2e('0x48')],'type':_0xf80dd8[_0xad2e('0x49')][_0xad2e('0x4a')]};});_0x1f2f49[_0xad2e('0x4b')]=_['map'](_0x36b103,_0xad2e('0x2d'));_0x1f2f49[_0xad2e('0x4c')]=_[_0xad2e('0x4d')](_0x4c99ec[_0xad2e('0x4c')]);_0x1f2f49['filters']=_['intersection'](_0x1f2f49[_0xad2e('0x4b')],_0x1f2f49[_0xad2e('0x4c')]);_0x579a26['attributes']=_['intersection'](_0x1f2f49[_0xad2e('0x4b')],qs['fields'](_0x4c99ec[_0xad2e('0x4c')][_0xad2e('0x4e')]));_0x579a26['attributes']=_0x579a26[_0xad2e('0x4f')][_0xad2e('0x50')]?_0x579a26[_0xad2e('0x4f')]:_0x1f2f49[_0xad2e('0x4b')];if(!_0x4c99ec['query']['hasOwnProperty'](_0xad2e('0x51'))){_0x579a26[_0xad2e('0x28')]=qs[_0xad2e('0x28')](_0x4c99ec[_0xad2e('0x4c')][_0xad2e('0x28')]);_0x579a26[_0xad2e('0x25')]=qs[_0xad2e('0x25')](_0x4c99ec[_0xad2e('0x4c')]['offset']);}_0x579a26[_0xad2e('0x52')]=qs['sort'](_0x4c99ec[_0xad2e('0x4c')][_0xad2e('0x53')]);_0x579a26[_0xad2e('0x54')]=qs[_0xad2e('0x55')](_[_0xad2e('0x56')](_0x4c99ec[_0xad2e('0x4c')],_0x1f2f49[_0xad2e('0x55')]),_0x36b103);var _0x4aeb4a=[];var _0x411956=squel['select']()[_0xad2e('0x57')]('id')[_0xad2e('0x57')](_0xad2e('0x2d'))[_0xad2e('0x57')]('color')[_0xad2e('0x58')](_0xad2e('0x59'));var _0x56e633=squel[_0xad2e('0x5a')]()['field'](_0xad2e('0x5b'))[_0xad2e('0x57')](_0xad2e('0x5c'))[_0xad2e('0x57')](_0xad2e('0x5d'))[_0xad2e('0x58')](_0xad2e('0x5e'),'ui')[_0xad2e('0x5f')](_0xad2e('0x60'),'u','u.id\x20=\x20ui.UserId');var _0xe2d4ac=squel[_0xad2e('0x5a')]()[_0xad2e('0x58')](_0xad2e('0x61'),'i')['left_join']('cm_contacts','c',_0xad2e('0x62'))[_0xad2e('0x5f')](_0xad2e('0x60'),'o',_0xad2e('0x63'))[_0xad2e('0x5f')](_0xad2e('0x64'),'a','a.id\x20=\x20i.ChatWebsiteId')[_0xad2e('0x5f')](_0xad2e('0x65'),'me','me.ChatInteractionId\x20=\x20i.id')[_0xad2e('0x5f')](_0xad2e('0x66'),'it',_0xad2e('0x67'))[_0xad2e('0x5f')](_0xad2e('0x59'),'t',_0xad2e('0x68'));var _0x1ce266=squel[_0xad2e('0x69')]();var _0x745c47=[];var _0x124eaf=squel['expr']();var _0x583c12;if(_0x4c99ec[_0xad2e('0x4c')]['search']){_0x583c12=as['parseSearch'](_0x4c99ec[_0xad2e('0x4c')][_0xad2e('0x6a')]);var _0x3bfa74=_0x583c12['sqlOperator'];for(var _0x114ed5=0x0;_0x114ed5<_0x583c12[_0xad2e('0x6b')][_0xad2e('0x50')];_0x114ed5++){var _0x470bda=_0x583c12[_0xad2e('0x6b')][_0x114ed5];var _0x5d538c='i';var _0x22554f=_['find'](_0x36b103,['name',_0x470bda['field']]);if(!_0x22554f){switch(_0x470bda['field']){case _0xad2e('0x6c'):if(_0x470bda[_0xad2e('0x6d')]==0x1){_0xe2d4ac[_0xad2e('0x6e')]('`'+_0x470bda[_0xad2e('0x57')]+_0xad2e('0x6f'));}else{_0xe2d4ac[_0xad2e('0x6e')]('`'+_0x470bda[_0xad2e('0x57')]+_0xad2e('0x70'));}break;case _0xad2e('0x71'):if(_0x470bda[_0xad2e('0x72')]===_0xad2e('0x73')){if(_0x470bda['value'][_0xad2e('0x3a')]('\x20')[_0xad2e('0x50')]>0x1){_0x1ce266[_0x3bfa74]('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs['getFullTextValue'](_0x470bda[_0xad2e('0x6d')]),null);}else{var _0x49a7d9='%'+_0x470bda[_0xad2e('0x6d')]+'%';_0x1ce266[_0x3bfa74](_0xad2e('0x74'),_0x49a7d9,_0x49a7d9,_0x49a7d9);}}else{_0x22554f=_[_0xad2e('0x75')](_0x36b103,[_0xad2e('0x2d'),_0xad2e('0x76')]);_0x470bda[_0xad2e('0x57')]=_0xad2e('0x76');_0x46bf5e=as[_0xad2e('0x77')](_0x5d538c,_0x22554f['type'],_0x470bda);_0x1ce266[_0x3bfa74](_0x46bf5e[_0xad2e('0x78')],_0x46bf5e['value']['start'],_0x46bf5e[_0xad2e('0x6d')][_0xad2e('0x23')]);}break;case'Tag':var _0x33846a=_0x470bda[_0xad2e('0x6d')][_0xad2e('0x3a')](',')['map'](function(_0x1e5f05){return Number(_0x1e5f05);});_0x33846a['forEach'](function(_0x1469a2){_0x124eaf['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x1469a2+',%');});_0x745c47=_[_0xad2e('0x79')](_0x745c47,_0x33846a);break;case _0xad2e('0x7a'):if(_0x470bda[_0xad2e('0x72')]===_0xad2e('0x73')){_0x1ce266[_0x3bfa74](_0xad2e('0x7b'),'%'+_0x470bda[_0xad2e('0x6d')]+'%',null);}else{_0x22554f=_['find'](_0x36b103,['name',_0xad2e('0x42')]);_0x470bda[_0xad2e('0x57')]=_0xad2e('0x42');_0x46bf5e=as[_0xad2e('0x77')](_0x5d538c,_0x22554f['type'],_0x470bda);_0x1ce266[_0x3bfa74](_0x46bf5e[_0xad2e('0x78')],_0x46bf5e[_0xad2e('0x6d')][_0xad2e('0x7c')],_0x46bf5e[_0xad2e('0x6d')][_0xad2e('0x23')]);}break;case _0xad2e('0x31'):_0x46bf5e=as[_0xad2e('0x77')]('me',null,_0x470bda);_0x1ce266[_0x3bfa74](_0x46bf5e[_0xad2e('0x78')],_0x46bf5e[_0xad2e('0x6d')]['start'],_0x46bf5e[_0xad2e('0x6d')][_0xad2e('0x23')]);break;}}else{var _0x46bf5e=as['buildExpression'](_0x5d538c,_0x22554f[_0xad2e('0x49')],_0x470bda);_0x1ce266[_0x3bfa74](_0x46bf5e[_0xad2e('0x78')],_0x46bf5e[_0xad2e('0x6d')][_0xad2e('0x7c')],_0x46bf5e[_0xad2e('0x6d')][_0xad2e('0x23')]);}}}else{var _0x4cf84e=_(_0x4c99ec['query'])['keys']()['map'](function(_0xa426c8){return _[_0xad2e('0x7d')](_0x36b103,['name',_0xa426c8])?_0xa426c8:undefined;})[_0xad2e('0x7e')]()[_0xad2e('0x6d')]();if(!_[_0xad2e('0x7f')](_0x4cf84e)){_0x4cf84e[_0xad2e('0x3b')](function(_0x13491c){if(_0x13491c===_0xad2e('0x80')){_0xe2d4ac[_0xad2e('0x54')](_0xad2e('0x81'),[]['concat'](_0x4c99ec['query'][_0x13491c]));}else if(_0x13491c==='createdAt'){var _0x4eb716=JSON['parse'](_0x4c99ec[_0xad2e('0x4c')][_0x13491c])['$gte'];var _0x3bdc76=JSON[_0xad2e('0x82')](_0x4c99ec[_0xad2e('0x4c')][_0x13491c])['$lte'];_0xe2d4ac['where'](_0xad2e('0x83'),_0x4eb716,_0x3bdc76);}else{if(_0x4c99ec['query'][_0x13491c]==='null'){_0xe2d4ac[_0xad2e('0x54')]('i.'+_0x13491c+_0xad2e('0x84'));}else{_0xe2d4ac[_0xad2e('0x54')]('i.'+_0x13491c+_0xad2e('0x85'),_0x4c99ec[_0xad2e('0x4c')][_0x13491c]);}}});}if(_0x4c99ec[_0xad2e('0x4c')][_0xad2e('0x86')]){if(_0x4c99ec[_0xad2e('0x4c')][_0xad2e('0x86')]==0x1){_0xe2d4ac[_0xad2e('0x6e')]('`unreadMessages`\x20=\x200');}else{_0xe2d4ac['having'](_0xad2e('0x87'));}}if(_0x4c99ec[_0xad2e('0x4c')]['tag']){_0x745c47=_[_0xad2e('0x88')](_0x4c99ec[_0xad2e('0x4c')]['tag'])?_0x4c99ec['query'][_0xad2e('0x89')]:new Array(_0x4c99ec[_0xad2e('0x4c')][_0xad2e('0x89')]);_0x745c47[_0xad2e('0x3b')](function(_0x11421f){_0x124eaf['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x11421f+',%');});}if(_0x4c99ec[_0xad2e('0x4c')]['filter']){var _0x76b71a=_0x4c99ec[_0xad2e('0x4c')]['filter'][_0xad2e('0x8a')]('\x5c','\x5c\x5c')[_0xad2e('0x8a')](/'/g,'\x27\x27');if(qs[_0xad2e('0x8b')](_0x76b71a)){_0x1ce266['or']('i.id\x20LIKE\x20?',_0x76b71a+'%');}else{_0x1ce266['or'](_0xad2e('0x8c'),qs[_0xad2e('0x8d')](_0x76b71a))['or'](_0xad2e('0x8e'),_0x76b71a+'%');}}}_0xe2d4ac[_0xad2e('0x54')](_0x1ce266);_0xe2d4ac[_0xad2e('0x8f')]('i.id');var _0x2ea2d8={'type':db['Sequelize'][_0xad2e('0x90')][_0xad2e('0x91')],'raw':!![]};var _0x10672d=_0xe2d4ac[_0xad2e('0x92')]();_0x10672d[_0xad2e('0x57')](_0xad2e('0x93'));_0x10672d[_0xad2e('0x57')](_0xad2e('0x94'),_0xad2e('0x6c'));if(_0x579a26[_0xad2e('0x52')]){_0x579a26[_0xad2e('0x52')][_0xad2e('0x3b')](function(_0x4a7a2e){var _0x1f2c13=_0x4a7a2e[0x0]===_0xad2e('0x95')?_0x4a7a2e[0x0]:'i.'+_0x4a7a2e[0x0];_0xe2d4ac[_0xad2e('0x52')](_0x1f2c13,_0x4a7a2e[0x1]===_0xad2e('0x96')?![]:!![]);});}if(!_['isEmpty'](_0x745c47)){_0xe2d4ac[_0xad2e('0x6e')](_0x124eaf);_0x10672d[_0xad2e('0x54')](_0xad2e('0x97'),_0x745c47);}BPromise[_0xad2e('0x98')]()['then'](function(){if(!_0x583c12){if(_0x4c99ec[_0xad2e('0x4c')][_0xad2e('0x80')])return;_0x10672d[_0xad2e('0x54')]('i.ChatWebsiteId\x20IS\x20NOT\x20NULL');_0xe2d4ac[_0xad2e('0x54')](_0xad2e('0x99'));return;}if(_0x4c99ec[_0xad2e('0x9a')][_0xad2e('0x9b')]!=='agent')return;return _0x4c99ec[_0xad2e('0x9a')][_0xad2e('0x9c')]({'attributes':['id'],'raw':!![]})[_0xad2e('0x2b')](function(_0xc55f6a){if(_[_0xad2e('0x7f')](_0xc55f6a)){_0x10672d[_0xad2e('0x54')](_0xad2e('0x9d'));_0xe2d4ac[_0xad2e('0x54')]('i.ChatWebsiteId\x20IS\x20NULL');}else{_0x10672d[_0xad2e('0x54')]('i.ChatWebsiteId\x20IN\x20?',_['map'](_0xc55f6a,'id'));_0xe2d4ac[_0xad2e('0x54')](_0xad2e('0x81'),_[_0xad2e('0x36')](_0xc55f6a,'id'));}});})[_0xad2e('0x2b')](function(){if(_0x4c99ec[_0xad2e('0x9a')][_0xad2e('0x9b')]===_0xad2e('0x33')&&!_0x583c12&&!_0x4c99ec[_0xad2e('0x4c')][_0xad2e('0x80')])return[];return db[_0xad2e('0x9e')][_0xad2e('0x4c')](_0x10672d[_0xad2e('0x9f')](),_0x2ea2d8);})['then'](function(_0x2f029b){_0x2ad66e[_0xad2e('0x27')]=_0x2f029b[_0xad2e('0x50')];if(_0x2ad66e[_0xad2e('0x27')]===0x0)return[];return db[_0xad2e('0x9e')][_0xad2e('0x4c')](_0x411956[_0xad2e('0x9f')](),_0x2ea2d8)[_0xad2e('0x2b')](function(_0x35d060){_0x4aeb4a=_[_0xad2e('0xa0')](_0x35d060,'id');_0x2ea2d8=_['merge'](_0x2ea2d8,{'model':db[_0xad2e('0x47')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x4c99ec[_0xad2e('0x4c')][_0xad2e('0x4e')]){_0x579a26[_0xad2e('0x4f')]['forEach'](function(_0x3c95ac){_0xe2d4ac['field']('i.'+_0x3c95ac);});}else{_0xe2d4ac[_0xad2e('0x57')](_0xad2e('0x94'),_0xad2e('0x6c'));_0xe2d4ac[_0xad2e('0x57')](_0xad2e('0xa1'),_0xad2e('0xa2'));_0xe2d4ac[_0xad2e('0x57')]('a.mandatoryDisposition',_0xad2e('0xa3'));_0xe2d4ac[_0xad2e('0x57')]('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','contactName');_0xe2d4ac[_0xad2e('0x57')]('i.*');_0xe2d4ac[_0xad2e('0x57')](_0xad2e('0xa4'),'Contact.firstName');_0xe2d4ac['field'](_0xad2e('0xa5'),'Contact.lastName');_0xe2d4ac[_0xad2e('0x57')](_0xad2e('0xa6'),'Contact.email');_0xe2d4ac[_0xad2e('0x57')]('c.phone',_0xad2e('0xa7'));_0xe2d4ac[_0xad2e('0x57')]('c.mobile','Contact.mobile');_0xe2d4ac[_0xad2e('0x57')](_0xad2e('0xa8'),'Contact.fax');_0xe2d4ac[_0xad2e('0x57')](_0xad2e('0xa9'),'Owner.fullname');_0xe2d4ac[_0xad2e('0x57')](_0xad2e('0xaa'),_0xad2e('0xab'));_0xe2d4ac[_0xad2e('0x57')](_0xad2e('0xac'),'TagIds');}if(_0x579a26[_0xad2e('0x28')])_0xe2d4ac[_0xad2e('0x28')](_0x579a26[_0xad2e('0x28')]);if(_0x579a26[_0xad2e('0x25')])_0xe2d4ac['offset'](_0x579a26[_0xad2e('0x25')]);return db['sequelize'][_0xad2e('0x4c')](_0xe2d4ac['toString'](),_0x2ea2d8);})[_0xad2e('0x2b')](function(_0x3692ec){if(_0x3692ec[_0xad2e('0x50')]>0x0)_0x56e633[_0xad2e('0x54')]('ui.ChatInteractionId\x20IN\x20?',_[_0xad2e('0x36')](_0x3692ec,'id'));return db[_0xad2e('0x9e')][_0xad2e('0x4c')](_0x56e633[_0xad2e('0x9f')](),_0x2ea2d8)['then'](function(_0x6a83f7){var _0x23f261=_[_0xad2e('0xad')](_0x6a83f7,'ChatInteractionId');var _0x45c0f6=[];_0x3692ec[_0xad2e('0x3b')](function(_0x10337a){_0x45c0f6['push'](updateChatInteraction(_0x10337a,_0x4aeb4a,_0x23f261));});return BPromise[_0xad2e('0xae')](_0x45c0f6);});});})[_0xad2e('0x2b')](function(_0x44708f){_0x2ad66e[_0xad2e('0xaf')]=_0x44708f;return _0x2ad66e;})[_0xad2e('0x2b')](respondWithFilteredResult(_0x15e253,_0x579a26))[_0xad2e('0x20')](handleError(_0x15e253,null));};exports['show']=function(_0x519618,_0x3f6971){var _0x114ff1={'raw':![],'where':{'id':_0x519618['params']['id']}},_0x495392={};_0x495392[_0xad2e('0x4b')]=_[_0xad2e('0x4d')](db[_0xad2e('0x47')][_0xad2e('0xb0')]);_0x495392[_0xad2e('0x4c')]=_[_0xad2e('0x4d')](_0x519618['query']);_0x495392['filters']=_[_0xad2e('0xb1')](_0x495392[_0xad2e('0x4b')],_0x495392[_0xad2e('0x4c')]);_0x114ff1['attributes']=_[_0xad2e('0xb1')](_0x495392[_0xad2e('0x4b')],qs[_0xad2e('0x4e')](_0x519618['query'][_0xad2e('0x4e')]));_0x114ff1['attributes']=_0x114ff1[_0xad2e('0x4f')][_0xad2e('0x50')]?_0x114ff1[_0xad2e('0x4f')]:_0x495392[_0xad2e('0x4b')];if(_0x519618[_0xad2e('0x4c')]['includeAll']){_0x114ff1['include']=[{'all':!![]}];}_0x114ff1=_['merge']({},_0x114ff1,_0x519618[_0xad2e('0xb2')]);return db[_0xad2e('0x47')][_0xad2e('0x75')](_0x114ff1)[_0xad2e('0x2b')](handleEntityNotFound(_0x3f6971,null))['then'](respondWithResult(_0x3f6971,null))[_0xad2e('0x20')](handleError(_0x3f6971,null));};exports[_0xad2e('0xb3')]=function(_0x413235,_0x4c5051){return db[_0xad2e('0x47')]['create'](_0x413235[_0xad2e('0x31')],{})[_0xad2e('0x2b')](respondWithResult(_0x4c5051,0xc9))[_0xad2e('0x20')](handleError(_0x4c5051,null));};exports[_0xad2e('0x2a')]=function(_0x284cd4,_0x1f49ee){if(_0x284cd4[_0xad2e('0x31')]['id']){delete _0x284cd4[_0xad2e('0x31')]['id'];}return db[_0xad2e('0x47')][_0xad2e('0x75')]({'where':{'id':_0x284cd4[_0xad2e('0xb4')]['id']}})[_0xad2e('0x2b')](handleEntityNotFound(_0x1f49ee,null))[_0xad2e('0x2b')](saveUpdates(_0x284cd4[_0xad2e('0x31')],null))[_0xad2e('0x2b')](respondWithResult(_0x1f49ee,null))[_0xad2e('0x20')](handleError(_0x1f49ee,null));};exports['destroy']=function(_0x2d358a,_0x39f3d7){return db['ChatInteraction'][_0xad2e('0x75')]({'where':{'id':_0x2d358a['params']['id']}})[_0xad2e('0x2b')](handleEntityNotFound(_0x39f3d7,null))[_0xad2e('0x2b')](removeEntity(_0x39f3d7,null))[_0xad2e('0x20')](handleError(_0x39f3d7,null));};exports['describe']=function(_0x5345fe,_0x40dd77){return db['ChatInteraction'][_0xad2e('0xb5')]()[_0xad2e('0x2b')](respondWithResult(_0x40dd77,null))['catch'](handleError(_0x40dd77,null));};exports[_0xad2e('0xb6')]=function(_0x271306,_0x34685b){var _0x3a447a=_0x271306['params']['id'];var _0x574f67;var _0x4ef473;var _0x843547;return db[_0xad2e('0x47')][_0xad2e('0xb7')]({'where':{'id':_0x3a447a}})[_0xad2e('0x2b')](function(_0x3a70de){_0x574f67=_0x3a70de;return db[_0xad2e('0xb8')]['findOne']({'where':{'id':_0x3a70de[_0xad2e('0x80')]},'attributes':['id','vidaooApiKey',_0xad2e('0xb9'),_0xad2e('0xba'),_0xad2e('0xbb'),_0xad2e('0xbc')],'raw':!![]});})[_0xad2e('0x2b')](function(_0x2fe953){if(_0x2fe953&&_0x2fe953[_0xad2e('0xbd')]&&_0x2fe953[_0xad2e('0xb9')]){_0x4ef473=_0x2fe953;var _0x4a14de={'interaction':{'id':_0x3a447a},'agent':{'id':_0x271306['user']['id'],'name':_0x271306[_0xad2e('0x9a')][_0xad2e('0x2d')],'fullname':_0x271306['user'][_0xad2e('0x37')],'email':_0x271306[_0xad2e('0x9a')][_0xad2e('0xbe')]},'contact':_0x271306[_0xad2e('0x31')][_0xad2e('0x32')],'account':_0x271306[_0xad2e('0x31')]['account']};var _0x528e42={'rejectUnauthorized':![],'method':_0xad2e('0xbf'),'url':_0xad2e('0xc0'),'headers':{'X-APIKEY':_0x2fe953[_0xad2e('0xbd')]},'body':{'duration':null,'scheduledAt':null,'participants':[_0x271306['user']['email']],'buttons':null,'topic':_0x4ef473[_0xad2e('0xba')],'note':_[_0xad2e('0xc1')](_0x4ef473[_0xad2e('0xbb')])?null:getMustacheRender(_0x4ef473[_0xad2e('0xbb')],_0x4a14de),'metadata':null},'redirect':_0xad2e('0xc2'),'json':!![]};try{if(!_[_0xad2e('0xc1')](_0x4ef473[_0xad2e('0xbc')])){var _0xf710d=getMustacheRender(_0x4ef473[_0xad2e('0xbc')],_0x4a14de);var _0x2a59af=JSON['parse'](_0xf710d);_0x528e42['body'][_0xad2e('0xc3')]=_0x2a59af;}}catch(_0x447f04){throw new db[(_0xad2e('0xc4'))][(_0xad2e('0xc5'))](_0xad2e('0xc6'));}return rp(_0x528e42);}else{throw new db['Sequelize'][(_0xad2e('0xc5'))]('Error\x20in\x20Vidaoo\x20configuration');}})['then'](function(_0x529069){_0x843547=_0x529069;if(_0x843547['id']){var _0x209d06={'body':_0x843547[_0xad2e('0xc7')],'ChatWebsiteId':_0x4ef473['id'],'ChatInteractionId':_0x574f67['id'],'direction':'out','UserId':_0x271306['user']['id']};return db[_0xad2e('0xc8')][_0xad2e('0xb3')](_0x209d06,{});}else{throw new db['Sequelize'][(_0xad2e('0xc5'))](_0xad2e('0xc9'));}})[_0xad2e('0x2b')](function(){return _0x574f67[_0xad2e('0xca')]({'vidaooSessionId':_0x843547['id']});})[_0xad2e('0x2b')](respondWithResult(_0x34685b,null))['catch'](handleError(_0x34685b,null));};exports[_0xad2e('0xcb')]=function(_0x3b2c9a,_0x1f7222){if(_0x3b2c9a[_0xad2e('0x31')]['id']){delete _0x3b2c9a[_0xad2e('0x31')]['id'];}return db[_0xad2e('0x47')]['find']({'where':{'id':_0x3b2c9a[_0xad2e('0xb4')]['id']},'include':[{'model':db[_0xad2e('0xcc')],'as':'Contact'}]})[_0xad2e('0x2b')](handleEntityNotFound(_0x1f7222,null))['then'](saveUpdates(_0x3b2c9a[_0xad2e('0x31')],null))[_0xad2e('0x2b')](respondWithResult(_0x1f7222,null))[_0xad2e('0x20')](handleError(_0x1f7222,null));};exports[_0xad2e('0xcd')]=function(_0x5888fb,_0x1c4530){if(_0x5888fb[_0xad2e('0x31')]['id']){delete _0x5888fb[_0xad2e('0x31')]['id'];}return db[_0xad2e('0x47')][_0xad2e('0x75')]({'where':{'id':_0x5888fb[_0xad2e('0xb4')]['id']}})[_0xad2e('0x2b')](function(_0x1afe03){if(!_0x1afe03){logger[_0xad2e('0x1c')](_0xad2e('0xce'),_0xad2e('0xcd'),0x194,_0xad2e('0xcf'));_0x1c4530[_0xad2e('0x21')](0x194);}else{if(_0x1afe03[_0xad2e('0x42')]){throw new db[(_0xad2e('0xc4'))][(_0xad2e('0xc5'))](_0xad2e('0xd0'));}}return _0x1afe03;})[_0xad2e('0x2b')](function(_0x5f1aaf){if(_0x5f1aaf){return _0x5f1aaf[_0xad2e('0x2a')]({'closed':_0x5888fb[_0xad2e('0x31')][_0xad2e('0x41')],'disposition':_0x5888fb['body']['disposition']})[_0xad2e('0x2b')](function(_0x55b7de){return _0x55b7de;});}})[_0xad2e('0x2b')](function(){return respondWithRpcPromise('AbandonInteraction','abandon',_0x5888fb[_0xad2e('0x31')],client9004);})[_0xad2e('0x2b')](respondWithResult(_0x1c4530,null))[_0xad2e('0x20')](handleError(_0x1c4530,null));};exports[_0xad2e('0xd1')]=function(_0x394518,_0xa25ed2){_0x394518['body']['name']=_0x394518[_0xad2e('0xd2')][_0xad2e('0xd3')];_0x394518[_0xad2e('0x31')]['basename']=_0x394518['file'][_0xad2e('0xd4')];_0x394518[_0xad2e('0x31')]['type']=_0x394518[_0xad2e('0xd2')]['mimetype'];return db[_0xad2e('0xd5')][_0xad2e('0xb3')](_0x394518[_0xad2e('0x31')])[_0xad2e('0x2b')](respondWithResult(_0xa25ed2,0xc9))[_0xad2e('0x20')](handleError(_0xa25ed2,null));};exports[_0xad2e('0xd6')]=function(_0x57ed5c,_0x1e9ade){return db[_0xad2e('0x47')]['findOne']({'where':{'id':_0x57ed5c[_0xad2e('0xb4')]['id']},'raw':!![]})[_0xad2e('0x2b')](handleEntityNotFound(_0x1e9ade,null))[_0xad2e('0x2b')](function(_0x360d04){if(_0x360d04){if(_0x360d04[_0xad2e('0x41')]){return _0x1e9ade[_0xad2e('0x22')](0x193)[_0xad2e('0x24')]({'status':0x193,'message':'Unauthorized'});}return db[_0xad2e('0xd5')]['findOne']({'where':{'id':_0x57ed5c[_0xad2e('0x4c')][_0xad2e('0xd7')]},'raw':!![]})[_0xad2e('0x2b')](handleEntityNotFound(_0x1e9ade,null));}})[_0xad2e('0x2b')](function(_0x1466fd){if(_0x1466fd){var _0x9b10b=_0x1466fd[_0xad2e('0xd8')]!==null;var _0x4f546b=path['join'](config[_0xad2e('0xd9')],_0xad2e('0xda'));if(_0x9b10b){_0x4f546b=path[_0xad2e('0xdb')](_0x4f546b,_0xad2e('0xdc'));}var _0x255aa0=path[_0xad2e('0xdb')](_0x4f546b,_0x1466fd[_0xad2e('0xdd')]);return _0x1e9ade[_0xad2e('0xde')](_0x255aa0);}})['catch'](handleError(_0x1e9ade,null));};exports['close']=function(_0xa94b3f,_0x203105){var _0x4d18b4=null;var _0x15a98d=null;var _0x2c5621=null;if(_0xa94b3f[_0xad2e('0x31')]['id']){delete _0xa94b3f[_0xad2e('0x31')]['id'];}if(_0xa94b3f[_0xad2e('0x31')][_0xad2e('0xdf')]){_0x2c5621=path[_0xad2e('0xdb')](config[_0xad2e('0xd9')],_0xad2e('0xe0'),util[_0xad2e('0xe1')]('transcript-%s.txt',Date[_0xad2e('0xe2')]()));_0xa94b3f[_0xad2e('0x31')][_0xad2e('0xe3')]=_0x2c5621;}return db[_0xad2e('0x47')][_0xad2e('0x75')]({'where':{'id':_0xa94b3f[_0xad2e('0xb4')]['id']},'include':[{'model':db['ChatMessage'],'as':'Messages','include':[{'model':db['User'],'as':_0xad2e('0x7a')}]}]})[_0xad2e('0x2b')](handleEntityNotFound(_0x203105,null))['then'](saveUpdates(_0xa94b3f['body'],null))['then'](function(_0x36fa66){if(_0x36fa66){_0x4d18b4=_0x36fa66;return db['ChatWebsite'][_0xad2e('0x75')]({'where':{'id':_0x4d18b4[_0xad2e('0x80')]}});}})['then'](function(_0x3a7e1f){if(_0x3a7e1f){_0x15a98d=_0x3a7e1f;return db[_0xad2e('0xcc')][_0xad2e('0x75')]({'where':{'id':_0x4d18b4[_0xad2e('0x76')]}});}})[_0xad2e('0x2b')](function(_0x2a9579){if(_0x2a9579){if(_0x2c5621){var _0x423e41=null;for(var _0x56aa85=0x1;_0x56aa85<_0x4d18b4['Messages'][_0xad2e('0x50')];++_0x56aa85){_0x423e41=_0x4d18b4[_0xad2e('0xe4')][_0x56aa85];var _0x3efa33=_0x423e41['UserId']?util[_0xad2e('0xe1')](_0xad2e('0xe5'),_0x15a98d[_0xad2e('0xe6')],_0x423e41[_0xad2e('0x42')]):'System';var _0x31250b=_0xa94b3f[_0xad2e('0x31')][_0xad2e('0xe7')]||util[_0xad2e('0xe1')](_0xad2e('0xe5'),_0xad2e('0xe8'),_0x423e41[_0xad2e('0x76')]);switch(_0x15a98d[_0xad2e('0xe9')]){case _0xad2e('0xea'):_0x3efa33=_0x423e41[_0xad2e('0x42')]?util[_0xad2e('0xe1')](_0xad2e('0xe5'),_0x15a98d[_0xad2e('0xe6')],_0x423e41['UserId']):_0xad2e('0xeb');break;case _0xad2e('0xec'):_0x3efa33=_0x423e41[_0xad2e('0x42')]?_0x423e41[_0xad2e('0x7a')][_0xad2e('0xed')]||_0x423e41['User'][_0xad2e('0x37')]:_0xad2e('0xeb');break;case _0xad2e('0xee'):_0x3efa33=_0x423e41[_0xad2e('0x42')]?_0x423e41['User'][_0xad2e('0x37')]:_0xad2e('0xeb');break;default:_0x3efa33=_0x423e41[_0xad2e('0x42')]?util[_0xad2e('0xe1')]('%s%d',_0x15a98d['agentAlias'],_0x423e41[_0xad2e('0x42')]):_0xad2e('0xeb');}var _0x2a1fd3=util['format'](_0xad2e('0xef'),moment(_0x423e41[_0xad2e('0xf0')])[_0xad2e('0xe1')](_0xad2e('0xf1')),_0x423e41[_0xad2e('0xf2')]==='in'?_0x31250b:_0x3efa33,_0x423e41[_0xad2e('0x31')]);if(!_0x423e41[_0xad2e('0xf3')]){fs[_0xad2e('0xf4')](_0x2c5621,_0x2a1fd3);}}return db[_0xad2e('0xf5')][_0xad2e('0xb7')]({'where':{'service':!![]},'include':[{'model':db[_0xad2e('0xf6')],'as':_0xad2e('0xf7'),'raw':!![],'include':[{'model':db['CloudProvider'],'as':_0xad2e('0xf8'),'raw':!![]}]}]});}}})[_0xad2e('0x2b')](function(_0x7ab79a){if(!_0x7ab79a||!_0x7ab79a[_0xad2e('0xf7')]||!_0xa94b3f[_0xad2e('0x31')])return _0x4d18b4;var _0x19dde7=_0x7ab79a['getSmtpOptions']();return respondWithRpcPromise(_0xad2e('0xf9'),_0xad2e('0xfa'),{'account':_0x19dde7,'message':{'from':util[_0xad2e('0xe1')](_0xad2e('0xfb'),_0x7ab79a[_0xad2e('0x2d')],_0x7ab79a[_0xad2e('0xbe')]||_0x7ab79a[_0xad2e('0xf7')][_0xad2e('0x9a')]),'to':_0xa94b3f[_0xad2e('0x31')]['mailTranscript'],'subject':'Mail\x20Transcript','text':util[_0xad2e('0xe1')](_0xad2e('0xfc'),_0xa94b3f['body'][_0xad2e('0xdf')]),'attachments':[{'path':_0x2c5621}]}})['then'](function(){return _0x4d18b4;})[_0xad2e('0x20')](function(_0x33de0b){logger['error'](_0x33de0b);});})['then'](respondWithStatusCode(_0x203105,0xc8))['catch'](handleError(_0x203105,null));};exports[_0xad2e('0xfd')]=function(_0x55947c,_0x1392f0){return db[_0xad2e('0xc8')][_0xad2e('0x75')]({'where':{'id':_0x55947c['params']['id']}})['then'](handleEntityNotFound(_0x1392f0,null))['then'](function(_0x167f32){if(_0x167f32){return _0x167f32['addMessage'](_0x55947c[_0xad2e('0x31')][_0xad2e('0xfe')],_[_0xad2e('0xff')](_0x55947c['body'],[_0xad2e('0xfe'),'id'])||{});}})[_0xad2e('0x2b')](respondWithResult(_0x1392f0,null))['catch'](handleError(_0x1392f0,null));};exports[_0xad2e('0x100')]=function(_0x14ed73,_0x54391f){var _0x52584a={'raw':![],'where':{}};var _0x4ce397={};var _0x2e5acc={'count':0x0,'rows':[]};return db[_0xad2e('0x47')][_0xad2e('0xb7')]({'where':{'id':_0x14ed73[_0xad2e('0xb4')]['id']}})[_0xad2e('0x2b')](handleEntityNotFound(_0x54391f,null))[_0xad2e('0x2b')](function(_0x2f59fd){if(_0x2f59fd){_0x4ce397[_0xad2e('0x4b')]=_[_0xad2e('0x4d')](db[_0xad2e('0xc8')][_0xad2e('0xb0')]);_0x4ce397[_0xad2e('0x4c')]=_[_0xad2e('0x4d')](_0x14ed73['query']);_0x4ce397[_0xad2e('0x55')]=_[_0xad2e('0xb1')](_0x4ce397['model'],_0x4ce397[_0xad2e('0x4c')]);_0x52584a[_0xad2e('0x4f')]=_[_0xad2e('0xb1')](_0x4ce397['model'],qs[_0xad2e('0x4e')](_0x14ed73['query'][_0xad2e('0x4e')]));_0x52584a[_0xad2e('0x4f')]=_0x52584a[_0xad2e('0x4f')][_0xad2e('0x50')]?_0x52584a[_0xad2e('0x4f')]:_0x4ce397[_0xad2e('0x4b')];if(!_0x14ed73['query'][_0xad2e('0x101')](_0xad2e('0x51'))){_0x52584a[_0xad2e('0x28')]=qs[_0xad2e('0x28')](_0x14ed73['query']['limit']);_0x52584a['offset']=qs['offset'](_0x14ed73[_0xad2e('0x4c')]['offset']);}_0x52584a[_0xad2e('0x52')]=qs[_0xad2e('0x53')](_0x14ed73['query'][_0xad2e('0x53')]);_0x52584a[_0xad2e('0x54')]=qs[_0xad2e('0x55')](_[_0xad2e('0x56')](_0x14ed73[_0xad2e('0x4c')],_0x4ce397[_0xad2e('0x55')]));_0x52584a[_0xad2e('0x54')][_0xad2e('0x102')]=_0x2f59fd['id'];if(_0x14ed73['query']['filter']){_0x52584a[_0xad2e('0x54')]=_[_0xad2e('0x30')](_0x52584a[_0xad2e('0x54')],{'$or':_[_0xad2e('0x36')](_0x52584a[_0xad2e('0x4f')],function(_0x5b9636){var _0x5c9dc0={};_0x5c9dc0[_0x5b9636]={'$like':'%'+_0x14ed73[_0xad2e('0x4c')][_0xad2e('0x103')]+'%'};return _0x5c9dc0;})});}if(_0x14ed73['query'][_0xad2e('0x104')]){var _0x4c70b8=_0x14ed73[_0xad2e('0x4c')][_0xad2e('0x104')][_0xad2e('0x3a')](',');var _0x180166={};_0x180166[_0x4c70b8[0x0]]={'$gte':moment(_0x4c70b8[0x1])[_0xad2e('0xe1')]('YYYY-MM-DD\x20HH:mm:ss')};_0x52584a[_0xad2e('0x54')]=_['merge'](_0x52584a['where'],_0x180166);}_0x52584a=_[_0xad2e('0x30')]({},_0x52584a,_0x14ed73[_0xad2e('0xb2')]);return db[_0xad2e('0xc8')][_0xad2e('0x27')]({'where':_0x52584a[_0xad2e('0x54')]})[_0xad2e('0x2b')](function(_0x14b851){_0x2e5acc['count']=_0x14b851;if(_0x14ed73[_0xad2e('0x4c')]['includeAll']){_0x52584a['include']=[{'all':!![]}];}return db['ChatMessage'][_0xad2e('0x105')](_0x52584a);})[_0xad2e('0x2b')](function(_0x4f28e2){_0x2e5acc['rows']=_0x4f28e2;return _0x2e5acc;});}})[_0xad2e('0x2b')](respondWithFilteredResult(_0x54391f,_0x52584a))[_0xad2e('0x20')](handleError(_0x54391f,null));};exports[_0xad2e('0x106')]=function(_0x59df92,_0x34bbc6){var _0x54feb5={'where':{}},_0x4a6fa3={},_0x4d4a27={'count':0x0,'rows':[]};return db['ChatInteraction'][_0xad2e('0xb7')]({'where':{'id':_0x59df92['params']['id']}})['then'](handleEntityNotFound(_0x34bbc6,null))[_0xad2e('0x2b')](function(_0x2dcb83){if(_0x2dcb83){_0x4a6fa3[_0xad2e('0x4b')]=_['keys'](db['ChatMessage'][_0xad2e('0xb0')]);_0x4a6fa3[_0xad2e('0x4c')]=_[_0xad2e('0x4d')](_0x59df92['query']);_0x4a6fa3[_0xad2e('0x55')]=_[_0xad2e('0xb1')](_0x4a6fa3['model'],_0x4a6fa3[_0xad2e('0x4c')]);_0x54feb5[_0xad2e('0x4f')]=_[_0xad2e('0xb1')](_0x4a6fa3[_0xad2e('0x4b')],qs[_0xad2e('0x4e')](_0x59df92[_0xad2e('0x4c')][_0xad2e('0x4e')]));_0x54feb5[_0xad2e('0x4f')]=_0x54feb5['attributes'][_0xad2e('0x50')]?_0x54feb5['attributes']:_0x4a6fa3[_0xad2e('0x4b')];if(!_0x59df92[_0xad2e('0x4c')]['hasOwnProperty']('nolimit')){_0x54feb5[_0xad2e('0x28')]=qs[_0xad2e('0x28')](_0x59df92[_0xad2e('0x4c')][_0xad2e('0x28')]);_0x54feb5['offset']=qs[_0xad2e('0x25')](_0x59df92['query'][_0xad2e('0x25')]);}_0x54feb5[_0xad2e('0x52')]=qs[_0xad2e('0x53')](_0x59df92[_0xad2e('0x4c')][_0xad2e('0x53')]);_0x54feb5[_0xad2e('0x54')]=qs[_0xad2e('0x55')](_[_0xad2e('0x56')](_0x59df92[_0xad2e('0x4c')],_0x4a6fa3[_0xad2e('0x55')]));_0x54feb5[_0xad2e('0x54')][_0xad2e('0x102')]=_0x2dcb83['id'];if(_0x59df92['query'][_0xad2e('0x103')]){_0x54feb5[_0xad2e('0x54')]=_['merge'](_0x54feb5[_0xad2e('0x54')],{'$or':_[_0xad2e('0x36')](_0x54feb5[_0xad2e('0x4f')],function(_0x5a85a4){var _0x20bca3={};_0x20bca3[_0x5a85a4]={'$like':'%'+_0x59df92[_0xad2e('0x4c')]['filter']+'%'};return _0x20bca3;})});}_0x54feb5[_0xad2e('0x54')][_0xad2e('0xf3')]=![];if(_0x59df92[_0xad2e('0x4c')]['id']){_0x54feb5[_0xad2e('0x54')]['id']={'$gt':_0x59df92[_0xad2e('0x4c')]['id']};}_0x54feb5=_[_0xad2e('0x30')]({},_0x54feb5,_0x59df92[_0xad2e('0xb2')]);return db['ChatMessage']['count']({'where':_0x54feb5['where']})[_0xad2e('0x2b')](function(_0x1cfdda){_0x4d4a27[_0xad2e('0x27')]=_0x1cfdda;_0x54feb5[_0xad2e('0x107')]=[];if(_0x59df92['query']['includeAgent']){_0x54feb5[_0xad2e('0x107')][_0xad2e('0x3c')]({'model':db['User'],'as':_0xad2e('0x7a'),'attributes':['id',_0xad2e('0x37'),'alias']});}if(_0x59df92[_0xad2e('0x4c')]['includeAll']){_0x54feb5[_0xad2e('0x107')]=[{'all':!![]}];}return db[_0xad2e('0xc8')]['findAll'](_0x54feb5);})[_0xad2e('0x2b')](function(_0x2cf359){_0x4d4a27['rows']=_0x2cf359;return _0x4d4a27;});}})['then'](respondWithFilteredResult(_0x34bbc6,_0x54feb5))[_0xad2e('0x20')](handleError(_0x34bbc6,null));};exports[_0xad2e('0x108')]=function(_0x492b7e,_0xad9fab){return db['ChatInteraction'][_0xad2e('0x75')]({'where':{'id':_0x492b7e[_0xad2e('0xb4')]['id']}})[_0xad2e('0x2b')](handleEntityNotFound(_0xad9fab,null))[_0xad2e('0x2b')](function(_0x2331f1){if(_0x2331f1){return _0x2331f1['setTags'](_0x492b7e['body'][_0xad2e('0xfe')],_[_0xad2e('0xff')](_0x492b7e[_0xad2e('0x31')],['ids','id'])||{})[_0xad2e('0x109')](function(){return db[_0xad2e('0x10a')][_0xad2e('0x105')]({'attributes':['id',_0xad2e('0x2d'),_0xad2e('0x10b')],'where':{'id':_0x492b7e[_0xad2e('0x31')][_0xad2e('0xfe')]}});})[_0xad2e('0x2b')](function(_0x21964b){socket[_0xad2e('0x10c')](_0xad2e('0x10d'),{'id':Number(_0x492b7e['params']['id']),'tags':_0x21964b||[]});return{'id':Number(_0x492b7e[_0xad2e('0xb4')]['id']),'tags':_0x21964b||[]};});}})[_0xad2e('0x2b')](respondWithResult(_0xad9fab,null))['catch'](handleError(_0xad9fab,null));};exports[_0xad2e('0x10e')]=function(_0x8bb3c4,_0x453fa7){return db[_0xad2e('0x47')][_0xad2e('0x75')]({'where':{'id':_0x8bb3c4['params']['id']}})[_0xad2e('0x2b')](handleEntityNotFound(_0x453fa7,null))[_0xad2e('0x2b')](function(_0x27ad41){if(_0x27ad41){return _0x27ad41[_0xad2e('0x10e')](_0x8bb3c4[_0xad2e('0x4c')][_0xad2e('0xfe')]);}})[_0xad2e('0x2b')](respondWithStatusCode(_0x453fa7,null))[_0xad2e('0x20')](handleError(_0x453fa7,null));};exports[_0xad2e('0xde')]=function(_0x40e752,_0x4c7c51){var _0x12a370=moment()['unix']()[_0xad2e('0x9f')]();var _0x853563=path[_0xad2e('0xdb')](config[_0xad2e('0xd9')],_0xad2e('0x10f'),'files',_0xad2e('0x110'));var _0x10eb76=path[_0xad2e('0xdb')](config['root'],_0xad2e('0x10f'),_0xad2e('0x111'),_0xad2e('0x112'));var _0x2dbfbd=path['join'](_0x853563,_0x12a370);var _0x56ac2d=util[_0xad2e('0xe1')]('transcript-%d-%s.zip',_0x40e752[_0xad2e('0xb4')]['id'],_0x12a370);var _0xf892e9=path[_0xad2e('0xdb')](_0x853563,_0x56ac2d);var _0x414763=[];_0x414763[_0xad2e('0x3c')]({'model':db[_0xad2e('0x7a')],'as':_0xad2e('0x7a'),'attributes':['id',_0xad2e('0x37')],'raw':!![]});_0x414763[_0xad2e('0x3c')]({'model':db[_0xad2e('0xcc')],'as':'Contact','attributes':['id',_0xad2e('0x113'),_0xad2e('0x114')],'raw':!![]});if(_0x40e752[_0xad2e('0x4c')][_0xad2e('0x112')]){_0x414763['push']({'model':db[_0xad2e('0xd5')],'as':_0xad2e('0xd5'),'raw':!![]});}var _0x366ebe=[{'model':db['ChatMessage'],'as':_0xad2e('0xe4'),'attributes':['id',_0xad2e('0x31'),'createdAt',_0xad2e('0xf2'),_0xad2e('0xf3'),_0xad2e('0x86')],'include':_0x414763}];_0x366ebe[_0xad2e('0x3c')]({'model':db[_0xad2e('0xb8')],'as':_0xad2e('0x115'),'attributes':['id','name']});_0x366ebe[_0xad2e('0x3c')]({'model':db[_0xad2e('0x7a')],'as':_0xad2e('0x116'),'attributes':['id',_0xad2e('0x37')]});return db[_0xad2e('0x47')]['find']({'where':{'id':_0x40e752[_0xad2e('0xb4')]['id']},'include':_0x366ebe})[_0xad2e('0x2b')](handleEntityNotFound(_0x4c7c51,null))[_0xad2e('0x2b')](function(_0x6d6ab1){if(_0x6d6ab1){var _0x2e8154=_0x6d6ab1[_0xad2e('0x117')]({'plain':!![]});fs[_0xad2e('0x118')](_0x2dbfbd);var _0x1d7adc={'channel':_0xad2e('0x119'),'account':_0x2e8154['Account'][_0xad2e('0x2d')],'agent':_0x2e8154[_0xad2e('0x116')]?_0x2e8154[_0xad2e('0x116')][_0xad2e('0x37')]:_0xad2e('0x11a'),'createdAt':moment(_0x2e8154[_0xad2e('0xf0')])['format'](_0xad2e('0x11b'))[_0xad2e('0x9f')](),'closedAt':_0x2e8154[_0xad2e('0x41')]?moment(_0x2e8154[_0xad2e('0x11c')])[_0xad2e('0xe1')](_0xad2e('0x11b'))[_0xad2e('0x9f')]():'','disposition':_0x2e8154[_0xad2e('0x43')],'chatInfo':{'browser':_0x2e8154[_0xad2e('0x11d')],'os':_0x2e8154[_0xad2e('0x11e')],'referer':_0x2e8154[_0xad2e('0x11f')],'customerIp':_0x2e8154[_0xad2e('0x120')],'customerPort':_0x2e8154[_0xad2e('0x121')]?_0x2e8154[_0xad2e('0x121')]:'N.A.'},'messages':_(_0x2e8154[_0xad2e('0xe4')])[_0xad2e('0x122')]()[_0xad2e('0x103')]({'secret':![]})['map'](function(_0x4fbe64){if(_0x4fbe64[_0xad2e('0xd5')]){var _0x424b02=path[_0xad2e('0xdb')](_0x10eb76,_0x4fbe64['Attachment'][_0xad2e('0xdd')]);if(fs['existsSync'](_0x424b02)){fs['createReadStream'](_0x424b02)[_0xad2e('0x123')](fs[_0xad2e('0x124')](path[_0xad2e('0xdb')](_0x2dbfbd,_0x4fbe64[_0xad2e('0xd5')][_0xad2e('0xdd')])));}}return{'date':moment(_0x4fbe64[_0xad2e('0xf0')])['format'](_0xad2e('0x11b'))[_0xad2e('0x9f')](),'sender':_0x4fbe64['direction']===_0xad2e('0x125')?_0x4fbe64[_0xad2e('0x7a')]?_0x4fbe64[_0xad2e('0x7a')][_0xad2e('0x37')]:'System':_0x4fbe64[_0xad2e('0x71')][_0xad2e('0x113')]+(_0x4fbe64['Contact'][_0xad2e('0x114')]?'\x20'+_0x4fbe64['Contact']['lastName']:''),'body':_0x4fbe64[_0xad2e('0xd5')]?_0x4fbe64[_0xad2e('0xd5')][_0xad2e('0xdd')]:_0x4fbe64[_0xad2e('0x31')],'direction':_0x4fbe64[_0xad2e('0xf2')]===_0xad2e('0x125')?'A':'C','secret':_0x4fbe64[_0xad2e('0xf3')],'read':_0x4fbe64[_0xad2e('0x86')],'attachment':_0x4fbe64['Attachment']};})[_0xad2e('0x6d')]()};return ejs[_0xad2e('0x126')](path[_0xad2e('0xdb')](config[_0xad2e('0xd9')],_0xad2e('0x10f'),_0xad2e('0x127'),_0xad2e('0x128')),{'interaction':_0x1d7adc})[_0xad2e('0x2b')](function(_0x25057b){var _0x30ac7f=path['join'](_0x2dbfbd,'transcript-'+_0x2e8154['id']+'-'+_0x12a370+'.pdf');var _0x5839ae={'path':_0x30ac7f,'channel':'Chat','interactionId':_0x2e8154['id']};return pdf[_0xad2e('0x129')](_0x25057b,_0x5839ae);})[_0xad2e('0x2b')](function(){return new Promise(function(_0x4db1d3,_0x50c6a0){zipdir(_0x2dbfbd,{'saveTo':_0xf892e9},function(_0x300d87,_0x1afd35){if(_0x300d87)return _0x50c6a0(_0x300d87);return _0x4db1d3(_0x1afd35);});})[_0xad2e('0x2b')](function(){return new BPromise(function(_0x231853,_0x1a60d6){rimraf(_0x2dbfbd,function(_0x2812f9){if(_0x2812f9)_0x1a60d6(_0x2812f9);return _0x231853();});});})['then'](function(){return _0x4c7c51[_0xad2e('0xde')](_0xf892e9,_0x56ac2d,function(_0x3ff14a){if(_0x3ff14a){logger[_0xad2e('0x1c')]('err',_0x3ff14a);}else{fs[_0xad2e('0x12a')](_0xf892e9);}});});});}else{return _0x4c7c51[_0xad2e('0x21')](0xc8);}})[_0xad2e('0x20')](handleError(_0x4c7c51,null));};
\ No newline at end of file
+var _0xf2bb=['direction','read','get','mkdirSync','Account','Owner','N.A.','closed','toString','browserName','osName','referer','customerIp','customerPort','tail','existsSync','createReadStream','pipe','createWriteStream','value','renderFile','views','downloadInteraction.ejs','Chat','err','unlinkSync','rimraf','zip-dir','request-promise','moment','bluebird','util','path','ejs','lodash','ioredis','../../components/interaction/service','../../components/export/pdf','../../config/logger','api','../../config/environment','redis','defaults','socket.io-emitter','./chatInteraction.socket','register','client','http','request','then','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','update','stack','send','merge','contact','agent','account','index','ChatInteraction','type','key','query','user','show','params','model','keys','intersection','attributes','fields','length','includeAll','include','options','find','create','body','describe','findOne','ChatWebsiteId','vidaooApiKey','vidaooEscalation','vidaooTopic','vidaooNote','name','fullname','POST','https://api-vidaoo.xcally.com/api/v1/meetings','email','isNull','follow','vidaooMetadata','parse','metadata','Sequelize','Error\x20in\x20Vidaoo\x20configuration','join_url','out','ChatMessage','ValidationError','updateAttributes','customUpdate','CmContact','Contact','abandon','abandonInteraction,\x20%s,\x20%s,\x20%s','entity\x20not\x20found','Interaction\x20already\x20assigned','disposition','AbandonInteraction','file','originalname','filename','mimetype','attachmentDownload','Unauthorized','attachId','ChatOfflineMessageId','join','root','server/files/attachments/','offline-chat/','basename','download','close','server/files/chat/upload/','format','transcript-%s.txt','now','pathTranscript','User','ChatWebsite','Messages','%s%d','UserId','customer','Visitor','ContactId','website_alias','agentAlias','alias','System','agent_fullname','[%s]\x20%s:\x20%s\x0a','createdAt','MM/DD/YYYY\x20HH:mm:ss','appendFileSync','MailAccount','MailServerOut','Smtp','CloudProvider','getSmtpOptions','SendMail','sendMail','addMessage','ids','getMessages','rawAttributes','filters','hasOwnProperty','nolimit','sort','where','pick','ChatInteractionId','filter','$gte','split','YYYY-MM-DD\x20HH:mm:ss','getMyMessages','secret','includeAgent','findAll','rows','addTags','setTags','omit','Tag','color','emit','removeTags','server','files','tmp','transcript-%d-%s.zip','push','firstName','lastName','attachments','Attachment'];(function(_0x4cdd4d,_0x3cce1e){var _0x1bbd06=function(_0x4578cf){while(--_0x4578cf){_0x4cdd4d['push'](_0x4cdd4d['shift']());}};_0x1bbd06(++_0x3cce1e);}(_0xf2bb,0xed));var _0xbf2b=function(_0xd0b415,_0x149675){_0xd0b415=_0xd0b415-0x0;var _0x2bdf2c=_0xf2bb[_0xd0b415];return _0x2bdf2c;};'use strict';var rimraf=require(_0xbf2b('0x0'));var zipdir=require(_0xbf2b('0x1'));var rp=require(_0xbf2b('0x2'));var moment=require(_0xbf2b('0x3'));var BPromise=require(_0xbf2b('0x4'));var Mustache=require('mustache');var util=require(_0xbf2b('0x5'));var path=require(_0xbf2b('0x6'));var ejs=require(_0xbf2b('0x7'));var fs=require('fs');var _=require(_0xbf2b('0x8'));var Redis=require(_0xbf2b('0x9'));var interaction=require(_0xbf2b('0xa'));var qs=require('../../components/parsers/qs');var pdf=require(_0xbf2b('0xb'));var logger=require(_0xbf2b('0xc'))(_0xbf2b('0xd'));var config=require(_0xbf2b('0xe'));var db=require('../../mysqldb')['db'];config[_0xbf2b('0xf')]=_[_0xbf2b('0x10')](config[_0xbf2b('0xf')],{'host':'localhost','port':0x18eb});var socket=require(_0xbf2b('0x11'))(new Redis(config[_0xbf2b('0xf')]));require(_0xbf2b('0x12'))[_0xbf2b('0x13')](socket);var jayson=require('jayson/promise');var client=jayson[_0xbf2b('0x14')][_0xbf2b('0x15')]({'port':0x232b});var client9004=jayson[_0xbf2b('0x14')][_0xbf2b('0x15')]({'port':0x232c});function respondWithRpcPromise(_0x3db67b,_0x4627c7,_0x27fa8c,_0x12f222){return new BPromise(function(_0x507266,_0x15706f){var _0x4c07ec=_0x12f222||client;return _0x4c07ec[_0xbf2b('0x16')](_0x3db67b,_0x27fa8c)[_0xbf2b('0x17')](function(_0x3d5795){logger[_0xbf2b('0x18')](_0xbf2b('0x19'),_0x4627c7,_0xbf2b('0x1a'));logger[_0xbf2b('0x1b')](_0xbf2b('0x1c'),_0x4627c7,'request\x20sent',JSON[_0xbf2b('0x1d')](_0x3d5795));if(_0x3d5795[_0xbf2b('0x1e')]){if(_0x3d5795[_0xbf2b('0x1e')][_0xbf2b('0x1f')]===0x1f4){logger[_0xbf2b('0x1e')](_0xbf2b('0x19'),_0x4627c7,_0x3d5795['error'][_0xbf2b('0x20')]);return _0x15706f(_0x3d5795['error'][_0xbf2b('0x20')]);}logger[_0xbf2b('0x1e')](_0xbf2b('0x19'),_0x4627c7,_0x3d5795[_0xbf2b('0x1e')][_0xbf2b('0x20')]);return _0x507266(_0x3d5795[_0xbf2b('0x1e')]['message']);}else{logger[_0xbf2b('0x18')]('ChatInteraction,\x20%s,\x20%s',_0x4627c7,_0xbf2b('0x1a'));_0x507266(_0x3d5795[_0xbf2b('0x21')][_0xbf2b('0x20')]);}})[_0xbf2b('0x22')](function(_0x2eba96){logger['error']('ChatInteraction,\x20%s,\x20%s',_0x4627c7,_0x2eba96);_0x15706f(_0x2eba96);});});}function respondWithStatusCode(_0x2026cb,_0x1ea33a){_0x1ea33a=_0x1ea33a||0xcc;return function(_0x46dafa){if(_0x46dafa){return _0x2026cb[_0xbf2b('0x23')](_0x1ea33a);}return _0x2026cb[_0xbf2b('0x24')](_0x1ea33a)[_0xbf2b('0x25')]();};}function respondWithResult(_0x3bfa21,_0x4a48c0){_0x4a48c0=_0x4a48c0||0xc8;return function(_0x53d797){if(_0x53d797){return _0x3bfa21['status'](_0x4a48c0)[_0xbf2b('0x26')](_0x53d797);}};}function respondWithFilteredResult(_0x4639bc,_0x5d3130){return function(_0x5ab4d0){if(_0x5ab4d0){var _0x1b531e=typeof _0x5d3130[_0xbf2b('0x27')]===_0xbf2b('0x28')&&typeof _0x5d3130[_0xbf2b('0x29')]===_0xbf2b('0x28');var _0x1d9011=_0x5ab4d0[_0xbf2b('0x2a')];var _0x520adc=_0x1b531e?0x0:_0x5d3130['offset'];var _0x585a4b=_0x1b531e?_0x5ab4d0[_0xbf2b('0x2a')]:_0x5d3130[_0xbf2b('0x27')]+_0x5d3130[_0xbf2b('0x29')];var _0x122ecd;if(_0x585a4b>=_0x1d9011){_0x585a4b=_0x1d9011;_0x122ecd=0xc8;}else{_0x122ecd=0xce;}_0x4639bc[_0xbf2b('0x24')](_0x122ecd);return _0x4639bc[_0xbf2b('0x2b')](_0xbf2b('0x2c'),_0x520adc+'-'+_0x585a4b+'/'+_0x1d9011)[_0xbf2b('0x26')](_0x5ab4d0);}return null;};}function saveUpdates(_0x44c42c){return function(_0x2c5946){if(_0x2c5946){return _0x2c5946[_0xbf2b('0x2d')](_0x44c42c)[_0xbf2b('0x17')](function(_0x3bfbf9){return _0x3bfbf9;});}return null;};}function removeEntity(_0x46ee1f){return function(_0x373c85){if(_0x373c85){return _0x373c85['destroy']()[_0xbf2b('0x17')](function(){_0x46ee1f[_0xbf2b('0x24')](0xcc)[_0xbf2b('0x25')]();});}};}function handleEntityNotFound(_0x365f73){return function(_0x231f97){if(!_0x231f97){_0x365f73[_0xbf2b('0x23')](0x194);}return _0x231f97;};}function handleError(_0x69912f,_0x37e5f7){_0x37e5f7=_0x37e5f7||0x1f4;return function(_0xc71953){logger['error'](_0xc71953[_0xbf2b('0x2e')]);if(_0xc71953['name']){delete _0xc71953['name'];}_0x69912f['status'](_0x37e5f7)[_0xbf2b('0x2f')](_0xc71953);};}function getMustacheRender(_0x2f7f0d,_0x418a79){return Mustache['render'](_0x2f7f0d,_[_0xbf2b('0x30')](_0x418a79['body'],{'contact':_0x418a79[_0xbf2b('0x31')],'message':_0x418a79['message'],'agent':_0x418a79[_0xbf2b('0x32')],'interaction':_0x418a79['interaction'],'account':_0x418a79[_0xbf2b('0x33')]}))||'';}exports[_0xbf2b('0x34')]=function(_0x27dc4e,_0x5caa7e){var _0x381b16={};var _0x513a40=_['map'](db[_0xbf2b('0x35')]['rawAttributes'],function(_0x571188){return{'name':_0x571188['fieldName'],'type':_0x571188[_0xbf2b('0x36')][_0xbf2b('0x37')]};});_0x381b16=qs['getOptions'](_0x513a40,_0x27dc4e);return interaction['findAll']('chat',_0x27dc4e[_0xbf2b('0x38')],_0x27dc4e[_0xbf2b('0x39')],_0x381b16,_0x513a40)['then'](respondWithFilteredResult(_0x5caa7e,_0x381b16))['catch'](handleError(_0x5caa7e,null));};exports[_0xbf2b('0x3a')]=function(_0x320ebd,_0x1847ad){var _0xabc739={'raw':![],'where':{'id':_0x320ebd[_0xbf2b('0x3b')]['id']}},_0x298a8f={};_0x298a8f[_0xbf2b('0x3c')]=_[_0xbf2b('0x3d')](db[_0xbf2b('0x35')]['rawAttributes']);_0x298a8f['query']=_[_0xbf2b('0x3d')](_0x320ebd['query']);_0x298a8f['filters']=_[_0xbf2b('0x3e')](_0x298a8f[_0xbf2b('0x3c')],_0x298a8f[_0xbf2b('0x38')]);_0xabc739[_0xbf2b('0x3f')]=_['intersection'](_0x298a8f[_0xbf2b('0x3c')],qs[_0xbf2b('0x40')](_0x320ebd[_0xbf2b('0x38')][_0xbf2b('0x40')]));_0xabc739[_0xbf2b('0x3f')]=_0xabc739['attributes'][_0xbf2b('0x41')]?_0xabc739[_0xbf2b('0x3f')]:_0x298a8f[_0xbf2b('0x3c')];if(_0x320ebd[_0xbf2b('0x38')][_0xbf2b('0x42')]){_0xabc739[_0xbf2b('0x43')]=[{'all':!![]}];}_0xabc739=_['merge']({},_0xabc739,_0x320ebd[_0xbf2b('0x44')]);return db[_0xbf2b('0x35')][_0xbf2b('0x45')](_0xabc739)[_0xbf2b('0x17')](handleEntityNotFound(_0x1847ad,null))[_0xbf2b('0x17')](respondWithResult(_0x1847ad,null))[_0xbf2b('0x22')](handleError(_0x1847ad,null));};exports['create']=function(_0x4f5dc1,_0x3881f3){return db['ChatInteraction'][_0xbf2b('0x46')](_0x4f5dc1[_0xbf2b('0x47')],{})[_0xbf2b('0x17')](respondWithResult(_0x3881f3,0xc9))[_0xbf2b('0x22')](handleError(_0x3881f3,null));};exports['update']=function(_0x44077e,_0x18fbc1){if(_0x44077e[_0xbf2b('0x47')]['id']){delete _0x44077e[_0xbf2b('0x47')]['id'];}return db[_0xbf2b('0x35')][_0xbf2b('0x45')]({'where':{'id':_0x44077e['params']['id']}})['then'](handleEntityNotFound(_0x18fbc1,null))['then'](saveUpdates(_0x44077e[_0xbf2b('0x47')],null))[_0xbf2b('0x17')](respondWithResult(_0x18fbc1,null))['catch'](handleError(_0x18fbc1,null));};exports['destroy']=function(_0x3b8dff,_0x46aa72){return db[_0xbf2b('0x35')]['find']({'where':{'id':_0x3b8dff[_0xbf2b('0x3b')]['id']}})[_0xbf2b('0x17')](handleEntityNotFound(_0x46aa72,null))[_0xbf2b('0x17')](removeEntity(_0x46aa72,null))[_0xbf2b('0x22')](handleError(_0x46aa72,null));};exports[_0xbf2b('0x48')]=function(_0x5cd796,_0x17c5ca){return db[_0xbf2b('0x35')]['describe']()[_0xbf2b('0x17')](respondWithResult(_0x17c5ca,null))[_0xbf2b('0x22')](handleError(_0x17c5ca,null));};exports['createVidaooSession']=function(_0x4ae39b,_0x5e34ec){var _0x2a72f4=_0x4ae39b['params']['id'];var _0x3f9124;var _0x2cbd4d;var _0x139375;return db['ChatInteraction'][_0xbf2b('0x49')]({'where':{'id':_0x2a72f4}})[_0xbf2b('0x17')](function(_0x225444){_0x3f9124=_0x225444;return db['ChatWebsite'][_0xbf2b('0x49')]({'where':{'id':_0x225444[_0xbf2b('0x4a')]},'attributes':['id',_0xbf2b('0x4b'),_0xbf2b('0x4c'),_0xbf2b('0x4d'),_0xbf2b('0x4e'),'vidaooMetadata'],'raw':!![]});})[_0xbf2b('0x17')](function(_0x350154){if(_0x350154&&_0x350154['vidaooApiKey']&&_0x350154[_0xbf2b('0x4c')]){_0x2cbd4d=_0x350154;var _0x477b0f={'interaction':{'id':_0x2a72f4},'agent':{'id':_0x4ae39b[_0xbf2b('0x39')]['id'],'name':_0x4ae39b[_0xbf2b('0x39')][_0xbf2b('0x4f')],'fullname':_0x4ae39b[_0xbf2b('0x39')][_0xbf2b('0x50')],'email':_0x4ae39b['user']['email']},'contact':_0x4ae39b[_0xbf2b('0x47')][_0xbf2b('0x31')],'account':_0x4ae39b[_0xbf2b('0x47')][_0xbf2b('0x33')]};var _0x1636db={'rejectUnauthorized':![],'method':_0xbf2b('0x51'),'url':_0xbf2b('0x52'),'headers':{'X-APIKEY':_0x350154[_0xbf2b('0x4b')]},'body':{'duration':null,'scheduledAt':null,'participants':[_0x4ae39b['user'][_0xbf2b('0x53')]],'buttons':null,'topic':_0x2cbd4d['vidaooTopic'],'note':_[_0xbf2b('0x54')](_0x2cbd4d[_0xbf2b('0x4e')])?null:getMustacheRender(_0x2cbd4d['vidaooNote'],_0x477b0f),'metadata':null},'redirect':_0xbf2b('0x55'),'json':!![]};try{if(!_['isNull'](_0x2cbd4d[_0xbf2b('0x56')])){var _0x2dbe47=getMustacheRender(_0x2cbd4d[_0xbf2b('0x56')],_0x477b0f);var _0x2c0529=JSON[_0xbf2b('0x57')](_0x2dbe47);_0x1636db[_0xbf2b('0x47')][_0xbf2b('0x58')]=_0x2c0529;}}catch(_0x5885ca){throw new db[(_0xbf2b('0x59'))]['ValidationError']('Error\x20in\x20conversion\x20vidaooMetadata');}return rp(_0x1636db);}else{throw new db[(_0xbf2b('0x59'))]['ValidationError'](_0xbf2b('0x5a'));}})['then'](function(_0x2d089a){_0x139375=_0x2d089a;if(_0x139375['id']){var _0x427984={'body':_0x139375[_0xbf2b('0x5b')],'ChatWebsiteId':_0x2cbd4d['id'],'ChatInteractionId':_0x3f9124['id'],'direction':_0xbf2b('0x5c'),'UserId':_0x4ae39b[_0xbf2b('0x39')]['id']};return db[_0xbf2b('0x5d')][_0xbf2b('0x46')](_0x427984,{});}else{throw new db[(_0xbf2b('0x59'))][(_0xbf2b('0x5e'))]('Unable\x20to\x20create\x20Vidaoo\x20session');}})[_0xbf2b('0x17')](function(){return _0x3f9124[_0xbf2b('0x5f')]({'vidaooSessionId':_0x139375['id']});})[_0xbf2b('0x17')](respondWithResult(_0x5e34ec,null))[_0xbf2b('0x22')](handleError(_0x5e34ec,null));};exports[_0xbf2b('0x60')]=function(_0x58ada7,_0xa9e7b5){if(_0x58ada7['body']['id']){delete _0x58ada7[_0xbf2b('0x47')]['id'];}return db[_0xbf2b('0x35')][_0xbf2b('0x45')]({'where':{'id':_0x58ada7[_0xbf2b('0x3b')]['id']},'include':[{'model':db[_0xbf2b('0x61')],'as':_0xbf2b('0x62')}]})[_0xbf2b('0x17')](handleEntityNotFound(_0xa9e7b5,null))[_0xbf2b('0x17')](saveUpdates(_0x58ada7[_0xbf2b('0x47')],null))[_0xbf2b('0x17')](respondWithResult(_0xa9e7b5,null))[_0xbf2b('0x22')](handleError(_0xa9e7b5,null));};exports[_0xbf2b('0x63')]=function(_0x3ee321,_0x2c798a){if(_0x3ee321[_0xbf2b('0x47')]['id']){delete _0x3ee321[_0xbf2b('0x47')]['id'];}return db['ChatInteraction'][_0xbf2b('0x45')]({'where':{'id':_0x3ee321[_0xbf2b('0x3b')]['id']}})[_0xbf2b('0x17')](function(_0xd66c32){if(!_0xd66c32){logger[_0xbf2b('0x1e')](_0xbf2b('0x64'),_0xbf2b('0x63'),0x194,_0xbf2b('0x65'));_0x2c798a[_0xbf2b('0x23')](0x194);}else{if(_0xd66c32['UserId']){throw new db[(_0xbf2b('0x59'))][(_0xbf2b('0x5e'))](_0xbf2b('0x66'));}}return _0xd66c32;})[_0xbf2b('0x17')](function(_0x1a85f6){if(_0x1a85f6){return _0x1a85f6[_0xbf2b('0x2d')]({'closed':_0x3ee321[_0xbf2b('0x47')]['closed'],'disposition':_0x3ee321[_0xbf2b('0x47')][_0xbf2b('0x67')]})['then'](function(_0x5241b1){return _0x5241b1;});}})['then'](function(){return respondWithRpcPromise(_0xbf2b('0x68'),_0xbf2b('0x63'),_0x3ee321[_0xbf2b('0x47')],client9004);})[_0xbf2b('0x17')](respondWithResult(_0x2c798a,null))['catch'](handleError(_0x2c798a,null));};exports['attachmentUpload']=function(_0x343080,_0x5c90ba){_0x343080[_0xbf2b('0x47')][_0xbf2b('0x4f')]=_0x343080[_0xbf2b('0x69')][_0xbf2b('0x6a')];_0x343080['body']['basename']=_0x343080[_0xbf2b('0x69')][_0xbf2b('0x6b')];_0x343080[_0xbf2b('0x47')][_0xbf2b('0x36')]=_0x343080[_0xbf2b('0x69')][_0xbf2b('0x6c')];return db['Attachment'][_0xbf2b('0x46')](_0x343080['body'])[_0xbf2b('0x17')](respondWithResult(_0x5c90ba,0xc9))[_0xbf2b('0x22')](handleError(_0x5c90ba,null));};exports[_0xbf2b('0x6d')]=function(_0xcff1fe,_0x5cc341){return db[_0xbf2b('0x35')]['findOne']({'where':{'id':_0xcff1fe[_0xbf2b('0x3b')]['id']},'raw':!![]})['then'](handleEntityNotFound(_0x5cc341,null))[_0xbf2b('0x17')](function(_0x36dea8){if(_0x36dea8){if(_0x36dea8['closed']){return _0x5cc341[_0xbf2b('0x24')](0x193)['json']({'status':0x193,'message':_0xbf2b('0x6e')});}return db['Attachment']['findOne']({'where':{'id':_0xcff1fe[_0xbf2b('0x38')][_0xbf2b('0x6f')]},'raw':!![]})[_0xbf2b('0x17')](handleEntityNotFound(_0x5cc341,null));}})[_0xbf2b('0x17')](function(_0x26af55){if(_0x26af55){var _0x3f85e4=_0x26af55[_0xbf2b('0x70')]!==null;var _0x2f842b=path[_0xbf2b('0x71')](config[_0xbf2b('0x72')],_0xbf2b('0x73'));if(_0x3f85e4){_0x2f842b=path[_0xbf2b('0x71')](_0x2f842b,_0xbf2b('0x74'));}var _0x4f08eb=path[_0xbf2b('0x71')](_0x2f842b,_0x26af55[_0xbf2b('0x75')]);return _0x5cc341[_0xbf2b('0x76')](_0x4f08eb);}})['catch'](handleError(_0x5cc341,null));};exports[_0xbf2b('0x77')]=function(_0x1cc28b,_0xd2812){var _0x5528da=null;var _0x1bd3e6=null;var _0x1e0023=null;if(_0x1cc28b[_0xbf2b('0x47')]['id']){delete _0x1cc28b[_0xbf2b('0x47')]['id'];}if(_0x1cc28b['body']['mailTranscript']){_0x1e0023=path['join'](config[_0xbf2b('0x72')],_0xbf2b('0x78'),util[_0xbf2b('0x79')](_0xbf2b('0x7a'),Date[_0xbf2b('0x7b')]()));_0x1cc28b[_0xbf2b('0x47')][_0xbf2b('0x7c')]=_0x1e0023;}return db[_0xbf2b('0x35')]['find']({'where':{'id':_0x1cc28b[_0xbf2b('0x3b')]['id']},'include':[{'model':db[_0xbf2b('0x5d')],'as':'Messages','include':[{'model':db[_0xbf2b('0x7d')],'as':_0xbf2b('0x7d')}]}]})[_0xbf2b('0x17')](handleEntityNotFound(_0xd2812,null))[_0xbf2b('0x17')](saveUpdates(_0x1cc28b[_0xbf2b('0x47')],null))[_0xbf2b('0x17')](function(_0x25e48f){if(_0x25e48f){_0x5528da=_0x25e48f;return db[_0xbf2b('0x7e')][_0xbf2b('0x45')]({'where':{'id':_0x5528da['ChatWebsiteId']}});}})[_0xbf2b('0x17')](function(_0x247a42){if(_0x247a42){_0x1bd3e6=_0x247a42;return db[_0xbf2b('0x61')][_0xbf2b('0x45')]({'where':{'id':_0x5528da['ContactId']}});}})[_0xbf2b('0x17')](function(_0x5d2dfb){if(_0x5d2dfb){if(_0x1e0023){var _0x45fb94=null;for(var _0x23c75f=0x1;_0x23c75f<_0x5528da[_0xbf2b('0x7f')][_0xbf2b('0x41')];++_0x23c75f){_0x45fb94=_0x5528da['Messages'][_0x23c75f];var _0x2a96e8=_0x45fb94['UserId']?util['format'](_0xbf2b('0x80'),_0x1bd3e6['agentAlias'],_0x45fb94[_0xbf2b('0x81')]):'System';var _0x10ad70=_0x1cc28b['body'][_0xbf2b('0x82')]||util['format']('%s%d',_0xbf2b('0x83'),_0x45fb94[_0xbf2b('0x84')]);switch(_0x1bd3e6['agentIdentifier']){case _0xbf2b('0x85'):_0x2a96e8=_0x45fb94[_0xbf2b('0x81')]?util[_0xbf2b('0x79')](_0xbf2b('0x80'),_0x1bd3e6[_0xbf2b('0x86')],_0x45fb94[_0xbf2b('0x81')]):'System';break;case'agent_alias':_0x2a96e8=_0x45fb94[_0xbf2b('0x81')]?_0x45fb94[_0xbf2b('0x7d')][_0xbf2b('0x87')]||_0x45fb94[_0xbf2b('0x7d')]['fullname']:_0xbf2b('0x88');break;case _0xbf2b('0x89'):_0x2a96e8=_0x45fb94[_0xbf2b('0x81')]?_0x45fb94[_0xbf2b('0x7d')]['fullname']:'System';break;default:_0x2a96e8=_0x45fb94[_0xbf2b('0x81')]?util[_0xbf2b('0x79')](_0xbf2b('0x80'),_0x1bd3e6[_0xbf2b('0x86')],_0x45fb94[_0xbf2b('0x81')]):_0xbf2b('0x88');}var _0xf709fe=util['format'](_0xbf2b('0x8a'),moment(_0x45fb94[_0xbf2b('0x8b')])[_0xbf2b('0x79')](_0xbf2b('0x8c')),_0x45fb94['direction']==='in'?_0x10ad70:_0x2a96e8,_0x45fb94[_0xbf2b('0x47')]);if(!_0x45fb94['secret']){fs[_0xbf2b('0x8d')](_0x1e0023,_0xf709fe);}}return db[_0xbf2b('0x8e')]['findOne']({'where':{'service':!![]},'include':[{'model':db[_0xbf2b('0x8f')],'as':_0xbf2b('0x90'),'raw':!![],'include':[{'model':db[_0xbf2b('0x91')],'as':'CloudProvider','raw':!![]}]}]});}}})[_0xbf2b('0x17')](function(_0x6cd4fc){if(!_0x6cd4fc||!_0x6cd4fc[_0xbf2b('0x90')]||!_0x1cc28b[_0xbf2b('0x47')])return _0x5528da;var _0x1eac1a=_0x6cd4fc[_0xbf2b('0x92')]();return respondWithRpcPromise(_0xbf2b('0x93'),_0xbf2b('0x94'),{'account':_0x1eac1a,'message':{'from':util['format']('\x22%s\x22\x20<%s>',_0x6cd4fc[_0xbf2b('0x4f')],_0x6cd4fc['email']||_0x6cd4fc[_0xbf2b('0x90')]['user']),'to':_0x1cc28b[_0xbf2b('0x47')]['mailTranscript'],'subject':'Mail\x20Transcript','text':util[_0xbf2b('0x79')]('Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a',_0x1cc28b[_0xbf2b('0x47')]['mailTranscript']),'attachments':[{'path':_0x1e0023}]}})[_0xbf2b('0x17')](function(){return _0x5528da;})['catch'](function(_0x678038){logger[_0xbf2b('0x1e')](_0x678038);});})[_0xbf2b('0x17')](respondWithStatusCode(_0xd2812,0xc8))[_0xbf2b('0x22')](handleError(_0xd2812,null));};exports[_0xbf2b('0x95')]=function(_0x559697,_0x14f9a2){return db['ChatMessage'][_0xbf2b('0x45')]({'where':{'id':_0x559697['params']['id']}})['then'](handleEntityNotFound(_0x14f9a2,null))[_0xbf2b('0x17')](function(_0x802a09){if(_0x802a09){return _0x802a09['addMessage'](_0x559697[_0xbf2b('0x47')][_0xbf2b('0x96')],_['omit'](_0x559697[_0xbf2b('0x47')],[_0xbf2b('0x96'),'id'])||{});}})[_0xbf2b('0x17')](respondWithResult(_0x14f9a2,null))['catch'](handleError(_0x14f9a2,null));};exports[_0xbf2b('0x97')]=function(_0x25fece,_0x5e028d){var _0x590dab={'raw':![],'where':{}};var _0x342ed4={};var _0x5b98b0={'count':0x0,'rows':[]};return db[_0xbf2b('0x35')][_0xbf2b('0x49')]({'where':{'id':_0x25fece[_0xbf2b('0x3b')]['id']}})[_0xbf2b('0x17')](handleEntityNotFound(_0x5e028d,null))[_0xbf2b('0x17')](function(_0x4920cd){if(_0x4920cd){_0x342ed4[_0xbf2b('0x3c')]=_[_0xbf2b('0x3d')](db['ChatMessage'][_0xbf2b('0x98')]);_0x342ed4[_0xbf2b('0x38')]=_[_0xbf2b('0x3d')](_0x25fece['query']);_0x342ed4[_0xbf2b('0x99')]=_[_0xbf2b('0x3e')](_0x342ed4['model'],_0x342ed4[_0xbf2b('0x38')]);_0x590dab['attributes']=_[_0xbf2b('0x3e')](_0x342ed4[_0xbf2b('0x3c')],qs[_0xbf2b('0x40')](_0x25fece[_0xbf2b('0x38')][_0xbf2b('0x40')]));_0x590dab[_0xbf2b('0x3f')]=_0x590dab[_0xbf2b('0x3f')][_0xbf2b('0x41')]?_0x590dab['attributes']:_0x342ed4[_0xbf2b('0x3c')];if(!_0x25fece[_0xbf2b('0x38')][_0xbf2b('0x9a')](_0xbf2b('0x9b'))){_0x590dab[_0xbf2b('0x29')]=qs['limit'](_0x25fece[_0xbf2b('0x38')][_0xbf2b('0x29')]);_0x590dab[_0xbf2b('0x27')]=qs[_0xbf2b('0x27')](_0x25fece[_0xbf2b('0x38')][_0xbf2b('0x27')]);}_0x590dab['order']=qs[_0xbf2b('0x9c')](_0x25fece[_0xbf2b('0x38')][_0xbf2b('0x9c')]);_0x590dab[_0xbf2b('0x9d')]=qs[_0xbf2b('0x99')](_[_0xbf2b('0x9e')](_0x25fece[_0xbf2b('0x38')],_0x342ed4[_0xbf2b('0x99')]));_0x590dab[_0xbf2b('0x9d')][_0xbf2b('0x9f')]=_0x4920cd['id'];if(_0x25fece[_0xbf2b('0x38')]['filter']){_0x590dab['where']=_[_0xbf2b('0x30')](_0x590dab[_0xbf2b('0x9d')],{'$or':_['map'](_0x590dab[_0xbf2b('0x3f')],function(_0x3722b4){var _0x5b679c={};_0x5b679c[_0x3722b4]={'$like':'%'+_0x25fece[_0xbf2b('0x38')][_0xbf2b('0xa0')]+'%'};return _0x5b679c;})});}if(_0x25fece[_0xbf2b('0x38')][_0xbf2b('0xa1')]){var _0x119887=_0x25fece[_0xbf2b('0x38')][_0xbf2b('0xa1')][_0xbf2b('0xa2')](',');var _0x4cb6d9={};_0x4cb6d9[_0x119887[0x0]]={'$gte':moment(_0x119887[0x1])[_0xbf2b('0x79')](_0xbf2b('0xa3'))};_0x590dab[_0xbf2b('0x9d')]=_[_0xbf2b('0x30')](_0x590dab[_0xbf2b('0x9d')],_0x4cb6d9);}_0x590dab=_[_0xbf2b('0x30')]({},_0x590dab,_0x25fece[_0xbf2b('0x44')]);return db[_0xbf2b('0x5d')][_0xbf2b('0x2a')]({'where':_0x590dab[_0xbf2b('0x9d')]})[_0xbf2b('0x17')](function(_0x5ab930){_0x5b98b0[_0xbf2b('0x2a')]=_0x5ab930;if(_0x25fece[_0xbf2b('0x38')][_0xbf2b('0x42')]){_0x590dab[_0xbf2b('0x43')]=[{'all':!![]}];}return db[_0xbf2b('0x5d')]['findAll'](_0x590dab);})[_0xbf2b('0x17')](function(_0x398633){_0x5b98b0['rows']=_0x398633;return _0x5b98b0;});}})[_0xbf2b('0x17')](respondWithFilteredResult(_0x5e028d,_0x590dab))[_0xbf2b('0x22')](handleError(_0x5e028d,null));};exports[_0xbf2b('0xa4')]=function(_0x275990,_0x36cac7){var _0x2b8e54={'where':{}},_0x580a4d={},_0x5e65af={'count':0x0,'rows':[]};return db[_0xbf2b('0x35')]['findOne']({'where':{'id':_0x275990['params']['id']}})['then'](handleEntityNotFound(_0x36cac7,null))['then'](function(_0x2ce960){if(_0x2ce960){_0x580a4d[_0xbf2b('0x3c')]=_[_0xbf2b('0x3d')](db[_0xbf2b('0x5d')]['rawAttributes']);_0x580a4d[_0xbf2b('0x38')]=_[_0xbf2b('0x3d')](_0x275990[_0xbf2b('0x38')]);_0x580a4d['filters']=_['intersection'](_0x580a4d[_0xbf2b('0x3c')],_0x580a4d['query']);_0x2b8e54['attributes']=_[_0xbf2b('0x3e')](_0x580a4d[_0xbf2b('0x3c')],qs[_0xbf2b('0x40')](_0x275990[_0xbf2b('0x38')][_0xbf2b('0x40')]));_0x2b8e54['attributes']=_0x2b8e54[_0xbf2b('0x3f')][_0xbf2b('0x41')]?_0x2b8e54['attributes']:_0x580a4d[_0xbf2b('0x3c')];if(!_0x275990[_0xbf2b('0x38')][_0xbf2b('0x9a')](_0xbf2b('0x9b'))){_0x2b8e54[_0xbf2b('0x29')]=qs[_0xbf2b('0x29')](_0x275990[_0xbf2b('0x38')][_0xbf2b('0x29')]);_0x2b8e54[_0xbf2b('0x27')]=qs[_0xbf2b('0x27')](_0x275990[_0xbf2b('0x38')][_0xbf2b('0x27')]);}_0x2b8e54['order']=qs[_0xbf2b('0x9c')](_0x275990[_0xbf2b('0x38')][_0xbf2b('0x9c')]);_0x2b8e54[_0xbf2b('0x9d')]=qs[_0xbf2b('0x99')](_[_0xbf2b('0x9e')](_0x275990[_0xbf2b('0x38')],_0x580a4d['filters']));_0x2b8e54[_0xbf2b('0x9d')][_0xbf2b('0x9f')]=_0x2ce960['id'];if(_0x275990[_0xbf2b('0x38')][_0xbf2b('0xa0')]){_0x2b8e54[_0xbf2b('0x9d')]=_[_0xbf2b('0x30')](_0x2b8e54[_0xbf2b('0x9d')],{'$or':_['map'](_0x2b8e54[_0xbf2b('0x3f')],function(_0x1393ee){var _0x2682c1={};_0x2682c1[_0x1393ee]={'$like':'%'+_0x275990['query'][_0xbf2b('0xa0')]+'%'};return _0x2682c1;})});}_0x2b8e54[_0xbf2b('0x9d')][_0xbf2b('0xa5')]=![];if(_0x275990[_0xbf2b('0x38')]['id']){_0x2b8e54[_0xbf2b('0x9d')]['id']={'$gt':_0x275990[_0xbf2b('0x38')]['id']};}_0x2b8e54=_['merge']({},_0x2b8e54,_0x275990[_0xbf2b('0x44')]);return db[_0xbf2b('0x5d')]['count']({'where':_0x2b8e54[_0xbf2b('0x9d')]})['then'](function(_0x513334){_0x5e65af[_0xbf2b('0x2a')]=_0x513334;_0x2b8e54[_0xbf2b('0x43')]=[];if(_0x275990[_0xbf2b('0x38')][_0xbf2b('0xa6')]){_0x2b8e54[_0xbf2b('0x43')]['push']({'model':db['User'],'as':'User','attributes':['id',_0xbf2b('0x50'),_0xbf2b('0x87')]});}if(_0x275990[_0xbf2b('0x38')]['includeAll']){_0x2b8e54[_0xbf2b('0x43')]=[{'all':!![]}];}return db[_0xbf2b('0x5d')][_0xbf2b('0xa7')](_0x2b8e54);})[_0xbf2b('0x17')](function(_0x3dee1b){_0x5e65af[_0xbf2b('0xa8')]=_0x3dee1b;return _0x5e65af;});}})['then'](respondWithFilteredResult(_0x36cac7,_0x2b8e54))['catch'](handleError(_0x36cac7,null));};exports[_0xbf2b('0xa9')]=function(_0x4d2187,_0x4cccb2){return db[_0xbf2b('0x35')][_0xbf2b('0x45')]({'where':{'id':_0x4d2187[_0xbf2b('0x3b')]['id']}})['then'](handleEntityNotFound(_0x4cccb2,null))[_0xbf2b('0x17')](function(_0xbcec91){if(_0xbcec91){return _0xbcec91[_0xbf2b('0xaa')](_0x4d2187[_0xbf2b('0x47')]['ids'],_[_0xbf2b('0xab')](_0x4d2187[_0xbf2b('0x47')],['ids','id'])||{})['spread'](function(){return db[_0xbf2b('0xac')][_0xbf2b('0xa7')]({'attributes':['id',_0xbf2b('0x4f'),_0xbf2b('0xad')],'where':{'id':_0x4d2187[_0xbf2b('0x47')][_0xbf2b('0x96')]}});})['then'](function(_0x5b971e){socket[_0xbf2b('0xae')]('chatInteractionTags:save',{'id':Number(_0x4d2187['params']['id']),'tags':_0x5b971e||[]});return{'id':Number(_0x4d2187[_0xbf2b('0x3b')]['id']),'tags':_0x5b971e||[]};});}})['then'](respondWithResult(_0x4cccb2,null))[_0xbf2b('0x22')](handleError(_0x4cccb2,null));};exports['removeTags']=function(_0x26f74c,_0x5297e8){return db[_0xbf2b('0x35')][_0xbf2b('0x45')]({'where':{'id':_0x26f74c[_0xbf2b('0x3b')]['id']}})[_0xbf2b('0x17')](handleEntityNotFound(_0x5297e8,null))[_0xbf2b('0x17')](function(_0x6ee08b){if(_0x6ee08b){return _0x6ee08b[_0xbf2b('0xaf')](_0x26f74c[_0xbf2b('0x38')][_0xbf2b('0x96')]);}})[_0xbf2b('0x17')](respondWithStatusCode(_0x5297e8,null))['catch'](handleError(_0x5297e8,null));};exports[_0xbf2b('0x76')]=function(_0xadc254,_0x2d4288){var _0x405edb=moment()['unix']()['toString']();var _0x53f853=path[_0xbf2b('0x71')](config[_0xbf2b('0x72')],_0xbf2b('0xb0'),_0xbf2b('0xb1'),_0xbf2b('0xb2'));var _0x33b7a5=path[_0xbf2b('0x71')](config[_0xbf2b('0x72')],'server',_0xbf2b('0xb1'),'attachments');var _0x1cc173=path['join'](_0x53f853,_0x405edb);var _0x5db5e3=util[_0xbf2b('0x79')](_0xbf2b('0xb3'),_0xadc254[_0xbf2b('0x3b')]['id'],_0x405edb);var _0x3f4f94=path[_0xbf2b('0x71')](_0x53f853,_0x5db5e3);var _0x12fda9=[];_0x12fda9[_0xbf2b('0xb4')]({'model':db[_0xbf2b('0x7d')],'as':'User','attributes':['id',_0xbf2b('0x50')],'raw':!![]});_0x12fda9[_0xbf2b('0xb4')]({'model':db['CmContact'],'as':_0xbf2b('0x62'),'attributes':['id',_0xbf2b('0xb5'),_0xbf2b('0xb6')],'raw':!![]});if(_0xadc254[_0xbf2b('0x38')][_0xbf2b('0xb7')]){_0x12fda9[_0xbf2b('0xb4')]({'model':db[_0xbf2b('0xb8')],'as':_0xbf2b('0xb8'),'raw':!![]});}var _0x43727f=[{'model':db['ChatMessage'],'as':'Messages','attributes':['id','body',_0xbf2b('0x8b'),_0xbf2b('0xb9'),_0xbf2b('0xa5'),_0xbf2b('0xba')],'include':_0x12fda9}];_0x43727f['push']({'model':db[_0xbf2b('0x7e')],'as':'Account','attributes':['id',_0xbf2b('0x4f')]});_0x43727f[_0xbf2b('0xb4')]({'model':db['User'],'as':'Owner','attributes':['id',_0xbf2b('0x50')]});return db[_0xbf2b('0x35')]['find']({'where':{'id':_0xadc254[_0xbf2b('0x3b')]['id']},'include':_0x43727f})[_0xbf2b('0x17')](handleEntityNotFound(_0x2d4288,null))['then'](function(_0x19fbd8){if(_0x19fbd8){var _0x3ad796=_0x19fbd8[_0xbf2b('0xbb')]({'plain':!![]});fs[_0xbf2b('0xbc')](_0x1cc173);var _0x3f4fab={'channel':'Chat','account':_0x3ad796[_0xbf2b('0xbd')]['name'],'agent':_0x3ad796[_0xbf2b('0xbe')]?_0x3ad796[_0xbf2b('0xbe')][_0xbf2b('0x50')]:_0xbf2b('0xbf'),'createdAt':moment(_0x3ad796[_0xbf2b('0x8b')])[_0xbf2b('0x79')](_0xbf2b('0xa3'))['toString'](),'closedAt':_0x3ad796[_0xbf2b('0xc0')]?moment(_0x3ad796['closedAt'])[_0xbf2b('0x79')](_0xbf2b('0xa3'))[_0xbf2b('0xc1')]():'','disposition':_0x3ad796[_0xbf2b('0x67')],'chatInfo':{'browser':_0x3ad796[_0xbf2b('0xc2')],'os':_0x3ad796[_0xbf2b('0xc3')],'referer':_0x3ad796[_0xbf2b('0xc4')],'customerIp':_0x3ad796[_0xbf2b('0xc5')],'customerPort':_0x3ad796['customerPort']?_0x3ad796[_0xbf2b('0xc6')]:_0xbf2b('0xbf')},'messages':_(_0x3ad796[_0xbf2b('0x7f')])[_0xbf2b('0xc7')]()[_0xbf2b('0xa0')]({'secret':![]})['map'](function(_0x392b71){if(_0x392b71[_0xbf2b('0xb8')]){var _0x2d0dd0=path[_0xbf2b('0x71')](_0x33b7a5,_0x392b71[_0xbf2b('0xb8')][_0xbf2b('0x75')]);if(fs[_0xbf2b('0xc8')](_0x2d0dd0)){fs[_0xbf2b('0xc9')](_0x2d0dd0)[_0xbf2b('0xca')](fs[_0xbf2b('0xcb')](path['join'](_0x1cc173,_0x392b71['Attachment'][_0xbf2b('0x75')])));}}return{'date':moment(_0x392b71[_0xbf2b('0x8b')])['format'](_0xbf2b('0xa3'))[_0xbf2b('0xc1')](),'sender':_0x392b71[_0xbf2b('0xb9')]==='out'?_0x392b71[_0xbf2b('0x7d')]?_0x392b71[_0xbf2b('0x7d')][_0xbf2b('0x50')]:_0xbf2b('0x88'):_0x392b71[_0xbf2b('0x62')][_0xbf2b('0xb5')]+(_0x392b71['Contact'][_0xbf2b('0xb6')]?'\x20'+_0x392b71[_0xbf2b('0x62')][_0xbf2b('0xb6')]:''),'body':_0x392b71['Attachment']?_0x392b71['Attachment'][_0xbf2b('0x75')]:_0x392b71[_0xbf2b('0x47')],'direction':_0x392b71[_0xbf2b('0xb9')]===_0xbf2b('0x5c')?'A':'C','secret':_0x392b71['secret'],'read':_0x392b71[_0xbf2b('0xba')],'attachment':_0x392b71['Attachment']};})[_0xbf2b('0xcc')]()};return ejs[_0xbf2b('0xcd')](path[_0xbf2b('0x71')](config['root'],_0xbf2b('0xb0'),_0xbf2b('0xce'),_0xbf2b('0xcf')),{'interaction':_0x3f4fab})[_0xbf2b('0x17')](function(_0x188ec9){var _0x544664=path[_0xbf2b('0x71')](_0x1cc173,'transcript-'+_0x3ad796['id']+'-'+_0x405edb+'.pdf');var _0x7504a5={'path':_0x544664,'channel':_0xbf2b('0xd0'),'interactionId':_0x3ad796['id']};return pdf['createPdfFromHTML'](_0x188ec9,_0x7504a5);})[_0xbf2b('0x17')](function(){return new Promise(function(_0x1fabf1,_0x5ef1bf){zipdir(_0x1cc173,{'saveTo':_0x3f4f94},function(_0x1f0ced,_0x27bbdd){if(_0x1f0ced)return _0x5ef1bf(_0x1f0ced);return _0x1fabf1(_0x27bbdd);});})[_0xbf2b('0x17')](function(){return new BPromise(function(_0x1f3027,_0x67c1cf){rimraf(_0x1cc173,function(_0x1eb351){if(_0x1eb351)_0x67c1cf(_0x1eb351);return _0x1f3027();});});})[_0xbf2b('0x17')](function(){return _0x2d4288[_0xbf2b('0x76')](_0x3f4f94,_0x5db5e3,function(_0x509b6f){if(_0x509b6f){logger[_0xbf2b('0x1e')](_0xbf2b('0xd1'),_0x509b6f);}else{fs[_0xbf2b('0xd2')](_0x3f4f94);}});});});}else{return _0x2d4288[_0xbf2b('0x23')](0xc8);}})[_0xbf2b('0x22')](handleError(_0x2d4288,null));};
\ No newline at end of file