Built motion from commit (unavailable).|2.5.11
[motion2.git] / server / api / smsInteraction / smsInteraction.controller.js
index dca5d72..f08be66 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xacf4=['log','unlinkSync','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','ejs','lodash','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/environment','defaults','redis','localhost','socket.io-emitter','./smsInteraction.socket','register','sendStatus','end','status','count','offset','limit','set','Content-Range','json','apply','save','update','then','error','stack','name','send','Users','map','fullname','TagIds','Tags','split','forEach','catch','rawAttributes','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','pick','select','field','color','from','tools_tags','u.id','u.fullname','ui.SmsInteractionId','user_has_sms_interactions','users','u.id\x20=\x20ui.UserId','sms_interactions','left_join','cm_contacts','o.id\x20=\x20i.UserId','sms_accounts','a.id\x20=\x20i.SmsAccountId','sms_messages','sms_interaction_has_tags','it.SmsInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','parseSearch','search','sqlOperator','conditions','length','find','value','having','`\x20>\x200','Contact','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','text','start','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','operator','$substring','UserId','body','some','compact','isEmpty','i.SmsAccountId\x20IN\x20?','$gte','parse','$lte','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','\x27\x27\x27\x27','isNumeric','i.id\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','group','SELECT','clone','i.id','unreadMessages','resolve','SmsAccountId','i.SmsAccountId\x20IS\x20NOT\x20NULL','user','getSmsAccounts','i.SmsAccountId\x20IS\x20NULL','sequelize','toString','keyBy','merge','SmsInteraction','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','a.key','Account.key','a.mandatoryDisposition','i.*','c.firstName','Contact.firstName','c.lastName','Contact.lastName','c.email','c.phone','Contact.phone','c.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','ui.SmsInteractionId\x20IN\x20?','groupBy','SmsInteractionId','push','includeAll','include','create','params','describe','addMessage','SmsMessage','ids','omit','getMessages','findOne','nolimit','format','YYYY-MM-DD\x20HH:mm:ss','options','findAll','setTags','spread','Tag','smsInteractionTags:save','removeTags','download','join','root','server','files','tmp','attachments','transcript-%d-%s.zip','User','CmContact','firstName','lastName','Messages','createdAt','direction','secret','SmsAccount','Account','Owner','get','10px','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>','Sms','YYYY-MM-DD','N.A.','closed','disposition','out','views','toFile','.pdf'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0xacf4,0xe7));var _0x4acf=function(_0x10dd3f,_0x4914c1){_0x10dd3f=_0x10dd3f-0x0;var _0x16e8b9=_0xacf4[_0x10dd3f];return _0x16e8b9;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x4acf('0x0'));var zipdir=require(_0x4acf('0x1'));var jsonpatch=require(_0x4acf('0x2'));var rp=require(_0x4acf('0x3'));var moment=require(_0x4acf('0x4'));var BPromise=require(_0x4acf('0x5'));var Mustache=require(_0x4acf('0x6'));var util=require('util');var path=require(_0x4acf('0x7'));var sox=require(_0x4acf('0x8'));var csv=require('to-csv');var ejs=require(_0x4acf('0x9'));var fs=require('fs');var _=require(_0x4acf('0xa'));var squel=require(_0x4acf('0xb'));var crypto=require(_0x4acf('0xc'));var jsforce=require(_0x4acf('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x4acf('0xe'));var Papa=require('papaparse');var Redis=require(_0x4acf('0xf'));var authService=require(_0x4acf('0x10'));var qs=require(_0x4acf('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x4acf('0x12'));var logger=require(_0x4acf('0x13'))('api');var utils=require('../../config/utils');var config=require(_0x4acf('0x14'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x4acf('0x15')](config[_0x4acf('0x16')],{'host':_0x4acf('0x17'),'port':0x18eb});var socket=require(_0x4acf('0x18'))(new Redis(config[_0x4acf('0x16')]));require(_0x4acf('0x19'))[_0x4acf('0x1a')](socket);function respondWithStatusCode(_0x15386a,_0x2025ca){_0x2025ca=_0x2025ca||0xcc;return function(_0x312bb5){if(_0x312bb5){return _0x15386a[_0x4acf('0x1b')](_0x2025ca);}return _0x15386a['status'](_0x2025ca)[_0x4acf('0x1c')]();};}function respondWithResult(_0x57d8e0,_0x34cec1){_0x34cec1=_0x34cec1||0xc8;return function(_0x4041c8){if(_0x4041c8){return _0x57d8e0[_0x4acf('0x1d')](_0x34cec1)['json'](_0x4041c8);}};}function respondWithFilteredResult(_0x5207e7,_0x13d10e){return function(_0x40cb8d){if(_0x40cb8d){var _0x240c00=_0x40cb8d[_0x4acf('0x1e')],_0x4b1d93=_0x13d10e[_0x4acf('0x1f')],_0x2a678b=_0x13d10e[_0x4acf('0x1f')]+_0x13d10e[_0x4acf('0x20')],_0x137302;if(_0x2a678b>=_0x240c00){_0x2a678b=_0x240c00;_0x137302=0xc8;}else{_0x137302=0xce;}_0x5207e7[_0x4acf('0x1d')](_0x137302);return _0x5207e7[_0x4acf('0x21')](_0x4acf('0x22'),_0x4b1d93+'-'+_0x2a678b+'/'+_0x240c00)[_0x4acf('0x23')](_0x40cb8d);}return null;};}function patchUpdates(_0x1a3118){return function(_0x5f0284){try{jsonpatch[_0x4acf('0x24')](_0x5f0284,_0x1a3118,!![]);}catch(_0x6bd89){return BPromise['reject'](_0x6bd89);}return _0x5f0284[_0x4acf('0x25')]();};}function saveUpdates(_0x17775f,_0x569d9e){return function(_0x3b26ac){if(_0x3b26ac){return _0x3b26ac[_0x4acf('0x26')](_0x17775f)[_0x4acf('0x27')](function(_0x454555){return _0x454555;});}return null;};}function removeEntity(_0x53885f,_0x1a2286){return function(_0x12e717){if(_0x12e717){return _0x12e717['destroy']()[_0x4acf('0x27')](function(){_0x53885f[_0x4acf('0x1d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x126522,_0x7ebb){return function(_0x38152c){if(!_0x38152c){_0x126522[_0x4acf('0x1b')](0x194);}return _0x38152c;};}function handleError(_0x571a30,_0x50236d){_0x50236d=_0x50236d||0x1f4;return function(_0x17a756){logger[_0x4acf('0x28')](_0x17a756[_0x4acf('0x29')]);if(_0x17a756[_0x4acf('0x2a')]){delete _0x17a756[_0x4acf('0x2a')];}_0x571a30[_0x4acf('0x1d')](_0x50236d)[_0x4acf('0x2b')](_0x17a756);};}function getInteractionUsers(_0x7a1e79,_0x382c41){return new BPromise(function(_0x2a3830,_0x57989e){try{if(_0x382c41[_0x7a1e79['id']]){_0x7a1e79[_0x4acf('0x2c')]=_[_0x4acf('0x2d')](_0x382c41[_0x7a1e79['id']],function(_0xd027c7){return{'id':_0xd027c7['id'],'fullname':_0xd027c7[_0x4acf('0x2e')]};});}}catch(_0x252cf1){_0x57989e(_0x252cf1);}_0x2a3830(_0x7a1e79);});}function getInteractionTags(_0x28570f,_0x27384c){return new BPromise(function(_0x5d862f,_0x337b3c){try{if(_0x28570f[_0x4acf('0x2f')]){_0x28570f[_0x4acf('0x30')]=[];_0x28570f['TagIds'][_0x4acf('0x31')](',')[_0x4acf('0x32')](function(_0x1fc815){_0x28570f[_0x4acf('0x30')]['push'](_0x27384c[_0x1fc815]);});}delete _0x28570f[_0x4acf('0x2f')];}catch(_0x1bf97e){_0x337b3c(_0x1bf97e);}_0x5d862f(_0x28570f);});}function updateSmsInteraction(_0x3f9990,_0x5e2332,_0x31fbce){return new BPromise(function(_0x34e2ee,_0x4084fe){return getInteractionUsers(_0x3f9990,_0x31fbce)[_0x4acf('0x27')](function(_0xd221b7){return getInteractionTags(_0xd221b7,_0x5e2332);})[_0x4acf('0x27')](function(_0x490880){_0x34e2ee(_0x490880);})[_0x4acf('0x33')](function(_0x25748e){_0x4084fe(_0x25748e);});});}exports['index']=function(_0xfd8ab5,_0x543a37){var _0x4cd020={},_0x58aacf={},_0x4bd85c={'count':0x0,'rows':[]};var _0x4ce916=_['map'](db['SmsInteraction'][_0x4acf('0x34')],function(_0x1b45f6){return{'name':_0x1b45f6['fieldName'],'type':_0x1b45f6[_0x4acf('0x35')][_0x4acf('0x36')]};});_0x58aacf[_0x4acf('0x37')]=_[_0x4acf('0x2d')](_0x4ce916,_0x4acf('0x2a'));_0x58aacf[_0x4acf('0x38')]=_[_0x4acf('0x39')](_0xfd8ab5[_0x4acf('0x38')]);_0x58aacf[_0x4acf('0x3a')]=_[_0x4acf('0x3b')](_0x58aacf['model'],_0x58aacf['query']);_0x4cd020[_0x4acf('0x3c')]=_[_0x4acf('0x3b')](_0x58aacf['model'],qs[_0x4acf('0x3d')](_0xfd8ab5[_0x4acf('0x38')][_0x4acf('0x3d')]));_0x4cd020[_0x4acf('0x3c')]=_0x4cd020['attributes']['length']?_0x4cd020[_0x4acf('0x3c')]:_0x58aacf[_0x4acf('0x37')];if(!_0xfd8ab5[_0x4acf('0x38')][_0x4acf('0x3e')]('nolimit')){_0x4cd020[_0x4acf('0x20')]=qs[_0x4acf('0x20')](_0xfd8ab5['query']['limit']);_0x4cd020['offset']=qs['offset'](_0xfd8ab5[_0x4acf('0x38')][_0x4acf('0x1f')]);}_0x4cd020[_0x4acf('0x3f')]=qs['sort'](_0xfd8ab5[_0x4acf('0x38')][_0x4acf('0x40')]);_0x4cd020[_0x4acf('0x41')]=qs[_0x4acf('0x3a')](_[_0x4acf('0x42')](_0xfd8ab5[_0x4acf('0x38')],_0x58aacf[_0x4acf('0x3a')]));var _0x17d5e9=[];var _0x461547=squel[_0x4acf('0x43')]()[_0x4acf('0x44')]('id')['field'](_0x4acf('0x2a'))[_0x4acf('0x44')](_0x4acf('0x45'))[_0x4acf('0x46')](_0x4acf('0x47'));var _0x58bc5d=squel['select']()[_0x4acf('0x44')](_0x4acf('0x48'))[_0x4acf('0x44')](_0x4acf('0x49'))[_0x4acf('0x44')](_0x4acf('0x4a'))['from'](_0x4acf('0x4b'),'ui')['left_join'](_0x4acf('0x4c'),'u',_0x4acf('0x4d'));var _0x54b2a8=squel['select']()[_0x4acf('0x46')](_0x4acf('0x4e'),'i')[_0x4acf('0x4f')](_0x4acf('0x50'),'c','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL')[_0x4acf('0x4f')](_0x4acf('0x4c'),'o',_0x4acf('0x51'))[_0x4acf('0x4f')](_0x4acf('0x52'),'a',_0x4acf('0x53'))[_0x4acf('0x4f')](_0x4acf('0x54'),'me','me.SmsInteractionId\x20=\x20i.id')['left_join'](_0x4acf('0x55'),'it',_0x4acf('0x56'))[_0x4acf('0x4f')](_0x4acf('0x47'),'t',_0x4acf('0x57'));var _0x859247=squel[_0x4acf('0x58')]();var _0x33b68=[];var _0x34b447=squel[_0x4acf('0x58')]();var _0x32d212;if(_0xfd8ab5[_0x4acf('0x38')]['search']){_0x32d212=as[_0x4acf('0x59')](_0xfd8ab5[_0x4acf('0x38')][_0x4acf('0x5a')]);var _0x464466=_0x32d212[_0x4acf('0x5b')];for(var _0x3cf54a=0x0;_0x3cf54a<_0x32d212[_0x4acf('0x5c')][_0x4acf('0x5d')];_0x3cf54a++){var _0x3382ad=_0x32d212[_0x4acf('0x5c')][_0x3cf54a];var _0xe96d97='i';var _0x3ad746=_[_0x4acf('0x5e')](_0x4ce916,[_0x4acf('0x2a'),_0x3382ad[_0x4acf('0x44')]]);if(!_0x3ad746){switch(_0x3382ad[_0x4acf('0x44')]){case'unreadMessages':if(_0x3382ad[_0x4acf('0x5f')]==0x1){_0x54b2a8[_0x4acf('0x60')]('`'+_0x3382ad[_0x4acf('0x44')]+'`\x20=\x200');}else{_0x54b2a8[_0x4acf('0x60')]('`'+_0x3382ad[_0x4acf('0x44')]+_0x4acf('0x61'));}break;case _0x4acf('0x62'):if(_0x3382ad['operator']==='$substring'){if(_0x3382ad['value'][_0x4acf('0x31')]('\x20')[_0x4acf('0x5d')]>0x1){_0x859247[_0x464466](_0x4acf('0x63'),qs['getFullTextValue'](_0x3382ad[_0x4acf('0x5f')]),null);}else{var _0x33de1c='%'+_0x3382ad['value']+'%';_0x859247[_0x464466](_0x4acf('0x64'),_0x33de1c,_0x33de1c,_0x33de1c);}}else{_0x3ad746=_[_0x4acf('0x5e')](_0x4ce916,[_0x4acf('0x2a'),_0x4acf('0x65')]);_0x3382ad['field']=_0x4acf('0x65');_0x26d4c7=as[_0x4acf('0x66')](_0xe96d97,_0x3ad746[_0x4acf('0x35')],_0x3382ad);_0x859247[_0x464466](_0x26d4c7[_0x4acf('0x67')],_0x26d4c7['value'][_0x4acf('0x68')],_0x26d4c7['value'][_0x4acf('0x1c')]);}break;case'Tag':var _0x41afd2=_0x3382ad[_0x4acf('0x5f')][_0x4acf('0x31')](',')[_0x4acf('0x2d')](function(_0x547128){return Number(_0x547128);});_0x41afd2['forEach'](function(_0x4cb554){_0x34b447['or'](_0x4acf('0x69'),'%,'+_0x4cb554+',%');});_0x33b68=_[_0x4acf('0x6a')](_0x33b68,_0x41afd2);break;case'User':if(_0x3382ad[_0x4acf('0x6b')]===_0x4acf('0x6c')){_0x859247[_0x464466]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0x3382ad[_0x4acf('0x5f')]+'%',null);}else{_0x3ad746=_[_0x4acf('0x5e')](_0x4ce916,['name',_0x4acf('0x6d')]);_0x3382ad[_0x4acf('0x44')]=_0x4acf('0x6d');_0x26d4c7=as['buildExpression'](_0xe96d97,_0x3ad746[_0x4acf('0x35')],_0x3382ad);_0x859247[_0x464466](_0x26d4c7[_0x4acf('0x67')],_0x26d4c7[_0x4acf('0x5f')][_0x4acf('0x68')],_0x26d4c7['value'][_0x4acf('0x1c')]);}break;case _0x4acf('0x6e'):_0x26d4c7=as[_0x4acf('0x66')]('me',null,_0x3382ad);_0x859247[_0x464466](_0x26d4c7['text'],_0x26d4c7[_0x4acf('0x5f')][_0x4acf('0x68')],_0x26d4c7[_0x4acf('0x5f')][_0x4acf('0x1c')]);break;}}else{var _0x26d4c7=as[_0x4acf('0x66')](_0xe96d97,_0x3ad746[_0x4acf('0x35')],_0x3382ad);_0x859247[_0x464466](_0x26d4c7[_0x4acf('0x67')],_0x26d4c7[_0x4acf('0x5f')][_0x4acf('0x68')],_0x26d4c7[_0x4acf('0x5f')][_0x4acf('0x1c')]);}}}else{var _0x237c8b=_(_0xfd8ab5[_0x4acf('0x38')])[_0x4acf('0x39')]()['map'](function(_0x262b6d){return _[_0x4acf('0x6f')](_0x4ce916,[_0x4acf('0x2a'),_0x262b6d])?_0x262b6d:undefined;})[_0x4acf('0x70')]()[_0x4acf('0x5f')]();if(!_[_0x4acf('0x71')](_0x237c8b)){_0x237c8b[_0x4acf('0x32')](function(_0x2845b5){if(_0x2845b5==='SmsAccountId'){_0x54b2a8['where'](_0x4acf('0x72'),[]['concat'](_0xfd8ab5[_0x4acf('0x38')][_0x2845b5]));}else if(_0x2845b5==='createdAt'){var _0x4dd618=JSON['parse'](_0xfd8ab5[_0x4acf('0x38')][_0x2845b5])[_0x4acf('0x73')];var _0x3b9ed2=JSON[_0x4acf('0x74')](_0xfd8ab5[_0x4acf('0x38')][_0x2845b5])[_0x4acf('0x75')];_0x54b2a8['where']('i.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x4dd618,_0x3b9ed2);}else{if(_0xfd8ab5['query'][_0x2845b5]===_0x4acf('0x76')){_0x54b2a8[_0x4acf('0x41')]('i.'+_0x2845b5+_0x4acf('0x77'));}else{_0x54b2a8['where']('i.'+_0x2845b5+_0x4acf('0x78'),_0xfd8ab5[_0x4acf('0x38')][_0x2845b5]);}}});}if(_0xfd8ab5[_0x4acf('0x38')][_0x4acf('0x79')]){if(_0xfd8ab5[_0x4acf('0x38')][_0x4acf('0x79')]==0x1){_0x54b2a8['having'](_0x4acf('0x7a'));}else{_0x54b2a8['having'](_0x4acf('0x7b'));}}if(_0xfd8ab5[_0x4acf('0x38')][_0x4acf('0x7c')]){_0x33b68=_[_0x4acf('0x7d')](_0xfd8ab5[_0x4acf('0x38')][_0x4acf('0x7c')])?_0xfd8ab5[_0x4acf('0x38')][_0x4acf('0x7c')]:new Array(_0xfd8ab5[_0x4acf('0x38')][_0x4acf('0x7c')]);_0x33b68[_0x4acf('0x32')](function(_0x203734){_0x34b447['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x203734+',%');});}if(_0xfd8ab5[_0x4acf('0x38')][_0x4acf('0x7e')]){var _0x40790e=_0xfd8ab5[_0x4acf('0x38')][_0x4acf('0x7e')][_0x4acf('0x7f')]('\x5c','\x5c\x5c')[_0x4acf('0x7f')]('\x27\x27',_0x4acf('0x80'));if(qs[_0x4acf('0x81')](_0x40790e)){_0x859247['or'](_0x4acf('0x82'),_0x40790e+'%')['or']('i.phone\x20LIKE\x20?',_0x40790e+'%');}else{_0x859247['or'](_0x4acf('0x83'),qs[_0x4acf('0x84')](_0x40790e))['or']('CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?',_0x40790e+'%');}}}_0x54b2a8[_0x4acf('0x41')](_0x859247);_0x54b2a8[_0x4acf('0x85')]('i.id');var _0x1fbf31={'type':db['Sequelize']['QueryTypes'][_0x4acf('0x86')],'raw':!![]};var _0x50bc20=_0x54b2a8[_0x4acf('0x87')]();_0x50bc20[_0x4acf('0x44')](_0x4acf('0x88'));_0x50bc20[_0x4acf('0x44')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x4acf('0x89'));if(_0x4cd020[_0x4acf('0x3f')]){_0x4cd020['order']['forEach'](function(_0x47e558){_0x54b2a8[_0x4acf('0x3f')]('i.'+_0x47e558[0x0],_0x47e558[0x1]==='DESC'?![]:!![]);});}if(!_[_0x4acf('0x71')](_0x33b68)){_0x54b2a8[_0x4acf('0x60')](_0x34b447);_0x50bc20[_0x4acf('0x41')]('t.id\x20IN\x20?',_0x33b68);}BPromise[_0x4acf('0x8a')]()[_0x4acf('0x27')](function(){if(!_0x32d212){if(_0xfd8ab5['query'][_0x4acf('0x8b')]||_0xfd8ab5[_0x4acf('0x38')]['journey'])return;_0x50bc20[_0x4acf('0x41')](_0x4acf('0x8c'));_0x54b2a8[_0x4acf('0x41')](_0x4acf('0x8c'));return;}return _0xfd8ab5[_0x4acf('0x8d')][_0x4acf('0x8e')]({'attributes':['id'],'raw':!![]})['then'](function(_0x208157){if(_['isEmpty'](_0x208157)){_0x50bc20[_0x4acf('0x41')](_0x4acf('0x8f'));_0x54b2a8['where']('i.SmsAccountId\x20IS\x20NULL');}else{_0x50bc20['where'](_0x4acf('0x72'),_['map'](_0x208157,'id'));_0x54b2a8['where']('i.SmsAccountId\x20IN\x20?',_[_0x4acf('0x2d')](_0x208157,'id'));}});})['then'](function(){db[_0x4acf('0x90')][_0x4acf('0x38')](_0x50bc20[_0x4acf('0x91')](),_0x1fbf31)[_0x4acf('0x27')](function(_0x41b415){_0x4bd85c['count']=_0x41b415['length'];if(_0x4bd85c[_0x4acf('0x1e')]===0x0)return[];return db[_0x4acf('0x90')][_0x4acf('0x38')](_0x461547[_0x4acf('0x91')](),_0x1fbf31)[_0x4acf('0x27')](function(_0x579d4e){_0x17d5e9=_[_0x4acf('0x92')](_0x579d4e,'id');_0x1fbf31=_[_0x4acf('0x93')](_0x1fbf31,{'model':db[_0x4acf('0x94')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0xfd8ab5[_0x4acf('0x38')][_0x4acf('0x3d')]){_0x4cd020[_0x4acf('0x3c')][_0x4acf('0x32')](function(_0x5b3925){_0x54b2a8[_0x4acf('0x44')]('i.'+_0x5b3925);});}else{_0x54b2a8['field'](_0x4acf('0x95'),_0x4acf('0x89'));_0x54b2a8[_0x4acf('0x44')](_0x4acf('0x96'),_0x4acf('0x97'));_0x54b2a8['field'](_0x4acf('0x98'),'Account.mandatoryDisposition');_0x54b2a8[_0x4acf('0x44')](_0x4acf('0x99'));_0x54b2a8['field'](_0x4acf('0x9a'),_0x4acf('0x9b'));_0x54b2a8[_0x4acf('0x44')](_0x4acf('0x9c'),_0x4acf('0x9d'));_0x54b2a8['field'](_0x4acf('0x9e'),'Contact.email');_0x54b2a8['field'](_0x4acf('0x9f'),_0x4acf('0xa0'));_0x54b2a8[_0x4acf('0x44')](_0x4acf('0xa1'),'Contact.mobile');_0x54b2a8['field'](_0x4acf('0xa2'),_0x4acf('0xa3'));_0x54b2a8[_0x4acf('0x44')](_0x4acf('0xa4'),_0x4acf('0xa5'));_0x54b2a8[_0x4acf('0x44')](_0x4acf('0xa6'),_0x4acf('0xa7'));_0x54b2a8['field']('GROUP_CONCAT(DISTINCT\x20t.id)',_0x4acf('0x2f'));}_0x54b2a8[_0x4acf('0x20')](_0x4cd020[_0x4acf('0x20')]);_0x54b2a8[_0x4acf('0x1f')](_0x4cd020[_0x4acf('0x1f')]);return db[_0x4acf('0x90')][_0x4acf('0x38')](_0x54b2a8[_0x4acf('0x91')](),_0x1fbf31);})[_0x4acf('0x27')](function(_0x4c2904){_0x58bc5d[_0x4acf('0x41')](_0x4acf('0xa8'),_[_0x4acf('0x2d')](_0x4c2904,'id'));return db[_0x4acf('0x90')][_0x4acf('0x38')](_0x58bc5d[_0x4acf('0x91')](),_0x1fbf31)[_0x4acf('0x27')](function(_0x1c57ce){var _0x37870c=_[_0x4acf('0xa9')](_0x1c57ce,_0x4acf('0xaa'));var _0x467114=[];_0x4c2904[_0x4acf('0x32')](function(_0x4ce149){_0x467114[_0x4acf('0xab')](updateSmsInteraction(_0x4ce149,_0x17d5e9,_0x37870c));});return BPromise['all'](_0x467114);});});})[_0x4acf('0x27')](function(_0x322e45){_0x4bd85c['rows']=_0x322e45;return _0x4bd85c;})[_0x4acf('0x27')](respondWithFilteredResult(_0x543a37,_0x4cd020));})[_0x4acf('0x33')](handleError(_0x543a37,null));};exports['show']=function(_0x555160,_0x175c91){var _0x440d48={'raw':![],'where':{'id':_0x555160['params']['id']}},_0x4f239f={};_0x4f239f[_0x4acf('0x37')]=_[_0x4acf('0x39')](db[_0x4acf('0x94')][_0x4acf('0x34')]);_0x4f239f['query']=_[_0x4acf('0x39')](_0x555160[_0x4acf('0x38')]);_0x4f239f[_0x4acf('0x3a')]=_[_0x4acf('0x3b')](_0x4f239f[_0x4acf('0x37')],_0x4f239f[_0x4acf('0x38')]);_0x440d48[_0x4acf('0x3c')]=_['intersection'](_0x4f239f[_0x4acf('0x37')],qs[_0x4acf('0x3d')](_0x555160[_0x4acf('0x38')]['fields']));_0x440d48[_0x4acf('0x3c')]=_0x440d48[_0x4acf('0x3c')][_0x4acf('0x5d')]?_0x440d48[_0x4acf('0x3c')]:_0x4f239f[_0x4acf('0x37')];if(_0x555160[_0x4acf('0x38')][_0x4acf('0xac')]){_0x440d48[_0x4acf('0xad')]=[{'all':!![]}];}_0x440d48=_['merge']({},_0x440d48,_0x555160['options']);return db['SmsInteraction']['find'](_0x440d48)['then'](handleEntityNotFound(_0x175c91,null))[_0x4acf('0x27')](respondWithResult(_0x175c91,null))['catch'](handleError(_0x175c91,null));};exports[_0x4acf('0xae')]=function(_0x454035,_0x59596e){return db[_0x4acf('0x94')][_0x4acf('0xae')](_0x454035[_0x4acf('0x6e')],{})[_0x4acf('0x27')](respondWithResult(_0x59596e,0xc9))[_0x4acf('0x33')](handleError(_0x59596e,null));};exports[_0x4acf('0x26')]=function(_0x420beb,_0x29beb3){if(_0x420beb[_0x4acf('0x6e')]['id']){delete _0x420beb[_0x4acf('0x6e')]['id'];}return db[_0x4acf('0x94')][_0x4acf('0x5e')]({'where':{'id':_0x420beb[_0x4acf('0xaf')]['id']}})[_0x4acf('0x27')](handleEntityNotFound(_0x29beb3,null))[_0x4acf('0x27')](saveUpdates(_0x420beb[_0x4acf('0x6e')],null))[_0x4acf('0x27')](respondWithResult(_0x29beb3,null))['catch'](handleError(_0x29beb3,null));};exports['destroy']=function(_0x16ac70,_0x1a7a89){return db[_0x4acf('0x94')][_0x4acf('0x5e')]({'where':{'id':_0x16ac70[_0x4acf('0xaf')]['id']}})[_0x4acf('0x27')](handleEntityNotFound(_0x1a7a89,null))[_0x4acf('0x27')](removeEntity(_0x1a7a89,null))[_0x4acf('0x33')](handleError(_0x1a7a89,null));};exports[_0x4acf('0xb0')]=function(_0x39151c,_0x43aff6){return db[_0x4acf('0x94')]['describe']()['then'](respondWithResult(_0x43aff6,null))[_0x4acf('0x33')](handleError(_0x43aff6,null));};exports[_0x4acf('0xb1')]=function(_0x343b84,_0xa57498,_0x336ef5){return db[_0x4acf('0xb2')]['find']({'where':{'id':_0x343b84[_0x4acf('0xaf')]['id']}})[_0x4acf('0x27')](handleEntityNotFound(_0xa57498,null))[_0x4acf('0x27')](function(_0x5146fc){if(_0x5146fc){return _0x5146fc[_0x4acf('0xb1')](_0x343b84[_0x4acf('0x6e')][_0x4acf('0xb3')],_[_0x4acf('0xb4')](_0x343b84[_0x4acf('0x6e')],[_0x4acf('0xb3'),'id'])||{});}})[_0x4acf('0x27')](respondWithResult(_0xa57498,null))[_0x4acf('0x33')](handleError(_0xa57498,null));};exports[_0x4acf('0xb5')]=function(_0x4eb713,_0x371ab5,_0x56b4d5){var _0x483069={'raw':![],'where':{}};var _0xfd74f={};var _0x135a82={'count':0x0,'rows':[]};return db[_0x4acf('0x94')][_0x4acf('0xb6')]({'where':{'id':_0x4eb713[_0x4acf('0xaf')]['id']}})[_0x4acf('0x27')](handleEntityNotFound(_0x371ab5,null))[_0x4acf('0x27')](function(_0x1aa0c5){if(_0x1aa0c5){_0xfd74f['model']=_[_0x4acf('0x39')](db[_0x4acf('0xb2')][_0x4acf('0x34')]);_0xfd74f[_0x4acf('0x38')]=_[_0x4acf('0x39')](_0x4eb713[_0x4acf('0x38')]);_0xfd74f['filters']=_[_0x4acf('0x3b')](_0xfd74f[_0x4acf('0x37')],_0xfd74f[_0x4acf('0x38')]);_0x483069[_0x4acf('0x3c')]=_[_0x4acf('0x3b')](_0xfd74f[_0x4acf('0x37')],qs[_0x4acf('0x3d')](_0x4eb713['query'][_0x4acf('0x3d')]));_0x483069[_0x4acf('0x3c')]=_0x483069['attributes'][_0x4acf('0x5d')]?_0x483069[_0x4acf('0x3c')]:_0xfd74f[_0x4acf('0x37')];if(!_0x4eb713[_0x4acf('0x38')]['hasOwnProperty'](_0x4acf('0xb7'))){_0x483069[_0x4acf('0x20')]=qs[_0x4acf('0x20')](_0x4eb713[_0x4acf('0x38')][_0x4acf('0x20')]);_0x483069[_0x4acf('0x1f')]=qs[_0x4acf('0x1f')](_0x4eb713[_0x4acf('0x38')][_0x4acf('0x1f')]);}_0x483069[_0x4acf('0x3f')]=qs[_0x4acf('0x40')](_0x4eb713[_0x4acf('0x38')][_0x4acf('0x40')]);_0x483069[_0x4acf('0x41')]=qs[_0x4acf('0x3a')](_[_0x4acf('0x42')](_0x4eb713['query'],_0xfd74f[_0x4acf('0x3a')]));_0x483069[_0x4acf('0x41')][_0x4acf('0xaa')]=_0x1aa0c5['id'];if(_0x4eb713[_0x4acf('0x38')][_0x4acf('0x7e')]){_0x483069[_0x4acf('0x41')]=_['merge'](_0x483069[_0x4acf('0x41')],{'$or':_['map'](_0x483069['attributes'],function(_0x175059){var _0x5d5f6e={};_0x5d5f6e[_0x175059]={'$like':'%'+_0x4eb713[_0x4acf('0x38')][_0x4acf('0x7e')]+'%'};return _0x5d5f6e;})});}if(_0x4eb713[_0x4acf('0x38')][_0x4acf('0x73')]){var _0x361c03=_0x4eb713[_0x4acf('0x38')][_0x4acf('0x73')]['split'](',');var _0x10aa8b={};_0x10aa8b[_0x361c03[0x0]]={'$gte':moment(_0x361c03[0x1])[_0x4acf('0xb8')](_0x4acf('0xb9'))};_0x483069[_0x4acf('0x41')]=_[_0x4acf('0x93')](_0x483069[_0x4acf('0x41')],_0x10aa8b);}_0x483069=_[_0x4acf('0x93')]({},_0x483069,_0x4eb713[_0x4acf('0xba')]);return db[_0x4acf('0xb2')][_0x4acf('0x1e')]({'where':_0x483069[_0x4acf('0x41')]})['then'](function(_0xbb57af){_0x135a82[_0x4acf('0x1e')]=_0xbb57af;if(_0x4eb713['query'][_0x4acf('0xac')]){_0x483069[_0x4acf('0xad')]=[{'all':!![]}];}return db[_0x4acf('0xb2')][_0x4acf('0xbb')](_0x483069);})[_0x4acf('0x27')](function(_0xcb7c90){_0x135a82['rows']=_0xcb7c90;return _0x135a82;});}})[_0x4acf('0x27')](respondWithFilteredResult(_0x371ab5,_0x483069))[_0x4acf('0x33')](handleError(_0x371ab5,null));};exports['addTags']=function(_0x4c7835,_0x26d915,_0x1cbb04){return db['SmsInteraction'][_0x4acf('0x5e')]({'where':{'id':_0x4c7835['params']['id']}})[_0x4acf('0x27')](handleEntityNotFound(_0x26d915,null))[_0x4acf('0x27')](function(_0x1e5b19){if(_0x1e5b19){return _0x1e5b19[_0x4acf('0xbc')](_0x4c7835[_0x4acf('0x6e')][_0x4acf('0xb3')],_[_0x4acf('0xb4')](_0x4c7835[_0x4acf('0x6e')],[_0x4acf('0xb3'),'id'])||{})[_0x4acf('0xbd')](function(){return db[_0x4acf('0xbe')][_0x4acf('0xbb')]({'attributes':['id',_0x4acf('0x2a'),_0x4acf('0x45')],'where':{'id':_0x4c7835[_0x4acf('0x6e')][_0x4acf('0xb3')]}});})[_0x4acf('0x27')](function(_0x30953f){socket['emit'](_0x4acf('0xbf'),{'id':Number(_0x4c7835[_0x4acf('0xaf')]['id']),'tags':_0x30953f||[]});return{'id':Number(_0x4c7835[_0x4acf('0xaf')]['id']),'tags':_0x30953f||[]};});}})['then'](respondWithResult(_0x26d915,null))[_0x4acf('0x33')](handleError(_0x26d915,null));};exports[_0x4acf('0xc0')]=function(_0x3f135c,_0x44b3ba,_0x23c6dc){return db[_0x4acf('0x94')][_0x4acf('0x5e')]({'where':{'id':_0x3f135c[_0x4acf('0xaf')]['id']}})[_0x4acf('0x27')](handleEntityNotFound(_0x44b3ba,null))[_0x4acf('0x27')](function(_0x3cec97){if(_0x3cec97){return _0x3cec97[_0x4acf('0xc0')](_0x3f135c[_0x4acf('0x38')][_0x4acf('0xb3')]);}})[_0x4acf('0x27')](respondWithStatusCode(_0x44b3ba,null))[_0x4acf('0x33')](handleError(_0x44b3ba,null));};exports[_0x4acf('0xc1')]=function(_0x1a63d7,_0x24c5d5){var _0x4ce265=moment()['unix']()[_0x4acf('0x91')]();var _0x197c12=path[_0x4acf('0xc2')](config[_0x4acf('0xc3')],_0x4acf('0xc4'),_0x4acf('0xc5'),_0x4acf('0xc6'));var _0x4b7a65=path[_0x4acf('0xc2')](config['root'],_0x4acf('0xc4'),_0x4acf('0xc5'),_0x4acf('0xc7'));var _0x12a9ab=path[_0x4acf('0xc2')](_0x197c12,_0x4ce265);var _0x45c320=util[_0x4acf('0xb8')](_0x4acf('0xc8'),_0x1a63d7[_0x4acf('0xaf')]['id'],_0x4ce265);var _0x57749b=path[_0x4acf('0xc2')](_0x197c12,_0x45c320);var _0x554d93=[];_0x554d93[_0x4acf('0xab')]({'model':db[_0x4acf('0xc9')],'as':_0x4acf('0xc9'),'attributes':['id','fullname'],'raw':!![]});_0x554d93[_0x4acf('0xab')]({'model':db[_0x4acf('0xca')],'as':_0x4acf('0x62'),'attributes':['id',_0x4acf('0xcb'),_0x4acf('0xcc')],'raw':!![]});var _0x349a78=[{'model':db[_0x4acf('0xb2')],'as':_0x4acf('0xcd'),'attributes':['id',_0x4acf('0x6e'),_0x4acf('0xce'),_0x4acf('0xcf'),_0x4acf('0xd0'),'read'],'include':_0x554d93}];_0x349a78['push']({'model':db[_0x4acf('0xd1')],'as':_0x4acf('0xd2'),'attributes':['id',_0x4acf('0x2a')]});_0x349a78[_0x4acf('0xab')]({'model':db[_0x4acf('0xc9')],'as':_0x4acf('0xd3'),'attributes':['id',_0x4acf('0x2e')]});return db[_0x4acf('0x94')]['find']({'where':{'id':_0x1a63d7[_0x4acf('0xaf')]['id']},'include':_0x349a78})['then'](handleEntityNotFound(_0x24c5d5,null))['then'](function(_0xb578c9){if(_0xb578c9){var _0xb0a748=_0xb578c9[_0x4acf('0xd4')]({'plain':!![]});fs['mkdirSync'](_0x12a9ab);var _0x4c12f0={'format':'A4','border':_0x4acf('0xd5'),'header':{'height':_0x4acf('0xd6'),'contents':{'first':_0x4acf('0xd7')}},'footer':{'height':_0x4acf('0xd8'),'contents':{'default':util['format'](_0x4acf('0xd9'),util[_0x4acf('0xb8')]('%s\x20#%d',_0x4acf('0xda'),_0xb0a748['id']),moment()[_0x4acf('0xb8')](_0x4acf('0xdb'))[_0x4acf('0x91')]())}}};var _0x156e4e={'channel':'Sms','account':_0xb0a748[_0x4acf('0xd2')][_0x4acf('0x2a')],'agent':_0xb0a748[_0x4acf('0xd3')]?_0xb0a748[_0x4acf('0xd3')]['fullname']:_0x4acf('0xdc'),'createdAt':moment(_0xb0a748[_0x4acf('0xce')])[_0x4acf('0xb8')](_0x4acf('0xb9'))[_0x4acf('0x91')](),'closedAt':_0xb0a748[_0x4acf('0xdd')]?moment(_0xb0a748['closedAt'])[_0x4acf('0xb8')](_0x4acf('0xb9'))[_0x4acf('0x91')]():'','disposition':_0xb0a748[_0x4acf('0xde')],'messages':_(_0xb0a748[_0x4acf('0xcd')])[_0x4acf('0x7e')]({'secret':![]})[_0x4acf('0x2d')](function(_0x347051){return{'date':moment(_0x347051[_0x4acf('0xce')])['format'](_0x4acf('0xb9'))[_0x4acf('0x91')](),'sender':_0x347051[_0x4acf('0xcf')]==='out'?_0x347051[_0x4acf('0xc9')]?_0x347051[_0x4acf('0xc9')][_0x4acf('0x2e')]:'System':_0x347051['Contact'][_0x4acf('0xcb')]+(_0x347051[_0x4acf('0x62')][_0x4acf('0xcc')]?'\x20'+_0x347051[_0x4acf('0x62')][_0x4acf('0xcc')]:''),'body':_0x347051[_0x4acf('0x6e')],'direction':_0x347051['direction']===_0x4acf('0xdf')?'A':'C','secret':_0x347051[_0x4acf('0xd0')],'read':_0x347051['read']};})['value']()};return ejs['renderFile'](path[_0x4acf('0xc2')](config[_0x4acf('0xc3')],'server',_0x4acf('0xe0'),'downloadInteraction.html'),{'interaction':_0x156e4e})[_0x4acf('0x27')](function(_0x28d215){return new BPromise(function(_0x5c95b0,_0x2017ad){pdf[_0x4acf('0xae')](_0x28d215,_0x4c12f0)[_0x4acf('0xe1')](path[_0x4acf('0xc2')](_0x12a9ab,'transcript-'+_0xb0a748['id']+'-'+_0x4ce265+_0x4acf('0xe2')),function(_0xd6e40,_0x4298de){if(_0xd6e40)return _0x2017ad(_0xd6e40);_0x5c95b0(_0x4298de);});});})[_0x4acf('0x27')](function(){return new BPromise(function(_0x5a10bf,_0x4b9452){zipdir(_0x12a9ab,{'saveTo':_0x57749b},function(_0x424aa0,_0x170eeb){if(_0x424aa0)return _0x4b9452(_0x424aa0);return _0x5a10bf(_0x170eeb);});})[_0x4acf('0x27')](function(){return new BPromise(function(_0x442c67,_0x5e433c){rimraf(_0x12a9ab,function(_0x411333){if(_0x411333)_0x5e433c(_0x411333);return _0x442c67();});});})['then'](function(){return _0x24c5d5[_0x4acf('0xc1')](_0x57749b,_0x45c320,function(_0x86cbc7){if(_0x86cbc7){console[_0x4acf('0xe3')]('err',_0x86cbc7);}else{fs[_0x4acf('0xe4')](_0x57749b);}});});});}else{return _0x24c5d5[_0x4acf('0x1b')](0xc8);}})['catch'](handleError(_0x24c5d5,null));};
\ No newline at end of file
+var _0x16cd=['where','i.SmsAccountId\x20IN\x20?','createdAt','parse','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','i.id\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','i.id','Sequelize','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','t.id\x20IN\x20?','resolve','journey','i.SmsAccountId\x20IS\x20NOT\x20NULL','user','role','getSmsAccounts','agent','toString','sequelize','keyBy','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','contactName','i.*','Contact.firstName','c.lastName','Contact.lastName','Contact.email','c.phone','Contact.phone','c.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','SmsInteractionId','rows','catch','params','includeAll','include','options','create','update','describe','addMessage','ids','omit','findOne','SmsMessage','nolimit','merge','$gte','format','YYYY-MM-DD\x20HH:mm:ss','findAll','addTags','spread','emit','smsInteractionTags:save','join','root','server','files','attachments','CmContact','lastName','Messages','direction','SmsAccount','Account','mkdirSync','10px','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>','%s\x20#%d','Sms','YYYY-MM-DD','Owner','closed','closedAt','out','firstName','secret','renderFile','downloadInteraction.html','toFile','transcript-','.pdf','download','log','err','unlinkSync','html-pdf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','to-csv','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./smsInteraction.socket','register','sendStatus','status','count','offset','limit','set','Content-Range','json','apply','save','then','destroy','end','stack','send','Users','fullname','TagIds','forEach','Tags','push','index','SmsInteraction','rawAttributes','type','key','map','name','query','keys','filters','intersection','model','fields','attributes','hasOwnProperty','order','sort','pick','field','color','from','select','u.id','u.fullname','ui.SmsInteractionId','user_has_sms_interactions','left_join','users','u.id\x20=\x20ui.UserId','sms_interactions','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','sms_accounts','sms_messages','sms_interaction_has_tags','tools_tags','t.id\x20=\x20it.TagId','expr','search','parseSearch','conditions','length','find','unreadMessages','value','having','`\x20=\x200','Contact','operator','$substring','split','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','text','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','buildExpression','body','some','compact','isEmpty','SmsAccountId'];(function(_0x2681d4,_0x4806f2){var _0x40d09e=function(_0x817e14){while(--_0x817e14){_0x2681d4['push'](_0x2681d4['shift']());}};_0x40d09e(++_0x4806f2);}(_0x16cd,0x15d));var _0xd16c=function(_0x334599,_0x4b1cfa){_0x334599=_0x334599-0x0;var _0x4cdff2=_0x16cd[_0x334599];return _0x4cdff2;};'use strict';var pdf=require(_0xd16c('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xd16c('0x1'));var jsonpatch=require(_0xd16c('0x2'));var rp=require(_0xd16c('0x3'));var moment=require(_0xd16c('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xd16c('0x5'));var util=require(_0xd16c('0x6'));var path=require(_0xd16c('0x7'));var sox=require('sox');var csv=require(_0xd16c('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xd16c('0x9'));var squel=require('squel');var crypto=require(_0xd16c('0xa'));var jsforce=require(_0xd16c('0xb'));var deskjs=require(_0xd16c('0xc'));var toCsv=require(_0xd16c('0x8'));var querystring=require(_0xd16c('0xd'));var Papa=require(_0xd16c('0xe'));var Redis=require(_0xd16c('0xf'));var authService=require(_0xd16c('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0xd16c('0x11'));var hardwareService=require(_0xd16c('0x12'));var logger=require(_0xd16c('0x13'))(_0xd16c('0x14'));var utils=require(_0xd16c('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xd16c('0x16'));var db=require(_0xd16c('0x17'))['db'];config[_0xd16c('0x18')]=_['defaults'](config['redis'],{'host':_0xd16c('0x19'),'port':0x18eb});var socket=require(_0xd16c('0x1a'))(new Redis(config[_0xd16c('0x18')]));require(_0xd16c('0x1b'))[_0xd16c('0x1c')](socket);function respondWithStatusCode(_0x375ce2,_0x452c3e){_0x452c3e=_0x452c3e||0xcc;return function(_0x30c855){if(_0x30c855){return _0x375ce2[_0xd16c('0x1d')](_0x452c3e);}return _0x375ce2[_0xd16c('0x1e')](_0x452c3e)['end']();};}function respondWithResult(_0x2138a7,_0x44336a){_0x44336a=_0x44336a||0xc8;return function(_0x494d76){if(_0x494d76){return _0x2138a7[_0xd16c('0x1e')](_0x44336a)['json'](_0x494d76);}};}function respondWithFilteredResult(_0x423794,_0xb8cff9){return function(_0x374f1d){if(_0x374f1d){var _0x29c1cb=_0x374f1d[_0xd16c('0x1f')],_0x2b61fd=_0xb8cff9[_0xd16c('0x20')],_0x64eb41=_0xb8cff9['offset']+_0xb8cff9[_0xd16c('0x21')],_0x47d753;if(_0x64eb41>=_0x29c1cb){_0x64eb41=_0x29c1cb;_0x47d753=0xc8;}else{_0x47d753=0xce;}_0x423794[_0xd16c('0x1e')](_0x47d753);return _0x423794[_0xd16c('0x22')](_0xd16c('0x23'),_0x2b61fd+'-'+_0x64eb41+'/'+_0x29c1cb)[_0xd16c('0x24')](_0x374f1d);}return null;};}function patchUpdates(_0x1c4b9d){return function(_0x2993db){try{jsonpatch[_0xd16c('0x25')](_0x2993db,_0x1c4b9d,!![]);}catch(_0x9eb4a){return BPromise['reject'](_0x9eb4a);}return _0x2993db[_0xd16c('0x26')]();};}function saveUpdates(_0x2a2007,_0x57fdfc){return function(_0x2c912b){if(_0x2c912b){return _0x2c912b['update'](_0x2a2007)[_0xd16c('0x27')](function(_0x55db63){return _0x55db63;});}return null;};}function removeEntity(_0x575163,_0x28db1d){return function(_0x47ad57){if(_0x47ad57){return _0x47ad57[_0xd16c('0x28')]()['then'](function(){_0x575163[_0xd16c('0x1e')](0xcc)[_0xd16c('0x29')]();});}};}function handleEntityNotFound(_0x4873e8,_0x492111){return function(_0x1f4035){if(!_0x1f4035){_0x4873e8[_0xd16c('0x1d')](0x194);}return _0x1f4035;};}function handleError(_0x1a21ba,_0x14683f){_0x14683f=_0x14683f||0x1f4;return function(_0x4c5b85){logger['error'](_0x4c5b85[_0xd16c('0x2a')]);if(_0x4c5b85['name']){delete _0x4c5b85['name'];}_0x1a21ba[_0xd16c('0x1e')](_0x14683f)[_0xd16c('0x2b')](_0x4c5b85);};}function getInteractionUsers(_0x213b17,_0x20d43b){return new BPromise(function(_0x2a5dfe,_0x5c5909){try{if(_0x20d43b[_0x213b17['id']]){_0x213b17[_0xd16c('0x2c')]=_['map'](_0x20d43b[_0x213b17['id']],function(_0x493707){return{'id':_0x493707['id'],'fullname':_0x493707[_0xd16c('0x2d')]};});}}catch(_0x5ce7e6){_0x5c5909(_0x5ce7e6);}_0x2a5dfe(_0x213b17);});}function getInteractionTags(_0xf745df,_0x5c1e33){return new BPromise(function(_0x25b93c,_0x43ca21){try{if(_0xf745df['TagIds']){_0xf745df['Tags']=[];_0xf745df[_0xd16c('0x2e')]['split'](',')[_0xd16c('0x2f')](function(_0xb86e81){_0xf745df[_0xd16c('0x30')][_0xd16c('0x31')](_0x5c1e33[_0xb86e81]);});}delete _0xf745df[_0xd16c('0x2e')];}catch(_0x3b8041){_0x43ca21(_0x3b8041);}_0x25b93c(_0xf745df);});}function updateSmsInteraction(_0x3847b1,_0x1fdbff,_0x3e74c7){return new BPromise(function(_0x568f01,_0x2352be){return getInteractionUsers(_0x3847b1,_0x3e74c7)[_0xd16c('0x27')](function(_0x4e49fe){return getInteractionTags(_0x4e49fe,_0x1fdbff);})[_0xd16c('0x27')](function(_0x2afe58){_0x568f01(_0x2afe58);})['catch'](function(_0x44bd9f){_0x2352be(_0x44bd9f);});});}exports[_0xd16c('0x32')]=function(_0x36e22d,_0xd73bc3){var _0x149197={},_0x3784e8={},_0xf72594={'count':0x0,'rows':[]};var _0x43c1d3=_['map'](db[_0xd16c('0x33')][_0xd16c('0x34')],function(_0x59568f){return{'name':_0x59568f['fieldName'],'type':_0x59568f[_0xd16c('0x35')][_0xd16c('0x36')]};});_0x3784e8['model']=_[_0xd16c('0x37')](_0x43c1d3,_0xd16c('0x38'));_0x3784e8[_0xd16c('0x39')]=_[_0xd16c('0x3a')](_0x36e22d[_0xd16c('0x39')]);_0x3784e8[_0xd16c('0x3b')]=_[_0xd16c('0x3c')](_0x3784e8['model'],_0x3784e8[_0xd16c('0x39')]);_0x149197['attributes']=_[_0xd16c('0x3c')](_0x3784e8[_0xd16c('0x3d')],qs[_0xd16c('0x3e')](_0x36e22d[_0xd16c('0x39')][_0xd16c('0x3e')]));_0x149197[_0xd16c('0x3f')]=_0x149197[_0xd16c('0x3f')]['length']?_0x149197[_0xd16c('0x3f')]:_0x3784e8[_0xd16c('0x3d')];if(!_0x36e22d['query'][_0xd16c('0x40')]('nolimit')){_0x149197[_0xd16c('0x21')]=qs[_0xd16c('0x21')](_0x36e22d['query'][_0xd16c('0x21')]);_0x149197[_0xd16c('0x20')]=qs['offset'](_0x36e22d['query']['offset']);}_0x149197[_0xd16c('0x41')]=qs['sort'](_0x36e22d[_0xd16c('0x39')][_0xd16c('0x42')]);_0x149197['where']=qs['filters'](_[_0xd16c('0x43')](_0x36e22d[_0xd16c('0x39')],_0x3784e8[_0xd16c('0x3b')]),_0x43c1d3);var _0x32b1e3=[];var _0x8d4de3=squel['select']()[_0xd16c('0x44')]('id')[_0xd16c('0x44')](_0xd16c('0x38'))['field'](_0xd16c('0x45'))[_0xd16c('0x46')]('tools_tags');var _0x4994c4=squel[_0xd16c('0x47')]()[_0xd16c('0x44')](_0xd16c('0x48'))['field'](_0xd16c('0x49'))[_0xd16c('0x44')](_0xd16c('0x4a'))[_0xd16c('0x46')](_0xd16c('0x4b'),'ui')[_0xd16c('0x4c')](_0xd16c('0x4d'),'u',_0xd16c('0x4e'));var _0x2144c6=squel[_0xd16c('0x47')]()[_0xd16c('0x46')](_0xd16c('0x4f'),'i')[_0xd16c('0x4c')]('cm_contacts','c',_0xd16c('0x50'))[_0xd16c('0x4c')](_0xd16c('0x4d'),'o',_0xd16c('0x51'))[_0xd16c('0x4c')](_0xd16c('0x52'),'a','a.id\x20=\x20i.SmsAccountId')[_0xd16c('0x4c')](_0xd16c('0x53'),'me','me.SmsInteractionId\x20=\x20i.id')['left_join'](_0xd16c('0x54'),'it','it.SmsInteractionId\x20=\x20i.id')[_0xd16c('0x4c')](_0xd16c('0x55'),'t',_0xd16c('0x56'));var _0xdc1e22=squel['expr']();var _0x36422a=[];var _0x4dc5b5=squel[_0xd16c('0x57')]();var _0x1d640e;if(_0x36e22d[_0xd16c('0x39')][_0xd16c('0x58')]){_0x1d640e=as[_0xd16c('0x59')](_0x36e22d[_0xd16c('0x39')][_0xd16c('0x58')]);var _0x5ecf4c=_0x1d640e['sqlOperator'];for(var _0x344bfe=0x0;_0x344bfe<_0x1d640e[_0xd16c('0x5a')][_0xd16c('0x5b')];_0x344bfe++){var _0x2cc255=_0x1d640e[_0xd16c('0x5a')][_0x344bfe];var _0x6900ec='i';var _0x113003=_[_0xd16c('0x5c')](_0x43c1d3,['name',_0x2cc255[_0xd16c('0x44')]]);if(!_0x113003){switch(_0x2cc255['field']){case _0xd16c('0x5d'):if(_0x2cc255[_0xd16c('0x5e')]==0x1){_0x2144c6[_0xd16c('0x5f')]('`'+_0x2cc255[_0xd16c('0x44')]+_0xd16c('0x60'));}else{_0x2144c6[_0xd16c('0x5f')]('`'+_0x2cc255[_0xd16c('0x44')]+'`\x20>\x200');}break;case _0xd16c('0x61'):if(_0x2cc255[_0xd16c('0x62')]===_0xd16c('0x63')){if(_0x2cc255[_0xd16c('0x5e')][_0xd16c('0x64')]('\x20')['length']>0x1){_0xdc1e22[_0x5ecf4c](_0xd16c('0x65'),qs[_0xd16c('0x66')](_0x2cc255[_0xd16c('0x5e')]),null);}else{var _0x509395='%'+_0x2cc255[_0xd16c('0x5e')]+'%';_0xdc1e22[_0x5ecf4c](_0xd16c('0x67'),_0x509395,_0x509395,_0x509395);}}else{_0x113003=_[_0xd16c('0x5c')](_0x43c1d3,[_0xd16c('0x38'),_0xd16c('0x68')]);_0x2cc255[_0xd16c('0x44')]=_0xd16c('0x68');_0x526541=as['buildExpression'](_0x6900ec,_0x113003[_0xd16c('0x35')],_0x2cc255);_0xdc1e22[_0x5ecf4c](_0x526541[_0xd16c('0x69')],_0x526541[_0xd16c('0x5e')][_0xd16c('0x6a')],_0x526541[_0xd16c('0x5e')]['end']);}break;case _0xd16c('0x6b'):var _0x59e25e=_0x2cc255[_0xd16c('0x5e')]['split'](',')[_0xd16c('0x37')](function(_0x248340){return Number(_0x248340);});_0x59e25e['forEach'](function(_0x29a3d0){_0x4dc5b5['or'](_0xd16c('0x6c'),'%,'+_0x29a3d0+',%');});_0x36422a=_[_0xd16c('0x6d')](_0x36422a,_0x59e25e);break;case _0xd16c('0x6e'):if(_0x2cc255[_0xd16c('0x62')]===_0xd16c('0x63')){_0xdc1e22[_0x5ecf4c](_0xd16c('0x6f'),'%'+_0x2cc255[_0xd16c('0x5e')]+'%',null);}else{_0x113003=_[_0xd16c('0x5c')](_0x43c1d3,['name',_0xd16c('0x70')]);_0x2cc255['field']=_0xd16c('0x70');_0x526541=as[_0xd16c('0x71')](_0x6900ec,_0x113003[_0xd16c('0x35')],_0x2cc255);_0xdc1e22[_0x5ecf4c](_0x526541[_0xd16c('0x69')],_0x526541[_0xd16c('0x5e')][_0xd16c('0x6a')],_0x526541[_0xd16c('0x5e')][_0xd16c('0x29')]);}break;case _0xd16c('0x72'):_0x526541=as[_0xd16c('0x71')]('me',null,_0x2cc255);_0xdc1e22[_0x5ecf4c](_0x526541[_0xd16c('0x69')],_0x526541[_0xd16c('0x5e')]['start'],_0x526541[_0xd16c('0x5e')][_0xd16c('0x29')]);break;}}else{var _0x526541=as['buildExpression'](_0x6900ec,_0x113003[_0xd16c('0x35')],_0x2cc255);_0xdc1e22[_0x5ecf4c](_0x526541[_0xd16c('0x69')],_0x526541[_0xd16c('0x5e')][_0xd16c('0x6a')],_0x526541['value']['end']);}}}else{var _0x291034=_(_0x36e22d['query'])[_0xd16c('0x3a')]()[_0xd16c('0x37')](function(_0x23514f){return _[_0xd16c('0x73')](_0x43c1d3,['name',_0x23514f])?_0x23514f:undefined;})[_0xd16c('0x74')]()['value']();if(!_[_0xd16c('0x75')](_0x291034)){_0x291034['forEach'](function(_0x3df940){if(_0x3df940===_0xd16c('0x76')){_0x2144c6[_0xd16c('0x77')](_0xd16c('0x78'),[]['concat'](_0x36e22d['query'][_0x3df940]));}else if(_0x3df940===_0xd16c('0x79')){var _0x2f299c=JSON['parse'](_0x36e22d[_0xd16c('0x39')][_0x3df940])['$gte'];var _0x1b9d08=JSON[_0xd16c('0x7a')](_0x36e22d[_0xd16c('0x39')][_0x3df940])[_0xd16c('0x7b')];_0x2144c6['where'](_0xd16c('0x7c'),_0x2f299c,_0x1b9d08);}else{if(_0x36e22d[_0xd16c('0x39')][_0x3df940]===_0xd16c('0x7d')){_0x2144c6[_0xd16c('0x77')]('i.'+_0x3df940+_0xd16c('0x7e'));}else{_0x2144c6[_0xd16c('0x77')]('i.'+_0x3df940+'\x20=\x20?',_0x36e22d['query'][_0x3df940]);}}});}if(_0x36e22d[_0xd16c('0x39')][_0xd16c('0x7f')]){if(_0x36e22d[_0xd16c('0x39')][_0xd16c('0x7f')]==0x1){_0x2144c6[_0xd16c('0x5f')](_0xd16c('0x80'));}else{_0x2144c6['having'](_0xd16c('0x81'));}}if(_0x36e22d[_0xd16c('0x39')][_0xd16c('0x82')]){_0x36422a=_[_0xd16c('0x83')](_0x36e22d[_0xd16c('0x39')][_0xd16c('0x82')])?_0x36e22d[_0xd16c('0x39')][_0xd16c('0x82')]:new Array(_0x36e22d[_0xd16c('0x39')][_0xd16c('0x82')]);_0x36422a[_0xd16c('0x2f')](function(_0x356636){_0x4dc5b5['or'](_0xd16c('0x6c'),'%,'+_0x356636+',%');});}if(_0x36e22d[_0xd16c('0x39')]['filter']){var _0x2dd096=_0x36e22d[_0xd16c('0x39')][_0xd16c('0x84')]['replace']('\x5c','\x5c\x5c')[_0xd16c('0x85')](/'/g,'\x27\x27');if(qs['isNumeric'](_0x2dd096)){_0xdc1e22['or'](_0xd16c('0x86'),_0x2dd096+'%')['or']('i.phone\x20LIKE\x20?',_0x2dd096+'%');}else{_0xdc1e22['or'](_0xd16c('0x87'),qs[_0xd16c('0x66')](_0x2dd096))['or'](_0xd16c('0x88'),_0x2dd096+'%');}}}_0x2144c6[_0xd16c('0x77')](_0xdc1e22);_0x2144c6['group'](_0xd16c('0x89'));var _0x565244={'type':db[_0xd16c('0x8a')][_0xd16c('0x8b')][_0xd16c('0x8c')],'raw':!![]};var _0x4843f5=_0x2144c6[_0xd16c('0x8d')]();_0x4843f5[_0xd16c('0x44')](_0xd16c('0x89'));_0x4843f5[_0xd16c('0x44')](_0xd16c('0x8e'),_0xd16c('0x5d'));if(_0x149197[_0xd16c('0x41')]){_0x149197[_0xd16c('0x41')]['forEach'](function(_0x39ca7b){var _0x4552d6=_0x39ca7b[0x0]==='contactName'?_0x39ca7b[0x0]:'i.'+_0x39ca7b[0x0];_0x2144c6[_0xd16c('0x41')](_0x4552d6,_0x39ca7b[0x1]==='DESC'?![]:!![]);});}if(!_[_0xd16c('0x75')](_0x36422a)){_0x2144c6[_0xd16c('0x5f')](_0x4dc5b5);_0x4843f5['where'](_0xd16c('0x8f'),_0x36422a);}BPromise[_0xd16c('0x90')]()['then'](function(){if(!_0x1d640e){if(_0x36e22d['query'][_0xd16c('0x76')]||_0x36e22d[_0xd16c('0x39')][_0xd16c('0x91')])return;_0x4843f5[_0xd16c('0x77')](_0xd16c('0x92'));_0x2144c6['where'](_0xd16c('0x92'));return;}if(_0x36e22d[_0xd16c('0x93')][_0xd16c('0x94')]!=='agent')return;return _0x36e22d[_0xd16c('0x93')][_0xd16c('0x95')]({'attributes':['id'],'raw':!![]})[_0xd16c('0x27')](function(_0x243659){if(_[_0xd16c('0x75')](_0x243659)){_0x4843f5['where']('i.SmsAccountId\x20IS\x20NULL');_0x2144c6[_0xd16c('0x77')]('i.SmsAccountId\x20IS\x20NULL');}else{_0x4843f5[_0xd16c('0x77')]('i.SmsAccountId\x20IN\x20?',_[_0xd16c('0x37')](_0x243659,'id'));_0x2144c6[_0xd16c('0x77')](_0xd16c('0x78'),_[_0xd16c('0x37')](_0x243659,'id'));}});})[_0xd16c('0x27')](function(){if(_0x36e22d[_0xd16c('0x93')]['role']===_0xd16c('0x96')&&!_0x1d640e&&!_0x36e22d[_0xd16c('0x39')][_0xd16c('0x76')])return[];return db['sequelize'][_0xd16c('0x39')](_0x4843f5[_0xd16c('0x97')](),_0x565244);})['then'](function(_0xcad032){_0xf72594[_0xd16c('0x1f')]=_0xcad032['length'];if(_0xf72594[_0xd16c('0x1f')]===0x0)return[];return db[_0xd16c('0x98')]['query'](_0x8d4de3[_0xd16c('0x97')](),_0x565244)['then'](function(_0x5f8e4a){_0x32b1e3=_[_0xd16c('0x99')](_0x5f8e4a,'id');_0x565244=_['merge'](_0x565244,{'model':db[_0xd16c('0x33')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x36e22d[_0xd16c('0x39')][_0xd16c('0x3e')]){_0x149197[_0xd16c('0x3f')][_0xd16c('0x2f')](function(_0xc78b6c){_0x2144c6['field']('i.'+_0xc78b6c);});}else{_0x2144c6[_0xd16c('0x44')](_0xd16c('0x8e'),_0xd16c('0x5d'));_0x2144c6[_0xd16c('0x44')](_0xd16c('0x9a'),_0xd16c('0x9b'));_0x2144c6[_0xd16c('0x44')](_0xd16c('0x9c'),_0xd16c('0x9d'));_0x2144c6['field'](_0xd16c('0x9e'),_0xd16c('0x9f'));_0x2144c6[_0xd16c('0x44')](_0xd16c('0xa0'));_0x2144c6['field']('c.firstName',_0xd16c('0xa1'));_0x2144c6[_0xd16c('0x44')](_0xd16c('0xa2'),_0xd16c('0xa3'));_0x2144c6[_0xd16c('0x44')]('c.email',_0xd16c('0xa4'));_0x2144c6[_0xd16c('0x44')](_0xd16c('0xa5'),_0xd16c('0xa6'));_0x2144c6[_0xd16c('0x44')](_0xd16c('0xa7'),'Contact.mobile');_0x2144c6[_0xd16c('0x44')](_0xd16c('0xa8'),_0xd16c('0xa9'));_0x2144c6[_0xd16c('0x44')](_0xd16c('0xaa'),_0xd16c('0xab'));_0x2144c6[_0xd16c('0x44')]('o.internal',_0xd16c('0xac'));_0x2144c6[_0xd16c('0x44')](_0xd16c('0xad'),'TagIds');}if(_0x149197['limit'])_0x2144c6[_0xd16c('0x21')](_0x149197[_0xd16c('0x21')]);if(_0x149197[_0xd16c('0x20')])_0x2144c6[_0xd16c('0x20')](_0x149197[_0xd16c('0x20')]);return db[_0xd16c('0x98')]['query'](_0x2144c6[_0xd16c('0x97')](),_0x565244);})[_0xd16c('0x27')](function(_0xee2aef){_0x4994c4[_0xd16c('0x77')]('ui.SmsInteractionId\x20IN\x20?',_[_0xd16c('0x37')](_0xee2aef,'id'));return db[_0xd16c('0x98')][_0xd16c('0x39')](_0x4994c4[_0xd16c('0x97')](),_0x565244)[_0xd16c('0x27')](function(_0x51cfa1){var _0x5678ee=_['groupBy'](_0x51cfa1,_0xd16c('0xae'));var _0x290941=[];_0xee2aef[_0xd16c('0x2f')](function(_0xa8deb9){_0x290941['push'](updateSmsInteraction(_0xa8deb9,_0x32b1e3,_0x5678ee));});return BPromise['all'](_0x290941);});});})[_0xd16c('0x27')](function(_0x13f6e7){_0xf72594[_0xd16c('0xaf')]=_0x13f6e7;return _0xf72594;})['then'](respondWithFilteredResult(_0xd73bc3,_0x149197))[_0xd16c('0xb0')](handleError(_0xd73bc3,null));};exports['show']=function(_0x33d302,_0x32a47d){var _0x947e30={'raw':![],'where':{'id':_0x33d302[_0xd16c('0xb1')]['id']}},_0x5d2db9={};_0x5d2db9[_0xd16c('0x3d')]=_['keys'](db[_0xd16c('0x33')][_0xd16c('0x34')]);_0x5d2db9[_0xd16c('0x39')]=_[_0xd16c('0x3a')](_0x33d302[_0xd16c('0x39')]);_0x5d2db9[_0xd16c('0x3b')]=_[_0xd16c('0x3c')](_0x5d2db9['model'],_0x5d2db9[_0xd16c('0x39')]);_0x947e30[_0xd16c('0x3f')]=_['intersection'](_0x5d2db9[_0xd16c('0x3d')],qs['fields'](_0x33d302[_0xd16c('0x39')]['fields']));_0x947e30[_0xd16c('0x3f')]=_0x947e30[_0xd16c('0x3f')][_0xd16c('0x5b')]?_0x947e30[_0xd16c('0x3f')]:_0x5d2db9[_0xd16c('0x3d')];if(_0x33d302[_0xd16c('0x39')][_0xd16c('0xb2')]){_0x947e30[_0xd16c('0xb3')]=[{'all':!![]}];}_0x947e30=_['merge']({},_0x947e30,_0x33d302[_0xd16c('0xb4')]);return db[_0xd16c('0x33')][_0xd16c('0x5c')](_0x947e30)[_0xd16c('0x27')](handleEntityNotFound(_0x32a47d,null))['then'](respondWithResult(_0x32a47d,null))[_0xd16c('0xb0')](handleError(_0x32a47d,null));};exports[_0xd16c('0xb5')]=function(_0xe9f740,_0x11c488){return db[_0xd16c('0x33')][_0xd16c('0xb5')](_0xe9f740['body'],{})[_0xd16c('0x27')](respondWithResult(_0x11c488,0xc9))[_0xd16c('0xb0')](handleError(_0x11c488,null));};exports[_0xd16c('0xb6')]=function(_0x5d3fe0,_0x4874e9){if(_0x5d3fe0[_0xd16c('0x72')]['id']){delete _0x5d3fe0[_0xd16c('0x72')]['id'];}return db[_0xd16c('0x33')][_0xd16c('0x5c')]({'where':{'id':_0x5d3fe0[_0xd16c('0xb1')]['id']}})[_0xd16c('0x27')](handleEntityNotFound(_0x4874e9,null))[_0xd16c('0x27')](saveUpdates(_0x5d3fe0[_0xd16c('0x72')],null))[_0xd16c('0x27')](respondWithResult(_0x4874e9,null))[_0xd16c('0xb0')](handleError(_0x4874e9,null));};exports[_0xd16c('0x28')]=function(_0x4dd64b,_0x19acfe){return db[_0xd16c('0x33')]['find']({'where':{'id':_0x4dd64b['params']['id']}})[_0xd16c('0x27')](handleEntityNotFound(_0x19acfe,null))[_0xd16c('0x27')](removeEntity(_0x19acfe,null))['catch'](handleError(_0x19acfe,null));};exports[_0xd16c('0xb7')]=function(_0x5e6606,_0x40f697){return db[_0xd16c('0x33')]['describe']()[_0xd16c('0x27')](respondWithResult(_0x40f697,null))[_0xd16c('0xb0')](handleError(_0x40f697,null));};exports['addMessage']=function(_0x50180d,_0x4f0721,_0x2d943a){return db['SmsMessage'][_0xd16c('0x5c')]({'where':{'id':_0x50180d['params']['id']}})[_0xd16c('0x27')](handleEntityNotFound(_0x4f0721,null))[_0xd16c('0x27')](function(_0x360115){if(_0x360115){return _0x360115[_0xd16c('0xb8')](_0x50180d['body'][_0xd16c('0xb9')],_[_0xd16c('0xba')](_0x50180d['body'],['ids','id'])||{});}})[_0xd16c('0x27')](respondWithResult(_0x4f0721,null))[_0xd16c('0xb0')](handleError(_0x4f0721,null));};exports['getMessages']=function(_0x39d208,_0x3e1843,_0x4ef01c){var _0x5ed571={'raw':![],'where':{}};var _0x240347={};var _0x11443f={'count':0x0,'rows':[]};return db[_0xd16c('0x33')][_0xd16c('0xbb')]({'where':{'id':_0x39d208[_0xd16c('0xb1')]['id']}})[_0xd16c('0x27')](handleEntityNotFound(_0x3e1843,null))[_0xd16c('0x27')](function(_0xe14f10){if(_0xe14f10){_0x240347['model']=_[_0xd16c('0x3a')](db[_0xd16c('0xbc')][_0xd16c('0x34')]);_0x240347['query']=_[_0xd16c('0x3a')](_0x39d208[_0xd16c('0x39')]);_0x240347[_0xd16c('0x3b')]=_[_0xd16c('0x3c')](_0x240347['model'],_0x240347['query']);_0x5ed571[_0xd16c('0x3f')]=_[_0xd16c('0x3c')](_0x240347[_0xd16c('0x3d')],qs[_0xd16c('0x3e')](_0x39d208[_0xd16c('0x39')][_0xd16c('0x3e')]));_0x5ed571[_0xd16c('0x3f')]=_0x5ed571[_0xd16c('0x3f')][_0xd16c('0x5b')]?_0x5ed571[_0xd16c('0x3f')]:_0x240347[_0xd16c('0x3d')];if(!_0x39d208['query'][_0xd16c('0x40')](_0xd16c('0xbd'))){_0x5ed571[_0xd16c('0x21')]=qs[_0xd16c('0x21')](_0x39d208[_0xd16c('0x39')][_0xd16c('0x21')]);_0x5ed571[_0xd16c('0x20')]=qs['offset'](_0x39d208[_0xd16c('0x39')][_0xd16c('0x20')]);}_0x5ed571['order']=qs[_0xd16c('0x42')](_0x39d208[_0xd16c('0x39')][_0xd16c('0x42')]);_0x5ed571[_0xd16c('0x77')]=qs['filters'](_[_0xd16c('0x43')](_0x39d208['query'],_0x240347[_0xd16c('0x3b')]));_0x5ed571[_0xd16c('0x77')][_0xd16c('0xae')]=_0xe14f10['id'];if(_0x39d208[_0xd16c('0x39')]['filter']){_0x5ed571[_0xd16c('0x77')]=_[_0xd16c('0xbe')](_0x5ed571[_0xd16c('0x77')],{'$or':_[_0xd16c('0x37')](_0x5ed571[_0xd16c('0x3f')],function(_0x1ac6ca){var _0x2de1a4={};_0x2de1a4[_0x1ac6ca]={'$like':'%'+_0x39d208[_0xd16c('0x39')][_0xd16c('0x84')]+'%'};return _0x2de1a4;})});}if(_0x39d208[_0xd16c('0x39')][_0xd16c('0xbf')]){var _0x2a4bd0=_0x39d208[_0xd16c('0x39')][_0xd16c('0xbf')][_0xd16c('0x64')](',');var _0x4c1f20={};_0x4c1f20[_0x2a4bd0[0x0]]={'$gte':moment(_0x2a4bd0[0x1])[_0xd16c('0xc0')](_0xd16c('0xc1'))};_0x5ed571['where']=_[_0xd16c('0xbe')](_0x5ed571['where'],_0x4c1f20);}_0x5ed571=_[_0xd16c('0xbe')]({},_0x5ed571,_0x39d208[_0xd16c('0xb4')]);return db[_0xd16c('0xbc')]['count']({'where':_0x5ed571[_0xd16c('0x77')]})['then'](function(_0x473754){_0x11443f[_0xd16c('0x1f')]=_0x473754;if(_0x39d208['query'][_0xd16c('0xb2')]){_0x5ed571[_0xd16c('0xb3')]=[{'all':!![]}];}return db[_0xd16c('0xbc')][_0xd16c('0xc2')](_0x5ed571);})[_0xd16c('0x27')](function(_0x2b1fba){_0x11443f['rows']=_0x2b1fba;return _0x11443f;});}})[_0xd16c('0x27')](respondWithFilteredResult(_0x3e1843,_0x5ed571))[_0xd16c('0xb0')](handleError(_0x3e1843,null));};exports[_0xd16c('0xc3')]=function(_0x4cb9eb,_0x144c7c,_0x18974a){return db[_0xd16c('0x33')][_0xd16c('0x5c')]({'where':{'id':_0x4cb9eb['params']['id']}})[_0xd16c('0x27')](handleEntityNotFound(_0x144c7c,null))[_0xd16c('0x27')](function(_0x34a1df){if(_0x34a1df){return _0x34a1df['setTags'](_0x4cb9eb[_0xd16c('0x72')]['ids'],_[_0xd16c('0xba')](_0x4cb9eb[_0xd16c('0x72')],[_0xd16c('0xb9'),'id'])||{})[_0xd16c('0xc4')](function(){return db[_0xd16c('0x6b')][_0xd16c('0xc2')]({'attributes':['id',_0xd16c('0x38'),'color'],'where':{'id':_0x4cb9eb['body']['ids']}});})[_0xd16c('0x27')](function(_0x33b803){socket[_0xd16c('0xc5')](_0xd16c('0xc6'),{'id':Number(_0x4cb9eb[_0xd16c('0xb1')]['id']),'tags':_0x33b803||[]});return{'id':Number(_0x4cb9eb[_0xd16c('0xb1')]['id']),'tags':_0x33b803||[]};});}})[_0xd16c('0x27')](respondWithResult(_0x144c7c,null))['catch'](handleError(_0x144c7c,null));};exports['removeTags']=function(_0x488ecf,_0x124b35,_0x4d55c3){return db[_0xd16c('0x33')][_0xd16c('0x5c')]({'where':{'id':_0x488ecf[_0xd16c('0xb1')]['id']}})['then'](handleEntityNotFound(_0x124b35,null))['then'](function(_0x50660b){if(_0x50660b){return _0x50660b['removeTags'](_0x488ecf[_0xd16c('0x39')]['ids']);}})[_0xd16c('0x27')](respondWithStatusCode(_0x124b35,null))[_0xd16c('0xb0')](handleError(_0x124b35,null));};exports['download']=function(_0x441ed0,_0x465c3e){var _0x348a6b=moment()['unix']()[_0xd16c('0x97')]();var _0x28e1fe=path[_0xd16c('0xc7')](config[_0xd16c('0xc8')],_0xd16c('0xc9'),_0xd16c('0xca'),'tmp');var _0xe037e2=path[_0xd16c('0xc7')](config[_0xd16c('0xc8')],_0xd16c('0xc9'),_0xd16c('0xca'),_0xd16c('0xcb'));var _0x3f944b=path[_0xd16c('0xc7')](_0x28e1fe,_0x348a6b);var _0x5ca5fd=util[_0xd16c('0xc0')]('transcript-%d-%s.zip',_0x441ed0[_0xd16c('0xb1')]['id'],_0x348a6b);var _0x54cda2=path[_0xd16c('0xc7')](_0x28e1fe,_0x5ca5fd);var _0x14d8a5=[];_0x14d8a5[_0xd16c('0x31')]({'model':db[_0xd16c('0x6e')],'as':'User','attributes':['id','fullname'],'raw':!![]});_0x14d8a5[_0xd16c('0x31')]({'model':db[_0xd16c('0xcc')],'as':'Contact','attributes':['id','firstName',_0xd16c('0xcd')],'raw':!![]});var _0x571c8d=[{'model':db['SmsMessage'],'as':_0xd16c('0xce'),'attributes':['id',_0xd16c('0x72'),_0xd16c('0x79'),_0xd16c('0xcf'),'secret',_0xd16c('0x7f')],'include':_0x14d8a5}];_0x571c8d[_0xd16c('0x31')]({'model':db[_0xd16c('0xd0')],'as':_0xd16c('0xd1'),'attributes':['id',_0xd16c('0x38')]});_0x571c8d[_0xd16c('0x31')]({'model':db[_0xd16c('0x6e')],'as':'Owner','attributes':['id',_0xd16c('0x2d')]});return db[_0xd16c('0x33')]['find']({'where':{'id':_0x441ed0[_0xd16c('0xb1')]['id']},'include':_0x571c8d})['then'](handleEntityNotFound(_0x465c3e,null))[_0xd16c('0x27')](function(_0x51d9b4){if(_0x51d9b4){var _0x181140=_0x51d9b4['get']({'plain':!![]});fs[_0xd16c('0xd2')](_0x3f944b);var _0x3e269c={'format':'A4','border':_0xd16c('0xd3'),'header':{'height':_0xd16c('0xd4'),'contents':{'first':_0xd16c('0xd5')}},'footer':{'height':_0xd16c('0xd6'),'contents':{'default':util['format'](_0xd16c('0xd7'),util[_0xd16c('0xc0')](_0xd16c('0xd8'),_0xd16c('0xd9'),_0x181140['id']),moment()[_0xd16c('0xc0')](_0xd16c('0xda'))[_0xd16c('0x97')]())}}};var _0x3c7482={'channel':_0xd16c('0xd9'),'account':_0x181140[_0xd16c('0xd1')][_0xd16c('0x38')],'agent':_0x181140['Owner']?_0x181140[_0xd16c('0xdb')][_0xd16c('0x2d')]:'N.A.','createdAt':moment(_0x181140[_0xd16c('0x79')])[_0xd16c('0xc0')](_0xd16c('0xc1'))[_0xd16c('0x97')](),'closedAt':_0x181140[_0xd16c('0xdc')]?moment(_0x181140[_0xd16c('0xdd')])[_0xd16c('0xc0')]('YYYY-MM-DD\x20HH:mm:ss')['toString']():'','disposition':_0x181140['disposition'],'messages':_(_0x181140[_0xd16c('0xce')])[_0xd16c('0x84')]({'secret':![]})['map'](function(_0x5a4ca4){return{'date':moment(_0x5a4ca4[_0xd16c('0x79')])[_0xd16c('0xc0')](_0xd16c('0xc1'))['toString'](),'sender':_0x5a4ca4['direction']===_0xd16c('0xde')?_0x5a4ca4[_0xd16c('0x6e')]?_0x5a4ca4[_0xd16c('0x6e')][_0xd16c('0x2d')]:'System':_0x5a4ca4[_0xd16c('0x61')][_0xd16c('0xdf')]+(_0x5a4ca4[_0xd16c('0x61')][_0xd16c('0xcd')]?'\x20'+_0x5a4ca4[_0xd16c('0x61')]['lastName']:''),'body':_0x5a4ca4[_0xd16c('0x72')],'direction':_0x5a4ca4[_0xd16c('0xcf')]===_0xd16c('0xde')?'A':'C','secret':_0x5a4ca4[_0xd16c('0xe0')],'read':_0x5a4ca4[_0xd16c('0x7f')]};})[_0xd16c('0x5e')]()};return ejs[_0xd16c('0xe1')](path[_0xd16c('0xc7')](config[_0xd16c('0xc8')],_0xd16c('0xc9'),'views',_0xd16c('0xe2')),{'interaction':_0x3c7482})[_0xd16c('0x27')](function(_0x55845a){return new BPromise(function(_0x116372,_0x2bee5f){pdf[_0xd16c('0xb5')](_0x55845a,_0x3e269c)[_0xd16c('0xe3')](path[_0xd16c('0xc7')](_0x3f944b,_0xd16c('0xe4')+_0x181140['id']+'-'+_0x348a6b+_0xd16c('0xe5')),function(_0x70ca70,_0x3de220){if(_0x70ca70)return _0x2bee5f(_0x70ca70);_0x116372(_0x3de220);});});})['then'](function(){return new BPromise(function(_0x18db17,_0x11c62a){zipdir(_0x3f944b,{'saveTo':_0x54cda2},function(_0x3ce4b7,_0x38d1f2){if(_0x3ce4b7)return _0x11c62a(_0x3ce4b7);return _0x18db17(_0x38d1f2);});})[_0xd16c('0x27')](function(){return new BPromise(function(_0x518946,_0x5894ff){rimraf(_0x3f944b,function(_0x504e7c){if(_0x504e7c)_0x5894ff(_0x504e7c);return _0x518946();});});})[_0xd16c('0x27')](function(){return _0x465c3e[_0xd16c('0xe6')](_0x54cda2,_0x5ca5fd,function(_0x3c5fca){if(_0x3c5fca){console[_0xd16c('0xe7')](_0xd16c('0xe8'),_0x3c5fca);}else{fs[_0xd16c('0xe9')](_0x54cda2);}});});});}else{return _0x465c3e[_0xd16c('0x1d')](0xc8);}})[_0xd16c('0xb0')](handleError(_0x465c3e,null));};
\ No newline at end of file