Built motion from commit bab6f49e.|2.6.17
[motion2.git] / server / api / smsInteraction / smsInteraction.controller.js
index 1615c80..2687e04 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa9e0=['params','keys','includeAll','include','options','create','body','describe','SmsMessage','addMessage','ids','omit','getMessages','format','rows','addTags','setTags','spread','Tag','emit','smsInteractionTags:save','removeTags','download','unix','root','server','files','tmp','join','transcript-%d-%s.zip','CmContact','lastName','direction','SmsAccount','Owner','mkdirSync','10px','<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>','Sms','YYYY-MM-DD','Account','N.A.','YYYY-MM-DD\x20HH:mm:ss','closed','disposition','Messages','out','System','secret','renderFile','views','downloadInteraction.html','toFile','transcript-','.pdf','log','unlinkSync','html-pdf','eml-format','rimraf','request-promise','bluebird','mustache','util','path','sox','ejs','lodash','squel','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/license/util','../../mysqldb','redis','defaults','localhost','./smsInteraction.socket','register','status','count','offset','limit','set','Content-Range','update','destroy','then','sendStatus','stack','name','send','Users','fullname','TagIds','Tags','split','forEach','catch','index','map','SmsInteraction','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','select','field','color','from','u.id','u.fullname','ui.SmsInteractionId','user_has_sms_interactions','left_join','users','u.id\x20=\x20ui.UserId','sms_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','a.id\x20=\x20i.SmsAccountId','sms_messages','sms_interaction_has_tags','it.SmsInteractionId\x20=\x20i.id','tools_tags','t.id\x20=\x20it.TagId','expr','search','parseSearch','sqlOperator','conditions','find','unreadMessages','`\x20=\x200','having','Contact','operator','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','value','ContactId','buildExpression','text','start','end','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','$substring','UserId','some','isEmpty','SmsAccountId','i.SmsAccountId\x20IN\x20?','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`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)','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','QueryTypes','SELECT','clone','i.id','contactName','DESC','t.id\x20IN\x20?','resolve','i.SmsAccountId\x20IS\x20NOT\x20NULL','user','role','agent','getSmsAccounts','i.SmsAccountId\x20IS\x20NULL','sequelize','toString','length','merge','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','a.key','Account.key','Account.mandatoryDisposition','i.*','c.firstName','Contact.firstName','Contact.lastName','c.email','Contact.email','c.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.SmsInteractionId\x20IN\x20?','groupBy','SmsInteractionId','push','all','show'];(function(_0x160c73,_0x2ee678){var _0xd9302=function(_0x169454){while(--_0x169454){_0x160c73['push'](_0x160c73['shift']());}};_0xd9302(++_0x2ee678);}(_0xa9e0,0x123));var _0x0a9e=function(_0x187ee1,_0x3fd1e6){_0x187ee1=_0x187ee1-0x0;var _0x388160=_0xa9e0[_0x187ee1];return _0x388160;};'use strict';var pdf=require(_0x0a9e('0x0'));var emlformat=require(_0x0a9e('0x1'));var rimraf=require(_0x0a9e('0x2'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x0a9e('0x3'));var moment=require('moment');var BPromise=require(_0x0a9e('0x4'));var Mustache=require(_0x0a9e('0x5'));var util=require(_0x0a9e('0x6'));var path=require(_0x0a9e('0x7'));var sox=require(_0x0a9e('0x8'));var csv=require('to-csv');var ejs=require(_0x0a9e('0x9'));var fs=require('fs');var _=require(_0x0a9e('0xa'));var squel=require(_0x0a9e('0xb'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x0a9e('0xc'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x0a9e('0xd'));var Redis=require(_0x0a9e('0xe'));var authService=require(_0x0a9e('0xf'));var qs=require(_0x0a9e('0x10'));var as=require(_0x0a9e('0x11'));var hardwareService=require(_0x0a9e('0x12'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x0a9e('0x13'));var db=require(_0x0a9e('0x14'))['db'];config[_0x0a9e('0x15')]=_[_0x0a9e('0x16')](config[_0x0a9e('0x15')],{'host':_0x0a9e('0x17'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x0a9e('0x15')]));require(_0x0a9e('0x18'))[_0x0a9e('0x19')](socket);function respondWithStatusCode(_0x281129,_0x44dcfd){_0x44dcfd=_0x44dcfd||0xcc;return function(_0x4d5611){if(_0x4d5611){return _0x281129['sendStatus'](_0x44dcfd);}return _0x281129[_0x0a9e('0x1a')](_0x44dcfd)['end']();};}function respondWithResult(_0x1985b6,_0x519dfd){_0x519dfd=_0x519dfd||0xc8;return function(_0x16033c){if(_0x16033c){return _0x1985b6[_0x0a9e('0x1a')](_0x519dfd)['json'](_0x16033c);}};}function respondWithFilteredResult(_0x225616,_0x5a0a06){return function(_0x459eb1){if(_0x459eb1){var _0x478723=_0x459eb1[_0x0a9e('0x1b')],_0x106033=_0x5a0a06[_0x0a9e('0x1c')],_0x205fd6=_0x5a0a06[_0x0a9e('0x1c')]+_0x5a0a06[_0x0a9e('0x1d')],_0x31b1ca;if(_0x205fd6>=_0x478723){_0x205fd6=_0x478723;_0x31b1ca=0xc8;}else{_0x31b1ca=0xce;}_0x225616[_0x0a9e('0x1a')](_0x31b1ca);return _0x225616[_0x0a9e('0x1e')](_0x0a9e('0x1f'),_0x106033+'-'+_0x205fd6+'/'+_0x478723)['json'](_0x459eb1);}return null;};}function patchUpdates(_0x2c3407){return function(_0x155cce){try{jsonpatch['apply'](_0x155cce,_0x2c3407,!![]);}catch(_0x20f109){return BPromise['reject'](_0x20f109);}return _0x155cce['save']();};}function saveUpdates(_0x3a02e1,_0x432e56){return function(_0x38e7c4){if(_0x38e7c4){return _0x38e7c4[_0x0a9e('0x20')](_0x3a02e1)['then'](function(_0xfb6e48){return _0xfb6e48;});}return null;};}function removeEntity(_0x2fb0e4,_0x3b45bc){return function(_0x4d00e6){if(_0x4d00e6){return _0x4d00e6[_0x0a9e('0x21')]()[_0x0a9e('0x22')](function(){_0x2fb0e4[_0x0a9e('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x59181e,_0x197ec0){return function(_0x3a8e58){if(!_0x3a8e58){_0x59181e[_0x0a9e('0x23')](0x194);}return _0x3a8e58;};}function handleError(_0x33161b,_0x526cf3){_0x526cf3=_0x526cf3||0x1f4;return function(_0x384319){logger['error'](_0x384319[_0x0a9e('0x24')]);if(_0x384319['name']){delete _0x384319[_0x0a9e('0x25')];}_0x33161b[_0x0a9e('0x1a')](_0x526cf3)[_0x0a9e('0x26')](_0x384319);};}function getInteractionUsers(_0x14433c,_0x140511){return new BPromise(function(_0x1538a4,_0x11c3b6){try{if(_0x140511[_0x14433c['id']]){_0x14433c[_0x0a9e('0x27')]=_['map'](_0x140511[_0x14433c['id']],function(_0x3652a7){return{'id':_0x3652a7['id'],'fullname':_0x3652a7[_0x0a9e('0x28')]};});}}catch(_0x2b1f27){_0x11c3b6(_0x2b1f27);}_0x1538a4(_0x14433c);});}function getInteractionTags(_0x2ec755,_0x5c877d){return new BPromise(function(_0x15b200,_0x40e7a3){try{if(_0x2ec755[_0x0a9e('0x29')]){_0x2ec755[_0x0a9e('0x2a')]=[];_0x2ec755[_0x0a9e('0x29')][_0x0a9e('0x2b')](',')[_0x0a9e('0x2c')](function(_0x2e8759){_0x2ec755[_0x0a9e('0x2a')]['push'](_0x5c877d[_0x2e8759]);});}delete _0x2ec755[_0x0a9e('0x29')];}catch(_0x5d1e0e){_0x40e7a3(_0x5d1e0e);}_0x15b200(_0x2ec755);});}function updateSmsInteraction(_0x2407f9,_0x3ae878,_0x1122db){return new BPromise(function(_0x33bdb7,_0x25ce3a){return getInteractionUsers(_0x2407f9,_0x1122db)['then'](function(_0x66c1d2){return getInteractionTags(_0x66c1d2,_0x3ae878);})[_0x0a9e('0x22')](function(_0x40cb85){_0x33bdb7(_0x40cb85);})[_0x0a9e('0x2d')](function(_0x2b45ea){_0x25ce3a(_0x2b45ea);});});}exports[_0x0a9e('0x2e')]=function(_0x332d35,_0x39e565){var _0x5583a4={},_0x44295a={},_0x5e7238={'count':0x0,'rows':[]};var _0x2cc7a0=_[_0x0a9e('0x2f')](db[_0x0a9e('0x30')][_0x0a9e('0x31')],function(_0x567193){return{'name':_0x567193[_0x0a9e('0x32')],'type':_0x567193[_0x0a9e('0x33')][_0x0a9e('0x34')]};});_0x44295a[_0x0a9e('0x35')]=_['map'](_0x2cc7a0,'name');_0x44295a[_0x0a9e('0x36')]=_['keys'](_0x332d35[_0x0a9e('0x36')]);_0x44295a[_0x0a9e('0x37')]=_[_0x0a9e('0x38')](_0x44295a[_0x0a9e('0x35')],_0x44295a['query']);_0x5583a4[_0x0a9e('0x39')]=_[_0x0a9e('0x38')](_0x44295a[_0x0a9e('0x35')],qs['fields'](_0x332d35[_0x0a9e('0x36')][_0x0a9e('0x3a')]));_0x5583a4[_0x0a9e('0x39')]=_0x5583a4['attributes']['length']?_0x5583a4[_0x0a9e('0x39')]:_0x44295a[_0x0a9e('0x35')];if(!_0x332d35['query'][_0x0a9e('0x3b')](_0x0a9e('0x3c'))){_0x5583a4[_0x0a9e('0x1d')]=qs[_0x0a9e('0x1d')](_0x332d35['query']['limit']);_0x5583a4[_0x0a9e('0x1c')]=qs[_0x0a9e('0x1c')](_0x332d35['query'][_0x0a9e('0x1c')]);}_0x5583a4[_0x0a9e('0x3d')]=qs[_0x0a9e('0x3e')](_0x332d35['query'][_0x0a9e('0x3e')]);_0x5583a4[_0x0a9e('0x3f')]=qs[_0x0a9e('0x37')](_[_0x0a9e('0x40')](_0x332d35[_0x0a9e('0x36')],_0x44295a[_0x0a9e('0x37')]),_0x2cc7a0);var _0x2881b3=[];var _0x45a9b8=squel[_0x0a9e('0x41')]()[_0x0a9e('0x42')]('id')[_0x0a9e('0x42')](_0x0a9e('0x25'))[_0x0a9e('0x42')](_0x0a9e('0x43'))[_0x0a9e('0x44')]('tools_tags');var _0x52628e=squel[_0x0a9e('0x41')]()[_0x0a9e('0x42')](_0x0a9e('0x45'))[_0x0a9e('0x42')](_0x0a9e('0x46'))[_0x0a9e('0x42')](_0x0a9e('0x47'))[_0x0a9e('0x44')](_0x0a9e('0x48'),'ui')[_0x0a9e('0x49')](_0x0a9e('0x4a'),'u',_0x0a9e('0x4b'));var _0x5026aa=squel[_0x0a9e('0x41')]()[_0x0a9e('0x44')](_0x0a9e('0x4c'),'i')[_0x0a9e('0x49')](_0x0a9e('0x4d'),'c',_0x0a9e('0x4e'))[_0x0a9e('0x49')](_0x0a9e('0x4a'),'o','o.id\x20=\x20i.UserId')[_0x0a9e('0x49')]('sms_accounts','a',_0x0a9e('0x4f'))[_0x0a9e('0x49')](_0x0a9e('0x50'),'me','me.SmsInteractionId\x20=\x20i.id')[_0x0a9e('0x49')](_0x0a9e('0x51'),'it',_0x0a9e('0x52'))[_0x0a9e('0x49')](_0x0a9e('0x53'),'t',_0x0a9e('0x54'));var _0x45bf7f=squel['expr']();var _0x13f44d=[];var _0x1bde3c=squel[_0x0a9e('0x55')]();var _0x16f976;if(_0x332d35[_0x0a9e('0x36')][_0x0a9e('0x56')]){_0x16f976=as[_0x0a9e('0x57')](_0x332d35[_0x0a9e('0x36')][_0x0a9e('0x56')]);var _0x58a5c2=_0x16f976[_0x0a9e('0x58')];for(var _0x3fe430=0x0;_0x3fe430<_0x16f976['conditions']['length'];_0x3fe430++){var _0x5ddf84=_0x16f976[_0x0a9e('0x59')][_0x3fe430];var _0x4317e3='i';var _0x37edaa=_[_0x0a9e('0x5a')](_0x2cc7a0,[_0x0a9e('0x25'),_0x5ddf84[_0x0a9e('0x42')]]);if(!_0x37edaa){switch(_0x5ddf84[_0x0a9e('0x42')]){case _0x0a9e('0x5b'):if(_0x5ddf84['value']==0x1){_0x5026aa['having']('`'+_0x5ddf84['field']+_0x0a9e('0x5c'));}else{_0x5026aa[_0x0a9e('0x5d')]('`'+_0x5ddf84[_0x0a9e('0x42')]+'`\x20>\x200');}break;case _0x0a9e('0x5e'):if(_0x5ddf84[_0x0a9e('0x5f')]==='$substring'){if(_0x5ddf84['value'][_0x0a9e('0x2b')]('\x20')['length']>0x1){_0x45bf7f[_0x58a5c2](_0x0a9e('0x60'),qs['getFullTextValue'](_0x5ddf84[_0x0a9e('0x61')]),null);}else{var _0x3c20b2='%'+_0x5ddf84[_0x0a9e('0x61')]+'%';_0x45bf7f[_0x58a5c2]('c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?',_0x3c20b2,_0x3c20b2,_0x3c20b2);}}else{_0x37edaa=_[_0x0a9e('0x5a')](_0x2cc7a0,[_0x0a9e('0x25'),'ContactId']);_0x5ddf84['field']=_0x0a9e('0x62');_0x261adb=as[_0x0a9e('0x63')](_0x4317e3,_0x37edaa['type'],_0x5ddf84);_0x45bf7f[_0x58a5c2](_0x261adb[_0x0a9e('0x64')],_0x261adb['value'][_0x0a9e('0x65')],_0x261adb['value'][_0x0a9e('0x66')]);}break;case'Tag':var _0x5da27d=_0x5ddf84['value'][_0x0a9e('0x2b')](',')['map'](function(_0x2f7092){return Number(_0x2f7092);});_0x5da27d[_0x0a9e('0x2c')](function(_0x3cfd00){_0x1bde3c['or'](_0x0a9e('0x67'),'%,'+_0x3cfd00+',%');});_0x13f44d=_[_0x0a9e('0x68')](_0x13f44d,_0x5da27d);break;case _0x0a9e('0x69'):if(_0x5ddf84[_0x0a9e('0x5f')]===_0x0a9e('0x6a')){_0x45bf7f[_0x58a5c2]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0x5ddf84[_0x0a9e('0x61')]+'%',null);}else{_0x37edaa=_[_0x0a9e('0x5a')](_0x2cc7a0,[_0x0a9e('0x25'),_0x0a9e('0x6b')]);_0x5ddf84[_0x0a9e('0x42')]=_0x0a9e('0x6b');_0x261adb=as['buildExpression'](_0x4317e3,_0x37edaa[_0x0a9e('0x33')],_0x5ddf84);_0x45bf7f[_0x58a5c2](_0x261adb[_0x0a9e('0x64')],_0x261adb['value'][_0x0a9e('0x65')],_0x261adb['value'][_0x0a9e('0x66')]);}break;case'body':_0x261adb=as['buildExpression']('me',null,_0x5ddf84);_0x45bf7f[_0x58a5c2](_0x261adb['text'],_0x261adb[_0x0a9e('0x61')]['start'],_0x261adb[_0x0a9e('0x61')][_0x0a9e('0x66')]);break;}}else{var _0x261adb=as[_0x0a9e('0x63')](_0x4317e3,_0x37edaa[_0x0a9e('0x33')],_0x5ddf84);_0x45bf7f[_0x58a5c2](_0x261adb[_0x0a9e('0x64')],_0x261adb['value'][_0x0a9e('0x65')],_0x261adb['value'][_0x0a9e('0x66')]);}}}else{var _0x1f07cb=_(_0x332d35[_0x0a9e('0x36')])['keys']()[_0x0a9e('0x2f')](function(_0x156f1c){return _[_0x0a9e('0x6c')](_0x2cc7a0,[_0x0a9e('0x25'),_0x156f1c])?_0x156f1c:undefined;})['compact']()[_0x0a9e('0x61')]();if(!_[_0x0a9e('0x6d')](_0x1f07cb)){_0x1f07cb['forEach'](function(_0x797b45){if(_0x797b45===_0x0a9e('0x6e')){_0x5026aa[_0x0a9e('0x3f')](_0x0a9e('0x6f'),[][_0x0a9e('0x70')](_0x332d35['query'][_0x797b45]));}else if(_0x797b45===_0x0a9e('0x71')){var _0x2937e0=JSON[_0x0a9e('0x72')](_0x332d35['query'][_0x797b45])[_0x0a9e('0x73')];var _0x4f1e60=JSON['parse'](_0x332d35[_0x0a9e('0x36')][_0x797b45])[_0x0a9e('0x74')];_0x5026aa[_0x0a9e('0x3f')](_0x0a9e('0x75'),_0x2937e0,_0x4f1e60);}else{if(_0x332d35[_0x0a9e('0x36')][_0x797b45]===_0x0a9e('0x76')){_0x5026aa[_0x0a9e('0x3f')]('i.'+_0x797b45+_0x0a9e('0x77'));}else{_0x5026aa[_0x0a9e('0x3f')]('i.'+_0x797b45+_0x0a9e('0x78'),_0x332d35[_0x0a9e('0x36')][_0x797b45]);}}});}if(_0x332d35[_0x0a9e('0x36')][_0x0a9e('0x79')]){if(_0x332d35[_0x0a9e('0x36')][_0x0a9e('0x79')]==0x1){_0x5026aa[_0x0a9e('0x5d')](_0x0a9e('0x7a'));}else{_0x5026aa[_0x0a9e('0x5d')]('`unreadMessages`\x20>\x200');}}if(_0x332d35[_0x0a9e('0x36')][_0x0a9e('0x7b')]){_0x13f44d=_[_0x0a9e('0x7c')](_0x332d35['query'][_0x0a9e('0x7b')])?_0x332d35[_0x0a9e('0x36')]['tag']:new Array(_0x332d35[_0x0a9e('0x36')][_0x0a9e('0x7b')]);_0x13f44d[_0x0a9e('0x2c')](function(_0x427946){_0x1bde3c['or'](_0x0a9e('0x67'),'%,'+_0x427946+',%');});}if(_0x332d35['query']['filter']){var _0x4a2438=_0x332d35[_0x0a9e('0x36')][_0x0a9e('0x7d')][_0x0a9e('0x7e')]('\x5c','\x5c\x5c')[_0x0a9e('0x7e')](/'/g,'\x27\x27');if(qs[_0x0a9e('0x7f')](_0x4a2438)){_0x45bf7f['or'](_0x0a9e('0x80'),_0x4a2438+'%')['or'](_0x0a9e('0x81'),_0x4a2438+'%');}else{_0x45bf7f['or'](_0x0a9e('0x82'),qs['getFullTextValue'](_0x4a2438))['or'](_0x0a9e('0x83'),_0x4a2438+'%');}}}_0x5026aa[_0x0a9e('0x3f')](_0x45bf7f);_0x5026aa[_0x0a9e('0x84')]('i.id');var _0x2bdc44={'type':db['Sequelize'][_0x0a9e('0x85')][_0x0a9e('0x86')],'raw':!![]};var _0x4c46c1=_0x5026aa[_0x0a9e('0x87')]();_0x4c46c1[_0x0a9e('0x42')](_0x0a9e('0x88'));_0x4c46c1[_0x0a9e('0x42')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x0a9e('0x5b'));if(_0x5583a4[_0x0a9e('0x3d')]){_0x5583a4[_0x0a9e('0x3d')][_0x0a9e('0x2c')](function(_0x5b7fc3){var _0x109ccb=_0x5b7fc3[0x0]===_0x0a9e('0x89')?_0x5b7fc3[0x0]:'i.'+_0x5b7fc3[0x0];_0x5026aa[_0x0a9e('0x3d')](_0x109ccb,_0x5b7fc3[0x1]===_0x0a9e('0x8a')?![]:!![]);});}if(!_['isEmpty'](_0x13f44d)){_0x5026aa[_0x0a9e('0x5d')](_0x1bde3c);_0x4c46c1[_0x0a9e('0x3f')](_0x0a9e('0x8b'),_0x13f44d);}BPromise[_0x0a9e('0x8c')]()[_0x0a9e('0x22')](function(){if(!_0x16f976){if(_0x332d35[_0x0a9e('0x36')][_0x0a9e('0x6e')])return;_0x4c46c1[_0x0a9e('0x3f')](_0x0a9e('0x8d'));_0x5026aa[_0x0a9e('0x3f')](_0x0a9e('0x8d'));return;}if(_0x332d35[_0x0a9e('0x8e')][_0x0a9e('0x8f')]!==_0x0a9e('0x90'))return;return _0x332d35['user'][_0x0a9e('0x91')]({'attributes':['id'],'raw':!![]})[_0x0a9e('0x22')](function(_0xc599b3){if(_['isEmpty'](_0xc599b3)){_0x4c46c1[_0x0a9e('0x3f')](_0x0a9e('0x92'));_0x5026aa[_0x0a9e('0x3f')](_0x0a9e('0x92'));}else{_0x4c46c1['where']('i.SmsAccountId\x20IN\x20?',_[_0x0a9e('0x2f')](_0xc599b3,'id'));_0x5026aa[_0x0a9e('0x3f')]('i.SmsAccountId\x20IN\x20?',_[_0x0a9e('0x2f')](_0xc599b3,'id'));}});})['then'](function(){if(_0x332d35[_0x0a9e('0x8e')][_0x0a9e('0x8f')]==='agent'&&!_0x16f976&&!_0x332d35[_0x0a9e('0x36')][_0x0a9e('0x6e')])return[];return db[_0x0a9e('0x93')][_0x0a9e('0x36')](_0x4c46c1[_0x0a9e('0x94')](),_0x2bdc44);})[_0x0a9e('0x22')](function(_0x444f1f){_0x5e7238['count']=_0x444f1f[_0x0a9e('0x95')];if(_0x5e7238[_0x0a9e('0x1b')]===0x0)return[];return db[_0x0a9e('0x93')][_0x0a9e('0x36')](_0x45a9b8['toString'](),_0x2bdc44)[_0x0a9e('0x22')](function(_0xf0db1){_0x2881b3=_['keyBy'](_0xf0db1,'id');_0x2bdc44=_[_0x0a9e('0x96')](_0x2bdc44,{'model':db['SmsInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x332d35[_0x0a9e('0x36')][_0x0a9e('0x3a')]){_0x5583a4[_0x0a9e('0x39')][_0x0a9e('0x2c')](function(_0x5af453){_0x5026aa['field']('i.'+_0x5af453);});}else{_0x5026aa[_0x0a9e('0x42')](_0x0a9e('0x97'),_0x0a9e('0x5b'));_0x5026aa['field'](_0x0a9e('0x98'),_0x0a9e('0x99'));_0x5026aa['field']('a.mandatoryDisposition',_0x0a9e('0x9a'));_0x5026aa['field']('CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','contactName');_0x5026aa[_0x0a9e('0x42')](_0x0a9e('0x9b'));_0x5026aa[_0x0a9e('0x42')](_0x0a9e('0x9c'),_0x0a9e('0x9d'));_0x5026aa[_0x0a9e('0x42')]('c.lastName',_0x0a9e('0x9e'));_0x5026aa['field'](_0x0a9e('0x9f'),_0x0a9e('0xa0'));_0x5026aa[_0x0a9e('0x42')](_0x0a9e('0xa1'),'Contact.phone');_0x5026aa[_0x0a9e('0x42')](_0x0a9e('0xa2'),_0x0a9e('0xa3'));_0x5026aa['field'](_0x0a9e('0xa4'),_0x0a9e('0xa5'));_0x5026aa[_0x0a9e('0x42')](_0x0a9e('0xa6'),_0x0a9e('0xa7'));_0x5026aa[_0x0a9e('0x42')](_0x0a9e('0xa8'),_0x0a9e('0xa9'));_0x5026aa['field'](_0x0a9e('0xaa'),_0x0a9e('0x29'));}if(_0x5583a4['limit'])_0x5026aa[_0x0a9e('0x1d')](_0x5583a4[_0x0a9e('0x1d')]);if(_0x5583a4[_0x0a9e('0x1c')])_0x5026aa['offset'](_0x5583a4[_0x0a9e('0x1c')]);return db['sequelize'][_0x0a9e('0x36')](_0x5026aa[_0x0a9e('0x94')](),_0x2bdc44);})[_0x0a9e('0x22')](function(_0x1f29bd){_0x52628e[_0x0a9e('0x3f')](_0x0a9e('0xab'),_[_0x0a9e('0x2f')](_0x1f29bd,'id'));return db[_0x0a9e('0x93')]['query'](_0x52628e[_0x0a9e('0x94')](),_0x2bdc44)[_0x0a9e('0x22')](function(_0x17f692){var _0x30ef6e=_[_0x0a9e('0xac')](_0x17f692,_0x0a9e('0xad'));var _0x6803d6=[];_0x1f29bd[_0x0a9e('0x2c')](function(_0x1808ba){_0x6803d6[_0x0a9e('0xae')](updateSmsInteraction(_0x1808ba,_0x2881b3,_0x30ef6e));});return BPromise[_0x0a9e('0xaf')](_0x6803d6);});});})[_0x0a9e('0x22')](function(_0x18273f){_0x5e7238['rows']=_0x18273f;return _0x5e7238;})[_0x0a9e('0x22')](respondWithFilteredResult(_0x39e565,_0x5583a4))[_0x0a9e('0x2d')](handleError(_0x39e565,null));};exports[_0x0a9e('0xb0')]=function(_0x2ed526,_0xb0599a){var _0x5d9ddb={'raw':![],'where':{'id':_0x2ed526[_0x0a9e('0xb1')]['id']}},_0x3afc8c={};_0x3afc8c['model']=_[_0x0a9e('0xb2')](db['SmsInteraction'][_0x0a9e('0x31')]);_0x3afc8c[_0x0a9e('0x36')]=_[_0x0a9e('0xb2')](_0x2ed526[_0x0a9e('0x36')]);_0x3afc8c['filters']=_[_0x0a9e('0x38')](_0x3afc8c['model'],_0x3afc8c[_0x0a9e('0x36')]);_0x5d9ddb[_0x0a9e('0x39')]=_['intersection'](_0x3afc8c[_0x0a9e('0x35')],qs[_0x0a9e('0x3a')](_0x2ed526[_0x0a9e('0x36')]['fields']));_0x5d9ddb['attributes']=_0x5d9ddb[_0x0a9e('0x39')][_0x0a9e('0x95')]?_0x5d9ddb[_0x0a9e('0x39')]:_0x3afc8c[_0x0a9e('0x35')];if(_0x2ed526[_0x0a9e('0x36')][_0x0a9e('0xb3')]){_0x5d9ddb[_0x0a9e('0xb4')]=[{'all':!![]}];}_0x5d9ddb=_[_0x0a9e('0x96')]({},_0x5d9ddb,_0x2ed526[_0x0a9e('0xb5')]);return db['SmsInteraction'][_0x0a9e('0x5a')](_0x5d9ddb)['then'](handleEntityNotFound(_0xb0599a,null))[_0x0a9e('0x22')](respondWithResult(_0xb0599a,null))[_0x0a9e('0x2d')](handleError(_0xb0599a,null));};exports[_0x0a9e('0xb6')]=function(_0x28ce92,_0x1b61d5){return db['SmsInteraction'][_0x0a9e('0xb6')](_0x28ce92[_0x0a9e('0xb7')],{})[_0x0a9e('0x22')](respondWithResult(_0x1b61d5,0xc9))[_0x0a9e('0x2d')](handleError(_0x1b61d5,null));};exports[_0x0a9e('0x20')]=function(_0x5c66ef,_0x4f074c){if(_0x5c66ef[_0x0a9e('0xb7')]['id']){delete _0x5c66ef['body']['id'];}return db[_0x0a9e('0x30')][_0x0a9e('0x5a')]({'where':{'id':_0x5c66ef[_0x0a9e('0xb1')]['id']}})[_0x0a9e('0x22')](handleEntityNotFound(_0x4f074c,null))[_0x0a9e('0x22')](saveUpdates(_0x5c66ef[_0x0a9e('0xb7')],null))['then'](respondWithResult(_0x4f074c,null))['catch'](handleError(_0x4f074c,null));};exports[_0x0a9e('0x21')]=function(_0x5dfbe2,_0x2469d1){return db['SmsInteraction'][_0x0a9e('0x5a')]({'where':{'id':_0x5dfbe2['params']['id']}})['then'](handleEntityNotFound(_0x2469d1,null))[_0x0a9e('0x22')](removeEntity(_0x2469d1,null))[_0x0a9e('0x2d')](handleError(_0x2469d1,null));};exports['describe']=function(_0x170af6,_0x17cb30){return db[_0x0a9e('0x30')][_0x0a9e('0xb8')]()[_0x0a9e('0x22')](respondWithResult(_0x17cb30,null))['catch'](handleError(_0x17cb30,null));};exports['addMessage']=function(_0x16449b,_0x22286c,_0x41c8cd){return db[_0x0a9e('0xb9')][_0x0a9e('0x5a')]({'where':{'id':_0x16449b['params']['id']}})[_0x0a9e('0x22')](handleEntityNotFound(_0x22286c,null))[_0x0a9e('0x22')](function(_0x5416a9){if(_0x5416a9){return _0x5416a9[_0x0a9e('0xba')](_0x16449b[_0x0a9e('0xb7')][_0x0a9e('0xbb')],_[_0x0a9e('0xbc')](_0x16449b[_0x0a9e('0xb7')],[_0x0a9e('0xbb'),'id'])||{});}})[_0x0a9e('0x22')](respondWithResult(_0x22286c,null))[_0x0a9e('0x2d')](handleError(_0x22286c,null));};exports[_0x0a9e('0xbd')]=function(_0x16afb3,_0x4bdebb,_0x1065a7){var _0x301047={'raw':![],'where':{}};var _0x2ada60={};var _0x1c4232={'count':0x0,'rows':[]};return db[_0x0a9e('0x30')]['findOne']({'where':{'id':_0x16afb3['params']['id']}})[_0x0a9e('0x22')](handleEntityNotFound(_0x4bdebb,null))[_0x0a9e('0x22')](function(_0x466bbf){if(_0x466bbf){_0x2ada60[_0x0a9e('0x35')]=_[_0x0a9e('0xb2')](db['SmsMessage'][_0x0a9e('0x31')]);_0x2ada60[_0x0a9e('0x36')]=_[_0x0a9e('0xb2')](_0x16afb3['query']);_0x2ada60[_0x0a9e('0x37')]=_['intersection'](_0x2ada60[_0x0a9e('0x35')],_0x2ada60['query']);_0x301047[_0x0a9e('0x39')]=_[_0x0a9e('0x38')](_0x2ada60[_0x0a9e('0x35')],qs['fields'](_0x16afb3[_0x0a9e('0x36')]['fields']));_0x301047[_0x0a9e('0x39')]=_0x301047[_0x0a9e('0x39')][_0x0a9e('0x95')]?_0x301047[_0x0a9e('0x39')]:_0x2ada60[_0x0a9e('0x35')];if(!_0x16afb3[_0x0a9e('0x36')][_0x0a9e('0x3b')](_0x0a9e('0x3c'))){_0x301047[_0x0a9e('0x1d')]=qs[_0x0a9e('0x1d')](_0x16afb3[_0x0a9e('0x36')][_0x0a9e('0x1d')]);_0x301047[_0x0a9e('0x1c')]=qs[_0x0a9e('0x1c')](_0x16afb3[_0x0a9e('0x36')][_0x0a9e('0x1c')]);}_0x301047['order']=qs['sort'](_0x16afb3[_0x0a9e('0x36')]['sort']);_0x301047[_0x0a9e('0x3f')]=qs[_0x0a9e('0x37')](_['pick'](_0x16afb3[_0x0a9e('0x36')],_0x2ada60[_0x0a9e('0x37')]));_0x301047[_0x0a9e('0x3f')][_0x0a9e('0xad')]=_0x466bbf['id'];if(_0x16afb3['query'][_0x0a9e('0x7d')]){_0x301047[_0x0a9e('0x3f')]=_[_0x0a9e('0x96')](_0x301047[_0x0a9e('0x3f')],{'$or':_['map'](_0x301047[_0x0a9e('0x39')],function(_0x1a0b08){var _0x2b7092={};_0x2b7092[_0x1a0b08]={'$like':'%'+_0x16afb3['query'][_0x0a9e('0x7d')]+'%'};return _0x2b7092;})});}if(_0x16afb3[_0x0a9e('0x36')][_0x0a9e('0x73')]){var _0x54b107=_0x16afb3[_0x0a9e('0x36')][_0x0a9e('0x73')][_0x0a9e('0x2b')](',');var _0x1a7f58={};_0x1a7f58[_0x54b107[0x0]]={'$gte':moment(_0x54b107[0x1])[_0x0a9e('0xbe')]('YYYY-MM-DD\x20HH:mm:ss')};_0x301047[_0x0a9e('0x3f')]=_[_0x0a9e('0x96')](_0x301047['where'],_0x1a7f58);}_0x301047=_[_0x0a9e('0x96')]({},_0x301047,_0x16afb3[_0x0a9e('0xb5')]);return db[_0x0a9e('0xb9')]['count']({'where':_0x301047['where']})['then'](function(_0x1015aa){_0x1c4232[_0x0a9e('0x1b')]=_0x1015aa;if(_0x16afb3['query'][_0x0a9e('0xb3')]){_0x301047[_0x0a9e('0xb4')]=[{'all':!![]}];}return db[_0x0a9e('0xb9')]['findAll'](_0x301047);})[_0x0a9e('0x22')](function(_0x30e037){_0x1c4232[_0x0a9e('0xbf')]=_0x30e037;return _0x1c4232;});}})[_0x0a9e('0x22')](respondWithFilteredResult(_0x4bdebb,_0x301047))[_0x0a9e('0x2d')](handleError(_0x4bdebb,null));};exports[_0x0a9e('0xc0')]=function(_0x40e6e7,_0x328ec5,_0x3b5bda){return db['SmsInteraction'][_0x0a9e('0x5a')]({'where':{'id':_0x40e6e7['params']['id']}})[_0x0a9e('0x22')](handleEntityNotFound(_0x328ec5,null))[_0x0a9e('0x22')](function(_0x2097d8){if(_0x2097d8){return _0x2097d8[_0x0a9e('0xc1')](_0x40e6e7[_0x0a9e('0xb7')][_0x0a9e('0xbb')],_['omit'](_0x40e6e7[_0x0a9e('0xb7')],[_0x0a9e('0xbb'),'id'])||{})[_0x0a9e('0xc2')](function(){return db[_0x0a9e('0xc3')]['findAll']({'attributes':['id',_0x0a9e('0x25'),_0x0a9e('0x43')],'where':{'id':_0x40e6e7[_0x0a9e('0xb7')][_0x0a9e('0xbb')]}});})[_0x0a9e('0x22')](function(_0x2be526){socket[_0x0a9e('0xc4')](_0x0a9e('0xc5'),{'id':Number(_0x40e6e7[_0x0a9e('0xb1')]['id']),'tags':_0x2be526||[]});return{'id':Number(_0x40e6e7[_0x0a9e('0xb1')]['id']),'tags':_0x2be526||[]};});}})['then'](respondWithResult(_0x328ec5,null))[_0x0a9e('0x2d')](handleError(_0x328ec5,null));};exports[_0x0a9e('0xc6')]=function(_0x2ff265,_0x26b826,_0xea8bd1){return db[_0x0a9e('0x30')][_0x0a9e('0x5a')]({'where':{'id':_0x2ff265[_0x0a9e('0xb1')]['id']}})['then'](handleEntityNotFound(_0x26b826,null))[_0x0a9e('0x22')](function(_0xd2391){if(_0xd2391){return _0xd2391[_0x0a9e('0xc6')](_0x2ff265['query'][_0x0a9e('0xbb')]);}})[_0x0a9e('0x22')](respondWithStatusCode(_0x26b826,null))[_0x0a9e('0x2d')](handleError(_0x26b826,null));};exports[_0x0a9e('0xc7')]=function(_0x370b5e,_0x1ba457){var _0x424f1b=moment()[_0x0a9e('0xc8')]()[_0x0a9e('0x94')]();var _0x451010=path['join'](config[_0x0a9e('0xc9')],_0x0a9e('0xca'),_0x0a9e('0xcb'),_0x0a9e('0xcc'));var _0x2b624e=path[_0x0a9e('0xcd')](config['root'],_0x0a9e('0xca'),'files','attachments');var _0x573df6=path[_0x0a9e('0xcd')](_0x451010,_0x424f1b);var _0x3fa3f2=util[_0x0a9e('0xbe')](_0x0a9e('0xce'),_0x370b5e['params']['id'],_0x424f1b);var _0x4156a5=path[_0x0a9e('0xcd')](_0x451010,_0x3fa3f2);var _0x3ddbc7=[];_0x3ddbc7[_0x0a9e('0xae')]({'model':db[_0x0a9e('0x69')],'as':'User','attributes':['id','fullname'],'raw':!![]});_0x3ddbc7[_0x0a9e('0xae')]({'model':db[_0x0a9e('0xcf')],'as':_0x0a9e('0x5e'),'attributes':['id','firstName',_0x0a9e('0xd0')],'raw':!![]});var _0x248a9a=[{'model':db[_0x0a9e('0xb9')],'as':'Messages','attributes':['id',_0x0a9e('0xb7'),_0x0a9e('0x71'),_0x0a9e('0xd1'),'secret',_0x0a9e('0x79')],'include':_0x3ddbc7}];_0x248a9a[_0x0a9e('0xae')]({'model':db[_0x0a9e('0xd2')],'as':'Account','attributes':['id','name']});_0x248a9a['push']({'model':db[_0x0a9e('0x69')],'as':_0x0a9e('0xd3'),'attributes':['id',_0x0a9e('0x28')]});return db[_0x0a9e('0x30')]['find']({'where':{'id':_0x370b5e[_0x0a9e('0xb1')]['id']},'include':_0x248a9a})['then'](handleEntityNotFound(_0x1ba457,null))[_0x0a9e('0x22')](function(_0x2ff2ab){if(_0x2ff2ab){var _0x242f23=_0x2ff2ab['get']({'plain':!![]});fs[_0x0a9e('0xd4')](_0x573df6);var _0x33a26c={'format':'A4','border':_0x0a9e('0xd5'),'header':{'height':'40px','contents':{'first':_0x0a9e('0xd6')}},'footer':{'height':'30px','contents':{'default':util[_0x0a9e('0xbe')]('<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>',util[_0x0a9e('0xbe')]('%s\x20#%d',_0x0a9e('0xd7'),_0x242f23['id']),moment()[_0x0a9e('0xbe')](_0x0a9e('0xd8'))[_0x0a9e('0x94')]())}}};var _0x1e306c={'channel':_0x0a9e('0xd7'),'account':_0x242f23[_0x0a9e('0xd9')]['name'],'agent':_0x242f23[_0x0a9e('0xd3')]?_0x242f23[_0x0a9e('0xd3')]['fullname']:_0x0a9e('0xda'),'createdAt':moment(_0x242f23[_0x0a9e('0x71')])['format'](_0x0a9e('0xdb'))[_0x0a9e('0x94')](),'closedAt':_0x242f23[_0x0a9e('0xdc')]?moment(_0x242f23['closedAt'])[_0x0a9e('0xbe')](_0x0a9e('0xdb'))[_0x0a9e('0x94')]():'','disposition':_0x242f23[_0x0a9e('0xdd')],'messages':_(_0x242f23[_0x0a9e('0xde')])[_0x0a9e('0x7d')]({'secret':![]})[_0x0a9e('0x2f')](function(_0x74d9b8){return{'date':moment(_0x74d9b8[_0x0a9e('0x71')])[_0x0a9e('0xbe')]('YYYY-MM-DD\x20HH:mm:ss')[_0x0a9e('0x94')](),'sender':_0x74d9b8['direction']===_0x0a9e('0xdf')?_0x74d9b8[_0x0a9e('0x69')]?_0x74d9b8[_0x0a9e('0x69')][_0x0a9e('0x28')]:_0x0a9e('0xe0'):_0x74d9b8[_0x0a9e('0x5e')]['firstName']+(_0x74d9b8[_0x0a9e('0x5e')][_0x0a9e('0xd0')]?'\x20'+_0x74d9b8[_0x0a9e('0x5e')]['lastName']:''),'body':_0x74d9b8[_0x0a9e('0xb7')],'direction':_0x74d9b8[_0x0a9e('0xd1')]===_0x0a9e('0xdf')?'A':'C','secret':_0x74d9b8[_0x0a9e('0xe1')],'read':_0x74d9b8[_0x0a9e('0x79')]};})[_0x0a9e('0x61')]()};return ejs[_0x0a9e('0xe2')](path['join'](config[_0x0a9e('0xc9')],_0x0a9e('0xca'),_0x0a9e('0xe3'),_0x0a9e('0xe4')),{'interaction':_0x1e306c})[_0x0a9e('0x22')](function(_0x241404){return new BPromise(function(_0x8120e,_0x5d6a48){pdf['create'](_0x241404,_0x33a26c)[_0x0a9e('0xe5')](path[_0x0a9e('0xcd')](_0x573df6,_0x0a9e('0xe6')+_0x242f23['id']+'-'+_0x424f1b+_0x0a9e('0xe7')),function(_0x40e2da,_0x131da8){if(_0x40e2da)return _0x5d6a48(_0x40e2da);_0x8120e(_0x131da8);});});})[_0x0a9e('0x22')](function(){return new BPromise(function(_0x584854,_0x39ea62){zipdir(_0x573df6,{'saveTo':_0x4156a5},function(_0x1d7fc4,_0x2d8e91){if(_0x1d7fc4)return _0x39ea62(_0x1d7fc4);return _0x584854(_0x2d8e91);});})[_0x0a9e('0x22')](function(){return new BPromise(function(_0x1b1757,_0x3c6082){rimraf(_0x573df6,function(_0x16be7e){if(_0x16be7e)_0x3c6082(_0x16be7e);return _0x1b1757();});});})['then'](function(){return _0x1ba457[_0x0a9e('0xc7')](_0x4156a5,_0x3fa3f2,function(_0x294310){if(_0x294310){console[_0x0a9e('0xe8')]('err',_0x294310);}else{fs[_0x0a9e('0xe9')](_0x4156a5);}});});});}else{return _0x1ba457[_0x0a9e('0x23')](0xc8);}})[_0x0a9e('0x2d')](handleError(_0x1ba457,null));};
\ No newline at end of file
+var _0xaa7c=['getMessages','findOne','nolimit','order','sort','where','pick','SmsInteractionId','filter','merge','$gte','format','YYYY-MM-DD\x20HH:mm:ss','count','includeAll','rows','addTags','setTags','spread','Tag','removeTags','download','join','root','files','tmp','transcript-%d-%s.zip','push','User','Contact','firstName','lastName','Messages','direction','secret','read','Account','Owner','fullname','get','Sms','N.A.','createdAt','toString','closed','disposition','out','System','renderFile','server','views','downloadInteraction.ejs','log','err','unlinkSync','bluebird','util','path','ejs','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../mysqldb','redis','localhost','socket.io-emitter','./smsInteraction.socket','register','status','end','offset','undefined','limit','set','Content-Range','json','update','then','destroy','sendStatus','error','name','send','index','map','SmsInteraction','rawAttributes','type','key','getOptions','findAll','sms','user','catch','show','params','keys','query','filters','intersection','model','attributes','fields','length','include','options','find','create','body','describe','SmsMessage','addMessage','ids','omit'];(function(_0x3401ee,_0x19476c){var _0x383615=function(_0x43ff06){while(--_0x43ff06){_0x3401ee['push'](_0x3401ee['shift']());}};_0x383615(++_0x19476c);}(_0xaa7c,0xad));var _0xcaa7=function(_0x491d3e,_0x3ceff6){_0x491d3e=_0x491d3e-0x0;var _0x399b13=_0xaa7c[_0x491d3e];return _0x399b13;};'use strict';var rimraf=require('rimraf');var zipdir=require('zip-dir');var moment=require('moment');var BPromise=require(_0xcaa7('0x0'));var util=require(_0xcaa7('0x1'));var path=require(_0xcaa7('0x2'));var ejs=require(_0xcaa7('0x3'));var fs=require('fs');var _=require(_0xcaa7('0x4'));var Redis=require(_0xcaa7('0x5'));var interaction=require(_0xcaa7('0x6'));var qs=require(_0xcaa7('0x7'));var pdf=require('../../components/export/pdf');var logger=require(_0xcaa7('0x8'))(_0xcaa7('0x9'));var config=require(_0xcaa7('0xa'));var db=require(_0xcaa7('0xb'))['db'];config[_0xcaa7('0xc')]=_['defaults'](config[_0xcaa7('0xc')],{'host':_0xcaa7('0xd'),'port':0x18eb});var socket=require(_0xcaa7('0xe'))(new Redis(config[_0xcaa7('0xc')]));require(_0xcaa7('0xf'))[_0xcaa7('0x10')](socket);function respondWithStatusCode(_0xca0966,_0x128156){_0x128156=_0x128156||0xcc;return function(_0x92495d){if(_0x92495d){return _0xca0966['sendStatus'](_0x128156);}return _0xca0966[_0xcaa7('0x11')](_0x128156)[_0xcaa7('0x12')]();};}function respondWithResult(_0x496403,_0x527022){_0x527022=_0x527022||0xc8;return function(_0x388edf){if(_0x388edf){return _0x496403[_0xcaa7('0x11')](_0x527022)['json'](_0x388edf);}};}function respondWithFilteredResult(_0x47c039,_0x33b381){return function(_0x1c9a5c){if(_0x1c9a5c){var _0x55360e=typeof _0x33b381[_0xcaa7('0x13')]===_0xcaa7('0x14')&&typeof _0x33b381[_0xcaa7('0x15')]===_0xcaa7('0x14');var _0x3bd708=_0x1c9a5c['count'];var _0x193d3e=_0x55360e?0x0:_0x33b381[_0xcaa7('0x13')];var _0x13a1ce=_0x55360e?_0x1c9a5c['count']:_0x33b381['offset']+_0x33b381[_0xcaa7('0x15')];var _0x58e97f;if(_0x13a1ce>=_0x3bd708){_0x13a1ce=_0x3bd708;_0x58e97f=0xc8;}else{_0x58e97f=0xce;}_0x47c039[_0xcaa7('0x11')](_0x58e97f);return _0x47c039[_0xcaa7('0x16')](_0xcaa7('0x17'),_0x193d3e+'-'+_0x13a1ce+'/'+_0x3bd708)[_0xcaa7('0x18')](_0x1c9a5c);}return null;};}function saveUpdates(_0x10456d){return function(_0x32fe30){if(_0x32fe30){return _0x32fe30[_0xcaa7('0x19')](_0x10456d)[_0xcaa7('0x1a')](function(_0x141973){return _0x141973;});}return null;};}function removeEntity(_0x43469a){return function(_0x3d006c){if(_0x3d006c){return _0x3d006c[_0xcaa7('0x1b')]()['then'](function(){_0x43469a[_0xcaa7('0x11')](0xcc)[_0xcaa7('0x12')]();});}};}function handleEntityNotFound(_0x41efcc){return function(_0x5301f0){if(!_0x5301f0){_0x41efcc[_0xcaa7('0x1c')](0x194);}return _0x5301f0;};}function handleError(_0x43e9fa,_0x7f706c){_0x7f706c=_0x7f706c||0x1f4;return function(_0x55b613){logger[_0xcaa7('0x1d')](_0x55b613['stack']);if(_0x55b613[_0xcaa7('0x1e')]){delete _0x55b613['name'];}_0x43e9fa[_0xcaa7('0x11')](_0x7f706c)[_0xcaa7('0x1f')](_0x55b613);};}exports[_0xcaa7('0x20')]=function(_0x31974b,_0x46cd60){var _0x2046ca={};var _0x400bab=_[_0xcaa7('0x21')](db[_0xcaa7('0x22')][_0xcaa7('0x23')],function(_0x1cafaa){return{'name':_0x1cafaa['fieldName'],'type':_0x1cafaa[_0xcaa7('0x24')][_0xcaa7('0x25')]};});_0x2046ca=qs[_0xcaa7('0x26')](_0x400bab,_0x31974b);return interaction[_0xcaa7('0x27')](_0xcaa7('0x28'),_0x31974b['query'],_0x31974b[_0xcaa7('0x29')],_0x2046ca,_0x400bab)[_0xcaa7('0x1a')](respondWithFilteredResult(_0x46cd60,_0x2046ca))[_0xcaa7('0x2a')](handleError(_0x46cd60,null));};exports[_0xcaa7('0x2b')]=function(_0x307788,_0x276672){var _0x57df63={'raw':![],'where':{'id':_0x307788[_0xcaa7('0x2c')]['id']}},_0x1f05a5={};_0x1f05a5['model']=_[_0xcaa7('0x2d')](db[_0xcaa7('0x22')][_0xcaa7('0x23')]);_0x1f05a5[_0xcaa7('0x2e')]=_['keys'](_0x307788['query']);_0x1f05a5[_0xcaa7('0x2f')]=_[_0xcaa7('0x30')](_0x1f05a5[_0xcaa7('0x31')],_0x1f05a5[_0xcaa7('0x2e')]);_0x57df63[_0xcaa7('0x32')]=_[_0xcaa7('0x30')](_0x1f05a5['model'],qs[_0xcaa7('0x33')](_0x307788[_0xcaa7('0x2e')]['fields']));_0x57df63['attributes']=_0x57df63[_0xcaa7('0x32')][_0xcaa7('0x34')]?_0x57df63['attributes']:_0x1f05a5[_0xcaa7('0x31')];if(_0x307788[_0xcaa7('0x2e')]['includeAll']){_0x57df63[_0xcaa7('0x35')]=[{'all':!![]}];}_0x57df63=_['merge']({},_0x57df63,_0x307788[_0xcaa7('0x36')]);return db[_0xcaa7('0x22')][_0xcaa7('0x37')](_0x57df63)[_0xcaa7('0x1a')](handleEntityNotFound(_0x276672,null))[_0xcaa7('0x1a')](respondWithResult(_0x276672,null))[_0xcaa7('0x2a')](handleError(_0x276672,null));};exports[_0xcaa7('0x38')]=function(_0x49b710,_0x20f2c7){return db[_0xcaa7('0x22')][_0xcaa7('0x38')](_0x49b710['body'],{})[_0xcaa7('0x1a')](respondWithResult(_0x20f2c7,0xc9))[_0xcaa7('0x2a')](handleError(_0x20f2c7,null));};exports[_0xcaa7('0x19')]=function(_0x399d2b,_0x3ae32d){if(_0x399d2b[_0xcaa7('0x39')]['id']){delete _0x399d2b[_0xcaa7('0x39')]['id'];}return db[_0xcaa7('0x22')]['find']({'where':{'id':_0x399d2b['params']['id']}})[_0xcaa7('0x1a')](handleEntityNotFound(_0x3ae32d,null))[_0xcaa7('0x1a')](saveUpdates(_0x399d2b[_0xcaa7('0x39')],null))[_0xcaa7('0x1a')](respondWithResult(_0x3ae32d,null))['catch'](handleError(_0x3ae32d,null));};exports[_0xcaa7('0x1b')]=function(_0xf940bb,_0x487bfb){return db[_0xcaa7('0x22')]['find']({'where':{'id':_0xf940bb[_0xcaa7('0x2c')]['id']}})[_0xcaa7('0x1a')](handleEntityNotFound(_0x487bfb,null))[_0xcaa7('0x1a')](removeEntity(_0x487bfb,null))['catch'](handleError(_0x487bfb,null));};exports[_0xcaa7('0x3a')]=function(_0x47f9e7,_0x4d164f){return db[_0xcaa7('0x22')][_0xcaa7('0x3a')]()['then'](respondWithResult(_0x4d164f,null))[_0xcaa7('0x2a')](handleError(_0x4d164f,null));};exports['addMessage']=function(_0x2bb094,_0x309fbb){return db[_0xcaa7('0x3b')][_0xcaa7('0x37')]({'where':{'id':_0x2bb094[_0xcaa7('0x2c')]['id']}})[_0xcaa7('0x1a')](handleEntityNotFound(_0x309fbb,null))[_0xcaa7('0x1a')](function(_0xd33b7c){if(_0xd33b7c){return _0xd33b7c[_0xcaa7('0x3c')](_0x2bb094[_0xcaa7('0x39')][_0xcaa7('0x3d')],_[_0xcaa7('0x3e')](_0x2bb094['body'],[_0xcaa7('0x3d'),'id'])||{});}})[_0xcaa7('0x1a')](respondWithResult(_0x309fbb,null))['catch'](handleError(_0x309fbb,null));};exports[_0xcaa7('0x3f')]=function(_0x31bf8a,_0x1030b8){var _0x281466={'raw':![],'where':{}};var _0x495c9e={};var _0x2a7951={'count':0x0,'rows':[]};return db['SmsInteraction'][_0xcaa7('0x40')]({'where':{'id':_0x31bf8a[_0xcaa7('0x2c')]['id']}})['then'](handleEntityNotFound(_0x1030b8,null))['then'](function(_0x31473e){if(_0x31473e){_0x495c9e['model']=_[_0xcaa7('0x2d')](db[_0xcaa7('0x3b')]['rawAttributes']);_0x495c9e[_0xcaa7('0x2e')]=_[_0xcaa7('0x2d')](_0x31bf8a[_0xcaa7('0x2e')]);_0x495c9e[_0xcaa7('0x2f')]=_[_0xcaa7('0x30')](_0x495c9e[_0xcaa7('0x31')],_0x495c9e[_0xcaa7('0x2e')]);_0x281466[_0xcaa7('0x32')]=_[_0xcaa7('0x30')](_0x495c9e[_0xcaa7('0x31')],qs[_0xcaa7('0x33')](_0x31bf8a['query'][_0xcaa7('0x33')]));_0x281466[_0xcaa7('0x32')]=_0x281466[_0xcaa7('0x32')]['length']?_0x281466[_0xcaa7('0x32')]:_0x495c9e[_0xcaa7('0x31')];if(!_0x31bf8a[_0xcaa7('0x2e')]['hasOwnProperty'](_0xcaa7('0x41'))){_0x281466['limit']=qs[_0xcaa7('0x15')](_0x31bf8a[_0xcaa7('0x2e')][_0xcaa7('0x15')]);_0x281466[_0xcaa7('0x13')]=qs[_0xcaa7('0x13')](_0x31bf8a[_0xcaa7('0x2e')][_0xcaa7('0x13')]);}_0x281466[_0xcaa7('0x42')]=qs['sort'](_0x31bf8a[_0xcaa7('0x2e')][_0xcaa7('0x43')]);_0x281466[_0xcaa7('0x44')]=qs['filters'](_[_0xcaa7('0x45')](_0x31bf8a[_0xcaa7('0x2e')],_0x495c9e['filters']));_0x281466[_0xcaa7('0x44')][_0xcaa7('0x46')]=_0x31473e['id'];if(_0x31bf8a['query'][_0xcaa7('0x47')]){_0x281466['where']=_[_0xcaa7('0x48')](_0x281466[_0xcaa7('0x44')],{'$or':_[_0xcaa7('0x21')](_0x281466['attributes'],function(_0x3e6cff){var _0xa307ea={};_0xa307ea[_0x3e6cff]={'$like':'%'+_0x31bf8a[_0xcaa7('0x2e')][_0xcaa7('0x47')]+'%'};return _0xa307ea;})});}if(_0x31bf8a[_0xcaa7('0x2e')][_0xcaa7('0x49')]){var _0x31b94b=_0x31bf8a[_0xcaa7('0x2e')][_0xcaa7('0x49')]['split'](',');var _0x160c2f={};_0x160c2f[_0x31b94b[0x0]]={'$gte':moment(_0x31b94b[0x1])[_0xcaa7('0x4a')](_0xcaa7('0x4b'))};_0x281466[_0xcaa7('0x44')]=_[_0xcaa7('0x48')](_0x281466[_0xcaa7('0x44')],_0x160c2f);}_0x281466=_['merge']({},_0x281466,_0x31bf8a[_0xcaa7('0x36')]);return db[_0xcaa7('0x3b')][_0xcaa7('0x4c')]({'where':_0x281466[_0xcaa7('0x44')]})[_0xcaa7('0x1a')](function(_0x22b523){_0x2a7951['count']=_0x22b523;if(_0x31bf8a['query'][_0xcaa7('0x4d')]){_0x281466[_0xcaa7('0x35')]=[{'all':!![]}];}return db['SmsMessage'][_0xcaa7('0x27')](_0x281466);})[_0xcaa7('0x1a')](function(_0x3a820e){_0x2a7951[_0xcaa7('0x4e')]=_0x3a820e;return _0x2a7951;});}})[_0xcaa7('0x1a')](respondWithFilteredResult(_0x1030b8,_0x281466))[_0xcaa7('0x2a')](handleError(_0x1030b8,null));};exports[_0xcaa7('0x4f')]=function(_0x7fe2b7,_0x112a1a){return db['SmsInteraction'][_0xcaa7('0x37')]({'where':{'id':_0x7fe2b7[_0xcaa7('0x2c')]['id']}})['then'](handleEntityNotFound(_0x112a1a,null))['then'](function(_0x16ec1b){if(_0x16ec1b){return _0x16ec1b[_0xcaa7('0x50')](_0x7fe2b7[_0xcaa7('0x39')][_0xcaa7('0x3d')],_[_0xcaa7('0x3e')](_0x7fe2b7[_0xcaa7('0x39')],[_0xcaa7('0x3d'),'id'])||{})[_0xcaa7('0x51')](function(){return db[_0xcaa7('0x52')][_0xcaa7('0x27')]({'attributes':['id',_0xcaa7('0x1e'),'color'],'where':{'id':_0x7fe2b7[_0xcaa7('0x39')][_0xcaa7('0x3d')]}});})[_0xcaa7('0x1a')](function(_0x385f1e){socket['emit']('smsInteractionTags:save',{'id':Number(_0x7fe2b7[_0xcaa7('0x2c')]['id']),'tags':_0x385f1e||[]});return{'id':Number(_0x7fe2b7['params']['id']),'tags':_0x385f1e||[]};});}})[_0xcaa7('0x1a')](respondWithResult(_0x112a1a,null))[_0xcaa7('0x2a')](handleError(_0x112a1a,null));};exports['removeTags']=function(_0x502853,_0x577c87){return db[_0xcaa7('0x22')][_0xcaa7('0x37')]({'where':{'id':_0x502853[_0xcaa7('0x2c')]['id']}})[_0xcaa7('0x1a')](handleEntityNotFound(_0x577c87,null))[_0xcaa7('0x1a')](function(_0x518ec3){if(_0x518ec3){return _0x518ec3[_0xcaa7('0x53')](_0x502853[_0xcaa7('0x2e')][_0xcaa7('0x3d')]);}})[_0xcaa7('0x1a')](respondWithStatusCode(_0x577c87,null))[_0xcaa7('0x2a')](handleError(_0x577c87,null));};exports[_0xcaa7('0x54')]=function(_0x15088e,_0x8f8e21){var _0x67d302=moment()['unix']()['toString']();var _0x14c149=path[_0xcaa7('0x55')](config[_0xcaa7('0x56')],'server',_0xcaa7('0x57'),_0xcaa7('0x58'));var _0xc3f944=path['join'](_0x14c149,_0x67d302);var _0x340a26=util['format'](_0xcaa7('0x59'),_0x15088e['params']['id'],_0x67d302);var _0x3f41ed=path[_0xcaa7('0x55')](_0x14c149,_0x340a26);var _0x361e04=[];_0x361e04[_0xcaa7('0x5a')]({'model':db['User'],'as':_0xcaa7('0x5b'),'attributes':['id','fullname'],'raw':!![]});_0x361e04[_0xcaa7('0x5a')]({'model':db['CmContact'],'as':_0xcaa7('0x5c'),'attributes':['id',_0xcaa7('0x5d'),_0xcaa7('0x5e')],'raw':!![]});var _0x2e1cdb=[{'model':db[_0xcaa7('0x3b')],'as':_0xcaa7('0x5f'),'attributes':['id',_0xcaa7('0x39'),'createdAt',_0xcaa7('0x60'),_0xcaa7('0x61'),_0xcaa7('0x62')],'include':_0x361e04}];_0x2e1cdb[_0xcaa7('0x5a')]({'model':db['SmsAccount'],'as':_0xcaa7('0x63'),'attributes':['id','name']});_0x2e1cdb['push']({'model':db['User'],'as':_0xcaa7('0x64'),'attributes':['id',_0xcaa7('0x65')]});return db['SmsInteraction'][_0xcaa7('0x37')]({'where':{'id':_0x15088e[_0xcaa7('0x2c')]['id']},'include':_0x2e1cdb})['then'](handleEntityNotFound(_0x8f8e21,null))[_0xcaa7('0x1a')](function(_0x1fe0e2){if(_0x1fe0e2){var _0x1362ed=_0x1fe0e2[_0xcaa7('0x66')]({'plain':!![]});fs['mkdirSync'](_0xc3f944);var _0x518db8={'channel':_0xcaa7('0x67'),'account':_0x1362ed[_0xcaa7('0x63')][_0xcaa7('0x1e')],'agent':_0x1362ed['Owner']?_0x1362ed[_0xcaa7('0x64')]['fullname']:_0xcaa7('0x68'),'createdAt':moment(_0x1362ed[_0xcaa7('0x69')])[_0xcaa7('0x4a')](_0xcaa7('0x4b'))[_0xcaa7('0x6a')](),'closedAt':_0x1362ed[_0xcaa7('0x6b')]?moment(_0x1362ed['closedAt'])[_0xcaa7('0x4a')]('YYYY-MM-DD\x20HH:mm:ss')[_0xcaa7('0x6a')]():'','disposition':_0x1362ed[_0xcaa7('0x6c')],'messages':_(_0x1362ed[_0xcaa7('0x5f')])[_0xcaa7('0x47')]({'secret':![]})[_0xcaa7('0x21')](function(_0x5ed4af){return{'date':moment(_0x5ed4af[_0xcaa7('0x69')])[_0xcaa7('0x4a')](_0xcaa7('0x4b'))[_0xcaa7('0x6a')](),'sender':_0x5ed4af[_0xcaa7('0x60')]===_0xcaa7('0x6d')?_0x5ed4af[_0xcaa7('0x5b')]?_0x5ed4af['User'][_0xcaa7('0x65')]:_0xcaa7('0x6e'):_0x5ed4af[_0xcaa7('0x5c')][_0xcaa7('0x5d')]+(_0x5ed4af[_0xcaa7('0x5c')][_0xcaa7('0x5e')]?'\x20'+_0x5ed4af[_0xcaa7('0x5c')][_0xcaa7('0x5e')]:''),'body':_0x5ed4af['body'],'direction':_0x5ed4af['direction']==='out'?'A':'C','secret':_0x5ed4af[_0xcaa7('0x61')],'read':_0x5ed4af[_0xcaa7('0x62')]};})['value']()};return ejs[_0xcaa7('0x6f')](path[_0xcaa7('0x55')](config[_0xcaa7('0x56')],_0xcaa7('0x70'),_0xcaa7('0x71'),_0xcaa7('0x72')),{'interaction':_0x518db8})['then'](function(_0x409cfa){var _0x583336=path[_0xcaa7('0x55')](_0xc3f944,'transcript-'+_0x1362ed['id']+'-'+_0x67d302+'.pdf');var _0x13fb22={'path':_0x583336,'channel':_0xcaa7('0x67'),'interactionId':_0x1362ed['id']};return pdf['createPdfFromHTML'](_0x409cfa,_0x13fb22);})[_0xcaa7('0x1a')](function(){return new BPromise(function(_0x2e8495,_0xb7c8d0){zipdir(_0xc3f944,{'saveTo':_0x3f41ed},function(_0x5916f3,_0x30b821){if(_0x5916f3)return _0xb7c8d0(_0x5916f3);return _0x2e8495(_0x30b821);});})[_0xcaa7('0x1a')](function(){return new BPromise(function(_0x255aec,_0x2e84ed){rimraf(_0xc3f944,function(_0x3b0a7f){if(_0x3b0a7f)_0x2e84ed(_0x3b0a7f);return _0x255aec();});});})[_0xcaa7('0x1a')](function(){return _0x8f8e21[_0xcaa7('0x54')](_0x3f41ed,_0x340a26,function(_0x57617a){if(_0x57617a){console[_0xcaa7('0x73')](_0xcaa7('0x74'),_0x57617a);}else{fs[_0xcaa7('0x75')](_0x3f41ed);}});});});}else{return _0x8f8e21[_0xcaa7('0x1c')](0xc8);}})[_0xcaa7('0x2a')](handleError(_0x8f8e21,null));};
\ No newline at end of file