Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / api / openchannelInteraction / openchannelInteraction.controller.js
index 526249c..267ff56 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 _0xaff5=['key','model','query','filters','intersection','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','field','color','from','select','u.fullname','user_has_openchannel_interactions','left_join','users','openchannel_interactions','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','openchannel_accounts','a.id\x20=\x20i.OpenchannelAccountId','t.id\x20=\x20it.TagId','expr','search','parseSearch','conditions','unreadMessages','value','having','`\x20>\x200','Contact','operator','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','find','ContactId','buildExpression','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','text','body','keys','some','compact','isEmpty','OpenchannelAccountId','concat','createdAt','$gte','parse','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','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?','i.id','Sequelize','QueryTypes','SELECT','clone','contactName','DESC','i.OpenchannelAccountId\x20IS\x20NOT\x20NULL','role','user','getOpenchannelAccounts','i.OpenchannelAccountId\x20IS\x20NULL','i.OpenchannelAccountId\x20IN\x20?','agent','toString','sequelize','merge','a.key','Account.key','a.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','c.firstName','Contact.lastName','c.email','c.phone','Contact.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.OpenchannelInteractionId\x20IN\x20?','groupBy','all','params','OpenchannelInteraction','fields','includeAll','include','options','create','describe','addMessage','OpenchannelMessage','ids','omit','getMessages','findOne','OpenchannelInteractionId','format','YYYY-MM-DD\x20HH:mm:ss','findAll','rows','addTags','setTags','spread','emit','openchannelInteractionTags:save','removeTags','download','unix','join','root','tmp','server','files','transcript-%d-%s.zip','fullname','firstName','lastName','Attachment','direction','secret','OpenchannelAccount','Account','Owner','get','mkdirSync','Openchannel','N.A.','closed','disposition','threadId','Public','Private','Messages','existsSync','createReadStream','pipe','createWriteStream','basename','out','System','renderFile','views','downloadInteraction.html','transcript-','.pdf','createPdfFromHTML','log','err','unlinkSync','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./openchannelInteraction.socket','register','sendStatus','end','json','offset','undefined','count','limit','status','set','apply','reject','save','update','then','destroy','stack','name','send','Users','map','TagIds','split','forEach','Tags','push','catch','index','rawAttributes','fieldName','type'];(function(_0x381137,_0x42f10a){var _0x2982b4=function(_0x248d10){while(--_0x248d10){_0x381137['push'](_0x381137['shift']());}};_0x2982b4(++_0x42f10a);}(_0xaff5,0x1a4));var _0x5aff=function(_0x286d1a,_0x15b34f){_0x286d1a=_0x286d1a-0x0;var _0x2977f9=_0xaff5[_0x286d1a];return _0x2977f9;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x5aff('0x0'));var zipdir=require(_0x5aff('0x1'));var jsonpatch=require(_0x5aff('0x2'));var rp=require('request-promise');var moment=require(_0x5aff('0x3'));var BPromise=require(_0x5aff('0x4'));var Mustache=require(_0x5aff('0x5'));var util=require(_0x5aff('0x6'));var path=require(_0x5aff('0x7'));var sox=require(_0x5aff('0x8'));var csv=require(_0x5aff('0x9'));var ejs=require(_0x5aff('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x5aff('0xb'));var squel=require(_0x5aff('0xc'));var crypto=require(_0x5aff('0xd'));var jsforce=require(_0x5aff('0xe'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x5aff('0xf'));var qs=require(_0x5aff('0x10'));var as=require(_0x5aff('0x11'));var pdf=require('../../components/export/pdf');var hardwareService=require(_0x5aff('0x12'));var logger=require(_0x5aff('0x13'))(_0x5aff('0x14'));var utils=require(_0x5aff('0x15'));var config=require(_0x5aff('0x16'));var licenseUtil=require(_0x5aff('0x17'));var db=require('../../mysqldb')['db'];config[_0x5aff('0x18')]=_[_0x5aff('0x19')](config[_0x5aff('0x18')],{'host':_0x5aff('0x1a'),'port':0x18eb});var socket=require(_0x5aff('0x1b'))(new Redis(config[_0x5aff('0x18')]));require(_0x5aff('0x1c'))[_0x5aff('0x1d')](socket);function respondWithStatusCode(_0x14d09e,_0x12d6fd){_0x12d6fd=_0x12d6fd||0xcc;return function(_0x58fff5){if(_0x58fff5){return _0x14d09e[_0x5aff('0x1e')](_0x12d6fd);}return _0x14d09e['status'](_0x12d6fd)[_0x5aff('0x1f')]();};}function respondWithResult(_0x44f97b,_0x41d5fb){_0x41d5fb=_0x41d5fb||0xc8;return function(_0x3eb95b){if(_0x3eb95b){return _0x44f97b['status'](_0x41d5fb)[_0x5aff('0x20')](_0x3eb95b);}};}function respondWithFilteredResult(_0x2c7547,_0x86fb93){return function(_0x12fb5b){if(_0x12fb5b){var _0x49c93c=typeof _0x86fb93[_0x5aff('0x21')]==='undefined'&&typeof _0x86fb93['limit']===_0x5aff('0x22');var _0x33f9b6=_0x12fb5b[_0x5aff('0x23')];var _0x26f693=_0x49c93c?0x0:_0x86fb93[_0x5aff('0x21')];var _0x190958=_0x49c93c?_0x12fb5b['count']:_0x86fb93[_0x5aff('0x21')]+_0x86fb93[_0x5aff('0x24')];var _0x1c243f;if(_0x190958>=_0x33f9b6){_0x190958=_0x33f9b6;_0x1c243f=0xc8;}else{_0x1c243f=0xce;}_0x2c7547[_0x5aff('0x25')](_0x1c243f);return _0x2c7547[_0x5aff('0x26')]('Content-Range',_0x26f693+'-'+_0x190958+'/'+_0x33f9b6)[_0x5aff('0x20')](_0x12fb5b);}return null;};}function patchUpdates(_0xf844a7){return function(_0x51cc33){try{jsonpatch[_0x5aff('0x27')](_0x51cc33,_0xf844a7,!![]);}catch(_0x5e2ce2){return BPromise[_0x5aff('0x28')](_0x5e2ce2);}return _0x51cc33[_0x5aff('0x29')]();};}function saveUpdates(_0x47f342,_0x145b01){return function(_0x3ae676){if(_0x3ae676){return _0x3ae676[_0x5aff('0x2a')](_0x47f342)[_0x5aff('0x2b')](function(_0x2020ce){return _0x2020ce;});}return null;};}function removeEntity(_0x3d588e,_0x174b12){return function(_0x35ee9f){if(_0x35ee9f){return _0x35ee9f[_0x5aff('0x2c')]()[_0x5aff('0x2b')](function(){_0x3d588e[_0x5aff('0x25')](0xcc)[_0x5aff('0x1f')]();});}};}function handleEntityNotFound(_0x239416,_0x39bc5e){return function(_0x324432){if(!_0x324432){_0x239416['sendStatus'](0x194);}return _0x324432;};}function handleError(_0x4bfffb,_0x2bc3f3){_0x2bc3f3=_0x2bc3f3||0x1f4;return function(_0xbfc9f8){logger['error'](_0xbfc9f8[_0x5aff('0x2d')]);if(_0xbfc9f8[_0x5aff('0x2e')]){delete _0xbfc9f8[_0x5aff('0x2e')];}_0x4bfffb['status'](_0x2bc3f3)[_0x5aff('0x2f')](_0xbfc9f8);};}function getInteractionUsers(_0x1d2af6,_0x11b10c){return new BPromise(function(_0x1a2471,_0x34a93f){try{if(_0x11b10c[_0x1d2af6['id']]){_0x1d2af6[_0x5aff('0x30')]=_[_0x5aff('0x31')](_0x11b10c[_0x1d2af6['id']],function(_0x5b72ff){return{'id':_0x5b72ff['id'],'fullname':_0x5b72ff['fullname']};});}}catch(_0x4b61ea){_0x34a93f(_0x4b61ea);}_0x1a2471(_0x1d2af6);});}function getInteractionTags(_0x1835ed,_0x16f8b8){return new BPromise(function(_0x1f066b,_0x24a5d9){try{if(_0x1835ed[_0x5aff('0x32')]){_0x1835ed['Tags']=[];_0x1835ed[_0x5aff('0x32')][_0x5aff('0x33')](',')[_0x5aff('0x34')](function(_0x559b3){_0x1835ed[_0x5aff('0x35')][_0x5aff('0x36')](_0x16f8b8[_0x559b3]);});}delete _0x1835ed[_0x5aff('0x32')];}catch(_0x102588){_0x24a5d9(_0x102588);}_0x1f066b(_0x1835ed);});}function updateOpenchannelInteraction(_0x486e84,_0xfb7591,_0x3c50ea){return new BPromise(function(_0x3f0829,_0x5c7686){return getInteractionUsers(_0x486e84,_0x3c50ea)['then'](function(_0x5ebe41){return getInteractionTags(_0x5ebe41,_0xfb7591);})[_0x5aff('0x2b')](function(_0x37bf5f){_0x3f0829(_0x37bf5f);})[_0x5aff('0x37')](function(_0x2e7d99){_0x5c7686(_0x2e7d99);});});}exports[_0x5aff('0x38')]=function(_0xbd77bc,_0x92de64){var _0x264b0a={},_0x3f2ee={},_0x276428={'count':0x0,'rows':[]};var _0x252b56=_[_0x5aff('0x31')](db['OpenchannelInteraction'][_0x5aff('0x39')],function(_0x19f0cf){return{'name':_0x19f0cf[_0x5aff('0x3a')],'type':_0x19f0cf[_0x5aff('0x3b')][_0x5aff('0x3c')]};});_0x3f2ee[_0x5aff('0x3d')]=_['map'](_0x252b56,_0x5aff('0x2e'));_0x3f2ee[_0x5aff('0x3e')]=_['keys'](_0xbd77bc['query']);_0x3f2ee[_0x5aff('0x3f')]=_[_0x5aff('0x40')](_0x3f2ee['model'],_0x3f2ee[_0x5aff('0x3e')]);_0x264b0a[_0x5aff('0x41')]=_[_0x5aff('0x40')](_0x3f2ee[_0x5aff('0x3d')],qs['fields'](_0xbd77bc[_0x5aff('0x3e')]['fields']));_0x264b0a['attributes']=_0x264b0a[_0x5aff('0x41')][_0x5aff('0x42')]?_0x264b0a[_0x5aff('0x41')]:_0x3f2ee[_0x5aff('0x3d')];if(!_0xbd77bc[_0x5aff('0x3e')][_0x5aff('0x43')](_0x5aff('0x44'))){_0x264b0a[_0x5aff('0x24')]=qs[_0x5aff('0x24')](_0xbd77bc[_0x5aff('0x3e')]['limit']);_0x264b0a[_0x5aff('0x21')]=qs['offset'](_0xbd77bc['query']['offset']);}_0x264b0a[_0x5aff('0x45')]=qs[_0x5aff('0x46')](_0xbd77bc[_0x5aff('0x3e')][_0x5aff('0x46')]);_0x264b0a[_0x5aff('0x47')]=qs[_0x5aff('0x3f')](_[_0x5aff('0x48')](_0xbd77bc[_0x5aff('0x3e')],_0x3f2ee[_0x5aff('0x3f')]),_0x252b56);var _0x3e4057=[];var _0x4ccfd2=squel['select']()['field']('id')[_0x5aff('0x49')](_0x5aff('0x2e'))['field'](_0x5aff('0x4a'))[_0x5aff('0x4b')]('tools_tags');var _0x53f84b=squel[_0x5aff('0x4c')]()['field']('u.id')[_0x5aff('0x49')](_0x5aff('0x4d'))[_0x5aff('0x49')]('ui.OpenchannelInteractionId')['from'](_0x5aff('0x4e'),'ui')[_0x5aff('0x4f')](_0x5aff('0x50'),'u','u.id\x20=\x20ui.UserId');var _0x47f35a=squel[_0x5aff('0x4c')]()[_0x5aff('0x4b')](_0x5aff('0x51'),'i')[_0x5aff('0x4f')]('cm_contacts','c',_0x5aff('0x52'))[_0x5aff('0x4f')](_0x5aff('0x50'),'o',_0x5aff('0x53'))['left_join'](_0x5aff('0x54'),'a',_0x5aff('0x55'))[_0x5aff('0x4f')]('openchannel_messages','me','me.OpenchannelInteractionId\x20=\x20i.id')[_0x5aff('0x4f')]('openchannel_interaction_has_tags','it','it.OpenchannelInteractionId\x20=\x20i.id')['left_join']('tools_tags','t',_0x5aff('0x56'));var _0x2ac198=squel['expr']();var _0x5f4f57=[];var _0x174fcd=squel[_0x5aff('0x57')]();var _0x436908;if(_0xbd77bc['query'][_0x5aff('0x58')]){_0x436908=as[_0x5aff('0x59')](_0xbd77bc[_0x5aff('0x3e')][_0x5aff('0x58')]);var _0x329dc0=_0x436908['sqlOperator'];for(var _0x207721=0x0;_0x207721<_0x436908[_0x5aff('0x5a')]['length'];_0x207721++){var _0x5d544c=_0x436908['conditions'][_0x207721];var _0x3fa4b0='i';var _0x346001=_['find'](_0x252b56,[_0x5aff('0x2e'),_0x5d544c['field']]);if(!_0x346001){switch(_0x5d544c[_0x5aff('0x49')]){case _0x5aff('0x5b'):if(_0x5d544c[_0x5aff('0x5c')]==0x1){_0x47f35a[_0x5aff('0x5d')]('`'+_0x5d544c[_0x5aff('0x49')]+'`\x20=\x200');}else{_0x47f35a[_0x5aff('0x5d')]('`'+_0x5d544c['field']+_0x5aff('0x5e'));}break;case _0x5aff('0x5f'):if(_0x5d544c[_0x5aff('0x60')]==='$substring'){if(_0x5d544c[_0x5aff('0x5c')][_0x5aff('0x33')]('\x20')['length']>0x1){_0x2ac198[_0x329dc0](_0x5aff('0x61'),qs[_0x5aff('0x62')](_0x5d544c['value']),null);}else{var _0x426383='%'+_0x5d544c['value']+'%';_0x2ac198[_0x329dc0]('c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?',_0x426383,_0x426383,_0x426383);}}else{_0x346001=_[_0x5aff('0x63')](_0x252b56,[_0x5aff('0x2e'),'ContactId']);_0x5d544c['field']=_0x5aff('0x64');_0x33bfbd=as[_0x5aff('0x65')](_0x3fa4b0,_0x346001['type'],_0x5d544c);_0x2ac198[_0x329dc0](_0x33bfbd['text'],_0x33bfbd[_0x5aff('0x5c')][_0x5aff('0x66')],_0x33bfbd[_0x5aff('0x5c')][_0x5aff('0x1f')]);}break;case _0x5aff('0x67'):var _0x22c0ec=_0x5d544c[_0x5aff('0x5c')][_0x5aff('0x33')](',')['map'](function(_0x5401d7){return Number(_0x5401d7);});_0x22c0ec[_0x5aff('0x34')](function(_0x2ae168){_0x174fcd['or'](_0x5aff('0x68'),'%,'+_0x2ae168+',%');});_0x5f4f57=_[_0x5aff('0x69')](_0x5f4f57,_0x22c0ec);break;case _0x5aff('0x6a'):if(_0x5d544c[_0x5aff('0x60')]===_0x5aff('0x6b')){_0x2ac198[_0x329dc0](_0x5aff('0x6c'),'%'+_0x5d544c['value']+'%',null);}else{_0x346001=_[_0x5aff('0x63')](_0x252b56,[_0x5aff('0x2e'),'UserId']);_0x5d544c[_0x5aff('0x49')]=_0x5aff('0x6d');_0x33bfbd=as[_0x5aff('0x65')](_0x3fa4b0,_0x346001[_0x5aff('0x3b')],_0x5d544c);_0x2ac198[_0x329dc0](_0x33bfbd[_0x5aff('0x6e')],_0x33bfbd[_0x5aff('0x5c')]['start'],_0x33bfbd[_0x5aff('0x5c')][_0x5aff('0x1f')]);}break;case _0x5aff('0x6f'):_0x33bfbd=as[_0x5aff('0x65')]('me',null,_0x5d544c);_0x2ac198[_0x329dc0](_0x33bfbd[_0x5aff('0x6e')],_0x33bfbd[_0x5aff('0x5c')][_0x5aff('0x66')],_0x33bfbd[_0x5aff('0x5c')][_0x5aff('0x1f')]);break;}}else{var _0x33bfbd=as[_0x5aff('0x65')](_0x3fa4b0,_0x346001[_0x5aff('0x3b')],_0x5d544c);_0x2ac198[_0x329dc0](_0x33bfbd[_0x5aff('0x6e')],_0x33bfbd['value']['start'],_0x33bfbd[_0x5aff('0x5c')][_0x5aff('0x1f')]);}}}else{var _0x1ede36=_(_0xbd77bc[_0x5aff('0x3e')])[_0x5aff('0x70')]()[_0x5aff('0x31')](function(_0x29fab){return _[_0x5aff('0x71')](_0x252b56,[_0x5aff('0x2e'),_0x29fab])?_0x29fab:undefined;})[_0x5aff('0x72')]()['value']();if(!_[_0x5aff('0x73')](_0x1ede36)){_0x1ede36['forEach'](function(_0xb4d56d){if(_0xb4d56d===_0x5aff('0x74')){_0x47f35a[_0x5aff('0x47')]('i.OpenchannelAccountId\x20IN\x20?',[][_0x5aff('0x75')](_0xbd77bc[_0x5aff('0x3e')][_0xb4d56d]));}else if(_0xb4d56d===_0x5aff('0x76')){var _0x64d6c7=JSON['parse'](_0xbd77bc['query'][_0xb4d56d])[_0x5aff('0x77')];var _0x1afe7d=JSON[_0x5aff('0x78')](_0xbd77bc[_0x5aff('0x3e')][_0xb4d56d])['$lte'];_0x47f35a[_0x5aff('0x47')](_0x5aff('0x79'),_0x64d6c7,_0x1afe7d);}else{if(_0xbd77bc[_0x5aff('0x3e')][_0xb4d56d]===_0x5aff('0x7a')){_0x47f35a[_0x5aff('0x47')]('i.'+_0xb4d56d+_0x5aff('0x7b'));}else{_0x47f35a['where']('i.'+_0xb4d56d+'\x20=\x20?',_0xbd77bc[_0x5aff('0x3e')][_0xb4d56d]);}}});}if(_0xbd77bc[_0x5aff('0x3e')]['read']){if(_0xbd77bc[_0x5aff('0x3e')][_0x5aff('0x7c')]==0x1){_0x47f35a[_0x5aff('0x5d')](_0x5aff('0x7d'));}else{_0x47f35a[_0x5aff('0x5d')](_0x5aff('0x7e'));}}if(_0xbd77bc[_0x5aff('0x3e')][_0x5aff('0x7f')]){_0x5f4f57=_[_0x5aff('0x80')](_0xbd77bc[_0x5aff('0x3e')][_0x5aff('0x7f')])?_0xbd77bc[_0x5aff('0x3e')][_0x5aff('0x7f')]:new Array(_0xbd77bc[_0x5aff('0x3e')][_0x5aff('0x7f')]);_0x5f4f57[_0x5aff('0x34')](function(_0x168aad){_0x174fcd['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x168aad+',%');});}if(_0xbd77bc['query'][_0x5aff('0x81')]){var _0x81605b=_0xbd77bc[_0x5aff('0x3e')][_0x5aff('0x81')]['replace']('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs['isNumeric'](_0x81605b)){_0x2ac198['or'](_0x5aff('0x82'),_0x81605b+'%');}else{_0x2ac198['or'](_0x5aff('0x83'),qs['getFullTextValue'](_0x81605b))['or'](_0x5aff('0x84'),_0x81605b+'%')['or'](_0x5aff('0x85'),_0x81605b+'%');}}}_0x47f35a[_0x5aff('0x47')](_0x2ac198);_0x47f35a['group'](_0x5aff('0x86'));var _0xd50d0a={'type':db[_0x5aff('0x87')][_0x5aff('0x88')][_0x5aff('0x89')],'raw':!![]};var _0x4a9bbe=_0x47f35a[_0x5aff('0x8a')]();_0x4a9bbe['field']('i.id');_0x4a9bbe['field']('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x5aff('0x5b'));if(_0x264b0a[_0x5aff('0x45')]){_0x264b0a[_0x5aff('0x45')][_0x5aff('0x34')](function(_0x587dbc){var _0x22fc69=_0x587dbc[0x0]===_0x5aff('0x8b')?_0x587dbc[0x0]:'i.'+_0x587dbc[0x0];_0x47f35a[_0x5aff('0x45')](_0x22fc69,_0x587dbc[0x1]===_0x5aff('0x8c')?![]:!![]);});}if(!_['isEmpty'](_0x5f4f57)){_0x47f35a['having'](_0x174fcd);_0x4a9bbe[_0x5aff('0x47')]('t.id\x20IN\x20?',_0x5f4f57);}BPromise['resolve']()[_0x5aff('0x2b')](function(){if(!_0x436908){if(_0xbd77bc[_0x5aff('0x3e')][_0x5aff('0x74')])return;_0x4a9bbe[_0x5aff('0x47')](_0x5aff('0x8d'));_0x47f35a['where'](_0x5aff('0x8d'));return;}if(_0xbd77bc['user'][_0x5aff('0x8e')]!=='agent')return;return _0xbd77bc[_0x5aff('0x8f')][_0x5aff('0x90')]({'attributes':['id'],'raw':!![]})[_0x5aff('0x2b')](function(_0x9a05e5){if(_[_0x5aff('0x73')](_0x9a05e5)){_0x4a9bbe[_0x5aff('0x47')](_0x5aff('0x91'));_0x47f35a[_0x5aff('0x47')]('i.OpenchannelAccountId\x20IS\x20NULL');}else{_0x4a9bbe[_0x5aff('0x47')](_0x5aff('0x92'),_[_0x5aff('0x31')](_0x9a05e5,'id'));_0x47f35a['where']('i.OpenchannelAccountId\x20IN\x20?',_[_0x5aff('0x31')](_0x9a05e5,'id'));}});})[_0x5aff('0x2b')](function(){if(_0xbd77bc[_0x5aff('0x8f')][_0x5aff('0x8e')]===_0x5aff('0x93')&&!_0x436908&&!_0xbd77bc['query'][_0x5aff('0x74')])return[];return db['sequelize']['query'](_0x4a9bbe[_0x5aff('0x94')](),_0xd50d0a);})[_0x5aff('0x2b')](function(_0x26cd8a){_0x276428[_0x5aff('0x23')]=_0x26cd8a[_0x5aff('0x42')];if(_0x276428['count']===0x0)return[];return db[_0x5aff('0x95')][_0x5aff('0x3e')](_0x4ccfd2[_0x5aff('0x94')](),_0xd50d0a)[_0x5aff('0x2b')](function(_0xb87fcb){_0x3e4057=_['keyBy'](_0xb87fcb,'id');_0xd50d0a=_[_0x5aff('0x96')](_0xd50d0a,{'model':db['OpenchannelInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0xbd77bc[_0x5aff('0x3e')]['fields']){_0x264b0a['attributes'][_0x5aff('0x34')](function(_0x2b9123){_0x47f35a['field']('i.'+_0x2b9123);});}else{_0x47f35a['field']('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages');_0x47f35a[_0x5aff('0x49')](_0x5aff('0x97'),_0x5aff('0x98'));_0x47f35a[_0x5aff('0x49')](_0x5aff('0x99'),'Account.mandatoryDisposition');_0x47f35a[_0x5aff('0x49')](_0x5aff('0x9a'),_0x5aff('0x8b'));_0x47f35a['field']('i.*');_0x47f35a['field'](_0x5aff('0x9b'),'Contact.firstName');_0x47f35a['field']('c.lastName',_0x5aff('0x9c'));_0x47f35a[_0x5aff('0x49')](_0x5aff('0x9d'),'Contact.email');_0x47f35a['field'](_0x5aff('0x9e'),_0x5aff('0x9f'));_0x47f35a[_0x5aff('0x49')](_0x5aff('0xa0'),_0x5aff('0xa1'));_0x47f35a[_0x5aff('0x49')](_0x5aff('0xa2'),_0x5aff('0xa3'));_0x47f35a[_0x5aff('0x49')](_0x5aff('0xa4'),_0x5aff('0xa5'));_0x47f35a[_0x5aff('0x49')](_0x5aff('0xa6'),_0x5aff('0xa7'));_0x47f35a[_0x5aff('0x49')](_0x5aff('0xa8'),_0x5aff('0x32'));}if(_0x264b0a[_0x5aff('0x24')])_0x47f35a[_0x5aff('0x24')](_0x264b0a['limit']);if(_0x264b0a['offset'])_0x47f35a['offset'](_0x264b0a[_0x5aff('0x21')]);return db[_0x5aff('0x95')][_0x5aff('0x3e')](_0x47f35a['toString'](),_0xd50d0a);})[_0x5aff('0x2b')](function(_0x3a6cd0){if(_0x3a6cd0[_0x5aff('0x42')]>0x0)_0x53f84b[_0x5aff('0x47')](_0x5aff('0xa9'),_[_0x5aff('0x31')](_0x3a6cd0,'id'));return db[_0x5aff('0x95')][_0x5aff('0x3e')](_0x53f84b['toString'](),_0xd50d0a)['then'](function(_0x2910d9){var _0x2f32cd=_[_0x5aff('0xaa')](_0x2910d9,'OpenchannelInteractionId');var _0x1335a6=[];_0x3a6cd0['forEach'](function(_0x454989){_0x1335a6['push'](updateOpenchannelInteraction(_0x454989,_0x3e4057,_0x2f32cd));});return BPromise[_0x5aff('0xab')](_0x1335a6);});});})['then'](function(_0x5d0102){_0x276428['rows']=_0x5d0102;return _0x276428;})['then'](respondWithFilteredResult(_0x92de64,_0x264b0a))[_0x5aff('0x37')](handleError(_0x92de64,null));};exports['show']=function(_0x49c081,_0x55e647){var _0x4ed27c={};if(_0x49c081['query'][_0x5aff('0x3b')]&&_0x49c081[_0x5aff('0x3e')][_0x5aff('0x3b')]===_0x5aff('0x4b')){_0x4ed27c[_0x5aff('0x4b')]=_0x49c081['params']['id'];}else{_0x4ed27c['id']=_0x49c081[_0x5aff('0xac')]['id'];}var _0x116ae2={'raw':![],'where':_0x4ed27c},_0xbcabfc={};_0xbcabfc[_0x5aff('0x3d')]=_[_0x5aff('0x70')](db[_0x5aff('0xad')][_0x5aff('0x39')]);_0xbcabfc[_0x5aff('0x3e')]=_[_0x5aff('0x70')](_0x49c081['query']);_0xbcabfc[_0x5aff('0x3f')]=_['intersection'](_0xbcabfc['model'],_0xbcabfc[_0x5aff('0x3e')]);_0x116ae2[_0x5aff('0x41')]=_[_0x5aff('0x40')](_0xbcabfc[_0x5aff('0x3d')],qs[_0x5aff('0xae')](_0x49c081[_0x5aff('0x3e')]['fields']));_0x116ae2[_0x5aff('0x41')]=_0x116ae2[_0x5aff('0x41')][_0x5aff('0x42')]?_0x116ae2[_0x5aff('0x41')]:_0xbcabfc[_0x5aff('0x3d')];if(_0x49c081[_0x5aff('0x3e')][_0x5aff('0xaf')]){_0x116ae2[_0x5aff('0xb0')]=[{'all':!![]}];}_0x116ae2=_['merge']({},_0x116ae2,_0x49c081[_0x5aff('0xb1')]);return db[_0x5aff('0xad')][_0x5aff('0x63')](_0x116ae2)[_0x5aff('0x2b')](handleEntityNotFound(_0x55e647,null))['then'](respondWithResult(_0x55e647,null))[_0x5aff('0x37')](handleError(_0x55e647,null));};exports['create']=function(_0x3b188a,_0x5e567f){return db[_0x5aff('0xad')][_0x5aff('0xb2')](_0x3b188a[_0x5aff('0x6f')],{})[_0x5aff('0x2b')](respondWithResult(_0x5e567f,0xc9))[_0x5aff('0x37')](handleError(_0x5e567f,null));};exports[_0x5aff('0x2a')]=function(_0x3147d7,_0x5d2105){if(_0x3147d7[_0x5aff('0x6f')]['id']){delete _0x3147d7[_0x5aff('0x6f')]['id'];}return db[_0x5aff('0xad')]['find']({'where':{'id':_0x3147d7[_0x5aff('0xac')]['id']}})[_0x5aff('0x2b')](handleEntityNotFound(_0x5d2105,null))[_0x5aff('0x2b')](saveUpdates(_0x3147d7[_0x5aff('0x6f')],null))[_0x5aff('0x2b')](respondWithResult(_0x5d2105,null))[_0x5aff('0x37')](handleError(_0x5d2105,null));};exports[_0x5aff('0x2c')]=function(_0x41ba64,_0x5d94fa){return db[_0x5aff('0xad')]['find']({'where':{'id':_0x41ba64['params']['id']}})[_0x5aff('0x2b')](handleEntityNotFound(_0x5d94fa,null))['then'](removeEntity(_0x5d94fa,null))['catch'](handleError(_0x5d94fa,null));};exports[_0x5aff('0xb3')]=function(_0x1ef66d,_0x30bf69){return db['OpenchannelInteraction'][_0x5aff('0xb3')]()[_0x5aff('0x2b')](respondWithResult(_0x30bf69,null))['catch'](handleError(_0x30bf69,null));};exports[_0x5aff('0xb4')]=function(_0x45a404,_0x22aed6,_0x5d17bb){return db[_0x5aff('0xb5')][_0x5aff('0x63')]({'where':{'id':_0x45a404[_0x5aff('0xac')]['id']}})[_0x5aff('0x2b')](handleEntityNotFound(_0x22aed6,null))[_0x5aff('0x2b')](function(_0xde29de){if(_0xde29de){return _0xde29de['addMessage'](_0x45a404[_0x5aff('0x6f')][_0x5aff('0xb6')],_[_0x5aff('0xb7')](_0x45a404[_0x5aff('0x6f')],[_0x5aff('0xb6'),'id'])||{});}})[_0x5aff('0x2b')](respondWithResult(_0x22aed6,null))[_0x5aff('0x37')](handleError(_0x22aed6,null));};exports[_0x5aff('0xb8')]=function(_0x4915db,_0x52ffb4,_0x2794e1){var _0x502a88={'raw':![],'where':{}};var _0x43dfcb={};var _0x762c67={'count':0x0,'rows':[]};return db[_0x5aff('0xad')][_0x5aff('0xb9')]({'where':{'id':_0x4915db[_0x5aff('0xac')]['id']}})[_0x5aff('0x2b')](handleEntityNotFound(_0x52ffb4,null))[_0x5aff('0x2b')](function(_0x1f5dc3){if(_0x1f5dc3){_0x43dfcb['model']=_['keys'](db['OpenchannelMessage'][_0x5aff('0x39')]);_0x43dfcb[_0x5aff('0x3e')]=_[_0x5aff('0x70')](_0x4915db[_0x5aff('0x3e')]);_0x43dfcb['filters']=_['intersection'](_0x43dfcb[_0x5aff('0x3d')],_0x43dfcb[_0x5aff('0x3e')]);_0x502a88[_0x5aff('0x41')]=_[_0x5aff('0x40')](_0x43dfcb[_0x5aff('0x3d')],qs['fields'](_0x4915db[_0x5aff('0x3e')]['fields']));_0x502a88[_0x5aff('0x41')]=_0x502a88['attributes'][_0x5aff('0x42')]?_0x502a88['attributes']:_0x43dfcb['model'];if(!_0x4915db[_0x5aff('0x3e')][_0x5aff('0x43')](_0x5aff('0x44'))){_0x502a88[_0x5aff('0x24')]=qs[_0x5aff('0x24')](_0x4915db[_0x5aff('0x3e')]['limit']);_0x502a88[_0x5aff('0x21')]=qs['offset'](_0x4915db[_0x5aff('0x3e')]['offset']);}_0x502a88[_0x5aff('0x45')]=qs[_0x5aff('0x46')](_0x4915db['query'][_0x5aff('0x46')]);_0x502a88['where']=qs[_0x5aff('0x3f')](_[_0x5aff('0x48')](_0x4915db['query'],_0x43dfcb[_0x5aff('0x3f')]));_0x502a88[_0x5aff('0x47')][_0x5aff('0xba')]=_0x1f5dc3['id'];if(_0x4915db[_0x5aff('0x3e')][_0x5aff('0x81')]){_0x502a88[_0x5aff('0x47')]=_[_0x5aff('0x96')](_0x502a88[_0x5aff('0x47')],{'$or':_[_0x5aff('0x31')](_0x502a88[_0x5aff('0x41')],function(_0x192400){var _0x5c2412={};_0x5c2412[_0x192400]={'$like':'%'+_0x4915db['query']['filter']+'%'};return _0x5c2412;})});}if(_0x4915db[_0x5aff('0x3e')][_0x5aff('0x77')]){var _0x13cc50=_0x4915db['query'][_0x5aff('0x77')]['split'](',');var _0x5d0cd4={};_0x5d0cd4[_0x13cc50[0x0]]={'$gte':moment(_0x13cc50[0x1])[_0x5aff('0xbb')](_0x5aff('0xbc'))};_0x502a88[_0x5aff('0x47')]=_['merge'](_0x502a88['where'],_0x5d0cd4);}_0x502a88=_['merge']({},_0x502a88,_0x4915db[_0x5aff('0xb1')]);return db[_0x5aff('0xb5')][_0x5aff('0x23')]({'where':_0x502a88['where']})['then'](function(_0x2bdb8e){_0x762c67[_0x5aff('0x23')]=_0x2bdb8e;if(_0x4915db[_0x5aff('0x3e')]['includeAll']){_0x502a88[_0x5aff('0xb0')]=[{'all':!![]}];}return db[_0x5aff('0xb5')][_0x5aff('0xbd')](_0x502a88);})['then'](function(_0x463522){_0x762c67[_0x5aff('0xbe')]=_0x463522;return _0x762c67;});}})[_0x5aff('0x2b')](respondWithFilteredResult(_0x52ffb4,_0x502a88))[_0x5aff('0x37')](handleError(_0x52ffb4,null));};exports[_0x5aff('0xbf')]=function(_0x341029,_0x258352,_0x5efa5a){return db[_0x5aff('0xad')][_0x5aff('0x63')]({'where':{'id':_0x341029['params']['id']}})[_0x5aff('0x2b')](handleEntityNotFound(_0x258352,null))[_0x5aff('0x2b')](function(_0x1868ba){if(_0x1868ba){return _0x1868ba[_0x5aff('0xc0')](_0x341029['body']['ids'],_[_0x5aff('0xb7')](_0x341029[_0x5aff('0x6f')],[_0x5aff('0xb6'),'id'])||{})[_0x5aff('0xc1')](function(){return db[_0x5aff('0x67')]['findAll']({'attributes':['id',_0x5aff('0x2e'),_0x5aff('0x4a')],'where':{'id':_0x341029[_0x5aff('0x6f')][_0x5aff('0xb6')]}});})['then'](function(_0x3c26ff){socket[_0x5aff('0xc2')](_0x5aff('0xc3'),{'id':Number(_0x341029[_0x5aff('0xac')]['id']),'tags':_0x3c26ff||[]});return{'id':Number(_0x341029[_0x5aff('0xac')]['id']),'tags':_0x3c26ff||[]};});}})[_0x5aff('0x2b')](respondWithResult(_0x258352,null))[_0x5aff('0x37')](handleError(_0x258352,null));};exports[_0x5aff('0xc4')]=function(_0xa557a5,_0x552399,_0x31b781){return db[_0x5aff('0xad')]['find']({'where':{'id':_0xa557a5[_0x5aff('0xac')]['id']}})[_0x5aff('0x2b')](handleEntityNotFound(_0x552399,null))[_0x5aff('0x2b')](function(_0x350b33){if(_0x350b33){return _0x350b33[_0x5aff('0xc4')](_0xa557a5['query'][_0x5aff('0xb6')]);}})[_0x5aff('0x2b')](respondWithStatusCode(_0x552399,null))[_0x5aff('0x37')](handleError(_0x552399,null));};exports[_0x5aff('0xc5')]=function(_0x3144ae,_0x5ba500){var _0x4e7716=moment()[_0x5aff('0xc6')]()[_0x5aff('0x94')]();var _0x55d770=path[_0x5aff('0xc7')](config[_0x5aff('0xc8')],'server','files',_0x5aff('0xc9'));var _0x3cecff=path[_0x5aff('0xc7')](config['root'],_0x5aff('0xca'),_0x5aff('0xcb'),'attachments');var _0x4626e4=path[_0x5aff('0xc7')](_0x55d770,_0x4e7716);var _0x59f33f=util[_0x5aff('0xbb')](_0x5aff('0xcc'),_0x3144ae[_0x5aff('0xac')]['id'],_0x4e7716);var _0x1f952=path[_0x5aff('0xc7')](_0x55d770,_0x59f33f);var _0x3a0856=[];_0x3a0856[_0x5aff('0x36')]({'model':db[_0x5aff('0x6a')],'as':_0x5aff('0x6a'),'attributes':['id',_0x5aff('0xcd')],'raw':!![]});_0x3a0856[_0x5aff('0x36')]({'model':db['CmContact'],'as':'Contact','attributes':['id',_0x5aff('0xce'),_0x5aff('0xcf')],'raw':!![]});if(_0x3144ae['query']['attachments']){_0x3a0856[_0x5aff('0x36')]({'model':db[_0x5aff('0xd0')],'as':_0x5aff('0xd0'),'raw':!![]});}var _0x30babb=[{'model':db[_0x5aff('0xb5')],'as':'Messages','attributes':['id',_0x5aff('0x6f'),'createdAt',_0x5aff('0xd1'),_0x5aff('0xd2'),_0x5aff('0x7c')],'include':_0x3a0856}];_0x30babb[_0x5aff('0x36')]({'model':db[_0x5aff('0xd3')],'as':_0x5aff('0xd4'),'attributes':['id',_0x5aff('0x2e')]});_0x30babb[_0x5aff('0x36')]({'model':db[_0x5aff('0x6a')],'as':_0x5aff('0xd5'),'attributes':['id',_0x5aff('0xcd')]});return db[_0x5aff('0xad')][_0x5aff('0x63')]({'where':{'id':_0x3144ae[_0x5aff('0xac')]['id']},'include':_0x30babb})[_0x5aff('0x2b')](handleEntityNotFound(_0x5ba500,null))[_0x5aff('0x2b')](function(_0x18ae5c){if(_0x18ae5c){var _0x5b632a=_0x18ae5c[_0x5aff('0xd6')]({'plain':!![]});fs[_0x5aff('0xd7')](_0x4626e4);var _0x4f43aa={'channel':_0x5aff('0xd8'),'account':_0x5b632a[_0x5aff('0xd4')]['name'],'agent':_0x5b632a[_0x5aff('0xd5')]?_0x5b632a[_0x5aff('0xd5')][_0x5aff('0xcd')]:_0x5aff('0xd9'),'createdAt':moment(_0x5b632a[_0x5aff('0x76')])[_0x5aff('0xbb')](_0x5aff('0xbc'))['toString'](),'closedAt':_0x5b632a[_0x5aff('0xda')]?moment(_0x5b632a['closedAt'])[_0x5aff('0xbb')](_0x5aff('0xbc'))[_0x5aff('0x94')]():'','disposition':_0x5b632a[_0x5aff('0xdb')],'visibility':_0x5b632a[_0x5aff('0xdc')]?_0x5aff('0xdd'):_0x5aff('0xde'),'messages':_(_0x5b632a[_0x5aff('0xdf')])['filter']({'secret':![]})[_0x5aff('0x31')](function(_0x45f7e7){if(_0x45f7e7[_0x5aff('0xd0')]){var _0x27277b=path['join'](_0x3cecff,_0x45f7e7[_0x5aff('0xd0')]['basename']);if(fs[_0x5aff('0xe0')](_0x27277b)){fs[_0x5aff('0xe1')](_0x27277b)[_0x5aff('0xe2')](fs[_0x5aff('0xe3')](path[_0x5aff('0xc7')](_0x4626e4,_0x45f7e7[_0x5aff('0xd0')][_0x5aff('0xe4')])));}}return{'date':moment(_0x45f7e7[_0x5aff('0x76')])[_0x5aff('0xbb')](_0x5aff('0xbc'))['toString'](),'sender':_0x45f7e7[_0x5aff('0xd1')]===_0x5aff('0xe5')?_0x45f7e7[_0x5aff('0x6a')]?_0x45f7e7[_0x5aff('0x6a')][_0x5aff('0xcd')]:_0x5aff('0xe6'):_0x45f7e7[_0x5aff('0x5f')][_0x5aff('0xce')]+(_0x45f7e7[_0x5aff('0x5f')][_0x5aff('0xcf')]?'\x20'+_0x45f7e7[_0x5aff('0x5f')]['lastName']:''),'body':_0x45f7e7[_0x5aff('0xd0')]?_0x45f7e7['Attachment'][_0x5aff('0xe4')]:_0x45f7e7['body'],'direction':_0x45f7e7[_0x5aff('0xd1')]===_0x5aff('0xe5')?'A':'C','secret':_0x45f7e7[_0x5aff('0xd2')],'read':_0x45f7e7[_0x5aff('0x7c')],'attachment':_0x45f7e7[_0x5aff('0xd0')]};})[_0x5aff('0x5c')]()};return ejs[_0x5aff('0xe7')](path[_0x5aff('0xc7')](config[_0x5aff('0xc8')],'server',_0x5aff('0xe8'),_0x5aff('0xe9')),{'interaction':_0x4f43aa})[_0x5aff('0x2b')](function(_0xdfc64b){var _0x303113=path[_0x5aff('0xc7')](_0x4626e4,_0x5aff('0xea')+_0x5b632a['id']+'-'+_0x4e7716+_0x5aff('0xeb'));var _0x6055dd={'path':_0x303113,'channel':'Openchannel','interactionId':_0x5b632a['id']};return pdf[_0x5aff('0xec')](_0xdfc64b,_0x6055dd);})['then'](function(){return new BPromise(function(_0x5443d4,_0x170f47){zipdir(_0x4626e4,{'saveTo':_0x1f952},function(_0x396981,_0x5b50ca){if(_0x396981)return _0x170f47(_0x396981);return _0x5443d4(_0x5b50ca);});})[_0x5aff('0x2b')](function(){return new BPromise(function(_0x4e4c86,_0x1338f9){rimraf(_0x4626e4,function(_0x51055c){if(_0x51055c)_0x1338f9(_0x51055c);return _0x4e4c86();});});})[_0x5aff('0x2b')](function(){return _0x5ba500['download'](_0x1f952,_0x59f33f,function(_0x245655){if(_0x245655){console[_0x5aff('0xed')](_0x5aff('0xee'),_0x245655);}else{fs[_0x5aff('0xef')](_0x1f952);}});});});}else{return _0x5ba500[_0x5aff('0x1e')](0xc8);}})[_0x5aff('0x37')](handleError(_0x5ba500,null));};
\ No newline at end of file