Built motion from commit ab870f9e.|2.5.44
[motion2.git] / server / api / smsInteraction / smsInteraction.controller.js
index 28afd65..a0a7258 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x2a08=['parse','$gte','$lte','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','isArray','tag','filter','replace','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','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','DESC','t.id\x20IN\x20?','journey','i.SmsAccountId\x20IS\x20NOT\x20NULL','user','getSmsAccounts','i.SmsAccountId\x20IS\x20NULL','i.SmsAccountId\x20IN\x20?','sequelize','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','Contact.firstName','c.lastName','Contact.lastName','c.email','c.phone','Contact.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','Owner.fullname','o.internal','Owner.internal','toString','ui.SmsInteractionId\x20IN\x20?','groupBy','SmsInteractionId','rows','show','params','model','includeAll','include','merge','options','create','body','describe','addMessage','SmsMessage','ids','omit','getMessages','findOne','nolimit','format','YYYY-MM-DD\x20HH:mm:ss','findAll','addTags','setTags','spread','emit','smsInteractionTags:save','download','unix','join','root','server','files','attachments','transcript-%d-%s.zip','CmContact','firstName','lastName','Messages','direction','secret','SmsAccount','Owner','get','mkdirSync','10px','40px','<div\x20class=\x22header\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<h5>Interaction\x20Transcript</h5>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','30px','<hr\x20class=\x22separator\x22/>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22footer\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22left\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22center\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>{{page}}/{{pages}}</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22right\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','%s\x20#%d','Sms','YYYY-MM-DD','Account','N.A.','closed','closedAt','disposition','out','System','renderFile','views','downloadInteraction.html','toFile','transcript-','.pdf','err','rimraf','zip-dir','request-promise','moment','bluebird','mustache','sox','to-csv','ejs','lodash','squel','desk.js','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','redis','defaults','socket.io-emitter','./smsInteraction.socket','register','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','reject','save','update','then','destroy','stack','name','send','Users','map','fullname','TagIds','Tags','split','forEach','push','catch','index','SmsInteraction','rawAttributes','fieldName','type','key','query','keys','filters','intersection','fields','attributes','hasOwnProperty','order','sort','where','pick','field','color','select','u.id','ui.SmsInteractionId','from','user_has_sms_interactions','users','u.id\x20=\x20ui.UserId','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','left_join','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','parseSearch','length','conditions','find','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','$substring','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','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','start','some','compact','isEmpty','SmsAccountId','concat','createdAt'];(function(_0x46ce29,_0x31b825){var _0x296776=function(_0x84b11e){while(--_0x84b11e){_0x46ce29['push'](_0x46ce29['shift']());}};_0x296776(++_0x31b825);}(_0x2a08,0x76));var _0x82a0=function(_0x31e29a,_0x349c9b){_0x31e29a=_0x31e29a-0x0;var _0x32d892=_0x2a08[_0x31e29a];return _0x32d892;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x82a0('0x0'));var zipdir=require(_0x82a0('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x82a0('0x2'));var moment=require(_0x82a0('0x3'));var BPromise=require(_0x82a0('0x4'));var Mustache=require(_0x82a0('0x5'));var util=require('util');var path=require('path');var sox=require(_0x82a0('0x6'));var csv=require(_0x82a0('0x7'));var ejs=require(_0x82a0('0x8'));var fs=require('fs');var _=require(_0x82a0('0x9'));var squel=require(_0x82a0('0xa'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x82a0('0xb'));var toCsv=require(_0x82a0('0x7'));var querystring=require(_0x82a0('0xc'));var Papa=require(_0x82a0('0xd'));var Redis=require(_0x82a0('0xe'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x82a0('0xf'));var hardwareService=require(_0x82a0('0x10'));var logger=require(_0x82a0('0x11'))(_0x82a0('0x12'));var utils=require(_0x82a0('0x13'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x82a0('0x14'))['db'];config[_0x82a0('0x15')]=_[_0x82a0('0x16')](config[_0x82a0('0x15')],{'host':'localhost','port':0x18eb});var socket=require(_0x82a0('0x17'))(new Redis(config[_0x82a0('0x15')]));require(_0x82a0('0x18'))[_0x82a0('0x19')](socket);function respondWithStatusCode(_0x1e2a32,_0x93bffa){_0x93bffa=_0x93bffa||0xcc;return function(_0x3322ad){if(_0x3322ad){return _0x1e2a32[_0x82a0('0x1a')](_0x93bffa);}return _0x1e2a32[_0x82a0('0x1b')](_0x93bffa)[_0x82a0('0x1c')]();};}function respondWithResult(_0x638fb6,_0x5b5652){_0x5b5652=_0x5b5652||0xc8;return function(_0x7838bf){if(_0x7838bf){return _0x638fb6[_0x82a0('0x1b')](_0x5b5652)[_0x82a0('0x1d')](_0x7838bf);}};}function respondWithFilteredResult(_0x33075b,_0x3fd473){return function(_0x39db96){if(_0x39db96){var _0x4a16aa=_0x39db96[_0x82a0('0x1e')],_0x3def67=_0x3fd473[_0x82a0('0x1f')],_0x14a708=_0x3fd473[_0x82a0('0x1f')]+_0x3fd473[_0x82a0('0x20')],_0x347361;if(_0x14a708>=_0x4a16aa){_0x14a708=_0x4a16aa;_0x347361=0xc8;}else{_0x347361=0xce;}_0x33075b['status'](_0x347361);return _0x33075b['set'](_0x82a0('0x21'),_0x3def67+'-'+_0x14a708+'/'+_0x4a16aa)[_0x82a0('0x1d')](_0x39db96);}return null;};}function patchUpdates(_0x2f8c9d){return function(_0x3e2998){try{jsonpatch[_0x82a0('0x22')](_0x3e2998,_0x2f8c9d,!![]);}catch(_0xd3cd29){return BPromise[_0x82a0('0x23')](_0xd3cd29);}return _0x3e2998[_0x82a0('0x24')]();};}function saveUpdates(_0x273c91,_0x3ff15d){return function(_0x2e2031){if(_0x2e2031){return _0x2e2031[_0x82a0('0x25')](_0x273c91)[_0x82a0('0x26')](function(_0x3a968a){return _0x3a968a;});}return null;};}function removeEntity(_0x525742,_0x4e2005){return function(_0x3c2677){if(_0x3c2677){return _0x3c2677[_0x82a0('0x27')]()[_0x82a0('0x26')](function(){_0x525742[_0x82a0('0x1b')](0xcc)[_0x82a0('0x1c')]();});}};}function handleEntityNotFound(_0x57de53,_0x27d2bb){return function(_0x597068){if(!_0x597068){_0x57de53['sendStatus'](0x194);}return _0x597068;};}function handleError(_0x24034a,_0x1e3da3){_0x1e3da3=_0x1e3da3||0x1f4;return function(_0x432785){logger['error'](_0x432785[_0x82a0('0x28')]);if(_0x432785[_0x82a0('0x29')]){delete _0x432785['name'];}_0x24034a[_0x82a0('0x1b')](_0x1e3da3)[_0x82a0('0x2a')](_0x432785);};}function getInteractionUsers(_0x500bd0,_0x3c9e9b){return new BPromise(function(_0x47a76e,_0x204480){try{if(_0x3c9e9b[_0x500bd0['id']]){_0x500bd0[_0x82a0('0x2b')]=_[_0x82a0('0x2c')](_0x3c9e9b[_0x500bd0['id']],function(_0x5c13a1){return{'id':_0x5c13a1['id'],'fullname':_0x5c13a1[_0x82a0('0x2d')]};});}}catch(_0x486112){_0x204480(_0x486112);}_0x47a76e(_0x500bd0);});}function getInteractionTags(_0x594929,_0x273263){return new BPromise(function(_0x26848a,_0x578ab8){try{if(_0x594929[_0x82a0('0x2e')]){_0x594929[_0x82a0('0x2f')]=[];_0x594929[_0x82a0('0x2e')][_0x82a0('0x30')](',')[_0x82a0('0x31')](function(_0x24191f){_0x594929[_0x82a0('0x2f')][_0x82a0('0x32')](_0x273263[_0x24191f]);});}delete _0x594929[_0x82a0('0x2e')];}catch(_0x286c09){_0x578ab8(_0x286c09);}_0x26848a(_0x594929);});}function updateSmsInteraction(_0x40884e,_0xc5fa88,_0x2fc73d){return new BPromise(function(_0x340ff3,_0x1f5dad){return getInteractionUsers(_0x40884e,_0x2fc73d)[_0x82a0('0x26')](function(_0x2d1a80){return getInteractionTags(_0x2d1a80,_0xc5fa88);})[_0x82a0('0x26')](function(_0x4c07ac){_0x340ff3(_0x4c07ac);})[_0x82a0('0x33')](function(_0xe19314){_0x1f5dad(_0xe19314);});});}exports[_0x82a0('0x34')]=function(_0x3e914c,_0x3b7d28){var _0x4b881c={},_0x69d084={},_0x5ecc49={'count':0x0,'rows':[]};var _0x56f269=_['map'](db[_0x82a0('0x35')][_0x82a0('0x36')],function(_0x165b49){return{'name':_0x165b49[_0x82a0('0x37')],'type':_0x165b49[_0x82a0('0x38')][_0x82a0('0x39')]};});_0x69d084['model']=_[_0x82a0('0x2c')](_0x56f269,_0x82a0('0x29'));_0x69d084[_0x82a0('0x3a')]=_[_0x82a0('0x3b')](_0x3e914c[_0x82a0('0x3a')]);_0x69d084[_0x82a0('0x3c')]=_[_0x82a0('0x3d')](_0x69d084['model'],_0x69d084['query']);_0x4b881c['attributes']=_[_0x82a0('0x3d')](_0x69d084['model'],qs[_0x82a0('0x3e')](_0x3e914c[_0x82a0('0x3a')]['fields']));_0x4b881c['attributes']=_0x4b881c[_0x82a0('0x3f')]['length']?_0x4b881c['attributes']:_0x69d084['model'];if(!_0x3e914c['query'][_0x82a0('0x40')]('nolimit')){_0x4b881c[_0x82a0('0x20')]=qs[_0x82a0('0x20')](_0x3e914c[_0x82a0('0x3a')][_0x82a0('0x20')]);_0x4b881c[_0x82a0('0x1f')]=qs[_0x82a0('0x1f')](_0x3e914c['query'][_0x82a0('0x1f')]);}_0x4b881c[_0x82a0('0x41')]=qs[_0x82a0('0x42')](_0x3e914c[_0x82a0('0x3a')]['sort']);_0x4b881c[_0x82a0('0x43')]=qs[_0x82a0('0x3c')](_[_0x82a0('0x44')](_0x3e914c[_0x82a0('0x3a')],_0x69d084['filters']),_0x56f269);var _0x35c4c9=[];var _0xcc7a5d=squel['select']()[_0x82a0('0x45')]('id')[_0x82a0('0x45')]('name')[_0x82a0('0x45')](_0x82a0('0x46'))['from']('tools_tags');var _0x2f737f=squel[_0x82a0('0x47')]()[_0x82a0('0x45')](_0x82a0('0x48'))[_0x82a0('0x45')]('u.fullname')[_0x82a0('0x45')](_0x82a0('0x49'))[_0x82a0('0x4a')](_0x82a0('0x4b'),'ui')['left_join'](_0x82a0('0x4c'),'u',_0x82a0('0x4d'));var _0x55ad8c=squel[_0x82a0('0x47')]()[_0x82a0('0x4a')]('sms_interactions','i')['left_join']('cm_contacts','c',_0x82a0('0x4e'))[_0x82a0('0x4f')](_0x82a0('0x4c'),'o','o.id\x20=\x20i.UserId')[_0x82a0('0x4f')](_0x82a0('0x50'),'a',_0x82a0('0x51'))[_0x82a0('0x4f')](_0x82a0('0x52'),'me',_0x82a0('0x53'))[_0x82a0('0x4f')](_0x82a0('0x54'),'it',_0x82a0('0x55'))[_0x82a0('0x4f')](_0x82a0('0x56'),'t',_0x82a0('0x57'));var _0x35be92=squel['expr']();var _0x3bd46b=[];var _0x2f71d4=squel[_0x82a0('0x58')]();var _0x4305c3;if(_0x3e914c[_0x82a0('0x3a')][_0x82a0('0x59')]){_0x4305c3=as[_0x82a0('0x5a')](_0x3e914c[_0x82a0('0x3a')][_0x82a0('0x59')]);var _0x3a613a=_0x4305c3['sqlOperator'];for(var _0x3cc5ba=0x0;_0x3cc5ba<_0x4305c3['conditions'][_0x82a0('0x5b')];_0x3cc5ba++){var _0x352937=_0x4305c3[_0x82a0('0x5c')][_0x3cc5ba];var _0x1ddbde='i';var _0xd45a6b=_[_0x82a0('0x5d')](_0x56f269,[_0x82a0('0x29'),_0x352937[_0x82a0('0x45')]]);if(!_0xd45a6b){switch(_0x352937[_0x82a0('0x45')]){case _0x82a0('0x5e'):if(_0x352937[_0x82a0('0x5f')]==0x1){_0x55ad8c[_0x82a0('0x60')]('`'+_0x352937['field']+_0x82a0('0x61'));}else{_0x55ad8c[_0x82a0('0x60')]('`'+_0x352937[_0x82a0('0x45')]+_0x82a0('0x62'));}break;case _0x82a0('0x63'):if(_0x352937['operator']===_0x82a0('0x64')){if(_0x352937[_0x82a0('0x5f')][_0x82a0('0x30')]('\x20')['length']>0x1){_0x35be92[_0x3a613a](_0x82a0('0x65'),qs[_0x82a0('0x66')](_0x352937[_0x82a0('0x5f')]),null);}else{var _0x4e3329='%'+_0x352937['value']+'%';_0x35be92[_0x3a613a](_0x82a0('0x67'),_0x4e3329,_0x4e3329,_0x4e3329);}}else{_0xd45a6b=_[_0x82a0('0x5d')](_0x56f269,[_0x82a0('0x29'),_0x82a0('0x68')]);_0x352937['field']=_0x82a0('0x68');_0x53b9a5=as[_0x82a0('0x69')](_0x1ddbde,_0xd45a6b['type'],_0x352937);_0x35be92[_0x3a613a](_0x53b9a5[_0x82a0('0x6a')],_0x53b9a5['value']['start'],_0x53b9a5[_0x82a0('0x5f')]['end']);}break;case _0x82a0('0x6b'):var _0xae2501=_0x352937[_0x82a0('0x5f')][_0x82a0('0x30')](',')[_0x82a0('0x2c')](function(_0x25d0f9){return Number(_0x25d0f9);});_0xae2501[_0x82a0('0x31')](function(_0x31bde0){_0x2f71d4['or'](_0x82a0('0x6c'),'%,'+_0x31bde0+',%');});_0x3bd46b=_['union'](_0x3bd46b,_0xae2501);break;case _0x82a0('0x6d'):if(_0x352937['operator']==='$substring'){_0x35be92[_0x3a613a](_0x82a0('0x6e'),'%'+_0x352937[_0x82a0('0x5f')]+'%',null);}else{_0xd45a6b=_[_0x82a0('0x5d')](_0x56f269,[_0x82a0('0x29'),_0x82a0('0x6f')]);_0x352937[_0x82a0('0x45')]=_0x82a0('0x6f');_0x53b9a5=as[_0x82a0('0x69')](_0x1ddbde,_0xd45a6b[_0x82a0('0x38')],_0x352937);_0x35be92[_0x3a613a](_0x53b9a5[_0x82a0('0x6a')],_0x53b9a5[_0x82a0('0x5f')][_0x82a0('0x70')],_0x53b9a5[_0x82a0('0x5f')][_0x82a0('0x1c')]);}break;case'body':_0x53b9a5=as['buildExpression']('me',null,_0x352937);_0x35be92[_0x3a613a](_0x53b9a5[_0x82a0('0x6a')],_0x53b9a5[_0x82a0('0x5f')][_0x82a0('0x70')],_0x53b9a5[_0x82a0('0x5f')][_0x82a0('0x1c')]);break;}}else{var _0x53b9a5=as[_0x82a0('0x69')](_0x1ddbde,_0xd45a6b[_0x82a0('0x38')],_0x352937);_0x35be92[_0x3a613a](_0x53b9a5[_0x82a0('0x6a')],_0x53b9a5[_0x82a0('0x5f')]['start'],_0x53b9a5[_0x82a0('0x5f')][_0x82a0('0x1c')]);}}}else{var _0x22d7aa=_(_0x3e914c['query'])['keys']()['map'](function(_0x28b6e9){return _[_0x82a0('0x71')](_0x56f269,[_0x82a0('0x29'),_0x28b6e9])?_0x28b6e9:undefined;})[_0x82a0('0x72')]()[_0x82a0('0x5f')]();if(!_[_0x82a0('0x73')](_0x22d7aa)){_0x22d7aa[_0x82a0('0x31')](function(_0x38a615){if(_0x38a615===_0x82a0('0x74')){_0x55ad8c[_0x82a0('0x43')]('i.SmsAccountId\x20IN\x20?',[][_0x82a0('0x75')](_0x3e914c[_0x82a0('0x3a')][_0x38a615]));}else if(_0x38a615===_0x82a0('0x76')){var _0x16faad=JSON[_0x82a0('0x77')](_0x3e914c[_0x82a0('0x3a')][_0x38a615])[_0x82a0('0x78')];var _0xcba7c7=JSON['parse'](_0x3e914c['query'][_0x38a615])[_0x82a0('0x79')];_0x55ad8c[_0x82a0('0x43')]('i.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x16faad,_0xcba7c7);}else{if(_0x3e914c[_0x82a0('0x3a')][_0x38a615]===_0x82a0('0x7a')){_0x55ad8c[_0x82a0('0x43')]('i.'+_0x38a615+_0x82a0('0x7b'));}else{_0x55ad8c['where']('i.'+_0x38a615+_0x82a0('0x7c'),_0x3e914c[_0x82a0('0x3a')][_0x38a615]);}}});}if(_0x3e914c['query']['read']){if(_0x3e914c[_0x82a0('0x3a')][_0x82a0('0x7d')]==0x1){_0x55ad8c[_0x82a0('0x60')](_0x82a0('0x7e'));}else{_0x55ad8c[_0x82a0('0x60')]('`unreadMessages`\x20>\x200');}}if(_0x3e914c[_0x82a0('0x3a')]['tag']){_0x3bd46b=_[_0x82a0('0x7f')](_0x3e914c[_0x82a0('0x3a')][_0x82a0('0x80')])?_0x3e914c[_0x82a0('0x3a')][_0x82a0('0x80')]:new Array(_0x3e914c[_0x82a0('0x3a')][_0x82a0('0x80')]);_0x3bd46b['forEach'](function(_0x16f4f3){_0x2f71d4['or'](_0x82a0('0x6c'),'%,'+_0x16f4f3+',%');});}if(_0x3e914c[_0x82a0('0x3a')]['filter']){var _0x11158d=_0x3e914c[_0x82a0('0x3a')][_0x82a0('0x81')]['replace']('\x5c','\x5c\x5c')[_0x82a0('0x82')](/'/g,'\x27\x27');if(qs['isNumeric'](_0x11158d)){_0x35be92['or'](_0x82a0('0x83'),_0x11158d+'%')['or'](_0x82a0('0x84'),_0x11158d+'%');}else{_0x35be92['or'](_0x82a0('0x85'),qs[_0x82a0('0x66')](_0x11158d))['or'](_0x82a0('0x86'),_0x11158d+'%');}}}_0x55ad8c[_0x82a0('0x43')](_0x35be92);_0x55ad8c[_0x82a0('0x87')](_0x82a0('0x88'));var _0x40ca77={'type':db['Sequelize'][_0x82a0('0x89')][_0x82a0('0x8a')],'raw':!![]};var _0x405646=_0x55ad8c[_0x82a0('0x8b')]();_0x405646['field'](_0x82a0('0x88'));_0x405646[_0x82a0('0x45')](_0x82a0('0x8c'),_0x82a0('0x5e'));if(_0x4b881c[_0x82a0('0x41')]){_0x4b881c[_0x82a0('0x41')][_0x82a0('0x31')](function(_0x106669){var _0x3f64e1=_0x106669[0x0]===_0x82a0('0x8d')?_0x106669[0x0]:'i.'+_0x106669[0x0];_0x55ad8c[_0x82a0('0x41')](_0x3f64e1,_0x106669[0x1]===_0x82a0('0x8e')?![]:!![]);});}if(!_[_0x82a0('0x73')](_0x3bd46b)){_0x55ad8c[_0x82a0('0x60')](_0x2f71d4);_0x405646[_0x82a0('0x43')](_0x82a0('0x8f'),_0x3bd46b);}BPromise['resolve']()[_0x82a0('0x26')](function(){if(!_0x4305c3){if(_0x3e914c[_0x82a0('0x3a')][_0x82a0('0x74')]||_0x3e914c[_0x82a0('0x3a')][_0x82a0('0x90')])return;_0x405646[_0x82a0('0x43')](_0x82a0('0x91'));_0x55ad8c[_0x82a0('0x43')](_0x82a0('0x91'));return;}return _0x3e914c[_0x82a0('0x92')][_0x82a0('0x93')]({'attributes':['id'],'raw':!![]})['then'](function(_0x345457){if(_[_0x82a0('0x73')](_0x345457)){_0x405646[_0x82a0('0x43')](_0x82a0('0x94'));_0x55ad8c[_0x82a0('0x43')]('i.SmsAccountId\x20IS\x20NULL');}else{_0x405646['where'](_0x82a0('0x95'),_[_0x82a0('0x2c')](_0x345457,'id'));_0x55ad8c[_0x82a0('0x43')](_0x82a0('0x95'),_[_0x82a0('0x2c')](_0x345457,'id'));}});})[_0x82a0('0x26')](function(){db[_0x82a0('0x96')][_0x82a0('0x3a')](_0x405646['toString'](),_0x40ca77)[_0x82a0('0x26')](function(_0x1d3dd5){_0x5ecc49['count']=_0x1d3dd5[_0x82a0('0x5b')];if(_0x5ecc49[_0x82a0('0x1e')]===0x0)return[];return db['sequelize']['query'](_0xcc7a5d['toString'](),_0x40ca77)[_0x82a0('0x26')](function(_0x3fb4b8){_0x35c4c9=_['keyBy'](_0x3fb4b8,'id');_0x40ca77=_['merge'](_0x40ca77,{'model':db['SmsInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x3e914c[_0x82a0('0x3a')][_0x82a0('0x3e')]){_0x4b881c[_0x82a0('0x3f')][_0x82a0('0x31')](function(_0x7c9698){_0x55ad8c[_0x82a0('0x45')]('i.'+_0x7c9698);});}else{_0x55ad8c[_0x82a0('0x45')](_0x82a0('0x8c'),_0x82a0('0x5e'));_0x55ad8c[_0x82a0('0x45')]('a.key','Account.key');_0x55ad8c[_0x82a0('0x45')](_0x82a0('0x97'),_0x82a0('0x98'));_0x55ad8c[_0x82a0('0x45')](_0x82a0('0x99'),_0x82a0('0x8d'));_0x55ad8c[_0x82a0('0x45')]('i.*');_0x55ad8c[_0x82a0('0x45')]('c.firstName',_0x82a0('0x9a'));_0x55ad8c[_0x82a0('0x45')](_0x82a0('0x9b'),_0x82a0('0x9c'));_0x55ad8c['field'](_0x82a0('0x9d'),'Contact.email');_0x55ad8c['field'](_0x82a0('0x9e'),_0x82a0('0x9f'));_0x55ad8c['field'](_0x82a0('0xa0'),_0x82a0('0xa1'));_0x55ad8c[_0x82a0('0x45')](_0x82a0('0xa2'),_0x82a0('0xa3'));_0x55ad8c[_0x82a0('0x45')]('o.fullname',_0x82a0('0xa4'));_0x55ad8c[_0x82a0('0x45')](_0x82a0('0xa5'),_0x82a0('0xa6'));_0x55ad8c[_0x82a0('0x45')]('GROUP_CONCAT(DISTINCT\x20t.id)','TagIds');}if(_0x4b881c[_0x82a0('0x20')])_0x55ad8c[_0x82a0('0x20')](_0x4b881c[_0x82a0('0x20')]);if(_0x4b881c[_0x82a0('0x1f')])_0x55ad8c[_0x82a0('0x1f')](_0x4b881c['offset']);return db[_0x82a0('0x96')][_0x82a0('0x3a')](_0x55ad8c[_0x82a0('0xa7')](),_0x40ca77);})['then'](function(_0x3488da){_0x2f737f[_0x82a0('0x43')](_0x82a0('0xa8'),_[_0x82a0('0x2c')](_0x3488da,'id'));return db[_0x82a0('0x96')]['query'](_0x2f737f['toString'](),_0x40ca77)['then'](function(_0x1b8f0e){var _0x3eb690=_[_0x82a0('0xa9')](_0x1b8f0e,_0x82a0('0xaa'));var _0x55ee1b=[];_0x3488da[_0x82a0('0x31')](function(_0x3489e6){_0x55ee1b['push'](updateSmsInteraction(_0x3489e6,_0x35c4c9,_0x3eb690));});return BPromise['all'](_0x55ee1b);});});})[_0x82a0('0x26')](function(_0x24fa9e){_0x5ecc49[_0x82a0('0xab')]=_0x24fa9e;return _0x5ecc49;})[_0x82a0('0x26')](respondWithFilteredResult(_0x3b7d28,_0x4b881c));})[_0x82a0('0x33')](handleError(_0x3b7d28,null));};exports[_0x82a0('0xac')]=function(_0x3f3895,_0x162dd8){var _0x2bd511={'raw':![],'where':{'id':_0x3f3895[_0x82a0('0xad')]['id']}},_0x65f52a={};_0x65f52a['model']=_[_0x82a0('0x3b')](db[_0x82a0('0x35')][_0x82a0('0x36')]);_0x65f52a['query']=_[_0x82a0('0x3b')](_0x3f3895[_0x82a0('0x3a')]);_0x65f52a[_0x82a0('0x3c')]=_[_0x82a0('0x3d')](_0x65f52a[_0x82a0('0xae')],_0x65f52a['query']);_0x2bd511[_0x82a0('0x3f')]=_[_0x82a0('0x3d')](_0x65f52a[_0x82a0('0xae')],qs[_0x82a0('0x3e')](_0x3f3895[_0x82a0('0x3a')][_0x82a0('0x3e')]));_0x2bd511[_0x82a0('0x3f')]=_0x2bd511[_0x82a0('0x3f')][_0x82a0('0x5b')]?_0x2bd511[_0x82a0('0x3f')]:_0x65f52a[_0x82a0('0xae')];if(_0x3f3895[_0x82a0('0x3a')][_0x82a0('0xaf')]){_0x2bd511[_0x82a0('0xb0')]=[{'all':!![]}];}_0x2bd511=_[_0x82a0('0xb1')]({},_0x2bd511,_0x3f3895[_0x82a0('0xb2')]);return db[_0x82a0('0x35')][_0x82a0('0x5d')](_0x2bd511)[_0x82a0('0x26')](handleEntityNotFound(_0x162dd8,null))[_0x82a0('0x26')](respondWithResult(_0x162dd8,null))[_0x82a0('0x33')](handleError(_0x162dd8,null));};exports[_0x82a0('0xb3')]=function(_0x34d489,_0x1ee497){return db[_0x82a0('0x35')]['create'](_0x34d489[_0x82a0('0xb4')],{})['then'](respondWithResult(_0x1ee497,0xc9))[_0x82a0('0x33')](handleError(_0x1ee497,null));};exports[_0x82a0('0x25')]=function(_0x3b34fc,_0x4f99b0){if(_0x3b34fc['body']['id']){delete _0x3b34fc[_0x82a0('0xb4')]['id'];}return db[_0x82a0('0x35')][_0x82a0('0x5d')]({'where':{'id':_0x3b34fc[_0x82a0('0xad')]['id']}})[_0x82a0('0x26')](handleEntityNotFound(_0x4f99b0,null))[_0x82a0('0x26')](saveUpdates(_0x3b34fc['body'],null))[_0x82a0('0x26')](respondWithResult(_0x4f99b0,null))[_0x82a0('0x33')](handleError(_0x4f99b0,null));};exports[_0x82a0('0x27')]=function(_0x10b3c0,_0x449e89){return db[_0x82a0('0x35')]['find']({'where':{'id':_0x10b3c0[_0x82a0('0xad')]['id']}})['then'](handleEntityNotFound(_0x449e89,null))[_0x82a0('0x26')](removeEntity(_0x449e89,null))[_0x82a0('0x33')](handleError(_0x449e89,null));};exports[_0x82a0('0xb5')]=function(_0x3d8ffe,_0x1e49b7){return db[_0x82a0('0x35')][_0x82a0('0xb5')]()[_0x82a0('0x26')](respondWithResult(_0x1e49b7,null))[_0x82a0('0x33')](handleError(_0x1e49b7,null));};exports[_0x82a0('0xb6')]=function(_0xfa4fb3,_0x6776d8,_0xb8e07a){return db[_0x82a0('0xb7')][_0x82a0('0x5d')]({'where':{'id':_0xfa4fb3['params']['id']}})[_0x82a0('0x26')](handleEntityNotFound(_0x6776d8,null))[_0x82a0('0x26')](function(_0x585e1f){if(_0x585e1f){return _0x585e1f['addMessage'](_0xfa4fb3[_0x82a0('0xb4')][_0x82a0('0xb8')],_[_0x82a0('0xb9')](_0xfa4fb3[_0x82a0('0xb4')],['ids','id'])||{});}})[_0x82a0('0x26')](respondWithResult(_0x6776d8,null))[_0x82a0('0x33')](handleError(_0x6776d8,null));};exports[_0x82a0('0xba')]=function(_0x4b8793,_0x2c2add,_0x336f26){var _0x5e5c1f={'raw':![],'where':{}};var _0x334f50={};var _0x280134={'count':0x0,'rows':[]};return db[_0x82a0('0x35')][_0x82a0('0xbb')]({'where':{'id':_0x4b8793['params']['id']}})[_0x82a0('0x26')](handleEntityNotFound(_0x2c2add,null))['then'](function(_0x57c691){if(_0x57c691){_0x334f50[_0x82a0('0xae')]=_['keys'](db[_0x82a0('0xb7')][_0x82a0('0x36')]);_0x334f50[_0x82a0('0x3a')]=_[_0x82a0('0x3b')](_0x4b8793[_0x82a0('0x3a')]);_0x334f50[_0x82a0('0x3c')]=_[_0x82a0('0x3d')](_0x334f50['model'],_0x334f50[_0x82a0('0x3a')]);_0x5e5c1f[_0x82a0('0x3f')]=_[_0x82a0('0x3d')](_0x334f50[_0x82a0('0xae')],qs['fields'](_0x4b8793['query'][_0x82a0('0x3e')]));_0x5e5c1f['attributes']=_0x5e5c1f[_0x82a0('0x3f')]['length']?_0x5e5c1f[_0x82a0('0x3f')]:_0x334f50[_0x82a0('0xae')];if(!_0x4b8793[_0x82a0('0x3a')][_0x82a0('0x40')](_0x82a0('0xbc'))){_0x5e5c1f[_0x82a0('0x20')]=qs[_0x82a0('0x20')](_0x4b8793['query'][_0x82a0('0x20')]);_0x5e5c1f[_0x82a0('0x1f')]=qs['offset'](_0x4b8793[_0x82a0('0x3a')]['offset']);}_0x5e5c1f[_0x82a0('0x41')]=qs[_0x82a0('0x42')](_0x4b8793[_0x82a0('0x3a')]['sort']);_0x5e5c1f[_0x82a0('0x43')]=qs[_0x82a0('0x3c')](_['pick'](_0x4b8793['query'],_0x334f50[_0x82a0('0x3c')]));_0x5e5c1f['where'][_0x82a0('0xaa')]=_0x57c691['id'];if(_0x4b8793[_0x82a0('0x3a')][_0x82a0('0x81')]){_0x5e5c1f[_0x82a0('0x43')]=_['merge'](_0x5e5c1f['where'],{'$or':_['map'](_0x5e5c1f[_0x82a0('0x3f')],function(_0x2faab2){var _0x20a852={};_0x20a852[_0x2faab2]={'$like':'%'+_0x4b8793[_0x82a0('0x3a')]['filter']+'%'};return _0x20a852;})});}if(_0x4b8793[_0x82a0('0x3a')][_0x82a0('0x78')]){var _0x2ecbbf=_0x4b8793[_0x82a0('0x3a')]['$gte'][_0x82a0('0x30')](',');var _0x274ab1={};_0x274ab1[_0x2ecbbf[0x0]]={'$gte':moment(_0x2ecbbf[0x1])[_0x82a0('0xbd')](_0x82a0('0xbe'))};_0x5e5c1f[_0x82a0('0x43')]=_[_0x82a0('0xb1')](_0x5e5c1f[_0x82a0('0x43')],_0x274ab1);}_0x5e5c1f=_['merge']({},_0x5e5c1f,_0x4b8793['options']);return db[_0x82a0('0xb7')][_0x82a0('0x1e')]({'where':_0x5e5c1f['where']})[_0x82a0('0x26')](function(_0x28021f){_0x280134[_0x82a0('0x1e')]=_0x28021f;if(_0x4b8793[_0x82a0('0x3a')][_0x82a0('0xaf')]){_0x5e5c1f['include']=[{'all':!![]}];}return db['SmsMessage'][_0x82a0('0xbf')](_0x5e5c1f);})['then'](function(_0x21a374){_0x280134[_0x82a0('0xab')]=_0x21a374;return _0x280134;});}})[_0x82a0('0x26')](respondWithFilteredResult(_0x2c2add,_0x5e5c1f))['catch'](handleError(_0x2c2add,null));};exports[_0x82a0('0xc0')]=function(_0x1d3183,_0x4c72c1,_0x5d5b9b){return db[_0x82a0('0x35')][_0x82a0('0x5d')]({'where':{'id':_0x1d3183[_0x82a0('0xad')]['id']}})['then'](handleEntityNotFound(_0x4c72c1,null))['then'](function(_0x15dd60){if(_0x15dd60){return _0x15dd60[_0x82a0('0xc1')](_0x1d3183['body']['ids'],_[_0x82a0('0xb9')](_0x1d3183['body'],['ids','id'])||{})[_0x82a0('0xc2')](function(){return db[_0x82a0('0x6b')][_0x82a0('0xbf')]({'attributes':['id',_0x82a0('0x29'),_0x82a0('0x46')],'where':{'id':_0x1d3183[_0x82a0('0xb4')]['ids']}});})['then'](function(_0x3bdf2e){socket[_0x82a0('0xc3')](_0x82a0('0xc4'),{'id':Number(_0x1d3183[_0x82a0('0xad')]['id']),'tags':_0x3bdf2e||[]});return{'id':Number(_0x1d3183[_0x82a0('0xad')]['id']),'tags':_0x3bdf2e||[]};});}})[_0x82a0('0x26')](respondWithResult(_0x4c72c1,null))[_0x82a0('0x33')](handleError(_0x4c72c1,null));};exports['removeTags']=function(_0x1fbd33,_0x3e9907,_0x320246){return db['SmsInteraction']['find']({'where':{'id':_0x1fbd33[_0x82a0('0xad')]['id']}})[_0x82a0('0x26')](handleEntityNotFound(_0x3e9907,null))[_0x82a0('0x26')](function(_0x5b7cc6){if(_0x5b7cc6){return _0x5b7cc6['removeTags'](_0x1fbd33['query'][_0x82a0('0xb8')]);}})['then'](respondWithStatusCode(_0x3e9907,null))[_0x82a0('0x33')](handleError(_0x3e9907,null));};exports[_0x82a0('0xc5')]=function(_0x5682fd,_0x3273f2){var _0x3a4ccb=moment()[_0x82a0('0xc6')]()['toString']();var _0x1e365d=path[_0x82a0('0xc7')](config[_0x82a0('0xc8')],_0x82a0('0xc9'),_0x82a0('0xca'),'tmp');var _0x37ec66=path[_0x82a0('0xc7')](config['root'],_0x82a0('0xc9'),_0x82a0('0xca'),_0x82a0('0xcb'));var _0x374ebe=path[_0x82a0('0xc7')](_0x1e365d,_0x3a4ccb);var _0x28132c=util['format'](_0x82a0('0xcc'),_0x5682fd[_0x82a0('0xad')]['id'],_0x3a4ccb);var _0x4ff9f8=path[_0x82a0('0xc7')](_0x1e365d,_0x28132c);var _0x2ce036=[];_0x2ce036[_0x82a0('0x32')]({'model':db['User'],'as':_0x82a0('0x6d'),'attributes':['id',_0x82a0('0x2d')],'raw':!![]});_0x2ce036[_0x82a0('0x32')]({'model':db[_0x82a0('0xcd')],'as':_0x82a0('0x63'),'attributes':['id',_0x82a0('0xce'),_0x82a0('0xcf')],'raw':!![]});var _0x5a3ba7=[{'model':db['SmsMessage'],'as':_0x82a0('0xd0'),'attributes':['id',_0x82a0('0xb4'),_0x82a0('0x76'),_0x82a0('0xd1'),_0x82a0('0xd2'),_0x82a0('0x7d')],'include':_0x2ce036}];_0x5a3ba7[_0x82a0('0x32')]({'model':db[_0x82a0('0xd3')],'as':'Account','attributes':['id',_0x82a0('0x29')]});_0x5a3ba7['push']({'model':db['User'],'as':_0x82a0('0xd4'),'attributes':['id','fullname']});return db[_0x82a0('0x35')][_0x82a0('0x5d')]({'where':{'id':_0x5682fd[_0x82a0('0xad')]['id']},'include':_0x5a3ba7})[_0x82a0('0x26')](handleEntityNotFound(_0x3273f2,null))[_0x82a0('0x26')](function(_0x59c4c6){if(_0x59c4c6){var _0xa43354=_0x59c4c6[_0x82a0('0xd5')]({'plain':!![]});fs[_0x82a0('0xd6')](_0x374ebe);var _0x5e9ca1={'format':'A4','border':_0x82a0('0xd7'),'header':{'height':_0x82a0('0xd8'),'contents':{'first':_0x82a0('0xd9')}},'footer':{'height':_0x82a0('0xda'),'contents':{'default':util[_0x82a0('0xbd')](_0x82a0('0xdb'),util[_0x82a0('0xbd')](_0x82a0('0xdc'),_0x82a0('0xdd'),_0xa43354['id']),moment()[_0x82a0('0xbd')](_0x82a0('0xde'))[_0x82a0('0xa7')]())}}};var _0x4f8b0e={'channel':_0x82a0('0xdd'),'account':_0xa43354[_0x82a0('0xdf')][_0x82a0('0x29')],'agent':_0xa43354[_0x82a0('0xd4')]?_0xa43354[_0x82a0('0xd4')][_0x82a0('0x2d')]:_0x82a0('0xe0'),'createdAt':moment(_0xa43354[_0x82a0('0x76')])[_0x82a0('0xbd')](_0x82a0('0xbe'))[_0x82a0('0xa7')](),'closedAt':_0xa43354[_0x82a0('0xe1')]?moment(_0xa43354[_0x82a0('0xe2')])[_0x82a0('0xbd')](_0x82a0('0xbe'))['toString']():'','disposition':_0xa43354[_0x82a0('0xe3')],'messages':_(_0xa43354[_0x82a0('0xd0')])[_0x82a0('0x81')]({'secret':![]})[_0x82a0('0x2c')](function(_0x4a2765){return{'date':moment(_0x4a2765[_0x82a0('0x76')])[_0x82a0('0xbd')](_0x82a0('0xbe'))[_0x82a0('0xa7')](),'sender':_0x4a2765['direction']===_0x82a0('0xe4')?_0x4a2765[_0x82a0('0x6d')]?_0x4a2765['User'][_0x82a0('0x2d')]:_0x82a0('0xe5'):_0x4a2765['Contact']['firstName']+(_0x4a2765[_0x82a0('0x63')]['lastName']?'\x20'+_0x4a2765[_0x82a0('0x63')][_0x82a0('0xcf')]:''),'body':_0x4a2765[_0x82a0('0xb4')],'direction':_0x4a2765[_0x82a0('0xd1')]==='out'?'A':'C','secret':_0x4a2765[_0x82a0('0xd2')],'read':_0x4a2765[_0x82a0('0x7d')]};})[_0x82a0('0x5f')]()};return ejs[_0x82a0('0xe6')](path['join'](config[_0x82a0('0xc8')],_0x82a0('0xc9'),_0x82a0('0xe7'),_0x82a0('0xe8')),{'interaction':_0x4f8b0e})['then'](function(_0x3f59db){return new BPromise(function(_0x57f187,_0x480d3e){pdf[_0x82a0('0xb3')](_0x3f59db,_0x5e9ca1)[_0x82a0('0xe9')](path[_0x82a0('0xc7')](_0x374ebe,_0x82a0('0xea')+_0xa43354['id']+'-'+_0x3a4ccb+_0x82a0('0xeb')),function(_0x2d0630,_0x2a27b7){if(_0x2d0630)return _0x480d3e(_0x2d0630);_0x57f187(_0x2a27b7);});});})['then'](function(){return new BPromise(function(_0x347d00,_0xf80c89){zipdir(_0x374ebe,{'saveTo':_0x4ff9f8},function(_0x4933f2,_0x4888bd){if(_0x4933f2)return _0xf80c89(_0x4933f2);return _0x347d00(_0x4888bd);});})[_0x82a0('0x26')](function(){return new BPromise(function(_0x1f6299,_0x3531f1){rimraf(_0x374ebe,function(_0xebb4e5){if(_0xebb4e5)_0x3531f1(_0xebb4e5);return _0x1f6299();});});})[_0x82a0('0x26')](function(){return _0x3273f2[_0x82a0('0xc5')](_0x4ff9f8,_0x28132c,function(_0x183578){if(_0x183578){console['log'](_0x82a0('0xec'),_0x183578);}else{fs['unlinkSync'](_0x4ff9f8);}});});});}else{return _0x3273f2[_0x82a0('0x1a')](0xc8);}})[_0x82a0('0x33')](handleError(_0x3273f2,null));};
\ No newline at end of file
+var _0x7f2b=['show','params','rawAttributes','include','options','create','describe','SmsMessage','addMessage','ids','getMessages','findOne','hasOwnProperty','nolimit','format','includeAll','findAll','addTags','omit','spread','emit','smsInteractionTags:save','removeTags','unix','root','server','files','tmp','join','transcript-%d-%s.zip','Contact','firstName','lastName','Messages','direction','SmsAccount','Owner','get','mkdirSync','Sms','Account','N.A.','YYYY-MM-DD\x20HH:mm:ss','closedAt','disposition','out','secret','renderFile','views','downloadInteraction.ejs','.pdf','createPdfFromHTML','download','log','err','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','redis','defaults','socket.io-emitter','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','destroy','then','stack','name','Users','map','fullname','TagIds','Tags','split','forEach','push','catch','answered','unmanaged','total','closed','UserId','waiting','talking','index','SmsInteraction','fieldName','type','model','query','filters','intersection','attributes','fields','length','order','sort','where','pick','field','from','tools_tags','select','u.fullname','user_has_sms_interactions','u.id\x20=\x20ui.UserId','sms_interactions','left_join','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','sms_accounts','a.id\x20=\x20i.SmsAccountId','me.SmsInteractionId\x20=\x20i.id','sms_interaction_has_tags','it.SmsInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','parseSearch','search','sqlOperator','conditions','having','`\x20=\x200','`\x20>\x200','operator','value','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','find','ContactId','buildExpression','text','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','User','$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','body','keys','compact','isEmpty','i.SmsAccountId\x20IN\x20?','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`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','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages','contactName','DESC','t.id\x20IN\x20?','SmsAccountId','i.SmsAccountId\x20IS\x20NOT\x20NULL','user','role','sequelize','toString','merge','a.key','Account.key','i.*','Contact.firstName','c.lastName','Contact.lastName','Contact.email','Contact.phone','c.mobile','c.fax','o.fullname','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.SmsInteractionId\x20IN\x20?','groupBy','SmsInteractionId','all'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x7f2b,0x11d));var _0xb7f2=function(_0x53211e,_0x470046){_0x53211e=_0x53211e-0x0;var _0x25a03f=_0x7f2b[_0x53211e];return _0x25a03f;};'use strict';var emlformat=require(_0xb7f2('0x0'));var rimraf=require(_0xb7f2('0x1'));var zipdir=require(_0xb7f2('0x2'));var jsonpatch=require(_0xb7f2('0x3'));var rp=require(_0xb7f2('0x4'));var moment=require(_0xb7f2('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xb7f2('0x6'));var util=require('util');var path=require(_0xb7f2('0x7'));var sox=require(_0xb7f2('0x8'));var csv=require(_0xb7f2('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xb7f2('0xa'));var _=require(_0xb7f2('0xb'));var squel=require(_0xb7f2('0xc'));var crypto=require(_0xb7f2('0xd'));var jsforce=require(_0xb7f2('0xe'));var deskjs=require(_0xb7f2('0xf'));var toCsv=require(_0xb7f2('0x9'));var querystring=require('querystring');var Papa=require(_0xb7f2('0x10'));var Redis=require(_0xb7f2('0x11'));var authService=require(_0xb7f2('0x12'));var qs=require(_0xb7f2('0x13'));var as=require(_0xb7f2('0x14'));var pdf=require('../../components/export/pdf');var hardwareService=require(_0xb7f2('0x15'));var logger=require(_0xb7f2('0x16'))('api');var utils=require(_0xb7f2('0x17'));var config=require(_0xb7f2('0x18'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0xb7f2('0x19')]=_[_0xb7f2('0x1a')](config[_0xb7f2('0x19')],{'host':'localhost','port':0x18eb});var socket=require(_0xb7f2('0x1b'))(new Redis(config[_0xb7f2('0x19')]));require('./smsInteraction.socket')['register'](socket);function respondWithStatusCode(_0x28d421,_0x10a377){_0x10a377=_0x10a377||0xcc;return function(_0x3f20cf){if(_0x3f20cf){return _0x28d421[_0xb7f2('0x1c')](_0x10a377);}return _0x28d421[_0xb7f2('0x1d')](_0x10a377)[_0xb7f2('0x1e')]();};}function respondWithResult(_0x9ccb9b,_0x250e49){_0x250e49=_0x250e49||0xc8;return function(_0x1e07bf){if(_0x1e07bf){return _0x9ccb9b[_0xb7f2('0x1d')](_0x250e49)[_0xb7f2('0x1f')](_0x1e07bf);}};}function respondWithFilteredResult(_0x4625f4,_0x171039){return function(_0xc3590e){if(_0xc3590e){var _0x320562=typeof _0x171039[_0xb7f2('0x20')]===_0xb7f2('0x21')&&typeof _0x171039[_0xb7f2('0x22')]===_0xb7f2('0x21');var _0xb91fdc=_0xc3590e[_0xb7f2('0x23')];var _0x22fdc3=_0x320562?0x0:_0x171039['offset'];var _0x42d066=_0x320562?_0xc3590e['count']:_0x171039['offset']+_0x171039[_0xb7f2('0x22')];var _0x3a8d56;if(_0x42d066>=_0xb91fdc){_0x42d066=_0xb91fdc;_0x3a8d56=0xc8;}else{_0x3a8d56=0xce;}_0x4625f4[_0xb7f2('0x1d')](_0x3a8d56);return _0x4625f4[_0xb7f2('0x24')](_0xb7f2('0x25'),_0x22fdc3+'-'+_0x42d066+'/'+_0xb91fdc)[_0xb7f2('0x1f')](_0xc3590e);}return null;};}function patchUpdates(_0x638508){return function(_0x437517){try{jsonpatch[_0xb7f2('0x26')](_0x437517,_0x638508,!![]);}catch(_0x524330){return BPromise[_0xb7f2('0x27')](_0x524330);}return _0x437517[_0xb7f2('0x28')]();};}function saveUpdates(_0x8a5e93,_0x4af04d){return function(_0x4b1236){if(_0x4b1236){return _0x4b1236[_0xb7f2('0x29')](_0x8a5e93)['then'](function(_0x36fed0){return _0x36fed0;});}return null;};}function removeEntity(_0x7fe04b,_0x3021de){return function(_0x416e00){if(_0x416e00){return _0x416e00[_0xb7f2('0x2a')]()[_0xb7f2('0x2b')](function(){_0x7fe04b['status'](0xcc)[_0xb7f2('0x1e')]();});}};}function handleEntityNotFound(_0x39f29f,_0x3dcf5f){return function(_0x2f5906){if(!_0x2f5906){_0x39f29f[_0xb7f2('0x1c')](0x194);}return _0x2f5906;};}function handleError(_0x52330b,_0xda7d4){_0xda7d4=_0xda7d4||0x1f4;return function(_0x76f5b6){logger['error'](_0x76f5b6[_0xb7f2('0x2c')]);if(_0x76f5b6[_0xb7f2('0x2d')]){delete _0x76f5b6[_0xb7f2('0x2d')];}_0x52330b['status'](_0xda7d4)['send'](_0x76f5b6);};}function getInteractionUsers(_0x4b12bb,_0x10c4d7){return new BPromise(function(_0x49d548,_0x4e6192){try{if(_0x10c4d7[_0x4b12bb['id']]){_0x4b12bb[_0xb7f2('0x2e')]=_[_0xb7f2('0x2f')](_0x10c4d7[_0x4b12bb['id']],function(_0x4ca4e8){return{'id':_0x4ca4e8['id'],'fullname':_0x4ca4e8[_0xb7f2('0x30')]};});}}catch(_0x4df33f){_0x4e6192(_0x4df33f);}_0x49d548(_0x4b12bb);});}function getInteractionTags(_0x5d0068,_0x88dbdb){return new BPromise(function(_0x586d02,_0x2b2a3e){try{if(_0x5d0068[_0xb7f2('0x31')]){_0x5d0068[_0xb7f2('0x32')]=[];_0x5d0068['TagIds'][_0xb7f2('0x33')](',')[_0xb7f2('0x34')](function(_0x216c64){_0x5d0068[_0xb7f2('0x32')][_0xb7f2('0x35')](_0x88dbdb[_0x216c64]);});}delete _0x5d0068[_0xb7f2('0x31')];}catch(_0xb0b708){_0x2b2a3e(_0xb0b708);}_0x586d02(_0x5d0068);});}function updateSmsInteraction(_0x356628,_0x11f6ea,_0x5ac7a3){return new BPromise(function(_0x382982,_0x33a301){return getInteractionUsers(_0x356628,_0x5ac7a3)[_0xb7f2('0x2b')](function(_0x356077){return getInteractionTags(_0x356077,_0x11f6ea);})[_0xb7f2('0x2b')](function(_0x73b219){return getStateInteraction(_0x73b219);})['then'](function(_0x3f50cf){_0x382982(_0x3f50cf);})[_0xb7f2('0x36')](function(_0x2f3885){_0x33a301(_0x2f3885);});});}function getStateInteraction(_0x32b6ed){return new BPromise(function(_0x409c1d){_0x32b6ed['waiting']=0x0;_0x32b6ed['talking']=0x0;_0x32b6ed[_0xb7f2('0x37')]=0x0;_0x32b6ed[_0xb7f2('0x38')]=0x0;_0x32b6ed[_0xb7f2('0x39')]=0x0;if(!_0x32b6ed[_0xb7f2('0x3a')]&&!_0x32b6ed[_0xb7f2('0x3b')]){_0x32b6ed[_0xb7f2('0x3c')]+=0x1;}if(!_0x32b6ed[_0xb7f2('0x3a')]&&_0x32b6ed['UserId']){_0x32b6ed[_0xb7f2('0x3d')]+=0x1;if(_0x32b6ed['waiting']){_0x32b6ed[_0xb7f2('0x3c')]-=0x1;}}if(_0x32b6ed['closed']&&_0x32b6ed[_0xb7f2('0x3b')]){_0x32b6ed[_0xb7f2('0x37')]+=0x1;if(_0x32b6ed[_0xb7f2('0x3d')]){_0x32b6ed[_0xb7f2('0x3d')]-=0x1;}}if(_0x32b6ed['closed']&&!_0x32b6ed['UserId']){_0x32b6ed['unmanaged']+=0x1;if(_0x32b6ed[_0xb7f2('0x3c')]){_0x32b6ed[_0xb7f2('0x3c')]-=0x1;}}_0x32b6ed[_0xb7f2('0x39')]+=0x1;_0x409c1d(_0x32b6ed);});}exports[_0xb7f2('0x3e')]=function(_0x5c8dfb,_0x17c759){var _0x517430={},_0x390f1a={},_0x2b990d={'count':0x0,'rows':[]};var _0x4df917=_[_0xb7f2('0x2f')](db[_0xb7f2('0x3f')]['rawAttributes'],function(_0x21e099){return{'name':_0x21e099[_0xb7f2('0x40')],'type':_0x21e099[_0xb7f2('0x41')]['key']};});_0x390f1a[_0xb7f2('0x42')]=_[_0xb7f2('0x2f')](_0x4df917,_0xb7f2('0x2d'));_0x390f1a[_0xb7f2('0x43')]=_['keys'](_0x5c8dfb[_0xb7f2('0x43')]);_0x390f1a[_0xb7f2('0x44')]=_[_0xb7f2('0x45')](_0x390f1a[_0xb7f2('0x42')],_0x390f1a['query']);_0x517430[_0xb7f2('0x46')]=_[_0xb7f2('0x45')](_0x390f1a['model'],qs['fields'](_0x5c8dfb[_0xb7f2('0x43')][_0xb7f2('0x47')]));_0x517430[_0xb7f2('0x46')]=_0x517430[_0xb7f2('0x46')][_0xb7f2('0x48')]?_0x517430[_0xb7f2('0x46')]:_0x390f1a[_0xb7f2('0x42')];if(!_0x5c8dfb[_0xb7f2('0x43')]['hasOwnProperty']('nolimit')){_0x517430[_0xb7f2('0x22')]=qs['limit'](_0x5c8dfb[_0xb7f2('0x43')][_0xb7f2('0x22')]);_0x517430['offset']=qs['offset'](_0x5c8dfb[_0xb7f2('0x43')]['offset']);}_0x517430[_0xb7f2('0x49')]=qs[_0xb7f2('0x4a')](_0x5c8dfb[_0xb7f2('0x43')][_0xb7f2('0x4a')]);_0x517430[_0xb7f2('0x4b')]=qs['filters'](_[_0xb7f2('0x4c')](_0x5c8dfb[_0xb7f2('0x43')],_0x390f1a[_0xb7f2('0x44')]),_0x4df917);var _0x33fab8=[];var _0x1c689c=squel['select']()['field']('id')[_0xb7f2('0x4d')](_0xb7f2('0x2d'))['field']('color')[_0xb7f2('0x4e')](_0xb7f2('0x4f'));var _0x325cee=squel[_0xb7f2('0x50')]()[_0xb7f2('0x4d')]('u.id')[_0xb7f2('0x4d')](_0xb7f2('0x51'))[_0xb7f2('0x4d')]('ui.SmsInteractionId')[_0xb7f2('0x4e')](_0xb7f2('0x52'),'ui')['left_join']('users','u',_0xb7f2('0x53'));var _0x546473=squel[_0xb7f2('0x50')]()['from'](_0xb7f2('0x54'),'i')[_0xb7f2('0x55')](_0xb7f2('0x56'),'c',_0xb7f2('0x57'))[_0xb7f2('0x55')]('users','o','o.id\x20=\x20i.UserId')[_0xb7f2('0x55')](_0xb7f2('0x58'),'a',_0xb7f2('0x59'))[_0xb7f2('0x55')]('sms_messages','me',_0xb7f2('0x5a'))[_0xb7f2('0x55')](_0xb7f2('0x5b'),'it',_0xb7f2('0x5c'))[_0xb7f2('0x55')]('tools_tags','t',_0xb7f2('0x5d'));var _0x3a6398=squel[_0xb7f2('0x5e')]();var _0x59682b=[];var _0x157fd5=squel[_0xb7f2('0x5e')]();var _0x7f1505;if(_0x5c8dfb[_0xb7f2('0x43')]['search']){_0x7f1505=as[_0xb7f2('0x5f')](_0x5c8dfb['query'][_0xb7f2('0x60')]);var _0x16d870=_0x7f1505[_0xb7f2('0x61')];for(var _0x28573b=0x0;_0x28573b<_0x7f1505['conditions'][_0xb7f2('0x48')];_0x28573b++){var _0x3fe3ce=_0x7f1505[_0xb7f2('0x62')][_0x28573b];var _0x28a714='i';var _0x3d8427=_['find'](_0x4df917,[_0xb7f2('0x2d'),_0x3fe3ce[_0xb7f2('0x4d')]]);if(!_0x3d8427){switch(_0x3fe3ce[_0xb7f2('0x4d')]){case'unreadMessages':if(_0x3fe3ce['value']==0x1){_0x546473[_0xb7f2('0x63')]('`'+_0x3fe3ce['field']+_0xb7f2('0x64'));}else{_0x546473[_0xb7f2('0x63')]('`'+_0x3fe3ce['field']+_0xb7f2('0x65'));}break;case'Contact':if(_0x3fe3ce[_0xb7f2('0x66')]==='$substring'){if(_0x3fe3ce[_0xb7f2('0x67')]['split']('\x20')[_0xb7f2('0x48')]>0x1){_0x3a6398[_0x16d870](_0xb7f2('0x68'),qs['getFullTextValue'](_0x3fe3ce[_0xb7f2('0x67')]),null);}else{var _0x2abb6f='%'+_0x3fe3ce[_0xb7f2('0x67')]+'%';_0x3a6398[_0x16d870](_0xb7f2('0x69'),_0x2abb6f,_0x2abb6f,_0x2abb6f);}}else{_0x3d8427=_[_0xb7f2('0x6a')](_0x4df917,[_0xb7f2('0x2d'),_0xb7f2('0x6b')]);_0x3fe3ce['field']=_0xb7f2('0x6b');_0x291cd4=as[_0xb7f2('0x6c')](_0x28a714,_0x3d8427['type'],_0x3fe3ce);_0x3a6398[_0x16d870](_0x291cd4[_0xb7f2('0x6d')],_0x291cd4[_0xb7f2('0x67')][_0xb7f2('0x6e')],_0x291cd4[_0xb7f2('0x67')][_0xb7f2('0x1e')]);}break;case _0xb7f2('0x6f'):var _0x4c1b8e=_0x3fe3ce[_0xb7f2('0x67')][_0xb7f2('0x33')](',')['map'](function(_0x4d80e9){return Number(_0x4d80e9);});_0x4c1b8e[_0xb7f2('0x34')](function(_0x3a1914){_0x157fd5['or'](_0xb7f2('0x70'),'%,'+_0x3a1914+',%');});_0x59682b=_['union'](_0x59682b,_0x4c1b8e);break;case _0xb7f2('0x71'):if(_0x3fe3ce['operator']===_0xb7f2('0x72')){_0x3a6398[_0x16d870](_0xb7f2('0x73'),'%'+_0x3fe3ce[_0xb7f2('0x67')]+'%',null);}else{_0x3d8427=_[_0xb7f2('0x6a')](_0x4df917,['name',_0xb7f2('0x3b')]);_0x3fe3ce[_0xb7f2('0x4d')]=_0xb7f2('0x3b');_0x291cd4=as[_0xb7f2('0x6c')](_0x28a714,_0x3d8427[_0xb7f2('0x41')],_0x3fe3ce);_0x3a6398[_0x16d870](_0x291cd4[_0xb7f2('0x6d')],_0x291cd4[_0xb7f2('0x67')][_0xb7f2('0x6e')],_0x291cd4['value'][_0xb7f2('0x1e')]);}break;case _0xb7f2('0x74'):_0x291cd4=as[_0xb7f2('0x6c')]('me',null,_0x3fe3ce);_0x3a6398[_0x16d870](_0x291cd4['text'],_0x291cd4['value'][_0xb7f2('0x6e')],_0x291cd4[_0xb7f2('0x67')]['end']);break;}}else{var _0x291cd4=as[_0xb7f2('0x6c')](_0x28a714,_0x3d8427[_0xb7f2('0x41')],_0x3fe3ce);_0x3a6398[_0x16d870](_0x291cd4[_0xb7f2('0x6d')],_0x291cd4[_0xb7f2('0x67')]['start'],_0x291cd4[_0xb7f2('0x67')][_0xb7f2('0x1e')]);}}}else{var _0x33ac3e=_(_0x5c8dfb['query'])[_0xb7f2('0x75')]()[_0xb7f2('0x2f')](function(_0x403bd9){return _['some'](_0x4df917,['name',_0x403bd9])?_0x403bd9:undefined;})[_0xb7f2('0x76')]()[_0xb7f2('0x67')]();if(!_[_0xb7f2('0x77')](_0x33ac3e)){_0x33ac3e[_0xb7f2('0x34')](function(_0x248c4e){if(_0x248c4e==='SmsAccountId'){_0x546473[_0xb7f2('0x4b')](_0xb7f2('0x78'),[][_0xb7f2('0x79')](_0x5c8dfb[_0xb7f2('0x43')][_0x248c4e]));}else if(_0x248c4e===_0xb7f2('0x7a')){var _0x38a1d8=JSON[_0xb7f2('0x7b')](_0x5c8dfb[_0xb7f2('0x43')][_0x248c4e])[_0xb7f2('0x7c')];var _0x4fc616=JSON[_0xb7f2('0x7b')](_0x5c8dfb['query'][_0x248c4e])[_0xb7f2('0x7d')];_0x546473[_0xb7f2('0x4b')](_0xb7f2('0x7e'),_0x38a1d8,_0x4fc616);}else{if(_0x5c8dfb[_0xb7f2('0x43')][_0x248c4e]===_0xb7f2('0x7f')){_0x546473[_0xb7f2('0x4b')]('i.'+_0x248c4e+_0xb7f2('0x80'));}else{_0x546473[_0xb7f2('0x4b')]('i.'+_0x248c4e+_0xb7f2('0x81'),_0x5c8dfb[_0xb7f2('0x43')][_0x248c4e]);}}});}if(_0x5c8dfb[_0xb7f2('0x43')][_0xb7f2('0x82')]){if(_0x5c8dfb[_0xb7f2('0x43')][_0xb7f2('0x82')]==0x1){_0x546473[_0xb7f2('0x63')](_0xb7f2('0x83'));}else{_0x546473[_0xb7f2('0x63')](_0xb7f2('0x84'));}}if(_0x5c8dfb[_0xb7f2('0x43')]['tag']){_0x59682b=_['isArray'](_0x5c8dfb[_0xb7f2('0x43')]['tag'])?_0x5c8dfb['query'][_0xb7f2('0x85')]:new Array(_0x5c8dfb[_0xb7f2('0x43')][_0xb7f2('0x85')]);_0x59682b[_0xb7f2('0x34')](function(_0x3dbe59){_0x157fd5['or'](_0xb7f2('0x70'),'%,'+_0x3dbe59+',%');});}if(_0x5c8dfb[_0xb7f2('0x43')]['filter']){var _0x290784=_0x5c8dfb[_0xb7f2('0x43')][_0xb7f2('0x86')][_0xb7f2('0x87')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs[_0xb7f2('0x88')](_0x290784)){_0x3a6398['or'](_0xb7f2('0x89'),_0x290784+'%')['or'](_0xb7f2('0x8a'),_0x290784+'%');}else{_0x3a6398['or'](_0xb7f2('0x8b'),qs['getFullTextValue'](_0x290784))['or'](_0xb7f2('0x8c'),_0x290784+'%');}}}_0x546473[_0xb7f2('0x4b')](_0x3a6398);_0x546473[_0xb7f2('0x8d')](_0xb7f2('0x8e'));var _0x4b6e33={'type':db['Sequelize'][_0xb7f2('0x8f')][_0xb7f2('0x90')],'raw':!![]};var _0x2e65f2=_0x546473[_0xb7f2('0x91')]();_0x2e65f2['field'](_0xb7f2('0x8e'));_0x2e65f2['field'](_0xb7f2('0x92'),_0xb7f2('0x93'));if(_0x517430[_0xb7f2('0x49')]){_0x517430[_0xb7f2('0x49')][_0xb7f2('0x34')](function(_0x148eff){var _0xd1975=_0x148eff[0x0]===_0xb7f2('0x94')?_0x148eff[0x0]:'i.'+_0x148eff[0x0];_0x546473[_0xb7f2('0x49')](_0xd1975,_0x148eff[0x1]===_0xb7f2('0x95')?![]:!![]);});}if(!_['isEmpty'](_0x59682b)){_0x546473['having'](_0x157fd5);_0x2e65f2[_0xb7f2('0x4b')](_0xb7f2('0x96'),_0x59682b);}BPromise['resolve']()[_0xb7f2('0x2b')](function(){if(!_0x7f1505){if(_0x5c8dfb[_0xb7f2('0x43')][_0xb7f2('0x97')])return;_0x2e65f2['where'](_0xb7f2('0x98'));_0x546473['where']('i.SmsAccountId\x20IS\x20NOT\x20NULL');return;}if(_0x5c8dfb[_0xb7f2('0x99')][_0xb7f2('0x9a')]!=='agent')return;return _0x5c8dfb['user']['getSmsAccounts']({'attributes':['id'],'raw':!![]})[_0xb7f2('0x2b')](function(_0x465e3e){if(_[_0xb7f2('0x77')](_0x465e3e)){_0x2e65f2[_0xb7f2('0x4b')]('i.SmsAccountId\x20IS\x20NULL');_0x546473[_0xb7f2('0x4b')]('i.SmsAccountId\x20IS\x20NULL');}else{_0x2e65f2[_0xb7f2('0x4b')]('i.SmsAccountId\x20IN\x20?',_[_0xb7f2('0x2f')](_0x465e3e,'id'));_0x546473[_0xb7f2('0x4b')](_0xb7f2('0x78'),_[_0xb7f2('0x2f')](_0x465e3e,'id'));}});})['then'](function(){if(_0x5c8dfb[_0xb7f2('0x99')][_0xb7f2('0x9a')]==='agent'&&!_0x7f1505&&!_0x5c8dfb['query']['SmsAccountId'])return[];return db[_0xb7f2('0x9b')][_0xb7f2('0x43')](_0x2e65f2['toString'](),_0x4b6e33);})[_0xb7f2('0x2b')](function(_0x7911d4){_0x2b990d[_0xb7f2('0x23')]=_0x7911d4[_0xb7f2('0x48')];if(_0x2b990d[_0xb7f2('0x23')]===0x0)return[];return db[_0xb7f2('0x9b')][_0xb7f2('0x43')](_0x1c689c[_0xb7f2('0x9c')](),_0x4b6e33)[_0xb7f2('0x2b')](function(_0x5d0c53){_0x33fab8=_['keyBy'](_0x5d0c53,'id');_0x4b6e33=_[_0xb7f2('0x9d')](_0x4b6e33,{'model':db[_0xb7f2('0x3f')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x5c8dfb['query']['fields']){_0x517430[_0xb7f2('0x46')][_0xb7f2('0x34')](function(_0x468aa8){_0x546473[_0xb7f2('0x4d')]('i.'+_0x468aa8);});}else{_0x546473[_0xb7f2('0x4d')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xb7f2('0x93'));_0x546473[_0xb7f2('0x4d')](_0xb7f2('0x9e'),_0xb7f2('0x9f'));_0x546473['field']('a.mandatoryDisposition','Account.mandatoryDisposition');_0x546473[_0xb7f2('0x4d')]('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',_0xb7f2('0x94'));_0x546473[_0xb7f2('0x4d')](_0xb7f2('0xa0'));_0x546473[_0xb7f2('0x4d')]('c.firstName',_0xb7f2('0xa1'));_0x546473[_0xb7f2('0x4d')](_0xb7f2('0xa2'),_0xb7f2('0xa3'));_0x546473[_0xb7f2('0x4d')]('c.email',_0xb7f2('0xa4'));_0x546473['field']('c.phone',_0xb7f2('0xa5'));_0x546473['field'](_0xb7f2('0xa6'),'Contact.mobile');_0x546473[_0xb7f2('0x4d')](_0xb7f2('0xa7'),'Contact.fax');_0x546473[_0xb7f2('0x4d')](_0xb7f2('0xa8'),'Owner.fullname');_0x546473[_0xb7f2('0x4d')]('o.internal',_0xb7f2('0xa9'));_0x546473['field'](_0xb7f2('0xaa'),'TagIds');}if(_0x517430[_0xb7f2('0x22')])_0x546473[_0xb7f2('0x22')](_0x517430[_0xb7f2('0x22')]);if(_0x517430[_0xb7f2('0x20')])_0x546473['offset'](_0x517430[_0xb7f2('0x20')]);return db[_0xb7f2('0x9b')][_0xb7f2('0x43')](_0x546473[_0xb7f2('0x9c')](),_0x4b6e33);})[_0xb7f2('0x2b')](function(_0x3cec8f){if(_0x3cec8f[_0xb7f2('0x48')]>0x0)_0x325cee[_0xb7f2('0x4b')](_0xb7f2('0xab'),_['map'](_0x3cec8f,'id'));return db[_0xb7f2('0x9b')][_0xb7f2('0x43')](_0x325cee['toString'](),_0x4b6e33)['then'](function(_0x3d6e40){var _0x2dfe58=_[_0xb7f2('0xac')](_0x3d6e40,_0xb7f2('0xad'));var _0x3fc738=[];_0x3cec8f[_0xb7f2('0x34')](function(_0x1359b1){_0x3fc738['push'](updateSmsInteraction(_0x1359b1,_0x33fab8,_0x2dfe58));});return BPromise[_0xb7f2('0xae')](_0x3fc738);});});})[_0xb7f2('0x2b')](function(_0x1e56a9){_0x2b990d['rows']=_0x1e56a9;return _0x2b990d;})['then'](respondWithFilteredResult(_0x17c759,_0x517430))[_0xb7f2('0x36')](handleError(_0x17c759,null));};exports[_0xb7f2('0xaf')]=function(_0x5a4f75,_0x4988c7){var _0x2fde99={'raw':![],'where':{'id':_0x5a4f75[_0xb7f2('0xb0')]['id']}},_0x34d7b6={};_0x34d7b6[_0xb7f2('0x42')]=_['keys'](db[_0xb7f2('0x3f')][_0xb7f2('0xb1')]);_0x34d7b6[_0xb7f2('0x43')]=_[_0xb7f2('0x75')](_0x5a4f75['query']);_0x34d7b6[_0xb7f2('0x44')]=_[_0xb7f2('0x45')](_0x34d7b6['model'],_0x34d7b6[_0xb7f2('0x43')]);_0x2fde99[_0xb7f2('0x46')]=_[_0xb7f2('0x45')](_0x34d7b6[_0xb7f2('0x42')],qs[_0xb7f2('0x47')](_0x5a4f75['query'][_0xb7f2('0x47')]));_0x2fde99['attributes']=_0x2fde99['attributes'][_0xb7f2('0x48')]?_0x2fde99['attributes']:_0x34d7b6[_0xb7f2('0x42')];if(_0x5a4f75[_0xb7f2('0x43')]['includeAll']){_0x2fde99[_0xb7f2('0xb2')]=[{'all':!![]}];}_0x2fde99=_[_0xb7f2('0x9d')]({},_0x2fde99,_0x5a4f75[_0xb7f2('0xb3')]);return db[_0xb7f2('0x3f')][_0xb7f2('0x6a')](_0x2fde99)[_0xb7f2('0x2b')](handleEntityNotFound(_0x4988c7,null))['then'](respondWithResult(_0x4988c7,null))[_0xb7f2('0x36')](handleError(_0x4988c7,null));};exports[_0xb7f2('0xb4')]=function(_0xd30ab3,_0x13a2e6){return db['SmsInteraction'][_0xb7f2('0xb4')](_0xd30ab3[_0xb7f2('0x74')],{})[_0xb7f2('0x2b')](respondWithResult(_0x13a2e6,0xc9))[_0xb7f2('0x36')](handleError(_0x13a2e6,null));};exports['update']=function(_0x3c3817,_0x4755b3){if(_0x3c3817[_0xb7f2('0x74')]['id']){delete _0x3c3817[_0xb7f2('0x74')]['id'];}return db['SmsInteraction'][_0xb7f2('0x6a')]({'where':{'id':_0x3c3817['params']['id']}})['then'](handleEntityNotFound(_0x4755b3,null))[_0xb7f2('0x2b')](saveUpdates(_0x3c3817[_0xb7f2('0x74')],null))[_0xb7f2('0x2b')](respondWithResult(_0x4755b3,null))['catch'](handleError(_0x4755b3,null));};exports[_0xb7f2('0x2a')]=function(_0x2d0eed,_0x5159e2){return db[_0xb7f2('0x3f')][_0xb7f2('0x6a')]({'where':{'id':_0x2d0eed['params']['id']}})[_0xb7f2('0x2b')](handleEntityNotFound(_0x5159e2,null))[_0xb7f2('0x2b')](removeEntity(_0x5159e2,null))[_0xb7f2('0x36')](handleError(_0x5159e2,null));};exports[_0xb7f2('0xb5')]=function(_0x4f26d1,_0x23fc9f){return db[_0xb7f2('0x3f')][_0xb7f2('0xb5')]()[_0xb7f2('0x2b')](respondWithResult(_0x23fc9f,null))[_0xb7f2('0x36')](handleError(_0x23fc9f,null));};exports['addMessage']=function(_0x337e4d,_0xf21802,_0x2d2206){return db[_0xb7f2('0xb6')][_0xb7f2('0x6a')]({'where':{'id':_0x337e4d['params']['id']}})['then'](handleEntityNotFound(_0xf21802,null))['then'](function(_0x355e40){if(_0x355e40){return _0x355e40[_0xb7f2('0xb7')](_0x337e4d[_0xb7f2('0x74')][_0xb7f2('0xb8')],_['omit'](_0x337e4d[_0xb7f2('0x74')],[_0xb7f2('0xb8'),'id'])||{});}})[_0xb7f2('0x2b')](respondWithResult(_0xf21802,null))['catch'](handleError(_0xf21802,null));};exports[_0xb7f2('0xb9')]=function(_0x459964,_0x38888d,_0x29a0c4){var _0x2e0932={'raw':![],'where':{}};var _0x4f02c3={};var _0x361b50={'count':0x0,'rows':[]};return db[_0xb7f2('0x3f')][_0xb7f2('0xba')]({'where':{'id':_0x459964['params']['id']}})[_0xb7f2('0x2b')](handleEntityNotFound(_0x38888d,null))[_0xb7f2('0x2b')](function(_0xbc2d6e){if(_0xbc2d6e){_0x4f02c3[_0xb7f2('0x42')]=_[_0xb7f2('0x75')](db[_0xb7f2('0xb6')]['rawAttributes']);_0x4f02c3[_0xb7f2('0x43')]=_[_0xb7f2('0x75')](_0x459964[_0xb7f2('0x43')]);_0x4f02c3[_0xb7f2('0x44')]=_[_0xb7f2('0x45')](_0x4f02c3[_0xb7f2('0x42')],_0x4f02c3[_0xb7f2('0x43')]);_0x2e0932['attributes']=_[_0xb7f2('0x45')](_0x4f02c3[_0xb7f2('0x42')],qs['fields'](_0x459964[_0xb7f2('0x43')][_0xb7f2('0x47')]));_0x2e0932['attributes']=_0x2e0932['attributes']['length']?_0x2e0932[_0xb7f2('0x46')]:_0x4f02c3[_0xb7f2('0x42')];if(!_0x459964[_0xb7f2('0x43')][_0xb7f2('0xbb')](_0xb7f2('0xbc'))){_0x2e0932[_0xb7f2('0x22')]=qs[_0xb7f2('0x22')](_0x459964[_0xb7f2('0x43')][_0xb7f2('0x22')]);_0x2e0932[_0xb7f2('0x20')]=qs[_0xb7f2('0x20')](_0x459964[_0xb7f2('0x43')][_0xb7f2('0x20')]);}_0x2e0932[_0xb7f2('0x49')]=qs[_0xb7f2('0x4a')](_0x459964[_0xb7f2('0x43')][_0xb7f2('0x4a')]);_0x2e0932['where']=qs[_0xb7f2('0x44')](_[_0xb7f2('0x4c')](_0x459964[_0xb7f2('0x43')],_0x4f02c3[_0xb7f2('0x44')]));_0x2e0932[_0xb7f2('0x4b')][_0xb7f2('0xad')]=_0xbc2d6e['id'];if(_0x459964[_0xb7f2('0x43')]['filter']){_0x2e0932[_0xb7f2('0x4b')]=_[_0xb7f2('0x9d')](_0x2e0932['where'],{'$or':_[_0xb7f2('0x2f')](_0x2e0932[_0xb7f2('0x46')],function(_0x190c6b){var _0x452aca={};_0x452aca[_0x190c6b]={'$like':'%'+_0x459964['query']['filter']+'%'};return _0x452aca;})});}if(_0x459964['query'][_0xb7f2('0x7c')]){var _0x2ff2f1=_0x459964[_0xb7f2('0x43')]['$gte'][_0xb7f2('0x33')](',');var _0x110029={};_0x110029[_0x2ff2f1[0x0]]={'$gte':moment(_0x2ff2f1[0x1])[_0xb7f2('0xbd')]('YYYY-MM-DD\x20HH:mm:ss')};_0x2e0932[_0xb7f2('0x4b')]=_['merge'](_0x2e0932['where'],_0x110029);}_0x2e0932=_['merge']({},_0x2e0932,_0x459964[_0xb7f2('0xb3')]);return db[_0xb7f2('0xb6')][_0xb7f2('0x23')]({'where':_0x2e0932[_0xb7f2('0x4b')]})[_0xb7f2('0x2b')](function(_0x312c69){_0x361b50['count']=_0x312c69;if(_0x459964[_0xb7f2('0x43')][_0xb7f2('0xbe')]){_0x2e0932['include']=[{'all':!![]}];}return db[_0xb7f2('0xb6')][_0xb7f2('0xbf')](_0x2e0932);})[_0xb7f2('0x2b')](function(_0x3919df){_0x361b50['rows']=_0x3919df;return _0x361b50;});}})[_0xb7f2('0x2b')](respondWithFilteredResult(_0x38888d,_0x2e0932))[_0xb7f2('0x36')](handleError(_0x38888d,null));};exports[_0xb7f2('0xc0')]=function(_0x5a6c2f,_0x444a5b,_0x192477){return db['SmsInteraction'][_0xb7f2('0x6a')]({'where':{'id':_0x5a6c2f[_0xb7f2('0xb0')]['id']}})[_0xb7f2('0x2b')](handleEntityNotFound(_0x444a5b,null))[_0xb7f2('0x2b')](function(_0x41ae14){if(_0x41ae14){return _0x41ae14['setTags'](_0x5a6c2f[_0xb7f2('0x74')][_0xb7f2('0xb8')],_[_0xb7f2('0xc1')](_0x5a6c2f[_0xb7f2('0x74')],[_0xb7f2('0xb8'),'id'])||{})[_0xb7f2('0xc2')](function(){return db[_0xb7f2('0x6f')][_0xb7f2('0xbf')]({'attributes':['id',_0xb7f2('0x2d'),'color'],'where':{'id':_0x5a6c2f[_0xb7f2('0x74')][_0xb7f2('0xb8')]}});})['then'](function(_0x466502){socket[_0xb7f2('0xc3')](_0xb7f2('0xc4'),{'id':Number(_0x5a6c2f[_0xb7f2('0xb0')]['id']),'tags':_0x466502||[]});return{'id':Number(_0x5a6c2f[_0xb7f2('0xb0')]['id']),'tags':_0x466502||[]};});}})[_0xb7f2('0x2b')](respondWithResult(_0x444a5b,null))[_0xb7f2('0x36')](handleError(_0x444a5b,null));};exports['removeTags']=function(_0x1e16c0,_0x8412c,_0x21de67){return db[_0xb7f2('0x3f')][_0xb7f2('0x6a')]({'where':{'id':_0x1e16c0[_0xb7f2('0xb0')]['id']}})['then'](handleEntityNotFound(_0x8412c,null))['then'](function(_0x668544){if(_0x668544){return _0x668544[_0xb7f2('0xc5')](_0x1e16c0['query'][_0xb7f2('0xb8')]);}})[_0xb7f2('0x2b')](respondWithStatusCode(_0x8412c,null))[_0xb7f2('0x36')](handleError(_0x8412c,null));};exports['download']=function(_0x409b07,_0x106824){var _0x2ad8b3=moment()[_0xb7f2('0xc6')]()[_0xb7f2('0x9c')]();var _0x3ee400=path['join'](config[_0xb7f2('0xc7')],_0xb7f2('0xc8'),_0xb7f2('0xc9'),_0xb7f2('0xca'));var _0x5a64cc=path[_0xb7f2('0xcb')](config['root'],'server',_0xb7f2('0xc9'),'attachments');var _0x5f0402=path['join'](_0x3ee400,_0x2ad8b3);var _0x90269d=util[_0xb7f2('0xbd')](_0xb7f2('0xcc'),_0x409b07[_0xb7f2('0xb0')]['id'],_0x2ad8b3);var _0x57560e=path[_0xb7f2('0xcb')](_0x3ee400,_0x90269d);var _0x14cfc0=[];_0x14cfc0['push']({'model':db[_0xb7f2('0x71')],'as':'User','attributes':['id',_0xb7f2('0x30')],'raw':!![]});_0x14cfc0[_0xb7f2('0x35')]({'model':db['CmContact'],'as':_0xb7f2('0xcd'),'attributes':['id',_0xb7f2('0xce'),_0xb7f2('0xcf')],'raw':!![]});var _0x5d6c43=[{'model':db[_0xb7f2('0xb6')],'as':_0xb7f2('0xd0'),'attributes':['id','body',_0xb7f2('0x7a'),_0xb7f2('0xd1'),'secret',_0xb7f2('0x82')],'include':_0x14cfc0}];_0x5d6c43[_0xb7f2('0x35')]({'model':db[_0xb7f2('0xd2')],'as':'Account','attributes':['id',_0xb7f2('0x2d')]});_0x5d6c43[_0xb7f2('0x35')]({'model':db[_0xb7f2('0x71')],'as':_0xb7f2('0xd3'),'attributes':['id',_0xb7f2('0x30')]});return db['SmsInteraction'][_0xb7f2('0x6a')]({'where':{'id':_0x409b07[_0xb7f2('0xb0')]['id']},'include':_0x5d6c43})['then'](handleEntityNotFound(_0x106824,null))[_0xb7f2('0x2b')](function(_0x4d5851){if(_0x4d5851){var _0x5dae23=_0x4d5851[_0xb7f2('0xd4')]({'plain':!![]});fs[_0xb7f2('0xd5')](_0x5f0402);var _0x496869={'channel':_0xb7f2('0xd6'),'account':_0x5dae23[_0xb7f2('0xd7')]['name'],'agent':_0x5dae23[_0xb7f2('0xd3')]?_0x5dae23[_0xb7f2('0xd3')][_0xb7f2('0x30')]:_0xb7f2('0xd8'),'createdAt':moment(_0x5dae23[_0xb7f2('0x7a')])[_0xb7f2('0xbd')](_0xb7f2('0xd9'))[_0xb7f2('0x9c')](),'closedAt':_0x5dae23[_0xb7f2('0x3a')]?moment(_0x5dae23[_0xb7f2('0xda')])[_0xb7f2('0xbd')](_0xb7f2('0xd9'))[_0xb7f2('0x9c')]():'','disposition':_0x5dae23[_0xb7f2('0xdb')],'messages':_(_0x5dae23[_0xb7f2('0xd0')])[_0xb7f2('0x86')]({'secret':![]})[_0xb7f2('0x2f')](function(_0x20bcfa){return{'date':moment(_0x20bcfa[_0xb7f2('0x7a')])[_0xb7f2('0xbd')](_0xb7f2('0xd9'))[_0xb7f2('0x9c')](),'sender':_0x20bcfa['direction']===_0xb7f2('0xdc')?_0x20bcfa['User']?_0x20bcfa[_0xb7f2('0x71')]['fullname']:'System':_0x20bcfa[_0xb7f2('0xcd')][_0xb7f2('0xce')]+(_0x20bcfa['Contact'][_0xb7f2('0xcf')]?'\x20'+_0x20bcfa['Contact'][_0xb7f2('0xcf')]:''),'body':_0x20bcfa[_0xb7f2('0x74')],'direction':_0x20bcfa['direction']===_0xb7f2('0xdc')?'A':'C','secret':_0x20bcfa[_0xb7f2('0xdd')],'read':_0x20bcfa[_0xb7f2('0x82')]};})[_0xb7f2('0x67')]()};return ejs[_0xb7f2('0xde')](path[_0xb7f2('0xcb')](config['root'],'server',_0xb7f2('0xdf'),_0xb7f2('0xe0')),{'interaction':_0x496869})[_0xb7f2('0x2b')](function(_0x58be37){var _0x125bf1=path[_0xb7f2('0xcb')](_0x5f0402,'transcript-'+_0x5dae23['id']+'-'+_0x2ad8b3+_0xb7f2('0xe1'));var _0x4a04ee={'path':_0x125bf1,'channel':_0xb7f2('0xd6'),'interactionId':_0x5dae23['id']};return pdf[_0xb7f2('0xe2')](_0x58be37,_0x4a04ee);})[_0xb7f2('0x2b')](function(){return new BPromise(function(_0x37e780,_0x2226b9){zipdir(_0x5f0402,{'saveTo':_0x57560e},function(_0x100870,_0x53bcb1){if(_0x100870)return _0x2226b9(_0x100870);return _0x37e780(_0x53bcb1);});})[_0xb7f2('0x2b')](function(){return new BPromise(function(_0x51a23a,_0x5cd9be){rimraf(_0x5f0402,function(_0x13041a){if(_0x13041a)_0x5cd9be(_0x13041a);return _0x51a23a();});});})['then'](function(){return _0x106824[_0xb7f2('0xe3')](_0x57560e,_0x90269d,function(_0x442687){if(_0x442687){console[_0xb7f2('0xe4')](_0xb7f2('0xe5'),_0x442687);}else{fs['unlinkSync'](_0x57560e);}});});});}else{return _0x106824[_0xb7f2('0x1c')](0xc8);}})[_0xb7f2('0x36')](handleError(_0x106824,null));};
\ No newline at end of file