Built motion from commit ddca4d0d.|2.5.47
[motion2.git] / server / api / smsInteraction / smsInteraction.controller.js
index 5180982..282a874 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x082b=['send','Users','TagIds','forEach','push','catch','waiting','talking','unmanaged','total','closed','UserId','answered','map','SmsInteraction','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','nolimit','sort','where','select','field','color','u.fullname','ui.SmsInteractionId','from','user_has_sms_interactions','left_join','users','u.id\x20=\x20ui.UserId','sms_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','sms_accounts','a.id\x20=\x20i.SmsAccountId','sms_messages','me.SmsInteractionId\x20=\x20i.id','sms_interaction_has_tags','it.SmsInteractionId\x20=\x20i.id','tools_tags','t.id\x20=\x20it.TagId','expr','search','sqlOperator','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','buildExpression','text','start','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','body','some','compact','SmsAccountId','i.SmsAccountId\x20IN\x20?','concat','createdAt','parse','$gte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','isNumeric','i.id\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','QueryTypes','SELECT','order','DESC','resolve','i.SmsAccountId\x20IS\x20NOT\x20NULL','user','role','getSmsAccounts','isEmpty','i.SmsAccountId\x20IS\x20NULL','agent','sequelize','toString','keyBy','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','a.mandatoryDisposition','Account.mandatoryDisposition','contactName','i.*','c.firstName','Contact.firstName','c.lastName','Contact.lastName','Contact.email','c.phone','Contact.phone','c.mobile','Contact.mobile','Contact.fax','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','groupBy','rows','show','params','include','merge','options','create','describe','addMessage','SmsMessage','ids','omit','getMessages','hasOwnProperty','pick','SmsInteractionId','format','YYYY-MM-DD\x20HH:mm:ss','includeAll','findAll','addTags','setTags','spread','Tag','emit','smsInteractionTags:save','removeTags','download','unix','join','root','server','files','attachments','transcript-%d-%s.zip','firstName','lastName','Messages','direction','SmsAccount','Account','Owner','fullname','get','mkdirSync','Sms','disposition','out','System','views','downloadInteraction.ejs','transcript-','.pdf','createPdfFromHTML','log','err','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/export/pdf','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','redis','localhost','socket.io-emitter','./smsInteraction.socket','register','sendStatus','end','status','json','offset','undefined','count','limit','Content-Range','apply','reject','save','update','then','destroy','error','stack','name'];(function(_0x2639ed,_0x4f5769){var _0x4ed95f=function(_0x354ff2){while(--_0x354ff2){_0x2639ed['push'](_0x2639ed['shift']());}};_0x4ed95f(++_0x4f5769);}(_0x082b,0xc1));var _0xb082=function(_0x539709,_0x2c9edd){_0x539709=_0x539709-0x0;var _0x73cc7e=_0x082b[_0x539709];return _0x73cc7e;};'use strict';var emlformat=require(_0xb082('0x0'));var rimraf=require(_0xb082('0x1'));var zipdir=require(_0xb082('0x2'));var jsonpatch=require(_0xb082('0x3'));var rp=require(_0xb082('0x4'));var moment=require(_0xb082('0x5'));var BPromise=require(_0xb082('0x6'));var Mustache=require(_0xb082('0x7'));var util=require(_0xb082('0x8'));var path=require(_0xb082('0x9'));var sox=require(_0xb082('0xa'));var csv=require(_0xb082('0xb'));var ejs=require(_0xb082('0xc'));var fs=require('fs');var fs_extra=require(_0xb082('0xd'));var _=require(_0xb082('0xe'));var squel=require(_0xb082('0xf'));var crypto=require(_0xb082('0x10'));var jsforce=require(_0xb082('0x11'));var deskjs=require(_0xb082('0x12'));var toCsv=require('to-csv');var querystring=require(_0xb082('0x13'));var Papa=require(_0xb082('0x14'));var Redis=require(_0xb082('0x15'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var pdf=require(_0xb082('0x16'));var hardwareService=require(_0xb082('0x17'));var logger=require(_0xb082('0x18'))(_0xb082('0x19'));var utils=require(_0xb082('0x1a'));var config=require(_0xb082('0x1b'));var licenseUtil=require(_0xb082('0x1c'));var db=require('../../mysqldb')['db'];config[_0xb082('0x1d')]=_['defaults'](config[_0xb082('0x1d')],{'host':_0xb082('0x1e'),'port':0x18eb});var socket=require(_0xb082('0x1f'))(new Redis(config[_0xb082('0x1d')]));require(_0xb082('0x20'))[_0xb082('0x21')](socket);function respondWithStatusCode(_0x8c2819,_0x421ec8){_0x421ec8=_0x421ec8||0xcc;return function(_0x35adc3){if(_0x35adc3){return _0x8c2819[_0xb082('0x22')](_0x421ec8);}return _0x8c2819['status'](_0x421ec8)[_0xb082('0x23')]();};}function respondWithResult(_0x2bea16,_0x31f31e){_0x31f31e=_0x31f31e||0xc8;return function(_0xe44b8c){if(_0xe44b8c){return _0x2bea16[_0xb082('0x24')](_0x31f31e)[_0xb082('0x25')](_0xe44b8c);}};}function respondWithFilteredResult(_0x499a45,_0x29bff4){return function(_0x2786e5){if(_0x2786e5){var _0x4ea876=typeof _0x29bff4[_0xb082('0x26')]==='undefined'&&typeof _0x29bff4['limit']===_0xb082('0x27');var _0x1dffe2=_0x2786e5[_0xb082('0x28')];var _0x2dcf6f=_0x4ea876?0x0:_0x29bff4[_0xb082('0x26')];var _0x318d6e=_0x4ea876?_0x2786e5[_0xb082('0x28')]:_0x29bff4[_0xb082('0x26')]+_0x29bff4[_0xb082('0x29')];var _0x500b2b;if(_0x318d6e>=_0x1dffe2){_0x318d6e=_0x1dffe2;_0x500b2b=0xc8;}else{_0x500b2b=0xce;}_0x499a45[_0xb082('0x24')](_0x500b2b);return _0x499a45['set'](_0xb082('0x2a'),_0x2dcf6f+'-'+_0x318d6e+'/'+_0x1dffe2)[_0xb082('0x25')](_0x2786e5);}return null;};}function patchUpdates(_0x3f17cc){return function(_0x5ac115){try{jsonpatch[_0xb082('0x2b')](_0x5ac115,_0x3f17cc,!![]);}catch(_0x523608){return BPromise[_0xb082('0x2c')](_0x523608);}return _0x5ac115[_0xb082('0x2d')]();};}function saveUpdates(_0x55ace0,_0x9c54c){return function(_0x5caf30){if(_0x5caf30){return _0x5caf30[_0xb082('0x2e')](_0x55ace0)[_0xb082('0x2f')](function(_0x369816){return _0x369816;});}return null;};}function removeEntity(_0xf2ed1e,_0x206987){return function(_0x4f265e){if(_0x4f265e){return _0x4f265e[_0xb082('0x30')]()[_0xb082('0x2f')](function(){_0xf2ed1e[_0xb082('0x24')](0xcc)[_0xb082('0x23')]();});}};}function handleEntityNotFound(_0x1477d8,_0x178617){return function(_0x31ed65){if(!_0x31ed65){_0x1477d8['sendStatus'](0x194);}return _0x31ed65;};}function handleError(_0x199d10,_0x1a687c){_0x1a687c=_0x1a687c||0x1f4;return function(_0x2bec0c){logger[_0xb082('0x31')](_0x2bec0c[_0xb082('0x32')]);if(_0x2bec0c[_0xb082('0x33')]){delete _0x2bec0c[_0xb082('0x33')];}_0x199d10['status'](_0x1a687c)[_0xb082('0x34')](_0x2bec0c);};}function getInteractionUsers(_0x47029f,_0x39b69c){return new BPromise(function(_0x1eaaaf,_0x458f78){try{if(_0x39b69c[_0x47029f['id']]){_0x47029f[_0xb082('0x35')]=_['map'](_0x39b69c[_0x47029f['id']],function(_0x28f1d9){return{'id':_0x28f1d9['id'],'fullname':_0x28f1d9['fullname']};});}}catch(_0xa5c3bf){_0x458f78(_0xa5c3bf);}_0x1eaaaf(_0x47029f);});}function getInteractionTags(_0x25beba,_0x4cc2be){return new BPromise(function(_0x34ba72,_0x349356){try{if(_0x25beba[_0xb082('0x36')]){_0x25beba['Tags']=[];_0x25beba['TagIds']['split'](',')[_0xb082('0x37')](function(_0x29d222){_0x25beba['Tags'][_0xb082('0x38')](_0x4cc2be[_0x29d222]);});}delete _0x25beba[_0xb082('0x36')];}catch(_0x109a0f){_0x349356(_0x109a0f);}_0x34ba72(_0x25beba);});}function updateSmsInteraction(_0x575902,_0x4a3c14,_0x398458){return new BPromise(function(_0x2b2313,_0x4a7a77){return getInteractionUsers(_0x575902,_0x398458)[_0xb082('0x2f')](function(_0x574d4d){return getInteractionTags(_0x574d4d,_0x4a3c14);})['then'](function(_0x110dbd){return getStateInteraction(_0x110dbd);})[_0xb082('0x2f')](function(_0x52b55b){_0x2b2313(_0x52b55b);})[_0xb082('0x39')](function(_0x2ccf09){_0x4a7a77(_0x2ccf09);});});}function getStateInteraction(_0x30027f){return new BPromise(function(_0x36bdb5){_0x30027f[_0xb082('0x3a')]=0x0;_0x30027f[_0xb082('0x3b')]=0x0;_0x30027f['answered']=0x0;_0x30027f[_0xb082('0x3c')]=0x0;_0x30027f[_0xb082('0x3d')]=0x0;if(!_0x30027f[_0xb082('0x3e')]&&!_0x30027f[_0xb082('0x3f')]){_0x30027f[_0xb082('0x3a')]+=0x1;}if(!_0x30027f[_0xb082('0x3e')]&&_0x30027f['UserId']){_0x30027f[_0xb082('0x3b')]+=0x1;if(_0x30027f[_0xb082('0x3a')]){_0x30027f['waiting']-=0x1;}}if(_0x30027f[_0xb082('0x3e')]&&_0x30027f[_0xb082('0x3f')]){_0x30027f[_0xb082('0x40')]+=0x1;if(_0x30027f[_0xb082('0x3b')]){_0x30027f[_0xb082('0x3b')]-=0x1;}}if(_0x30027f[_0xb082('0x3e')]&&!_0x30027f['UserId']){_0x30027f[_0xb082('0x3c')]+=0x1;if(_0x30027f[_0xb082('0x3a')]){_0x30027f[_0xb082('0x3a')]-=0x1;}}_0x30027f[_0xb082('0x3d')]+=0x1;_0x36bdb5(_0x30027f);});}exports['index']=function(_0x57cf6f,_0x50c60){var _0x1c7839={},_0x18000a={},_0x2751cb={'count':0x0,'rows':[]};var _0x1021fe=_[_0xb082('0x41')](db[_0xb082('0x42')][_0xb082('0x43')],function(_0x39592d){return{'name':_0x39592d[_0xb082('0x44')],'type':_0x39592d[_0xb082('0x45')][_0xb082('0x46')]};});_0x18000a[_0xb082('0x47')]=_[_0xb082('0x41')](_0x1021fe,'name');_0x18000a['query']=_[_0xb082('0x48')](_0x57cf6f[_0xb082('0x49')]);_0x18000a[_0xb082('0x4a')]=_[_0xb082('0x4b')](_0x18000a[_0xb082('0x47')],_0x18000a['query']);_0x1c7839[_0xb082('0x4c')]=_['intersection'](_0x18000a[_0xb082('0x47')],qs[_0xb082('0x4d')](_0x57cf6f[_0xb082('0x49')][_0xb082('0x4d')]));_0x1c7839[_0xb082('0x4c')]=_0x1c7839[_0xb082('0x4c')]['length']?_0x1c7839[_0xb082('0x4c')]:_0x18000a[_0xb082('0x47')];if(!_0x57cf6f['query']['hasOwnProperty'](_0xb082('0x4e'))){_0x1c7839[_0xb082('0x29')]=qs[_0xb082('0x29')](_0x57cf6f['query'][_0xb082('0x29')]);_0x1c7839[_0xb082('0x26')]=qs[_0xb082('0x26')](_0x57cf6f['query'][_0xb082('0x26')]);}_0x1c7839['order']=qs[_0xb082('0x4f')](_0x57cf6f[_0xb082('0x49')][_0xb082('0x4f')]);_0x1c7839[_0xb082('0x50')]=qs[_0xb082('0x4a')](_['pick'](_0x57cf6f[_0xb082('0x49')],_0x18000a[_0xb082('0x4a')]),_0x1021fe);var _0x2fe0ac=[];var _0x375226=squel[_0xb082('0x51')]()[_0xb082('0x52')]('id')['field'](_0xb082('0x33'))['field'](_0xb082('0x53'))['from']('tools_tags');var _0x5c65a5=squel['select']()['field']('u.id')['field'](_0xb082('0x54'))[_0xb082('0x52')](_0xb082('0x55'))[_0xb082('0x56')](_0xb082('0x57'),'ui')[_0xb082('0x58')](_0xb082('0x59'),'u',_0xb082('0x5a'));var _0x2ade41=squel[_0xb082('0x51')]()[_0xb082('0x56')](_0xb082('0x5b'),'i')['left_join'](_0xb082('0x5c'),'c',_0xb082('0x5d'))[_0xb082('0x58')]('users','o','o.id\x20=\x20i.UserId')[_0xb082('0x58')](_0xb082('0x5e'),'a',_0xb082('0x5f'))[_0xb082('0x58')](_0xb082('0x60'),'me',_0xb082('0x61'))[_0xb082('0x58')](_0xb082('0x62'),'it',_0xb082('0x63'))[_0xb082('0x58')](_0xb082('0x64'),'t',_0xb082('0x65'));var _0x3fc8d9=squel['expr']();var _0x15d903=[];var _0x386ab6=squel[_0xb082('0x66')]();var _0x2ef32f;if(_0x57cf6f[_0xb082('0x49')][_0xb082('0x67')]){_0x2ef32f=as['parseSearch'](_0x57cf6f['query'][_0xb082('0x67')]);var _0x78018f=_0x2ef32f[_0xb082('0x68')];for(var _0x49425b=0x0;_0x49425b<_0x2ef32f[_0xb082('0x69')][_0xb082('0x6a')];_0x49425b++){var _0x50e1aa=_0x2ef32f[_0xb082('0x69')][_0x49425b];var _0x2e95d7='i';var _0x1caace=_[_0xb082('0x6b')](_0x1021fe,[_0xb082('0x33'),_0x50e1aa[_0xb082('0x52')]]);if(!_0x1caace){switch(_0x50e1aa[_0xb082('0x52')]){case _0xb082('0x6c'):if(_0x50e1aa[_0xb082('0x6d')]==0x1){_0x2ade41[_0xb082('0x6e')]('`'+_0x50e1aa[_0xb082('0x52')]+_0xb082('0x6f'));}else{_0x2ade41['having']('`'+_0x50e1aa['field']+'`\x20>\x200');}break;case _0xb082('0x70'):if(_0x50e1aa[_0xb082('0x71')]===_0xb082('0x72')){if(_0x50e1aa[_0xb082('0x6d')][_0xb082('0x73')]('\x20')[_0xb082('0x6a')]>0x1){_0x3fc8d9[_0x78018f](_0xb082('0x74'),qs[_0xb082('0x75')](_0x50e1aa[_0xb082('0x6d')]),null);}else{var _0x437a57='%'+_0x50e1aa[_0xb082('0x6d')]+'%';_0x3fc8d9[_0x78018f](_0xb082('0x76'),_0x437a57,_0x437a57,_0x437a57);}}else{_0x1caace=_['find'](_0x1021fe,[_0xb082('0x33'),_0xb082('0x77')]);_0x50e1aa[_0xb082('0x52')]=_0xb082('0x77');_0x3f0dbc=as[_0xb082('0x78')](_0x2e95d7,_0x1caace[_0xb082('0x45')],_0x50e1aa);_0x3fc8d9[_0x78018f](_0x3f0dbc[_0xb082('0x79')],_0x3f0dbc[_0xb082('0x6d')][_0xb082('0x7a')],_0x3f0dbc[_0xb082('0x6d')]['end']);}break;case'Tag':var _0xeb1122=_0x50e1aa['value'][_0xb082('0x73')](',')[_0xb082('0x41')](function(_0x3f18e7){return Number(_0x3f18e7);});_0xeb1122[_0xb082('0x37')](function(_0x2f7713){_0x386ab6['or'](_0xb082('0x7b'),'%,'+_0x2f7713+',%');});_0x15d903=_[_0xb082('0x7c')](_0x15d903,_0xeb1122);break;case _0xb082('0x7d'):if(_0x50e1aa[_0xb082('0x71')]===_0xb082('0x72')){_0x3fc8d9[_0x78018f](_0xb082('0x7e'),'%'+_0x50e1aa['value']+'%',null);}else{_0x1caace=_[_0xb082('0x6b')](_0x1021fe,['name',_0xb082('0x3f')]);_0x50e1aa[_0xb082('0x52')]='UserId';_0x3f0dbc=as[_0xb082('0x78')](_0x2e95d7,_0x1caace['type'],_0x50e1aa);_0x3fc8d9[_0x78018f](_0x3f0dbc[_0xb082('0x79')],_0x3f0dbc['value'][_0xb082('0x7a')],_0x3f0dbc['value'][_0xb082('0x23')]);}break;case _0xb082('0x7f'):_0x3f0dbc=as[_0xb082('0x78')]('me',null,_0x50e1aa);_0x3fc8d9[_0x78018f](_0x3f0dbc[_0xb082('0x79')],_0x3f0dbc[_0xb082('0x6d')][_0xb082('0x7a')],_0x3f0dbc['value'][_0xb082('0x23')]);break;}}else{var _0x3f0dbc=as[_0xb082('0x78')](_0x2e95d7,_0x1caace[_0xb082('0x45')],_0x50e1aa);_0x3fc8d9[_0x78018f](_0x3f0dbc[_0xb082('0x79')],_0x3f0dbc['value']['start'],_0x3f0dbc[_0xb082('0x6d')]['end']);}}}else{var _0x57f83a=_(_0x57cf6f[_0xb082('0x49')])['keys']()['map'](function(_0x590895){return _[_0xb082('0x80')](_0x1021fe,[_0xb082('0x33'),_0x590895])?_0x590895:undefined;})[_0xb082('0x81')]()['value']();if(!_['isEmpty'](_0x57f83a)){_0x57f83a['forEach'](function(_0x36f71a){if(_0x36f71a===_0xb082('0x82')){_0x2ade41[_0xb082('0x50')](_0xb082('0x83'),[][_0xb082('0x84')](_0x57cf6f[_0xb082('0x49')][_0x36f71a]));}else if(_0x36f71a===_0xb082('0x85')){var _0x4fad89=JSON[_0xb082('0x86')](_0x57cf6f[_0xb082('0x49')][_0x36f71a])[_0xb082('0x87')];var _0x34d263=JSON[_0xb082('0x86')](_0x57cf6f[_0xb082('0x49')][_0x36f71a])['$lte'];_0x2ade41[_0xb082('0x50')](_0xb082('0x88'),_0x4fad89,_0x34d263);}else{if(_0x57cf6f['query'][_0x36f71a]===_0xb082('0x89')){_0x2ade41['where']('i.'+_0x36f71a+_0xb082('0x8a'));}else{_0x2ade41[_0xb082('0x50')]('i.'+_0x36f71a+_0xb082('0x8b'),_0x57cf6f['query'][_0x36f71a]);}}});}if(_0x57cf6f['query'][_0xb082('0x8c')]){if(_0x57cf6f['query'][_0xb082('0x8c')]==0x1){_0x2ade41[_0xb082('0x6e')](_0xb082('0x8d'));}else{_0x2ade41[_0xb082('0x6e')](_0xb082('0x8e'));}}if(_0x57cf6f[_0xb082('0x49')][_0xb082('0x8f')]){_0x15d903=_[_0xb082('0x90')](_0x57cf6f[_0xb082('0x49')][_0xb082('0x8f')])?_0x57cf6f[_0xb082('0x49')]['tag']:new Array(_0x57cf6f[_0xb082('0x49')]['tag']);_0x15d903['forEach'](function(_0x1c5510){_0x386ab6['or'](_0xb082('0x7b'),'%,'+_0x1c5510+',%');});}if(_0x57cf6f['query']['filter']){var _0x473cb3=_0x57cf6f[_0xb082('0x49')][_0xb082('0x91')][_0xb082('0x92')]('\x5c','\x5c\x5c')[_0xb082('0x92')](/'/g,'\x27\x27');if(qs[_0xb082('0x93')](_0x473cb3)){_0x3fc8d9['or'](_0xb082('0x94'),_0x473cb3+'%')['or']('i.phone\x20LIKE\x20?',_0x473cb3+'%');}else{_0x3fc8d9['or'](_0xb082('0x95'),qs[_0xb082('0x75')](_0x473cb3))['or'](_0xb082('0x96'),_0x473cb3+'%');}}}_0x2ade41[_0xb082('0x50')](_0x3fc8d9);_0x2ade41[_0xb082('0x97')](_0xb082('0x98'));var _0x2a89d9={'type':db['Sequelize'][_0xb082('0x99')][_0xb082('0x9a')],'raw':!![]};var _0x436c94=_0x2ade41['clone']();_0x436c94[_0xb082('0x52')](_0xb082('0x98'));_0x436c94[_0xb082('0x52')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xb082('0x6c'));if(_0x1c7839[_0xb082('0x9b')]){_0x1c7839[_0xb082('0x9b')]['forEach'](function(_0x20a076){var _0x425732=_0x20a076[0x0]==='contactName'?_0x20a076[0x0]:'i.'+_0x20a076[0x0];_0x2ade41[_0xb082('0x9b')](_0x425732,_0x20a076[0x1]===_0xb082('0x9c')?![]:!![]);});}if(!_['isEmpty'](_0x15d903)){_0x2ade41['having'](_0x386ab6);_0x436c94[_0xb082('0x50')]('t.id\x20IN\x20?',_0x15d903);}BPromise[_0xb082('0x9d')]()[_0xb082('0x2f')](function(){if(!_0x2ef32f){if(_0x57cf6f[_0xb082('0x49')][_0xb082('0x82')])return;_0x436c94['where']('i.SmsAccountId\x20IS\x20NOT\x20NULL');_0x2ade41[_0xb082('0x50')](_0xb082('0x9e'));return;}if(_0x57cf6f[_0xb082('0x9f')][_0xb082('0xa0')]!=='agent')return;return _0x57cf6f['user'][_0xb082('0xa1')]({'attributes':['id'],'raw':!![]})[_0xb082('0x2f')](function(_0x38f5fd){if(_[_0xb082('0xa2')](_0x38f5fd)){_0x436c94[_0xb082('0x50')](_0xb082('0xa3'));_0x2ade41[_0xb082('0x50')](_0xb082('0xa3'));}else{_0x436c94[_0xb082('0x50')](_0xb082('0x83'),_[_0xb082('0x41')](_0x38f5fd,'id'));_0x2ade41['where']('i.SmsAccountId\x20IN\x20?',_[_0xb082('0x41')](_0x38f5fd,'id'));}});})[_0xb082('0x2f')](function(){if(_0x57cf6f[_0xb082('0x9f')][_0xb082('0xa0')]===_0xb082('0xa4')&&!_0x2ef32f&&!_0x57cf6f[_0xb082('0x49')]['SmsAccountId'])return[];return db[_0xb082('0xa5')][_0xb082('0x49')](_0x436c94[_0xb082('0xa6')](),_0x2a89d9);})[_0xb082('0x2f')](function(_0xbebee7){_0x2751cb[_0xb082('0x28')]=_0xbebee7[_0xb082('0x6a')];if(_0x2751cb['count']===0x0)return[];return db[_0xb082('0xa5')][_0xb082('0x49')](_0x375226['toString'](),_0x2a89d9)[_0xb082('0x2f')](function(_0x4053a9){_0x2fe0ac=_[_0xb082('0xa7')](_0x4053a9,'id');_0x2a89d9=_['merge'](_0x2a89d9,{'model':db[_0xb082('0x42')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x57cf6f['query'][_0xb082('0x4d')]){_0x1c7839['attributes'][_0xb082('0x37')](function(_0x1a7ff2){_0x2ade41[_0xb082('0x52')]('i.'+_0x1a7ff2);});}else{_0x2ade41[_0xb082('0x52')](_0xb082('0xa8'),_0xb082('0x6c'));_0x2ade41[_0xb082('0x52')]('a.key','Account.key');_0x2ade41['field'](_0xb082('0xa9'),_0xb082('0xaa'));_0x2ade41[_0xb082('0x52')]('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',_0xb082('0xab'));_0x2ade41[_0xb082('0x52')](_0xb082('0xac'));_0x2ade41[_0xb082('0x52')](_0xb082('0xad'),_0xb082('0xae'));_0x2ade41[_0xb082('0x52')](_0xb082('0xaf'),_0xb082('0xb0'));_0x2ade41[_0xb082('0x52')]('c.email',_0xb082('0xb1'));_0x2ade41[_0xb082('0x52')](_0xb082('0xb2'),_0xb082('0xb3'));_0x2ade41[_0xb082('0x52')](_0xb082('0xb4'),_0xb082('0xb5'));_0x2ade41[_0xb082('0x52')]('c.fax',_0xb082('0xb6'));_0x2ade41[_0xb082('0x52')]('o.fullname',_0xb082('0xb7'));_0x2ade41[_0xb082('0x52')](_0xb082('0xb8'),_0xb082('0xb9'));_0x2ade41['field'](_0xb082('0xba'),_0xb082('0x36'));}if(_0x1c7839[_0xb082('0x29')])_0x2ade41[_0xb082('0x29')](_0x1c7839[_0xb082('0x29')]);if(_0x1c7839['offset'])_0x2ade41[_0xb082('0x26')](_0x1c7839['offset']);return db[_0xb082('0xa5')][_0xb082('0x49')](_0x2ade41['toString'](),_0x2a89d9);})[_0xb082('0x2f')](function(_0x48f43a){if(_0x48f43a['length']>0x0)_0x5c65a5[_0xb082('0x50')]('ui.SmsInteractionId\x20IN\x20?',_[_0xb082('0x41')](_0x48f43a,'id'));return db['sequelize'][_0xb082('0x49')](_0x5c65a5['toString'](),_0x2a89d9)[_0xb082('0x2f')](function(_0x250bd4){var _0x1c1433=_[_0xb082('0xbb')](_0x250bd4,'SmsInteractionId');var _0x484a09=[];_0x48f43a['forEach'](function(_0x1bd924){_0x484a09[_0xb082('0x38')](updateSmsInteraction(_0x1bd924,_0x2fe0ac,_0x1c1433));});return BPromise['all'](_0x484a09);});});})[_0xb082('0x2f')](function(_0x460845){_0x2751cb[_0xb082('0xbc')]=_0x460845;return _0x2751cb;})[_0xb082('0x2f')](respondWithFilteredResult(_0x50c60,_0x1c7839))['catch'](handleError(_0x50c60,null));};exports[_0xb082('0xbd')]=function(_0x10bd26,_0x124917){var _0x170daa={'raw':![],'where':{'id':_0x10bd26[_0xb082('0xbe')]['id']}},_0x21ae51={};_0x21ae51['model']=_[_0xb082('0x48')](db['SmsInteraction'][_0xb082('0x43')]);_0x21ae51[_0xb082('0x49')]=_['keys'](_0x10bd26[_0xb082('0x49')]);_0x21ae51[_0xb082('0x4a')]=_[_0xb082('0x4b')](_0x21ae51[_0xb082('0x47')],_0x21ae51[_0xb082('0x49')]);_0x170daa[_0xb082('0x4c')]=_[_0xb082('0x4b')](_0x21ae51['model'],qs[_0xb082('0x4d')](_0x10bd26[_0xb082('0x49')][_0xb082('0x4d')]));_0x170daa[_0xb082('0x4c')]=_0x170daa[_0xb082('0x4c')]['length']?_0x170daa[_0xb082('0x4c')]:_0x21ae51['model'];if(_0x10bd26['query']['includeAll']){_0x170daa[_0xb082('0xbf')]=[{'all':!![]}];}_0x170daa=_[_0xb082('0xc0')]({},_0x170daa,_0x10bd26[_0xb082('0xc1')]);return db[_0xb082('0x42')]['find'](_0x170daa)['then'](handleEntityNotFound(_0x124917,null))[_0xb082('0x2f')](respondWithResult(_0x124917,null))[_0xb082('0x39')](handleError(_0x124917,null));};exports[_0xb082('0xc2')]=function(_0x2a8e36,_0x1f82fb){return db[_0xb082('0x42')][_0xb082('0xc2')](_0x2a8e36[_0xb082('0x7f')],{})['then'](respondWithResult(_0x1f82fb,0xc9))[_0xb082('0x39')](handleError(_0x1f82fb,null));};exports[_0xb082('0x2e')]=function(_0x5c54e9,_0x5bb257){if(_0x5c54e9[_0xb082('0x7f')]['id']){delete _0x5c54e9['body']['id'];}return db[_0xb082('0x42')][_0xb082('0x6b')]({'where':{'id':_0x5c54e9[_0xb082('0xbe')]['id']}})[_0xb082('0x2f')](handleEntityNotFound(_0x5bb257,null))['then'](saveUpdates(_0x5c54e9[_0xb082('0x7f')],null))[_0xb082('0x2f')](respondWithResult(_0x5bb257,null))['catch'](handleError(_0x5bb257,null));};exports['destroy']=function(_0x391922,_0x1c9e0f){return db['SmsInteraction'][_0xb082('0x6b')]({'where':{'id':_0x391922[_0xb082('0xbe')]['id']}})[_0xb082('0x2f')](handleEntityNotFound(_0x1c9e0f,null))[_0xb082('0x2f')](removeEntity(_0x1c9e0f,null))[_0xb082('0x39')](handleError(_0x1c9e0f,null));};exports[_0xb082('0xc3')]=function(_0x1f4022,_0x480d46){return db[_0xb082('0x42')][_0xb082('0xc3')]()[_0xb082('0x2f')](respondWithResult(_0x480d46,null))[_0xb082('0x39')](handleError(_0x480d46,null));};exports[_0xb082('0xc4')]=function(_0x104ff1,_0x4724b1,_0x4a8832){return db[_0xb082('0xc5')][_0xb082('0x6b')]({'where':{'id':_0x104ff1[_0xb082('0xbe')]['id']}})[_0xb082('0x2f')](handleEntityNotFound(_0x4724b1,null))[_0xb082('0x2f')](function(_0xa7c1af){if(_0xa7c1af){return _0xa7c1af[_0xb082('0xc4')](_0x104ff1['body'][_0xb082('0xc6')],_[_0xb082('0xc7')](_0x104ff1[_0xb082('0x7f')],['ids','id'])||{});}})[_0xb082('0x2f')](respondWithResult(_0x4724b1,null))[_0xb082('0x39')](handleError(_0x4724b1,null));};exports[_0xb082('0xc8')]=function(_0x134ca2,_0x30f2e2,_0x5ccaae){var _0x24e8aa={'raw':![],'where':{}};var _0x5cd37a={};var _0x29249b={'count':0x0,'rows':[]};return db[_0xb082('0x42')]['findOne']({'where':{'id':_0x134ca2[_0xb082('0xbe')]['id']}})['then'](handleEntityNotFound(_0x30f2e2,null))[_0xb082('0x2f')](function(_0x2b1431){if(_0x2b1431){_0x5cd37a[_0xb082('0x47')]=_[_0xb082('0x48')](db[_0xb082('0xc5')][_0xb082('0x43')]);_0x5cd37a[_0xb082('0x49')]=_['keys'](_0x134ca2[_0xb082('0x49')]);_0x5cd37a[_0xb082('0x4a')]=_[_0xb082('0x4b')](_0x5cd37a[_0xb082('0x47')],_0x5cd37a[_0xb082('0x49')]);_0x24e8aa[_0xb082('0x4c')]=_[_0xb082('0x4b')](_0x5cd37a[_0xb082('0x47')],qs[_0xb082('0x4d')](_0x134ca2['query']['fields']));_0x24e8aa[_0xb082('0x4c')]=_0x24e8aa[_0xb082('0x4c')][_0xb082('0x6a')]?_0x24e8aa[_0xb082('0x4c')]:_0x5cd37a[_0xb082('0x47')];if(!_0x134ca2['query'][_0xb082('0xc9')](_0xb082('0x4e'))){_0x24e8aa[_0xb082('0x29')]=qs[_0xb082('0x29')](_0x134ca2[_0xb082('0x49')]['limit']);_0x24e8aa[_0xb082('0x26')]=qs[_0xb082('0x26')](_0x134ca2[_0xb082('0x49')][_0xb082('0x26')]);}_0x24e8aa[_0xb082('0x9b')]=qs[_0xb082('0x4f')](_0x134ca2[_0xb082('0x49')][_0xb082('0x4f')]);_0x24e8aa['where']=qs[_0xb082('0x4a')](_[_0xb082('0xca')](_0x134ca2[_0xb082('0x49')],_0x5cd37a['filters']));_0x24e8aa[_0xb082('0x50')][_0xb082('0xcb')]=_0x2b1431['id'];if(_0x134ca2[_0xb082('0x49')][_0xb082('0x91')]){_0x24e8aa[_0xb082('0x50')]=_[_0xb082('0xc0')](_0x24e8aa['where'],{'$or':_['map'](_0x24e8aa[_0xb082('0x4c')],function(_0x1608f5){var _0x55f313={};_0x55f313[_0x1608f5]={'$like':'%'+_0x134ca2['query'][_0xb082('0x91')]+'%'};return _0x55f313;})});}if(_0x134ca2[_0xb082('0x49')][_0xb082('0x87')]){var _0x5b653e=_0x134ca2[_0xb082('0x49')][_0xb082('0x87')]['split'](',');var _0x57770b={};_0x57770b[_0x5b653e[0x0]]={'$gte':moment(_0x5b653e[0x1])[_0xb082('0xcc')](_0xb082('0xcd'))};_0x24e8aa[_0xb082('0x50')]=_['merge'](_0x24e8aa[_0xb082('0x50')],_0x57770b);}_0x24e8aa=_['merge']({},_0x24e8aa,_0x134ca2[_0xb082('0xc1')]);return db[_0xb082('0xc5')][_0xb082('0x28')]({'where':_0x24e8aa['where']})[_0xb082('0x2f')](function(_0x1fd8e6){_0x29249b[_0xb082('0x28')]=_0x1fd8e6;if(_0x134ca2[_0xb082('0x49')][_0xb082('0xce')]){_0x24e8aa[_0xb082('0xbf')]=[{'all':!![]}];}return db['SmsMessage'][_0xb082('0xcf')](_0x24e8aa);})[_0xb082('0x2f')](function(_0x222f08){_0x29249b[_0xb082('0xbc')]=_0x222f08;return _0x29249b;});}})['then'](respondWithFilteredResult(_0x30f2e2,_0x24e8aa))[_0xb082('0x39')](handleError(_0x30f2e2,null));};exports[_0xb082('0xd0')]=function(_0x4e1257,_0x5c4905,_0x102b9a){return db['SmsInteraction']['find']({'where':{'id':_0x4e1257[_0xb082('0xbe')]['id']}})[_0xb082('0x2f')](handleEntityNotFound(_0x5c4905,null))[_0xb082('0x2f')](function(_0x4bd814){if(_0x4bd814){return _0x4bd814[_0xb082('0xd1')](_0x4e1257[_0xb082('0x7f')][_0xb082('0xc6')],_[_0xb082('0xc7')](_0x4e1257[_0xb082('0x7f')],[_0xb082('0xc6'),'id'])||{})[_0xb082('0xd2')](function(){return db[_0xb082('0xd3')]['findAll']({'attributes':['id',_0xb082('0x33'),_0xb082('0x53')],'where':{'id':_0x4e1257[_0xb082('0x7f')][_0xb082('0xc6')]}});})[_0xb082('0x2f')](function(_0x2cce3b){socket[_0xb082('0xd4')](_0xb082('0xd5'),{'id':Number(_0x4e1257['params']['id']),'tags':_0x2cce3b||[]});return{'id':Number(_0x4e1257[_0xb082('0xbe')]['id']),'tags':_0x2cce3b||[]};});}})['then'](respondWithResult(_0x5c4905,null))[_0xb082('0x39')](handleError(_0x5c4905,null));};exports[_0xb082('0xd6')]=function(_0x21ac33,_0x1f6fc4,_0x5141ba){return db['SmsInteraction'][_0xb082('0x6b')]({'where':{'id':_0x21ac33[_0xb082('0xbe')]['id']}})['then'](handleEntityNotFound(_0x1f6fc4,null))['then'](function(_0x407baf){if(_0x407baf){return _0x407baf[_0xb082('0xd6')](_0x21ac33[_0xb082('0x49')][_0xb082('0xc6')]);}})[_0xb082('0x2f')](respondWithStatusCode(_0x1f6fc4,null))[_0xb082('0x39')](handleError(_0x1f6fc4,null));};exports[_0xb082('0xd7')]=function(_0x4b5568,_0x96284c){var _0x159a90=moment()[_0xb082('0xd8')]()[_0xb082('0xa6')]();var _0x12b459=path[_0xb082('0xd9')](config[_0xb082('0xda')],_0xb082('0xdb'),_0xb082('0xdc'),'tmp');var _0x581141=path['join'](config[_0xb082('0xda')],'server',_0xb082('0xdc'),_0xb082('0xdd'));var _0x329dba=path[_0xb082('0xd9')](_0x12b459,_0x159a90);var _0x21ac9a=util[_0xb082('0xcc')](_0xb082('0xde'),_0x4b5568[_0xb082('0xbe')]['id'],_0x159a90);var _0x2a2be8=path[_0xb082('0xd9')](_0x12b459,_0x21ac9a);var _0x4b4571=[];_0x4b4571[_0xb082('0x38')]({'model':db[_0xb082('0x7d')],'as':_0xb082('0x7d'),'attributes':['id','fullname'],'raw':!![]});_0x4b4571['push']({'model':db['CmContact'],'as':'Contact','attributes':['id',_0xb082('0xdf'),_0xb082('0xe0')],'raw':!![]});var _0x40ee7e=[{'model':db[_0xb082('0xc5')],'as':_0xb082('0xe1'),'attributes':['id',_0xb082('0x7f'),'createdAt',_0xb082('0xe2'),'secret',_0xb082('0x8c')],'include':_0x4b4571}];_0x40ee7e['push']({'model':db[_0xb082('0xe3')],'as':_0xb082('0xe4'),'attributes':['id','name']});_0x40ee7e['push']({'model':db[_0xb082('0x7d')],'as':_0xb082('0xe5'),'attributes':['id',_0xb082('0xe6')]});return db[_0xb082('0x42')][_0xb082('0x6b')]({'where':{'id':_0x4b5568[_0xb082('0xbe')]['id']},'include':_0x40ee7e})[_0xb082('0x2f')](handleEntityNotFound(_0x96284c,null))[_0xb082('0x2f')](function(_0x3c34be){if(_0x3c34be){var _0x5001da=_0x3c34be[_0xb082('0xe7')]({'plain':!![]});fs[_0xb082('0xe8')](_0x329dba);var _0x2f0e3b={'channel':_0xb082('0xe9'),'account':_0x5001da[_0xb082('0xe4')][_0xb082('0x33')],'agent':_0x5001da['Owner']?_0x5001da[_0xb082('0xe5')][_0xb082('0xe6')]:'N.A.','createdAt':moment(_0x5001da[_0xb082('0x85')])[_0xb082('0xcc')]('YYYY-MM-DD\x20HH:mm:ss')[_0xb082('0xa6')](),'closedAt':_0x5001da[_0xb082('0x3e')]?moment(_0x5001da['closedAt'])[_0xb082('0xcc')](_0xb082('0xcd'))['toString']():'','disposition':_0x5001da[_0xb082('0xea')],'messages':_(_0x5001da['Messages'])[_0xb082('0x91')]({'secret':![]})[_0xb082('0x41')](function(_0x2bac42){return{'date':moment(_0x2bac42[_0xb082('0x85')])[_0xb082('0xcc')](_0xb082('0xcd'))[_0xb082('0xa6')](),'sender':_0x2bac42['direction']===_0xb082('0xeb')?_0x2bac42[_0xb082('0x7d')]?_0x2bac42[_0xb082('0x7d')][_0xb082('0xe6')]:_0xb082('0xec'):_0x2bac42[_0xb082('0x70')]['firstName']+(_0x2bac42[_0xb082('0x70')][_0xb082('0xe0')]?'\x20'+_0x2bac42[_0xb082('0x70')][_0xb082('0xe0')]:''),'body':_0x2bac42['body'],'direction':_0x2bac42[_0xb082('0xe2')]===_0xb082('0xeb')?'A':'C','secret':_0x2bac42['secret'],'read':_0x2bac42[_0xb082('0x8c')]};})[_0xb082('0x6d')]()};return ejs['renderFile'](path[_0xb082('0xd9')](config[_0xb082('0xda')],'server',_0xb082('0xed'),_0xb082('0xee')),{'interaction':_0x2f0e3b})['then'](function(_0x4bc4ac){var _0x410f51=path['join'](_0x329dba,_0xb082('0xef')+_0x5001da['id']+'-'+_0x159a90+_0xb082('0xf0'));var _0x235c63={'path':_0x410f51,'channel':_0xb082('0xe9'),'interactionId':_0x5001da['id']};return pdf[_0xb082('0xf1')](_0x4bc4ac,_0x235c63);})['then'](function(){return new BPromise(function(_0x28a11e,_0x4b8c55){zipdir(_0x329dba,{'saveTo':_0x2a2be8},function(_0x54df91,_0x2f1e62){if(_0x54df91)return _0x4b8c55(_0x54df91);return _0x28a11e(_0x2f1e62);});})[_0xb082('0x2f')](function(){return new BPromise(function(_0x13e2ba,_0x5bd092){rimraf(_0x329dba,function(_0x11a336){if(_0x11a336)_0x5bd092(_0x11a336);return _0x13e2ba();});});})[_0xb082('0x2f')](function(){return _0x96284c['download'](_0x2a2be8,_0x21ac9a,function(_0x43b0f7){if(_0x43b0f7){console[_0xb082('0xf2')](_0xb082('0xf3'),_0x43b0f7);}else{fs[_0xb082('0xf4')](_0x2a2be8);}});});});}else{return _0x96284c[_0xb082('0x22')](0xc8);}})[_0xb082('0x39')](handleError(_0x96284c,null));};
\ No newline at end of file
+var _0x60fc=['i.SmsAccountId\x20IN\x20?','role','sequelize','toString','keyBy','merge','a.key','Account.key','i.*','Contact.firstName','c.lastName','Contact.lastName','c.email','c.phone','c.mobile','Contact.mobile','o.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.SmsInteractionId\x20IN\x20?','all','rows','rawAttributes','includeAll','include','options','create','params','describe','SmsMessage','omit','ids','getMessages','findOne','hasOwnProperty','SmsInteractionId','format','YYYY-MM-DD\x20HH:mm:ss','addTags','setTags','spread','findAll','emit','removeTags','download','unix','join','root','server','tmp','attachments','CmContact','lastName','Messages','direction','secret','SmsAccount','Account','Owner','get','mkdirSync','firstName','views','Sms','createPdfFromHTML','log','err','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','to-csv','ejs','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','redis','localhost','./smsInteraction.socket','register','sendStatus','json','offset','undefined','limit','count','status','set','apply','reject','save','update','then','destroy','end','error','name','send','Users','map','fullname','Tags','split','forEach','push','TagIds','catch','waiting','answered','unmanaged','total','closed','UserId','talking','SmsInteraction','fieldName','key','model','query','keys','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','select','field','color','from','tools_tags','u.fullname','ui.SmsInteractionId','left_join','users','u.id\x20=\x20ui.UserId','sms_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','sms_accounts','sms_messages','me.SmsInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch','conditions','find','unreadMessages','value','having','`\x20>\x200','Contact','operator','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','ContactId','text','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','buildExpression','start','body','type','some','compact','isEmpty','SmsAccountId','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','tag','filter','replace','isNumeric','i.id\x20LIKE\x20?','i.phone\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','Sequelize','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','DESC','t.id\x20IN\x20?','resolve','i.SmsAccountId\x20IS\x20NOT\x20NULL','agent','user','i.SmsAccountId\x20IS\x20NULL'];(function(_0x1049b7,_0xc4573b){var _0x3763a4=function(_0x2620e1){while(--_0x2620e1){_0x1049b7['push'](_0x1049b7['shift']());}};_0x3763a4(++_0xc4573b);}(_0x60fc,0x128));var _0xc60f=function(_0x3bec1f,_0x135f71){_0x3bec1f=_0x3bec1f-0x0;var _0x332192=_0x60fc[_0x3bec1f];return _0x332192;};'use strict';var emlformat=require(_0xc60f('0x0'));var rimraf=require(_0xc60f('0x1'));var zipdir=require(_0xc60f('0x2'));var jsonpatch=require(_0xc60f('0x3'));var rp=require('request-promise');var moment=require(_0xc60f('0x4'));var BPromise=require(_0xc60f('0x5'));var Mustache=require(_0xc60f('0x6'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require(_0xc60f('0x7'));var ejs=require(_0xc60f('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xc60f('0x9'));var deskjs=require(_0xc60f('0xa'));var toCsv=require(_0xc60f('0x7'));var querystring=require(_0xc60f('0xb'));var Papa=require(_0xc60f('0xc'));var Redis=require(_0xc60f('0xd'));var authService=require(_0xc60f('0xe'));var qs=require(_0xc60f('0xf'));var as=require(_0xc60f('0x10'));var pdf=require('../../components/export/pdf');var hardwareService=require(_0xc60f('0x11'));var logger=require(_0xc60f('0x12'))(_0xc60f('0x13'));var utils=require(_0xc60f('0x14'));var config=require(_0xc60f('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0xc60f('0x16'))['db'];config[_0xc60f('0x17')]=_['defaults'](config[_0xc60f('0x17')],{'host':_0xc60f('0x18'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xc60f('0x17')]));require(_0xc60f('0x19'))[_0xc60f('0x1a')](socket);function respondWithStatusCode(_0x244e15,_0x594361){_0x594361=_0x594361||0xcc;return function(_0x4f3b3e){if(_0x4f3b3e){return _0x244e15[_0xc60f('0x1b')](_0x594361);}return _0x244e15['status'](_0x594361)['end']();};}function respondWithResult(_0x29acc6,_0x466d65){_0x466d65=_0x466d65||0xc8;return function(_0x3c26bf){if(_0x3c26bf){return _0x29acc6['status'](_0x466d65)[_0xc60f('0x1c')](_0x3c26bf);}};}function respondWithFilteredResult(_0x5b2b89,_0x56be40){return function(_0x1eb196){if(_0x1eb196){var _0x158927=typeof _0x56be40[_0xc60f('0x1d')]===_0xc60f('0x1e')&&typeof _0x56be40[_0xc60f('0x1f')]===_0xc60f('0x1e');var _0xfabbc3=_0x1eb196['count'];var _0x55ffb2=_0x158927?0x0:_0x56be40[_0xc60f('0x1d')];var _0x2c0d60=_0x158927?_0x1eb196[_0xc60f('0x20')]:_0x56be40[_0xc60f('0x1d')]+_0x56be40['limit'];var _0x90951d;if(_0x2c0d60>=_0xfabbc3){_0x2c0d60=_0xfabbc3;_0x90951d=0xc8;}else{_0x90951d=0xce;}_0x5b2b89[_0xc60f('0x21')](_0x90951d);return _0x5b2b89[_0xc60f('0x22')]('Content-Range',_0x55ffb2+'-'+_0x2c0d60+'/'+_0xfabbc3)['json'](_0x1eb196);}return null;};}function patchUpdates(_0x19683f){return function(_0x1d937b){try{jsonpatch[_0xc60f('0x23')](_0x1d937b,_0x19683f,!![]);}catch(_0x3b892e){return BPromise[_0xc60f('0x24')](_0x3b892e);}return _0x1d937b[_0xc60f('0x25')]();};}function saveUpdates(_0x246641,_0x3d9f6c){return function(_0x2eab69){if(_0x2eab69){return _0x2eab69[_0xc60f('0x26')](_0x246641)[_0xc60f('0x27')](function(_0x585345){return _0x585345;});}return null;};}function removeEntity(_0x3d7bac,_0x5802a1){return function(_0x3ef226){if(_0x3ef226){return _0x3ef226[_0xc60f('0x28')]()['then'](function(){_0x3d7bac[_0xc60f('0x21')](0xcc)[_0xc60f('0x29')]();});}};}function handleEntityNotFound(_0x18c8fa,_0x3e9575){return function(_0x18a72a){if(!_0x18a72a){_0x18c8fa[_0xc60f('0x1b')](0x194);}return _0x18a72a;};}function handleError(_0x10fa31,_0x46bae2){_0x46bae2=_0x46bae2||0x1f4;return function(_0x124d58){logger[_0xc60f('0x2a')](_0x124d58['stack']);if(_0x124d58['name']){delete _0x124d58[_0xc60f('0x2b')];}_0x10fa31[_0xc60f('0x21')](_0x46bae2)[_0xc60f('0x2c')](_0x124d58);};}function getInteractionUsers(_0x3d9467,_0x17ea85){return new BPromise(function(_0x2aa387,_0x250f5d){try{if(_0x17ea85[_0x3d9467['id']]){_0x3d9467[_0xc60f('0x2d')]=_[_0xc60f('0x2e')](_0x17ea85[_0x3d9467['id']],function(_0x227b35){return{'id':_0x227b35['id'],'fullname':_0x227b35[_0xc60f('0x2f')]};});}}catch(_0x47f621){_0x250f5d(_0x47f621);}_0x2aa387(_0x3d9467);});}function getInteractionTags(_0x1f27f4,_0x1bb150){return new BPromise(function(_0xb390e6,_0x4db602){try{if(_0x1f27f4['TagIds']){_0x1f27f4[_0xc60f('0x30')]=[];_0x1f27f4['TagIds'][_0xc60f('0x31')](',')[_0xc60f('0x32')](function(_0x7d8e40){_0x1f27f4[_0xc60f('0x30')][_0xc60f('0x33')](_0x1bb150[_0x7d8e40]);});}delete _0x1f27f4[_0xc60f('0x34')];}catch(_0x3b6305){_0x4db602(_0x3b6305);}_0xb390e6(_0x1f27f4);});}function updateSmsInteraction(_0x52917c,_0x1d3b1f,_0x15c4c7){return new BPromise(function(_0x583362,_0x4f4bfe){return getInteractionUsers(_0x52917c,_0x15c4c7)[_0xc60f('0x27')](function(_0x1b628e){return getInteractionTags(_0x1b628e,_0x1d3b1f);})[_0xc60f('0x27')](function(_0x35dfc3){return getStateInteraction(_0x35dfc3);})[_0xc60f('0x27')](function(_0x578c94){_0x583362(_0x578c94);})[_0xc60f('0x35')](function(_0x34122d){_0x4f4bfe(_0x34122d);});});}function getStateInteraction(_0x4fa176){return new BPromise(function(_0xeeebfc){_0x4fa176[_0xc60f('0x36')]=0x0;_0x4fa176['talking']=0x0;_0x4fa176[_0xc60f('0x37')]=0x0;_0x4fa176[_0xc60f('0x38')]=0x0;_0x4fa176[_0xc60f('0x39')]=0x0;if(!_0x4fa176[_0xc60f('0x3a')]&&!_0x4fa176[_0xc60f('0x3b')]){_0x4fa176['waiting']+=0x1;}if(!_0x4fa176[_0xc60f('0x3a')]&&_0x4fa176['UserId']){_0x4fa176[_0xc60f('0x3c')]+=0x1;if(_0x4fa176[_0xc60f('0x36')]){_0x4fa176[_0xc60f('0x36')]-=0x1;}}if(_0x4fa176['closed']&&_0x4fa176[_0xc60f('0x3b')]){_0x4fa176[_0xc60f('0x37')]+=0x1;if(_0x4fa176[_0xc60f('0x3c')]){_0x4fa176['talking']-=0x1;}}if(_0x4fa176['closed']&&!_0x4fa176[_0xc60f('0x3b')]){_0x4fa176[_0xc60f('0x38')]+=0x1;if(_0x4fa176[_0xc60f('0x36')]){_0x4fa176[_0xc60f('0x36')]-=0x1;}}_0x4fa176[_0xc60f('0x39')]+=0x1;_0xeeebfc(_0x4fa176);});}exports['index']=function(_0x1877d2,_0x254eaa){var _0x490e17={},_0x360eb8={},_0x4274c6={'count':0x0,'rows':[]};var _0x4dac3e=_[_0xc60f('0x2e')](db[_0xc60f('0x3d')]['rawAttributes'],function(_0x37598e){return{'name':_0x37598e[_0xc60f('0x3e')],'type':_0x37598e['type'][_0xc60f('0x3f')]};});_0x360eb8[_0xc60f('0x40')]=_[_0xc60f('0x2e')](_0x4dac3e,'name');_0x360eb8[_0xc60f('0x41')]=_[_0xc60f('0x42')](_0x1877d2[_0xc60f('0x41')]);_0x360eb8[_0xc60f('0x43')]=_[_0xc60f('0x44')](_0x360eb8[_0xc60f('0x40')],_0x360eb8[_0xc60f('0x41')]);_0x490e17[_0xc60f('0x45')]=_[_0xc60f('0x44')](_0x360eb8[_0xc60f('0x40')],qs[_0xc60f('0x46')](_0x1877d2[_0xc60f('0x41')][_0xc60f('0x46')]));_0x490e17[_0xc60f('0x45')]=_0x490e17[_0xc60f('0x45')][_0xc60f('0x47')]?_0x490e17[_0xc60f('0x45')]:_0x360eb8[_0xc60f('0x40')];if(!_0x1877d2[_0xc60f('0x41')]['hasOwnProperty'](_0xc60f('0x48'))){_0x490e17[_0xc60f('0x1f')]=qs['limit'](_0x1877d2[_0xc60f('0x41')][_0xc60f('0x1f')]);_0x490e17['offset']=qs[_0xc60f('0x1d')](_0x1877d2[_0xc60f('0x41')][_0xc60f('0x1d')]);}_0x490e17[_0xc60f('0x49')]=qs[_0xc60f('0x4a')](_0x1877d2[_0xc60f('0x41')][_0xc60f('0x4a')]);_0x490e17[_0xc60f('0x4b')]=qs['filters'](_[_0xc60f('0x4c')](_0x1877d2[_0xc60f('0x41')],_0x360eb8[_0xc60f('0x43')]),_0x4dac3e);var _0x486ffb=[];var _0x134bc3=squel[_0xc60f('0x4d')]()[_0xc60f('0x4e')]('id')[_0xc60f('0x4e')](_0xc60f('0x2b'))['field'](_0xc60f('0x4f'))[_0xc60f('0x50')](_0xc60f('0x51'));var _0x41eb66=squel['select']()['field']('u.id')[_0xc60f('0x4e')](_0xc60f('0x52'))['field'](_0xc60f('0x53'))[_0xc60f('0x50')]('user_has_sms_interactions','ui')[_0xc60f('0x54')](_0xc60f('0x55'),'u',_0xc60f('0x56'));var _0x425e8b=squel['select']()[_0xc60f('0x50')](_0xc60f('0x57'),'i')['left_join'](_0xc60f('0x58'),'c',_0xc60f('0x59'))[_0xc60f('0x54')](_0xc60f('0x55'),'o',_0xc60f('0x5a'))[_0xc60f('0x54')](_0xc60f('0x5b'),'a','a.id\x20=\x20i.SmsAccountId')[_0xc60f('0x54')](_0xc60f('0x5c'),'me',_0xc60f('0x5d'))['left_join']('sms_interaction_has_tags','it','it.SmsInteractionId\x20=\x20i.id')[_0xc60f('0x54')]('tools_tags','t',_0xc60f('0x5e'));var _0x58a82b=squel['expr']();var _0x4e5803=[];var _0x5b5777=squel[_0xc60f('0x5f')]();var _0x299cc9;if(_0x1877d2[_0xc60f('0x41')][_0xc60f('0x60')]){_0x299cc9=as[_0xc60f('0x61')](_0x1877d2[_0xc60f('0x41')]['search']);var _0x342f0d=_0x299cc9['sqlOperator'];for(var _0x4ff8e8=0x0;_0x4ff8e8<_0x299cc9[_0xc60f('0x62')][_0xc60f('0x47')];_0x4ff8e8++){var _0xd2db32=_0x299cc9['conditions'][_0x4ff8e8];var _0x19d925='i';var _0x25ea3f=_[_0xc60f('0x63')](_0x4dac3e,[_0xc60f('0x2b'),_0xd2db32[_0xc60f('0x4e')]]);if(!_0x25ea3f){switch(_0xd2db32['field']){case _0xc60f('0x64'):if(_0xd2db32[_0xc60f('0x65')]==0x1){_0x425e8b[_0xc60f('0x66')]('`'+_0xd2db32[_0xc60f('0x4e')]+'`\x20=\x200');}else{_0x425e8b[_0xc60f('0x66')]('`'+_0xd2db32[_0xc60f('0x4e')]+_0xc60f('0x67'));}break;case _0xc60f('0x68'):if(_0xd2db32[_0xc60f('0x69')]==='$substring'){if(_0xd2db32[_0xc60f('0x65')][_0xc60f('0x31')]('\x20')[_0xc60f('0x47')]>0x1){_0x58a82b[_0x342f0d](_0xc60f('0x6a'),qs[_0xc60f('0x6b')](_0xd2db32[_0xc60f('0x65')]),null);}else{var _0x912cac='%'+_0xd2db32[_0xc60f('0x65')]+'%';_0x58a82b[_0x342f0d]('c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?',_0x912cac,_0x912cac,_0x912cac);}}else{_0x25ea3f=_[_0xc60f('0x63')](_0x4dac3e,[_0xc60f('0x2b'),_0xc60f('0x6c')]);_0xd2db32[_0xc60f('0x4e')]='ContactId';_0xa25fdc=as['buildExpression'](_0x19d925,_0x25ea3f['type'],_0xd2db32);_0x58a82b[_0x342f0d](_0xa25fdc[_0xc60f('0x6d')],_0xa25fdc['value']['start'],_0xa25fdc[_0xc60f('0x65')][_0xc60f('0x29')]);}break;case _0xc60f('0x6e'):var _0x25a2b6=_0xd2db32[_0xc60f('0x65')][_0xc60f('0x31')](',')[_0xc60f('0x2e')](function(_0x57306d){return Number(_0x57306d);});_0x25a2b6[_0xc60f('0x32')](function(_0x1bc25c){_0x5b5777['or'](_0xc60f('0x6f'),'%,'+_0x1bc25c+',%');});_0x4e5803=_[_0xc60f('0x70')](_0x4e5803,_0x25a2b6);break;case _0xc60f('0x71'):if(_0xd2db32[_0xc60f('0x69')]===_0xc60f('0x72')){_0x58a82b[_0x342f0d](_0xc60f('0x73'),'%'+_0xd2db32['value']+'%',null);}else{_0x25ea3f=_[_0xc60f('0x63')](_0x4dac3e,[_0xc60f('0x2b'),_0xc60f('0x3b')]);_0xd2db32[_0xc60f('0x4e')]='UserId';_0xa25fdc=as[_0xc60f('0x74')](_0x19d925,_0x25ea3f['type'],_0xd2db32);_0x58a82b[_0x342f0d](_0xa25fdc[_0xc60f('0x6d')],_0xa25fdc[_0xc60f('0x65')][_0xc60f('0x75')],_0xa25fdc[_0xc60f('0x65')]['end']);}break;case _0xc60f('0x76'):_0xa25fdc=as[_0xc60f('0x74')]('me',null,_0xd2db32);_0x58a82b[_0x342f0d](_0xa25fdc[_0xc60f('0x6d')],_0xa25fdc[_0xc60f('0x65')]['start'],_0xa25fdc[_0xc60f('0x65')][_0xc60f('0x29')]);break;}}else{var _0xa25fdc=as[_0xc60f('0x74')](_0x19d925,_0x25ea3f[_0xc60f('0x77')],_0xd2db32);_0x58a82b[_0x342f0d](_0xa25fdc[_0xc60f('0x6d')],_0xa25fdc[_0xc60f('0x65')][_0xc60f('0x75')],_0xa25fdc[_0xc60f('0x65')][_0xc60f('0x29')]);}}}else{var _0x4091b4=_(_0x1877d2['query'])[_0xc60f('0x42')]()[_0xc60f('0x2e')](function(_0x3431b7){return _[_0xc60f('0x78')](_0x4dac3e,['name',_0x3431b7])?_0x3431b7:undefined;})[_0xc60f('0x79')]()['value']();if(!_[_0xc60f('0x7a')](_0x4091b4)){_0x4091b4[_0xc60f('0x32')](function(_0x4c3bbf){if(_0x4c3bbf===_0xc60f('0x7b')){_0x425e8b[_0xc60f('0x4b')]('i.SmsAccountId\x20IN\x20?',[][_0xc60f('0x7c')](_0x1877d2[_0xc60f('0x41')][_0x4c3bbf]));}else if(_0x4c3bbf===_0xc60f('0x7d')){var _0x2e3719=JSON[_0xc60f('0x7e')](_0x1877d2[_0xc60f('0x41')][_0x4c3bbf])[_0xc60f('0x7f')];var _0x14049c=JSON[_0xc60f('0x7e')](_0x1877d2[_0xc60f('0x41')][_0x4c3bbf])[_0xc60f('0x80')];_0x425e8b[_0xc60f('0x4b')](_0xc60f('0x81'),_0x2e3719,_0x14049c);}else{if(_0x1877d2[_0xc60f('0x41')][_0x4c3bbf]===_0xc60f('0x82')){_0x425e8b['where']('i.'+_0x4c3bbf+_0xc60f('0x83'));}else{_0x425e8b[_0xc60f('0x4b')]('i.'+_0x4c3bbf+_0xc60f('0x84'),_0x1877d2['query'][_0x4c3bbf]);}}});}if(_0x1877d2[_0xc60f('0x41')][_0xc60f('0x85')]){if(_0x1877d2[_0xc60f('0x41')][_0xc60f('0x85')]==0x1){_0x425e8b[_0xc60f('0x66')](_0xc60f('0x86'));}else{_0x425e8b[_0xc60f('0x66')]('`unreadMessages`\x20>\x200');}}if(_0x1877d2[_0xc60f('0x41')]['tag']){_0x4e5803=_['isArray'](_0x1877d2[_0xc60f('0x41')][_0xc60f('0x87')])?_0x1877d2[_0xc60f('0x41')]['tag']:new Array(_0x1877d2[_0xc60f('0x41')][_0xc60f('0x87')]);_0x4e5803[_0xc60f('0x32')](function(_0x2526e2){_0x5b5777['or'](_0xc60f('0x6f'),'%,'+_0x2526e2+',%');});}if(_0x1877d2['query'][_0xc60f('0x88')]){var _0x2a0231=_0x1877d2[_0xc60f('0x41')]['filter'][_0xc60f('0x89')]('\x5c','\x5c\x5c')[_0xc60f('0x89')](/'/g,'\x27\x27');if(qs[_0xc60f('0x8a')](_0x2a0231)){_0x58a82b['or'](_0xc60f('0x8b'),_0x2a0231+'%')['or'](_0xc60f('0x8c'),_0x2a0231+'%');}else{_0x58a82b['or'](_0xc60f('0x8d'),qs[_0xc60f('0x6b')](_0x2a0231))['or'](_0xc60f('0x8e'),_0x2a0231+'%');}}}_0x425e8b[_0xc60f('0x4b')](_0x58a82b);_0x425e8b[_0xc60f('0x8f')](_0xc60f('0x90'));var _0x5f10b5={'type':db[_0xc60f('0x91')][_0xc60f('0x92')][_0xc60f('0x93')],'raw':!![]};var _0x191e64=_0x425e8b[_0xc60f('0x94')]();_0x191e64[_0xc60f('0x4e')]('i.id');_0x191e64[_0xc60f('0x4e')](_0xc60f('0x95'),_0xc60f('0x64'));if(_0x490e17[_0xc60f('0x49')]){_0x490e17[_0xc60f('0x49')][_0xc60f('0x32')](function(_0x27310e){var _0x3c841f=_0x27310e[0x0]===_0xc60f('0x96')?_0x27310e[0x0]:'i.'+_0x27310e[0x0];_0x425e8b[_0xc60f('0x49')](_0x3c841f,_0x27310e[0x1]===_0xc60f('0x97')?![]:!![]);});}if(!_['isEmpty'](_0x4e5803)){_0x425e8b[_0xc60f('0x66')](_0x5b5777);_0x191e64['where'](_0xc60f('0x98'),_0x4e5803);}BPromise[_0xc60f('0x99')]()[_0xc60f('0x27')](function(){if(!_0x299cc9){if(_0x1877d2[_0xc60f('0x41')][_0xc60f('0x7b')])return;_0x191e64[_0xc60f('0x4b')](_0xc60f('0x9a'));_0x425e8b[_0xc60f('0x4b')](_0xc60f('0x9a'));return;}if(_0x1877d2['user']['role']!==_0xc60f('0x9b'))return;return _0x1877d2[_0xc60f('0x9c')]['getSmsAccounts']({'attributes':['id'],'raw':!![]})['then'](function(_0x8a96fc){if(_[_0xc60f('0x7a')](_0x8a96fc)){_0x191e64['where'](_0xc60f('0x9d'));_0x425e8b[_0xc60f('0x4b')](_0xc60f('0x9d'));}else{_0x191e64[_0xc60f('0x4b')](_0xc60f('0x9e'),_[_0xc60f('0x2e')](_0x8a96fc,'id'));_0x425e8b['where'](_0xc60f('0x9e'),_[_0xc60f('0x2e')](_0x8a96fc,'id'));}});})[_0xc60f('0x27')](function(){if(_0x1877d2[_0xc60f('0x9c')][_0xc60f('0x9f')]===_0xc60f('0x9b')&&!_0x299cc9&&!_0x1877d2[_0xc60f('0x41')][_0xc60f('0x7b')])return[];return db[_0xc60f('0xa0')][_0xc60f('0x41')](_0x191e64[_0xc60f('0xa1')](),_0x5f10b5);})[_0xc60f('0x27')](function(_0x19a6a2){_0x4274c6[_0xc60f('0x20')]=_0x19a6a2['length'];if(_0x4274c6[_0xc60f('0x20')]===0x0)return[];return db[_0xc60f('0xa0')]['query'](_0x134bc3['toString'](),_0x5f10b5)[_0xc60f('0x27')](function(_0x565f9d){_0x486ffb=_[_0xc60f('0xa2')](_0x565f9d,'id');_0x5f10b5=_[_0xc60f('0xa3')](_0x5f10b5,{'model':db[_0xc60f('0x3d')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x1877d2[_0xc60f('0x41')][_0xc60f('0x46')]){_0x490e17[_0xc60f('0x45')][_0xc60f('0x32')](function(_0x369812){_0x425e8b[_0xc60f('0x4e')]('i.'+_0x369812);});}else{_0x425e8b[_0xc60f('0x4e')](_0xc60f('0x95'),_0xc60f('0x64'));_0x425e8b[_0xc60f('0x4e')](_0xc60f('0xa4'),_0xc60f('0xa5'));_0x425e8b['field']('a.mandatoryDisposition','Account.mandatoryDisposition');_0x425e8b[_0xc60f('0x4e')]('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',_0xc60f('0x96'));_0x425e8b[_0xc60f('0x4e')](_0xc60f('0xa6'));_0x425e8b[_0xc60f('0x4e')]('c.firstName',_0xc60f('0xa7'));_0x425e8b[_0xc60f('0x4e')](_0xc60f('0xa8'),_0xc60f('0xa9'));_0x425e8b['field'](_0xc60f('0xaa'),'Contact.email');_0x425e8b['field'](_0xc60f('0xab'),'Contact.phone');_0x425e8b[_0xc60f('0x4e')](_0xc60f('0xac'),_0xc60f('0xad'));_0x425e8b[_0xc60f('0x4e')]('c.fax','Contact.fax');_0x425e8b[_0xc60f('0x4e')](_0xc60f('0xae'),'Owner.fullname');_0x425e8b[_0xc60f('0x4e')](_0xc60f('0xaf'),_0xc60f('0xb0'));_0x425e8b[_0xc60f('0x4e')](_0xc60f('0xb1'),_0xc60f('0x34'));}if(_0x490e17[_0xc60f('0x1f')])_0x425e8b[_0xc60f('0x1f')](_0x490e17[_0xc60f('0x1f')]);if(_0x490e17[_0xc60f('0x1d')])_0x425e8b['offset'](_0x490e17[_0xc60f('0x1d')]);return db[_0xc60f('0xa0')][_0xc60f('0x41')](_0x425e8b[_0xc60f('0xa1')](),_0x5f10b5);})[_0xc60f('0x27')](function(_0x42799f){if(_0x42799f['length']>0x0)_0x41eb66[_0xc60f('0x4b')](_0xc60f('0xb2'),_[_0xc60f('0x2e')](_0x42799f,'id'));return db['sequelize'][_0xc60f('0x41')](_0x41eb66[_0xc60f('0xa1')](),_0x5f10b5)['then'](function(_0x58ffc9){var _0x5e8b9a=_['groupBy'](_0x58ffc9,'SmsInteractionId');var _0x1f208f=[];_0x42799f['forEach'](function(_0x13c785){_0x1f208f[_0xc60f('0x33')](updateSmsInteraction(_0x13c785,_0x486ffb,_0x5e8b9a));});return BPromise[_0xc60f('0xb3')](_0x1f208f);});});})[_0xc60f('0x27')](function(_0x5f418b){_0x4274c6[_0xc60f('0xb4')]=_0x5f418b;return _0x4274c6;})[_0xc60f('0x27')](respondWithFilteredResult(_0x254eaa,_0x490e17))['catch'](handleError(_0x254eaa,null));};exports['show']=function(_0x394d28,_0x2710b2){var _0x146be0={'raw':![],'where':{'id':_0x394d28['params']['id']}},_0x49b0a3={};_0x49b0a3['model']=_[_0xc60f('0x42')](db[_0xc60f('0x3d')][_0xc60f('0xb5')]);_0x49b0a3[_0xc60f('0x41')]=_[_0xc60f('0x42')](_0x394d28[_0xc60f('0x41')]);_0x49b0a3['filters']=_[_0xc60f('0x44')](_0x49b0a3[_0xc60f('0x40')],_0x49b0a3[_0xc60f('0x41')]);_0x146be0[_0xc60f('0x45')]=_[_0xc60f('0x44')](_0x49b0a3[_0xc60f('0x40')],qs[_0xc60f('0x46')](_0x394d28[_0xc60f('0x41')][_0xc60f('0x46')]));_0x146be0[_0xc60f('0x45')]=_0x146be0[_0xc60f('0x45')]['length']?_0x146be0[_0xc60f('0x45')]:_0x49b0a3['model'];if(_0x394d28[_0xc60f('0x41')][_0xc60f('0xb6')]){_0x146be0[_0xc60f('0xb7')]=[{'all':!![]}];}_0x146be0=_[_0xc60f('0xa3')]({},_0x146be0,_0x394d28[_0xc60f('0xb8')]);return db[_0xc60f('0x3d')][_0xc60f('0x63')](_0x146be0)[_0xc60f('0x27')](handleEntityNotFound(_0x2710b2,null))[_0xc60f('0x27')](respondWithResult(_0x2710b2,null))[_0xc60f('0x35')](handleError(_0x2710b2,null));};exports[_0xc60f('0xb9')]=function(_0x4d54cd,_0x45e9ba){return db[_0xc60f('0x3d')][_0xc60f('0xb9')](_0x4d54cd[_0xc60f('0x76')],{})[_0xc60f('0x27')](respondWithResult(_0x45e9ba,0xc9))[_0xc60f('0x35')](handleError(_0x45e9ba,null));};exports[_0xc60f('0x26')]=function(_0x10d795,_0x119a2e){if(_0x10d795[_0xc60f('0x76')]['id']){delete _0x10d795[_0xc60f('0x76')]['id'];}return db['SmsInteraction']['find']({'where':{'id':_0x10d795[_0xc60f('0xba')]['id']}})[_0xc60f('0x27')](handleEntityNotFound(_0x119a2e,null))[_0xc60f('0x27')](saveUpdates(_0x10d795[_0xc60f('0x76')],null))['then'](respondWithResult(_0x119a2e,null))[_0xc60f('0x35')](handleError(_0x119a2e,null));};exports[_0xc60f('0x28')]=function(_0x2a64a6,_0x19fbf2){return db[_0xc60f('0x3d')][_0xc60f('0x63')]({'where':{'id':_0x2a64a6[_0xc60f('0xba')]['id']}})[_0xc60f('0x27')](handleEntityNotFound(_0x19fbf2,null))[_0xc60f('0x27')](removeEntity(_0x19fbf2,null))['catch'](handleError(_0x19fbf2,null));};exports[_0xc60f('0xbb')]=function(_0x3e3b6c,_0x5c99ef){return db['SmsInteraction'][_0xc60f('0xbb')]()[_0xc60f('0x27')](respondWithResult(_0x5c99ef,null))[_0xc60f('0x35')](handleError(_0x5c99ef,null));};exports['addMessage']=function(_0x83d520,_0x4c0208,_0x2d318f){return db[_0xc60f('0xbc')][_0xc60f('0x63')]({'where':{'id':_0x83d520[_0xc60f('0xba')]['id']}})[_0xc60f('0x27')](handleEntityNotFound(_0x4c0208,null))[_0xc60f('0x27')](function(_0x440f63){if(_0x440f63){return _0x440f63['addMessage'](_0x83d520[_0xc60f('0x76')]['ids'],_[_0xc60f('0xbd')](_0x83d520[_0xc60f('0x76')],[_0xc60f('0xbe'),'id'])||{});}})[_0xc60f('0x27')](respondWithResult(_0x4c0208,null))[_0xc60f('0x35')](handleError(_0x4c0208,null));};exports[_0xc60f('0xbf')]=function(_0x3a5ad4,_0x21564e,_0x43fc47){var _0x35a22b={'raw':![],'where':{}};var _0x5389dd={};var _0x466cd1={'count':0x0,'rows':[]};return db[_0xc60f('0x3d')][_0xc60f('0xc0')]({'where':{'id':_0x3a5ad4[_0xc60f('0xba')]['id']}})[_0xc60f('0x27')](handleEntityNotFound(_0x21564e,null))[_0xc60f('0x27')](function(_0x4036a5){if(_0x4036a5){_0x5389dd[_0xc60f('0x40')]=_[_0xc60f('0x42')](db['SmsMessage'][_0xc60f('0xb5')]);_0x5389dd[_0xc60f('0x41')]=_['keys'](_0x3a5ad4[_0xc60f('0x41')]);_0x5389dd['filters']=_[_0xc60f('0x44')](_0x5389dd[_0xc60f('0x40')],_0x5389dd[_0xc60f('0x41')]);_0x35a22b[_0xc60f('0x45')]=_['intersection'](_0x5389dd[_0xc60f('0x40')],qs[_0xc60f('0x46')](_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0x46')]));_0x35a22b[_0xc60f('0x45')]=_0x35a22b[_0xc60f('0x45')][_0xc60f('0x47')]?_0x35a22b[_0xc60f('0x45')]:_0x5389dd[_0xc60f('0x40')];if(!_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0xc1')](_0xc60f('0x48'))){_0x35a22b[_0xc60f('0x1f')]=qs['limit'](_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0x1f')]);_0x35a22b[_0xc60f('0x1d')]=qs[_0xc60f('0x1d')](_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0x1d')]);}_0x35a22b[_0xc60f('0x49')]=qs[_0xc60f('0x4a')](_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0x4a')]);_0x35a22b[_0xc60f('0x4b')]=qs[_0xc60f('0x43')](_[_0xc60f('0x4c')](_0x3a5ad4[_0xc60f('0x41')],_0x5389dd['filters']));_0x35a22b[_0xc60f('0x4b')][_0xc60f('0xc2')]=_0x4036a5['id'];if(_0x3a5ad4[_0xc60f('0x41')]['filter']){_0x35a22b[_0xc60f('0x4b')]=_[_0xc60f('0xa3')](_0x35a22b[_0xc60f('0x4b')],{'$or':_['map'](_0x35a22b[_0xc60f('0x45')],function(_0x2a36ca){var _0xaba9d5={};_0xaba9d5[_0x2a36ca]={'$like':'%'+_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0x88')]+'%'};return _0xaba9d5;})});}if(_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0x7f')]){var _0x57893f=_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0x7f')][_0xc60f('0x31')](',');var _0x2068a3={};_0x2068a3[_0x57893f[0x0]]={'$gte':moment(_0x57893f[0x1])[_0xc60f('0xc3')](_0xc60f('0xc4'))};_0x35a22b[_0xc60f('0x4b')]=_[_0xc60f('0xa3')](_0x35a22b['where'],_0x2068a3);}_0x35a22b=_['merge']({},_0x35a22b,_0x3a5ad4[_0xc60f('0xb8')]);return db[_0xc60f('0xbc')][_0xc60f('0x20')]({'where':_0x35a22b[_0xc60f('0x4b')]})['then'](function(_0x385db3){_0x466cd1['count']=_0x385db3;if(_0x3a5ad4['query']['includeAll']){_0x35a22b['include']=[{'all':!![]}];}return db[_0xc60f('0xbc')]['findAll'](_0x35a22b);})[_0xc60f('0x27')](function(_0x433aa1){_0x466cd1[_0xc60f('0xb4')]=_0x433aa1;return _0x466cd1;});}})[_0xc60f('0x27')](respondWithFilteredResult(_0x21564e,_0x35a22b))[_0xc60f('0x35')](handleError(_0x21564e,null));};exports[_0xc60f('0xc5')]=function(_0x337f40,_0x397995,_0x472bab){return db[_0xc60f('0x3d')][_0xc60f('0x63')]({'where':{'id':_0x337f40[_0xc60f('0xba')]['id']}})['then'](handleEntityNotFound(_0x397995,null))[_0xc60f('0x27')](function(_0x39fc63){if(_0x39fc63){return _0x39fc63[_0xc60f('0xc6')](_0x337f40[_0xc60f('0x76')][_0xc60f('0xbe')],_[_0xc60f('0xbd')](_0x337f40[_0xc60f('0x76')],[_0xc60f('0xbe'),'id'])||{})[_0xc60f('0xc7')](function(){return db[_0xc60f('0x6e')][_0xc60f('0xc8')]({'attributes':['id','name',_0xc60f('0x4f')],'where':{'id':_0x337f40[_0xc60f('0x76')][_0xc60f('0xbe')]}});})['then'](function(_0x3cdabd){socket[_0xc60f('0xc9')]('smsInteractionTags:save',{'id':Number(_0x337f40[_0xc60f('0xba')]['id']),'tags':_0x3cdabd||[]});return{'id':Number(_0x337f40[_0xc60f('0xba')]['id']),'tags':_0x3cdabd||[]};});}})[_0xc60f('0x27')](respondWithResult(_0x397995,null))['catch'](handleError(_0x397995,null));};exports[_0xc60f('0xca')]=function(_0x4fdaec,_0x193c51,_0x210e3a){return db['SmsInteraction'][_0xc60f('0x63')]({'where':{'id':_0x4fdaec[_0xc60f('0xba')]['id']}})['then'](handleEntityNotFound(_0x193c51,null))['then'](function(_0x1855d8){if(_0x1855d8){return _0x1855d8[_0xc60f('0xca')](_0x4fdaec[_0xc60f('0x41')][_0xc60f('0xbe')]);}})[_0xc60f('0x27')](respondWithStatusCode(_0x193c51,null))[_0xc60f('0x35')](handleError(_0x193c51,null));};exports[_0xc60f('0xcb')]=function(_0x526eb8,_0xdf49){var _0x193fc8=moment()[_0xc60f('0xcc')]()[_0xc60f('0xa1')]();var _0x31b5ec=path[_0xc60f('0xcd')](config[_0xc60f('0xce')],_0xc60f('0xcf'),'files',_0xc60f('0xd0'));var _0x5cae3a=path[_0xc60f('0xcd')](config[_0xc60f('0xce')],_0xc60f('0xcf'),'files',_0xc60f('0xd1'));var _0x3cba5c=path[_0xc60f('0xcd')](_0x31b5ec,_0x193fc8);var _0x5c0ca1=util['format']('transcript-%d-%s.zip',_0x526eb8['params']['id'],_0x193fc8);var _0x14c7e4=path[_0xc60f('0xcd')](_0x31b5ec,_0x5c0ca1);var _0x4619b8=[];_0x4619b8[_0xc60f('0x33')]({'model':db[_0xc60f('0x71')],'as':'User','attributes':['id','fullname'],'raw':!![]});_0x4619b8['push']({'model':db[_0xc60f('0xd2')],'as':_0xc60f('0x68'),'attributes':['id','firstName',_0xc60f('0xd3')],'raw':!![]});var _0x61ccfe=[{'model':db[_0xc60f('0xbc')],'as':_0xc60f('0xd4'),'attributes':['id',_0xc60f('0x76'),'createdAt',_0xc60f('0xd5'),_0xc60f('0xd6'),_0xc60f('0x85')],'include':_0x4619b8}];_0x61ccfe['push']({'model':db[_0xc60f('0xd7')],'as':_0xc60f('0xd8'),'attributes':['id',_0xc60f('0x2b')]});_0x61ccfe[_0xc60f('0x33')]({'model':db[_0xc60f('0x71')],'as':_0xc60f('0xd9'),'attributes':['id','fullname']});return db[_0xc60f('0x3d')]['find']({'where':{'id':_0x526eb8[_0xc60f('0xba')]['id']},'include':_0x61ccfe})[_0xc60f('0x27')](handleEntityNotFound(_0xdf49,null))[_0xc60f('0x27')](function(_0x1bf987){if(_0x1bf987){var _0x56315b=_0x1bf987[_0xc60f('0xda')]({'plain':!![]});fs[_0xc60f('0xdb')](_0x3cba5c);var _0x3051df={'channel':'Sms','account':_0x56315b[_0xc60f('0xd8')]['name'],'agent':_0x56315b[_0xc60f('0xd9')]?_0x56315b[_0xc60f('0xd9')]['fullname']:'N.A.','createdAt':moment(_0x56315b[_0xc60f('0x7d')])[_0xc60f('0xc3')](_0xc60f('0xc4'))[_0xc60f('0xa1')](),'closedAt':_0x56315b[_0xc60f('0x3a')]?moment(_0x56315b['closedAt'])['format']('YYYY-MM-DD\x20HH:mm:ss')['toString']():'','disposition':_0x56315b['disposition'],'messages':_(_0x56315b['Messages'])['filter']({'secret':![]})[_0xc60f('0x2e')](function(_0x4d89ca){return{'date':moment(_0x4d89ca['createdAt'])[_0xc60f('0xc3')](_0xc60f('0xc4'))[_0xc60f('0xa1')](),'sender':_0x4d89ca[_0xc60f('0xd5')]==='out'?_0x4d89ca['User']?_0x4d89ca[_0xc60f('0x71')][_0xc60f('0x2f')]:'System':_0x4d89ca[_0xc60f('0x68')][_0xc60f('0xdc')]+(_0x4d89ca[_0xc60f('0x68')][_0xc60f('0xd3')]?'\x20'+_0x4d89ca[_0xc60f('0x68')]['lastName']:''),'body':_0x4d89ca[_0xc60f('0x76')],'direction':_0x4d89ca[_0xc60f('0xd5')]==='out'?'A':'C','secret':_0x4d89ca[_0xc60f('0xd6')],'read':_0x4d89ca[_0xc60f('0x85')]};})['value']()};return ejs['renderFile'](path[_0xc60f('0xcd')](config[_0xc60f('0xce')],'server',_0xc60f('0xdd'),'downloadInteraction.ejs'),{'interaction':_0x3051df})['then'](function(_0x4c0bdf){var _0x47019d=path[_0xc60f('0xcd')](_0x3cba5c,'transcript-'+_0x56315b['id']+'-'+_0x193fc8+'.pdf');var _0x35a5da={'path':_0x47019d,'channel':_0xc60f('0xde'),'interactionId':_0x56315b['id']};return pdf[_0xc60f('0xdf')](_0x4c0bdf,_0x35a5da);})[_0xc60f('0x27')](function(){return new BPromise(function(_0x22f328,_0x1e200f){zipdir(_0x3cba5c,{'saveTo':_0x14c7e4},function(_0x2c5ef1,_0x5c82b1){if(_0x2c5ef1)return _0x1e200f(_0x2c5ef1);return _0x22f328(_0x5c82b1);});})[_0xc60f('0x27')](function(){return new BPromise(function(_0x294d22,_0x52cab2){rimraf(_0x3cba5c,function(_0x2941e4){if(_0x2941e4)_0x52cab2(_0x2941e4);return _0x294d22();});});})[_0xc60f('0x27')](function(){return _0xdf49['download'](_0x14c7e4,_0x5c0ca1,function(_0x1c92e8){if(_0x1c92e8){console[_0xc60f('0xe0')](_0xc60f('0xe1'),_0x1c92e8);}else{fs[_0xc60f('0xe2')](_0x14c7e4);}});});});}else{return _0xdf49[_0xc60f('0x1b')](0xc8);}})[_0xc60f('0x35')](handleError(_0xdf49,null));};
\ No newline at end of file