Built motion from commit fe909640.|2.6.8
[motion2.git] / server / api / openchannelInteraction / openchannelInteraction.controller.js
index 526249c..0f1a086 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 _0x317b=['params','keys','filters','intersection','model','fields','attributes','length','includeAll','include','options','find','body','destroy','addMessage','ids','omit','getMessages','findOne','OpenchannelMessage','hasOwnProperty','nolimit','order','sort','where','pick','OpenchannelInteractionId','filter','merge','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','rows','addTags','spread','Tag','color','emit','openchannelInteractionTags:save','removeTags','download','unix','toString','files','join','root','attachments','push','User','fullname','Attachment','Messages','direction','secret','OpenchannelAccount','Account','Owner','get','Openchannel','N.A.','createdAt','closed','closedAt','disposition','threadId','Public','Private','basename','pipe','createWriteStream','Contact','firstName','lastName','value','renderFile','transcript-','.pdf','Unable\x20to\x20delete\x20zip\x20file','unlinkSync','rimraf','zip-dir','util','path','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','redis','localhost','./openchannelInteraction.socket','register','status','end','json','limit','count','offset','Content-Range','update','then','sendStatus','error','stack','name','index','map','OpenchannelInteraction','rawAttributes','fieldName','key','getOptions','findAll','openchannel','query','user','catch','show','type','from'];(function(_0x1a89a1,_0x56d889){var _0x3d5b46=function(_0x56debf){while(--_0x56debf){_0x1a89a1['push'](_0x1a89a1['shift']());}};_0x3d5b46(++_0x56d889);}(_0x317b,0x1c7));var _0xb317=function(_0x42eb88,_0x307611){_0x42eb88=_0x42eb88-0x0;var _0x144e50=_0x317b[_0x42eb88];return _0x144e50;};'use strict';var rimraf=require(_0xb317('0x0'));var zipdir=require(_0xb317('0x1'));var moment=require('moment');var util=require(_0xb317('0x2'));var path=require(_0xb317('0x3'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xb317('0x4'));var Redis=require(_0xb317('0x5'));var interaction=require(_0xb317('0x6'));var qs=require(_0xb317('0x7'));var pdf=require(_0xb317('0x8'));var logger=require(_0xb317('0x9'))(_0xb317('0xa'));var config=require(_0xb317('0xb'));var db=require(_0xb317('0xc'))['db'];config[_0xb317('0xd')]=_['defaults'](config[_0xb317('0xd')],{'host':_0xb317('0xe'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xb317('0xd')]));require(_0xb317('0xf'))[_0xb317('0x10')](socket);function respondWithStatusCode(_0xd2deea,_0xbffffb){_0xbffffb=_0xbffffb||0xcc;return function(_0x354a87){if(_0x354a87){return _0xd2deea['sendStatus'](_0xbffffb);}return _0xd2deea[_0xb317('0x11')](_0xbffffb)[_0xb317('0x12')]();};}function respondWithResult(_0x58d153,_0x1000d9){_0x1000d9=_0x1000d9||0xc8;return function(_0x494541){if(_0x494541){return _0x58d153[_0xb317('0x11')](_0x1000d9)[_0xb317('0x13')](_0x494541);}};}function respondWithFilteredResult(_0x458584,_0x15f3f5){return function(_0x4d99d8){if(_0x4d99d8){var _0xf88e1c=typeof _0x15f3f5['offset']==='undefined'&&typeof _0x15f3f5[_0xb317('0x14')]==='undefined';var _0x237b84=_0x4d99d8[_0xb317('0x15')];var _0x2ef2c6=_0xf88e1c?0x0:_0x15f3f5['offset'];var _0x4ade83=_0xf88e1c?_0x4d99d8['count']:_0x15f3f5[_0xb317('0x16')]+_0x15f3f5['limit'];var _0x266bdc;if(_0x4ade83>=_0x237b84){_0x4ade83=_0x237b84;_0x266bdc=0xc8;}else{_0x266bdc=0xce;}_0x458584[_0xb317('0x11')](_0x266bdc);return _0x458584['set'](_0xb317('0x17'),_0x2ef2c6+'-'+_0x4ade83+'/'+_0x237b84)[_0xb317('0x13')](_0x4d99d8);}return null;};}function saveUpdates(_0x53bbd3){return function(_0x497992){if(_0x497992){return _0x497992[_0xb317('0x18')](_0x53bbd3)[_0xb317('0x19')](function(_0x235895){return _0x235895;});}return null;};}function removeEntity(_0x13d760){return function(_0x2cc220){if(_0x2cc220){return _0x2cc220['destroy']()[_0xb317('0x19')](function(){_0x13d760[_0xb317('0x11')](0xcc)[_0xb317('0x12')]();});}};}function handleEntityNotFound(_0x2493a2){return function(_0x19a166){if(!_0x19a166){_0x2493a2[_0xb317('0x1a')](0x194);}return _0x19a166;};}function handleError(_0x1a2b0a,_0x459f6d){_0x459f6d=_0x459f6d||0x1f4;return function(_0x1fb834){logger[_0xb317('0x1b')](_0x1fb834[_0xb317('0x1c')]);if(_0x1fb834[_0xb317('0x1d')]){delete _0x1fb834[_0xb317('0x1d')];}_0x1a2b0a[_0xb317('0x11')](_0x459f6d)['send'](_0x1fb834);};}exports[_0xb317('0x1e')]=function(_0x55bf91,_0x16ef79){var _0x4b7eb6={};var _0x3009fb=_[_0xb317('0x1f')](db[_0xb317('0x20')][_0xb317('0x21')],function(_0x109189){return{'name':_0x109189[_0xb317('0x22')],'type':_0x109189['type'][_0xb317('0x23')]};});_0x4b7eb6=qs[_0xb317('0x24')](_0x3009fb,_0x55bf91);return interaction[_0xb317('0x25')](_0xb317('0x26'),_0x55bf91[_0xb317('0x27')],_0x55bf91[_0xb317('0x28')],_0x4b7eb6,_0x3009fb)['then'](respondWithFilteredResult(_0x16ef79,_0x4b7eb6))[_0xb317('0x29')](handleError(_0x16ef79,null));};exports[_0xb317('0x2a')]=function(_0x5be03a,_0x5c629c){var _0x33b3c1={};if(_0x5be03a[_0xb317('0x27')][_0xb317('0x2b')]&&_0x5be03a['query'][_0xb317('0x2b')]===_0xb317('0x2c')){_0x33b3c1[_0xb317('0x2c')]=_0x5be03a[_0xb317('0x2d')]['id'];}else{_0x33b3c1['id']=_0x5be03a[_0xb317('0x2d')]['id'];}var _0x5a14ae={'raw':![],'where':_0x33b3c1},_0x39c2aa={};_0x39c2aa['model']=_[_0xb317('0x2e')](db['OpenchannelInteraction'][_0xb317('0x21')]);_0x39c2aa[_0xb317('0x27')]=_[_0xb317('0x2e')](_0x5be03a['query']);_0x39c2aa[_0xb317('0x2f')]=_[_0xb317('0x30')](_0x39c2aa[_0xb317('0x31')],_0x39c2aa['query']);_0x5a14ae['attributes']=_[_0xb317('0x30')](_0x39c2aa['model'],qs['fields'](_0x5be03a['query'][_0xb317('0x32')]));_0x5a14ae[_0xb317('0x33')]=_0x5a14ae[_0xb317('0x33')][_0xb317('0x34')]?_0x5a14ae['attributes']:_0x39c2aa[_0xb317('0x31')];if(_0x5be03a[_0xb317('0x27')][_0xb317('0x35')]){_0x5a14ae[_0xb317('0x36')]=[{'all':!![]}];}_0x5a14ae=_['merge']({},_0x5a14ae,_0x5be03a[_0xb317('0x37')]);return db['OpenchannelInteraction'][_0xb317('0x38')](_0x5a14ae)[_0xb317('0x19')](handleEntityNotFound(_0x5c629c,null))[_0xb317('0x19')](respondWithResult(_0x5c629c,null))[_0xb317('0x29')](handleError(_0x5c629c,null));};exports['create']=function(_0x24649a,_0x1aeee3){return db[_0xb317('0x20')]['create'](_0x24649a[_0xb317('0x39')],{})[_0xb317('0x19')](respondWithResult(_0x1aeee3,0xc9))[_0xb317('0x29')](handleError(_0x1aeee3,null));};exports[_0xb317('0x18')]=function(_0x47cc23,_0x2d0e6e){if(_0x47cc23[_0xb317('0x39')]['id']){delete _0x47cc23[_0xb317('0x39')]['id'];}return db[_0xb317('0x20')][_0xb317('0x38')]({'where':{'id':_0x47cc23[_0xb317('0x2d')]['id']}})[_0xb317('0x19')](handleEntityNotFound(_0x2d0e6e,null))['then'](saveUpdates(_0x47cc23[_0xb317('0x39')],null))['then'](respondWithResult(_0x2d0e6e,null))[_0xb317('0x29')](handleError(_0x2d0e6e,null));};exports[_0xb317('0x3a')]=function(_0x35ea1d,_0x48fd3f){return db[_0xb317('0x20')][_0xb317('0x38')]({'where':{'id':_0x35ea1d[_0xb317('0x2d')]['id']}})[_0xb317('0x19')](handleEntityNotFound(_0x48fd3f,null))['then'](removeEntity(_0x48fd3f,null))[_0xb317('0x29')](handleError(_0x48fd3f,null));};exports['describe']=function(_0x682954,_0x4c5418){return db[_0xb317('0x20')]['describe']()[_0xb317('0x19')](respondWithResult(_0x4c5418,null))['catch'](handleError(_0x4c5418,null));};exports[_0xb317('0x3b')]=function(_0x15eff3,_0x1b4d2f){return db['OpenchannelMessage']['find']({'where':{'id':_0x15eff3[_0xb317('0x2d')]['id']}})[_0xb317('0x19')](handleEntityNotFound(_0x1b4d2f,null))['then'](function(_0x450ff8){if(_0x450ff8){return _0x450ff8[_0xb317('0x3b')](_0x15eff3[_0xb317('0x39')][_0xb317('0x3c')],_[_0xb317('0x3d')](_0x15eff3['body'],['ids','id'])||{});}})[_0xb317('0x19')](respondWithResult(_0x1b4d2f,null))['catch'](handleError(_0x1b4d2f,null));};exports[_0xb317('0x3e')]=function(_0x2bd5a1,_0x40ee2c){var _0x312b8d={'raw':![],'where':{}};var _0xda2983={};var _0x233a76={'count':0x0,'rows':[]};return db[_0xb317('0x20')][_0xb317('0x3f')]({'where':{'id':_0x2bd5a1[_0xb317('0x2d')]['id']}})[_0xb317('0x19')](handleEntityNotFound(_0x40ee2c,null))[_0xb317('0x19')](function(_0x2fbb19){if(_0x2fbb19){_0xda2983[_0xb317('0x31')]=_['keys'](db[_0xb317('0x40')]['rawAttributes']);_0xda2983[_0xb317('0x27')]=_[_0xb317('0x2e')](_0x2bd5a1[_0xb317('0x27')]);_0xda2983['filters']=_['intersection'](_0xda2983[_0xb317('0x31')],_0xda2983[_0xb317('0x27')]);_0x312b8d[_0xb317('0x33')]=_[_0xb317('0x30')](_0xda2983[_0xb317('0x31')],qs['fields'](_0x2bd5a1[_0xb317('0x27')][_0xb317('0x32')]));_0x312b8d[_0xb317('0x33')]=_0x312b8d[_0xb317('0x33')]['length']?_0x312b8d[_0xb317('0x33')]:_0xda2983[_0xb317('0x31')];if(!_0x2bd5a1[_0xb317('0x27')][_0xb317('0x41')](_0xb317('0x42'))){_0x312b8d[_0xb317('0x14')]=qs['limit'](_0x2bd5a1[_0xb317('0x27')][_0xb317('0x14')]);_0x312b8d[_0xb317('0x16')]=qs[_0xb317('0x16')](_0x2bd5a1[_0xb317('0x27')][_0xb317('0x16')]);}_0x312b8d[_0xb317('0x43')]=qs['sort'](_0x2bd5a1[_0xb317('0x27')][_0xb317('0x44')]);_0x312b8d[_0xb317('0x45')]=qs[_0xb317('0x2f')](_[_0xb317('0x46')](_0x2bd5a1[_0xb317('0x27')],_0xda2983['filters']));_0x312b8d['where'][_0xb317('0x47')]=_0x2fbb19['id'];if(_0x2bd5a1['query'][_0xb317('0x48')]){_0x312b8d[_0xb317('0x45')]=_[_0xb317('0x49')](_0x312b8d[_0xb317('0x45')],{'$or':_['map'](_0x312b8d[_0xb317('0x33')],function(_0x49f860){var _0x58c725={};_0x58c725[_0x49f860]={'$like':'%'+_0x2bd5a1['query'][_0xb317('0x48')]+'%'};return _0x58c725;})});}if(_0x2bd5a1['query']['$gte']){var _0x1a6fe6=_0x2bd5a1[_0xb317('0x27')][_0xb317('0x4a')][_0xb317('0x4b')](',');var _0x16db1a={};_0x16db1a[_0x1a6fe6[0x0]]={'$gte':moment(_0x1a6fe6[0x1])[_0xb317('0x4c')](_0xb317('0x4d'))};_0x312b8d[_0xb317('0x45')]=_[_0xb317('0x49')](_0x312b8d[_0xb317('0x45')],_0x16db1a);}_0x312b8d=_[_0xb317('0x49')]({},_0x312b8d,_0x2bd5a1[_0xb317('0x37')]);return db[_0xb317('0x40')][_0xb317('0x15')]({'where':_0x312b8d['where']})[_0xb317('0x19')](function(_0xf94328){_0x233a76[_0xb317('0x15')]=_0xf94328;if(_0x2bd5a1[_0xb317('0x27')][_0xb317('0x35')]){_0x312b8d[_0xb317('0x36')]=[{'all':!![]}];}return db[_0xb317('0x40')]['findAll'](_0x312b8d);})[_0xb317('0x19')](function(_0x241183){_0x233a76[_0xb317('0x4e')]=_0x241183;return _0x233a76;});}})['then'](respondWithFilteredResult(_0x40ee2c,_0x312b8d))[_0xb317('0x29')](handleError(_0x40ee2c,null));};exports[_0xb317('0x4f')]=function(_0x21838d,_0xa6af78){return db[_0xb317('0x20')][_0xb317('0x38')]({'where':{'id':_0x21838d['params']['id']}})[_0xb317('0x19')](handleEntityNotFound(_0xa6af78,null))[_0xb317('0x19')](function(_0x54b22e){if(_0x54b22e){return _0x54b22e['setTags'](_0x21838d[_0xb317('0x39')][_0xb317('0x3c')],_[_0xb317('0x3d')](_0x21838d[_0xb317('0x39')],[_0xb317('0x3c'),'id'])||{})[_0xb317('0x50')](function(){return db[_0xb317('0x51')][_0xb317('0x25')]({'attributes':['id',_0xb317('0x1d'),_0xb317('0x52')],'where':{'id':_0x21838d[_0xb317('0x39')][_0xb317('0x3c')]}});})[_0xb317('0x19')](function(_0x379b71){socket[_0xb317('0x53')](_0xb317('0x54'),{'id':Number(_0x21838d[_0xb317('0x2d')]['id']),'tags':_0x379b71||[]});return{'id':Number(_0x21838d[_0xb317('0x2d')]['id']),'tags':_0x379b71||[]};});}})[_0xb317('0x19')](respondWithResult(_0xa6af78,null))[_0xb317('0x29')](handleError(_0xa6af78,null));};exports[_0xb317('0x55')]=function(_0x54bd24,_0x3c7c1c){return db[_0xb317('0x20')][_0xb317('0x38')]({'where':{'id':_0x54bd24[_0xb317('0x2d')]['id']}})[_0xb317('0x19')](handleEntityNotFound(_0x3c7c1c,null))[_0xb317('0x19')](function(_0x12faf7){if(_0x12faf7){return _0x12faf7[_0xb317('0x55')](_0x54bd24[_0xb317('0x27')]['ids']);}})[_0xb317('0x19')](respondWithStatusCode(_0x3c7c1c,null))['catch'](handleError(_0x3c7c1c,null));};exports[_0xb317('0x56')]=function(_0x1bde17,_0x3214bc){var _0x53eb13=moment()[_0xb317('0x57')]()[_0xb317('0x58')]();var _0x405cff=path['join'](config['root'],'server',_0xb317('0x59'),'tmp');var _0x5c754e=path[_0xb317('0x5a')](config[_0xb317('0x5b')],'server',_0xb317('0x59'),_0xb317('0x5c'));var _0x41f20a=path[_0xb317('0x5a')](_0x405cff,_0x53eb13);var _0x3f6986=util[_0xb317('0x4c')]('transcript-%d-%s.zip',_0x1bde17[_0xb317('0x2d')]['id'],_0x53eb13);var _0x43872d=path[_0xb317('0x5a')](_0x405cff,_0x3f6986);var _0x4c22ac=[];_0x4c22ac[_0xb317('0x5d')]({'model':db[_0xb317('0x5e')],'as':_0xb317('0x5e'),'attributes':['id',_0xb317('0x5f')],'raw':!![]});_0x4c22ac['push']({'model':db['CmContact'],'as':'Contact','attributes':['id','firstName','lastName'],'raw':!![]});if(_0x1bde17['query'][_0xb317('0x5c')]){_0x4c22ac['push']({'model':db[_0xb317('0x60')],'as':_0xb317('0x60'),'raw':!![]});}var _0xf03195=[{'model':db[_0xb317('0x40')],'as':_0xb317('0x61'),'attributes':['id',_0xb317('0x39'),'createdAt',_0xb317('0x62'),_0xb317('0x63'),'read'],'include':_0x4c22ac}];_0xf03195['push']({'model':db[_0xb317('0x64')],'as':_0xb317('0x65'),'attributes':['id',_0xb317('0x1d')]});_0xf03195[_0xb317('0x5d')]({'model':db['User'],'as':_0xb317('0x66'),'attributes':['id',_0xb317('0x5f')]});return db[_0xb317('0x20')][_0xb317('0x38')]({'where':{'id':_0x1bde17[_0xb317('0x2d')]['id']},'include':_0xf03195})[_0xb317('0x19')](handleEntityNotFound(_0x3214bc,null))[_0xb317('0x19')](function(_0x554430){if(_0x554430){var _0x2796f6=_0x554430[_0xb317('0x67')]({'plain':!![]});fs['mkdirSync'](_0x41f20a);var _0x2c17fa={'channel':_0xb317('0x68'),'account':_0x2796f6[_0xb317('0x65')][_0xb317('0x1d')],'agent':_0x2796f6[_0xb317('0x66')]?_0x2796f6[_0xb317('0x66')][_0xb317('0x5f')]:_0xb317('0x69'),'createdAt':moment(_0x2796f6[_0xb317('0x6a')])['format'](_0xb317('0x4d'))[_0xb317('0x58')](),'closedAt':_0x2796f6[_0xb317('0x6b')]?moment(_0x2796f6[_0xb317('0x6c')])[_0xb317('0x4c')](_0xb317('0x4d'))[_0xb317('0x58')]():'','disposition':_0x2796f6[_0xb317('0x6d')],'visibility':_0x2796f6[_0xb317('0x6e')]?_0xb317('0x6f'):_0xb317('0x70'),'messages':_(_0x2796f6[_0xb317('0x61')])[_0xb317('0x48')]({'secret':![]})[_0xb317('0x1f')](function(_0x2af3e4){if(_0x2af3e4[_0xb317('0x60')]){var _0x568bbb=path[_0xb317('0x5a')](_0x5c754e,_0x2af3e4[_0xb317('0x60')][_0xb317('0x71')]);if(fs['existsSync'](_0x568bbb)){fs['createReadStream'](_0x568bbb)[_0xb317('0x72')](fs[_0xb317('0x73')](path['join'](_0x41f20a,_0x2af3e4[_0xb317('0x60')][_0xb317('0x71')])));}}return{'date':moment(_0x2af3e4[_0xb317('0x6a')])[_0xb317('0x4c')](_0xb317('0x4d'))[_0xb317('0x58')](),'sender':_0x2af3e4['direction']==='out'?_0x2af3e4['User']?_0x2af3e4['User']['fullname']:'System':_0x2af3e4[_0xb317('0x74')][_0xb317('0x75')]+(_0x2af3e4['Contact'][_0xb317('0x76')]?'\x20'+_0x2af3e4[_0xb317('0x74')][_0xb317('0x76')]:''),'body':_0x2af3e4[_0xb317('0x60')]?_0x2af3e4[_0xb317('0x60')][_0xb317('0x71')]:_0x2af3e4['body'],'direction':_0x2af3e4[_0xb317('0x62')]==='out'?'A':'C','secret':_0x2af3e4[_0xb317('0x63')],'read':_0x2af3e4['read'],'attachment':_0x2af3e4[_0xb317('0x60')]};})[_0xb317('0x77')]()};return ejs[_0xb317('0x78')](path['join'](config[_0xb317('0x5b')],'server','views','downloadInteraction.ejs'),{'interaction':_0x2c17fa})[_0xb317('0x19')](function(_0x4919dd){var _0x1cfea7=path[_0xb317('0x5a')](_0x41f20a,_0xb317('0x79')+_0x2796f6['id']+'-'+_0x53eb13+_0xb317('0x7a'));var _0x20ccc4={'path':_0x1cfea7,'channel':_0xb317('0x68'),'interactionId':_0x2796f6['id']};return pdf['createPdfFromHTML'](_0x4919dd,_0x20ccc4);})[_0xb317('0x19')](function(){return new Promise(function(_0x1ab96f,_0xdc26bf){zipdir(_0x41f20a,{'saveTo':_0x43872d},function(_0x24dad2,_0x17f396){if(_0x24dad2)return _0xdc26bf(_0x24dad2);return _0x1ab96f(_0x17f396);});})['then'](function(){return new Promise(function(_0x496752,_0x8c9be9){rimraf(_0x41f20a,function(_0x36b5d1){if(_0x36b5d1)_0x8c9be9(_0x36b5d1);return _0x496752();});});})[_0xb317('0x19')](function(){return _0x3214bc[_0xb317('0x56')](_0x43872d,_0x3f6986,function(_0x922f2e){if(_0x922f2e){logger[_0xb317('0x1b')](_0xb317('0x7b'),_0x922f2e);}else{fs[_0xb317('0x7c')](_0x43872d);}});});});}else{return _0x3214bc[_0xb317('0x1a')](0xc8);}})[_0xb317('0x29')](handleError(_0x3214bc,null));};
\ No newline at end of file