Built motion from commit 00bf23f6.|2.6.16
[motion2.git] / server / api / openchannelInteraction / openchannelInteraction.controller.js
index 526249c..99a014d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x02fb=['$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','type','start','body','compact','isEmpty','OpenchannelAccountId','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20=\x20?','read','tag','isArray','filter','replace','isNumeric','i.id\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','i.from\x20LIKE\x20?','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','QueryTypes','SELECT','i.id','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','order','DESC','i.OpenchannelAccountId\x20IS\x20NOT\x20NULL','user','role','i.OpenchannelAccountId\x20IN\x20?','agent','sequelize','toString','keyBy','merge','fields','unreadMessages','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','CASE\x20WHEN\x20i.from\x20IS\x20NOT\x20NULL\x20AND\x20i.from\x20<>\x20\x27\x27\x20THEN\x20i.from\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','i.*','Contact.firstName','Contact.lastName','c.email','Contact.email','c.mobile','Contact.mobile','Contact.fax','o.fullname','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','groupBy','all','rows','show','includeAll','include','options','create','params','describe','OpenchannelMessage','addMessage','ids','omit','findOne','OpenchannelInteractionId','format','findAll','addTags','setTags','spread','emit','openchannelInteractionTags:save','removeTags','download','unix','root','server','tmp','join','files','attachments','transcript-%d-%s.zip','CmContact','firstName','Attachment','secret','Owner','get','mkdirSync','40px','<div\x20class=\x22header\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<h5>Interaction\x20Transcript</h5>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','30px','<hr\x20class=\x22separator\x22/>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22footer\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22left\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22center\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>{{page}}/{{pages}}</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22right\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','Openchannel','YYYY-MM-DD','Account','N.A.','YYYY-MM-DD\x20HH:mm:ss','closed','disposition','threadId','Public','Private','Messages','basename','createReadStream','pipe','direction','out','System','lastName','renderFile','downloadInteraction.html','transcript-','.pdf','err','unlinkSync','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','to-csv','ejs','lodash','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/environment','../../config/license/util','../../mysqldb','defaults','localhost','redis','./openchannelInteraction.socket','sendStatus','status','end','json','count','offset','limit','apply','reject','save','update','then','destroy','name','Users','map','fullname','TagIds','Tags','forEach','push','catch','OpenchannelInteraction','rawAttributes','fieldName','query','keys','intersection','model','attributes','length','hasOwnProperty','nolimit','sort','where','filters','pick','select','field','color','from','tools_tags','u.id','u.fullname','ui.OpenchannelInteractionId','user_has_openchannel_interactions','left_join','users','openchannel_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','openchannel_accounts','a.id\x20=\x20i.OpenchannelAccountId','openchannel_messages','me.OpenchannelInteractionId\x20=\x20i.id','openchannel_interaction_has_tags','t.id\x20=\x20it.TagId','expr','search','conditions','find','having','`\x20=\x200','`\x20>\x200','Contact','operator','value','split','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','text','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','User'];(function(_0x355c9a,_0x688098){var _0x41c8a4=function(_0x1832a6){while(--_0x1832a6){_0x355c9a['push'](_0x355c9a['shift']());}};_0x41c8a4(++_0x688098);}(_0x02fb,0x16c));var _0xb02f=function(_0x3f4639,_0x579849){_0x3f4639=_0x3f4639-0x0;var _0x5ef2c9=_0x02fb[_0x3f4639];return _0x5ef2c9;};'use strict';var pdf=require(_0xb02f('0x0'));var emlformat=require(_0xb02f('0x1'));var rimraf=require(_0xb02f('0x2'));var zipdir=require(_0xb02f('0x3'));var jsonpatch=require(_0xb02f('0x4'));var rp=require(_0xb02f('0x5'));var moment=require(_0xb02f('0x6'));var BPromise=require('bluebird');var Mustache=require(_0xb02f('0x7'));var util=require(_0xb02f('0x8'));var path=require(_0xb02f('0x9'));var sox=require('sox');var csv=require(_0xb02f('0xa'));var ejs=require(_0xb02f('0xb'));var fs=require('fs');var _=require(_0xb02f('0xc'));var squel=require('squel');var crypto=require(_0xb02f('0xd'));var jsforce=require(_0xb02f('0xe'));var deskjs=require(_0xb02f('0xf'));var toCsv=require(_0xb02f('0xa'));var querystring=require('querystring');var Papa=require(_0xb02f('0x10'));var Redis=require(_0xb02f('0x11'));var authService=require(_0xb02f('0x12'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb02f('0x13'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0xb02f('0x14'));var licenseUtil=require(_0xb02f('0x15'));var db=require(_0xb02f('0x16'))['db'];config['redis']=_[_0xb02f('0x17')](config['redis'],{'host':_0xb02f('0x18'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xb02f('0x19')]));require(_0xb02f('0x1a'))['register'](socket);function respondWithStatusCode(_0x11a6ea,_0x3ce985){_0x3ce985=_0x3ce985||0xcc;return function(_0x4d2955){if(_0x4d2955){return _0x11a6ea[_0xb02f('0x1b')](_0x3ce985);}return _0x11a6ea[_0xb02f('0x1c')](_0x3ce985)[_0xb02f('0x1d')]();};}function respondWithResult(_0xa751de,_0x5c649a){_0x5c649a=_0x5c649a||0xc8;return function(_0x28b8d9){if(_0x28b8d9){return _0xa751de[_0xb02f('0x1c')](_0x5c649a)[_0xb02f('0x1e')](_0x28b8d9);}};}function respondWithFilteredResult(_0x10ef2e,_0x336fd1){return function(_0x35d6e7){if(_0x35d6e7){var _0x46b46d=_0x35d6e7[_0xb02f('0x1f')],_0x40d305=_0x336fd1[_0xb02f('0x20')],_0x3897f4=_0x336fd1[_0xb02f('0x20')]+_0x336fd1[_0xb02f('0x21')],_0x57ecd9;if(_0x3897f4>=_0x46b46d){_0x3897f4=_0x46b46d;_0x57ecd9=0xc8;}else{_0x57ecd9=0xce;}_0x10ef2e[_0xb02f('0x1c')](_0x57ecd9);return _0x10ef2e['set']('Content-Range',_0x40d305+'-'+_0x3897f4+'/'+_0x46b46d)['json'](_0x35d6e7);}return null;};}function patchUpdates(_0x329a25){return function(_0x29b2aa){try{jsonpatch[_0xb02f('0x22')](_0x29b2aa,_0x329a25,!![]);}catch(_0x23daa0){return BPromise[_0xb02f('0x23')](_0x23daa0);}return _0x29b2aa[_0xb02f('0x24')]();};}function saveUpdates(_0x134366,_0x1be900){return function(_0x220643){if(_0x220643){return _0x220643[_0xb02f('0x25')](_0x134366)[_0xb02f('0x26')](function(_0x84d57d){return _0x84d57d;});}return null;};}function removeEntity(_0xdeadc8,_0x54d59f){return function(_0x541f72){if(_0x541f72){return _0x541f72[_0xb02f('0x27')]()[_0xb02f('0x26')](function(){_0xdeadc8[_0xb02f('0x1c')](0xcc)[_0xb02f('0x1d')]();});}};}function handleEntityNotFound(_0x2a5dd2,_0x591cfb){return function(_0x1423e9){if(!_0x1423e9){_0x2a5dd2[_0xb02f('0x1b')](0x194);}return _0x1423e9;};}function handleError(_0x591f19,_0x1a84a5){_0x1a84a5=_0x1a84a5||0x1f4;return function(_0x403a52){logger['error'](_0x403a52['stack']);if(_0x403a52['name']){delete _0x403a52[_0xb02f('0x28')];}_0x591f19[_0xb02f('0x1c')](_0x1a84a5)['send'](_0x403a52);};}function getInteractionUsers(_0x37a2a8,_0x5e71d8){return new BPromise(function(_0x17f83d,_0xd16bae){try{if(_0x5e71d8[_0x37a2a8['id']]){_0x37a2a8[_0xb02f('0x29')]=_[_0xb02f('0x2a')](_0x5e71d8[_0x37a2a8['id']],function(_0x2efaa6){return{'id':_0x2efaa6['id'],'fullname':_0x2efaa6[_0xb02f('0x2b')]};});}}catch(_0x4343d4){_0xd16bae(_0x4343d4);}_0x17f83d(_0x37a2a8);});}function getInteractionTags(_0x1cb2cf,_0x124709){return new BPromise(function(_0x489609,_0x53387a){try{if(_0x1cb2cf[_0xb02f('0x2c')]){_0x1cb2cf[_0xb02f('0x2d')]=[];_0x1cb2cf[_0xb02f('0x2c')]['split'](',')[_0xb02f('0x2e')](function(_0x57399e){_0x1cb2cf[_0xb02f('0x2d')][_0xb02f('0x2f')](_0x124709[_0x57399e]);});}delete _0x1cb2cf[_0xb02f('0x2c')];}catch(_0x82c900){_0x53387a(_0x82c900);}_0x489609(_0x1cb2cf);});}function updateOpenchannelInteraction(_0x257b9c,_0x11421a,_0x5326e7){return new BPromise(function(_0x23c118,_0x18a4f7){return getInteractionUsers(_0x257b9c,_0x5326e7)[_0xb02f('0x26')](function(_0x59fc78){return getInteractionTags(_0x59fc78,_0x11421a);})[_0xb02f('0x26')](function(_0x599c10){_0x23c118(_0x599c10);})[_0xb02f('0x30')](function(_0x8db873){_0x18a4f7(_0x8db873);});});}exports['index']=function(_0x5508eb,_0x410785){var _0x26c3a0={},_0x1043ad={},_0x14ef66={'count':0x0,'rows':[]};var _0xea9c44=_['map'](db[_0xb02f('0x31')][_0xb02f('0x32')],function(_0x52da1c){return{'name':_0x52da1c[_0xb02f('0x33')],'type':_0x52da1c['type']['key']};});_0x1043ad['model']=_['map'](_0xea9c44,_0xb02f('0x28'));_0x1043ad[_0xb02f('0x34')]=_[_0xb02f('0x35')](_0x5508eb[_0xb02f('0x34')]);_0x1043ad['filters']=_[_0xb02f('0x36')](_0x1043ad[_0xb02f('0x37')],_0x1043ad[_0xb02f('0x34')]);_0x26c3a0[_0xb02f('0x38')]=_[_0xb02f('0x36')](_0x1043ad[_0xb02f('0x37')],qs['fields'](_0x5508eb[_0xb02f('0x34')]['fields']));_0x26c3a0[_0xb02f('0x38')]=_0x26c3a0[_0xb02f('0x38')][_0xb02f('0x39')]?_0x26c3a0[_0xb02f('0x38')]:_0x1043ad[_0xb02f('0x37')];if(!_0x5508eb[_0xb02f('0x34')][_0xb02f('0x3a')](_0xb02f('0x3b'))){_0x26c3a0[_0xb02f('0x21')]=qs['limit'](_0x5508eb['query']['limit']);_0x26c3a0['offset']=qs[_0xb02f('0x20')](_0x5508eb['query'][_0xb02f('0x20')]);}_0x26c3a0['order']=qs[_0xb02f('0x3c')](_0x5508eb['query'][_0xb02f('0x3c')]);_0x26c3a0[_0xb02f('0x3d')]=qs[_0xb02f('0x3e')](_[_0xb02f('0x3f')](_0x5508eb[_0xb02f('0x34')],_0x1043ad[_0xb02f('0x3e')]),_0xea9c44);var _0x2cafcb=[];var _0x4e67a4=squel[_0xb02f('0x40')]()[_0xb02f('0x41')]('id')[_0xb02f('0x41')](_0xb02f('0x28'))[_0xb02f('0x41')](_0xb02f('0x42'))[_0xb02f('0x43')](_0xb02f('0x44'));var _0x589680=squel['select']()[_0xb02f('0x41')](_0xb02f('0x45'))[_0xb02f('0x41')](_0xb02f('0x46'))[_0xb02f('0x41')](_0xb02f('0x47'))['from'](_0xb02f('0x48'),'ui')[_0xb02f('0x49')](_0xb02f('0x4a'),'u','u.id\x20=\x20ui.UserId');var _0x3ebbc4=squel[_0xb02f('0x40')]()['from'](_0xb02f('0x4b'),'i')[_0xb02f('0x49')](_0xb02f('0x4c'),'c',_0xb02f('0x4d'))[_0xb02f('0x49')]('users','o',_0xb02f('0x4e'))['left_join'](_0xb02f('0x4f'),'a',_0xb02f('0x50'))['left_join'](_0xb02f('0x51'),'me',_0xb02f('0x52'))[_0xb02f('0x49')](_0xb02f('0x53'),'it','it.OpenchannelInteractionId\x20=\x20i.id')[_0xb02f('0x49')]('tools_tags','t',_0xb02f('0x54'));var _0x180169=squel[_0xb02f('0x55')]();var _0x17ecb5=[];var _0xd11747=squel[_0xb02f('0x55')]();var _0xc7011e;if(_0x5508eb[_0xb02f('0x34')][_0xb02f('0x56')]){_0xc7011e=as['parseSearch'](_0x5508eb['query'][_0xb02f('0x56')]);var _0x5607ae=_0xc7011e['sqlOperator'];for(var _0x5e95a9=0x0;_0x5e95a9<_0xc7011e[_0xb02f('0x57')]['length'];_0x5e95a9++){var _0x485a59=_0xc7011e[_0xb02f('0x57')][_0x5e95a9];var _0x92f5ec='i';var _0x2f3dc6=_[_0xb02f('0x58')](_0xea9c44,[_0xb02f('0x28'),_0x485a59[_0xb02f('0x41')]]);if(!_0x2f3dc6){switch(_0x485a59[_0xb02f('0x41')]){case'unreadMessages':if(_0x485a59['value']==0x1){_0x3ebbc4[_0xb02f('0x59')]('`'+_0x485a59[_0xb02f('0x41')]+_0xb02f('0x5a'));}else{_0x3ebbc4[_0xb02f('0x59')]('`'+_0x485a59[_0xb02f('0x41')]+_0xb02f('0x5b'));}break;case _0xb02f('0x5c'):if(_0x485a59[_0xb02f('0x5d')]==='$substring'){if(_0x485a59[_0xb02f('0x5e')][_0xb02f('0x5f')]('\x20')[_0xb02f('0x39')]>0x1){_0x180169[_0x5607ae]('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xb02f('0x60')](_0x485a59[_0xb02f('0x5e')]),null);}else{var _0x36e324='%'+_0x485a59['value']+'%';_0x180169[_0x5607ae](_0xb02f('0x61'),_0x36e324,_0x36e324,_0x36e324);}}else{_0x2f3dc6=_[_0xb02f('0x58')](_0xea9c44,[_0xb02f('0x28'),_0xb02f('0x62')]);_0x485a59[_0xb02f('0x41')]='ContactId';_0x3ca1b0=as[_0xb02f('0x63')](_0x92f5ec,_0x2f3dc6['type'],_0x485a59);_0x180169[_0x5607ae](_0x3ca1b0[_0xb02f('0x64')],_0x3ca1b0['value']['start'],_0x3ca1b0[_0xb02f('0x5e')][_0xb02f('0x1d')]);}break;case _0xb02f('0x65'):var _0x24f942=_0x485a59['value'][_0xb02f('0x5f')](',')[_0xb02f('0x2a')](function(_0x297482){return Number(_0x297482);});_0x24f942[_0xb02f('0x2e')](function(_0x540d87){_0xd11747['or'](_0xb02f('0x66'),'%,'+_0x540d87+',%');});_0x17ecb5=_['union'](_0x17ecb5,_0x24f942);break;case _0xb02f('0x67'):if(_0x485a59[_0xb02f('0x5d')]===_0xb02f('0x68')){_0x180169[_0x5607ae](_0xb02f('0x69'),'%'+_0x485a59['value']+'%',null);}else{_0x2f3dc6=_['find'](_0xea9c44,['name',_0xb02f('0x6a')]);_0x485a59[_0xb02f('0x41')]=_0xb02f('0x6a');_0x3ca1b0=as[_0xb02f('0x63')](_0x92f5ec,_0x2f3dc6[_0xb02f('0x6b')],_0x485a59);_0x180169[_0x5607ae](_0x3ca1b0['text'],_0x3ca1b0['value'][_0xb02f('0x6c')],_0x3ca1b0['value']['end']);}break;case _0xb02f('0x6d'):_0x3ca1b0=as[_0xb02f('0x63')]('me',null,_0x485a59);_0x180169[_0x5607ae](_0x3ca1b0[_0xb02f('0x64')],_0x3ca1b0['value'][_0xb02f('0x6c')],_0x3ca1b0[_0xb02f('0x5e')][_0xb02f('0x1d')]);break;}}else{var _0x3ca1b0=as[_0xb02f('0x63')](_0x92f5ec,_0x2f3dc6[_0xb02f('0x6b')],_0x485a59);_0x180169[_0x5607ae](_0x3ca1b0['text'],_0x3ca1b0[_0xb02f('0x5e')][_0xb02f('0x6c')],_0x3ca1b0[_0xb02f('0x5e')][_0xb02f('0x1d')]);}}}else{var _0x434e31=_(_0x5508eb[_0xb02f('0x34')])[_0xb02f('0x35')]()['map'](function(_0x421034){return _['some'](_0xea9c44,['name',_0x421034])?_0x421034:undefined;})[_0xb02f('0x6e')]()['value']();if(!_[_0xb02f('0x6f')](_0x434e31)){_0x434e31[_0xb02f('0x2e')](function(_0x217e89){if(_0x217e89===_0xb02f('0x70')){_0x3ebbc4[_0xb02f('0x3d')]('i.OpenchannelAccountId\x20IN\x20?',[][_0xb02f('0x71')](_0x5508eb[_0xb02f('0x34')][_0x217e89]));}else if(_0x217e89===_0xb02f('0x72')){var _0x566e66=JSON[_0xb02f('0x73')](_0x5508eb[_0xb02f('0x34')][_0x217e89])[_0xb02f('0x74')];var _0x1dcb69=JSON['parse'](_0x5508eb['query'][_0x217e89])[_0xb02f('0x75')];_0x3ebbc4[_0xb02f('0x3d')](_0xb02f('0x76'),_0x566e66,_0x1dcb69);}else{if(_0x5508eb[_0xb02f('0x34')][_0x217e89]===_0xb02f('0x77')){_0x3ebbc4[_0xb02f('0x3d')]('i.'+_0x217e89+'\x20IS\x20NULL');}else{_0x3ebbc4[_0xb02f('0x3d')]('i.'+_0x217e89+_0xb02f('0x78'),_0x5508eb[_0xb02f('0x34')][_0x217e89]);}}});}if(_0x5508eb[_0xb02f('0x34')][_0xb02f('0x79')]){if(_0x5508eb['query'][_0xb02f('0x79')]==0x1){_0x3ebbc4[_0xb02f('0x59')]('`unreadMessages`\x20=\x200');}else{_0x3ebbc4[_0xb02f('0x59')]('`unreadMessages`\x20>\x200');}}if(_0x5508eb[_0xb02f('0x34')][_0xb02f('0x7a')]){_0x17ecb5=_[_0xb02f('0x7b')](_0x5508eb[_0xb02f('0x34')][_0xb02f('0x7a')])?_0x5508eb['query'][_0xb02f('0x7a')]:new Array(_0x5508eb[_0xb02f('0x34')][_0xb02f('0x7a')]);_0x17ecb5[_0xb02f('0x2e')](function(_0x10c9c8){_0xd11747['or'](_0xb02f('0x66'),'%,'+_0x10c9c8+',%');});}if(_0x5508eb[_0xb02f('0x34')][_0xb02f('0x7c')]){var _0x2845d9=_0x5508eb[_0xb02f('0x34')][_0xb02f('0x7c')][_0xb02f('0x7d')]('\x5c','\x5c\x5c')[_0xb02f('0x7d')](/'/g,'\x27\x27');if(qs[_0xb02f('0x7e')](_0x2845d9)){_0x180169['or'](_0xb02f('0x7f'),_0x2845d9+'%');}else{_0x180169['or'](_0xb02f('0x80'),qs['getFullTextValue'](_0x2845d9))['or'](_0xb02f('0x81'),_0x2845d9+'%')['or'](_0xb02f('0x82'),_0x2845d9+'%');}}}_0x3ebbc4['where'](_0x180169);_0x3ebbc4[_0xb02f('0x83')]('i.id');var _0x1b4e0d={'type':db['Sequelize'][_0xb02f('0x84')][_0xb02f('0x85')],'raw':!![]};var _0x5364a9=_0x3ebbc4['clone']();_0x5364a9[_0xb02f('0x41')](_0xb02f('0x86'));_0x5364a9[_0xb02f('0x41')](_0xb02f('0x87'),'unreadMessages');if(_0x26c3a0[_0xb02f('0x88')]){_0x26c3a0[_0xb02f('0x88')][_0xb02f('0x2e')](function(_0x260f97){var _0x539d33=_0x260f97[0x0]==='contactName'?_0x260f97[0x0]:'i.'+_0x260f97[0x0];_0x3ebbc4[_0xb02f('0x88')](_0x539d33,_0x260f97[0x1]===_0xb02f('0x89')?![]:!![]);});}if(!_[_0xb02f('0x6f')](_0x17ecb5)){_0x3ebbc4['having'](_0xd11747);_0x5364a9[_0xb02f('0x3d')]('t.id\x20IN\x20?',_0x17ecb5);}BPromise['resolve']()[_0xb02f('0x26')](function(){if(!_0xc7011e){if(_0x5508eb[_0xb02f('0x34')][_0xb02f('0x70')])return;_0x5364a9[_0xb02f('0x3d')](_0xb02f('0x8a'));_0x3ebbc4['where'](_0xb02f('0x8a'));return;}if(_0x5508eb[_0xb02f('0x8b')][_0xb02f('0x8c')]!=='agent')return;return _0x5508eb[_0xb02f('0x8b')]['getOpenchannelAccounts']({'attributes':['id'],'raw':!![]})[_0xb02f('0x26')](function(_0xf767a7){if(_[_0xb02f('0x6f')](_0xf767a7)){_0x5364a9[_0xb02f('0x3d')]('i.OpenchannelAccountId\x20IS\x20NULL');_0x3ebbc4[_0xb02f('0x3d')]('i.OpenchannelAccountId\x20IS\x20NULL');}else{_0x5364a9['where'](_0xb02f('0x8d'),_[_0xb02f('0x2a')](_0xf767a7,'id'));_0x3ebbc4[_0xb02f('0x3d')](_0xb02f('0x8d'),_[_0xb02f('0x2a')](_0xf767a7,'id'));}});})[_0xb02f('0x26')](function(){if(_0x5508eb['user']['role']===_0xb02f('0x8e')&&!_0xc7011e&&!_0x5508eb[_0xb02f('0x34')][_0xb02f('0x70')])return[];return db[_0xb02f('0x8f')][_0xb02f('0x34')](_0x5364a9['toString'](),_0x1b4e0d);})[_0xb02f('0x26')](function(_0x575c28){_0x14ef66[_0xb02f('0x1f')]=_0x575c28['length'];if(_0x14ef66[_0xb02f('0x1f')]===0x0)return[];return db[_0xb02f('0x8f')]['query'](_0x4e67a4[_0xb02f('0x90')](),_0x1b4e0d)[_0xb02f('0x26')](function(_0x4bbb8d){_0x2cafcb=_[_0xb02f('0x91')](_0x4bbb8d,'id');_0x1b4e0d=_[_0xb02f('0x92')](_0x1b4e0d,{'model':db[_0xb02f('0x31')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x5508eb['query'][_0xb02f('0x93')]){_0x26c3a0[_0xb02f('0x38')][_0xb02f('0x2e')](function(_0xd4874b){_0x3ebbc4[_0xb02f('0x41')]('i.'+_0xd4874b);});}else{_0x3ebbc4[_0xb02f('0x41')](_0xb02f('0x87'),_0xb02f('0x94'));_0x3ebbc4[_0xb02f('0x41')](_0xb02f('0x95'),_0xb02f('0x96'));_0x3ebbc4[_0xb02f('0x41')](_0xb02f('0x97'),_0xb02f('0x98'));_0x3ebbc4[_0xb02f('0x41')](_0xb02f('0x99'),_0xb02f('0x9a'));_0x3ebbc4['field'](_0xb02f('0x9b'));_0x3ebbc4[_0xb02f('0x41')]('c.firstName',_0xb02f('0x9c'));_0x3ebbc4[_0xb02f('0x41')]('c.lastName',_0xb02f('0x9d'));_0x3ebbc4['field'](_0xb02f('0x9e'),_0xb02f('0x9f'));_0x3ebbc4[_0xb02f('0x41')]('c.phone','Contact.phone');_0x3ebbc4['field'](_0xb02f('0xa0'),_0xb02f('0xa1'));_0x3ebbc4['field']('c.fax',_0xb02f('0xa2'));_0x3ebbc4[_0xb02f('0x41')](_0xb02f('0xa3'),'Owner.fullname');_0x3ebbc4[_0xb02f('0x41')]('o.internal',_0xb02f('0xa4'));_0x3ebbc4[_0xb02f('0x41')](_0xb02f('0xa5'),'TagIds');}if(_0x26c3a0[_0xb02f('0x21')])_0x3ebbc4[_0xb02f('0x21')](_0x26c3a0[_0xb02f('0x21')]);if(_0x26c3a0[_0xb02f('0x20')])_0x3ebbc4['offset'](_0x26c3a0[_0xb02f('0x20')]);return db['sequelize'][_0xb02f('0x34')](_0x3ebbc4[_0xb02f('0x90')](),_0x1b4e0d);})['then'](function(_0x52ec54){_0x589680[_0xb02f('0x3d')]('ui.OpenchannelInteractionId\x20IN\x20?',_[_0xb02f('0x2a')](_0x52ec54,'id'));return db[_0xb02f('0x8f')][_0xb02f('0x34')](_0x589680[_0xb02f('0x90')](),_0x1b4e0d)['then'](function(_0x595d0b){var _0x2023c9=_[_0xb02f('0xa6')](_0x595d0b,'OpenchannelInteractionId');var _0x2386fb=[];_0x52ec54['forEach'](function(_0x477aa2){_0x2386fb[_0xb02f('0x2f')](updateOpenchannelInteraction(_0x477aa2,_0x2cafcb,_0x2023c9));});return BPromise[_0xb02f('0xa7')](_0x2386fb);});});})[_0xb02f('0x26')](function(_0x4fbee5){_0x14ef66[_0xb02f('0xa8')]=_0x4fbee5;return _0x14ef66;})['then'](respondWithFilteredResult(_0x410785,_0x26c3a0))[_0xb02f('0x30')](handleError(_0x410785,null));};exports[_0xb02f('0xa9')]=function(_0x59c70c,_0x141086){var _0x47a4b1={};if(_0x59c70c[_0xb02f('0x34')][_0xb02f('0x6b')]&&_0x59c70c[_0xb02f('0x34')][_0xb02f('0x6b')]==='from'){_0x47a4b1[_0xb02f('0x43')]=_0x59c70c['params']['id'];}else{_0x47a4b1['id']=_0x59c70c['params']['id'];}var _0x5875d2={'raw':![],'where':_0x47a4b1},_0xa1069a={};_0xa1069a[_0xb02f('0x37')]=_[_0xb02f('0x35')](db['OpenchannelInteraction'][_0xb02f('0x32')]);_0xa1069a['query']=_['keys'](_0x59c70c['query']);_0xa1069a[_0xb02f('0x3e')]=_[_0xb02f('0x36')](_0xa1069a[_0xb02f('0x37')],_0xa1069a[_0xb02f('0x34')]);_0x5875d2[_0xb02f('0x38')]=_[_0xb02f('0x36')](_0xa1069a[_0xb02f('0x37')],qs['fields'](_0x59c70c[_0xb02f('0x34')][_0xb02f('0x93')]));_0x5875d2[_0xb02f('0x38')]=_0x5875d2['attributes']['length']?_0x5875d2[_0xb02f('0x38')]:_0xa1069a[_0xb02f('0x37')];if(_0x59c70c[_0xb02f('0x34')][_0xb02f('0xaa')]){_0x5875d2[_0xb02f('0xab')]=[{'all':!![]}];}_0x5875d2=_[_0xb02f('0x92')]({},_0x5875d2,_0x59c70c[_0xb02f('0xac')]);return db['OpenchannelInteraction'][_0xb02f('0x58')](_0x5875d2)[_0xb02f('0x26')](handleEntityNotFound(_0x141086,null))[_0xb02f('0x26')](respondWithResult(_0x141086,null))[_0xb02f('0x30')](handleError(_0x141086,null));};exports[_0xb02f('0xad')]=function(_0x595a3d,_0x4e698b){return db[_0xb02f('0x31')][_0xb02f('0xad')](_0x595a3d[_0xb02f('0x6d')],{})['then'](respondWithResult(_0x4e698b,0xc9))[_0xb02f('0x30')](handleError(_0x4e698b,null));};exports['update']=function(_0x42e0c6,_0x3cf8c4){if(_0x42e0c6['body']['id']){delete _0x42e0c6['body']['id'];}return db['OpenchannelInteraction'][_0xb02f('0x58')]({'where':{'id':_0x42e0c6['params']['id']}})['then'](handleEntityNotFound(_0x3cf8c4,null))['then'](saveUpdates(_0x42e0c6[_0xb02f('0x6d')],null))[_0xb02f('0x26')](respondWithResult(_0x3cf8c4,null))[_0xb02f('0x30')](handleError(_0x3cf8c4,null));};exports['destroy']=function(_0x97f152,_0x589372){return db[_0xb02f('0x31')][_0xb02f('0x58')]({'where':{'id':_0x97f152[_0xb02f('0xae')]['id']}})[_0xb02f('0x26')](handleEntityNotFound(_0x589372,null))['then'](removeEntity(_0x589372,null))[_0xb02f('0x30')](handleError(_0x589372,null));};exports['describe']=function(_0x5eb135,_0x209cce){return db[_0xb02f('0x31')][_0xb02f('0xaf')]()[_0xb02f('0x26')](respondWithResult(_0x209cce,null))[_0xb02f('0x30')](handleError(_0x209cce,null));};exports['addMessage']=function(_0xd40ebb,_0x29b686,_0x131c44){return db[_0xb02f('0xb0')][_0xb02f('0x58')]({'where':{'id':_0xd40ebb[_0xb02f('0xae')]['id']}})[_0xb02f('0x26')](handleEntityNotFound(_0x29b686,null))[_0xb02f('0x26')](function(_0x28b095){if(_0x28b095){return _0x28b095[_0xb02f('0xb1')](_0xd40ebb[_0xb02f('0x6d')][_0xb02f('0xb2')],_[_0xb02f('0xb3')](_0xd40ebb[_0xb02f('0x6d')],[_0xb02f('0xb2'),'id'])||{});}})[_0xb02f('0x26')](respondWithResult(_0x29b686,null))['catch'](handleError(_0x29b686,null));};exports['getMessages']=function(_0xcd0c40,_0x5daffe,_0xd56b9d){var _0x56ff87={'raw':![],'where':{}};var _0x5e6c81={};var _0x50444b={'count':0x0,'rows':[]};return db[_0xb02f('0x31')][_0xb02f('0xb4')]({'where':{'id':_0xcd0c40['params']['id']}})[_0xb02f('0x26')](handleEntityNotFound(_0x5daffe,null))['then'](function(_0x39f1f5){if(_0x39f1f5){_0x5e6c81[_0xb02f('0x37')]=_['keys'](db['OpenchannelMessage'][_0xb02f('0x32')]);_0x5e6c81[_0xb02f('0x34')]=_[_0xb02f('0x35')](_0xcd0c40[_0xb02f('0x34')]);_0x5e6c81[_0xb02f('0x3e')]=_[_0xb02f('0x36')](_0x5e6c81[_0xb02f('0x37')],_0x5e6c81[_0xb02f('0x34')]);_0x56ff87['attributes']=_['intersection'](_0x5e6c81[_0xb02f('0x37')],qs[_0xb02f('0x93')](_0xcd0c40['query'][_0xb02f('0x93')]));_0x56ff87[_0xb02f('0x38')]=_0x56ff87[_0xb02f('0x38')][_0xb02f('0x39')]?_0x56ff87[_0xb02f('0x38')]:_0x5e6c81[_0xb02f('0x37')];if(!_0xcd0c40[_0xb02f('0x34')][_0xb02f('0x3a')](_0xb02f('0x3b'))){_0x56ff87[_0xb02f('0x21')]=qs[_0xb02f('0x21')](_0xcd0c40[_0xb02f('0x34')][_0xb02f('0x21')]);_0x56ff87[_0xb02f('0x20')]=qs[_0xb02f('0x20')](_0xcd0c40['query']['offset']);}_0x56ff87[_0xb02f('0x88')]=qs[_0xb02f('0x3c')](_0xcd0c40[_0xb02f('0x34')][_0xb02f('0x3c')]);_0x56ff87[_0xb02f('0x3d')]=qs[_0xb02f('0x3e')](_[_0xb02f('0x3f')](_0xcd0c40[_0xb02f('0x34')],_0x5e6c81[_0xb02f('0x3e')]));_0x56ff87[_0xb02f('0x3d')][_0xb02f('0xb5')]=_0x39f1f5['id'];if(_0xcd0c40['query'][_0xb02f('0x7c')]){_0x56ff87[_0xb02f('0x3d')]=_['merge'](_0x56ff87[_0xb02f('0x3d')],{'$or':_[_0xb02f('0x2a')](_0x56ff87['attributes'],function(_0x10b022){var _0x56874a={};_0x56874a[_0x10b022]={'$like':'%'+_0xcd0c40['query'][_0xb02f('0x7c')]+'%'};return _0x56874a;})});}if(_0xcd0c40['query'][_0xb02f('0x74')]){var _0x2e0dcd=_0xcd0c40[_0xb02f('0x34')][_0xb02f('0x74')][_0xb02f('0x5f')](',');var _0x107a90={};_0x107a90[_0x2e0dcd[0x0]]={'$gte':moment(_0x2e0dcd[0x1])[_0xb02f('0xb6')]('YYYY-MM-DD\x20HH:mm:ss')};_0x56ff87[_0xb02f('0x3d')]=_['merge'](_0x56ff87['where'],_0x107a90);}_0x56ff87=_[_0xb02f('0x92')]({},_0x56ff87,_0xcd0c40[_0xb02f('0xac')]);return db['OpenchannelMessage'][_0xb02f('0x1f')]({'where':_0x56ff87[_0xb02f('0x3d')]})[_0xb02f('0x26')](function(_0x368805){_0x50444b[_0xb02f('0x1f')]=_0x368805;if(_0xcd0c40[_0xb02f('0x34')][_0xb02f('0xaa')]){_0x56ff87['include']=[{'all':!![]}];}return db[_0xb02f('0xb0')][_0xb02f('0xb7')](_0x56ff87);})['then'](function(_0x25074c){_0x50444b['rows']=_0x25074c;return _0x50444b;});}})['then'](respondWithFilteredResult(_0x5daffe,_0x56ff87))[_0xb02f('0x30')](handleError(_0x5daffe,null));};exports[_0xb02f('0xb8')]=function(_0x1f939c,_0x487491,_0xb1f899){return db[_0xb02f('0x31')]['find']({'where':{'id':_0x1f939c['params']['id']}})[_0xb02f('0x26')](handleEntityNotFound(_0x487491,null))[_0xb02f('0x26')](function(_0x385cbc){if(_0x385cbc){return _0x385cbc[_0xb02f('0xb9')](_0x1f939c['body'][_0xb02f('0xb2')],_[_0xb02f('0xb3')](_0x1f939c[_0xb02f('0x6d')],[_0xb02f('0xb2'),'id'])||{})[_0xb02f('0xba')](function(){return db[_0xb02f('0x65')][_0xb02f('0xb7')]({'attributes':['id',_0xb02f('0x28'),_0xb02f('0x42')],'where':{'id':_0x1f939c[_0xb02f('0x6d')][_0xb02f('0xb2')]}});})['then'](function(_0x512ed2){socket[_0xb02f('0xbb')](_0xb02f('0xbc'),{'id':Number(_0x1f939c[_0xb02f('0xae')]['id']),'tags':_0x512ed2||[]});return{'id':Number(_0x1f939c[_0xb02f('0xae')]['id']),'tags':_0x512ed2||[]};});}})[_0xb02f('0x26')](respondWithResult(_0x487491,null))[_0xb02f('0x30')](handleError(_0x487491,null));};exports[_0xb02f('0xbd')]=function(_0x484f87,_0x27d9cb,_0x2bde7b){return db['OpenchannelInteraction']['find']({'where':{'id':_0x484f87['params']['id']}})['then'](handleEntityNotFound(_0x27d9cb,null))['then'](function(_0x58fc1e){if(_0x58fc1e){return _0x58fc1e[_0xb02f('0xbd')](_0x484f87['query'][_0xb02f('0xb2')]);}})[_0xb02f('0x26')](respondWithStatusCode(_0x27d9cb,null))['catch'](handleError(_0x27d9cb,null));};exports[_0xb02f('0xbe')]=function(_0x3a1ccc,_0x14bc9b){var _0x2729aa=moment()[_0xb02f('0xbf')]()[_0xb02f('0x90')]();var _0x377f3c=path['join'](config[_0xb02f('0xc0')],_0xb02f('0xc1'),'files',_0xb02f('0xc2'));var _0x3718bf=path[_0xb02f('0xc3')](config[_0xb02f('0xc0')],'server',_0xb02f('0xc4'),_0xb02f('0xc5'));var _0x4a0bdf=path[_0xb02f('0xc3')](_0x377f3c,_0x2729aa);var _0x1769ad=util['format'](_0xb02f('0xc6'),_0x3a1ccc[_0xb02f('0xae')]['id'],_0x2729aa);var _0x4f1da2=path[_0xb02f('0xc3')](_0x377f3c,_0x1769ad);var _0x52df41=[];_0x52df41[_0xb02f('0x2f')]({'model':db[_0xb02f('0x67')],'as':_0xb02f('0x67'),'attributes':['id',_0xb02f('0x2b')],'raw':!![]});_0x52df41[_0xb02f('0x2f')]({'model':db[_0xb02f('0xc7')],'as':_0xb02f('0x5c'),'attributes':['id',_0xb02f('0xc8'),'lastName'],'raw':!![]});if(_0x3a1ccc[_0xb02f('0x34')][_0xb02f('0xc5')]){_0x52df41[_0xb02f('0x2f')]({'model':db['Attachment'],'as':_0xb02f('0xc9'),'raw':!![]});}var _0x215f82=[{'model':db[_0xb02f('0xb0')],'as':'Messages','attributes':['id',_0xb02f('0x6d'),'createdAt','direction',_0xb02f('0xca'),'read'],'include':_0x52df41}];_0x215f82[_0xb02f('0x2f')]({'model':db['OpenchannelAccount'],'as':'Account','attributes':['id',_0xb02f('0x28')]});_0x215f82[_0xb02f('0x2f')]({'model':db[_0xb02f('0x67')],'as':_0xb02f('0xcb'),'attributes':['id',_0xb02f('0x2b')]});return db[_0xb02f('0x31')]['find']({'where':{'id':_0x3a1ccc[_0xb02f('0xae')]['id']},'include':_0x215f82})['then'](handleEntityNotFound(_0x14bc9b,null))['then'](function(_0x123f4d){if(_0x123f4d){var _0x40507f=_0x123f4d[_0xb02f('0xcc')]({'plain':!![]});fs[_0xb02f('0xcd')](_0x4a0bdf);var _0x5280e8={'format':'A4','border':'10px','header':{'height':_0xb02f('0xce'),'contents':{'first':_0xb02f('0xcf')}},'footer':{'height':_0xb02f('0xd0'),'contents':{'default':util[_0xb02f('0xb6')](_0xb02f('0xd1'),util[_0xb02f('0xb6')]('%s\x20#%d',_0xb02f('0xd2'),_0x40507f['id']),moment()[_0xb02f('0xb6')](_0xb02f('0xd3'))[_0xb02f('0x90')]())}}};var _0x421450={'channel':_0xb02f('0xd2'),'account':_0x40507f[_0xb02f('0xd4')][_0xb02f('0x28')],'agent':_0x40507f[_0xb02f('0xcb')]?_0x40507f[_0xb02f('0xcb')]['fullname']:_0xb02f('0xd5'),'createdAt':moment(_0x40507f[_0xb02f('0x72')])[_0xb02f('0xb6')](_0xb02f('0xd6'))[_0xb02f('0x90')](),'closedAt':_0x40507f[_0xb02f('0xd7')]?moment(_0x40507f['closedAt'])['format']('YYYY-MM-DD\x20HH:mm:ss')[_0xb02f('0x90')]():'','disposition':_0x40507f[_0xb02f('0xd8')],'visibility':_0x40507f[_0xb02f('0xd9')]?_0xb02f('0xda'):_0xb02f('0xdb'),'messages':_(_0x40507f[_0xb02f('0xdc')])[_0xb02f('0x7c')]({'secret':![]})[_0xb02f('0x2a')](function(_0x349952){if(_0x349952[_0xb02f('0xc9')]){var _0x2fbbf0=path['join'](_0x3718bf,_0x349952[_0xb02f('0xc9')][_0xb02f('0xdd')]);if(fs['existsSync'](_0x2fbbf0)){fs[_0xb02f('0xde')](_0x2fbbf0)[_0xb02f('0xdf')](fs['createWriteStream'](path[_0xb02f('0xc3')](_0x4a0bdf,_0x349952[_0xb02f('0xc9')][_0xb02f('0xdd')])));}}return{'date':moment(_0x349952['createdAt'])['format'](_0xb02f('0xd6'))['toString'](),'sender':_0x349952[_0xb02f('0xe0')]===_0xb02f('0xe1')?_0x349952[_0xb02f('0x67')]?_0x349952['User']['fullname']:_0xb02f('0xe2'):_0x349952['Contact'][_0xb02f('0xc8')]+(_0x349952[_0xb02f('0x5c')]['lastName']?'\x20'+_0x349952[_0xb02f('0x5c')][_0xb02f('0xe3')]:''),'body':_0x349952['Attachment']?_0x349952[_0xb02f('0xc9')][_0xb02f('0xdd')]:_0x349952['body'],'direction':_0x349952[_0xb02f('0xe0')]===_0xb02f('0xe1')?'A':'C','secret':_0x349952['secret'],'read':_0x349952[_0xb02f('0x79')],'attachment':_0x349952[_0xb02f('0xc9')]};})[_0xb02f('0x5e')]()};return ejs[_0xb02f('0xe4')](path['join'](config['root'],'server','views',_0xb02f('0xe5')),{'interaction':_0x421450})[_0xb02f('0x26')](function(_0x30cb4a){return new BPromise(function(_0x222f22,_0x13966c){pdf[_0xb02f('0xad')](_0x30cb4a,_0x5280e8)['toFile'](path[_0xb02f('0xc3')](_0x4a0bdf,_0xb02f('0xe6')+_0x40507f['id']+'-'+_0x2729aa+_0xb02f('0xe7')),function(_0x43cb3c,_0x51eeb1){if(_0x43cb3c)return _0x13966c(_0x43cb3c);_0x222f22(_0x51eeb1);});});})[_0xb02f('0x26')](function(){return new BPromise(function(_0x44306a,_0x4a9908){zipdir(_0x4a0bdf,{'saveTo':_0x4f1da2},function(_0x3a6bbd,_0xa17efe){if(_0x3a6bbd)return _0x4a9908(_0x3a6bbd);return _0x44306a(_0xa17efe);});})[_0xb02f('0x26')](function(){return new BPromise(function(_0x52ba36,_0x273417){rimraf(_0x4a0bdf,function(_0x474624){if(_0x474624)_0x273417(_0x474624);return _0x52ba36();});});})[_0xb02f('0x26')](function(){return _0x14bc9b[_0xb02f('0xbe')](_0x4f1da2,_0x1769ad,function(_0x55dae1){if(_0x55dae1){console['log'](_0xb02f('0xe8'),_0x55dae1);}else{fs[_0xb02f('0xe9')](_0x4f1da2);}});});});}else{return _0x14bc9b['sendStatus'](0xc8);}})[_0xb02f('0x30')](handleError(_0x14bc9b,null));};
\ No newline at end of file
+var _0x6215=['tmp','attachments','transcript-%d-%s.zip','push','User','fullname','CmContact','Contact','firstName','lastName','Attachment','Messages','secret','read','Account','Owner','get','mkdirSync','Openchannel','N.A.','createdAt','YYYY-MM-DD\x20HH:mm:ss','toString','Public','Private','basename','existsSync','createReadStream','createWriteStream','direction','System','out','value','views','transcript-','.pdf','createPdfFromHTML','Unable\x20to\x20delete\x20zip\x20file','unlinkSync','zip-dir','util','path','ejs','lodash','../../components/interaction/service','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./openchannelInteraction.socket','register','sendStatus','status','end','json','offset','undefined','limit','count','update','then','destroy','error','stack','name','send','index','OpenchannelInteraction','findAll','openchannel','query','catch','show','params','model','rawAttributes','filters','intersection','fields','attributes','length','include','merge','options','create','body','find','describe','OpenchannelMessage','addMessage','omit','ids','findOne','hasOwnProperty','order','sort','where','pick','OpenchannelInteractionId','filter','map','$gte','split','format','addTags','setTags','spread','Tag','color','emit','removeTags','download','join','root','server','files'];(function(_0x1de511,_0x3763b9){var _0xdee9e4=function(_0x2260ea){while(--_0x2260ea){_0x1de511['push'](_0x1de511['shift']());}};_0xdee9e4(++_0x3763b9);}(_0x6215,0x119));var _0x5621=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x6215[_0x3dd15e];return _0x231fd0;};'use strict';var rimraf=require('rimraf');var zipdir=require(_0x5621('0x0'));var moment=require('moment');var util=require(_0x5621('0x1'));var path=require(_0x5621('0x2'));var ejs=require(_0x5621('0x3'));var fs=require('fs');var _=require(_0x5621('0x4'));var Redis=require('ioredis');var interaction=require(_0x5621('0x5'));var qs=require(_0x5621('0x6'));var pdf=require('../../components/export/pdf');var logger=require(_0x5621('0x7'))(_0x5621('0x8'));var config=require(_0x5621('0x9'));var db=require(_0x5621('0xa'))['db'];config[_0x5621('0xb')]=_[_0x5621('0xc')](config['redis'],{'host':_0x5621('0xd'),'port':0x18eb});var socket=require(_0x5621('0xe'))(new Redis(config[_0x5621('0xb')]));require(_0x5621('0xf'))[_0x5621('0x10')](socket);function respondWithStatusCode(_0x57ccae,_0xf5e389){_0xf5e389=_0xf5e389||0xcc;return function(_0x4cfb95){if(_0x4cfb95){return _0x57ccae[_0x5621('0x11')](_0xf5e389);}return _0x57ccae[_0x5621('0x12')](_0xf5e389)[_0x5621('0x13')]();};}function respondWithResult(_0xfc032c,_0x50ffd0){_0x50ffd0=_0x50ffd0||0xc8;return function(_0x3e59db){if(_0x3e59db){return _0xfc032c[_0x5621('0x12')](_0x50ffd0)[_0x5621('0x14')](_0x3e59db);}};}function respondWithFilteredResult(_0x46b591,_0xf00432){return function(_0x5905c4){if(_0x5905c4){var _0x40ee84=typeof _0xf00432[_0x5621('0x15')]===_0x5621('0x16')&&typeof _0xf00432[_0x5621('0x17')]==='undefined';var _0x17ac2f=_0x5905c4[_0x5621('0x18')];var _0x16fc45=_0x40ee84?0x0:_0xf00432[_0x5621('0x15')];var _0x504807=_0x40ee84?_0x5905c4[_0x5621('0x18')]:_0xf00432[_0x5621('0x15')]+_0xf00432[_0x5621('0x17')];var _0x56ddba;if(_0x504807>=_0x17ac2f){_0x504807=_0x17ac2f;_0x56ddba=0xc8;}else{_0x56ddba=0xce;}_0x46b591[_0x5621('0x12')](_0x56ddba);return _0x46b591['set']('Content-Range',_0x16fc45+'-'+_0x504807+'/'+_0x17ac2f)[_0x5621('0x14')](_0x5905c4);}return null;};}function saveUpdates(_0x2b484f){return function(_0x2f8764){if(_0x2f8764){return _0x2f8764[_0x5621('0x19')](_0x2b484f)[_0x5621('0x1a')](function(_0x50afc1){return _0x50afc1;});}return null;};}function removeEntity(_0x3d33d2){return function(_0x1bd37f){if(_0x1bd37f){return _0x1bd37f[_0x5621('0x1b')]()[_0x5621('0x1a')](function(){_0x3d33d2[_0x5621('0x12')](0xcc)[_0x5621('0x13')]();});}};}function handleEntityNotFound(_0x332353){return function(_0x1cb840){if(!_0x1cb840){_0x332353[_0x5621('0x11')](0x194);}return _0x1cb840;};}function handleError(_0x5345bd,_0x54496d){_0x54496d=_0x54496d||0x1f4;return function(_0x20d508){logger[_0x5621('0x1c')](_0x20d508[_0x5621('0x1d')]);if(_0x20d508[_0x5621('0x1e')]){delete _0x20d508[_0x5621('0x1e')];}_0x5345bd[_0x5621('0x12')](_0x54496d)[_0x5621('0x1f')](_0x20d508);};}exports[_0x5621('0x20')]=function(_0x40701b,_0x153efb){var _0x50ff2a={};var _0x520559=_['map'](db[_0x5621('0x21')]['rawAttributes'],function(_0x584484){return{'name':_0x584484['fieldName'],'type':_0x584484['type']['key']};});_0x50ff2a=qs['getOptions'](_0x520559,_0x40701b);return interaction[_0x5621('0x22')](_0x5621('0x23'),_0x40701b[_0x5621('0x24')],_0x40701b['user'],_0x50ff2a,_0x520559)[_0x5621('0x1a')](respondWithFilteredResult(_0x153efb,_0x50ff2a))[_0x5621('0x25')](handleError(_0x153efb,null));};exports[_0x5621('0x26')]=function(_0x293e78,_0x462856){var _0x29904d={};if(_0x293e78[_0x5621('0x24')]['type']&&_0x293e78['query']['type']==='from'){_0x29904d['from']=_0x293e78[_0x5621('0x27')]['id'];}else{_0x29904d['id']=_0x293e78[_0x5621('0x27')]['id'];}var _0xcd22fb={'raw':![],'where':_0x29904d},_0x20d3a4={};_0x20d3a4[_0x5621('0x28')]=_['keys'](db[_0x5621('0x21')][_0x5621('0x29')]);_0x20d3a4['query']=_['keys'](_0x293e78[_0x5621('0x24')]);_0x20d3a4[_0x5621('0x2a')]=_['intersection'](_0x20d3a4[_0x5621('0x28')],_0x20d3a4['query']);_0xcd22fb['attributes']=_[_0x5621('0x2b')](_0x20d3a4[_0x5621('0x28')],qs['fields'](_0x293e78['query'][_0x5621('0x2c')]));_0xcd22fb[_0x5621('0x2d')]=_0xcd22fb[_0x5621('0x2d')][_0x5621('0x2e')]?_0xcd22fb[_0x5621('0x2d')]:_0x20d3a4[_0x5621('0x28')];if(_0x293e78[_0x5621('0x24')]['includeAll']){_0xcd22fb[_0x5621('0x2f')]=[{'all':!![]}];}_0xcd22fb=_[_0x5621('0x30')]({},_0xcd22fb,_0x293e78[_0x5621('0x31')]);return db['OpenchannelInteraction']['find'](_0xcd22fb)['then'](handleEntityNotFound(_0x462856,null))[_0x5621('0x1a')](respondWithResult(_0x462856,null))[_0x5621('0x25')](handleError(_0x462856,null));};exports[_0x5621('0x32')]=function(_0x5093d6,_0x2aa3e0){return db[_0x5621('0x21')]['create'](_0x5093d6[_0x5621('0x33')],{})[_0x5621('0x1a')](respondWithResult(_0x2aa3e0,0xc9))[_0x5621('0x25')](handleError(_0x2aa3e0,null));};exports[_0x5621('0x19')]=function(_0x2d99f2,_0x55f212){if(_0x2d99f2[_0x5621('0x33')]['id']){delete _0x2d99f2[_0x5621('0x33')]['id'];}return db[_0x5621('0x21')][_0x5621('0x34')]({'where':{'id':_0x2d99f2['params']['id']}})[_0x5621('0x1a')](handleEntityNotFound(_0x55f212,null))[_0x5621('0x1a')](saveUpdates(_0x2d99f2[_0x5621('0x33')],null))[_0x5621('0x1a')](respondWithResult(_0x55f212,null))[_0x5621('0x25')](handleError(_0x55f212,null));};exports['destroy']=function(_0x274c9b,_0xb14c37){return db[_0x5621('0x21')][_0x5621('0x34')]({'where':{'id':_0x274c9b[_0x5621('0x27')]['id']}})[_0x5621('0x1a')](handleEntityNotFound(_0xb14c37,null))[_0x5621('0x1a')](removeEntity(_0xb14c37,null))['catch'](handleError(_0xb14c37,null));};exports[_0x5621('0x35')]=function(_0x4e1172,_0x3d62e6){return db[_0x5621('0x21')][_0x5621('0x35')]()['then'](respondWithResult(_0x3d62e6,null))['catch'](handleError(_0x3d62e6,null));};exports['addMessage']=function(_0x545364,_0xb53e47){return db[_0x5621('0x36')][_0x5621('0x34')]({'where':{'id':_0x545364[_0x5621('0x27')]['id']}})[_0x5621('0x1a')](handleEntityNotFound(_0xb53e47,null))[_0x5621('0x1a')](function(_0x4f6834){if(_0x4f6834){return _0x4f6834[_0x5621('0x37')](_0x545364[_0x5621('0x33')]['ids'],_[_0x5621('0x38')](_0x545364['body'],[_0x5621('0x39'),'id'])||{});}})[_0x5621('0x1a')](respondWithResult(_0xb53e47,null))['catch'](handleError(_0xb53e47,null));};exports['getMessages']=function(_0x146167,_0x3de0ad){var _0x2834e8={'raw':![],'where':{}};var _0x5ccf95={};var _0x102c3a={'count':0x0,'rows':[]};return db[_0x5621('0x21')][_0x5621('0x3a')]({'where':{'id':_0x146167['params']['id']}})[_0x5621('0x1a')](handleEntityNotFound(_0x3de0ad,null))[_0x5621('0x1a')](function(_0x3b8059){if(_0x3b8059){_0x5ccf95[_0x5621('0x28')]=_['keys'](db[_0x5621('0x36')]['rawAttributes']);_0x5ccf95[_0x5621('0x24')]=_['keys'](_0x146167[_0x5621('0x24')]);_0x5ccf95[_0x5621('0x2a')]=_[_0x5621('0x2b')](_0x5ccf95[_0x5621('0x28')],_0x5ccf95['query']);_0x2834e8[_0x5621('0x2d')]=_['intersection'](_0x5ccf95[_0x5621('0x28')],qs[_0x5621('0x2c')](_0x146167[_0x5621('0x24')][_0x5621('0x2c')]));_0x2834e8[_0x5621('0x2d')]=_0x2834e8[_0x5621('0x2d')][_0x5621('0x2e')]?_0x2834e8[_0x5621('0x2d')]:_0x5ccf95['model'];if(!_0x146167[_0x5621('0x24')][_0x5621('0x3b')]('nolimit')){_0x2834e8[_0x5621('0x17')]=qs[_0x5621('0x17')](_0x146167[_0x5621('0x24')]['limit']);_0x2834e8[_0x5621('0x15')]=qs[_0x5621('0x15')](_0x146167[_0x5621('0x24')][_0x5621('0x15')]);}_0x2834e8[_0x5621('0x3c')]=qs[_0x5621('0x3d')](_0x146167['query']['sort']);_0x2834e8[_0x5621('0x3e')]=qs[_0x5621('0x2a')](_[_0x5621('0x3f')](_0x146167['query'],_0x5ccf95['filters']));_0x2834e8[_0x5621('0x3e')][_0x5621('0x40')]=_0x3b8059['id'];if(_0x146167['query'][_0x5621('0x41')]){_0x2834e8[_0x5621('0x3e')]=_['merge'](_0x2834e8['where'],{'$or':_[_0x5621('0x42')](_0x2834e8['attributes'],function(_0x4e332c){var _0x3c41b3={};_0x3c41b3[_0x4e332c]={'$like':'%'+_0x146167[_0x5621('0x24')]['filter']+'%'};return _0x3c41b3;})});}if(_0x146167['query']['$gte']){var _0x1dd009=_0x146167[_0x5621('0x24')][_0x5621('0x43')][_0x5621('0x44')](',');var _0x26b08f={};_0x26b08f[_0x1dd009[0x0]]={'$gte':moment(_0x1dd009[0x1])[_0x5621('0x45')]('YYYY-MM-DD\x20HH:mm:ss')};_0x2834e8['where']=_[_0x5621('0x30')](_0x2834e8[_0x5621('0x3e')],_0x26b08f);}_0x2834e8=_[_0x5621('0x30')]({},_0x2834e8,_0x146167[_0x5621('0x31')]);return db[_0x5621('0x36')][_0x5621('0x18')]({'where':_0x2834e8[_0x5621('0x3e')]})[_0x5621('0x1a')](function(_0x279c84){_0x102c3a[_0x5621('0x18')]=_0x279c84;if(_0x146167[_0x5621('0x24')]['includeAll']){_0x2834e8[_0x5621('0x2f')]=[{'all':!![]}];}return db[_0x5621('0x36')][_0x5621('0x22')](_0x2834e8);})[_0x5621('0x1a')](function(_0xf0142e){_0x102c3a['rows']=_0xf0142e;return _0x102c3a;});}})['then'](respondWithFilteredResult(_0x3de0ad,_0x2834e8))[_0x5621('0x25')](handleError(_0x3de0ad,null));};exports[_0x5621('0x46')]=function(_0x410e8a,_0x2c6131){return db[_0x5621('0x21')][_0x5621('0x34')]({'where':{'id':_0x410e8a['params']['id']}})['then'](handleEntityNotFound(_0x2c6131,null))[_0x5621('0x1a')](function(_0x2f946d){if(_0x2f946d){return _0x2f946d[_0x5621('0x47')](_0x410e8a['body']['ids'],_[_0x5621('0x38')](_0x410e8a[_0x5621('0x33')],[_0x5621('0x39'),'id'])||{})[_0x5621('0x48')](function(){return db[_0x5621('0x49')][_0x5621('0x22')]({'attributes':['id',_0x5621('0x1e'),_0x5621('0x4a')],'where':{'id':_0x410e8a['body'][_0x5621('0x39')]}});})['then'](function(_0x37081f){socket[_0x5621('0x4b')]('openchannelInteractionTags:save',{'id':Number(_0x410e8a[_0x5621('0x27')]['id']),'tags':_0x37081f||[]});return{'id':Number(_0x410e8a[_0x5621('0x27')]['id']),'tags':_0x37081f||[]};});}})[_0x5621('0x1a')](respondWithResult(_0x2c6131,null))[_0x5621('0x25')](handleError(_0x2c6131,null));};exports[_0x5621('0x4c')]=function(_0x2841c0,_0xbfdceb){return db[_0x5621('0x21')]['find']({'where':{'id':_0x2841c0[_0x5621('0x27')]['id']}})['then'](handleEntityNotFound(_0xbfdceb,null))[_0x5621('0x1a')](function(_0x24ff20){if(_0x24ff20){return _0x24ff20['removeTags'](_0x2841c0['query']['ids']);}})[_0x5621('0x1a')](respondWithStatusCode(_0xbfdceb,null))[_0x5621('0x25')](handleError(_0xbfdceb,null));};exports[_0x5621('0x4d')]=function(_0x46b92b,_0x12b6db){var _0x4ed883=moment()['unix']()['toString']();var _0x6f901a=path[_0x5621('0x4e')](config[_0x5621('0x4f')],_0x5621('0x50'),_0x5621('0x51'),_0x5621('0x52'));var _0x46f8a9=path[_0x5621('0x4e')](config[_0x5621('0x4f')],_0x5621('0x50'),_0x5621('0x51'),_0x5621('0x53'));var _0xad63df=path[_0x5621('0x4e')](_0x6f901a,_0x4ed883);var _0x15b6a0=util[_0x5621('0x45')](_0x5621('0x54'),_0x46b92b[_0x5621('0x27')]['id'],_0x4ed883);var _0x3bacc9=path['join'](_0x6f901a,_0x15b6a0);var _0x13c72c=[];_0x13c72c[_0x5621('0x55')]({'model':db[_0x5621('0x56')],'as':_0x5621('0x56'),'attributes':['id',_0x5621('0x57')],'raw':!![]});_0x13c72c[_0x5621('0x55')]({'model':db[_0x5621('0x58')],'as':_0x5621('0x59'),'attributes':['id',_0x5621('0x5a'),_0x5621('0x5b')],'raw':!![]});if(_0x46b92b[_0x5621('0x24')][_0x5621('0x53')]){_0x13c72c[_0x5621('0x55')]({'model':db[_0x5621('0x5c')],'as':'Attachment','raw':!![]});}var _0x4feb05=[{'model':db[_0x5621('0x36')],'as':_0x5621('0x5d'),'attributes':['id','body','createdAt','direction',_0x5621('0x5e'),_0x5621('0x5f')],'include':_0x13c72c}];_0x4feb05[_0x5621('0x55')]({'model':db['OpenchannelAccount'],'as':_0x5621('0x60'),'attributes':['id','name']});_0x4feb05[_0x5621('0x55')]({'model':db[_0x5621('0x56')],'as':_0x5621('0x61'),'attributes':['id',_0x5621('0x57')]});return db['OpenchannelInteraction'][_0x5621('0x34')]({'where':{'id':_0x46b92b[_0x5621('0x27')]['id']},'include':_0x4feb05})['then'](handleEntityNotFound(_0x12b6db,null))[_0x5621('0x1a')](function(_0x4b71c9){if(_0x4b71c9){var _0x381ffa=_0x4b71c9[_0x5621('0x62')]({'plain':!![]});fs[_0x5621('0x63')](_0xad63df);var _0x210dd1={'channel':_0x5621('0x64'),'account':_0x381ffa['Account']['name'],'agent':_0x381ffa['Owner']?_0x381ffa[_0x5621('0x61')][_0x5621('0x57')]:_0x5621('0x65'),'createdAt':moment(_0x381ffa[_0x5621('0x66')])[_0x5621('0x45')](_0x5621('0x67'))[_0x5621('0x68')](),'closedAt':_0x381ffa['closed']?moment(_0x381ffa['closedAt'])[_0x5621('0x45')](_0x5621('0x67'))['toString']():'','disposition':_0x381ffa['disposition'],'visibility':_0x381ffa['threadId']?_0x5621('0x69'):_0x5621('0x6a'),'messages':_(_0x381ffa[_0x5621('0x5d')])['filter']({'secret':![]})[_0x5621('0x42')](function(_0x36c4d0){if(_0x36c4d0[_0x5621('0x5c')]){var _0xacda22=path[_0x5621('0x4e')](_0x46f8a9,_0x36c4d0[_0x5621('0x5c')][_0x5621('0x6b')]);if(fs[_0x5621('0x6c')](_0xacda22)){fs[_0x5621('0x6d')](_0xacda22)['pipe'](fs[_0x5621('0x6e')](path[_0x5621('0x4e')](_0xad63df,_0x36c4d0[_0x5621('0x5c')][_0x5621('0x6b')])));}}return{'date':moment(_0x36c4d0[_0x5621('0x66')])[_0x5621('0x45')](_0x5621('0x67'))['toString'](),'sender':_0x36c4d0[_0x5621('0x6f')]==='out'?_0x36c4d0[_0x5621('0x56')]?_0x36c4d0[_0x5621('0x56')]['fullname']:_0x5621('0x70'):_0x36c4d0[_0x5621('0x59')][_0x5621('0x5a')]+(_0x36c4d0[_0x5621('0x59')][_0x5621('0x5b')]?'\x20'+_0x36c4d0['Contact'][_0x5621('0x5b')]:''),'body':_0x36c4d0['Attachment']?_0x36c4d0[_0x5621('0x5c')][_0x5621('0x6b')]:_0x36c4d0[_0x5621('0x33')],'direction':_0x36c4d0[_0x5621('0x6f')]===_0x5621('0x71')?'A':'C','secret':_0x36c4d0[_0x5621('0x5e')],'read':_0x36c4d0[_0x5621('0x5f')],'attachment':_0x36c4d0['Attachment']};})[_0x5621('0x72')]()};return ejs['renderFile'](path[_0x5621('0x4e')](config[_0x5621('0x4f')],_0x5621('0x50'),_0x5621('0x73'),'downloadInteraction.ejs'),{'interaction':_0x210dd1})['then'](function(_0xcc4822){var _0x5bda79=path[_0x5621('0x4e')](_0xad63df,_0x5621('0x74')+_0x381ffa['id']+'-'+_0x4ed883+_0x5621('0x75'));var _0x476877={'path':_0x5bda79,'channel':_0x5621('0x64'),'interactionId':_0x381ffa['id']};return pdf[_0x5621('0x76')](_0xcc4822,_0x476877);})['then'](function(){return new Promise(function(_0x2a651e,_0x15ccb9){zipdir(_0xad63df,{'saveTo':_0x3bacc9},function(_0x48cdbe,_0x241ac8){if(_0x48cdbe)return _0x15ccb9(_0x48cdbe);return _0x2a651e(_0x241ac8);});})[_0x5621('0x1a')](function(){return new Promise(function(_0x3f409c,_0x34e50c){rimraf(_0xad63df,function(_0x214116){if(_0x214116)_0x34e50c(_0x214116);return _0x3f409c();});});})[_0x5621('0x1a')](function(){return _0x12b6db[_0x5621('0x4d')](_0x3bacc9,_0x15b6a0,function(_0x3eefc9){if(_0x3eefc9){logger[_0x5621('0x1c')](_0x5621('0x77'),_0x3eefc9);}else{fs[_0x5621('0x78')](_0x3bacc9);}});});});}else{return _0x12b6db[_0x5621('0x11')](0xc8);}})[_0x5621('0x25')](handleError(_0x12b6db,null));};
\ No newline at end of file