Built motion from commit (unavailable).|2.5.27
[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 _0x5beb=['`unreadMessages`\x20>\x200','tag','isArray','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','filter','replace','isNumeric','i.id\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages','order','DESC','resolve','i.ChatWebsiteId\x20IS\x20NOT\x20NULL','user','getChatWebsites','role','sequelize','toString','keyBy','merge','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','i.*','c.firstName','c.lastName','Contact.lastName','c.email','Contact.email','Contact.phone','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.ChatInteractionId\x20IN\x20?','groupBy','ChatInteractionId','all','rows','show','params','includeAll','include','options','create','body','destroy','describe','createVidaooSession','findOne','ChatWebsite','vidaooApiKey','vidaooEscalation','https://api-vidaoo.xcally.com/api/v1/sessions','MotionCWB:','follow','Sequelize','ValidationError','out','Unable\x20to\x20create\x20Vidaoo\x20session','customUpdate','CmContact','Contact','abandon','Interaction\x20already\x20assigned','closed','disposition','attachmentUpload','originalname','basename','file','filename','mimetype','Attachment','attachmentDownload','attachId','ChatOfflineMessageId','join','root','server/files/attachments/','offline-chat/','download','close','server/files/chat/upload/','transcript-%s.txt','now','ChatMessage','Messages','format','%s%d','agentAlias','System','customer','Visitor','website_alias','agent_alias','alias','agent_fullname','MM/DD/YYYY\x20HH:mm:ss','direction','secret','MailAccount','MailServerOut','Smtp','service','host','port','secure','auth','pass','SendMail','sendMail','\x22%s\x22\x20<%s>','email','mailTranscript','Mail\x20Transcript','addMessage','ids','omit','getMessages','nolimit','$gte','YYYY-MM-DD\x20HH:mm:ss','findAll','hasOwnProperty','includeAgent','spread','color','emit','removeTags','unix','server','files','tmp','transcript-%d-%s.zip','firstName','attachments','Account','get','Chat','Owner','N.A.','closedAt','osName','referer','customerIp','customerPort','tail','existsSync','createReadStream','pipe','createWriteStream','lastName','renderFile','views','downloadInteraction.html','.pdf','log','err','eml-format','rimraf','fast-json-patch','moment','mustache','util','path','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/export/pdf','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','socket.io-emitter','./chatInteraction.socket','register','jayson/promise','http','request','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','debug','error','message','result','catch','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','update','then','stack','name','send','Users','map','fullname','TagIds','Tags','push','index','ChatInteraction','rawAttributes','fieldName','type','model','query','keys','intersection','attributes','fields','length','sort','where','pick','filters','select','field','tools_tags','u.id','ui.ChatInteractionId','from','user_has_chat_interactions','users','u.id\x20=\x20ui.UserId','chat_interactions','left_join','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','chat_websites','a.id\x20=\x20i.ChatWebsiteId','chat_interaction_has_tags','it.ChatInteractionId\x20=\x20i.id','expr','search','sqlOperator','conditions','find','value','having','`\x20>\x200','operator','$substring','split','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','Tag','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','buildExpression','start','text','some','compact','isEmpty','forEach','ChatWebsiteId','i.ChatWebsiteId\x20IN\x20?','createdAt','parse','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200'];(function(_0xbc8e6f,_0xbc133d){var _0x169a3c=function(_0x28b18d){while(--_0x28b18d){_0xbc8e6f['push'](_0xbc8e6f['shift']());}};_0x169a3c(++_0xbc133d);}(_0x5beb,0xaa));var _0xb5be=function(_0x54424d,_0x292791){_0x54424d=_0x54424d-0x0;var _0xd9cc7e=_0x5beb[_0x54424d];return _0xd9cc7e;};'use strict';var emlformat=require(_0xb5be('0x0'));var rimraf=require(_0xb5be('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xb5be('0x2'));var rp=require('request-promise');var moment=require(_0xb5be('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xb5be('0x4'));var util=require(_0xb5be('0x5'));var path=require(_0xb5be('0x6'));var sox=require('sox');var csv=require(_0xb5be('0x7'));var ejs=require(_0xb5be('0x8'));var fs=require('fs');var fs_extra=require(_0xb5be('0x9'));var _=require('lodash');var squel=require(_0xb5be('0xa'));var crypto=require(_0xb5be('0xb'));var jsforce=require(_0xb5be('0xc'));var deskjs=require(_0xb5be('0xd'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xb5be('0xe'));var authService=require(_0xb5be('0xf'));var qs=require(_0xb5be('0x10'));var as=require('../../components/parsers/advancedSearch');var pdf=require(_0xb5be('0x11'));var hardwareService=require(_0xb5be('0x12'));var logger=require(_0xb5be('0x13'))(_0xb5be('0x14'));var utils=require(_0xb5be('0x15'));var config=require(_0xb5be('0x16'));var licenseUtil=require(_0xb5be('0x17'));var db=require(_0xb5be('0x18'))['db'];config['redis']=_['defaults'](config[_0xb5be('0x19')],{'host':'localhost','port':0x18eb});var socket=require(_0xb5be('0x1a'))(new Redis(config[_0xb5be('0x19')]));require(_0xb5be('0x1b'))[_0xb5be('0x1c')](socket);var jayson=require(_0xb5be('0x1d'));var client=jayson['client'][_0xb5be('0x1e')]({'port':0x232b});var client9004=jayson['client'][_0xb5be('0x1e')]({'port':0x232c});function respondWithRpcPromise(_0x18154b,_0x2c32d1,_0x199c6d,_0x57db14){return new BPromise(function(_0x4ed5fd,_0xb1a3bf){var _0x12a655=_0x57db14||client;return _0x12a655[_0xb5be('0x1f')](_0x18154b,_0x199c6d)['then'](function(_0x4c6f0a){logger[_0xb5be('0x20')](_0xb5be('0x21'),_0x2c32d1,_0xb5be('0x22'));logger[_0xb5be('0x23')]('ChatInteraction,\x20%s,\x20%s,\x20%s',_0x2c32d1,_0xb5be('0x22'),JSON['stringify'](_0x4c6f0a));if(_0x4c6f0a[_0xb5be('0x24')]){if(_0x4c6f0a[_0xb5be('0x24')]['code']===0x1f4){logger[_0xb5be('0x24')](_0xb5be('0x21'),_0x2c32d1,_0x4c6f0a[_0xb5be('0x24')][_0xb5be('0x25')]);return _0xb1a3bf(_0x4c6f0a[_0xb5be('0x24')][_0xb5be('0x25')]);}logger[_0xb5be('0x24')](_0xb5be('0x21'),_0x2c32d1,_0x4c6f0a[_0xb5be('0x24')][_0xb5be('0x25')]);return _0x4ed5fd(_0x4c6f0a[_0xb5be('0x24')][_0xb5be('0x25')]);}else{logger[_0xb5be('0x20')]('ChatInteraction,\x20%s,\x20%s',_0x2c32d1,_0xb5be('0x22'));_0x4ed5fd(_0x4c6f0a[_0xb5be('0x26')][_0xb5be('0x25')]);}})[_0xb5be('0x27')](function(_0x369650){logger[_0xb5be('0x24')](_0xb5be('0x21'),_0x2c32d1,_0x369650);_0xb1a3bf(_0x369650);});});}function respondWithStatusCode(_0x156c63,_0x5c39af){_0x5c39af=_0x5c39af||0xcc;return function(_0x52579b){if(_0x52579b){return _0x156c63[_0xb5be('0x28')](_0x5c39af);}return _0x156c63[_0xb5be('0x29')](_0x5c39af)[_0xb5be('0x2a')]();};}function respondWithResult(_0x5b2938,_0x3463a1){_0x3463a1=_0x3463a1||0xc8;return function(_0x5ee09b){if(_0x5ee09b){return _0x5b2938[_0xb5be('0x29')](_0x3463a1)[_0xb5be('0x2b')](_0x5ee09b);}};}function respondWithFilteredResult(_0x38f1b3,_0x15eba2){return function(_0x53b43b){if(_0x53b43b){var _0x300969=_0x53b43b[_0xb5be('0x2c')],_0x1b596e=_0x15eba2[_0xb5be('0x2d')],_0xd0e480=_0x15eba2[_0xb5be('0x2d')]+_0x15eba2[_0xb5be('0x2e')],_0x26afcb;if(_0xd0e480>=_0x300969){_0xd0e480=_0x300969;_0x26afcb=0xc8;}else{_0x26afcb=0xce;}_0x38f1b3[_0xb5be('0x29')](_0x26afcb);return _0x38f1b3[_0xb5be('0x2f')](_0xb5be('0x30'),_0x1b596e+'-'+_0xd0e480+'/'+_0x300969)[_0xb5be('0x2b')](_0x53b43b);}return null;};}function patchUpdates(_0x413d5b){return function(_0x30d81c){try{jsonpatch[_0xb5be('0x31')](_0x30d81c,_0x413d5b,!![]);}catch(_0x2910ae){return BPromise['reject'](_0x2910ae);}return _0x30d81c['save']();};}function saveUpdates(_0x1e678e,_0x350d8d){return function(_0x3c05e8){if(_0x3c05e8){return _0x3c05e8[_0xb5be('0x32')](_0x1e678e)[_0xb5be('0x33')](function(_0x488efb){return _0x488efb;});}return null;};}function removeEntity(_0x3d9060,_0x59ebc7){return function(_0x525283){if(_0x525283){return _0x525283['destroy']()['then'](function(){_0x3d9060[_0xb5be('0x29')](0xcc)[_0xb5be('0x2a')]();});}};}function handleEntityNotFound(_0x16355a,_0x45906a){return function(_0x23d8a5){if(!_0x23d8a5){_0x16355a[_0xb5be('0x28')](0x194);}return _0x23d8a5;};}function handleError(_0x102543,_0x4efb53){_0x4efb53=_0x4efb53||0x1f4;return function(_0xc2499){logger[_0xb5be('0x24')](_0xc2499[_0xb5be('0x34')]);if(_0xc2499['name']){delete _0xc2499[_0xb5be('0x35')];}_0x102543['status'](_0x4efb53)[_0xb5be('0x36')](_0xc2499);};}function getInteractionUsers(_0x1df4f4,_0x293ef2){return new BPromise(function(_0x5d6e14,_0x30961b){try{if(_0x293ef2[_0x1df4f4['id']]){_0x1df4f4[_0xb5be('0x37')]=_[_0xb5be('0x38')](_0x293ef2[_0x1df4f4['id']],function(_0x3fc2d5){return{'id':_0x3fc2d5['id'],'fullname':_0x3fc2d5[_0xb5be('0x39')]};});}}catch(_0x1e17d4){_0x30961b(_0x1e17d4);}_0x5d6e14(_0x1df4f4);});}function getInteractionTags(_0x4b1f87,_0x301b36){return new BPromise(function(_0x4ee16b,_0x494398){try{if(_0x4b1f87[_0xb5be('0x3a')]){_0x4b1f87[_0xb5be('0x3b')]=[];_0x4b1f87[_0xb5be('0x3a')]['split'](',')['forEach'](function(_0x3daeb1){_0x4b1f87[_0xb5be('0x3b')][_0xb5be('0x3c')](_0x301b36[_0x3daeb1]);});}delete _0x4b1f87[_0xb5be('0x3a')];}catch(_0x250f45){_0x494398(_0x250f45);}_0x4ee16b(_0x4b1f87);});}function updateChatInteraction(_0x339d08,_0x4efd6b,_0x52e50d){return new BPromise(function(_0x595a6a,_0x105114){return getInteractionUsers(_0x339d08,_0x52e50d)[_0xb5be('0x33')](function(_0x428de7){return getInteractionTags(_0x428de7,_0x4efd6b);})[_0xb5be('0x33')](function(_0x3a704b){_0x595a6a(_0x3a704b);})['catch'](function(_0x485c5c){_0x105114(_0x485c5c);});});}exports[_0xb5be('0x3d')]=function(_0x1405e3,_0xe04f30){var _0x3af79d={},_0x5aeaad={},_0x133e6b={'count':0x0,'rows':[]};var _0x1e7eaa=_['map'](db[_0xb5be('0x3e')][_0xb5be('0x3f')],function(_0x3caaac){return{'name':_0x3caaac[_0xb5be('0x40')],'type':_0x3caaac[_0xb5be('0x41')]['key']};});_0x5aeaad[_0xb5be('0x42')]=_['map'](_0x1e7eaa,_0xb5be('0x35'));_0x5aeaad[_0xb5be('0x43')]=_[_0xb5be('0x44')](_0x1405e3[_0xb5be('0x43')]);_0x5aeaad['filters']=_[_0xb5be('0x45')](_0x5aeaad[_0xb5be('0x42')],_0x5aeaad['query']);_0x3af79d[_0xb5be('0x46')]=_['intersection'](_0x5aeaad['model'],qs[_0xb5be('0x47')](_0x1405e3[_0xb5be('0x43')][_0xb5be('0x47')]));_0x3af79d['attributes']=_0x3af79d['attributes'][_0xb5be('0x48')]?_0x3af79d[_0xb5be('0x46')]:_0x5aeaad[_0xb5be('0x42')];if(!_0x1405e3['query']['hasOwnProperty']('nolimit')){_0x3af79d['limit']=qs[_0xb5be('0x2e')](_0x1405e3[_0xb5be('0x43')]['limit']);_0x3af79d[_0xb5be('0x2d')]=qs['offset'](_0x1405e3['query'][_0xb5be('0x2d')]);}_0x3af79d['order']=qs[_0xb5be('0x49')](_0x1405e3[_0xb5be('0x43')][_0xb5be('0x49')]);_0x3af79d[_0xb5be('0x4a')]=qs['filters'](_[_0xb5be('0x4b')](_0x1405e3['query'],_0x5aeaad[_0xb5be('0x4c')]),_0x1e7eaa);var _0x82c230=[];var _0x479932=squel[_0xb5be('0x4d')]()[_0xb5be('0x4e')]('id')[_0xb5be('0x4e')](_0xb5be('0x35'))[_0xb5be('0x4e')]('color')['from'](_0xb5be('0x4f'));var _0x258786=squel[_0xb5be('0x4d')]()[_0xb5be('0x4e')](_0xb5be('0x50'))['field']('u.fullname')[_0xb5be('0x4e')](_0xb5be('0x51'))[_0xb5be('0x52')](_0xb5be('0x53'),'ui')['left_join'](_0xb5be('0x54'),'u',_0xb5be('0x55'));var _0x5b13ad=squel[_0xb5be('0x4d')]()[_0xb5be('0x52')](_0xb5be('0x56'),'i')[_0xb5be('0x57')]('cm_contacts','c',_0xb5be('0x58'))[_0xb5be('0x57')](_0xb5be('0x54'),'o',_0xb5be('0x59'))[_0xb5be('0x57')](_0xb5be('0x5a'),'a',_0xb5be('0x5b'))[_0xb5be('0x57')]('chat_messages','me','me.ChatInteractionId\x20=\x20i.id')['left_join'](_0xb5be('0x5c'),'it',_0xb5be('0x5d'))[_0xb5be('0x57')]('tools_tags','t','t.id\x20=\x20it.TagId');var _0x1578c9=squel[_0xb5be('0x5e')]();var _0x41c19a=[];var _0x1ab892=squel['expr']();var _0x4208b2;if(_0x1405e3[_0xb5be('0x43')][_0xb5be('0x5f')]){_0x4208b2=as['parseSearch'](_0x1405e3[_0xb5be('0x43')]['search']);var _0x50d1df=_0x4208b2[_0xb5be('0x60')];for(var _0x5ead80=0x0;_0x5ead80<_0x4208b2['conditions'][_0xb5be('0x48')];_0x5ead80++){var _0x27f0f8=_0x4208b2[_0xb5be('0x61')][_0x5ead80];var _0x26d400='i';var _0x50206b=_[_0xb5be('0x62')](_0x1e7eaa,[_0xb5be('0x35'),_0x27f0f8['field']]);if(!_0x50206b){switch(_0x27f0f8[_0xb5be('0x4e')]){case'unreadMessages':if(_0x27f0f8[_0xb5be('0x63')]==0x1){_0x5b13ad[_0xb5be('0x64')]('`'+_0x27f0f8[_0xb5be('0x4e')]+'`\x20=\x200');}else{_0x5b13ad['having']('`'+_0x27f0f8[_0xb5be('0x4e')]+_0xb5be('0x65'));}break;case'Contact':if(_0x27f0f8[_0xb5be('0x66')]===_0xb5be('0x67')){if(_0x27f0f8[_0xb5be('0x63')][_0xb5be('0x68')]('\x20')[_0xb5be('0x48')]>0x1){_0x1578c9[_0x50d1df](_0xb5be('0x69'),qs[_0xb5be('0x6a')](_0x27f0f8[_0xb5be('0x63')]),null);}else{var _0x41d216='%'+_0x27f0f8[_0xb5be('0x63')]+'%';_0x1578c9[_0x50d1df](_0xb5be('0x6b'),_0x41d216,_0x41d216,_0x41d216);}}else{_0x50206b=_['find'](_0x1e7eaa,['name','ContactId']);_0x27f0f8['field']=_0xb5be('0x6c');_0x3397a6=as['buildExpression'](_0x26d400,_0x50206b[_0xb5be('0x41')],_0x27f0f8);_0x1578c9[_0x50d1df](_0x3397a6['text'],_0x3397a6[_0xb5be('0x63')]['start'],_0x3397a6[_0xb5be('0x63')][_0xb5be('0x2a')]);}break;case _0xb5be('0x6d'):var _0x35a9e7=_0x27f0f8[_0xb5be('0x63')]['split'](',')[_0xb5be('0x38')](function(_0x295492){return Number(_0x295492);});_0x35a9e7['forEach'](function(_0x4c2ece){_0x1ab892['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x4c2ece+',%');});_0x41c19a=_[_0xb5be('0x6e')](_0x41c19a,_0x35a9e7);break;case _0xb5be('0x6f'):if(_0x27f0f8[_0xb5be('0x66')]===_0xb5be('0x67')){_0x1578c9[_0x50d1df](_0xb5be('0x70'),'%'+_0x27f0f8[_0xb5be('0x63')]+'%',null);}else{_0x50206b=_['find'](_0x1e7eaa,['name',_0xb5be('0x71')]);_0x27f0f8[_0xb5be('0x4e')]=_0xb5be('0x71');_0x3397a6=as[_0xb5be('0x72')](_0x26d400,_0x50206b['type'],_0x27f0f8);_0x1578c9[_0x50d1df](_0x3397a6['text'],_0x3397a6[_0xb5be('0x63')][_0xb5be('0x73')],_0x3397a6[_0xb5be('0x63')][_0xb5be('0x2a')]);}break;case'body':_0x3397a6=as[_0xb5be('0x72')]('me',null,_0x27f0f8);_0x1578c9[_0x50d1df](_0x3397a6[_0xb5be('0x74')],_0x3397a6[_0xb5be('0x63')][_0xb5be('0x73')],_0x3397a6[_0xb5be('0x63')]['end']);break;}}else{var _0x3397a6=as['buildExpression'](_0x26d400,_0x50206b[_0xb5be('0x41')],_0x27f0f8);_0x1578c9[_0x50d1df](_0x3397a6[_0xb5be('0x74')],_0x3397a6[_0xb5be('0x63')]['start'],_0x3397a6[_0xb5be('0x63')][_0xb5be('0x2a')]);}}}else{var _0x3b69eb=_(_0x1405e3[_0xb5be('0x43')])[_0xb5be('0x44')]()[_0xb5be('0x38')](function(_0x108dc7){return _[_0xb5be('0x75')](_0x1e7eaa,[_0xb5be('0x35'),_0x108dc7])?_0x108dc7:undefined;})[_0xb5be('0x76')]()[_0xb5be('0x63')]();if(!_[_0xb5be('0x77')](_0x3b69eb)){_0x3b69eb[_0xb5be('0x78')](function(_0x1df251){if(_0x1df251===_0xb5be('0x79')){_0x5b13ad[_0xb5be('0x4a')](_0xb5be('0x7a'),[]['concat'](_0x1405e3[_0xb5be('0x43')][_0x1df251]));}else if(_0x1df251===_0xb5be('0x7b')){var _0x2237e9=JSON[_0xb5be('0x7c')](_0x1405e3[_0xb5be('0x43')][_0x1df251])['$gte'];var _0x57900b=JSON[_0xb5be('0x7c')](_0x1405e3[_0xb5be('0x43')][_0x1df251])[_0xb5be('0x7d')];_0x5b13ad[_0xb5be('0x4a')](_0xb5be('0x7e'),_0x2237e9,_0x57900b);}else{if(_0x1405e3['query'][_0x1df251]===_0xb5be('0x7f')){_0x5b13ad[_0xb5be('0x4a')]('i.'+_0x1df251+_0xb5be('0x80'));}else{_0x5b13ad['where']('i.'+_0x1df251+_0xb5be('0x81'),_0x1405e3[_0xb5be('0x43')][_0x1df251]);}}});}if(_0x1405e3[_0xb5be('0x43')][_0xb5be('0x82')]){if(_0x1405e3[_0xb5be('0x43')][_0xb5be('0x82')]==0x1){_0x5b13ad['having'](_0xb5be('0x83'));}else{_0x5b13ad[_0xb5be('0x64')](_0xb5be('0x84'));}}if(_0x1405e3[_0xb5be('0x43')][_0xb5be('0x85')]){_0x41c19a=_[_0xb5be('0x86')](_0x1405e3[_0xb5be('0x43')]['tag'])?_0x1405e3[_0xb5be('0x43')][_0xb5be('0x85')]:new Array(_0x1405e3[_0xb5be('0x43')][_0xb5be('0x85')]);_0x41c19a[_0xb5be('0x78')](function(_0x4dc852){_0x1ab892['or'](_0xb5be('0x87'),'%,'+_0x4dc852+',%');});}if(_0x1405e3[_0xb5be('0x43')]['filter']){var _0x42e5dd=_0x1405e3[_0xb5be('0x43')][_0xb5be('0x88')]['replace']('\x5c','\x5c\x5c')[_0xb5be('0x89')](/'/g,'\x27\x27');if(qs[_0xb5be('0x8a')](_0x42e5dd)){_0x1578c9['or'](_0xb5be('0x8b'),_0x42e5dd+'%');}else{_0x1578c9['or'](_0xb5be('0x8c'),qs['getFullTextValue'](_0x42e5dd))['or'](_0xb5be('0x8d'),_0x42e5dd+'%');}}}_0x5b13ad[_0xb5be('0x4a')](_0x1578c9);_0x5b13ad[_0xb5be('0x8e')](_0xb5be('0x8f'));var _0x62379c={'type':db['Sequelize']['QueryTypes'][_0xb5be('0x90')],'raw':!![]};var _0x462d95=_0x5b13ad[_0xb5be('0x91')]();_0x462d95[_0xb5be('0x4e')](_0xb5be('0x8f'));_0x462d95[_0xb5be('0x4e')](_0xb5be('0x92'),_0xb5be('0x93'));if(_0x3af79d[_0xb5be('0x94')]){_0x3af79d[_0xb5be('0x94')][_0xb5be('0x78')](function(_0x1bd4be){var _0x1e1b4c=_0x1bd4be[0x0]==='contactName'?_0x1bd4be[0x0]:'i.'+_0x1bd4be[0x0];_0x5b13ad[_0xb5be('0x94')](_0x1e1b4c,_0x1bd4be[0x1]===_0xb5be('0x95')?![]:!![]);});}if(!_[_0xb5be('0x77')](_0x41c19a)){_0x5b13ad[_0xb5be('0x64')](_0x1ab892);_0x462d95[_0xb5be('0x4a')]('t.id\x20IN\x20?',_0x41c19a);}BPromise[_0xb5be('0x96')]()[_0xb5be('0x33')](function(){if(!_0x4208b2){if(_0x1405e3['query']['ChatWebsiteId'])return;_0x462d95[_0xb5be('0x4a')](_0xb5be('0x97'));_0x5b13ad['where'](_0xb5be('0x97'));return;}if(_0x1405e3[_0xb5be('0x98')]['role']!=='agent')return;return _0x1405e3[_0xb5be('0x98')][_0xb5be('0x99')]({'attributes':['id'],'raw':!![]})[_0xb5be('0x33')](function(_0x54edd0){if(_[_0xb5be('0x77')](_0x54edd0)){_0x462d95[_0xb5be('0x4a')]('i.ChatWebsiteId\x20IS\x20NULL');_0x5b13ad[_0xb5be('0x4a')]('i.ChatWebsiteId\x20IS\x20NULL');}else{_0x462d95[_0xb5be('0x4a')](_0xb5be('0x7a'),_[_0xb5be('0x38')](_0x54edd0,'id'));_0x5b13ad[_0xb5be('0x4a')]('i.ChatWebsiteId\x20IN\x20?',_[_0xb5be('0x38')](_0x54edd0,'id'));}});})[_0xb5be('0x33')](function(){if(_0x1405e3['user'][_0xb5be('0x9a')]==='agent'&&!_0x4208b2&&!_0x1405e3['query'][_0xb5be('0x79')])return[];return db['sequelize'][_0xb5be('0x43')](_0x462d95['toString'](),_0x62379c);})['then'](function(_0x488cb2){_0x133e6b[_0xb5be('0x2c')]=_0x488cb2['length'];if(_0x133e6b[_0xb5be('0x2c')]===0x0)return[];return db[_0xb5be('0x9b')][_0xb5be('0x43')](_0x479932[_0xb5be('0x9c')](),_0x62379c)[_0xb5be('0x33')](function(_0x2688c6){_0x82c230=_[_0xb5be('0x9d')](_0x2688c6,'id');_0x62379c=_[_0xb5be('0x9e')](_0x62379c,{'model':db[_0xb5be('0x3e')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x1405e3[_0xb5be('0x43')]['fields']){_0x3af79d[_0xb5be('0x46')][_0xb5be('0x78')](function(_0xd4c231){_0x5b13ad[_0xb5be('0x4e')]('i.'+_0xd4c231);});}else{_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0x92'),'unreadMessages');_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0x9f'),_0xb5be('0xa0'));_0x5b13ad['field'](_0xb5be('0xa1'),_0xb5be('0xa2'));_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0xa3'),'contactName');_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0xa4'));_0x5b13ad['field'](_0xb5be('0xa5'),'Contact.firstName');_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0xa6'),_0xb5be('0xa7'));_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0xa8'),_0xb5be('0xa9'));_0x5b13ad[_0xb5be('0x4e')]('c.phone',_0xb5be('0xaa'));_0x5b13ad[_0xb5be('0x4e')]('c.mobile','Contact.mobile');_0x5b13ad[_0xb5be('0x4e')]('c.fax',_0xb5be('0xab'));_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0xac'),_0xb5be('0xad'));_0x5b13ad['field'](_0xb5be('0xae'),_0xb5be('0xaf'));_0x5b13ad[_0xb5be('0x4e')](_0xb5be('0xb0'),_0xb5be('0x3a'));}if(_0x3af79d[_0xb5be('0x2e')])_0x5b13ad[_0xb5be('0x2e')](_0x3af79d['limit']);if(_0x3af79d[_0xb5be('0x2d')])_0x5b13ad[_0xb5be('0x2d')](_0x3af79d[_0xb5be('0x2d')]);return db['sequelize']['query'](_0x5b13ad[_0xb5be('0x9c')](),_0x62379c);})['then'](function(_0x508a38){_0x258786['where'](_0xb5be('0xb1'),_[_0xb5be('0x38')](_0x508a38,'id'));return db[_0xb5be('0x9b')][_0xb5be('0x43')](_0x258786['toString'](),_0x62379c)['then'](function(_0x41a660){var _0x56a439=_[_0xb5be('0xb2')](_0x41a660,_0xb5be('0xb3'));var _0x173698=[];_0x508a38[_0xb5be('0x78')](function(_0x479e36){_0x173698['push'](updateChatInteraction(_0x479e36,_0x82c230,_0x56a439));});return BPromise[_0xb5be('0xb4')](_0x173698);});});})[_0xb5be('0x33')](function(_0x1bb3f1){_0x133e6b[_0xb5be('0xb5')]=_0x1bb3f1;return _0x133e6b;})[_0xb5be('0x33')](respondWithFilteredResult(_0xe04f30,_0x3af79d))[_0xb5be('0x27')](handleError(_0xe04f30,null));};exports[_0xb5be('0xb6')]=function(_0xb118ee,_0x1959f9){var _0x522ddf={'raw':![],'where':{'id':_0xb118ee[_0xb5be('0xb7')]['id']}},_0x2e70a8={};_0x2e70a8[_0xb5be('0x42')]=_[_0xb5be('0x44')](db[_0xb5be('0x3e')][_0xb5be('0x3f')]);_0x2e70a8[_0xb5be('0x43')]=_[_0xb5be('0x44')](_0xb118ee[_0xb5be('0x43')]);_0x2e70a8[_0xb5be('0x4c')]=_[_0xb5be('0x45')](_0x2e70a8[_0xb5be('0x42')],_0x2e70a8['query']);_0x522ddf[_0xb5be('0x46')]=_['intersection'](_0x2e70a8[_0xb5be('0x42')],qs[_0xb5be('0x47')](_0xb118ee[_0xb5be('0x43')][_0xb5be('0x47')]));_0x522ddf[_0xb5be('0x46')]=_0x522ddf['attributes'][_0xb5be('0x48')]?_0x522ddf['attributes']:_0x2e70a8[_0xb5be('0x42')];if(_0xb118ee[_0xb5be('0x43')][_0xb5be('0xb8')]){_0x522ddf[_0xb5be('0xb9')]=[{'all':!![]}];}_0x522ddf=_[_0xb5be('0x9e')]({},_0x522ddf,_0xb118ee[_0xb5be('0xba')]);return db[_0xb5be('0x3e')][_0xb5be('0x62')](_0x522ddf)[_0xb5be('0x33')](handleEntityNotFound(_0x1959f9,null))[_0xb5be('0x33')](respondWithResult(_0x1959f9,null))[_0xb5be('0x27')](handleError(_0x1959f9,null));};exports[_0xb5be('0xbb')]=function(_0x2aa594,_0x3952b5){return db[_0xb5be('0x3e')][_0xb5be('0xbb')](_0x2aa594[_0xb5be('0xbc')],{})[_0xb5be('0x33')](respondWithResult(_0x3952b5,0xc9))[_0xb5be('0x27')](handleError(_0x3952b5,null));};exports['update']=function(_0x283370,_0x535faa){if(_0x283370[_0xb5be('0xbc')]['id']){delete _0x283370[_0xb5be('0xbc')]['id'];}return db[_0xb5be('0x3e')][_0xb5be('0x62')]({'where':{'id':_0x283370[_0xb5be('0xb7')]['id']}})[_0xb5be('0x33')](handleEntityNotFound(_0x535faa,null))[_0xb5be('0x33')](saveUpdates(_0x283370['body'],null))[_0xb5be('0x33')](respondWithResult(_0x535faa,null))[_0xb5be('0x27')](handleError(_0x535faa,null));};exports[_0xb5be('0xbd')]=function(_0x4bdc1f,_0x45a751){return db[_0xb5be('0x3e')]['find']({'where':{'id':_0x4bdc1f['params']['id']}})[_0xb5be('0x33')](handleEntityNotFound(_0x45a751,null))[_0xb5be('0x33')](removeEntity(_0x45a751,null))['catch'](handleError(_0x45a751,null));};exports[_0xb5be('0xbe')]=function(_0x53a8d8,_0x1f8636){return db['ChatInteraction']['describe']()[_0xb5be('0x33')](respondWithResult(_0x1f8636,null))[_0xb5be('0x27')](handleError(_0x1f8636,null));};exports[_0xb5be('0xbf')]=function(_0x358b7b,_0x1350d7){var _0xf96273=_0x358b7b[_0xb5be('0xb7')]['id'];var _0x1df8ce;var _0x2f73e6;var _0x4e3a67;return db[_0xb5be('0x3e')][_0xb5be('0xc0')]({'where':{'id':_0xf96273}})[_0xb5be('0x33')](function(_0x4672d9){_0x1df8ce=_0x4672d9;return db[_0xb5be('0xc1')][_0xb5be('0xc0')]({'where':{'id':_0x4672d9[_0xb5be('0x79')]},'attributes':['id',_0xb5be('0xc2'),_0xb5be('0xc3')],'raw':!![]});})[_0xb5be('0x33')](function(_0x452cdf){if(_0x452cdf&&_0x452cdf['vidaooApiKey']&&_0x452cdf['vidaooEscalation']){_0x2f73e6=_0x452cdf;var _0x49f219={'rejectUnauthorized':![],'method':'POST','uri':_0xb5be('0xc4'),'headers':{'X-APIKEY':_0x452cdf[_0xb5be('0xc2')]},'body':{'name':_0xb5be('0xc5')+_0xf96273},'redirect':_0xb5be('0xc6'),'json':!![]};return rp(_0x49f219);}else{throw new db[(_0xb5be('0xc7'))][(_0xb5be('0xc8'))]('Error\x20in\x20Vidaoo\x20configuration');}})[_0xb5be('0x33')](function(_0x47f80d){_0x4e3a67=_0x47f80d;if(_0x4e3a67['id']){var _0x2016ea={'body':_0x4e3a67['join_url'],'ChatWebsiteId':_0x2f73e6['id'],'ChatInteractionId':_0x1df8ce['id'],'direction':_0xb5be('0xc9'),'UserId':_0x358b7b[_0xb5be('0x98')]['id']};return db['ChatMessage'][_0xb5be('0xbb')](_0x2016ea,{});}else{throw new db[(_0xb5be('0xc7'))][(_0xb5be('0xc8'))](_0xb5be('0xca'));}})[_0xb5be('0x33')](function(){return _0x1df8ce['updateAttributes']({'vidaooSessionId':_0x4e3a67['id']});})[_0xb5be('0x33')](respondWithResult(_0x1350d7,null))['catch'](handleError(_0x1350d7,null));};exports[_0xb5be('0xcb')]=function(_0x1fa3c0,_0x358c96){if(_0x1fa3c0[_0xb5be('0xbc')]['id']){delete _0x1fa3c0['body']['id'];}return db[_0xb5be('0x3e')][_0xb5be('0x62')]({'where':{'id':_0x1fa3c0[_0xb5be('0xb7')]['id']},'include':[{'model':db[_0xb5be('0xcc')],'as':_0xb5be('0xcd')}]})[_0xb5be('0x33')](handleEntityNotFound(_0x358c96,null))[_0xb5be('0x33')](saveUpdates(_0x1fa3c0[_0xb5be('0xbc')],null))['then'](respondWithResult(_0x358c96,null))['catch'](handleError(_0x358c96,null));};exports[_0xb5be('0xce')]=function(_0x4bbbe4,_0x353fe4,_0x3904d7){if(_0x4bbbe4['body']['id']){delete _0x4bbbe4[_0xb5be('0xbc')]['id'];}return db['ChatInteraction']['find']({'where':{'id':_0x4bbbe4[_0xb5be('0xb7')]['id']}})[_0xb5be('0x33')](function(_0x1a2d70){if(!_0x1a2d70){logger[_0xb5be('0x24')]('abandonInteraction,\x20%s,\x20%s,\x20%s',_0xb5be('0xce'),0x194,'entity\x20not\x20found');_0x353fe4[_0xb5be('0x28')](0x194);}else{if(_0x1a2d70[_0xb5be('0x71')]){throw new db[(_0xb5be('0xc7'))][(_0xb5be('0xc8'))](_0xb5be('0xcf'));}}return _0x1a2d70;})[_0xb5be('0x33')](function(_0x735d36){if(_0x735d36){return _0x735d36['update']({'closed':_0x4bbbe4[_0xb5be('0xbc')][_0xb5be('0xd0')],'disposition':_0x4bbbe4[_0xb5be('0xbc')][_0xb5be('0xd1')]})[_0xb5be('0x33')](function(_0x4e0e5e){return _0x4e0e5e;});}})['then'](function(_0x33c744){return respondWithRpcPromise('AbandonInteraction',_0xb5be('0xce'),_0x4bbbe4[_0xb5be('0xbc')],client9004);})['then'](respondWithResult(_0x353fe4,null))[_0xb5be('0x27')](handleError(_0x353fe4,null));};exports[_0xb5be('0xd2')]=function(_0x13f705,_0x20b694,_0x3851dc){_0x13f705[_0xb5be('0xbc')][_0xb5be('0x35')]=_0x13f705['file'][_0xb5be('0xd3')];_0x13f705[_0xb5be('0xbc')][_0xb5be('0xd4')]=_0x13f705[_0xb5be('0xd5')][_0xb5be('0xd6')];_0x13f705[_0xb5be('0xbc')][_0xb5be('0x41')]=_0x13f705[_0xb5be('0xd5')][_0xb5be('0xd7')];return db[_0xb5be('0xd8')][_0xb5be('0xbb')](_0x13f705[_0xb5be('0xbc')])[_0xb5be('0x33')](respondWithResult(_0x20b694,0xc9))['catch'](handleError(_0x20b694,null));};exports[_0xb5be('0xd9')]=function(_0x218024,_0x5584db,_0x1664e2){return db[_0xb5be('0x3e')]['findOne']({'where':{'id':_0x218024['params']['id']},'raw':!![]})[_0xb5be('0x33')](handleEntityNotFound(_0x5584db,null))[_0xb5be('0x33')](function(_0x3d9f51){if(_0x3d9f51){if(_0x3d9f51[_0xb5be('0xd0')]){return _0x5584db['status'](0x193)[_0xb5be('0x2b')]({'status':0x193,'message':'Unauthorized'});}return db[_0xb5be('0xd8')][_0xb5be('0xc0')]({'where':{'id':_0x218024[_0xb5be('0x43')][_0xb5be('0xda')]},'raw':!![]})['then'](handleEntityNotFound(_0x5584db,null));}})[_0xb5be('0x33')](function(_0x142345){if(_0x142345){var _0x482a39=_0x142345[_0xb5be('0xdb')]!==null;var _0x112c27=path[_0xb5be('0xdc')](config[_0xb5be('0xdd')],_0xb5be('0xde'));if(_0x482a39){_0x112c27=path[_0xb5be('0xdc')](_0x112c27,_0xb5be('0xdf'));}var _0x1cd69e=path[_0xb5be('0xdc')](_0x112c27,_0x142345[_0xb5be('0xd4')]);return _0x5584db[_0xb5be('0xe0')](_0x1cd69e);}})[_0xb5be('0x27')](handleError(_0x5584db,null));};exports[_0xb5be('0xe1')]=function(_0x5c236d,_0xf9a8ea){var _0x222e9d=null;var _0x516cd5=null;var _0x31c8be=null;var _0x360149=null;if(_0x5c236d['body']['id']){delete _0x5c236d['body']['id'];}if(_0x5c236d[_0xb5be('0xbc')]['mailTranscript']){_0x360149=path[_0xb5be('0xdc')](config['root'],_0xb5be('0xe2'),util['format'](_0xb5be('0xe3'),Date[_0xb5be('0xe4')]()));_0x5c236d[_0xb5be('0xbc')]['pathTranscript']=_0x360149;}return db[_0xb5be('0x3e')][_0xb5be('0x62')]({'where':{'id':_0x5c236d[_0xb5be('0xb7')]['id']},'include':[{'model':db[_0xb5be('0xe5')],'as':_0xb5be('0xe6'),'include':[{'model':db['User'],'as':_0xb5be('0x6f')}]}]})[_0xb5be('0x33')](handleEntityNotFound(_0xf9a8ea,null))[_0xb5be('0x33')](saveUpdates(_0x5c236d['body'],null))[_0xb5be('0x33')](function(_0x52b595){if(_0x52b595){_0x222e9d=_0x52b595;return db['ChatWebsite']['find']({'where':{'id':_0x222e9d[_0xb5be('0x79')]}});}})[_0xb5be('0x33')](function(_0x5bff95){if(_0x5bff95){_0x31c8be=_0x5bff95;return db[_0xb5be('0xcc')][_0xb5be('0x62')]({'where':{'id':_0x222e9d['ContactId']}});}})[_0xb5be('0x33')](function(_0xa4ed30){if(_0xa4ed30){_0x516cd5=_0xa4ed30;if(_0x360149){var _0x8e3a5f=null;for(var _0x105f9d=0x1;_0x105f9d<_0x222e9d[_0xb5be('0xe6')]['length'];++_0x105f9d){_0x8e3a5f=_0x222e9d['Messages'][_0x105f9d];var _0x549b00=_0x8e3a5f[_0xb5be('0x71')]?util[_0xb5be('0xe7')](_0xb5be('0xe8'),_0x31c8be[_0xb5be('0xe9')],_0x8e3a5f[_0xb5be('0x71')]):_0xb5be('0xea');var _0x5302a8=_0x5c236d[_0xb5be('0xbc')][_0xb5be('0xeb')]||util[_0xb5be('0xe7')](_0xb5be('0xe8'),_0xb5be('0xec'),_0x8e3a5f[_0xb5be('0x6c')]);switch(_0x31c8be['agentIdentifier']){case _0xb5be('0xed'):_0x549b00=_0x8e3a5f[_0xb5be('0x71')]?util[_0xb5be('0xe7')]('%s%d',_0x31c8be[_0xb5be('0xe9')],_0x8e3a5f[_0xb5be('0x71')]):_0xb5be('0xea');break;case _0xb5be('0xee'):_0x549b00=_0x8e3a5f[_0xb5be('0x71')]?_0x8e3a5f['User'][_0xb5be('0xef')]||_0x8e3a5f[_0xb5be('0x6f')][_0xb5be('0x39')]:_0xb5be('0xea');break;case _0xb5be('0xf0'):_0x549b00=_0x8e3a5f[_0xb5be('0x71')]?_0x8e3a5f['User'][_0xb5be('0x39')]:_0xb5be('0xea');break;default:_0x549b00=_0x8e3a5f[_0xb5be('0x71')]?util[_0xb5be('0xe7')](_0xb5be('0xe8'),_0x31c8be[_0xb5be('0xe9')],_0x8e3a5f[_0xb5be('0x71')]):_0xb5be('0xea');}var _0x1c4580=util[_0xb5be('0xe7')]('[%s]\x20%s:\x20%s\x0a',moment(_0x8e3a5f[_0xb5be('0x7b')])['format'](_0xb5be('0xf1')),_0x8e3a5f[_0xb5be('0xf2')]==='in'?_0x5302a8:_0x549b00,_0x8e3a5f['body']);if(!_0x8e3a5f[_0xb5be('0xf3')]){fs['appendFileSync'](_0x360149,_0x1c4580);}}return db[_0xb5be('0xf4')][_0xb5be('0xc0')]({'where':{'service':!![]},'include':[{'model':db[_0xb5be('0xf5')],'as':_0xb5be('0xf6'),'raw':!![]}]});}}})[_0xb5be('0x33')](function(_0x3e8640){if(_0x3e8640&&_0x3e8640[_0xb5be('0xf6')]&&_0x5c236d[_0xb5be('0xbc')]){var _0xcfc71e={'tls':{'rejectUnauthorized':![]}};if(_0x3e8640[_0xb5be('0xf6')][_0xb5be('0xf7')]){_0xcfc71e[_0xb5be('0xf7')]=_0x3e8640['Smtp']['service'];}else{_0xcfc71e[_0xb5be('0xf8')]=_0x3e8640[_0xb5be('0xf6')][_0xb5be('0xf8')];_0xcfc71e[_0xb5be('0xf9')]=_0x3e8640[_0xb5be('0xf6')]['port'];_0xcfc71e[_0xb5be('0xfa')]=_0x3e8640[_0xb5be('0xf6')][_0xb5be('0xfa')];}if(_0x3e8640['Smtp']['authentication']){_0xcfc71e[_0xb5be('0xfb')]={'user':_0x3e8640[_0xb5be('0xf6')][_0xb5be('0x98')],'pass':_0x3e8640[_0xb5be('0xf6')][_0xb5be('0xfc')]};}return respondWithRpcPromise(_0xb5be('0xfd'),_0xb5be('0xfe'),{'account':_0xcfc71e,'message':{'from':util[_0xb5be('0xe7')](_0xb5be('0xff'),_0x3e8640[_0xb5be('0x35')],_0x3e8640[_0xb5be('0x100')]||_0x3e8640[_0xb5be('0xf6')][_0xb5be('0x98')]),'to':_0x5c236d['body'][_0xb5be('0x101')],'subject':_0xb5be('0x102'),'text':util['format']('Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a',_0x5c236d[_0xb5be('0xbc')][_0xb5be('0x101')]),'attachments':[{'path':_0x360149}]}})[_0xb5be('0x33')](function(){return _0x222e9d;})[_0xb5be('0x27')](function(_0xc631dd){console[_0xb5be('0x24')](_0xc631dd);});}else{return _0x222e9d;}})[_0xb5be('0x33')](respondWithStatusCode(_0xf9a8ea,0xc8))[_0xb5be('0x27')](handleError(_0xf9a8ea,null));};exports[_0xb5be('0x103')]=function(_0x8d8cc6,_0x4824ee,_0x15721a){return db[_0xb5be('0xe5')]['find']({'where':{'id':_0x8d8cc6[_0xb5be('0xb7')]['id']}})['then'](handleEntityNotFound(_0x4824ee,null))[_0xb5be('0x33')](function(_0x1da38a){if(_0x1da38a){return _0x1da38a[_0xb5be('0x103')](_0x8d8cc6[_0xb5be('0xbc')][_0xb5be('0x104')],_[_0xb5be('0x105')](_0x8d8cc6[_0xb5be('0xbc')],['ids','id'])||{});}})[_0xb5be('0x33')](respondWithResult(_0x4824ee,null))[_0xb5be('0x27')](handleError(_0x4824ee,null));};exports[_0xb5be('0x106')]=function(_0x25b180,_0x378823,_0x48d634){var _0x35eeb6={'raw':![],'where':{}};var _0x2db877={};var _0x267784={'count':0x0,'rows':[]};return db[_0xb5be('0x3e')]['findOne']({'where':{'id':_0x25b180[_0xb5be('0xb7')]['id']}})['then'](handleEntityNotFound(_0x378823,null))[_0xb5be('0x33')](function(_0x359e08){if(_0x359e08){_0x2db877[_0xb5be('0x42')]=_[_0xb5be('0x44')](db[_0xb5be('0xe5')][_0xb5be('0x3f')]);_0x2db877['query']=_[_0xb5be('0x44')](_0x25b180[_0xb5be('0x43')]);_0x2db877[_0xb5be('0x4c')]=_[_0xb5be('0x45')](_0x2db877[_0xb5be('0x42')],_0x2db877['query']);_0x35eeb6[_0xb5be('0x46')]=_[_0xb5be('0x45')](_0x2db877[_0xb5be('0x42')],qs[_0xb5be('0x47')](_0x25b180[_0xb5be('0x43')][_0xb5be('0x47')]));_0x35eeb6[_0xb5be('0x46')]=_0x35eeb6[_0xb5be('0x46')][_0xb5be('0x48')]?_0x35eeb6[_0xb5be('0x46')]:_0x2db877[_0xb5be('0x42')];if(!_0x25b180['query']['hasOwnProperty'](_0xb5be('0x107'))){_0x35eeb6[_0xb5be('0x2e')]=qs[_0xb5be('0x2e')](_0x25b180[_0xb5be('0x43')][_0xb5be('0x2e')]);_0x35eeb6[_0xb5be('0x2d')]=qs[_0xb5be('0x2d')](_0x25b180[_0xb5be('0x43')][_0xb5be('0x2d')]);}_0x35eeb6[_0xb5be('0x94')]=qs[_0xb5be('0x49')](_0x25b180['query'][_0xb5be('0x49')]);_0x35eeb6['where']=qs[_0xb5be('0x4c')](_['pick'](_0x25b180['query'],_0x2db877[_0xb5be('0x4c')]));_0x35eeb6[_0xb5be('0x4a')][_0xb5be('0xb3')]=_0x359e08['id'];if(_0x25b180[_0xb5be('0x43')]['filter']){_0x35eeb6[_0xb5be('0x4a')]=_[_0xb5be('0x9e')](_0x35eeb6[_0xb5be('0x4a')],{'$or':_[_0xb5be('0x38')](_0x35eeb6['attributes'],function(_0x504426){var _0x185e92={};_0x185e92[_0x504426]={'$like':'%'+_0x25b180[_0xb5be('0x43')][_0xb5be('0x88')]+'%'};return _0x185e92;})});}if(_0x25b180[_0xb5be('0x43')]['$gte']){var _0x4ceb9b=_0x25b180[_0xb5be('0x43')][_0xb5be('0x108')]['split'](',');var _0x4518c4={};_0x4518c4[_0x4ceb9b[0x0]]={'$gte':moment(_0x4ceb9b[0x1])[_0xb5be('0xe7')](_0xb5be('0x109'))};_0x35eeb6[_0xb5be('0x4a')]=_[_0xb5be('0x9e')](_0x35eeb6[_0xb5be('0x4a')],_0x4518c4);}_0x35eeb6=_[_0xb5be('0x9e')]({},_0x35eeb6,_0x25b180['options']);return db[_0xb5be('0xe5')][_0xb5be('0x2c')]({'where':_0x35eeb6[_0xb5be('0x4a')]})['then'](function(_0x441d66){_0x267784[_0xb5be('0x2c')]=_0x441d66;if(_0x25b180[_0xb5be('0x43')][_0xb5be('0xb8')]){_0x35eeb6['include']=[{'all':!![]}];}return db[_0xb5be('0xe5')][_0xb5be('0x10a')](_0x35eeb6);})[_0xb5be('0x33')](function(_0x573d68){_0x267784[_0xb5be('0xb5')]=_0x573d68;return _0x267784;});}})[_0xb5be('0x33')](respondWithFilteredResult(_0x378823,_0x35eeb6))[_0xb5be('0x27')](handleError(_0x378823,null));};exports['getMyMessages']=function(_0x252379,_0x5b684f,_0x3efde1){var _0x2ff2bf={'where':{}},_0xc34b7={},_0x54d1d4={'count':0x0,'rows':[]};return db[_0xb5be('0x3e')][_0xb5be('0xc0')]({'where':{'id':_0x252379['params']['id']}})['then'](handleEntityNotFound(_0x5b684f,null))['then'](function(_0x45695b){if(_0x45695b){_0xc34b7[_0xb5be('0x42')]=_[_0xb5be('0x44')](db[_0xb5be('0xe5')][_0xb5be('0x3f')]);_0xc34b7[_0xb5be('0x43')]=_[_0xb5be('0x44')](_0x252379[_0xb5be('0x43')]);_0xc34b7[_0xb5be('0x4c')]=_['intersection'](_0xc34b7[_0xb5be('0x42')],_0xc34b7[_0xb5be('0x43')]);_0x2ff2bf[_0xb5be('0x46')]=_['intersection'](_0xc34b7[_0xb5be('0x42')],qs[_0xb5be('0x47')](_0x252379['query'][_0xb5be('0x47')]));_0x2ff2bf[_0xb5be('0x46')]=_0x2ff2bf[_0xb5be('0x46')][_0xb5be('0x48')]?_0x2ff2bf[_0xb5be('0x46')]:_0xc34b7[_0xb5be('0x42')];if(!_0x252379['query'][_0xb5be('0x10b')](_0xb5be('0x107'))){_0x2ff2bf[_0xb5be('0x2e')]=qs[_0xb5be('0x2e')](_0x252379['query'][_0xb5be('0x2e')]);_0x2ff2bf[_0xb5be('0x2d')]=qs[_0xb5be('0x2d')](_0x252379[_0xb5be('0x43')][_0xb5be('0x2d')]);}_0x2ff2bf[_0xb5be('0x94')]=qs[_0xb5be('0x49')](_0x252379[_0xb5be('0x43')][_0xb5be('0x49')]);_0x2ff2bf[_0xb5be('0x4a')]=qs[_0xb5be('0x4c')](_[_0xb5be('0x4b')](_0x252379[_0xb5be('0x43')],_0xc34b7[_0xb5be('0x4c')]));_0x2ff2bf[_0xb5be('0x4a')][_0xb5be('0xb3')]=_0x45695b['id'];if(_0x252379[_0xb5be('0x43')][_0xb5be('0x88')]){_0x2ff2bf['where']=_[_0xb5be('0x9e')](_0x2ff2bf[_0xb5be('0x4a')],{'$or':_[_0xb5be('0x38')](_0x2ff2bf[_0xb5be('0x46')],function(_0x1837b7){var _0x3a101e={};_0x3a101e[_0x1837b7]={'$like':'%'+_0x252379[_0xb5be('0x43')][_0xb5be('0x88')]+'%'};return _0x3a101e;})});}_0x2ff2bf[_0xb5be('0x4a')][_0xb5be('0xf3')]=![];if(_0x252379['query']['id']){_0x2ff2bf['where']['id']={'$gt':_0x252379[_0xb5be('0x43')]['id']};}_0x2ff2bf=_[_0xb5be('0x9e')]({},_0x2ff2bf,_0x252379['options']);return db['ChatMessage'][_0xb5be('0x2c')]({'where':_0x2ff2bf['where']})[_0xb5be('0x33')](function(_0xc3843){_0x54d1d4[_0xb5be('0x2c')]=_0xc3843;_0x2ff2bf[_0xb5be('0xb9')]=[];if(_0x252379['query'][_0xb5be('0x10c')]){_0x2ff2bf[_0xb5be('0xb9')][_0xb5be('0x3c')]({'model':db[_0xb5be('0x6f')],'as':'User','attributes':['id',_0xb5be('0x39'),_0xb5be('0xef')]});}if(_0x252379[_0xb5be('0x43')][_0xb5be('0xb8')]){_0x2ff2bf[_0xb5be('0xb9')]=[{'all':!![]}];}return db[_0xb5be('0xe5')][_0xb5be('0x10a')](_0x2ff2bf);})[_0xb5be('0x33')](function(_0x4344b8){_0x54d1d4[_0xb5be('0xb5')]=_0x4344b8;return _0x54d1d4;});}})[_0xb5be('0x33')](respondWithFilteredResult(_0x5b684f,_0x2ff2bf))[_0xb5be('0x27')](handleError(_0x5b684f,null));};exports['addTags']=function(_0x33f586,_0x514455,_0x3607c2){return db[_0xb5be('0x3e')]['find']({'where':{'id':_0x33f586[_0xb5be('0xb7')]['id']}})[_0xb5be('0x33')](handleEntityNotFound(_0x514455,null))[_0xb5be('0x33')](function(_0x2a3176){if(_0x2a3176){return _0x2a3176['setTags'](_0x33f586['body'][_0xb5be('0x104')],_['omit'](_0x33f586[_0xb5be('0xbc')],[_0xb5be('0x104'),'id'])||{})[_0xb5be('0x10d')](function(){return db[_0xb5be('0x6d')][_0xb5be('0x10a')]({'attributes':['id',_0xb5be('0x35'),_0xb5be('0x10e')],'where':{'id':_0x33f586['body'][_0xb5be('0x104')]}});})[_0xb5be('0x33')](function(_0x1184b0){socket[_0xb5be('0x10f')]('chatInteractionTags:save',{'id':Number(_0x33f586[_0xb5be('0xb7')]['id']),'tags':_0x1184b0||[]});return{'id':Number(_0x33f586['params']['id']),'tags':_0x1184b0||[]};});}})[_0xb5be('0x33')](respondWithResult(_0x514455,null))[_0xb5be('0x27')](handleError(_0x514455,null));};exports[_0xb5be('0x110')]=function(_0x28a3b9,_0x12ba53,_0x323b00){return db[_0xb5be('0x3e')]['find']({'where':{'id':_0x28a3b9[_0xb5be('0xb7')]['id']}})['then'](handleEntityNotFound(_0x12ba53,null))[_0xb5be('0x33')](function(_0x68f992){if(_0x68f992){return _0x68f992[_0xb5be('0x110')](_0x28a3b9['query'][_0xb5be('0x104')]);}})[_0xb5be('0x33')](respondWithStatusCode(_0x12ba53,null))[_0xb5be('0x27')](handleError(_0x12ba53,null));};exports[_0xb5be('0xe0')]=function(_0x2caeae,_0x436308){var _0x4ed9c7=moment()[_0xb5be('0x111')]()['toString']();var _0x51245c=path[_0xb5be('0xdc')](config[_0xb5be('0xdd')],_0xb5be('0x112'),_0xb5be('0x113'),_0xb5be('0x114'));var _0x3efb7d=path[_0xb5be('0xdc')](config[_0xb5be('0xdd')],_0xb5be('0x112'),'files','attachments');var _0x1326f2=path[_0xb5be('0xdc')](_0x51245c,_0x4ed9c7);var _0x277895=util[_0xb5be('0xe7')](_0xb5be('0x115'),_0x2caeae[_0xb5be('0xb7')]['id'],_0x4ed9c7);var _0x313053=path['join'](_0x51245c,_0x277895);var _0x467938=[];_0x467938[_0xb5be('0x3c')]({'model':db[_0xb5be('0x6f')],'as':_0xb5be('0x6f'),'attributes':['id',_0xb5be('0x39')],'raw':!![]});_0x467938[_0xb5be('0x3c')]({'model':db['CmContact'],'as':_0xb5be('0xcd'),'attributes':['id',_0xb5be('0x116'),'lastName'],'raw':!![]});if(_0x2caeae[_0xb5be('0x43')][_0xb5be('0x117')]){_0x467938['push']({'model':db[_0xb5be('0xd8')],'as':'Attachment','raw':!![]});}var _0x2359e7=[{'model':db[_0xb5be('0xe5')],'as':_0xb5be('0xe6'),'attributes':['id',_0xb5be('0xbc'),_0xb5be('0x7b'),_0xb5be('0xf2'),_0xb5be('0xf3'),_0xb5be('0x82')],'include':_0x467938}];_0x2359e7['push']({'model':db[_0xb5be('0xc1')],'as':_0xb5be('0x118'),'attributes':['id',_0xb5be('0x35')]});_0x2359e7[_0xb5be('0x3c')]({'model':db[_0xb5be('0x6f')],'as':'Owner','attributes':['id',_0xb5be('0x39')]});return db[_0xb5be('0x3e')][_0xb5be('0x62')]({'where':{'id':_0x2caeae[_0xb5be('0xb7')]['id']},'include':_0x2359e7})[_0xb5be('0x33')](handleEntityNotFound(_0x436308,null))[_0xb5be('0x33')](function(_0x7828ce){if(_0x7828ce){var _0x1359a5=_0x7828ce[_0xb5be('0x119')]({'plain':!![]});fs['mkdirSync'](_0x1326f2);var _0x2ba3f3={'channel':_0xb5be('0x11a'),'account':_0x1359a5['Account'][_0xb5be('0x35')],'agent':_0x1359a5[_0xb5be('0x11b')]?_0x1359a5[_0xb5be('0x11b')][_0xb5be('0x39')]:_0xb5be('0x11c'),'createdAt':moment(_0x1359a5[_0xb5be('0x7b')])['format'](_0xb5be('0x109'))[_0xb5be('0x9c')](),'closedAt':_0x1359a5[_0xb5be('0xd0')]?moment(_0x1359a5[_0xb5be('0x11d')])[_0xb5be('0xe7')]('YYYY-MM-DD\x20HH:mm:ss')[_0xb5be('0x9c')]():'','disposition':_0x1359a5[_0xb5be('0xd1')],'chatInfo':{'browser':_0x1359a5['browserName'],'os':_0x1359a5[_0xb5be('0x11e')],'referer':_0x1359a5[_0xb5be('0x11f')],'customerIp':_0x1359a5[_0xb5be('0x120')],'customerPort':_0x1359a5[_0xb5be('0x121')]?_0x1359a5[_0xb5be('0x121')]:_0xb5be('0x11c')},'messages':_(_0x1359a5[_0xb5be('0xe6')])[_0xb5be('0x122')]()[_0xb5be('0x88')]({'secret':![]})['map'](function(_0x56ba91){if(_0x56ba91[_0xb5be('0xd8')]){var _0x47f814=path[_0xb5be('0xdc')](_0x3efb7d,_0x56ba91[_0xb5be('0xd8')][_0xb5be('0xd4')]);if(fs[_0xb5be('0x123')](_0x47f814)){fs[_0xb5be('0x124')](_0x47f814)[_0xb5be('0x125')](fs[_0xb5be('0x126')](path[_0xb5be('0xdc')](_0x1326f2,_0x56ba91[_0xb5be('0xd8')][_0xb5be('0xd4')])));}}return{'date':moment(_0x56ba91[_0xb5be('0x7b')])[_0xb5be('0xe7')](_0xb5be('0x109'))[_0xb5be('0x9c')](),'sender':_0x56ba91[_0xb5be('0xf2')]==='out'?_0x56ba91[_0xb5be('0x6f')]?_0x56ba91[_0xb5be('0x6f')][_0xb5be('0x39')]:'System':_0x56ba91[_0xb5be('0xcd')]['firstName']+(_0x56ba91[_0xb5be('0xcd')][_0xb5be('0x127')]?'\x20'+_0x56ba91[_0xb5be('0xcd')]['lastName']:''),'body':_0x56ba91[_0xb5be('0xd8')]?_0x56ba91['Attachment'][_0xb5be('0xd4')]:_0x56ba91[_0xb5be('0xbc')],'direction':_0x56ba91[_0xb5be('0xf2')]===_0xb5be('0xc9')?'A':'C','secret':_0x56ba91['secret'],'read':_0x56ba91[_0xb5be('0x82')],'attachment':_0x56ba91[_0xb5be('0xd8')]};})[_0xb5be('0x63')]()};return ejs[_0xb5be('0x128')](path[_0xb5be('0xdc')](config[_0xb5be('0xdd')],_0xb5be('0x112'),_0xb5be('0x129'),_0xb5be('0x12a')),{'interaction':_0x2ba3f3})['then'](function(_0xe4652f){var _0x9431a5=path[_0xb5be('0xdc')](_0x1326f2,'transcript-'+_0x1359a5['id']+'-'+_0x4ed9c7+_0xb5be('0x12b'));var _0x5dca47={'path':_0x9431a5,'channel':_0xb5be('0x11a'),'interactionId':_0x1359a5['id']};return pdf['createPdfFromHTML'](_0xe4652f,_0x5dca47);})[_0xb5be('0x33')](function(){return new BPromise(function(_0x399ac6,_0x52a6ea){zipdir(_0x1326f2,{'saveTo':_0x313053},function(_0x3f941b,_0x1e3784){if(_0x3f941b)return _0x52a6ea(_0x3f941b);return _0x399ac6(_0x1e3784);});})[_0xb5be('0x33')](function(){return new BPromise(function(_0x43b32c,_0x1ab2a1){rimraf(_0x1326f2,function(_0x5374b3){if(_0x5374b3)_0x1ab2a1(_0x5374b3);return _0x43b32c();});});})['then'](function(){return _0x436308['download'](_0x313053,_0x277895,function(_0xe7e31c){if(_0xe7e31c){console[_0xb5be('0x12c')](_0xb5be('0x12d'),_0xe7e31c);}else{fs['unlinkSync'](_0x313053);}});});});}else{return _0x436308[_0xb5be('0x28')](0xc8);}})[_0xb5be('0x27')](handleError(_0x436308,null));};