Built motion from commit e6806ed6.|2.6.0
[motion2.git] / server / api / smsInteraction / smsInteraction.controller.js
index df69531..b8f6a5f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xba5b=['Sms','YYYY-MM-DD','N.A.','closed','disposition','System','firstName','lastName','views','downloadInteraction.html','toFile','transcript-','.pdf','log','err','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','lodash','squel','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','socket.io-emitter','register','status','end','count','offset','limit','set','Content-Range','json','apply','reject','save','update','then','destroy','sendStatus','error','stack','name','send','Users','TagIds','Tags','split','push','catch','index','map','fieldName','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','select','field','color','u.id','u.fullname','ui.SmsInteractionId','from','user_has_sms_interactions','left_join','u.id\x20=\x20ui.UserId','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','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','find','value','having','`\x20=\x200','`\x20>\x200','Contact','operator','$substring','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','type','text','start','Tag','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','buildExpression','isEmpty','SmsAccountId','concat','createdAt','parse','$gte','$lte','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?','i.phone\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','i.id','Sequelize','SELECT','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','t.id\x20IN\x20?','resolve','i.SmsAccountId\x20IS\x20NOT\x20NULL','role','user','i.SmsAccountId\x20IN\x20?','agent','sequelize','toString','merge','SmsInteraction','unreadMessages','a.key','Account.key','a.mandatoryDisposition','i.*','c.firstName','Contact.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','Contact.phone','c.mobile','o.fullname','ui.SmsInteractionId\x20IN\x20?','groupBy','SmsInteractionId','all','rows','params','includeAll','include','options','create','body','describe','addMessage','SmsMessage','ids','omit','findOne','rawAttributes','format','YYYY-MM-DD\x20HH:mm:ss','findAll','setTags','spread','emit','smsInteractionTags:save','removeTags','download','unix','root','server','files','join','attachments','transcript-%d-%s.zip','fullname','CmContact','Messages','direction','Owner','get','mkdirSync','<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'];(function(_0x3c9126,_0x552791){var _0x2216c3=function(_0x2b6e5c){while(--_0x2b6e5c){_0x3c9126['push'](_0x3c9126['shift']());}};_0x2216c3(++_0x552791);}(_0xba5b,0x1de));var _0xbba5=function(_0x17d9e3,_0x1f969c){_0x17d9e3=_0x17d9e3-0x0;var _0x14192d=_0xba5b[_0x17d9e3];return _0x14192d;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xbba5('0x0'));var rimraf=require(_0xbba5('0x1'));var zipdir=require(_0xbba5('0x2'));var jsonpatch=require(_0xbba5('0x3'));var rp=require(_0xbba5('0x4'));var moment=require(_0xbba5('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xbba5('0x6'));var util=require(_0xbba5('0x7'));var path=require(_0xbba5('0x8'));var sox=require(_0xbba5('0x9'));var csv=require(_0xbba5('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xbba5('0xb'));var squel=require(_0xbba5('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xbba5('0xd'));var toCsv=require(_0xbba5('0xa'));var querystring=require(_0xbba5('0xe'));var Papa=require('papaparse');var Redis=require(_0xbba5('0xf'));var authService=require(_0xbba5('0x10'));var qs=require(_0xbba5('0x11'));var as=require(_0xbba5('0x12'));var hardwareService=require(_0xbba5('0x13'));var logger=require(_0xbba5('0x14'))(_0xbba5('0x15'));var utils=require(_0xbba5('0x16'));var config=require(_0xbba5('0x17'));var licenseUtil=require(_0xbba5('0x18'));var db=require('../../mysqldb')['db'];config[_0xbba5('0x19')]=_[_0xbba5('0x1a')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xbba5('0x1b'))(new Redis(config[_0xbba5('0x19')]));require('./smsInteraction.socket')[_0xbba5('0x1c')](socket);function respondWithStatusCode(_0x14486a,_0x335289){_0x335289=_0x335289||0xcc;return function(_0x507c79){if(_0x507c79){return _0x14486a['sendStatus'](_0x335289);}return _0x14486a[_0xbba5('0x1d')](_0x335289)[_0xbba5('0x1e')]();};}function respondWithResult(_0x79adaa,_0xe4578a){_0xe4578a=_0xe4578a||0xc8;return function(_0x5f4469){if(_0x5f4469){return _0x79adaa[_0xbba5('0x1d')](_0xe4578a)['json'](_0x5f4469);}};}function respondWithFilteredResult(_0x3feda3,_0xa9992e){return function(_0xa4454c){if(_0xa4454c){var _0x4ef50b=_0xa4454c[_0xbba5('0x1f')],_0x401766=_0xa9992e[_0xbba5('0x20')],_0x21853c=_0xa9992e[_0xbba5('0x20')]+_0xa9992e[_0xbba5('0x21')],_0xb94431;if(_0x21853c>=_0x4ef50b){_0x21853c=_0x4ef50b;_0xb94431=0xc8;}else{_0xb94431=0xce;}_0x3feda3[_0xbba5('0x1d')](_0xb94431);return _0x3feda3[_0xbba5('0x22')](_0xbba5('0x23'),_0x401766+'-'+_0x21853c+'/'+_0x4ef50b)[_0xbba5('0x24')](_0xa4454c);}return null;};}function patchUpdates(_0x1fa2a9){return function(_0x1b43d9){try{jsonpatch[_0xbba5('0x25')](_0x1b43d9,_0x1fa2a9,!![]);}catch(_0x40a02f){return BPromise[_0xbba5('0x26')](_0x40a02f);}return _0x1b43d9[_0xbba5('0x27')]();};}function saveUpdates(_0x4f6964,_0x506498){return function(_0x150900){if(_0x150900){return _0x150900[_0xbba5('0x28')](_0x4f6964)[_0xbba5('0x29')](function(_0x4ff282){return _0x4ff282;});}return null;};}function removeEntity(_0x1aeee9,_0xe2e888){return function(_0x4faf77){if(_0x4faf77){return _0x4faf77[_0xbba5('0x2a')]()['then'](function(){_0x1aeee9[_0xbba5('0x1d')](0xcc)[_0xbba5('0x1e')]();});}};}function handleEntityNotFound(_0x3d37ec,_0x53467c){return function(_0x2aadb8){if(!_0x2aadb8){_0x3d37ec[_0xbba5('0x2b')](0x194);}return _0x2aadb8;};}function handleError(_0xeaa4fa,_0x4e098f){_0x4e098f=_0x4e098f||0x1f4;return function(_0x624612){logger[_0xbba5('0x2c')](_0x624612[_0xbba5('0x2d')]);if(_0x624612['name']){delete _0x624612[_0xbba5('0x2e')];}_0xeaa4fa[_0xbba5('0x1d')](_0x4e098f)[_0xbba5('0x2f')](_0x624612);};}function getInteractionUsers(_0x54f7ad,_0x1ac3f3){return new BPromise(function(_0x1833c9,_0x396d67){try{if(_0x1ac3f3[_0x54f7ad['id']]){_0x54f7ad[_0xbba5('0x30')]=_['map'](_0x1ac3f3[_0x54f7ad['id']],function(_0x5a52ad){return{'id':_0x5a52ad['id'],'fullname':_0x5a52ad['fullname']};});}}catch(_0x4a10b0){_0x396d67(_0x4a10b0);}_0x1833c9(_0x54f7ad);});}function getInteractionTags(_0x26f19f,_0x5349c6){return new BPromise(function(_0x52dab0,_0x5044a3){try{if(_0x26f19f[_0xbba5('0x31')]){_0x26f19f[_0xbba5('0x32')]=[];_0x26f19f[_0xbba5('0x31')][_0xbba5('0x33')](',')['forEach'](function(_0x5911bd){_0x26f19f[_0xbba5('0x32')][_0xbba5('0x34')](_0x5349c6[_0x5911bd]);});}delete _0x26f19f[_0xbba5('0x31')];}catch(_0x302ae3){_0x5044a3(_0x302ae3);}_0x52dab0(_0x26f19f);});}function updateSmsInteraction(_0x1a7762,_0x321851,_0x58c0c3){return new BPromise(function(_0xc6cda7,_0x1707df){return getInteractionUsers(_0x1a7762,_0x58c0c3)[_0xbba5('0x29')](function(_0x969f4){return getInteractionTags(_0x969f4,_0x321851);})['then'](function(_0x1a2d62){_0xc6cda7(_0x1a2d62);})[_0xbba5('0x35')](function(_0x123def){_0x1707df(_0x123def);});});}exports[_0xbba5('0x36')]=function(_0x2f1b76,_0x5c5bd7){var _0x24af49={},_0x43ae4e={},_0x358e7e={'count':0x0,'rows':[]};var _0x381964=_[_0xbba5('0x37')](db['SmsInteraction']['rawAttributes'],function(_0x321579){return{'name':_0x321579[_0xbba5('0x38')],'type':_0x321579['type'][_0xbba5('0x39')]};});_0x43ae4e[_0xbba5('0x3a')]=_[_0xbba5('0x37')](_0x381964,'name');_0x43ae4e[_0xbba5('0x3b')]=_[_0xbba5('0x3c')](_0x2f1b76[_0xbba5('0x3b')]);_0x43ae4e[_0xbba5('0x3d')]=_[_0xbba5('0x3e')](_0x43ae4e[_0xbba5('0x3a')],_0x43ae4e['query']);_0x24af49[_0xbba5('0x3f')]=_[_0xbba5('0x3e')](_0x43ae4e[_0xbba5('0x3a')],qs['fields'](_0x2f1b76[_0xbba5('0x3b')][_0xbba5('0x40')]));_0x24af49[_0xbba5('0x3f')]=_0x24af49[_0xbba5('0x3f')][_0xbba5('0x41')]?_0x24af49[_0xbba5('0x3f')]:_0x43ae4e[_0xbba5('0x3a')];if(!_0x2f1b76[_0xbba5('0x3b')][_0xbba5('0x42')](_0xbba5('0x43'))){_0x24af49[_0xbba5('0x21')]=qs[_0xbba5('0x21')](_0x2f1b76[_0xbba5('0x3b')]['limit']);_0x24af49['offset']=qs[_0xbba5('0x20')](_0x2f1b76[_0xbba5('0x3b')][_0xbba5('0x20')]);}_0x24af49[_0xbba5('0x44')]=qs['sort'](_0x2f1b76['query'][_0xbba5('0x45')]);_0x24af49[_0xbba5('0x46')]=qs['filters'](_[_0xbba5('0x47')](_0x2f1b76[_0xbba5('0x3b')],_0x43ae4e['filters']),_0x381964);var _0x35a87b=[];var _0x5c336e=squel[_0xbba5('0x48')]()['field']('id')['field'](_0xbba5('0x2e'))[_0xbba5('0x49')](_0xbba5('0x4a'))['from']('tools_tags');var _0x20cfb7=squel[_0xbba5('0x48')]()[_0xbba5('0x49')](_0xbba5('0x4b'))['field'](_0xbba5('0x4c'))[_0xbba5('0x49')](_0xbba5('0x4d'))[_0xbba5('0x4e')](_0xbba5('0x4f'),'ui')[_0xbba5('0x50')]('users','u',_0xbba5('0x51'));var _0x55a167=squel[_0xbba5('0x48')]()['from']('sms_interactions','i')['left_join'](_0xbba5('0x52'),'c',_0xbba5('0x53'))[_0xbba5('0x50')]('users','o',_0xbba5('0x54'))[_0xbba5('0x50')]('sms_accounts','a',_0xbba5('0x55'))[_0xbba5('0x50')](_0xbba5('0x56'),'me',_0xbba5('0x57'))['left_join'](_0xbba5('0x58'),'it',_0xbba5('0x59'))[_0xbba5('0x50')](_0xbba5('0x5a'),'t',_0xbba5('0x5b'));var _0x434732=squel['expr']();var _0x448dba=[];var _0x29b3c5=squel[_0xbba5('0x5c')]();var _0x49df3d;if(_0x2f1b76[_0xbba5('0x3b')]['search']){_0x49df3d=as['parseSearch'](_0x2f1b76['query'][_0xbba5('0x5d')]);var _0x25925b=_0x49df3d[_0xbba5('0x5e')];for(var _0x5a7c1e=0x0;_0x5a7c1e<_0x49df3d[_0xbba5('0x5f')][_0xbba5('0x41')];_0x5a7c1e++){var _0x37a31a=_0x49df3d['conditions'][_0x5a7c1e];var _0x4b1886='i';var _0x4173c9=_[_0xbba5('0x60')](_0x381964,[_0xbba5('0x2e'),_0x37a31a[_0xbba5('0x49')]]);if(!_0x4173c9){switch(_0x37a31a[_0xbba5('0x49')]){case'unreadMessages':if(_0x37a31a[_0xbba5('0x61')]==0x1){_0x55a167[_0xbba5('0x62')]('`'+_0x37a31a[_0xbba5('0x49')]+_0xbba5('0x63'));}else{_0x55a167['having']('`'+_0x37a31a['field']+_0xbba5('0x64'));}break;case _0xbba5('0x65'):if(_0x37a31a[_0xbba5('0x66')]===_0xbba5('0x67')){if(_0x37a31a[_0xbba5('0x61')][_0xbba5('0x33')]('\x20')[_0xbba5('0x41')]>0x1){_0x434732[_0x25925b]('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs['getFullTextValue'](_0x37a31a[_0xbba5('0x61')]),null);}else{var _0x42c5cb='%'+_0x37a31a[_0xbba5('0x61')]+'%';_0x434732[_0x25925b](_0xbba5('0x68'),_0x42c5cb,_0x42c5cb,_0x42c5cb);}}else{_0x4173c9=_[_0xbba5('0x60')](_0x381964,[_0xbba5('0x2e'),_0xbba5('0x69')]);_0x37a31a['field']=_0xbba5('0x69');_0x2440ef=as['buildExpression'](_0x4b1886,_0x4173c9[_0xbba5('0x6a')],_0x37a31a);_0x434732[_0x25925b](_0x2440ef[_0xbba5('0x6b')],_0x2440ef[_0xbba5('0x61')][_0xbba5('0x6c')],_0x2440ef[_0xbba5('0x61')][_0xbba5('0x1e')]);}break;case _0xbba5('0x6d'):var _0x57b747=_0x37a31a[_0xbba5('0x61')][_0xbba5('0x33')](',')[_0xbba5('0x37')](function(_0x28a49c){return Number(_0x28a49c);});_0x57b747[_0xbba5('0x6e')](function(_0x4f825a){_0x29b3c5['or'](_0xbba5('0x6f'),'%,'+_0x4f825a+',%');});_0x448dba=_['union'](_0x448dba,_0x57b747);break;case _0xbba5('0x70'):if(_0x37a31a[_0xbba5('0x66')]===_0xbba5('0x67')){_0x434732[_0x25925b](_0xbba5('0x71'),'%'+_0x37a31a[_0xbba5('0x61')]+'%',null);}else{_0x4173c9=_[_0xbba5('0x60')](_0x381964,[_0xbba5('0x2e'),_0xbba5('0x72')]);_0x37a31a[_0xbba5('0x49')]=_0xbba5('0x72');_0x2440ef=as[_0xbba5('0x73')](_0x4b1886,_0x4173c9['type'],_0x37a31a);_0x434732[_0x25925b](_0x2440ef['text'],_0x2440ef[_0xbba5('0x61')][_0xbba5('0x6c')],_0x2440ef['value']['end']);}break;case'body':_0x2440ef=as[_0xbba5('0x73')]('me',null,_0x37a31a);_0x434732[_0x25925b](_0x2440ef[_0xbba5('0x6b')],_0x2440ef['value'][_0xbba5('0x6c')],_0x2440ef[_0xbba5('0x61')][_0xbba5('0x1e')]);break;}}else{var _0x2440ef=as[_0xbba5('0x73')](_0x4b1886,_0x4173c9[_0xbba5('0x6a')],_0x37a31a);_0x434732[_0x25925b](_0x2440ef['text'],_0x2440ef[_0xbba5('0x61')]['start'],_0x2440ef[_0xbba5('0x61')][_0xbba5('0x1e')]);}}}else{var _0x3ac7c3=_(_0x2f1b76[_0xbba5('0x3b')])['keys']()[_0xbba5('0x37')](function(_0x4996dc){return _['some'](_0x381964,[_0xbba5('0x2e'),_0x4996dc])?_0x4996dc:undefined;})['compact']()[_0xbba5('0x61')]();if(!_[_0xbba5('0x74')](_0x3ac7c3)){_0x3ac7c3['forEach'](function(_0x2811d5){if(_0x2811d5===_0xbba5('0x75')){_0x55a167[_0xbba5('0x46')]('i.SmsAccountId\x20IN\x20?',[][_0xbba5('0x76')](_0x2f1b76[_0xbba5('0x3b')][_0x2811d5]));}else if(_0x2811d5===_0xbba5('0x77')){var _0x1706f0=JSON[_0xbba5('0x78')](_0x2f1b76[_0xbba5('0x3b')][_0x2811d5])[_0xbba5('0x79')];var _0x55f93f=JSON[_0xbba5('0x78')](_0x2f1b76[_0xbba5('0x3b')][_0x2811d5])[_0xbba5('0x7a')];_0x55a167['where'](_0xbba5('0x7b'),_0x1706f0,_0x55f93f);}else{if(_0x2f1b76['query'][_0x2811d5]===_0xbba5('0x7c')){_0x55a167['where']('i.'+_0x2811d5+_0xbba5('0x7d'));}else{_0x55a167[_0xbba5('0x46')]('i.'+_0x2811d5+_0xbba5('0x7e'),_0x2f1b76[_0xbba5('0x3b')][_0x2811d5]);}}});}if(_0x2f1b76[_0xbba5('0x3b')]['read']){if(_0x2f1b76[_0xbba5('0x3b')][_0xbba5('0x7f')]==0x1){_0x55a167['having'](_0xbba5('0x80'));}else{_0x55a167[_0xbba5('0x62')](_0xbba5('0x81'));}}if(_0x2f1b76[_0xbba5('0x3b')][_0xbba5('0x82')]){_0x448dba=_[_0xbba5('0x83')](_0x2f1b76[_0xbba5('0x3b')]['tag'])?_0x2f1b76[_0xbba5('0x3b')]['tag']:new Array(_0x2f1b76[_0xbba5('0x3b')][_0xbba5('0x82')]);_0x448dba[_0xbba5('0x6e')](function(_0xc09f3c){_0x29b3c5['or'](_0xbba5('0x6f'),'%,'+_0xc09f3c+',%');});}if(_0x2f1b76[_0xbba5('0x3b')][_0xbba5('0x84')]){var _0x40a016=_0x2f1b76['query'][_0xbba5('0x84')]['replace']('\x5c','\x5c\x5c')[_0xbba5('0x85')](/'/g,'\x27\x27');if(qs[_0xbba5('0x86')](_0x40a016)){_0x434732['or'](_0xbba5('0x87'),_0x40a016+'%')['or'](_0xbba5('0x88'),_0x40a016+'%');}else{_0x434732['or'](_0xbba5('0x89'),qs[_0xbba5('0x8a')](_0x40a016))['or']('CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?',_0x40a016+'%');}}}_0x55a167[_0xbba5('0x46')](_0x434732);_0x55a167['group'](_0xbba5('0x8b'));var _0x2dcb45={'type':db[_0xbba5('0x8c')]['QueryTypes'][_0xbba5('0x8d')],'raw':!![]};var _0x2c496d=_0x55a167['clone']();_0x2c496d['field'](_0xbba5('0x8b'));_0x2c496d[_0xbba5('0x49')](_0xbba5('0x8e'),'unreadMessages');if(_0x24af49[_0xbba5('0x44')]){_0x24af49[_0xbba5('0x44')][_0xbba5('0x6e')](function(_0xb36551){var _0x296a58=_0xb36551[0x0]===_0xbba5('0x8f')?_0xb36551[0x0]:'i.'+_0xb36551[0x0];_0x55a167['order'](_0x296a58,_0xb36551[0x1]==='DESC'?![]:!![]);});}if(!_[_0xbba5('0x74')](_0x448dba)){_0x55a167[_0xbba5('0x62')](_0x29b3c5);_0x2c496d[_0xbba5('0x46')](_0xbba5('0x90'),_0x448dba);}BPromise[_0xbba5('0x91')]()['then'](function(){if(!_0x49df3d){if(_0x2f1b76[_0xbba5('0x3b')][_0xbba5('0x75')])return;_0x2c496d['where']('i.SmsAccountId\x20IS\x20NOT\x20NULL');_0x55a167[_0xbba5('0x46')](_0xbba5('0x92'));return;}if(_0x2f1b76['user'][_0xbba5('0x93')]!=='agent')return;return _0x2f1b76[_0xbba5('0x94')]['getSmsAccounts']({'attributes':['id'],'raw':!![]})['then'](function(_0x3ee142){if(_[_0xbba5('0x74')](_0x3ee142)){_0x2c496d[_0xbba5('0x46')]('i.SmsAccountId\x20IS\x20NULL');_0x55a167[_0xbba5('0x46')]('i.SmsAccountId\x20IS\x20NULL');}else{_0x2c496d[_0xbba5('0x46')](_0xbba5('0x95'),_['map'](_0x3ee142,'id'));_0x55a167[_0xbba5('0x46')](_0xbba5('0x95'),_['map'](_0x3ee142,'id'));}});})[_0xbba5('0x29')](function(){if(_0x2f1b76[_0xbba5('0x94')][_0xbba5('0x93')]===_0xbba5('0x96')&&!_0x49df3d&&!_0x2f1b76[_0xbba5('0x3b')][_0xbba5('0x75')])return[];return db[_0xbba5('0x97')][_0xbba5('0x3b')](_0x2c496d[_0xbba5('0x98')](),_0x2dcb45);})[_0xbba5('0x29')](function(_0x5a7e3f){_0x358e7e['count']=_0x5a7e3f[_0xbba5('0x41')];if(_0x358e7e[_0xbba5('0x1f')]===0x0)return[];return db[_0xbba5('0x97')][_0xbba5('0x3b')](_0x5c336e[_0xbba5('0x98')](),_0x2dcb45)[_0xbba5('0x29')](function(_0x5b4247){_0x35a87b=_['keyBy'](_0x5b4247,'id');_0x2dcb45=_[_0xbba5('0x99')](_0x2dcb45,{'model':db[_0xbba5('0x9a')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x2f1b76['query'][_0xbba5('0x40')]){_0x24af49[_0xbba5('0x3f')][_0xbba5('0x6e')](function(_0x4ab2ef){_0x55a167[_0xbba5('0x49')]('i.'+_0x4ab2ef);});}else{_0x55a167[_0xbba5('0x49')](_0xbba5('0x8e'),_0xbba5('0x9b'));_0x55a167[_0xbba5('0x49')](_0xbba5('0x9c'),_0xbba5('0x9d'));_0x55a167[_0xbba5('0x49')](_0xbba5('0x9e'),'Account.mandatoryDisposition');_0x55a167[_0xbba5('0x49')]('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',_0xbba5('0x8f'));_0x55a167[_0xbba5('0x49')](_0xbba5('0x9f'));_0x55a167[_0xbba5('0x49')](_0xbba5('0xa0'),_0xbba5('0xa1'));_0x55a167[_0xbba5('0x49')](_0xbba5('0xa2'),_0xbba5('0xa3'));_0x55a167[_0xbba5('0x49')](_0xbba5('0xa4'),_0xbba5('0xa5'));_0x55a167[_0xbba5('0x49')](_0xbba5('0xa6'),_0xbba5('0xa7'));_0x55a167[_0xbba5('0x49')](_0xbba5('0xa8'),'Contact.mobile');_0x55a167[_0xbba5('0x49')]('c.fax','Contact.fax');_0x55a167['field'](_0xbba5('0xa9'),'Owner.fullname');_0x55a167[_0xbba5('0x49')]('o.internal','Owner.internal');_0x55a167[_0xbba5('0x49')]('GROUP_CONCAT(DISTINCT\x20t.id)',_0xbba5('0x31'));}if(_0x24af49[_0xbba5('0x21')])_0x55a167[_0xbba5('0x21')](_0x24af49[_0xbba5('0x21')]);if(_0x24af49[_0xbba5('0x20')])_0x55a167['offset'](_0x24af49[_0xbba5('0x20')]);return db['sequelize'][_0xbba5('0x3b')](_0x55a167[_0xbba5('0x98')](),_0x2dcb45);})[_0xbba5('0x29')](function(_0x37a4b1){_0x20cfb7[_0xbba5('0x46')](_0xbba5('0xaa'),_[_0xbba5('0x37')](_0x37a4b1,'id'));return db[_0xbba5('0x97')][_0xbba5('0x3b')](_0x20cfb7[_0xbba5('0x98')](),_0x2dcb45)[_0xbba5('0x29')](function(_0x2157d8){var _0x517721=_[_0xbba5('0xab')](_0x2157d8,_0xbba5('0xac'));var _0x5676ba=[];_0x37a4b1[_0xbba5('0x6e')](function(_0xcee25){_0x5676ba[_0xbba5('0x34')](updateSmsInteraction(_0xcee25,_0x35a87b,_0x517721));});return BPromise[_0xbba5('0xad')](_0x5676ba);});});})[_0xbba5('0x29')](function(_0x2f5d2c){_0x358e7e[_0xbba5('0xae')]=_0x2f5d2c;return _0x358e7e;})[_0xbba5('0x29')](respondWithFilteredResult(_0x5c5bd7,_0x24af49))[_0xbba5('0x35')](handleError(_0x5c5bd7,null));};exports['show']=function(_0x402605,_0x28cd44){var _0x22f6f5={'raw':![],'where':{'id':_0x402605[_0xbba5('0xaf')]['id']}},_0x52be4b={};_0x52be4b['model']=_['keys'](db[_0xbba5('0x9a')]['rawAttributes']);_0x52be4b[_0xbba5('0x3b')]=_[_0xbba5('0x3c')](_0x402605[_0xbba5('0x3b')]);_0x52be4b[_0xbba5('0x3d')]=_['intersection'](_0x52be4b[_0xbba5('0x3a')],_0x52be4b['query']);_0x22f6f5[_0xbba5('0x3f')]=_[_0xbba5('0x3e')](_0x52be4b[_0xbba5('0x3a')],qs[_0xbba5('0x40')](_0x402605['query']['fields']));_0x22f6f5[_0xbba5('0x3f')]=_0x22f6f5[_0xbba5('0x3f')][_0xbba5('0x41')]?_0x22f6f5[_0xbba5('0x3f')]:_0x52be4b[_0xbba5('0x3a')];if(_0x402605[_0xbba5('0x3b')][_0xbba5('0xb0')]){_0x22f6f5[_0xbba5('0xb1')]=[{'all':!![]}];}_0x22f6f5=_[_0xbba5('0x99')]({},_0x22f6f5,_0x402605[_0xbba5('0xb2')]);return db[_0xbba5('0x9a')][_0xbba5('0x60')](_0x22f6f5)['then'](handleEntityNotFound(_0x28cd44,null))[_0xbba5('0x29')](respondWithResult(_0x28cd44,null))[_0xbba5('0x35')](handleError(_0x28cd44,null));};exports[_0xbba5('0xb3')]=function(_0x39b02d,_0x5d2742){return db[_0xbba5('0x9a')][_0xbba5('0xb3')](_0x39b02d['body'],{})['then'](respondWithResult(_0x5d2742,0xc9))[_0xbba5('0x35')](handleError(_0x5d2742,null));};exports[_0xbba5('0x28')]=function(_0x5d5ce4,_0x26bea5){if(_0x5d5ce4[_0xbba5('0xb4')]['id']){delete _0x5d5ce4[_0xbba5('0xb4')]['id'];}return db['SmsInteraction']['find']({'where':{'id':_0x5d5ce4[_0xbba5('0xaf')]['id']}})[_0xbba5('0x29')](handleEntityNotFound(_0x26bea5,null))[_0xbba5('0x29')](saveUpdates(_0x5d5ce4[_0xbba5('0xb4')],null))['then'](respondWithResult(_0x26bea5,null))[_0xbba5('0x35')](handleError(_0x26bea5,null));};exports[_0xbba5('0x2a')]=function(_0x47e8b8,_0x4c0a51){return db['SmsInteraction'][_0xbba5('0x60')]({'where':{'id':_0x47e8b8['params']['id']}})[_0xbba5('0x29')](handleEntityNotFound(_0x4c0a51,null))[_0xbba5('0x29')](removeEntity(_0x4c0a51,null))[_0xbba5('0x35')](handleError(_0x4c0a51,null));};exports[_0xbba5('0xb5')]=function(_0x566ed8,_0x1ffea9){return db[_0xbba5('0x9a')][_0xbba5('0xb5')]()[_0xbba5('0x29')](respondWithResult(_0x1ffea9,null))['catch'](handleError(_0x1ffea9,null));};exports[_0xbba5('0xb6')]=function(_0xff261e,_0x526478,_0x4f1c7e){return db[_0xbba5('0xb7')]['find']({'where':{'id':_0xff261e[_0xbba5('0xaf')]['id']}})[_0xbba5('0x29')](handleEntityNotFound(_0x526478,null))[_0xbba5('0x29')](function(_0x3e07b8){if(_0x3e07b8){return _0x3e07b8[_0xbba5('0xb6')](_0xff261e['body'][_0xbba5('0xb8')],_[_0xbba5('0xb9')](_0xff261e[_0xbba5('0xb4')],[_0xbba5('0xb8'),'id'])||{});}})[_0xbba5('0x29')](respondWithResult(_0x526478,null))[_0xbba5('0x35')](handleError(_0x526478,null));};exports['getMessages']=function(_0x6b1562,_0x340aaf,_0x13a059){var _0x30a93c={'raw':![],'where':{}};var _0x458a29={};var _0x1c1f8f={'count':0x0,'rows':[]};return db[_0xbba5('0x9a')][_0xbba5('0xba')]({'where':{'id':_0x6b1562[_0xbba5('0xaf')]['id']}})[_0xbba5('0x29')](handleEntityNotFound(_0x340aaf,null))[_0xbba5('0x29')](function(_0x3ae5e4){if(_0x3ae5e4){_0x458a29[_0xbba5('0x3a')]=_[_0xbba5('0x3c')](db['SmsMessage'][_0xbba5('0xbb')]);_0x458a29[_0xbba5('0x3b')]=_[_0xbba5('0x3c')](_0x6b1562['query']);_0x458a29['filters']=_[_0xbba5('0x3e')](_0x458a29[_0xbba5('0x3a')],_0x458a29[_0xbba5('0x3b')]);_0x30a93c['attributes']=_[_0xbba5('0x3e')](_0x458a29[_0xbba5('0x3a')],qs['fields'](_0x6b1562[_0xbba5('0x3b')][_0xbba5('0x40')]));_0x30a93c[_0xbba5('0x3f')]=_0x30a93c['attributes'][_0xbba5('0x41')]?_0x30a93c['attributes']:_0x458a29[_0xbba5('0x3a')];if(!_0x6b1562['query'][_0xbba5('0x42')](_0xbba5('0x43'))){_0x30a93c[_0xbba5('0x21')]=qs['limit'](_0x6b1562['query'][_0xbba5('0x21')]);_0x30a93c[_0xbba5('0x20')]=qs[_0xbba5('0x20')](_0x6b1562['query'][_0xbba5('0x20')]);}_0x30a93c['order']=qs['sort'](_0x6b1562[_0xbba5('0x3b')]['sort']);_0x30a93c[_0xbba5('0x46')]=qs['filters'](_[_0xbba5('0x47')](_0x6b1562[_0xbba5('0x3b')],_0x458a29['filters']));_0x30a93c[_0xbba5('0x46')][_0xbba5('0xac')]=_0x3ae5e4['id'];if(_0x6b1562[_0xbba5('0x3b')][_0xbba5('0x84')]){_0x30a93c[_0xbba5('0x46')]=_[_0xbba5('0x99')](_0x30a93c['where'],{'$or':_[_0xbba5('0x37')](_0x30a93c[_0xbba5('0x3f')],function(_0x38480c){var _0x5ba16e={};_0x5ba16e[_0x38480c]={'$like':'%'+_0x6b1562[_0xbba5('0x3b')][_0xbba5('0x84')]+'%'};return _0x5ba16e;})});}if(_0x6b1562[_0xbba5('0x3b')][_0xbba5('0x79')]){var _0x2b4537=_0x6b1562[_0xbba5('0x3b')][_0xbba5('0x79')]['split'](',');var _0x29d184={};_0x29d184[_0x2b4537[0x0]]={'$gte':moment(_0x2b4537[0x1])[_0xbba5('0xbc')](_0xbba5('0xbd'))};_0x30a93c[_0xbba5('0x46')]=_['merge'](_0x30a93c[_0xbba5('0x46')],_0x29d184);}_0x30a93c=_[_0xbba5('0x99')]({},_0x30a93c,_0x6b1562[_0xbba5('0xb2')]);return db[_0xbba5('0xb7')][_0xbba5('0x1f')]({'where':_0x30a93c['where']})[_0xbba5('0x29')](function(_0x5eedb3){_0x1c1f8f['count']=_0x5eedb3;if(_0x6b1562[_0xbba5('0x3b')][_0xbba5('0xb0')]){_0x30a93c[_0xbba5('0xb1')]=[{'all':!![]}];}return db[_0xbba5('0xb7')][_0xbba5('0xbe')](_0x30a93c);})[_0xbba5('0x29')](function(_0x249fee){_0x1c1f8f[_0xbba5('0xae')]=_0x249fee;return _0x1c1f8f;});}})[_0xbba5('0x29')](respondWithFilteredResult(_0x340aaf,_0x30a93c))['catch'](handleError(_0x340aaf,null));};exports['addTags']=function(_0x470ca7,_0x565994,_0x591307){return db[_0xbba5('0x9a')][_0xbba5('0x60')]({'where':{'id':_0x470ca7[_0xbba5('0xaf')]['id']}})['then'](handleEntityNotFound(_0x565994,null))[_0xbba5('0x29')](function(_0x4de99f){if(_0x4de99f){return _0x4de99f[_0xbba5('0xbf')](_0x470ca7[_0xbba5('0xb4')][_0xbba5('0xb8')],_[_0xbba5('0xb9')](_0x470ca7[_0xbba5('0xb4')],['ids','id'])||{})[_0xbba5('0xc0')](function(){return db[_0xbba5('0x6d')][_0xbba5('0xbe')]({'attributes':['id',_0xbba5('0x2e'),_0xbba5('0x4a')],'where':{'id':_0x470ca7[_0xbba5('0xb4')][_0xbba5('0xb8')]}});})['then'](function(_0x395fbb){socket[_0xbba5('0xc1')](_0xbba5('0xc2'),{'id':Number(_0x470ca7[_0xbba5('0xaf')]['id']),'tags':_0x395fbb||[]});return{'id':Number(_0x470ca7[_0xbba5('0xaf')]['id']),'tags':_0x395fbb||[]};});}})[_0xbba5('0x29')](respondWithResult(_0x565994,null))['catch'](handleError(_0x565994,null));};exports[_0xbba5('0xc3')]=function(_0x138d9a,_0x5c6aa7,_0x497be7){return db[_0xbba5('0x9a')][_0xbba5('0x60')]({'where':{'id':_0x138d9a['params']['id']}})['then'](handleEntityNotFound(_0x5c6aa7,null))[_0xbba5('0x29')](function(_0xc756a8){if(_0xc756a8){return _0xc756a8[_0xbba5('0xc3')](_0x138d9a['query'][_0xbba5('0xb8')]);}})[_0xbba5('0x29')](respondWithStatusCode(_0x5c6aa7,null))['catch'](handleError(_0x5c6aa7,null));};exports[_0xbba5('0xc4')]=function(_0x49de17,_0x4536c9){var _0x5089df=moment()[_0xbba5('0xc5')]()['toString']();var _0x4a16bd=path['join'](config[_0xbba5('0xc6')],_0xbba5('0xc7'),_0xbba5('0xc8'),'tmp');var _0x3b77de=path[_0xbba5('0xc9')](config[_0xbba5('0xc6')],_0xbba5('0xc7'),'files',_0xbba5('0xca'));var _0x178601=path[_0xbba5('0xc9')](_0x4a16bd,_0x5089df);var _0x629aa5=util['format'](_0xbba5('0xcb'),_0x49de17['params']['id'],_0x5089df);var _0x4c9e4e=path[_0xbba5('0xc9')](_0x4a16bd,_0x629aa5);var _0x68c2e2=[];_0x68c2e2[_0xbba5('0x34')]({'model':db[_0xbba5('0x70')],'as':_0xbba5('0x70'),'attributes':['id',_0xbba5('0xcc')],'raw':!![]});_0x68c2e2[_0xbba5('0x34')]({'model':db[_0xbba5('0xcd')],'as':_0xbba5('0x65'),'attributes':['id','firstName','lastName'],'raw':!![]});var _0xbea35=[{'model':db[_0xbba5('0xb7')],'as':_0xbba5('0xce'),'attributes':['id',_0xbba5('0xb4'),_0xbba5('0x77'),_0xbba5('0xcf'),'secret',_0xbba5('0x7f')],'include':_0x68c2e2}];_0xbea35[_0xbba5('0x34')]({'model':db['SmsAccount'],'as':'Account','attributes':['id',_0xbba5('0x2e')]});_0xbea35[_0xbba5('0x34')]({'model':db[_0xbba5('0x70')],'as':_0xbba5('0xd0'),'attributes':['id',_0xbba5('0xcc')]});return db[_0xbba5('0x9a')]['find']({'where':{'id':_0x49de17[_0xbba5('0xaf')]['id']},'include':_0xbea35})[_0xbba5('0x29')](handleEntityNotFound(_0x4536c9,null))[_0xbba5('0x29')](function(_0x251571){if(_0x251571){var _0x209887=_0x251571[_0xbba5('0xd1')]({'plain':!![]});fs[_0xbba5('0xd2')](_0x178601);var _0x4c7a4f={'format':'A4','border':'10px','header':{'height':'40px','contents':{'first':_0xbba5('0xd3')}},'footer':{'height':_0xbba5('0xd4'),'contents':{'default':util['format'](_0xbba5('0xd5'),util[_0xbba5('0xbc')](_0xbba5('0xd6'),_0xbba5('0xd7'),_0x209887['id']),moment()[_0xbba5('0xbc')](_0xbba5('0xd8'))[_0xbba5('0x98')]())}}};var _0x1251b5={'channel':_0xbba5('0xd7'),'account':_0x209887['Account'][_0xbba5('0x2e')],'agent':_0x209887[_0xbba5('0xd0')]?_0x209887['Owner'][_0xbba5('0xcc')]:_0xbba5('0xd9'),'createdAt':moment(_0x209887[_0xbba5('0x77')])['format'](_0xbba5('0xbd'))[_0xbba5('0x98')](),'closedAt':_0x209887[_0xbba5('0xda')]?moment(_0x209887['closedAt'])[_0xbba5('0xbc')](_0xbba5('0xbd'))['toString']():'','disposition':_0x209887[_0xbba5('0xdb')],'messages':_(_0x209887[_0xbba5('0xce')])[_0xbba5('0x84')]({'secret':![]})[_0xbba5('0x37')](function(_0x4391d2){return{'date':moment(_0x4391d2[_0xbba5('0x77')])['format'](_0xbba5('0xbd'))['toString'](),'sender':_0x4391d2[_0xbba5('0xcf')]==='out'?_0x4391d2[_0xbba5('0x70')]?_0x4391d2[_0xbba5('0x70')][_0xbba5('0xcc')]:_0xbba5('0xdc'):_0x4391d2[_0xbba5('0x65')][_0xbba5('0xdd')]+(_0x4391d2[_0xbba5('0x65')][_0xbba5('0xde')]?'\x20'+_0x4391d2[_0xbba5('0x65')][_0xbba5('0xde')]:''),'body':_0x4391d2[_0xbba5('0xb4')],'direction':_0x4391d2[_0xbba5('0xcf')]==='out'?'A':'C','secret':_0x4391d2['secret'],'read':_0x4391d2['read']};})[_0xbba5('0x61')]()};return ejs['renderFile'](path['join'](config[_0xbba5('0xc6')],_0xbba5('0xc7'),_0xbba5('0xdf'),_0xbba5('0xe0')),{'interaction':_0x1251b5})[_0xbba5('0x29')](function(_0x53f993){return new BPromise(function(_0x309079,_0x36ad4a){pdf['create'](_0x53f993,_0x4c7a4f)[_0xbba5('0xe1')](path['join'](_0x178601,_0xbba5('0xe2')+_0x209887['id']+'-'+_0x5089df+_0xbba5('0xe3')),function(_0xf38fab,_0x2cf2b1){if(_0xf38fab)return _0x36ad4a(_0xf38fab);_0x309079(_0x2cf2b1);});});})['then'](function(){return new BPromise(function(_0x5c4224,_0x3f9d20){zipdir(_0x178601,{'saveTo':_0x4c9e4e},function(_0x330a10,_0x2eca2b){if(_0x330a10)return _0x3f9d20(_0x330a10);return _0x5c4224(_0x2eca2b);});})[_0xbba5('0x29')](function(){return new BPromise(function(_0x57f417,_0x162ada){rimraf(_0x178601,function(_0x31ae2b){if(_0x31ae2b)_0x162ada(_0x31ae2b);return _0x57f417();});});})['then'](function(){return _0x4536c9['download'](_0x4c9e4e,_0x629aa5,function(_0x3f910f){if(_0x3f910f){console[_0xbba5('0xe4')](_0xbba5('0xe5'),_0x3f910f);}else{fs[_0xbba5('0xe6')](_0x4c9e4e);}});});});}else{return _0x4536c9[_0xbba5('0x2b')](0xc8);}})[_0xbba5('0x35')](handleError(_0x4536c9,null));};
\ No newline at end of file
+var _0xda26=['direction','secret','SmsAccount','Owner','get','YYYY-MM-DD\x20HH:mm:ss','closedAt','out','System','views','downloadInteraction.ejs','.pdf','createPdfFromHTML','unlinkSync','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../components/export/pdf','../../config/license/hardware','../../config/logger','../../config/license/util','../../mysqldb','redis','localhost','./smsInteraction.socket','register','sendStatus','status','end','json','offset','undefined','limit','count','Content-Range','apply','update','then','destroy','error','stack','name','send','Users','map','fullname','TagIds','Tags','waiting','talking','answered','unmanaged','closed','UserId','total','index','SmsInteraction','rawAttributes','fieldName','type','key','query','filters','intersection','attributes','model','fields','length','hasOwnProperty','nolimit','order','sort','select','field','from','tools_tags','u.id','u.fullname','ui.SmsInteractionId','users','u.id\x20=\x20ui.UserId','left_join','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','sms_accounts','sms_messages','me.SmsInteractionId\x20=\x20i.id','it.SmsInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch','sqlOperator','conditions','find','unreadMessages','value','having','`\x20=\x200','Contact','operator','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','$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','buildExpression','keys','some','isEmpty','forEach','SmsAccountId','where','i.SmsAccountId\x20IN\x20?','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','read','`unreadMessages`\x20=\x200','tag','isArray','filter','replace','isNumeric','i.phone\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','group','Sequelize','QueryTypes','SELECT','i.id','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','DESC','resolve','i.SmsAccountId\x20IS\x20NOT\x20NULL','user','role','agent','i.SmsAccountId\x20IS\x20NULL','toString','sequelize','keyBy','merge','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','i.*','c.firstName','Contact.firstName','c.lastName','Contact.lastName','c.email','c.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','groupBy','push','all','rows','show','params','includeAll','include','catch','create','body','describe','addMessage','SmsMessage','ids','omit','findOne','pick','SmsInteractionId','format','options','setTags','spread','findAll','color','emit','smsInteractionTags:save','removeTags','download','unix','join','root','server','files','attachments','transcript-%d-%s.zip','User','CmContact','firstName','lastName','Messages'];(function(_0x1203f,_0x554bbc){var _0x365f0a=function(_0x3531d0){while(--_0x3531d0){_0x1203f['push'](_0x1203f['shift']());}};_0x365f0a(++_0x554bbc);}(_0xda26,0xf4));var _0x6da2=function(_0x104da2,_0x19c390){_0x104da2=_0x104da2-0x0;var _0x5eab7e=_0xda26[_0x104da2];return _0x5eab7e;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x6da2('0x0'));var zipdir=require(_0x6da2('0x1'));var jsonpatch=require(_0x6da2('0x2'));var rp=require(_0x6da2('0x3'));var moment=require(_0x6da2('0x4'));var BPromise=require(_0x6da2('0x5'));var Mustache=require(_0x6da2('0x6'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x6da2('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x6da2('0x8'));var squel=require(_0x6da2('0x9'));var crypto=require(_0x6da2('0xa'));var jsforce=require('jsforce');var deskjs=require(_0x6da2('0xb'));var toCsv=require('to-csv');var querystring=require(_0x6da2('0xc'));var Papa=require(_0x6da2('0xd'));var Redis=require(_0x6da2('0xe'));var authService=require(_0x6da2('0xf'));var qs=require(_0x6da2('0x10'));var as=require(_0x6da2('0x11'));var pdf=require(_0x6da2('0x12'));var hardwareService=require(_0x6da2('0x13'));var logger=require(_0x6da2('0x14'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x6da2('0x15'));var db=require(_0x6da2('0x16'))['db'];config[_0x6da2('0x17')]=_['defaults'](config[_0x6da2('0x17')],{'host':_0x6da2('0x18'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x6da2('0x17')]));require(_0x6da2('0x19'))[_0x6da2('0x1a')](socket);function respondWithStatusCode(_0xeac6c6,_0x160b51){_0x160b51=_0x160b51||0xcc;return function(_0x25395f){if(_0x25395f){return _0xeac6c6[_0x6da2('0x1b')](_0x160b51);}return _0xeac6c6[_0x6da2('0x1c')](_0x160b51)[_0x6da2('0x1d')]();};}function respondWithResult(_0x290d55,_0x1775f4){_0x1775f4=_0x1775f4||0xc8;return function(_0x798368){if(_0x798368){return _0x290d55[_0x6da2('0x1c')](_0x1775f4)[_0x6da2('0x1e')](_0x798368);}};}function respondWithFilteredResult(_0x28aec2,_0x473be2){return function(_0x46aba3){if(_0x46aba3){var _0x441cf6=typeof _0x473be2[_0x6da2('0x1f')]===_0x6da2('0x20')&&typeof _0x473be2[_0x6da2('0x21')]===_0x6da2('0x20');var _0x5157cf=_0x46aba3[_0x6da2('0x22')];var _0xef39ee=_0x441cf6?0x0:_0x473be2['offset'];var _0x1d5831=_0x441cf6?_0x46aba3['count']:_0x473be2['offset']+_0x473be2[_0x6da2('0x21')];var _0x2b236e;if(_0x1d5831>=_0x5157cf){_0x1d5831=_0x5157cf;_0x2b236e=0xc8;}else{_0x2b236e=0xce;}_0x28aec2[_0x6da2('0x1c')](_0x2b236e);return _0x28aec2['set'](_0x6da2('0x23'),_0xef39ee+'-'+_0x1d5831+'/'+_0x5157cf)[_0x6da2('0x1e')](_0x46aba3);}return null;};}function patchUpdates(_0x447560){return function(_0x1ebeae){try{jsonpatch[_0x6da2('0x24')](_0x1ebeae,_0x447560,!![]);}catch(_0x1f8525){return BPromise['reject'](_0x1f8525);}return _0x1ebeae['save']();};}function saveUpdates(_0x459813,_0x455d57){return function(_0x32e12e){if(_0x32e12e){return _0x32e12e[_0x6da2('0x25')](_0x459813)[_0x6da2('0x26')](function(_0x230ac8){return _0x230ac8;});}return null;};}function removeEntity(_0x289da6,_0x12fbac){return function(_0x4b5451){if(_0x4b5451){return _0x4b5451[_0x6da2('0x27')]()[_0x6da2('0x26')](function(){_0x289da6[_0x6da2('0x1c')](0xcc)[_0x6da2('0x1d')]();});}};}function handleEntityNotFound(_0x3b071c,_0x389dd4){return function(_0x35ff1b){if(!_0x35ff1b){_0x3b071c[_0x6da2('0x1b')](0x194);}return _0x35ff1b;};}function handleError(_0x5332cb,_0xbe31c6){_0xbe31c6=_0xbe31c6||0x1f4;return function(_0x44e8e2){logger[_0x6da2('0x28')](_0x44e8e2[_0x6da2('0x29')]);if(_0x44e8e2[_0x6da2('0x2a')]){delete _0x44e8e2[_0x6da2('0x2a')];}_0x5332cb['status'](_0xbe31c6)[_0x6da2('0x2b')](_0x44e8e2);};}function getInteractionUsers(_0x1ff7a1,_0x4ce745){return new BPromise(function(_0x110521,_0x3eb846){try{if(_0x4ce745[_0x1ff7a1['id']]){_0x1ff7a1[_0x6da2('0x2c')]=_[_0x6da2('0x2d')](_0x4ce745[_0x1ff7a1['id']],function(_0x47b120){return{'id':_0x47b120['id'],'fullname':_0x47b120[_0x6da2('0x2e')]};});}}catch(_0x27d088){_0x3eb846(_0x27d088);}_0x110521(_0x1ff7a1);});}function getInteractionTags(_0xc3e11c,_0x24700a){return new BPromise(function(_0x3c25b2,_0x1fde07){try{if(_0xc3e11c[_0x6da2('0x2f')]){_0xc3e11c[_0x6da2('0x30')]=[];_0xc3e11c[_0x6da2('0x2f')]['split'](',')['forEach'](function(_0x1e23ff){_0xc3e11c[_0x6da2('0x30')]['push'](_0x24700a[_0x1e23ff]);});}delete _0xc3e11c[_0x6da2('0x2f')];}catch(_0x95288d){_0x1fde07(_0x95288d);}_0x3c25b2(_0xc3e11c);});}function updateSmsInteraction(_0x271ffa,_0x523e97,_0x36f39c){return new BPromise(function(_0x50468f,_0x179714){return getInteractionUsers(_0x271ffa,_0x36f39c)[_0x6da2('0x26')](function(_0x1db5c4){return getInteractionTags(_0x1db5c4,_0x523e97);})[_0x6da2('0x26')](function(_0x1ed86c){return getStateInteraction(_0x1ed86c);})['then'](function(_0x33541c){_0x50468f(_0x33541c);})['catch'](function(_0xfea7c5){_0x179714(_0xfea7c5);});});}function getStateInteraction(_0x58de65){return new BPromise(function(_0x269096){_0x58de65[_0x6da2('0x31')]=0x0;_0x58de65[_0x6da2('0x32')]=0x0;_0x58de65[_0x6da2('0x33')]=0x0;_0x58de65[_0x6da2('0x34')]=0x0;_0x58de65['total']=0x0;if(!_0x58de65[_0x6da2('0x35')]&&!_0x58de65['UserId']){_0x58de65[_0x6da2('0x31')]+=0x1;}if(!_0x58de65[_0x6da2('0x35')]&&_0x58de65['UserId']){_0x58de65[_0x6da2('0x32')]+=0x1;if(_0x58de65[_0x6da2('0x31')]){_0x58de65['waiting']-=0x1;}}if(_0x58de65[_0x6da2('0x35')]&&_0x58de65['UserId']){_0x58de65[_0x6da2('0x33')]+=0x1;if(_0x58de65[_0x6da2('0x32')]){_0x58de65[_0x6da2('0x32')]-=0x1;}}if(_0x58de65[_0x6da2('0x35')]&&!_0x58de65[_0x6da2('0x36')]){_0x58de65[_0x6da2('0x34')]+=0x1;if(_0x58de65[_0x6da2('0x31')]){_0x58de65[_0x6da2('0x31')]-=0x1;}}_0x58de65[_0x6da2('0x37')]+=0x1;_0x269096(_0x58de65);});}exports[_0x6da2('0x38')]=function(_0x378c81,_0x2f5b04){var _0x3b40d0={},_0x119433={},_0x1610d0={'count':0x0,'rows':[]};var _0x3c1f6c=_[_0x6da2('0x2d')](db[_0x6da2('0x39')][_0x6da2('0x3a')],function(_0x57f468){return{'name':_0x57f468[_0x6da2('0x3b')],'type':_0x57f468[_0x6da2('0x3c')][_0x6da2('0x3d')]};});_0x119433['model']=_[_0x6da2('0x2d')](_0x3c1f6c,'name');_0x119433[_0x6da2('0x3e')]=_['keys'](_0x378c81[_0x6da2('0x3e')]);_0x119433[_0x6da2('0x3f')]=_[_0x6da2('0x40')](_0x119433['model'],_0x119433['query']);_0x3b40d0[_0x6da2('0x41')]=_[_0x6da2('0x40')](_0x119433[_0x6da2('0x42')],qs[_0x6da2('0x43')](_0x378c81[_0x6da2('0x3e')]['fields']));_0x3b40d0[_0x6da2('0x41')]=_0x3b40d0['attributes'][_0x6da2('0x44')]?_0x3b40d0[_0x6da2('0x41')]:_0x119433[_0x6da2('0x42')];if(!_0x378c81[_0x6da2('0x3e')][_0x6da2('0x45')](_0x6da2('0x46'))){_0x3b40d0['limit']=qs[_0x6da2('0x21')](_0x378c81[_0x6da2('0x3e')][_0x6da2('0x21')]);_0x3b40d0['offset']=qs[_0x6da2('0x1f')](_0x378c81['query']['offset']);}_0x3b40d0[_0x6da2('0x47')]=qs[_0x6da2('0x48')](_0x378c81['query'][_0x6da2('0x48')]);_0x3b40d0['where']=qs['filters'](_['pick'](_0x378c81[_0x6da2('0x3e')],_0x119433['filters']),_0x3c1f6c);var _0x43c58b=[];var _0x2babb8=squel[_0x6da2('0x49')]()[_0x6da2('0x4a')]('id')['field'](_0x6da2('0x2a'))['field']('color')[_0x6da2('0x4b')](_0x6da2('0x4c'));var _0x30058a=squel['select']()[_0x6da2('0x4a')](_0x6da2('0x4d'))[_0x6da2('0x4a')](_0x6da2('0x4e'))[_0x6da2('0x4a')](_0x6da2('0x4f'))['from']('user_has_sms_interactions','ui')['left_join'](_0x6da2('0x50'),'u',_0x6da2('0x51'));var _0x55d63a=squel['select']()['from']('sms_interactions','i')[_0x6da2('0x52')]('cm_contacts','c',_0x6da2('0x53'))[_0x6da2('0x52')](_0x6da2('0x50'),'o',_0x6da2('0x54'))[_0x6da2('0x52')](_0x6da2('0x55'),'a','a.id\x20=\x20i.SmsAccountId')['left_join'](_0x6da2('0x56'),'me',_0x6da2('0x57'))['left_join']('sms_interaction_has_tags','it',_0x6da2('0x58'))[_0x6da2('0x52')](_0x6da2('0x4c'),'t',_0x6da2('0x59'));var _0x3da93d=squel['expr']();var _0x4a79f2=[];var _0x3ea91a=squel[_0x6da2('0x5a')]();var _0x41ddc8;if(_0x378c81[_0x6da2('0x3e')][_0x6da2('0x5b')]){_0x41ddc8=as[_0x6da2('0x5c')](_0x378c81[_0x6da2('0x3e')][_0x6da2('0x5b')]);var _0x3935d8=_0x41ddc8[_0x6da2('0x5d')];for(var _0x36341f=0x0;_0x36341f<_0x41ddc8[_0x6da2('0x5e')][_0x6da2('0x44')];_0x36341f++){var _0x14e3aa=_0x41ddc8['conditions'][_0x36341f];var _0x22f7b7='i';var _0x44bb0f=_[_0x6da2('0x5f')](_0x3c1f6c,[_0x6da2('0x2a'),_0x14e3aa[_0x6da2('0x4a')]]);if(!_0x44bb0f){switch(_0x14e3aa[_0x6da2('0x4a')]){case _0x6da2('0x60'):if(_0x14e3aa[_0x6da2('0x61')]==0x1){_0x55d63a[_0x6da2('0x62')]('`'+_0x14e3aa['field']+_0x6da2('0x63'));}else{_0x55d63a[_0x6da2('0x62')]('`'+_0x14e3aa[_0x6da2('0x4a')]+'`\x20>\x200');}break;case _0x6da2('0x64'):if(_0x14e3aa[_0x6da2('0x65')]==='$substring'){if(_0x14e3aa[_0x6da2('0x61')][_0x6da2('0x66')]('\x20')[_0x6da2('0x44')]>0x1){_0x3da93d[_0x3935d8](_0x6da2('0x67'),qs[_0x6da2('0x68')](_0x14e3aa['value']),null);}else{var _0x297ae9='%'+_0x14e3aa[_0x6da2('0x61')]+'%';_0x3da93d[_0x3935d8](_0x6da2('0x69'),_0x297ae9,_0x297ae9,_0x297ae9);}}else{_0x44bb0f=_[_0x6da2('0x5f')](_0x3c1f6c,['name',_0x6da2('0x6a')]);_0x14e3aa[_0x6da2('0x4a')]='ContactId';_0x4c919f=as['buildExpression'](_0x22f7b7,_0x44bb0f[_0x6da2('0x3c')],_0x14e3aa);_0x3da93d[_0x3935d8](_0x4c919f[_0x6da2('0x6b')],_0x4c919f[_0x6da2('0x61')][_0x6da2('0x6c')],_0x4c919f[_0x6da2('0x61')][_0x6da2('0x1d')]);}break;case _0x6da2('0x6d'):var _0x5afb50=_0x14e3aa[_0x6da2('0x61')]['split'](',')[_0x6da2('0x2d')](function(_0x3e56f8){return Number(_0x3e56f8);});_0x5afb50['forEach'](function(_0x283c8e){_0x3ea91a['or'](_0x6da2('0x6e'),'%,'+_0x283c8e+',%');});_0x4a79f2=_[_0x6da2('0x6f')](_0x4a79f2,_0x5afb50);break;case'User':if(_0x14e3aa[_0x6da2('0x65')]===_0x6da2('0x70')){_0x3da93d[_0x3935d8](_0x6da2('0x71'),'%'+_0x14e3aa[_0x6da2('0x61')]+'%',null);}else{_0x44bb0f=_[_0x6da2('0x5f')](_0x3c1f6c,['name',_0x6da2('0x36')]);_0x14e3aa[_0x6da2('0x4a')]=_0x6da2('0x36');_0x4c919f=as['buildExpression'](_0x22f7b7,_0x44bb0f['type'],_0x14e3aa);_0x3da93d[_0x3935d8](_0x4c919f[_0x6da2('0x6b')],_0x4c919f[_0x6da2('0x61')][_0x6da2('0x6c')],_0x4c919f[_0x6da2('0x61')]['end']);}break;case'body':_0x4c919f=as[_0x6da2('0x72')]('me',null,_0x14e3aa);_0x3da93d[_0x3935d8](_0x4c919f[_0x6da2('0x6b')],_0x4c919f[_0x6da2('0x61')][_0x6da2('0x6c')],_0x4c919f[_0x6da2('0x61')][_0x6da2('0x1d')]);break;}}else{var _0x4c919f=as[_0x6da2('0x72')](_0x22f7b7,_0x44bb0f[_0x6da2('0x3c')],_0x14e3aa);_0x3da93d[_0x3935d8](_0x4c919f[_0x6da2('0x6b')],_0x4c919f['value'][_0x6da2('0x6c')],_0x4c919f[_0x6da2('0x61')][_0x6da2('0x1d')]);}}}else{var _0x7ae745=_(_0x378c81['query'])[_0x6da2('0x73')]()['map'](function(_0x115a76){return _[_0x6da2('0x74')](_0x3c1f6c,[_0x6da2('0x2a'),_0x115a76])?_0x115a76:undefined;})['compact']()[_0x6da2('0x61')]();if(!_[_0x6da2('0x75')](_0x7ae745)){_0x7ae745[_0x6da2('0x76')](function(_0xb85452){if(_0xb85452===_0x6da2('0x77')){_0x55d63a[_0x6da2('0x78')](_0x6da2('0x79'),[][_0x6da2('0x7a')](_0x378c81['query'][_0xb85452]));}else if(_0xb85452===_0x6da2('0x7b')){var _0x3848c6=JSON[_0x6da2('0x7c')](_0x378c81[_0x6da2('0x3e')][_0xb85452])[_0x6da2('0x7d')];var _0x116d31=JSON['parse'](_0x378c81['query'][_0xb85452])[_0x6da2('0x7e')];_0x55d63a[_0x6da2('0x78')](_0x6da2('0x7f'),_0x3848c6,_0x116d31);}else{if(_0x378c81[_0x6da2('0x3e')][_0xb85452]===_0x6da2('0x80')){_0x55d63a[_0x6da2('0x78')]('i.'+_0xb85452+_0x6da2('0x81'));}else{_0x55d63a[_0x6da2('0x78')]('i.'+_0xb85452+'\x20=\x20?',_0x378c81[_0x6da2('0x3e')][_0xb85452]);}}});}if(_0x378c81[_0x6da2('0x3e')]['read']){if(_0x378c81[_0x6da2('0x3e')][_0x6da2('0x82')]==0x1){_0x55d63a[_0x6da2('0x62')](_0x6da2('0x83'));}else{_0x55d63a[_0x6da2('0x62')]('`unreadMessages`\x20>\x200');}}if(_0x378c81['query'][_0x6da2('0x84')]){_0x4a79f2=_[_0x6da2('0x85')](_0x378c81['query']['tag'])?_0x378c81[_0x6da2('0x3e')][_0x6da2('0x84')]:new Array(_0x378c81[_0x6da2('0x3e')][_0x6da2('0x84')]);_0x4a79f2[_0x6da2('0x76')](function(_0x43ac67){_0x3ea91a['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x43ac67+',%');});}if(_0x378c81[_0x6da2('0x3e')][_0x6da2('0x86')]){var _0x470da9=_0x378c81[_0x6da2('0x3e')][_0x6da2('0x86')]['replace']('\x5c','\x5c\x5c')[_0x6da2('0x87')](/'/g,'\x27\x27');if(qs[_0x6da2('0x88')](_0x470da9)){_0x3da93d['or']('i.id\x20LIKE\x20?',_0x470da9+'%')['or'](_0x6da2('0x89'),_0x470da9+'%');}else{_0x3da93d['or'](_0x6da2('0x8a'),qs[_0x6da2('0x68')](_0x470da9))['or']('CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?',_0x470da9+'%');}}}_0x55d63a[_0x6da2('0x78')](_0x3da93d);_0x55d63a[_0x6da2('0x8b')]('i.id');var _0x1cbfab={'type':db[_0x6da2('0x8c')][_0x6da2('0x8d')][_0x6da2('0x8e')],'raw':!![]};var _0x4fa1ca=_0x55d63a['clone']();_0x4fa1ca[_0x6da2('0x4a')](_0x6da2('0x8f'));_0x4fa1ca[_0x6da2('0x4a')](_0x6da2('0x90'),_0x6da2('0x60'));if(_0x3b40d0[_0x6da2('0x47')]){_0x3b40d0[_0x6da2('0x47')][_0x6da2('0x76')](function(_0x5f5040){var _0x2bb5c7=_0x5f5040[0x0]===_0x6da2('0x91')?_0x5f5040[0x0]:'i.'+_0x5f5040[0x0];_0x55d63a['order'](_0x2bb5c7,_0x5f5040[0x1]===_0x6da2('0x92')?![]:!![]);});}if(!_[_0x6da2('0x75')](_0x4a79f2)){_0x55d63a[_0x6da2('0x62')](_0x3ea91a);_0x4fa1ca['where']('t.id\x20IN\x20?',_0x4a79f2);}BPromise[_0x6da2('0x93')]()[_0x6da2('0x26')](function(){if(!_0x41ddc8){if(_0x378c81['query']['SmsAccountId'])return;_0x4fa1ca['where'](_0x6da2('0x94'));_0x55d63a[_0x6da2('0x78')](_0x6da2('0x94'));return;}if(_0x378c81[_0x6da2('0x95')][_0x6da2('0x96')]!==_0x6da2('0x97'))return;return _0x378c81[_0x6da2('0x95')]['getSmsAccounts']({'attributes':['id'],'raw':!![]})[_0x6da2('0x26')](function(_0x328055){if(_[_0x6da2('0x75')](_0x328055)){_0x4fa1ca[_0x6da2('0x78')](_0x6da2('0x98'));_0x55d63a[_0x6da2('0x78')](_0x6da2('0x98'));}else{_0x4fa1ca[_0x6da2('0x78')](_0x6da2('0x79'),_['map'](_0x328055,'id'));_0x55d63a[_0x6da2('0x78')](_0x6da2('0x79'),_[_0x6da2('0x2d')](_0x328055,'id'));}});})[_0x6da2('0x26')](function(){if(_0x378c81['user'][_0x6da2('0x96')]==='agent'&&!_0x41ddc8&&!_0x378c81[_0x6da2('0x3e')]['SmsAccountId'])return[];return db['sequelize'][_0x6da2('0x3e')](_0x4fa1ca[_0x6da2('0x99')](),_0x1cbfab);})['then'](function(_0xfc2466){_0x1610d0[_0x6da2('0x22')]=_0xfc2466[_0x6da2('0x44')];if(_0x1610d0[_0x6da2('0x22')]===0x0)return[];return db[_0x6da2('0x9a')][_0x6da2('0x3e')](_0x2babb8[_0x6da2('0x99')](),_0x1cbfab)[_0x6da2('0x26')](function(_0x2d6e87){_0x43c58b=_[_0x6da2('0x9b')](_0x2d6e87,'id');_0x1cbfab=_[_0x6da2('0x9c')](_0x1cbfab,{'model':db['SmsInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x378c81[_0x6da2('0x3e')][_0x6da2('0x43')]){_0x3b40d0[_0x6da2('0x41')][_0x6da2('0x76')](function(_0x9c4752){_0x55d63a['field']('i.'+_0x9c4752);});}else{_0x55d63a[_0x6da2('0x4a')](_0x6da2('0x90'),_0x6da2('0x60'));_0x55d63a['field'](_0x6da2('0x9d'),_0x6da2('0x9e'));_0x55d63a['field'](_0x6da2('0x9f'),_0x6da2('0xa0'));_0x55d63a[_0x6da2('0x4a')](_0x6da2('0xa1'),_0x6da2('0x91'));_0x55d63a[_0x6da2('0x4a')](_0x6da2('0xa2'));_0x55d63a[_0x6da2('0x4a')](_0x6da2('0xa3'),_0x6da2('0xa4'));_0x55d63a[_0x6da2('0x4a')](_0x6da2('0xa5'),_0x6da2('0xa6'));_0x55d63a[_0x6da2('0x4a')](_0x6da2('0xa7'),'Contact.email');_0x55d63a['field'](_0x6da2('0xa8'),'Contact.phone');_0x55d63a['field'](_0x6da2('0xa9'),_0x6da2('0xaa'));_0x55d63a[_0x6da2('0x4a')](_0x6da2('0xab'),_0x6da2('0xac'));_0x55d63a['field'](_0x6da2('0xad'),_0x6da2('0xae'));_0x55d63a[_0x6da2('0x4a')]('o.internal','Owner.internal');_0x55d63a[_0x6da2('0x4a')]('GROUP_CONCAT(DISTINCT\x20t.id)',_0x6da2('0x2f'));}if(_0x3b40d0[_0x6da2('0x21')])_0x55d63a['limit'](_0x3b40d0[_0x6da2('0x21')]);if(_0x3b40d0[_0x6da2('0x1f')])_0x55d63a[_0x6da2('0x1f')](_0x3b40d0[_0x6da2('0x1f')]);return db[_0x6da2('0x9a')][_0x6da2('0x3e')](_0x55d63a[_0x6da2('0x99')](),_0x1cbfab);})['then'](function(_0x2af128){if(_0x2af128['length']>0x0)_0x30058a[_0x6da2('0x78')]('ui.SmsInteractionId\x20IN\x20?',_[_0x6da2('0x2d')](_0x2af128,'id'));return db['sequelize'][_0x6da2('0x3e')](_0x30058a[_0x6da2('0x99')](),_0x1cbfab)[_0x6da2('0x26')](function(_0x5c62c0){var _0x1c15d2=_[_0x6da2('0xaf')](_0x5c62c0,'SmsInteractionId');var _0x2be09a=[];_0x2af128['forEach'](function(_0x549e0d){_0x2be09a[_0x6da2('0xb0')](updateSmsInteraction(_0x549e0d,_0x43c58b,_0x1c15d2));});return BPromise[_0x6da2('0xb1')](_0x2be09a);});});})[_0x6da2('0x26')](function(_0x5c480e){_0x1610d0[_0x6da2('0xb2')]=_0x5c480e;return _0x1610d0;})[_0x6da2('0x26')](respondWithFilteredResult(_0x2f5b04,_0x3b40d0))['catch'](handleError(_0x2f5b04,null));};exports[_0x6da2('0xb3')]=function(_0x297b94,_0x55849b){var _0x14e4e7={'raw':![],'where':{'id':_0x297b94[_0x6da2('0xb4')]['id']}},_0x341667={};_0x341667[_0x6da2('0x42')]=_[_0x6da2('0x73')](db[_0x6da2('0x39')][_0x6da2('0x3a')]);_0x341667['query']=_[_0x6da2('0x73')](_0x297b94[_0x6da2('0x3e')]);_0x341667[_0x6da2('0x3f')]=_[_0x6da2('0x40')](_0x341667[_0x6da2('0x42')],_0x341667[_0x6da2('0x3e')]);_0x14e4e7['attributes']=_[_0x6da2('0x40')](_0x341667[_0x6da2('0x42')],qs[_0x6da2('0x43')](_0x297b94['query']['fields']));_0x14e4e7[_0x6da2('0x41')]=_0x14e4e7['attributes'][_0x6da2('0x44')]?_0x14e4e7['attributes']:_0x341667[_0x6da2('0x42')];if(_0x297b94[_0x6da2('0x3e')][_0x6da2('0xb5')]){_0x14e4e7[_0x6da2('0xb6')]=[{'all':!![]}];}_0x14e4e7=_[_0x6da2('0x9c')]({},_0x14e4e7,_0x297b94['options']);return db['SmsInteraction'][_0x6da2('0x5f')](_0x14e4e7)['then'](handleEntityNotFound(_0x55849b,null))['then'](respondWithResult(_0x55849b,null))[_0x6da2('0xb7')](handleError(_0x55849b,null));};exports[_0x6da2('0xb8')]=function(_0x53c630,_0x432a0b){return db[_0x6da2('0x39')][_0x6da2('0xb8')](_0x53c630['body'],{})['then'](respondWithResult(_0x432a0b,0xc9))[_0x6da2('0xb7')](handleError(_0x432a0b,null));};exports[_0x6da2('0x25')]=function(_0x56dee4,_0x5dfab4){if(_0x56dee4['body']['id']){delete _0x56dee4[_0x6da2('0xb9')]['id'];}return db[_0x6da2('0x39')][_0x6da2('0x5f')]({'where':{'id':_0x56dee4[_0x6da2('0xb4')]['id']}})[_0x6da2('0x26')](handleEntityNotFound(_0x5dfab4,null))[_0x6da2('0x26')](saveUpdates(_0x56dee4[_0x6da2('0xb9')],null))[_0x6da2('0x26')](respondWithResult(_0x5dfab4,null))[_0x6da2('0xb7')](handleError(_0x5dfab4,null));};exports[_0x6da2('0x27')]=function(_0x24ac8e,_0x317cb2){return db[_0x6da2('0x39')][_0x6da2('0x5f')]({'where':{'id':_0x24ac8e[_0x6da2('0xb4')]['id']}})[_0x6da2('0x26')](handleEntityNotFound(_0x317cb2,null))[_0x6da2('0x26')](removeEntity(_0x317cb2,null))[_0x6da2('0xb7')](handleError(_0x317cb2,null));};exports[_0x6da2('0xba')]=function(_0x22ae2d,_0x223d15){return db[_0x6da2('0x39')]['describe']()[_0x6da2('0x26')](respondWithResult(_0x223d15,null))['catch'](handleError(_0x223d15,null));};exports[_0x6da2('0xbb')]=function(_0x47d31f,_0x158ee4,_0xc559e9){return db[_0x6da2('0xbc')][_0x6da2('0x5f')]({'where':{'id':_0x47d31f[_0x6da2('0xb4')]['id']}})[_0x6da2('0x26')](handleEntityNotFound(_0x158ee4,null))[_0x6da2('0x26')](function(_0x13a765){if(_0x13a765){return _0x13a765['addMessage'](_0x47d31f[_0x6da2('0xb9')][_0x6da2('0xbd')],_[_0x6da2('0xbe')](_0x47d31f[_0x6da2('0xb9')],[_0x6da2('0xbd'),'id'])||{});}})[_0x6da2('0x26')](respondWithResult(_0x158ee4,null))[_0x6da2('0xb7')](handleError(_0x158ee4,null));};exports['getMessages']=function(_0x14eb5d,_0x1278a1,_0x4b98bf){var _0xf3e872={'raw':![],'where':{}};var _0x5e25fb={};var _0x1755a8={'count':0x0,'rows':[]};return db[_0x6da2('0x39')][_0x6da2('0xbf')]({'where':{'id':_0x14eb5d['params']['id']}})[_0x6da2('0x26')](handleEntityNotFound(_0x1278a1,null))[_0x6da2('0x26')](function(_0x4c153b){if(_0x4c153b){_0x5e25fb['model']=_[_0x6da2('0x73')](db[_0x6da2('0xbc')]['rawAttributes']);_0x5e25fb[_0x6da2('0x3e')]=_[_0x6da2('0x73')](_0x14eb5d[_0x6da2('0x3e')]);_0x5e25fb[_0x6da2('0x3f')]=_['intersection'](_0x5e25fb[_0x6da2('0x42')],_0x5e25fb[_0x6da2('0x3e')]);_0xf3e872['attributes']=_[_0x6da2('0x40')](_0x5e25fb[_0x6da2('0x42')],qs[_0x6da2('0x43')](_0x14eb5d[_0x6da2('0x3e')][_0x6da2('0x43')]));_0xf3e872[_0x6da2('0x41')]=_0xf3e872[_0x6da2('0x41')][_0x6da2('0x44')]?_0xf3e872[_0x6da2('0x41')]:_0x5e25fb['model'];if(!_0x14eb5d[_0x6da2('0x3e')][_0x6da2('0x45')](_0x6da2('0x46'))){_0xf3e872[_0x6da2('0x21')]=qs[_0x6da2('0x21')](_0x14eb5d[_0x6da2('0x3e')]['limit']);_0xf3e872[_0x6da2('0x1f')]=qs['offset'](_0x14eb5d['query']['offset']);}_0xf3e872[_0x6da2('0x47')]=qs[_0x6da2('0x48')](_0x14eb5d[_0x6da2('0x3e')][_0x6da2('0x48')]);_0xf3e872[_0x6da2('0x78')]=qs[_0x6da2('0x3f')](_[_0x6da2('0xc0')](_0x14eb5d[_0x6da2('0x3e')],_0x5e25fb['filters']));_0xf3e872[_0x6da2('0x78')][_0x6da2('0xc1')]=_0x4c153b['id'];if(_0x14eb5d[_0x6da2('0x3e')][_0x6da2('0x86')]){_0xf3e872[_0x6da2('0x78')]=_[_0x6da2('0x9c')](_0xf3e872[_0x6da2('0x78')],{'$or':_[_0x6da2('0x2d')](_0xf3e872[_0x6da2('0x41')],function(_0x52d809){var _0x51d809={};_0x51d809[_0x52d809]={'$like':'%'+_0x14eb5d['query']['filter']+'%'};return _0x51d809;})});}if(_0x14eb5d['query'][_0x6da2('0x7d')]){var _0x152ba5=_0x14eb5d['query'][_0x6da2('0x7d')]['split'](',');var _0x17abe2={};_0x17abe2[_0x152ba5[0x0]]={'$gte':moment(_0x152ba5[0x1])[_0x6da2('0xc2')]('YYYY-MM-DD\x20HH:mm:ss')};_0xf3e872['where']=_['merge'](_0xf3e872[_0x6da2('0x78')],_0x17abe2);}_0xf3e872=_['merge']({},_0xf3e872,_0x14eb5d[_0x6da2('0xc3')]);return db[_0x6da2('0xbc')][_0x6da2('0x22')]({'where':_0xf3e872['where']})[_0x6da2('0x26')](function(_0x2596ed){_0x1755a8[_0x6da2('0x22')]=_0x2596ed;if(_0x14eb5d[_0x6da2('0x3e')][_0x6da2('0xb5')]){_0xf3e872['include']=[{'all':!![]}];}return db['SmsMessage']['findAll'](_0xf3e872);})[_0x6da2('0x26')](function(_0x22edbf){_0x1755a8['rows']=_0x22edbf;return _0x1755a8;});}})[_0x6da2('0x26')](respondWithFilteredResult(_0x1278a1,_0xf3e872))[_0x6da2('0xb7')](handleError(_0x1278a1,null));};exports['addTags']=function(_0x113e6b,_0x2b2da6,_0x5cb967){return db[_0x6da2('0x39')][_0x6da2('0x5f')]({'where':{'id':_0x113e6b['params']['id']}})[_0x6da2('0x26')](handleEntityNotFound(_0x2b2da6,null))[_0x6da2('0x26')](function(_0x8db559){if(_0x8db559){return _0x8db559[_0x6da2('0xc4')](_0x113e6b[_0x6da2('0xb9')][_0x6da2('0xbd')],_['omit'](_0x113e6b['body'],[_0x6da2('0xbd'),'id'])||{})[_0x6da2('0xc5')](function(){return db[_0x6da2('0x6d')][_0x6da2('0xc6')]({'attributes':['id',_0x6da2('0x2a'),_0x6da2('0xc7')],'where':{'id':_0x113e6b[_0x6da2('0xb9')][_0x6da2('0xbd')]}});})[_0x6da2('0x26')](function(_0x94691e){socket[_0x6da2('0xc8')](_0x6da2('0xc9'),{'id':Number(_0x113e6b[_0x6da2('0xb4')]['id']),'tags':_0x94691e||[]});return{'id':Number(_0x113e6b[_0x6da2('0xb4')]['id']),'tags':_0x94691e||[]};});}})[_0x6da2('0x26')](respondWithResult(_0x2b2da6,null))[_0x6da2('0xb7')](handleError(_0x2b2da6,null));};exports['removeTags']=function(_0x1aedbb,_0x1141a4,_0x253bef){return db['SmsInteraction'][_0x6da2('0x5f')]({'where':{'id':_0x1aedbb[_0x6da2('0xb4')]['id']}})[_0x6da2('0x26')](handleEntityNotFound(_0x1141a4,null))[_0x6da2('0x26')](function(_0x11c65d){if(_0x11c65d){return _0x11c65d[_0x6da2('0xca')](_0x1aedbb['query'][_0x6da2('0xbd')]);}})[_0x6da2('0x26')](respondWithStatusCode(_0x1141a4,null))[_0x6da2('0xb7')](handleError(_0x1141a4,null));};exports[_0x6da2('0xcb')]=function(_0x15df0a,_0x2695b5){var _0x200e81=moment()[_0x6da2('0xcc')]()[_0x6da2('0x99')]();var _0x14e63e=path[_0x6da2('0xcd')](config[_0x6da2('0xce')],_0x6da2('0xcf'),_0x6da2('0xd0'),'tmp');var _0x4fb66e=path[_0x6da2('0xcd')](config[_0x6da2('0xce')],_0x6da2('0xcf'),_0x6da2('0xd0'),_0x6da2('0xd1'));var _0x305611=path[_0x6da2('0xcd')](_0x14e63e,_0x200e81);var _0x257905=util[_0x6da2('0xc2')](_0x6da2('0xd2'),_0x15df0a[_0x6da2('0xb4')]['id'],_0x200e81);var _0x5c151e=path['join'](_0x14e63e,_0x257905);var _0x14df3f=[];_0x14df3f[_0x6da2('0xb0')]({'model':db[_0x6da2('0xd3')],'as':'User','attributes':['id',_0x6da2('0x2e')],'raw':!![]});_0x14df3f['push']({'model':db[_0x6da2('0xd4')],'as':_0x6da2('0x64'),'attributes':['id',_0x6da2('0xd5'),_0x6da2('0xd6')],'raw':!![]});var _0x2e73e0=[{'model':db[_0x6da2('0xbc')],'as':_0x6da2('0xd7'),'attributes':['id',_0x6da2('0xb9'),'createdAt',_0x6da2('0xd8'),_0x6da2('0xd9'),_0x6da2('0x82')],'include':_0x14df3f}];_0x2e73e0['push']({'model':db[_0x6da2('0xda')],'as':'Account','attributes':['id',_0x6da2('0x2a')]});_0x2e73e0[_0x6da2('0xb0')]({'model':db[_0x6da2('0xd3')],'as':_0x6da2('0xdb'),'attributes':['id',_0x6da2('0x2e')]});return db[_0x6da2('0x39')][_0x6da2('0x5f')]({'where':{'id':_0x15df0a[_0x6da2('0xb4')]['id']},'include':_0x2e73e0})['then'](handleEntityNotFound(_0x2695b5,null))[_0x6da2('0x26')](function(_0x57db7c){if(_0x57db7c){var _0x2da507=_0x57db7c[_0x6da2('0xdc')]({'plain':!![]});fs['mkdirSync'](_0x305611);var _0x159b20={'channel':'Sms','account':_0x2da507['Account'][_0x6da2('0x2a')],'agent':_0x2da507[_0x6da2('0xdb')]?_0x2da507['Owner'][_0x6da2('0x2e')]:'N.A.','createdAt':moment(_0x2da507['createdAt'])['format'](_0x6da2('0xdd'))[_0x6da2('0x99')](),'closedAt':_0x2da507[_0x6da2('0x35')]?moment(_0x2da507[_0x6da2('0xde')])[_0x6da2('0xc2')](_0x6da2('0xdd'))[_0x6da2('0x99')]():'','disposition':_0x2da507['disposition'],'messages':_(_0x2da507[_0x6da2('0xd7')])[_0x6da2('0x86')]({'secret':![]})[_0x6da2('0x2d')](function(_0x2de04d){return{'date':moment(_0x2de04d[_0x6da2('0x7b')])[_0x6da2('0xc2')]('YYYY-MM-DD\x20HH:mm:ss')['toString'](),'sender':_0x2de04d[_0x6da2('0xd8')]===_0x6da2('0xdf')?_0x2de04d[_0x6da2('0xd3')]?_0x2de04d[_0x6da2('0xd3')][_0x6da2('0x2e')]:_0x6da2('0xe0'):_0x2de04d[_0x6da2('0x64')]['firstName']+(_0x2de04d[_0x6da2('0x64')][_0x6da2('0xd6')]?'\x20'+_0x2de04d['Contact']['lastName']:''),'body':_0x2de04d['body'],'direction':_0x2de04d[_0x6da2('0xd8')]===_0x6da2('0xdf')?'A':'C','secret':_0x2de04d[_0x6da2('0xd9')],'read':_0x2de04d['read']};})[_0x6da2('0x61')]()};return ejs['renderFile'](path[_0x6da2('0xcd')](config[_0x6da2('0xce')],_0x6da2('0xcf'),_0x6da2('0xe1'),_0x6da2('0xe2')),{'interaction':_0x159b20})['then'](function(_0x4108e8){var _0x3f1b29=path[_0x6da2('0xcd')](_0x305611,'transcript-'+_0x2da507['id']+'-'+_0x200e81+_0x6da2('0xe3'));var _0x10ae09={'path':_0x3f1b29,'channel':'Sms','interactionId':_0x2da507['id']};return pdf[_0x6da2('0xe4')](_0x4108e8,_0x10ae09);})[_0x6da2('0x26')](function(){return new BPromise(function(_0x5be935,_0x548ce2){zipdir(_0x305611,{'saveTo':_0x5c151e},function(_0x24ca40,_0x30d6c2){if(_0x24ca40)return _0x548ce2(_0x24ca40);return _0x5be935(_0x30d6c2);});})[_0x6da2('0x26')](function(){return new BPromise(function(_0xc0d00b,_0x3f9f39){rimraf(_0x305611,function(_0x41a23a){if(_0x41a23a)_0x3f9f39(_0x41a23a);return _0xc0d00b();});});})[_0x6da2('0x26')](function(){return _0x2695b5[_0x6da2('0xcb')](_0x5c151e,_0x257905,function(_0xc35086){if(_0xc35086){console['log']('err',_0xc35086);}else{fs[_0x6da2('0xe5')](_0x5c151e);}});});});}else{return _0x2695b5[_0x6da2('0x1b')](0xc8);}})[_0x6da2('0xb7')](handleError(_0x2695b5,null));};
\ No newline at end of file