Built motion from commit 25580385.|2.6.2
[motion2.git] / server / api / chatInteraction / chatInteraction.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x4ea3=['vidaooNote','vidaooMetadata','email','contact','POST','https://api-vidaoo.xcally.com/api/v1/meetings','vidaooTopic','isNull','metadata','ValidationError','Error\x20in\x20conversion\x20vidaooMetadata','Error\x20in\x20Vidaoo\x20configuration','join_url','out','Unable\x20to\x20create\x20Vidaoo\x20session','updateAttributes','CmContact','abandon','entity\x20not\x20found','Interaction\x20already\x20assigned','attachmentUpload','file','basename','filename','mimetype','Attachment','attachmentDownload','attachId','join','root','offline-chat/','download','close','mailTranscript','server/files/chat/upload/','format','transcript-%s.txt','now','pathTranscript','Messages','%s%d','agentAlias','customer','Visitor','agentIdentifier','website_alias','System','agent_alias','alias','agent_fullname','MM/DD/YYYY\x20HH:mm:ss','direction','secret','appendFileSync','MailAccount','Smtp','CloudProvider','getSmtpOptions','SendMail','sendMail','\x22%s\x22\x20<%s>','Mail\x20Transcript','Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a','addMessage','ChatMessage','ids','omit','getMessages','ChatInteractionId','YYYY-MM-DD\x20HH:mm:ss','includeAll','include','findAll','rows','getMyMessages','includeAgent','addTags','setTags','Tag','color','chatInteractionTags:save','removeTags','unix','files','attachments','transcript-%d-%s.zip','firstName','lastName','Account','Owner','get','mkdirSync','Chat','N.A.','closedAt','browserName','osName','referer','customerPort','tail','existsSync','createReadStream','pipe','createWriteStream','renderFile','server','views','transcript-','.pdf','createPdfFromHTML','err','unlinkSync','rimraf','zip-dir','request-promise','moment','mustache','path','squel','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../components/export/pdf','../../config/logger','api','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','jayson/promise','client','http','request','then','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','debug','ChatInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','sendStatus','status','end','json','offset','undefined','limit','count','set','destroy','name','send','render','agent','interaction','map','fullname','TagIds','Tags','push','waiting','talking','unmanaged','total','closed','UserId','disposition','abandoned','answered','rawAttributes','fieldName','key','query','keys','intersection','attributes','model','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','select','field','tools_tags','u.fullname','ui.ChatInteractionId','from','user_has_chat_interactions','left_join','users','u.id\x20=\x20ui.UserId','chat_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','chat_websites','a.id\x20=\x20i.ChatWebsiteId','chat_messages','me.ChatInteractionId\x20=\x20i.id','chat_interaction_has_tags','it.ChatInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','conditions','find','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','split','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','type','start','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','User','operator','$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','text','compact','isEmpty','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','isArray','tag','filter','replace','isNumeric','i.id\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','Sequelize','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','DESC','resolve','ChatWebsiteId','user','getChatWebsites','i.ChatWebsiteId\x20IS\x20NULL','i.ChatWebsiteId\x20IN\x20?','role','sequelize','toString','keyBy','merge','ChatInteraction','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','i.*','Contact.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','c.fax','Contact.fax','o.fullname','Owner.fullname','o.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.ChatInteractionId\x20IN\x20?','groupBy','show','params','options','create','update','body','describe','findOne','ChatWebsite','vidaooApiKey','vidaooEscalation'];(function(_0x38bf31,_0x574a5e){var _0xaa4078=function(_0x49bcdc){while(--_0x49bcdc){_0x38bf31['push'](_0x38bf31['shift']());}};_0xaa4078(++_0x574a5e);}(_0x4ea3,0x70));var _0x34ea=function(_0x3b380d,_0x4bf247){_0x3b380d=_0x3b380d-0x0;var _0x54502b=_0x4ea3[_0x3b380d];return _0x54502b;};'use strict';var rimraf=require(_0x34ea('0x0'));var zipdir=require(_0x34ea('0x1'));var rp=require(_0x34ea('0x2'));var moment=require(_0x34ea('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x34ea('0x4'));var util=require('util');var path=require(_0x34ea('0x5'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x34ea('0x6'));var Redis=require(_0x34ea('0x7'));var qs=require(_0x34ea('0x8'));var as=require(_0x34ea('0x9'));var pdf=require(_0x34ea('0xa'));var logger=require(_0x34ea('0xb'))(_0x34ea('0xc'));var config=require('../../config/environment');var db=require(_0x34ea('0xd'))['db'];config[_0x34ea('0xe')]=_[_0x34ea('0xf')](config['redis'],{'host':_0x34ea('0x10'),'port':0x18eb});var socket=require(_0x34ea('0x11'))(new Redis(config['redis']));require('./chatInteraction.socket')[_0x34ea('0x12')](socket);var jayson=require(_0x34ea('0x13'));var client=jayson[_0x34ea('0x14')]['http']({'port':0x232b});var client9004=jayson[_0x34ea('0x14')][_0x34ea('0x15')]({'port':0x232c});function respondWithRpcPromise(_0x10135f,_0x233b11,_0x60725f,_0xc56a7d){return new BPromise(function(_0x37e1b4,_0x36af43){var _0x1ff760=_0xc56a7d||client;return _0x1ff760[_0x34ea('0x16')](_0x10135f,_0x60725f)[_0x34ea('0x17')](function(_0x5ef9ae){logger[_0x34ea('0x18')](_0x34ea('0x19'),_0x233b11,_0x34ea('0x1a'));logger[_0x34ea('0x1b')](_0x34ea('0x1c'),_0x233b11,'request\x20sent',JSON[_0x34ea('0x1d')](_0x5ef9ae));if(_0x5ef9ae[_0x34ea('0x1e')]){if(_0x5ef9ae[_0x34ea('0x1e')][_0x34ea('0x1f')]===0x1f4){logger['error'](_0x34ea('0x19'),_0x233b11,_0x5ef9ae[_0x34ea('0x1e')][_0x34ea('0x20')]);return _0x36af43(_0x5ef9ae['error'][_0x34ea('0x20')]);}logger[_0x34ea('0x1e')](_0x34ea('0x19'),_0x233b11,_0x5ef9ae[_0x34ea('0x1e')]['message']);return _0x37e1b4(_0x5ef9ae[_0x34ea('0x1e')][_0x34ea('0x20')]);}else{logger[_0x34ea('0x18')](_0x34ea('0x19'),_0x233b11,'request\x20sent');_0x37e1b4(_0x5ef9ae['result'][_0x34ea('0x20')]);}})[_0x34ea('0x21')](function(_0x151fae){logger['error']('ChatInteraction,\x20%s,\x20%s',_0x233b11,_0x151fae);_0x36af43(_0x151fae);});});}function respondWithStatusCode(_0x2eafc6,_0x3ff80e){_0x3ff80e=_0x3ff80e||0xcc;return function(_0x2a0ec2){if(_0x2a0ec2){return _0x2eafc6[_0x34ea('0x22')](_0x3ff80e);}return _0x2eafc6[_0x34ea('0x23')](_0x3ff80e)[_0x34ea('0x24')]();};}function respondWithResult(_0x5ade46,_0xf24962){_0xf24962=_0xf24962||0xc8;return function(_0x46671f){if(_0x46671f){return _0x5ade46[_0x34ea('0x23')](_0xf24962)[_0x34ea('0x25')](_0x46671f);}};}function respondWithFilteredResult(_0x5b5885,_0x56f320){return function(_0x564d1b){if(_0x564d1b){var _0x142709=typeof _0x56f320[_0x34ea('0x26')]===_0x34ea('0x27')&&typeof _0x56f320[_0x34ea('0x28')]==='undefined';var _0x26c80b=_0x564d1b[_0x34ea('0x29')];var _0x27c6f7=_0x142709?0x0:_0x56f320['offset'];var _0x4cded8=_0x142709?_0x564d1b['count']:_0x56f320['offset']+_0x56f320[_0x34ea('0x28')];var _0x6227db;if(_0x4cded8>=_0x26c80b){_0x4cded8=_0x26c80b;_0x6227db=0xc8;}else{_0x6227db=0xce;}_0x5b5885[_0x34ea('0x23')](_0x6227db);return _0x5b5885[_0x34ea('0x2a')]('Content-Range',_0x27c6f7+'-'+_0x4cded8+'/'+_0x26c80b)[_0x34ea('0x25')](_0x564d1b);}return null;};}function saveUpdates(_0x59b9f6){return function(_0x2c6de8){if(_0x2c6de8){return _0x2c6de8['update'](_0x59b9f6)[_0x34ea('0x17')](function(_0x14e018){return _0x14e018;});}return null;};}function removeEntity(_0x3cb968){return function(_0x57b19d){if(_0x57b19d){return _0x57b19d[_0x34ea('0x2b')]()[_0x34ea('0x17')](function(){_0x3cb968['status'](0xcc)[_0x34ea('0x24')]();});}};}function handleEntityNotFound(_0x5717e6){return function(_0x1392b6){if(!_0x1392b6){_0x5717e6[_0x34ea('0x22')](0x194);}return _0x1392b6;};}function handleError(_0x2d358e,_0x5ead76){_0x5ead76=_0x5ead76||0x1f4;return function(_0x4c5fb4){logger[_0x34ea('0x1e')](_0x4c5fb4['stack']);if(_0x4c5fb4[_0x34ea('0x2c')]){delete _0x4c5fb4[_0x34ea('0x2c')];}_0x2d358e['status'](_0x5ead76)[_0x34ea('0x2d')](_0x4c5fb4);};}function getMustacheRender(_0x3b7d8d,_0x2cdde6){return Mustache[_0x34ea('0x2e')](_0x3b7d8d,_['merge'](_0x2cdde6['body'],{'contact':_0x2cdde6['contact'],'message':_0x2cdde6[_0x34ea('0x20')],'agent':_0x2cdde6[_0x34ea('0x2f')],'interaction':_0x2cdde6[_0x34ea('0x30')],'account':_0x2cdde6['account']}))||'';}function getInteractionUsers(_0x4e26e0,_0x47ba14){return new BPromise(function(_0x156ce6,_0x39fe11){try{if(_0x47ba14[_0x4e26e0['id']]){_0x4e26e0['Users']=_[_0x34ea('0x31')](_0x47ba14[_0x4e26e0['id']],function(_0x240c77){return{'id':_0x240c77['id'],'fullname':_0x240c77[_0x34ea('0x32')]};});}}catch(_0x16a969){_0x39fe11(_0x16a969);}_0x156ce6(_0x4e26e0);});}function getInteractionTags(_0x3a393b,_0x185883){return new BPromise(function(_0x4e99e4,_0x2faf49){try{if(_0x3a393b[_0x34ea('0x33')]){_0x3a393b[_0x34ea('0x34')]=[];_0x3a393b[_0x34ea('0x33')]['split'](',')['forEach'](function(_0x6f024c){_0x3a393b[_0x34ea('0x34')][_0x34ea('0x35')](_0x185883[_0x6f024c]);});}delete _0x3a393b[_0x34ea('0x33')];}catch(_0x29260c){_0x2faf49(_0x29260c);}_0x4e99e4(_0x3a393b);});}function updateChatInteraction(_0x4c696f,_0x31bdfe,_0xb19a03){return new BPromise(function(_0x475313,_0x3a6a90){return getInteractionUsers(_0x4c696f,_0xb19a03)[_0x34ea('0x17')](function(_0x4743f1){return getInteractionTags(_0x4743f1,_0x31bdfe);})[_0x34ea('0x17')](function(_0xa1ff39){return getStateInteraction(_0xa1ff39);})[_0x34ea('0x17')](function(_0x1b5b56){_0x475313(_0x1b5b56);})[_0x34ea('0x21')](function(_0x109cff){_0x3a6a90(_0x109cff);});});}function getStateInteraction(_0x218691){return new BPromise(function(_0x41fefb){_0x218691[_0x34ea('0x36')]=0x0;_0x218691[_0x34ea('0x37')]=0x0;_0x218691['answered']=0x0;_0x218691[_0x34ea('0x38')]=0x0;_0x218691['abandoned']=0x0;_0x218691[_0x34ea('0x39')]=0x0;if(!_0x218691[_0x34ea('0x3a')]&&!_0x218691[_0x34ea('0x3b')]){_0x218691[_0x34ea('0x36')]+=0x1;}if(!_0x218691[_0x34ea('0x3a')]&&_0x218691[_0x34ea('0x3b')]){_0x218691[_0x34ea('0x37')]+=0x1;if(_0x218691[_0x34ea('0x36')]){_0x218691[_0x34ea('0x36')]-=0x1;}}if(_0x218691['closed']&&_0x218691[_0x34ea('0x3c')]==='abandoned'){_0x218691[_0x34ea('0x3d')]+=0x1;if(_0x218691[_0x34ea('0x36')]){_0x218691[_0x34ea('0x36')]-=0x1;}}else if(_0x218691[_0x34ea('0x3a')]&&!_0x218691[_0x34ea('0x3b')]&&_0x218691[_0x34ea('0x3c')]){_0x218691['unmanaged']+=0x1;if(_0x218691[_0x34ea('0x36')]){_0x218691[_0x34ea('0x36')]-=0x1;}}else if(_0x218691['closed']&&_0x218691[_0x34ea('0x3b')]){_0x218691[_0x34ea('0x3e')]+=0x1;if(_0x218691[_0x34ea('0x37')]){_0x218691[_0x34ea('0x37')]-=0x1;}}_0x218691[_0x34ea('0x39')]+=0x1;_0x41fefb(_0x218691);});}exports['index']=function(_0x4384cc,_0x180444){var _0x3f7456={},_0x2487bd={},_0x3e2e61={'count':0x0,'rows':[]};var _0x16c1a6=_['map'](db['ChatInteraction'][_0x34ea('0x3f')],function(_0x117047){return{'name':_0x117047[_0x34ea('0x40')],'type':_0x117047['type'][_0x34ea('0x41')]};});_0x2487bd['model']=_[_0x34ea('0x31')](_0x16c1a6,'name');_0x2487bd[_0x34ea('0x42')]=_[_0x34ea('0x43')](_0x4384cc[_0x34ea('0x42')]);_0x2487bd['filters']=_[_0x34ea('0x44')](_0x2487bd['model'],_0x2487bd[_0x34ea('0x42')]);_0x3f7456[_0x34ea('0x45')]=_[_0x34ea('0x44')](_0x2487bd[_0x34ea('0x46')],qs['fields'](_0x4384cc[_0x34ea('0x42')][_0x34ea('0x47')]));_0x3f7456[_0x34ea('0x45')]=_0x3f7456[_0x34ea('0x45')][_0x34ea('0x48')]?_0x3f7456[_0x34ea('0x45')]:_0x2487bd[_0x34ea('0x46')];if(!_0x4384cc['query'][_0x34ea('0x49')](_0x34ea('0x4a'))){_0x3f7456[_0x34ea('0x28')]=qs[_0x34ea('0x28')](_0x4384cc[_0x34ea('0x42')][_0x34ea('0x28')]);_0x3f7456[_0x34ea('0x26')]=qs[_0x34ea('0x26')](_0x4384cc[_0x34ea('0x42')][_0x34ea('0x26')]);}_0x3f7456[_0x34ea('0x4b')]=qs[_0x34ea('0x4c')](_0x4384cc[_0x34ea('0x42')]['sort']);_0x3f7456[_0x34ea('0x4d')]=qs[_0x34ea('0x4e')](_[_0x34ea('0x4f')](_0x4384cc['query'],_0x2487bd[_0x34ea('0x4e')]),_0x16c1a6);var _0x4f00f0=[];var _0x16497b=squel[_0x34ea('0x50')]()['field']('id')[_0x34ea('0x51')](_0x34ea('0x2c'))[_0x34ea('0x51')]('color')['from'](_0x34ea('0x52'));var _0x481054=squel['select']()[_0x34ea('0x51')]('u.id')[_0x34ea('0x51')](_0x34ea('0x53'))[_0x34ea('0x51')](_0x34ea('0x54'))[_0x34ea('0x55')](_0x34ea('0x56'),'ui')[_0x34ea('0x57')](_0x34ea('0x58'),'u',_0x34ea('0x59'));var _0x30d4a5=squel[_0x34ea('0x50')]()[_0x34ea('0x55')](_0x34ea('0x5a'),'i')[_0x34ea('0x57')](_0x34ea('0x5b'),'c',_0x34ea('0x5c'))['left_join'](_0x34ea('0x58'),'o','o.id\x20=\x20i.UserId')[_0x34ea('0x57')](_0x34ea('0x5d'),'a',_0x34ea('0x5e'))[_0x34ea('0x57')](_0x34ea('0x5f'),'me',_0x34ea('0x60'))['left_join'](_0x34ea('0x61'),'it',_0x34ea('0x62'))[_0x34ea('0x57')](_0x34ea('0x52'),'t',_0x34ea('0x63'));var _0x55549e=squel[_0x34ea('0x64')]();var _0x5814ef=[];var _0x58b428=squel['expr']();var _0x3247f0;if(_0x4384cc['query'][_0x34ea('0x65')]){_0x3247f0=as['parseSearch'](_0x4384cc[_0x34ea('0x42')]['search']);var _0x3d649f=_0x3247f0['sqlOperator'];for(var _0xd5ed90=0x0;_0xd5ed90<_0x3247f0[_0x34ea('0x66')][_0x34ea('0x48')];_0xd5ed90++){var _0x83c14e=_0x3247f0[_0x34ea('0x66')][_0xd5ed90];var _0x4916f9='i';var _0x4c59b0=_[_0x34ea('0x67')](_0x16c1a6,[_0x34ea('0x2c'),_0x83c14e[_0x34ea('0x51')]]);if(!_0x4c59b0){switch(_0x83c14e[_0x34ea('0x51')]){case _0x34ea('0x68'):if(_0x83c14e[_0x34ea('0x69')]==0x1){_0x30d4a5[_0x34ea('0x6a')]('`'+_0x83c14e[_0x34ea('0x51')]+_0x34ea('0x6b'));}else{_0x30d4a5['having']('`'+_0x83c14e[_0x34ea('0x51')]+_0x34ea('0x6c'));}break;case _0x34ea('0x6d'):if(_0x83c14e['operator']==='$substring'){if(_0x83c14e[_0x34ea('0x69')][_0x34ea('0x6e')]('\x20')[_0x34ea('0x48')]>0x1){_0x55549e[_0x3d649f]('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x34ea('0x6f')](_0x83c14e[_0x34ea('0x69')]),null);}else{var _0x38542d='%'+_0x83c14e['value']+'%';_0x55549e[_0x3d649f](_0x34ea('0x70'),_0x38542d,_0x38542d,_0x38542d);}}else{_0x4c59b0=_[_0x34ea('0x67')](_0x16c1a6,['name',_0x34ea('0x71')]);_0x83c14e[_0x34ea('0x51')]=_0x34ea('0x71');_0x5850f0=as['buildExpression'](_0x4916f9,_0x4c59b0[_0x34ea('0x72')],_0x83c14e);_0x55549e[_0x3d649f](_0x5850f0['text'],_0x5850f0[_0x34ea('0x69')][_0x34ea('0x73')],_0x5850f0[_0x34ea('0x69')][_0x34ea('0x24')]);}break;case'Tag':var _0x14cfe0=_0x83c14e[_0x34ea('0x69')]['split'](',')[_0x34ea('0x31')](function(_0x5cb452){return Number(_0x5cb452);});_0x14cfe0[_0x34ea('0x74')](function(_0x39296e){_0x58b428['or'](_0x34ea('0x75'),'%,'+_0x39296e+',%');});_0x5814ef=_['union'](_0x5814ef,_0x14cfe0);break;case _0x34ea('0x76'):if(_0x83c14e[_0x34ea('0x77')]===_0x34ea('0x78')){_0x55549e[_0x3d649f](_0x34ea('0x79'),'%'+_0x83c14e['value']+'%',null);}else{_0x4c59b0=_[_0x34ea('0x67')](_0x16c1a6,[_0x34ea('0x2c'),_0x34ea('0x3b')]);_0x83c14e[_0x34ea('0x51')]='UserId';_0x5850f0=as['buildExpression'](_0x4916f9,_0x4c59b0[_0x34ea('0x72')],_0x83c14e);_0x55549e[_0x3d649f](_0x5850f0[_0x34ea('0x7a')],_0x5850f0['value'][_0x34ea('0x73')],_0x5850f0[_0x34ea('0x69')][_0x34ea('0x24')]);}break;case'body':_0x5850f0=as['buildExpression']('me',null,_0x83c14e);_0x55549e[_0x3d649f](_0x5850f0['text'],_0x5850f0[_0x34ea('0x69')]['start'],_0x5850f0[_0x34ea('0x69')]['end']);break;}}else{var _0x5850f0=as['buildExpression'](_0x4916f9,_0x4c59b0[_0x34ea('0x72')],_0x83c14e);_0x55549e[_0x3d649f](_0x5850f0[_0x34ea('0x7a')],_0x5850f0[_0x34ea('0x69')][_0x34ea('0x73')],_0x5850f0[_0x34ea('0x69')][_0x34ea('0x24')]);}}}else{var _0x18fdb9=_(_0x4384cc[_0x34ea('0x42')])[_0x34ea('0x43')]()['map'](function(_0x13d47c){return _['some'](_0x16c1a6,['name',_0x13d47c])?_0x13d47c:undefined;})[_0x34ea('0x7b')]()['value']();if(!_[_0x34ea('0x7c')](_0x18fdb9)){_0x18fdb9[_0x34ea('0x74')](function(_0x3bdb7b){if(_0x3bdb7b==='ChatWebsiteId'){_0x30d4a5[_0x34ea('0x4d')]('i.ChatWebsiteId\x20IN\x20?',[][_0x34ea('0x7d')](_0x4384cc[_0x34ea('0x42')][_0x3bdb7b]));}else if(_0x3bdb7b===_0x34ea('0x7e')){var _0xbde6b2=JSON[_0x34ea('0x7f')](_0x4384cc[_0x34ea('0x42')][_0x3bdb7b])[_0x34ea('0x80')];var _0x2625e5=JSON['parse'](_0x4384cc[_0x34ea('0x42')][_0x3bdb7b])[_0x34ea('0x81')];_0x30d4a5[_0x34ea('0x4d')](_0x34ea('0x82'),_0xbde6b2,_0x2625e5);}else{if(_0x4384cc[_0x34ea('0x42')][_0x3bdb7b]==='null'){_0x30d4a5[_0x34ea('0x4d')]('i.'+_0x3bdb7b+'\x20IS\x20NULL');}else{_0x30d4a5[_0x34ea('0x4d')]('i.'+_0x3bdb7b+'\x20=\x20?',_0x4384cc['query'][_0x3bdb7b]);}}});}if(_0x4384cc['query'][_0x34ea('0x83')]){if(_0x4384cc[_0x34ea('0x42')][_0x34ea('0x83')]==0x1){_0x30d4a5['having'](_0x34ea('0x84'));}else{_0x30d4a5['having'](_0x34ea('0x85'));}}if(_0x4384cc['query']['tag']){_0x5814ef=_[_0x34ea('0x86')](_0x4384cc[_0x34ea('0x42')][_0x34ea('0x87')])?_0x4384cc[_0x34ea('0x42')][_0x34ea('0x87')]:new Array(_0x4384cc['query'][_0x34ea('0x87')]);_0x5814ef['forEach'](function(_0x56f17c){_0x58b428['or'](_0x34ea('0x75'),'%,'+_0x56f17c+',%');});}if(_0x4384cc[_0x34ea('0x42')][_0x34ea('0x88')]){var _0xc58265=_0x4384cc['query'][_0x34ea('0x88')][_0x34ea('0x89')]('\x5c','\x5c\x5c')[_0x34ea('0x89')](/'/g,'\x27\x27');if(qs[_0x34ea('0x8a')](_0xc58265)){_0x55549e['or'](_0x34ea('0x8b'),_0xc58265+'%');}else{_0x55549e['or'](_0x34ea('0x8c'),qs[_0x34ea('0x6f')](_0xc58265))['or'](_0x34ea('0x8d'),_0xc58265+'%');}}}_0x30d4a5[_0x34ea('0x4d')](_0x55549e);_0x30d4a5[_0x34ea('0x8e')](_0x34ea('0x8f'));var _0x2365a7={'type':db[_0x34ea('0x90')][_0x34ea('0x91')][_0x34ea('0x92')],'raw':!![]};var _0x4822a5=_0x30d4a5[_0x34ea('0x93')]();_0x4822a5[_0x34ea('0x51')](_0x34ea('0x8f'));_0x4822a5['field'](_0x34ea('0x94'),'unreadMessages');if(_0x3f7456[_0x34ea('0x4b')]){_0x3f7456[_0x34ea('0x4b')][_0x34ea('0x74')](function(_0x15ac2a){var _0x146a83=_0x15ac2a[0x0]===_0x34ea('0x95')?_0x15ac2a[0x0]:'i.'+_0x15ac2a[0x0];_0x30d4a5[_0x34ea('0x4b')](_0x146a83,_0x15ac2a[0x1]===_0x34ea('0x96')?![]:!![]);});}if(!_[_0x34ea('0x7c')](_0x5814ef)){_0x30d4a5['having'](_0x58b428);_0x4822a5[_0x34ea('0x4d')]('t.id\x20IN\x20?',_0x5814ef);}BPromise[_0x34ea('0x97')]()[_0x34ea('0x17')](function(){if(!_0x3247f0){if(_0x4384cc[_0x34ea('0x42')][_0x34ea('0x98')])return;_0x4822a5[_0x34ea('0x4d')]('i.ChatWebsiteId\x20IS\x20NOT\x20NULL');_0x30d4a5[_0x34ea('0x4d')]('i.ChatWebsiteId\x20IS\x20NOT\x20NULL');return;}if(_0x4384cc['user']['role']!==_0x34ea('0x2f'))return;return _0x4384cc[_0x34ea('0x99')][_0x34ea('0x9a')]({'attributes':['id'],'raw':!![]})[_0x34ea('0x17')](function(_0x4d5eb8){if(_[_0x34ea('0x7c')](_0x4d5eb8)){_0x4822a5[_0x34ea('0x4d')](_0x34ea('0x9b'));_0x30d4a5[_0x34ea('0x4d')](_0x34ea('0x9b'));}else{_0x4822a5['where'](_0x34ea('0x9c'),_['map'](_0x4d5eb8,'id'));_0x30d4a5[_0x34ea('0x4d')](_0x34ea('0x9c'),_[_0x34ea('0x31')](_0x4d5eb8,'id'));}});})[_0x34ea('0x17')](function(){if(_0x4384cc[_0x34ea('0x99')][_0x34ea('0x9d')]==='agent'&&!_0x3247f0&&!_0x4384cc[_0x34ea('0x42')][_0x34ea('0x98')])return[];return db[_0x34ea('0x9e')][_0x34ea('0x42')](_0x4822a5['toString'](),_0x2365a7);})[_0x34ea('0x17')](function(_0x13dfe2){_0x3e2e61['count']=_0x13dfe2[_0x34ea('0x48')];if(_0x3e2e61[_0x34ea('0x29')]===0x0)return[];return db[_0x34ea('0x9e')][_0x34ea('0x42')](_0x16497b[_0x34ea('0x9f')](),_0x2365a7)[_0x34ea('0x17')](function(_0x4e4947){_0x4f00f0=_[_0x34ea('0xa0')](_0x4e4947,'id');_0x2365a7=_[_0x34ea('0xa1')](_0x2365a7,{'model':db[_0x34ea('0xa2')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x4384cc[_0x34ea('0x42')][_0x34ea('0x47')]){_0x3f7456[_0x34ea('0x45')][_0x34ea('0x74')](function(_0x5f10a6){_0x30d4a5[_0x34ea('0x51')]('i.'+_0x5f10a6);});}else{_0x30d4a5[_0x34ea('0x51')](_0x34ea('0x94'),_0x34ea('0x68'));_0x30d4a5['field'](_0x34ea('0xa3'),_0x34ea('0xa4'));_0x30d4a5[_0x34ea('0x51')](_0x34ea('0xa5'),_0x34ea('0xa6'));_0x30d4a5[_0x34ea('0x51')](_0x34ea('0xa7'),_0x34ea('0x95'));_0x30d4a5[_0x34ea('0x51')](_0x34ea('0xa8'));_0x30d4a5[_0x34ea('0x51')]('c.firstName',_0x34ea('0xa9'));_0x30d4a5[_0x34ea('0x51')](_0x34ea('0xaa'),_0x34ea('0xab'));_0x30d4a5['field'](_0x34ea('0xac'),_0x34ea('0xad'));_0x30d4a5[_0x34ea('0x51')](_0x34ea('0xae'),'Contact.phone');_0x30d4a5[_0x34ea('0x51')]('c.mobile','Contact.mobile');_0x30d4a5[_0x34ea('0x51')](_0x34ea('0xaf'),_0x34ea('0xb0'));_0x30d4a5['field'](_0x34ea('0xb1'),_0x34ea('0xb2'));_0x30d4a5[_0x34ea('0x51')](_0x34ea('0xb3'),'Owner.internal');_0x30d4a5[_0x34ea('0x51')](_0x34ea('0xb4'),_0x34ea('0x33'));}if(_0x3f7456[_0x34ea('0x28')])_0x30d4a5[_0x34ea('0x28')](_0x3f7456[_0x34ea('0x28')]);if(_0x3f7456[_0x34ea('0x26')])_0x30d4a5[_0x34ea('0x26')](_0x3f7456[_0x34ea('0x26')]);return db[_0x34ea('0x9e')][_0x34ea('0x42')](_0x30d4a5['toString'](),_0x2365a7);})[_0x34ea('0x17')](function(_0x347acd){if(_0x347acd['length']>0x0)_0x481054[_0x34ea('0x4d')](_0x34ea('0xb5'),_[_0x34ea('0x31')](_0x347acd,'id'));return db['sequelize'][_0x34ea('0x42')](_0x481054['toString'](),_0x2365a7)[_0x34ea('0x17')](function(_0x1d48b5){var _0x4b424b=_[_0x34ea('0xb6')](_0x1d48b5,'ChatInteractionId');var _0x17e783=[];_0x347acd[_0x34ea('0x74')](function(_0x6a7b4a){_0x17e783[_0x34ea('0x35')](updateChatInteraction(_0x6a7b4a,_0x4f00f0,_0x4b424b));});return BPromise['all'](_0x17e783);});});})[_0x34ea('0x17')](function(_0x2f10c4){_0x3e2e61['rows']=_0x2f10c4;return _0x3e2e61;})[_0x34ea('0x17')](respondWithFilteredResult(_0x180444,_0x3f7456))[_0x34ea('0x21')](handleError(_0x180444,null));};exports[_0x34ea('0xb7')]=function(_0x40afee,_0x4d0ae5){var _0x31948f={'raw':![],'where':{'id':_0x40afee[_0x34ea('0xb8')]['id']}},_0x542b5f={};_0x542b5f[_0x34ea('0x46')]=_[_0x34ea('0x43')](db[_0x34ea('0xa2')]['rawAttributes']);_0x542b5f['query']=_[_0x34ea('0x43')](_0x40afee[_0x34ea('0x42')]);_0x542b5f[_0x34ea('0x4e')]=_[_0x34ea('0x44')](_0x542b5f[_0x34ea('0x46')],_0x542b5f[_0x34ea('0x42')]);_0x31948f['attributes']=_[_0x34ea('0x44')](_0x542b5f[_0x34ea('0x46')],qs[_0x34ea('0x47')](_0x40afee[_0x34ea('0x42')][_0x34ea('0x47')]));_0x31948f[_0x34ea('0x45')]=_0x31948f[_0x34ea('0x45')][_0x34ea('0x48')]?_0x31948f['attributes']:_0x542b5f[_0x34ea('0x46')];if(_0x40afee[_0x34ea('0x42')]['includeAll']){_0x31948f['include']=[{'all':!![]}];}_0x31948f=_[_0x34ea('0xa1')]({},_0x31948f,_0x40afee[_0x34ea('0xb9')]);return db['ChatInteraction'][_0x34ea('0x67')](_0x31948f)[_0x34ea('0x17')](handleEntityNotFound(_0x4d0ae5,null))[_0x34ea('0x17')](respondWithResult(_0x4d0ae5,null))[_0x34ea('0x21')](handleError(_0x4d0ae5,null));};exports['create']=function(_0x480ce2,_0x5c429e){return db[_0x34ea('0xa2')][_0x34ea('0xba')](_0x480ce2['body'],{})['then'](respondWithResult(_0x5c429e,0xc9))['catch'](handleError(_0x5c429e,null));};exports[_0x34ea('0xbb')]=function(_0x11d731,_0x38d687){if(_0x11d731[_0x34ea('0xbc')]['id']){delete _0x11d731[_0x34ea('0xbc')]['id'];}return db[_0x34ea('0xa2')]['find']({'where':{'id':_0x11d731[_0x34ea('0xb8')]['id']}})['then'](handleEntityNotFound(_0x38d687,null))[_0x34ea('0x17')](saveUpdates(_0x11d731[_0x34ea('0xbc')],null))[_0x34ea('0x17')](respondWithResult(_0x38d687,null))[_0x34ea('0x21')](handleError(_0x38d687,null));};exports['destroy']=function(_0x2b0acd,_0x1011a2){return db[_0x34ea('0xa2')][_0x34ea('0x67')]({'where':{'id':_0x2b0acd[_0x34ea('0xb8')]['id']}})[_0x34ea('0x17')](handleEntityNotFound(_0x1011a2,null))[_0x34ea('0x17')](removeEntity(_0x1011a2,null))[_0x34ea('0x21')](handleError(_0x1011a2,null));};exports['describe']=function(_0x5c2753,_0xdbd294){return db[_0x34ea('0xa2')][_0x34ea('0xbd')]()['then'](respondWithResult(_0xdbd294,null))['catch'](handleError(_0xdbd294,null));};exports['createVidaooSession']=function(_0x3922cd,_0x18784d){var _0x2e6b8b=_0x3922cd[_0x34ea('0xb8')]['id'];var _0x1a2f46;var _0x317c9f;var _0x2372ee;return db[_0x34ea('0xa2')][_0x34ea('0xbe')]({'where':{'id':_0x2e6b8b}})['then'](function(_0x32f3e3){_0x1a2f46=_0x32f3e3;return db[_0x34ea('0xbf')]['findOne']({'where':{'id':_0x32f3e3[_0x34ea('0x98')]},'attributes':['id',_0x34ea('0xc0'),_0x34ea('0xc1'),'vidaooTopic',_0x34ea('0xc2'),_0x34ea('0xc3')],'raw':!![]});})[_0x34ea('0x17')](function(_0x462c64){if(_0x462c64&&_0x462c64[_0x34ea('0xc0')]&&_0x462c64[_0x34ea('0xc1')]){_0x317c9f=_0x462c64;var _0x4a0d01={'interaction':{'id':_0x2e6b8b},'agent':{'id':_0x3922cd[_0x34ea('0x99')]['id'],'name':_0x3922cd[_0x34ea('0x99')][_0x34ea('0x2c')],'fullname':_0x3922cd[_0x34ea('0x99')][_0x34ea('0x32')],'email':_0x3922cd[_0x34ea('0x99')][_0x34ea('0xc4')]},'contact':_0x3922cd[_0x34ea('0xbc')][_0x34ea('0xc5')],'account':_0x3922cd[_0x34ea('0xbc')]['account']};var _0x26b9d3={'rejectUnauthorized':![],'method':_0x34ea('0xc6'),'url':_0x34ea('0xc7'),'headers':{'X-APIKEY':_0x462c64[_0x34ea('0xc0')]},'body':{'duration':null,'scheduledAt':null,'participants':[_0x3922cd[_0x34ea('0x99')][_0x34ea('0xc4')]],'buttons':null,'topic':_0x317c9f[_0x34ea('0xc8')],'note':_['isNull'](_0x317c9f[_0x34ea('0xc2')])?null:getMustacheRender(_0x317c9f[_0x34ea('0xc2')],_0x4a0d01),'metadata':null},'redirect':'follow','json':!![]};try{if(!_[_0x34ea('0xc9')](_0x317c9f[_0x34ea('0xc3')])){var _0x509622=getMustacheRender(_0x317c9f[_0x34ea('0xc3')],_0x4a0d01);var _0x3327fa=JSON[_0x34ea('0x7f')](_0x509622);_0x26b9d3['body'][_0x34ea('0xca')]=_0x3327fa;}}catch(_0x1ef257){throw new db[(_0x34ea('0x90'))][(_0x34ea('0xcb'))](_0x34ea('0xcc'));}return rp(_0x26b9d3);}else{throw new db['Sequelize']['ValidationError'](_0x34ea('0xcd'));}})[_0x34ea('0x17')](function(_0x4b4491){_0x2372ee=_0x4b4491;if(_0x2372ee['id']){var _0x22fa63={'body':_0x2372ee[_0x34ea('0xce')],'ChatWebsiteId':_0x317c9f['id'],'ChatInteractionId':_0x1a2f46['id'],'direction':_0x34ea('0xcf'),'UserId':_0x3922cd[_0x34ea('0x99')]['id']};return db['ChatMessage'][_0x34ea('0xba')](_0x22fa63,{});}else{throw new db['Sequelize'][(_0x34ea('0xcb'))](_0x34ea('0xd0'));}})[_0x34ea('0x17')](function(){return _0x1a2f46[_0x34ea('0xd1')]({'vidaooSessionId':_0x2372ee['id']});})[_0x34ea('0x17')](respondWithResult(_0x18784d,null))[_0x34ea('0x21')](handleError(_0x18784d,null));};exports['customUpdate']=function(_0x50b728,_0x492239){if(_0x50b728[_0x34ea('0xbc')]['id']){delete _0x50b728['body']['id'];}return db[_0x34ea('0xa2')][_0x34ea('0x67')]({'where':{'id':_0x50b728[_0x34ea('0xb8')]['id']},'include':[{'model':db[_0x34ea('0xd2')],'as':_0x34ea('0x6d')}]})[_0x34ea('0x17')](handleEntityNotFound(_0x492239,null))[_0x34ea('0x17')](saveUpdates(_0x50b728['body'],null))[_0x34ea('0x17')](respondWithResult(_0x492239,null))[_0x34ea('0x21')](handleError(_0x492239,null));};exports[_0x34ea('0xd3')]=function(_0x267b94,_0x316361){if(_0x267b94[_0x34ea('0xbc')]['id']){delete _0x267b94[_0x34ea('0xbc')]['id'];}return db[_0x34ea('0xa2')][_0x34ea('0x67')]({'where':{'id':_0x267b94[_0x34ea('0xb8')]['id']}})[_0x34ea('0x17')](function(_0x4a26b2){if(!_0x4a26b2){logger[_0x34ea('0x1e')]('abandonInteraction,\x20%s,\x20%s,\x20%s','abandon',0x194,_0x34ea('0xd4'));_0x316361[_0x34ea('0x22')](0x194);}else{if(_0x4a26b2['UserId']){throw new db[(_0x34ea('0x90'))][(_0x34ea('0xcb'))](_0x34ea('0xd5'));}}return _0x4a26b2;})['then'](function(_0x201557){if(_0x201557){return _0x201557[_0x34ea('0xbb')]({'closed':_0x267b94[_0x34ea('0xbc')][_0x34ea('0x3a')],'disposition':_0x267b94['body'][_0x34ea('0x3c')]})['then'](function(_0x3baefe){return _0x3baefe;});}})[_0x34ea('0x17')](function(){return respondWithRpcPromise('AbandonInteraction',_0x34ea('0xd3'),_0x267b94[_0x34ea('0xbc')],client9004);})[_0x34ea('0x17')](respondWithResult(_0x316361,null))[_0x34ea('0x21')](handleError(_0x316361,null));};exports[_0x34ea('0xd6')]=function(_0x24871b,_0x402f29){_0x24871b[_0x34ea('0xbc')][_0x34ea('0x2c')]=_0x24871b[_0x34ea('0xd7')]['originalname'];_0x24871b[_0x34ea('0xbc')][_0x34ea('0xd8')]=_0x24871b[_0x34ea('0xd7')][_0x34ea('0xd9')];_0x24871b['body'][_0x34ea('0x72')]=_0x24871b[_0x34ea('0xd7')][_0x34ea('0xda')];return db[_0x34ea('0xdb')][_0x34ea('0xba')](_0x24871b['body'])[_0x34ea('0x17')](respondWithResult(_0x402f29,0xc9))[_0x34ea('0x21')](handleError(_0x402f29,null));};exports[_0x34ea('0xdc')]=function(_0x5ac2c4,_0x15ff4b){return db[_0x34ea('0xa2')]['findOne']({'where':{'id':_0x5ac2c4['params']['id']},'raw':!![]})[_0x34ea('0x17')](handleEntityNotFound(_0x15ff4b,null))[_0x34ea('0x17')](function(_0x46f60a){if(_0x46f60a){if(_0x46f60a[_0x34ea('0x3a')]){return _0x15ff4b[_0x34ea('0x23')](0x193)[_0x34ea('0x25')]({'status':0x193,'message':'Unauthorized'});}return db[_0x34ea('0xdb')]['findOne']({'where':{'id':_0x5ac2c4[_0x34ea('0x42')][_0x34ea('0xdd')]},'raw':!![]})[_0x34ea('0x17')](handleEntityNotFound(_0x15ff4b,null));}})[_0x34ea('0x17')](function(_0x24959d){if(_0x24959d){var _0xaeae99=_0x24959d['ChatOfflineMessageId']!==null;var _0x13563c=path[_0x34ea('0xde')](config[_0x34ea('0xdf')],'server/files/attachments/');if(_0xaeae99){_0x13563c=path[_0x34ea('0xde')](_0x13563c,_0x34ea('0xe0'));}var _0x1df2e9=path[_0x34ea('0xde')](_0x13563c,_0x24959d['basename']);return _0x15ff4b[_0x34ea('0xe1')](_0x1df2e9);}})[_0x34ea('0x21')](handleError(_0x15ff4b,null));};exports[_0x34ea('0xe2')]=function(_0x1ab953,_0x4d2ff5){var _0x538e97=null;var _0x2c2f31=null;var _0xa56581=null;if(_0x1ab953[_0x34ea('0xbc')]['id']){delete _0x1ab953[_0x34ea('0xbc')]['id'];}if(_0x1ab953[_0x34ea('0xbc')][_0x34ea('0xe3')]){_0xa56581=path[_0x34ea('0xde')](config[_0x34ea('0xdf')],_0x34ea('0xe4'),util[_0x34ea('0xe5')](_0x34ea('0xe6'),Date[_0x34ea('0xe7')]()));_0x1ab953[_0x34ea('0xbc')][_0x34ea('0xe8')]=_0xa56581;}return db[_0x34ea('0xa2')][_0x34ea('0x67')]({'where':{'id':_0x1ab953[_0x34ea('0xb8')]['id']},'include':[{'model':db['ChatMessage'],'as':_0x34ea('0xe9'),'include':[{'model':db[_0x34ea('0x76')],'as':_0x34ea('0x76')}]}]})['then'](handleEntityNotFound(_0x4d2ff5,null))[_0x34ea('0x17')](saveUpdates(_0x1ab953[_0x34ea('0xbc')],null))['then'](function(_0x1f1693){if(_0x1f1693){_0x538e97=_0x1f1693;return db[_0x34ea('0xbf')]['find']({'where':{'id':_0x538e97[_0x34ea('0x98')]}});}})[_0x34ea('0x17')](function(_0x39f944){if(_0x39f944){_0x2c2f31=_0x39f944;return db[_0x34ea('0xd2')][_0x34ea('0x67')]({'where':{'id':_0x538e97[_0x34ea('0x71')]}});}})['then'](function(_0x11f23a){if(_0x11f23a){if(_0xa56581){var _0x146ce8=null;for(var _0x1f5805=0x1;_0x1f5805<_0x538e97[_0x34ea('0xe9')][_0x34ea('0x48')];++_0x1f5805){_0x146ce8=_0x538e97[_0x34ea('0xe9')][_0x1f5805];var _0x440ce9=_0x146ce8[_0x34ea('0x3b')]?util[_0x34ea('0xe5')](_0x34ea('0xea'),_0x2c2f31[_0x34ea('0xeb')],_0x146ce8[_0x34ea('0x3b')]):'System';var _0x2cd229=_0x1ab953['body'][_0x34ea('0xec')]||util[_0x34ea('0xe5')](_0x34ea('0xea'),_0x34ea('0xed'),_0x146ce8[_0x34ea('0x71')]);switch(_0x2c2f31[_0x34ea('0xee')]){case _0x34ea('0xef'):_0x440ce9=_0x146ce8[_0x34ea('0x3b')]?util[_0x34ea('0xe5')](_0x34ea('0xea'),_0x2c2f31['agentAlias'],_0x146ce8[_0x34ea('0x3b')]):_0x34ea('0xf0');break;case _0x34ea('0xf1'):_0x440ce9=_0x146ce8[_0x34ea('0x3b')]?_0x146ce8[_0x34ea('0x76')][_0x34ea('0xf2')]||_0x146ce8['User'][_0x34ea('0x32')]:_0x34ea('0xf0');break;case _0x34ea('0xf3'):_0x440ce9=_0x146ce8['UserId']?_0x146ce8[_0x34ea('0x76')][_0x34ea('0x32')]:'System';break;default:_0x440ce9=_0x146ce8['UserId']?util[_0x34ea('0xe5')](_0x34ea('0xea'),_0x2c2f31[_0x34ea('0xeb')],_0x146ce8[_0x34ea('0x3b')]):_0x34ea('0xf0');}var _0x381630=util[_0x34ea('0xe5')]('[%s]\x20%s:\x20%s\x0a',moment(_0x146ce8['createdAt'])[_0x34ea('0xe5')](_0x34ea('0xf4')),_0x146ce8[_0x34ea('0xf5')]==='in'?_0x2cd229:_0x440ce9,_0x146ce8['body']);if(!_0x146ce8[_0x34ea('0xf6')]){fs[_0x34ea('0xf7')](_0xa56581,_0x381630);}}return db[_0x34ea('0xf8')][_0x34ea('0xbe')]({'where':{'service':!![]},'include':[{'model':db['MailServerOut'],'as':_0x34ea('0xf9'),'raw':!![],'include':[{'model':db[_0x34ea('0xfa')],'as':'CloudProvider','raw':!![]}]}]});}}})[_0x34ea('0x17')](function(_0x4ff9c6){if(!_0x4ff9c6||!_0x4ff9c6[_0x34ea('0xf9')]||!_0x1ab953['body'])return _0x538e97;var _0xd11b7d=_0x4ff9c6[_0x34ea('0xfb')]();return respondWithRpcPromise(_0x34ea('0xfc'),_0x34ea('0xfd'),{'account':_0xd11b7d,'message':{'from':util[_0x34ea('0xe5')](_0x34ea('0xfe'),_0x4ff9c6['name'],_0x4ff9c6[_0x34ea('0xc4')]||_0x4ff9c6['Smtp'][_0x34ea('0x99')]),'to':_0x1ab953[_0x34ea('0xbc')][_0x34ea('0xe3')],'subject':_0x34ea('0xff'),'text':util[_0x34ea('0xe5')](_0x34ea('0x100'),_0x1ab953[_0x34ea('0xbc')][_0x34ea('0xe3')]),'attachments':[{'path':_0xa56581}]}})[_0x34ea('0x17')](function(){return _0x538e97;})[_0x34ea('0x21')](function(_0x4da7a5){logger[_0x34ea('0x1e')](_0x4da7a5);});})[_0x34ea('0x17')](respondWithStatusCode(_0x4d2ff5,0xc8))['catch'](handleError(_0x4d2ff5,null));};exports[_0x34ea('0x101')]=function(_0x4a0a5e,_0x29d8d1){return db[_0x34ea('0x102')][_0x34ea('0x67')]({'where':{'id':_0x4a0a5e[_0x34ea('0xb8')]['id']}})[_0x34ea('0x17')](handleEntityNotFound(_0x29d8d1,null))[_0x34ea('0x17')](function(_0x590951){if(_0x590951){return _0x590951[_0x34ea('0x101')](_0x4a0a5e[_0x34ea('0xbc')][_0x34ea('0x103')],_[_0x34ea('0x104')](_0x4a0a5e[_0x34ea('0xbc')],[_0x34ea('0x103'),'id'])||{});}})['then'](respondWithResult(_0x29d8d1,null))[_0x34ea('0x21')](handleError(_0x29d8d1,null));};exports[_0x34ea('0x105')]=function(_0x3133c3,_0x1fb802){var _0x1b57b1={'raw':![],'where':{}};var _0x455bac={};var _0x22ebe2={'count':0x0,'rows':[]};return db[_0x34ea('0xa2')][_0x34ea('0xbe')]({'where':{'id':_0x3133c3['params']['id']}})[_0x34ea('0x17')](handleEntityNotFound(_0x1fb802,null))[_0x34ea('0x17')](function(_0x41eb2b){if(_0x41eb2b){_0x455bac[_0x34ea('0x46')]=_[_0x34ea('0x43')](db[_0x34ea('0x102')][_0x34ea('0x3f')]);_0x455bac[_0x34ea('0x42')]=_[_0x34ea('0x43')](_0x3133c3[_0x34ea('0x42')]);_0x455bac['filters']=_['intersection'](_0x455bac[_0x34ea('0x46')],_0x455bac[_0x34ea('0x42')]);_0x1b57b1[_0x34ea('0x45')]=_['intersection'](_0x455bac['model'],qs[_0x34ea('0x47')](_0x3133c3['query'][_0x34ea('0x47')]));_0x1b57b1[_0x34ea('0x45')]=_0x1b57b1[_0x34ea('0x45')][_0x34ea('0x48')]?_0x1b57b1[_0x34ea('0x45')]:_0x455bac['model'];if(!_0x3133c3['query'][_0x34ea('0x49')](_0x34ea('0x4a'))){_0x1b57b1[_0x34ea('0x28')]=qs[_0x34ea('0x28')](_0x3133c3[_0x34ea('0x42')][_0x34ea('0x28')]);_0x1b57b1[_0x34ea('0x26')]=qs['offset'](_0x3133c3[_0x34ea('0x42')][_0x34ea('0x26')]);}_0x1b57b1[_0x34ea('0x4b')]=qs[_0x34ea('0x4c')](_0x3133c3[_0x34ea('0x42')][_0x34ea('0x4c')]);_0x1b57b1[_0x34ea('0x4d')]=qs[_0x34ea('0x4e')](_[_0x34ea('0x4f')](_0x3133c3[_0x34ea('0x42')],_0x455bac[_0x34ea('0x4e')]));_0x1b57b1[_0x34ea('0x4d')][_0x34ea('0x106')]=_0x41eb2b['id'];if(_0x3133c3[_0x34ea('0x42')][_0x34ea('0x88')]){_0x1b57b1[_0x34ea('0x4d')]=_['merge'](_0x1b57b1[_0x34ea('0x4d')],{'$or':_['map'](_0x1b57b1[_0x34ea('0x45')],function(_0x30be05){var _0x551851={};_0x551851[_0x30be05]={'$like':'%'+_0x3133c3[_0x34ea('0x42')]['filter']+'%'};return _0x551851;})});}if(_0x3133c3[_0x34ea('0x42')][_0x34ea('0x80')]){var _0x48e3f4=_0x3133c3[_0x34ea('0x42')]['$gte']['split'](',');var _0x49e56e={};_0x49e56e[_0x48e3f4[0x0]]={'$gte':moment(_0x48e3f4[0x1])['format'](_0x34ea('0x107'))};_0x1b57b1['where']=_['merge'](_0x1b57b1[_0x34ea('0x4d')],_0x49e56e);}_0x1b57b1=_[_0x34ea('0xa1')]({},_0x1b57b1,_0x3133c3[_0x34ea('0xb9')]);return db['ChatMessage'][_0x34ea('0x29')]({'where':_0x1b57b1[_0x34ea('0x4d')]})[_0x34ea('0x17')](function(_0x133d0e){_0x22ebe2[_0x34ea('0x29')]=_0x133d0e;if(_0x3133c3[_0x34ea('0x42')][_0x34ea('0x108')]){_0x1b57b1[_0x34ea('0x109')]=[{'all':!![]}];}return db['ChatMessage'][_0x34ea('0x10a')](_0x1b57b1);})[_0x34ea('0x17')](function(_0x1a90d8){_0x22ebe2[_0x34ea('0x10b')]=_0x1a90d8;return _0x22ebe2;});}})[_0x34ea('0x17')](respondWithFilteredResult(_0x1fb802,_0x1b57b1))[_0x34ea('0x21')](handleError(_0x1fb802,null));};exports[_0x34ea('0x10c')]=function(_0x46f1b6,_0x18ad0c){var _0x255029={'where':{}},_0x4301bd={},_0x813efb={'count':0x0,'rows':[]};return db[_0x34ea('0xa2')][_0x34ea('0xbe')]({'where':{'id':_0x46f1b6[_0x34ea('0xb8')]['id']}})[_0x34ea('0x17')](handleEntityNotFound(_0x18ad0c,null))[_0x34ea('0x17')](function(_0x42e64f){if(_0x42e64f){_0x4301bd['model']=_[_0x34ea('0x43')](db[_0x34ea('0x102')]['rawAttributes']);_0x4301bd['query']=_[_0x34ea('0x43')](_0x46f1b6[_0x34ea('0x42')]);_0x4301bd[_0x34ea('0x4e')]=_[_0x34ea('0x44')](_0x4301bd[_0x34ea('0x46')],_0x4301bd['query']);_0x255029[_0x34ea('0x45')]=_[_0x34ea('0x44')](_0x4301bd[_0x34ea('0x46')],qs[_0x34ea('0x47')](_0x46f1b6[_0x34ea('0x42')][_0x34ea('0x47')]));_0x255029['attributes']=_0x255029['attributes']['length']?_0x255029['attributes']:_0x4301bd['model'];if(!_0x46f1b6[_0x34ea('0x42')]['hasOwnProperty'](_0x34ea('0x4a'))){_0x255029['limit']=qs[_0x34ea('0x28')](_0x46f1b6['query'][_0x34ea('0x28')]);_0x255029[_0x34ea('0x26')]=qs['offset'](_0x46f1b6[_0x34ea('0x42')][_0x34ea('0x26')]);}_0x255029['order']=qs[_0x34ea('0x4c')](_0x46f1b6[_0x34ea('0x42')]['sort']);_0x255029['where']=qs['filters'](_['pick'](_0x46f1b6['query'],_0x4301bd[_0x34ea('0x4e')]));_0x255029[_0x34ea('0x4d')]['ChatInteractionId']=_0x42e64f['id'];if(_0x46f1b6[_0x34ea('0x42')][_0x34ea('0x88')]){_0x255029[_0x34ea('0x4d')]=_['merge'](_0x255029['where'],{'$or':_[_0x34ea('0x31')](_0x255029['attributes'],function(_0x5f0bdb){var _0x47d824={};_0x47d824[_0x5f0bdb]={'$like':'%'+_0x46f1b6[_0x34ea('0x42')][_0x34ea('0x88')]+'%'};return _0x47d824;})});}_0x255029[_0x34ea('0x4d')][_0x34ea('0xf6')]=![];if(_0x46f1b6[_0x34ea('0x42')]['id']){_0x255029[_0x34ea('0x4d')]['id']={'$gt':_0x46f1b6[_0x34ea('0x42')]['id']};}_0x255029=_[_0x34ea('0xa1')]({},_0x255029,_0x46f1b6[_0x34ea('0xb9')]);return db['ChatMessage'][_0x34ea('0x29')]({'where':_0x255029[_0x34ea('0x4d')]})[_0x34ea('0x17')](function(_0x3f6508){_0x813efb[_0x34ea('0x29')]=_0x3f6508;_0x255029[_0x34ea('0x109')]=[];if(_0x46f1b6[_0x34ea('0x42')][_0x34ea('0x10d')]){_0x255029[_0x34ea('0x109')][_0x34ea('0x35')]({'model':db[_0x34ea('0x76')],'as':_0x34ea('0x76'),'attributes':['id',_0x34ea('0x32'),_0x34ea('0xf2')]});}if(_0x46f1b6[_0x34ea('0x42')][_0x34ea('0x108')]){_0x255029[_0x34ea('0x109')]=[{'all':!![]}];}return db[_0x34ea('0x102')][_0x34ea('0x10a')](_0x255029);})['then'](function(_0x1c2b19){_0x813efb['rows']=_0x1c2b19;return _0x813efb;});}})[_0x34ea('0x17')](respondWithFilteredResult(_0x18ad0c,_0x255029))['catch'](handleError(_0x18ad0c,null));};exports[_0x34ea('0x10e')]=function(_0x257843,_0x1d7450){return db[_0x34ea('0xa2')][_0x34ea('0x67')]({'where':{'id':_0x257843[_0x34ea('0xb8')]['id']}})[_0x34ea('0x17')](handleEntityNotFound(_0x1d7450,null))['then'](function(_0x5c1242){if(_0x5c1242){return _0x5c1242[_0x34ea('0x10f')](_0x257843[_0x34ea('0xbc')][_0x34ea('0x103')],_[_0x34ea('0x104')](_0x257843['body'],[_0x34ea('0x103'),'id'])||{})['spread'](function(){return db[_0x34ea('0x110')][_0x34ea('0x10a')]({'attributes':['id',_0x34ea('0x2c'),_0x34ea('0x111')],'where':{'id':_0x257843['body'][_0x34ea('0x103')]}});})[_0x34ea('0x17')](function(_0x27c98e){socket['emit'](_0x34ea('0x112'),{'id':Number(_0x257843['params']['id']),'tags':_0x27c98e||[]});return{'id':Number(_0x257843[_0x34ea('0xb8')]['id']),'tags':_0x27c98e||[]};});}})[_0x34ea('0x17')](respondWithResult(_0x1d7450,null))[_0x34ea('0x21')](handleError(_0x1d7450,null));};exports[_0x34ea('0x113')]=function(_0x47dd74,_0x38c831){return db['ChatInteraction'][_0x34ea('0x67')]({'where':{'id':_0x47dd74[_0x34ea('0xb8')]['id']}})[_0x34ea('0x17')](handleEntityNotFound(_0x38c831,null))[_0x34ea('0x17')](function(_0x3d596c){if(_0x3d596c){return _0x3d596c[_0x34ea('0x113')](_0x47dd74['query'][_0x34ea('0x103')]);}})[_0x34ea('0x17')](respondWithStatusCode(_0x38c831,null))[_0x34ea('0x21')](handleError(_0x38c831,null));};exports[_0x34ea('0xe1')]=function(_0x57fa0b,_0x35d23b){var _0x1c28f8=moment()[_0x34ea('0x114')]()[_0x34ea('0x9f')]();var _0x3505b3=path['join'](config['root'],'server','files','tmp');var _0x5111c4=path[_0x34ea('0xde')](config[_0x34ea('0xdf')],'server',_0x34ea('0x115'),_0x34ea('0x116'));var _0xfc300b=path[_0x34ea('0xde')](_0x3505b3,_0x1c28f8);var _0x27cd0c=util[_0x34ea('0xe5')](_0x34ea('0x117'),_0x57fa0b[_0x34ea('0xb8')]['id'],_0x1c28f8);var _0x111abd=path[_0x34ea('0xde')](_0x3505b3,_0x27cd0c);var _0x2369e5=[];_0x2369e5[_0x34ea('0x35')]({'model':db[_0x34ea('0x76')],'as':_0x34ea('0x76'),'attributes':['id','fullname'],'raw':!![]});_0x2369e5[_0x34ea('0x35')]({'model':db[_0x34ea('0xd2')],'as':_0x34ea('0x6d'),'attributes':['id',_0x34ea('0x118'),_0x34ea('0x119')],'raw':!![]});if(_0x57fa0b[_0x34ea('0x42')][_0x34ea('0x116')]){_0x2369e5[_0x34ea('0x35')]({'model':db[_0x34ea('0xdb')],'as':'Attachment','raw':!![]});}var _0x346db6=[{'model':db[_0x34ea('0x102')],'as':_0x34ea('0xe9'),'attributes':['id',_0x34ea('0xbc'),'createdAt',_0x34ea('0xf5'),_0x34ea('0xf6'),_0x34ea('0x83')],'include':_0x2369e5}];_0x346db6[_0x34ea('0x35')]({'model':db[_0x34ea('0xbf')],'as':_0x34ea('0x11a'),'attributes':['id',_0x34ea('0x2c')]});_0x346db6['push']({'model':db[_0x34ea('0x76')],'as':_0x34ea('0x11b'),'attributes':['id',_0x34ea('0x32')]});return db[_0x34ea('0xa2')][_0x34ea('0x67')]({'where':{'id':_0x57fa0b[_0x34ea('0xb8')]['id']},'include':_0x346db6})[_0x34ea('0x17')](handleEntityNotFound(_0x35d23b,null))[_0x34ea('0x17')](function(_0x45c213){if(_0x45c213){var _0x27ff9a=_0x45c213[_0x34ea('0x11c')]({'plain':!![]});fs[_0x34ea('0x11d')](_0xfc300b);var _0x542e4a={'channel':_0x34ea('0x11e'),'account':_0x27ff9a['Account'][_0x34ea('0x2c')],'agent':_0x27ff9a[_0x34ea('0x11b')]?_0x27ff9a[_0x34ea('0x11b')][_0x34ea('0x32')]:_0x34ea('0x11f'),'createdAt':moment(_0x27ff9a[_0x34ea('0x7e')])[_0x34ea('0xe5')]('YYYY-MM-DD\x20HH:mm:ss')['toString'](),'closedAt':_0x27ff9a['closed']?moment(_0x27ff9a[_0x34ea('0x120')])['format'](_0x34ea('0x107'))[_0x34ea('0x9f')]():'','disposition':_0x27ff9a[_0x34ea('0x3c')],'chatInfo':{'browser':_0x27ff9a[_0x34ea('0x121')],'os':_0x27ff9a[_0x34ea('0x122')],'referer':_0x27ff9a[_0x34ea('0x123')],'customerIp':_0x27ff9a['customerIp'],'customerPort':_0x27ff9a[_0x34ea('0x124')]?_0x27ff9a[_0x34ea('0x124')]:'N.A.'},'messages':_(_0x27ff9a['Messages'])[_0x34ea('0x125')]()[_0x34ea('0x88')]({'secret':![]})['map'](function(_0x245f85){if(_0x245f85[_0x34ea('0xdb')]){var _0x38bf72=path[_0x34ea('0xde')](_0x5111c4,_0x245f85['Attachment'][_0x34ea('0xd8')]);if(fs[_0x34ea('0x126')](_0x38bf72)){fs[_0x34ea('0x127')](_0x38bf72)[_0x34ea('0x128')](fs[_0x34ea('0x129')](path[_0x34ea('0xde')](_0xfc300b,_0x245f85[_0x34ea('0xdb')]['basename'])));}}return{'date':moment(_0x245f85[_0x34ea('0x7e')])['format'](_0x34ea('0x107'))[_0x34ea('0x9f')](),'sender':_0x245f85['direction']===_0x34ea('0xcf')?_0x245f85['User']?_0x245f85['User'][_0x34ea('0x32')]:_0x34ea('0xf0'):_0x245f85[_0x34ea('0x6d')]['firstName']+(_0x245f85[_0x34ea('0x6d')][_0x34ea('0x119')]?'\x20'+_0x245f85[_0x34ea('0x6d')][_0x34ea('0x119')]:''),'body':_0x245f85[_0x34ea('0xdb')]?_0x245f85['Attachment'][_0x34ea('0xd8')]:_0x245f85[_0x34ea('0xbc')],'direction':_0x245f85[_0x34ea('0xf5')]==='out'?'A':'C','secret':_0x245f85[_0x34ea('0xf6')],'read':_0x245f85[_0x34ea('0x83')],'attachment':_0x245f85[_0x34ea('0xdb')]};})[_0x34ea('0x69')]()};return ejs[_0x34ea('0x12a')](path[_0x34ea('0xde')](config[_0x34ea('0xdf')],_0x34ea('0x12b'),_0x34ea('0x12c'),'downloadInteraction.ejs'),{'interaction':_0x542e4a})['then'](function(_0x4d6d55){var _0x59e03b=path[_0x34ea('0xde')](_0xfc300b,_0x34ea('0x12d')+_0x27ff9a['id']+'-'+_0x1c28f8+_0x34ea('0x12e'));var _0x447b75={'path':_0x59e03b,'channel':'Chat','interactionId':_0x27ff9a['id']};return pdf[_0x34ea('0x12f')](_0x4d6d55,_0x447b75);})['then'](function(){return new Promise(function(_0x5ce8e7,_0x6afdbe){zipdir(_0xfc300b,{'saveTo':_0x111abd},function(_0x4e5053,_0x35954a){if(_0x4e5053)return _0x6afdbe(_0x4e5053);return _0x5ce8e7(_0x35954a);});})[_0x34ea('0x17')](function(){return new BPromise(function(_0x2ccb56,_0x291423){rimraf(_0xfc300b,function(_0x1d5256){if(_0x1d5256)_0x291423(_0x1d5256);return _0x2ccb56();});});})[_0x34ea('0x17')](function(){return _0x35d23b[_0x34ea('0xe1')](_0x111abd,_0x27cd0c,function(_0x3323c9){if(_0x3323c9){logger[_0x34ea('0x1e')](_0x34ea('0x130'),_0x3323c9);}else{fs[_0x34ea('0x131')](_0x111abd);}});});});}else{return _0x35d23b['sendStatus'](0xc8);}})[_0x34ea('0x21')](handleError(_0x35d23b,null));};