Built motion from commit b5996064.|2.6.21
[motion2.git] / server / api / smsInteraction / smsInteraction.controller.js
index 35d2bc0..bdf6b89 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf084=['tools_tags','u.id','u.fullname','ui.SmsInteractionId','user_has_sms_interactions','left_join','u.id\x20=\x20ui.UserId','sms_interactions','sms_accounts','sms_messages','sms_interaction_has_tags','it.SmsInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','search','parseSearch','sqlOperator','conditions','find','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','operator','$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','start','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','body','some','compact','isEmpty','SmsAccountId','i.SmsAccountId\x20IN\x20?','concat','createdAt','$gte','parse','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','i.phone\x20LIKE\x20?','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','Sequelize','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','order','contactName','DESC','t.id\x20IN\x20?','i.SmsAccountId\x20IS\x20NOT\x20NULL','user','agent','getSmsAccounts','i.SmsAccountId\x20IS\x20NULL','sequelize','toString','merge','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','c.firstName','Contact.firstName','c.lastName','Contact.lastName','c.email','Contact.email','Contact.phone','c.mobile','Contact.mobile','c.fax','o.fullname','Owner.fullname','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.SmsInteractionId\x20IN\x20?','groupBy','SmsInteractionId','all','rows','params','includeAll','include','options','create','describe','addMessage','ids','omit','getMessages','findOne','YYYY-MM-DD\x20HH:mm:ss','SmsMessage','findAll','setTags','spread','Tag','color','emit','smsInteractionTags:save','removeTags','unix','join','server','files','root','attachments','transcript-%d-%s.zip','CmContact','firstName','lastName','Messages','direction','secret','SmsAccount','Account','Owner','mkdirSync','Sms','N.A.','format','closed','closedAt','System','out','renderFile','views','downloadInteraction.html','transcript-','createPdfFromHTML','download','log','err','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','moment','mustache','util','path','sox','fs-extra','lodash','squel','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','defaults','redis','localhost','socket.io-emitter','register','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','save','update','destroy','error','stack','name','Users','map','fullname','TagIds','split','forEach','Tags','push','then','catch','index','SmsInteraction','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','filters','pick','select','field','from'];(function(_0xa41fdc,_0x10b016){var _0x1cfe5b=function(_0x143c75){while(--_0x143c75){_0xa41fdc['push'](_0xa41fdc['shift']());}};_0x1cfe5b(++_0x10b016);}(_0xf084,0x183));var _0x4f08=function(_0x3ec7c7,_0x3d51b9){_0x3ec7c7=_0x3ec7c7-0x0;var _0x21bd81=_0xf084[_0x3ec7c7];return _0x21bd81;};'use strict';var emlformat=require(_0x4f08('0x0'));var rimraf=require(_0x4f08('0x1'));var zipdir=require(_0x4f08('0x2'));var jsonpatch=require(_0x4f08('0x3'));var rp=require('request-promise');var moment=require(_0x4f08('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x4f08('0x5'));var util=require(_0x4f08('0x6'));var path=require(_0x4f08('0x7'));var sox=require(_0x4f08('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x4f08('0x9'));var _=require(_0x4f08('0xa'));var squel=require(_0x4f08('0xb'));var crypto=require('crypto');var jsforce=require(_0x4f08('0xc'));var deskjs=require(_0x4f08('0xd'));var toCsv=require(_0x4f08('0xe'));var querystring=require(_0x4f08('0xf'));var Papa=require(_0x4f08('0x10'));var Redis=require('ioredis');var authService=require(_0x4f08('0x11'));var qs=require(_0x4f08('0x12'));var as=require(_0x4f08('0x13'));var pdf=require('../../components/export/pdf');var hardwareService=require(_0x4f08('0x14'));var logger=require(_0x4f08('0x15'))(_0x4f08('0x16'));var utils=require(_0x4f08('0x17'));var config=require(_0x4f08('0x18'));var licenseUtil=require(_0x4f08('0x19'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x4f08('0x1a')](config[_0x4f08('0x1b')],{'host':_0x4f08('0x1c'),'port':0x18eb});var socket=require(_0x4f08('0x1d'))(new Redis(config['redis']));require('./smsInteraction.socket')[_0x4f08('0x1e')](socket);function respondWithStatusCode(_0x92fb83,_0x4dfaf5){_0x4dfaf5=_0x4dfaf5||0xcc;return function(_0x43c081){if(_0x43c081){return _0x92fb83[_0x4f08('0x1f')](_0x4dfaf5);}return _0x92fb83[_0x4f08('0x20')](_0x4dfaf5)[_0x4f08('0x21')]();};}function respondWithResult(_0x16709f,_0x3fbcd8){_0x3fbcd8=_0x3fbcd8||0xc8;return function(_0x23d2b7){if(_0x23d2b7){return _0x16709f[_0x4f08('0x20')](_0x3fbcd8)[_0x4f08('0x22')](_0x23d2b7);}};}function respondWithFilteredResult(_0x33cf07,_0x1196b1){return function(_0x2415d6){if(_0x2415d6){var _0x294723=typeof _0x1196b1[_0x4f08('0x23')]===_0x4f08('0x24')&&typeof _0x1196b1[_0x4f08('0x25')]===_0x4f08('0x24');var _0x1331c5=_0x2415d6['count'];var _0x80b4b9=_0x294723?0x0:_0x1196b1['offset'];var _0x59f386=_0x294723?_0x2415d6[_0x4f08('0x26')]:_0x1196b1[_0x4f08('0x23')]+_0x1196b1[_0x4f08('0x25')];var _0xd74128;if(_0x59f386>=_0x1331c5){_0x59f386=_0x1331c5;_0xd74128=0xc8;}else{_0xd74128=0xce;}_0x33cf07['status'](_0xd74128);return _0x33cf07[_0x4f08('0x27')](_0x4f08('0x28'),_0x80b4b9+'-'+_0x59f386+'/'+_0x1331c5)['json'](_0x2415d6);}return null;};}function patchUpdates(_0x4396cb){return function(_0x23d736){try{jsonpatch['apply'](_0x23d736,_0x4396cb,!![]);}catch(_0x4efc8d){return BPromise['reject'](_0x4efc8d);}return _0x23d736[_0x4f08('0x29')]();};}function saveUpdates(_0x40776a,_0x519d9a){return function(_0x43f873){if(_0x43f873){return _0x43f873[_0x4f08('0x2a')](_0x40776a)['then'](function(_0x30e5f7){return _0x30e5f7;});}return null;};}function removeEntity(_0x5e8537,_0x3de228){return function(_0x24aacd){if(_0x24aacd){return _0x24aacd[_0x4f08('0x2b')]()['then'](function(){_0x5e8537[_0x4f08('0x20')](0xcc)['end']();});}};}function handleEntityNotFound(_0x19af61,_0x5162ac){return function(_0x14bc24){if(!_0x14bc24){_0x19af61[_0x4f08('0x1f')](0x194);}return _0x14bc24;};}function handleError(_0x2858c1,_0x5a5069){_0x5a5069=_0x5a5069||0x1f4;return function(_0x202909){logger[_0x4f08('0x2c')](_0x202909[_0x4f08('0x2d')]);if(_0x202909[_0x4f08('0x2e')]){delete _0x202909[_0x4f08('0x2e')];}_0x2858c1[_0x4f08('0x20')](_0x5a5069)['send'](_0x202909);};}function getInteractionUsers(_0x3917db,_0xf7d606){return new BPromise(function(_0x252050,_0x425f4e){try{if(_0xf7d606[_0x3917db['id']]){_0x3917db[_0x4f08('0x2f')]=_[_0x4f08('0x30')](_0xf7d606[_0x3917db['id']],function(_0x170d77){return{'id':_0x170d77['id'],'fullname':_0x170d77[_0x4f08('0x31')]};});}}catch(_0x1ccc82){_0x425f4e(_0x1ccc82);}_0x252050(_0x3917db);});}function getInteractionTags(_0x1f45ab,_0x403b2b){return new BPromise(function(_0x5a1c88,_0x30d874){try{if(_0x1f45ab[_0x4f08('0x32')]){_0x1f45ab['Tags']=[];_0x1f45ab[_0x4f08('0x32')][_0x4f08('0x33')](',')[_0x4f08('0x34')](function(_0x2d1da8){_0x1f45ab[_0x4f08('0x35')][_0x4f08('0x36')](_0x403b2b[_0x2d1da8]);});}delete _0x1f45ab['TagIds'];}catch(_0x397220){_0x30d874(_0x397220);}_0x5a1c88(_0x1f45ab);});}function updateSmsInteraction(_0x171e5e,_0x2cc22a,_0x575954){return new BPromise(function(_0x1d1d6b,_0x3d7b16){return getInteractionUsers(_0x171e5e,_0x575954)[_0x4f08('0x37')](function(_0x2b8e5b){return getInteractionTags(_0x2b8e5b,_0x2cc22a);})[_0x4f08('0x37')](function(_0x589ac3){_0x1d1d6b(_0x589ac3);})[_0x4f08('0x38')](function(_0x669ef9){_0x3d7b16(_0x669ef9);});});}exports[_0x4f08('0x39')]=function(_0x556875,_0x442e64){var _0x2f2240={},_0x22de94={},_0x5f2d14={'count':0x0,'rows':[]};var _0x23dc90=_[_0x4f08('0x30')](db[_0x4f08('0x3a')][_0x4f08('0x3b')],function(_0x308366){return{'name':_0x308366[_0x4f08('0x3c')],'type':_0x308366[_0x4f08('0x3d')][_0x4f08('0x3e')]};});_0x22de94[_0x4f08('0x3f')]=_[_0x4f08('0x30')](_0x23dc90,_0x4f08('0x2e'));_0x22de94[_0x4f08('0x40')]=_[_0x4f08('0x41')](_0x556875['query']);_0x22de94['filters']=_[_0x4f08('0x42')](_0x22de94['model'],_0x22de94[_0x4f08('0x40')]);_0x2f2240[_0x4f08('0x43')]=_[_0x4f08('0x42')](_0x22de94['model'],qs[_0x4f08('0x44')](_0x556875[_0x4f08('0x40')]['fields']));_0x2f2240[_0x4f08('0x43')]=_0x2f2240[_0x4f08('0x43')][_0x4f08('0x45')]?_0x2f2240[_0x4f08('0x43')]:_0x22de94[_0x4f08('0x3f')];if(!_0x556875[_0x4f08('0x40')][_0x4f08('0x46')](_0x4f08('0x47'))){_0x2f2240['limit']=qs[_0x4f08('0x25')](_0x556875[_0x4f08('0x40')]['limit']);_0x2f2240[_0x4f08('0x23')]=qs[_0x4f08('0x23')](_0x556875[_0x4f08('0x40')][_0x4f08('0x23')]);}_0x2f2240['order']=qs[_0x4f08('0x48')](_0x556875['query'][_0x4f08('0x48')]);_0x2f2240[_0x4f08('0x49')]=qs[_0x4f08('0x4a')](_[_0x4f08('0x4b')](_0x556875[_0x4f08('0x40')],_0x22de94[_0x4f08('0x4a')]),_0x23dc90);var _0x56363e=[];var _0xaacc97=squel[_0x4f08('0x4c')]()[_0x4f08('0x4d')]('id')[_0x4f08('0x4d')](_0x4f08('0x2e'))[_0x4f08('0x4d')]('color')[_0x4f08('0x4e')](_0x4f08('0x4f'));var _0x46fd92=squel[_0x4f08('0x4c')]()[_0x4f08('0x4d')](_0x4f08('0x50'))[_0x4f08('0x4d')](_0x4f08('0x51'))['field'](_0x4f08('0x52'))[_0x4f08('0x4e')](_0x4f08('0x53'),'ui')[_0x4f08('0x54')]('users','u',_0x4f08('0x55'));var _0x533c27=squel[_0x4f08('0x4c')]()[_0x4f08('0x4e')](_0x4f08('0x56'),'i')[_0x4f08('0x54')]('cm_contacts','c','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL')[_0x4f08('0x54')]('users','o','o.id\x20=\x20i.UserId')['left_join'](_0x4f08('0x57'),'a','a.id\x20=\x20i.SmsAccountId')[_0x4f08('0x54')](_0x4f08('0x58'),'me','me.SmsInteractionId\x20=\x20i.id')[_0x4f08('0x54')](_0x4f08('0x59'),'it',_0x4f08('0x5a'))[_0x4f08('0x54')](_0x4f08('0x4f'),'t',_0x4f08('0x5b'));var _0x27a48e=squel['expr']();var _0x22408f=[];var _0x2c6305=squel['expr']();var _0x1e76fd;if(_0x556875['query'][_0x4f08('0x5c')]){_0x1e76fd=as[_0x4f08('0x5d')](_0x556875[_0x4f08('0x40')][_0x4f08('0x5c')]);var _0x1e0e16=_0x1e76fd[_0x4f08('0x5e')];for(var _0x45b15d=0x0;_0x45b15d<_0x1e76fd[_0x4f08('0x5f')][_0x4f08('0x45')];_0x45b15d++){var _0x2699a8=_0x1e76fd['conditions'][_0x45b15d];var _0x172076='i';var _0xd2681=_[_0x4f08('0x60')](_0x23dc90,['name',_0x2699a8['field']]);if(!_0xd2681){switch(_0x2699a8['field']){case _0x4f08('0x61'):if(_0x2699a8[_0x4f08('0x62')]==0x1){_0x533c27[_0x4f08('0x63')]('`'+_0x2699a8[_0x4f08('0x4d')]+_0x4f08('0x64'));}else{_0x533c27['having']('`'+_0x2699a8[_0x4f08('0x4d')]+_0x4f08('0x65'));}break;case _0x4f08('0x66'):if(_0x2699a8[_0x4f08('0x67')]===_0x4f08('0x68')){if(_0x2699a8[_0x4f08('0x62')]['split']('\x20')[_0x4f08('0x45')]>0x1){_0x27a48e[_0x1e0e16](_0x4f08('0x69'),qs[_0x4f08('0x6a')](_0x2699a8['value']),null);}else{var _0x3d170c='%'+_0x2699a8['value']+'%';_0x27a48e[_0x1e0e16](_0x4f08('0x6b'),_0x3d170c,_0x3d170c,_0x3d170c);}}else{_0xd2681=_['find'](_0x23dc90,['name','ContactId']);_0x2699a8[_0x4f08('0x4d')]=_0x4f08('0x6c');_0x1e0500=as[_0x4f08('0x6d')](_0x172076,_0xd2681[_0x4f08('0x3d')],_0x2699a8);_0x27a48e[_0x1e0e16](_0x1e0500[_0x4f08('0x6e')],_0x1e0500['value'][_0x4f08('0x6f')],_0x1e0500['value'][_0x4f08('0x21')]);}break;case'Tag':var _0x4c82d3=_0x2699a8[_0x4f08('0x62')][_0x4f08('0x33')](',')[_0x4f08('0x30')](function(_0x12585d){return Number(_0x12585d);});_0x4c82d3[_0x4f08('0x34')](function(_0x75a891){_0x2c6305['or'](_0x4f08('0x70'),'%,'+_0x75a891+',%');});_0x22408f=_[_0x4f08('0x71')](_0x22408f,_0x4c82d3);break;case _0x4f08('0x72'):if(_0x2699a8[_0x4f08('0x67')]==='$substring'){_0x27a48e[_0x1e0e16](_0x4f08('0x73'),'%'+_0x2699a8['value']+'%',null);}else{_0xd2681=_[_0x4f08('0x60')](_0x23dc90,['name',_0x4f08('0x74')]);_0x2699a8[_0x4f08('0x4d')]='UserId';_0x1e0500=as['buildExpression'](_0x172076,_0xd2681[_0x4f08('0x3d')],_0x2699a8);_0x27a48e[_0x1e0e16](_0x1e0500[_0x4f08('0x6e')],_0x1e0500['value']['start'],_0x1e0500[_0x4f08('0x62')][_0x4f08('0x21')]);}break;case _0x4f08('0x75'):_0x1e0500=as[_0x4f08('0x6d')]('me',null,_0x2699a8);_0x27a48e[_0x1e0e16](_0x1e0500[_0x4f08('0x6e')],_0x1e0500[_0x4f08('0x62')][_0x4f08('0x6f')],_0x1e0500[_0x4f08('0x62')]['end']);break;}}else{var _0x1e0500=as[_0x4f08('0x6d')](_0x172076,_0xd2681[_0x4f08('0x3d')],_0x2699a8);_0x27a48e[_0x1e0e16](_0x1e0500['text'],_0x1e0500[_0x4f08('0x62')][_0x4f08('0x6f')],_0x1e0500[_0x4f08('0x62')][_0x4f08('0x21')]);}}}else{var _0x530d03=_(_0x556875[_0x4f08('0x40')])[_0x4f08('0x41')]()['map'](function(_0x434a16){return _[_0x4f08('0x76')](_0x23dc90,[_0x4f08('0x2e'),_0x434a16])?_0x434a16:undefined;})[_0x4f08('0x77')]()['value']();if(!_[_0x4f08('0x78')](_0x530d03)){_0x530d03[_0x4f08('0x34')](function(_0x4174a3){if(_0x4174a3===_0x4f08('0x79')){_0x533c27[_0x4f08('0x49')](_0x4f08('0x7a'),[][_0x4f08('0x7b')](_0x556875[_0x4f08('0x40')][_0x4174a3]));}else if(_0x4174a3===_0x4f08('0x7c')){var _0x2aacd1=JSON['parse'](_0x556875[_0x4f08('0x40')][_0x4174a3])[_0x4f08('0x7d')];var _0x4a11b2=JSON[_0x4f08('0x7e')](_0x556875[_0x4f08('0x40')][_0x4174a3])['$lte'];_0x533c27[_0x4f08('0x49')](_0x4f08('0x7f'),_0x2aacd1,_0x4a11b2);}else{if(_0x556875['query'][_0x4174a3]==='null'){_0x533c27[_0x4f08('0x49')]('i.'+_0x4174a3+_0x4f08('0x80'));}else{_0x533c27[_0x4f08('0x49')]('i.'+_0x4174a3+_0x4f08('0x81'),_0x556875[_0x4f08('0x40')][_0x4174a3]);}}});}if(_0x556875['query'][_0x4f08('0x82')]){if(_0x556875['query'][_0x4f08('0x82')]==0x1){_0x533c27[_0x4f08('0x63')](_0x4f08('0x83'));}else{_0x533c27[_0x4f08('0x63')](_0x4f08('0x84'));}}if(_0x556875[_0x4f08('0x40')][_0x4f08('0x85')]){_0x22408f=_[_0x4f08('0x86')](_0x556875[_0x4f08('0x40')][_0x4f08('0x85')])?_0x556875[_0x4f08('0x40')][_0x4f08('0x85')]:new Array(_0x556875[_0x4f08('0x40')][_0x4f08('0x85')]);_0x22408f[_0x4f08('0x34')](function(_0x82d066){_0x2c6305['or'](_0x4f08('0x70'),'%,'+_0x82d066+',%');});}if(_0x556875[_0x4f08('0x40')]['filter']){var _0x36e828=_0x556875[_0x4f08('0x40')][_0x4f08('0x87')][_0x4f08('0x88')]('\x5c','\x5c\x5c')[_0x4f08('0x88')](/'/g,'\x27\x27');if(qs['isNumeric'](_0x36e828)){_0x27a48e['or']('i.id\x20LIKE\x20?',_0x36e828+'%')['or'](_0x4f08('0x89'),_0x36e828+'%');}else{_0x27a48e['or']('MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs['getFullTextValue'](_0x36e828))['or'](_0x4f08('0x8a'),_0x36e828+'%');}}}_0x533c27[_0x4f08('0x49')](_0x27a48e);_0x533c27[_0x4f08('0x8b')]('i.id');var _0x567b8c={'type':db[_0x4f08('0x8c')][_0x4f08('0x8d')][_0x4f08('0x8e')],'raw':!![]};var _0x5bd94f=_0x533c27[_0x4f08('0x8f')]();_0x5bd94f[_0x4f08('0x4d')]('i.id');_0x5bd94f['field'](_0x4f08('0x90'),_0x4f08('0x61'));if(_0x2f2240['order']){_0x2f2240[_0x4f08('0x91')][_0x4f08('0x34')](function(_0x1f5d31){var _0x37e78c=_0x1f5d31[0x0]===_0x4f08('0x92')?_0x1f5d31[0x0]:'i.'+_0x1f5d31[0x0];_0x533c27['order'](_0x37e78c,_0x1f5d31[0x1]===_0x4f08('0x93')?![]:!![]);});}if(!_[_0x4f08('0x78')](_0x22408f)){_0x533c27[_0x4f08('0x63')](_0x2c6305);_0x5bd94f[_0x4f08('0x49')](_0x4f08('0x94'),_0x22408f);}BPromise['resolve']()[_0x4f08('0x37')](function(){if(!_0x1e76fd){if(_0x556875[_0x4f08('0x40')][_0x4f08('0x79')])return;_0x5bd94f['where'](_0x4f08('0x95'));_0x533c27[_0x4f08('0x49')](_0x4f08('0x95'));return;}if(_0x556875[_0x4f08('0x96')]['role']!==_0x4f08('0x97'))return;return _0x556875[_0x4f08('0x96')][_0x4f08('0x98')]({'attributes':['id'],'raw':!![]})['then'](function(_0x2336fe){if(_['isEmpty'](_0x2336fe)){_0x5bd94f[_0x4f08('0x49')](_0x4f08('0x99'));_0x533c27[_0x4f08('0x49')](_0x4f08('0x99'));}else{_0x5bd94f[_0x4f08('0x49')](_0x4f08('0x7a'),_['map'](_0x2336fe,'id'));_0x533c27[_0x4f08('0x49')](_0x4f08('0x7a'),_[_0x4f08('0x30')](_0x2336fe,'id'));}});})[_0x4f08('0x37')](function(){if(_0x556875[_0x4f08('0x96')]['role']===_0x4f08('0x97')&&!_0x1e76fd&&!_0x556875[_0x4f08('0x40')]['SmsAccountId'])return[];return db[_0x4f08('0x9a')][_0x4f08('0x40')](_0x5bd94f[_0x4f08('0x9b')](),_0x567b8c);})[_0x4f08('0x37')](function(_0x4c6544){_0x5f2d14[_0x4f08('0x26')]=_0x4c6544['length'];if(_0x5f2d14[_0x4f08('0x26')]===0x0)return[];return db['sequelize'][_0x4f08('0x40')](_0xaacc97['toString'](),_0x567b8c)['then'](function(_0xee7e21){_0x56363e=_['keyBy'](_0xee7e21,'id');_0x567b8c=_[_0x4f08('0x9c')](_0x567b8c,{'model':db['SmsInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x556875[_0x4f08('0x40')][_0x4f08('0x44')]){_0x2f2240[_0x4f08('0x43')][_0x4f08('0x34')](function(_0x46c5cf){_0x533c27['field']('i.'+_0x46c5cf);});}else{_0x533c27[_0x4f08('0x4d')](_0x4f08('0x90'),_0x4f08('0x61'));_0x533c27[_0x4f08('0x4d')]('a.key',_0x4f08('0x9d'));_0x533c27[_0x4f08('0x4d')](_0x4f08('0x9e'),_0x4f08('0x9f'));_0x533c27['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',_0x4f08('0x92'));_0x533c27[_0x4f08('0x4d')]('i.*');_0x533c27[_0x4f08('0x4d')](_0x4f08('0xa0'),_0x4f08('0xa1'));_0x533c27[_0x4f08('0x4d')](_0x4f08('0xa2'),_0x4f08('0xa3'));_0x533c27[_0x4f08('0x4d')](_0x4f08('0xa4'),_0x4f08('0xa5'));_0x533c27[_0x4f08('0x4d')]('c.phone',_0x4f08('0xa6'));_0x533c27[_0x4f08('0x4d')](_0x4f08('0xa7'),_0x4f08('0xa8'));_0x533c27[_0x4f08('0x4d')](_0x4f08('0xa9'),'Contact.fax');_0x533c27[_0x4f08('0x4d')](_0x4f08('0xaa'),_0x4f08('0xab'));_0x533c27['field']('o.internal',_0x4f08('0xac'));_0x533c27[_0x4f08('0x4d')](_0x4f08('0xad'),_0x4f08('0x32'));}if(_0x2f2240[_0x4f08('0x25')])_0x533c27['limit'](_0x2f2240[_0x4f08('0x25')]);if(_0x2f2240[_0x4f08('0x23')])_0x533c27[_0x4f08('0x23')](_0x2f2240[_0x4f08('0x23')]);return db[_0x4f08('0x9a')][_0x4f08('0x40')](_0x533c27[_0x4f08('0x9b')](),_0x567b8c);})[_0x4f08('0x37')](function(_0x1ac8b2){if(_0x1ac8b2[_0x4f08('0x45')]>0x0)_0x46fd92[_0x4f08('0x49')](_0x4f08('0xae'),_[_0x4f08('0x30')](_0x1ac8b2,'id'));return db[_0x4f08('0x9a')][_0x4f08('0x40')](_0x46fd92[_0x4f08('0x9b')](),_0x567b8c)[_0x4f08('0x37')](function(_0x17fdff){var _0x40362e=_[_0x4f08('0xaf')](_0x17fdff,_0x4f08('0xb0'));var _0x4f7cb9=[];_0x1ac8b2[_0x4f08('0x34')](function(_0x2017d0){_0x4f7cb9[_0x4f08('0x36')](updateSmsInteraction(_0x2017d0,_0x56363e,_0x40362e));});return BPromise[_0x4f08('0xb1')](_0x4f7cb9);});});})['then'](function(_0x7622f9){_0x5f2d14[_0x4f08('0xb2')]=_0x7622f9;return _0x5f2d14;})[_0x4f08('0x37')](respondWithFilteredResult(_0x442e64,_0x2f2240))[_0x4f08('0x38')](handleError(_0x442e64,null));};exports['show']=function(_0xa7f7ad,_0x1bc9be){var _0x456a0c={'raw':![],'where':{'id':_0xa7f7ad[_0x4f08('0xb3')]['id']}},_0x27aa15={};_0x27aa15['model']=_[_0x4f08('0x41')](db[_0x4f08('0x3a')][_0x4f08('0x3b')]);_0x27aa15[_0x4f08('0x40')]=_[_0x4f08('0x41')](_0xa7f7ad['query']);_0x27aa15[_0x4f08('0x4a')]=_[_0x4f08('0x42')](_0x27aa15[_0x4f08('0x3f')],_0x27aa15[_0x4f08('0x40')]);_0x456a0c[_0x4f08('0x43')]=_[_0x4f08('0x42')](_0x27aa15[_0x4f08('0x3f')],qs[_0x4f08('0x44')](_0xa7f7ad['query'][_0x4f08('0x44')]));_0x456a0c[_0x4f08('0x43')]=_0x456a0c[_0x4f08('0x43')]['length']?_0x456a0c[_0x4f08('0x43')]:_0x27aa15[_0x4f08('0x3f')];if(_0xa7f7ad['query'][_0x4f08('0xb4')]){_0x456a0c[_0x4f08('0xb5')]=[{'all':!![]}];}_0x456a0c=_[_0x4f08('0x9c')]({},_0x456a0c,_0xa7f7ad[_0x4f08('0xb6')]);return db['SmsInteraction']['find'](_0x456a0c)[_0x4f08('0x37')](handleEntityNotFound(_0x1bc9be,null))[_0x4f08('0x37')](respondWithResult(_0x1bc9be,null))['catch'](handleError(_0x1bc9be,null));};exports[_0x4f08('0xb7')]=function(_0x451fca,_0x4cd4dc){return db[_0x4f08('0x3a')][_0x4f08('0xb7')](_0x451fca[_0x4f08('0x75')],{})[_0x4f08('0x37')](respondWithResult(_0x4cd4dc,0xc9))[_0x4f08('0x38')](handleError(_0x4cd4dc,null));};exports['update']=function(_0x23e5ba,_0xdcc47e){if(_0x23e5ba[_0x4f08('0x75')]['id']){delete _0x23e5ba['body']['id'];}return db[_0x4f08('0x3a')]['find']({'where':{'id':_0x23e5ba[_0x4f08('0xb3')]['id']}})[_0x4f08('0x37')](handleEntityNotFound(_0xdcc47e,null))[_0x4f08('0x37')](saveUpdates(_0x23e5ba['body'],null))['then'](respondWithResult(_0xdcc47e,null))[_0x4f08('0x38')](handleError(_0xdcc47e,null));};exports[_0x4f08('0x2b')]=function(_0x3d1ac2,_0x40fd13){return db[_0x4f08('0x3a')][_0x4f08('0x60')]({'where':{'id':_0x3d1ac2[_0x4f08('0xb3')]['id']}})[_0x4f08('0x37')](handleEntityNotFound(_0x40fd13,null))[_0x4f08('0x37')](removeEntity(_0x40fd13,null))[_0x4f08('0x38')](handleError(_0x40fd13,null));};exports[_0x4f08('0xb8')]=function(_0x50aba5,_0x25cbc5){return db[_0x4f08('0x3a')][_0x4f08('0xb8')]()['then'](respondWithResult(_0x25cbc5,null))['catch'](handleError(_0x25cbc5,null));};exports[_0x4f08('0xb9')]=function(_0x286ea5,_0x286472,_0x29a964){return db['SmsMessage'][_0x4f08('0x60')]({'where':{'id':_0x286ea5[_0x4f08('0xb3')]['id']}})[_0x4f08('0x37')](handleEntityNotFound(_0x286472,null))[_0x4f08('0x37')](function(_0x59603f){if(_0x59603f){return _0x59603f[_0x4f08('0xb9')](_0x286ea5[_0x4f08('0x75')][_0x4f08('0xba')],_[_0x4f08('0xbb')](_0x286ea5[_0x4f08('0x75')],['ids','id'])||{});}})[_0x4f08('0x37')](respondWithResult(_0x286472,null))['catch'](handleError(_0x286472,null));};exports[_0x4f08('0xbc')]=function(_0x55bab6,_0x36999f,_0x57c710){var _0x2c30e0={'raw':![],'where':{}};var _0x296a59={};var _0x26df9e={'count':0x0,'rows':[]};return db[_0x4f08('0x3a')][_0x4f08('0xbd')]({'where':{'id':_0x55bab6['params']['id']}})[_0x4f08('0x37')](handleEntityNotFound(_0x36999f,null))['then'](function(_0x531d3f){if(_0x531d3f){_0x296a59[_0x4f08('0x3f')]=_[_0x4f08('0x41')](db['SmsMessage'][_0x4f08('0x3b')]);_0x296a59['query']=_[_0x4f08('0x41')](_0x55bab6[_0x4f08('0x40')]);_0x296a59[_0x4f08('0x4a')]=_['intersection'](_0x296a59[_0x4f08('0x3f')],_0x296a59[_0x4f08('0x40')]);_0x2c30e0[_0x4f08('0x43')]=_[_0x4f08('0x42')](_0x296a59[_0x4f08('0x3f')],qs['fields'](_0x55bab6[_0x4f08('0x40')][_0x4f08('0x44')]));_0x2c30e0['attributes']=_0x2c30e0[_0x4f08('0x43')][_0x4f08('0x45')]?_0x2c30e0[_0x4f08('0x43')]:_0x296a59[_0x4f08('0x3f')];if(!_0x55bab6[_0x4f08('0x40')][_0x4f08('0x46')](_0x4f08('0x47'))){_0x2c30e0[_0x4f08('0x25')]=qs[_0x4f08('0x25')](_0x55bab6[_0x4f08('0x40')]['limit']);_0x2c30e0[_0x4f08('0x23')]=qs[_0x4f08('0x23')](_0x55bab6[_0x4f08('0x40')][_0x4f08('0x23')]);}_0x2c30e0[_0x4f08('0x91')]=qs['sort'](_0x55bab6[_0x4f08('0x40')][_0x4f08('0x48')]);_0x2c30e0[_0x4f08('0x49')]=qs[_0x4f08('0x4a')](_['pick'](_0x55bab6['query'],_0x296a59['filters']));_0x2c30e0['where'][_0x4f08('0xb0')]=_0x531d3f['id'];if(_0x55bab6['query'][_0x4f08('0x87')]){_0x2c30e0[_0x4f08('0x49')]=_[_0x4f08('0x9c')](_0x2c30e0[_0x4f08('0x49')],{'$or':_[_0x4f08('0x30')](_0x2c30e0[_0x4f08('0x43')],function(_0x3f7dfb){var _0x3afe44={};_0x3afe44[_0x3f7dfb]={'$like':'%'+_0x55bab6[_0x4f08('0x40')][_0x4f08('0x87')]+'%'};return _0x3afe44;})});}if(_0x55bab6['query'][_0x4f08('0x7d')]){var _0x5297a4=_0x55bab6['query'][_0x4f08('0x7d')][_0x4f08('0x33')](',');var _0x4ae87f={};_0x4ae87f[_0x5297a4[0x0]]={'$gte':moment(_0x5297a4[0x1])['format'](_0x4f08('0xbe'))};_0x2c30e0['where']=_['merge'](_0x2c30e0[_0x4f08('0x49')],_0x4ae87f);}_0x2c30e0=_['merge']({},_0x2c30e0,_0x55bab6[_0x4f08('0xb6')]);return db[_0x4f08('0xbf')][_0x4f08('0x26')]({'where':_0x2c30e0['where']})['then'](function(_0x3813b9){_0x26df9e[_0x4f08('0x26')]=_0x3813b9;if(_0x55bab6['query'][_0x4f08('0xb4')]){_0x2c30e0[_0x4f08('0xb5')]=[{'all':!![]}];}return db[_0x4f08('0xbf')][_0x4f08('0xc0')](_0x2c30e0);})[_0x4f08('0x37')](function(_0x15a8df){_0x26df9e['rows']=_0x15a8df;return _0x26df9e;});}})[_0x4f08('0x37')](respondWithFilteredResult(_0x36999f,_0x2c30e0))[_0x4f08('0x38')](handleError(_0x36999f,null));};exports['addTags']=function(_0x4be004,_0x161ab8,_0x594050){return db[_0x4f08('0x3a')][_0x4f08('0x60')]({'where':{'id':_0x4be004[_0x4f08('0xb3')]['id']}})[_0x4f08('0x37')](handleEntityNotFound(_0x161ab8,null))[_0x4f08('0x37')](function(_0x1f0764){if(_0x1f0764){return _0x1f0764[_0x4f08('0xc1')](_0x4be004[_0x4f08('0x75')][_0x4f08('0xba')],_[_0x4f08('0xbb')](_0x4be004[_0x4f08('0x75')],['ids','id'])||{})[_0x4f08('0xc2')](function(){return db[_0x4f08('0xc3')][_0x4f08('0xc0')]({'attributes':['id','name',_0x4f08('0xc4')],'where':{'id':_0x4be004['body']['ids']}});})[_0x4f08('0x37')](function(_0x470856){socket[_0x4f08('0xc5')](_0x4f08('0xc6'),{'id':Number(_0x4be004[_0x4f08('0xb3')]['id']),'tags':_0x470856||[]});return{'id':Number(_0x4be004[_0x4f08('0xb3')]['id']),'tags':_0x470856||[]};});}})[_0x4f08('0x37')](respondWithResult(_0x161ab8,null))[_0x4f08('0x38')](handleError(_0x161ab8,null));};exports[_0x4f08('0xc7')]=function(_0x73b406,_0x59815c,_0x20d576){return db[_0x4f08('0x3a')][_0x4f08('0x60')]({'where':{'id':_0x73b406[_0x4f08('0xb3')]['id']}})[_0x4f08('0x37')](handleEntityNotFound(_0x59815c,null))[_0x4f08('0x37')](function(_0x43535b){if(_0x43535b){return _0x43535b[_0x4f08('0xc7')](_0x73b406['query']['ids']);}})[_0x4f08('0x37')](respondWithStatusCode(_0x59815c,null))[_0x4f08('0x38')](handleError(_0x59815c,null));};exports['download']=function(_0x8aa4,_0x36c6eb){var _0x2ba1b3=moment()[_0x4f08('0xc8')]()[_0x4f08('0x9b')]();var _0x4d8ecc=path[_0x4f08('0xc9')](config['root'],_0x4f08('0xca'),_0x4f08('0xcb'),'tmp');var _0x577412=path[_0x4f08('0xc9')](config[_0x4f08('0xcc')],_0x4f08('0xca'),_0x4f08('0xcb'),_0x4f08('0xcd'));var _0x2fc9b9=path[_0x4f08('0xc9')](_0x4d8ecc,_0x2ba1b3);var _0x4df763=util['format'](_0x4f08('0xce'),_0x8aa4['params']['id'],_0x2ba1b3);var _0x3ce66b=path[_0x4f08('0xc9')](_0x4d8ecc,_0x4df763);var _0x418b58=[];_0x418b58[_0x4f08('0x36')]({'model':db['User'],'as':'User','attributes':['id',_0x4f08('0x31')],'raw':!![]});_0x418b58['push']({'model':db[_0x4f08('0xcf')],'as':_0x4f08('0x66'),'attributes':['id',_0x4f08('0xd0'),_0x4f08('0xd1')],'raw':!![]});var _0x3e7cc9=[{'model':db['SmsMessage'],'as':_0x4f08('0xd2'),'attributes':['id','body',_0x4f08('0x7c'),_0x4f08('0xd3'),_0x4f08('0xd4'),_0x4f08('0x82')],'include':_0x418b58}];_0x3e7cc9[_0x4f08('0x36')]({'model':db[_0x4f08('0xd5')],'as':_0x4f08('0xd6'),'attributes':['id',_0x4f08('0x2e')]});_0x3e7cc9[_0x4f08('0x36')]({'model':db['User'],'as':_0x4f08('0xd7'),'attributes':['id',_0x4f08('0x31')]});return db[_0x4f08('0x3a')][_0x4f08('0x60')]({'where':{'id':_0x8aa4['params']['id']},'include':_0x3e7cc9})[_0x4f08('0x37')](handleEntityNotFound(_0x36c6eb,null))['then'](function(_0x5988ba){if(_0x5988ba){var _0x4c4c13=_0x5988ba['get']({'plain':!![]});fs[_0x4f08('0xd8')](_0x2fc9b9);var _0x4fd770={'channel':_0x4f08('0xd9'),'account':_0x4c4c13[_0x4f08('0xd6')][_0x4f08('0x2e')],'agent':_0x4c4c13[_0x4f08('0xd7')]?_0x4c4c13['Owner'][_0x4f08('0x31')]:_0x4f08('0xda'),'createdAt':moment(_0x4c4c13['createdAt'])[_0x4f08('0xdb')](_0x4f08('0xbe'))[_0x4f08('0x9b')](),'closedAt':_0x4c4c13[_0x4f08('0xdc')]?moment(_0x4c4c13[_0x4f08('0xdd')])['format'](_0x4f08('0xbe'))['toString']():'','disposition':_0x4c4c13['disposition'],'messages':_(_0x4c4c13[_0x4f08('0xd2')])['filter']({'secret':![]})['map'](function(_0x3bd36a){return{'date':moment(_0x3bd36a['createdAt'])['format'](_0x4f08('0xbe'))[_0x4f08('0x9b')](),'sender':_0x3bd36a[_0x4f08('0xd3')]==='out'?_0x3bd36a[_0x4f08('0x72')]?_0x3bd36a['User'][_0x4f08('0x31')]:_0x4f08('0xde'):_0x3bd36a[_0x4f08('0x66')][_0x4f08('0xd0')]+(_0x3bd36a[_0x4f08('0x66')][_0x4f08('0xd1')]?'\x20'+_0x3bd36a[_0x4f08('0x66')]['lastName']:''),'body':_0x3bd36a['body'],'direction':_0x3bd36a[_0x4f08('0xd3')]===_0x4f08('0xdf')?'A':'C','secret':_0x3bd36a[_0x4f08('0xd4')],'read':_0x3bd36a[_0x4f08('0x82')]};})['value']()};return ejs[_0x4f08('0xe0')](path[_0x4f08('0xc9')](config[_0x4f08('0xcc')],_0x4f08('0xca'),_0x4f08('0xe1'),_0x4f08('0xe2')),{'interaction':_0x4fd770})['then'](function(_0x1c5d63){var _0x6044eb=path[_0x4f08('0xc9')](_0x2fc9b9,_0x4f08('0xe3')+_0x4c4c13['id']+'-'+_0x2ba1b3+'.pdf');var _0x564a37={'path':_0x6044eb,'channel':_0x4f08('0xd9'),'interactionId':_0x4c4c13['id']};return pdf[_0x4f08('0xe4')](_0x1c5d63,_0x564a37);})[_0x4f08('0x37')](function(){return new BPromise(function(_0x21d1df,_0x6f8e22){zipdir(_0x2fc9b9,{'saveTo':_0x3ce66b},function(_0x1ee815,_0x21edd5){if(_0x1ee815)return _0x6f8e22(_0x1ee815);return _0x21d1df(_0x21edd5);});})[_0x4f08('0x37')](function(){return new BPromise(function(_0x5ce412,_0x30a77f){rimraf(_0x2fc9b9,function(_0x21c204){if(_0x21c204)_0x30a77f(_0x21c204);return _0x5ce412();});});})['then'](function(){return _0x36c6eb[_0x4f08('0xe5')](_0x3ce66b,_0x4df763,function(_0x3bc3ce){if(_0x3bc3ce){console[_0x4f08('0xe6')](_0x4f08('0xe7'),_0x3bc3ce);}else{fs[_0x4f08('0xe8')](_0x3ce66b);}});});});}else{return _0x36c6eb[_0x4f08('0x1f')](0xc8);}})[_0x4f08('0x38')](handleError(_0x36c6eb,null));};
\ No newline at end of file
+var _0xb3de=['../../components/parsers/qs','../../components/export/pdf','../../config/logger','../../config/environment','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./smsInteraction.socket','register','sendStatus','end','json','offset','undefined','limit','set','Content-Range','update','destroy','name','status','map','SmsInteraction','rawAttributes','fieldName','key','findAll','sms','query','user','then','catch','show','params','model','keys','filters','intersection','attributes','fields','length','includeAll','include','options','find','create','body','describe','addMessage','SmsMessage','omit','ids','getMessages','hasOwnProperty','nolimit','where','pick','SmsInteractionId','filter','merge','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','count','addTags','setTags','spread','Tag','color','emit','smsInteractionTags:save','removeTags','download','join','root','server','files','tmp','transcript-%d-%s.zip','push','User','fullname','CmContact','Contact','firstName','lastName','Messages','secret','read','SmsAccount','Account','Owner','get','Sms','N.A.','createdAt','toString','closed','closedAt','direction','out','value','views','transcript-','.pdf','createPdfFromHTML','log','err','unlinkSync','rimraf','zip-dir','moment','bluebird','util','path','ejs','lodash','ioredis','../../components/interaction/service'];(function(_0x4272b1,_0x39eaa6){var _0x579b7e=function(_0x3110f2){while(--_0x3110f2){_0x4272b1['push'](_0x4272b1['shift']());}};_0x579b7e(++_0x39eaa6);}(_0xb3de,0x164));var _0xeb3d=function(_0x2795d4,_0x250a4f){_0x2795d4=_0x2795d4-0x0;var _0x24262c=_0xb3de[_0x2795d4];return _0x24262c;};'use strict';var rimraf=require(_0xeb3d('0x0'));var zipdir=require(_0xeb3d('0x1'));var moment=require(_0xeb3d('0x2'));var BPromise=require(_0xeb3d('0x3'));var util=require(_0xeb3d('0x4'));var path=require(_0xeb3d('0x5'));var ejs=require(_0xeb3d('0x6'));var fs=require('fs');var _=require(_0xeb3d('0x7'));var Redis=require(_0xeb3d('0x8'));var interaction=require(_0xeb3d('0x9'));var qs=require(_0xeb3d('0xa'));var pdf=require(_0xeb3d('0xb'));var logger=require(_0xeb3d('0xc'))('api');var config=require(_0xeb3d('0xd'));var db=require(_0xeb3d('0xe'))['db'];config['redis']=_[_0xeb3d('0xf')](config[_0xeb3d('0x10')],{'host':_0xeb3d('0x11'),'port':0x18eb});var socket=require(_0xeb3d('0x12'))(new Redis(config[_0xeb3d('0x10')]));require(_0xeb3d('0x13'))[_0xeb3d('0x14')](socket);function respondWithStatusCode(_0x1fbbd1,_0x4b57da){_0x4b57da=_0x4b57da||0xcc;return function(_0x2933f7){if(_0x2933f7){return _0x1fbbd1[_0xeb3d('0x15')](_0x4b57da);}return _0x1fbbd1['status'](_0x4b57da)[_0xeb3d('0x16')]();};}function respondWithResult(_0x497e13,_0x3a1a5e){_0x3a1a5e=_0x3a1a5e||0xc8;return function(_0x3d2912){if(_0x3d2912){return _0x497e13['status'](_0x3a1a5e)[_0xeb3d('0x17')](_0x3d2912);}};}function respondWithFilteredResult(_0x59c365,_0x4f35b4){return function(_0x4ea1f1){if(_0x4ea1f1){var _0x367939=typeof _0x4f35b4[_0xeb3d('0x18')]===_0xeb3d('0x19')&&typeof _0x4f35b4[_0xeb3d('0x1a')]==='undefined';var _0x59c8eb=_0x4ea1f1['count'];var _0x27a223=_0x367939?0x0:_0x4f35b4[_0xeb3d('0x18')];var _0x117916=_0x367939?_0x4ea1f1['count']:_0x4f35b4[_0xeb3d('0x18')]+_0x4f35b4[_0xeb3d('0x1a')];var _0x2738d3;if(_0x117916>=_0x59c8eb){_0x117916=_0x59c8eb;_0x2738d3=0xc8;}else{_0x2738d3=0xce;}_0x59c365['status'](_0x2738d3);return _0x59c365[_0xeb3d('0x1b')](_0xeb3d('0x1c'),_0x27a223+'-'+_0x117916+'/'+_0x59c8eb)[_0xeb3d('0x17')](_0x4ea1f1);}return null;};}function saveUpdates(_0xeda6c8){return function(_0x4efbf3){if(_0x4efbf3){return _0x4efbf3[_0xeb3d('0x1d')](_0xeda6c8)['then'](function(_0x33511c){return _0x33511c;});}return null;};}function removeEntity(_0x170470){return function(_0x53b33a){if(_0x53b33a){return _0x53b33a[_0xeb3d('0x1e')]()['then'](function(){_0x170470['status'](0xcc)[_0xeb3d('0x16')]();});}};}function handleEntityNotFound(_0xe2c3bc){return function(_0x106df2){if(!_0x106df2){_0xe2c3bc['sendStatus'](0x194);}return _0x106df2;};}function handleError(_0x577b1f,_0x3c239f){_0x3c239f=_0x3c239f||0x1f4;return function(_0x11e229){logger['error'](_0x11e229['stack']);if(_0x11e229[_0xeb3d('0x1f')]){delete _0x11e229[_0xeb3d('0x1f')];}_0x577b1f[_0xeb3d('0x20')](_0x3c239f)['send'](_0x11e229);};}exports['index']=function(_0x4e789a,_0x1bf9fb){var _0x5a7a1b={};var _0x31eccf=_[_0xeb3d('0x21')](db[_0xeb3d('0x22')][_0xeb3d('0x23')],function(_0x2bf491){return{'name':_0x2bf491[_0xeb3d('0x24')],'type':_0x2bf491['type'][_0xeb3d('0x25')]};});_0x5a7a1b=qs['getOptions'](_0x31eccf,_0x4e789a);return interaction[_0xeb3d('0x26')](_0xeb3d('0x27'),_0x4e789a[_0xeb3d('0x28')],_0x4e789a[_0xeb3d('0x29')],_0x5a7a1b,_0x31eccf)[_0xeb3d('0x2a')](respondWithFilteredResult(_0x1bf9fb,_0x5a7a1b))[_0xeb3d('0x2b')](handleError(_0x1bf9fb,null));};exports[_0xeb3d('0x2c')]=function(_0x114ac4,_0x2b273a){var _0xaed886={'raw':![],'where':{'id':_0x114ac4[_0xeb3d('0x2d')]['id']}},_0x2e7d42={};_0x2e7d42[_0xeb3d('0x2e')]=_[_0xeb3d('0x2f')](db[_0xeb3d('0x22')][_0xeb3d('0x23')]);_0x2e7d42[_0xeb3d('0x28')]=_['keys'](_0x114ac4['query']);_0x2e7d42[_0xeb3d('0x30')]=_[_0xeb3d('0x31')](_0x2e7d42[_0xeb3d('0x2e')],_0x2e7d42[_0xeb3d('0x28')]);_0xaed886[_0xeb3d('0x32')]=_[_0xeb3d('0x31')](_0x2e7d42[_0xeb3d('0x2e')],qs['fields'](_0x114ac4[_0xeb3d('0x28')][_0xeb3d('0x33')]));_0xaed886[_0xeb3d('0x32')]=_0xaed886[_0xeb3d('0x32')][_0xeb3d('0x34')]?_0xaed886[_0xeb3d('0x32')]:_0x2e7d42[_0xeb3d('0x2e')];if(_0x114ac4[_0xeb3d('0x28')][_0xeb3d('0x35')]){_0xaed886[_0xeb3d('0x36')]=[{'all':!![]}];}_0xaed886=_['merge']({},_0xaed886,_0x114ac4[_0xeb3d('0x37')]);return db[_0xeb3d('0x22')][_0xeb3d('0x38')](_0xaed886)['then'](handleEntityNotFound(_0x2b273a,null))[_0xeb3d('0x2a')](respondWithResult(_0x2b273a,null))['catch'](handleError(_0x2b273a,null));};exports[_0xeb3d('0x39')]=function(_0x1ea652,_0x12451d){return db[_0xeb3d('0x22')]['create'](_0x1ea652['body'],{})['then'](respondWithResult(_0x12451d,0xc9))[_0xeb3d('0x2b')](handleError(_0x12451d,null));};exports['update']=function(_0x42705f,_0x47993e){if(_0x42705f[_0xeb3d('0x3a')]['id']){delete _0x42705f[_0xeb3d('0x3a')]['id'];}return db['SmsInteraction'][_0xeb3d('0x38')]({'where':{'id':_0x42705f[_0xeb3d('0x2d')]['id']}})[_0xeb3d('0x2a')](handleEntityNotFound(_0x47993e,null))[_0xeb3d('0x2a')](saveUpdates(_0x42705f[_0xeb3d('0x3a')],null))[_0xeb3d('0x2a')](respondWithResult(_0x47993e,null))[_0xeb3d('0x2b')](handleError(_0x47993e,null));};exports[_0xeb3d('0x1e')]=function(_0x4a8d7f,_0x219f4d){return db[_0xeb3d('0x22')][_0xeb3d('0x38')]({'where':{'id':_0x4a8d7f[_0xeb3d('0x2d')]['id']}})[_0xeb3d('0x2a')](handleEntityNotFound(_0x219f4d,null))[_0xeb3d('0x2a')](removeEntity(_0x219f4d,null))[_0xeb3d('0x2b')](handleError(_0x219f4d,null));};exports[_0xeb3d('0x3b')]=function(_0x18b558,_0x217eeb){return db['SmsInteraction'][_0xeb3d('0x3b')]()[_0xeb3d('0x2a')](respondWithResult(_0x217eeb,null))[_0xeb3d('0x2b')](handleError(_0x217eeb,null));};exports[_0xeb3d('0x3c')]=function(_0xa88f85,_0x41f1db){return db[_0xeb3d('0x3d')]['find']({'where':{'id':_0xa88f85[_0xeb3d('0x2d')]['id']}})[_0xeb3d('0x2a')](handleEntityNotFound(_0x41f1db,null))[_0xeb3d('0x2a')](function(_0x92ceee){if(_0x92ceee){return _0x92ceee[_0xeb3d('0x3c')](_0xa88f85['body']['ids'],_[_0xeb3d('0x3e')](_0xa88f85['body'],[_0xeb3d('0x3f'),'id'])||{});}})[_0xeb3d('0x2a')](respondWithResult(_0x41f1db,null))[_0xeb3d('0x2b')](handleError(_0x41f1db,null));};exports[_0xeb3d('0x40')]=function(_0x43a605,_0x95425c){var _0x6f1cea={'raw':![],'where':{}};var _0x2d1b56={};var _0x10b24b={'count':0x0,'rows':[]};return db[_0xeb3d('0x22')]['findOne']({'where':{'id':_0x43a605[_0xeb3d('0x2d')]['id']}})[_0xeb3d('0x2a')](handleEntityNotFound(_0x95425c,null))[_0xeb3d('0x2a')](function(_0xd75ec4){if(_0xd75ec4){_0x2d1b56['model']=_[_0xeb3d('0x2f')](db[_0xeb3d('0x3d')][_0xeb3d('0x23')]);_0x2d1b56[_0xeb3d('0x28')]=_[_0xeb3d('0x2f')](_0x43a605[_0xeb3d('0x28')]);_0x2d1b56[_0xeb3d('0x30')]=_[_0xeb3d('0x31')](_0x2d1b56[_0xeb3d('0x2e')],_0x2d1b56[_0xeb3d('0x28')]);_0x6f1cea['attributes']=_[_0xeb3d('0x31')](_0x2d1b56[_0xeb3d('0x2e')],qs[_0xeb3d('0x33')](_0x43a605[_0xeb3d('0x28')][_0xeb3d('0x33')]));_0x6f1cea['attributes']=_0x6f1cea[_0xeb3d('0x32')]['length']?_0x6f1cea['attributes']:_0x2d1b56['model'];if(!_0x43a605[_0xeb3d('0x28')][_0xeb3d('0x41')](_0xeb3d('0x42'))){_0x6f1cea['limit']=qs['limit'](_0x43a605[_0xeb3d('0x28')][_0xeb3d('0x1a')]);_0x6f1cea[_0xeb3d('0x18')]=qs[_0xeb3d('0x18')](_0x43a605[_0xeb3d('0x28')]['offset']);}_0x6f1cea['order']=qs['sort'](_0x43a605[_0xeb3d('0x28')]['sort']);_0x6f1cea[_0xeb3d('0x43')]=qs[_0xeb3d('0x30')](_[_0xeb3d('0x44')](_0x43a605['query'],_0x2d1b56['filters']));_0x6f1cea['where'][_0xeb3d('0x45')]=_0xd75ec4['id'];if(_0x43a605[_0xeb3d('0x28')][_0xeb3d('0x46')]){_0x6f1cea['where']=_[_0xeb3d('0x47')](_0x6f1cea['where'],{'$or':_[_0xeb3d('0x21')](_0x6f1cea['attributes'],function(_0x4f6abe){var _0x4663a4={};_0x4663a4[_0x4f6abe]={'$like':'%'+_0x43a605['query'][_0xeb3d('0x46')]+'%'};return _0x4663a4;})});}if(_0x43a605[_0xeb3d('0x28')][_0xeb3d('0x48')]){var _0x573650=_0x43a605[_0xeb3d('0x28')][_0xeb3d('0x48')][_0xeb3d('0x49')](',');var _0x396d67={};_0x396d67[_0x573650[0x0]]={'$gte':moment(_0x573650[0x1])[_0xeb3d('0x4a')](_0xeb3d('0x4b'))};_0x6f1cea[_0xeb3d('0x43')]=_['merge'](_0x6f1cea[_0xeb3d('0x43')],_0x396d67);}_0x6f1cea=_[_0xeb3d('0x47')]({},_0x6f1cea,_0x43a605[_0xeb3d('0x37')]);return db['SmsMessage']['count']({'where':_0x6f1cea[_0xeb3d('0x43')]})[_0xeb3d('0x2a')](function(_0x4cefb9){_0x10b24b[_0xeb3d('0x4c')]=_0x4cefb9;if(_0x43a605[_0xeb3d('0x28')]['includeAll']){_0x6f1cea['include']=[{'all':!![]}];}return db[_0xeb3d('0x3d')]['findAll'](_0x6f1cea);})[_0xeb3d('0x2a')](function(_0xf7cca1){_0x10b24b['rows']=_0xf7cca1;return _0x10b24b;});}})[_0xeb3d('0x2a')](respondWithFilteredResult(_0x95425c,_0x6f1cea))['catch'](handleError(_0x95425c,null));};exports[_0xeb3d('0x4d')]=function(_0x40c4fd,_0x12e1ac){return db[_0xeb3d('0x22')]['find']({'where':{'id':_0x40c4fd[_0xeb3d('0x2d')]['id']}})['then'](handleEntityNotFound(_0x12e1ac,null))[_0xeb3d('0x2a')](function(_0x5d7858){if(_0x5d7858){return _0x5d7858[_0xeb3d('0x4e')](_0x40c4fd[_0xeb3d('0x3a')][_0xeb3d('0x3f')],_[_0xeb3d('0x3e')](_0x40c4fd['body'],[_0xeb3d('0x3f'),'id'])||{})[_0xeb3d('0x4f')](function(){return db[_0xeb3d('0x50')]['findAll']({'attributes':['id',_0xeb3d('0x1f'),_0xeb3d('0x51')],'where':{'id':_0x40c4fd['body'][_0xeb3d('0x3f')]}});})[_0xeb3d('0x2a')](function(_0x96bdac){socket[_0xeb3d('0x52')](_0xeb3d('0x53'),{'id':Number(_0x40c4fd[_0xeb3d('0x2d')]['id']),'tags':_0x96bdac||[]});return{'id':Number(_0x40c4fd[_0xeb3d('0x2d')]['id']),'tags':_0x96bdac||[]};});}})[_0xeb3d('0x2a')](respondWithResult(_0x12e1ac,null))['catch'](handleError(_0x12e1ac,null));};exports[_0xeb3d('0x54')]=function(_0x2a95f5,_0x113a8d){return db[_0xeb3d('0x22')][_0xeb3d('0x38')]({'where':{'id':_0x2a95f5[_0xeb3d('0x2d')]['id']}})[_0xeb3d('0x2a')](handleEntityNotFound(_0x113a8d,null))[_0xeb3d('0x2a')](function(_0x3e8130){if(_0x3e8130){return _0x3e8130[_0xeb3d('0x54')](_0x2a95f5['query']['ids']);}})[_0xeb3d('0x2a')](respondWithStatusCode(_0x113a8d,null))[_0xeb3d('0x2b')](handleError(_0x113a8d,null));};exports[_0xeb3d('0x55')]=function(_0x3b71ec,_0x58c704){var _0x49d4c6=moment()['unix']()['toString']();var _0x592639=path[_0xeb3d('0x56')](config[_0xeb3d('0x57')],_0xeb3d('0x58'),_0xeb3d('0x59'),_0xeb3d('0x5a'));var _0x8b7f8e=path[_0xeb3d('0x56')](_0x592639,_0x49d4c6);var _0x4882f0=util[_0xeb3d('0x4a')](_0xeb3d('0x5b'),_0x3b71ec[_0xeb3d('0x2d')]['id'],_0x49d4c6);var _0x334b8b=path['join'](_0x592639,_0x4882f0);var _0x4779ea=[];_0x4779ea[_0xeb3d('0x5c')]({'model':db[_0xeb3d('0x5d')],'as':_0xeb3d('0x5d'),'attributes':['id',_0xeb3d('0x5e')],'raw':!![]});_0x4779ea[_0xeb3d('0x5c')]({'model':db[_0xeb3d('0x5f')],'as':_0xeb3d('0x60'),'attributes':['id',_0xeb3d('0x61'),_0xeb3d('0x62')],'raw':!![]});var _0x2cc629=[{'model':db['SmsMessage'],'as':_0xeb3d('0x63'),'attributes':['id',_0xeb3d('0x3a'),'createdAt','direction',_0xeb3d('0x64'),_0xeb3d('0x65')],'include':_0x4779ea}];_0x2cc629['push']({'model':db[_0xeb3d('0x66')],'as':_0xeb3d('0x67'),'attributes':['id',_0xeb3d('0x1f')]});_0x2cc629[_0xeb3d('0x5c')]({'model':db['User'],'as':_0xeb3d('0x68'),'attributes':['id','fullname']});return db['SmsInteraction'][_0xeb3d('0x38')]({'where':{'id':_0x3b71ec[_0xeb3d('0x2d')]['id']},'include':_0x2cc629})[_0xeb3d('0x2a')](handleEntityNotFound(_0x58c704,null))[_0xeb3d('0x2a')](function(_0x1be1e0){if(_0x1be1e0){var _0x47c67d=_0x1be1e0[_0xeb3d('0x69')]({'plain':!![]});fs['mkdirSync'](_0x8b7f8e);var _0x5680e4={'channel':_0xeb3d('0x6a'),'account':_0x47c67d[_0xeb3d('0x67')][_0xeb3d('0x1f')],'agent':_0x47c67d[_0xeb3d('0x68')]?_0x47c67d['Owner'][_0xeb3d('0x5e')]:_0xeb3d('0x6b'),'createdAt':moment(_0x47c67d[_0xeb3d('0x6c')])[_0xeb3d('0x4a')]('YYYY-MM-DD\x20HH:mm:ss')[_0xeb3d('0x6d')](),'closedAt':_0x47c67d[_0xeb3d('0x6e')]?moment(_0x47c67d[_0xeb3d('0x6f')])[_0xeb3d('0x4a')]('YYYY-MM-DD\x20HH:mm:ss')[_0xeb3d('0x6d')]():'','disposition':_0x47c67d['disposition'],'messages':_(_0x47c67d[_0xeb3d('0x63')])[_0xeb3d('0x46')]({'secret':![]})[_0xeb3d('0x21')](function(_0x6fc801){return{'date':moment(_0x6fc801[_0xeb3d('0x6c')])[_0xeb3d('0x4a')]('YYYY-MM-DD\x20HH:mm:ss')[_0xeb3d('0x6d')](),'sender':_0x6fc801[_0xeb3d('0x70')]===_0xeb3d('0x71')?_0x6fc801[_0xeb3d('0x5d')]?_0x6fc801['User'][_0xeb3d('0x5e')]:'System':_0x6fc801['Contact'][_0xeb3d('0x61')]+(_0x6fc801[_0xeb3d('0x60')][_0xeb3d('0x62')]?'\x20'+_0x6fc801[_0xeb3d('0x60')][_0xeb3d('0x62')]:''),'body':_0x6fc801[_0xeb3d('0x3a')],'direction':_0x6fc801['direction']==='out'?'A':'C','secret':_0x6fc801[_0xeb3d('0x64')],'read':_0x6fc801[_0xeb3d('0x65')]};})[_0xeb3d('0x72')]()};return ejs['renderFile'](path[_0xeb3d('0x56')](config[_0xeb3d('0x57')],_0xeb3d('0x58'),_0xeb3d('0x73'),'downloadInteraction.ejs'),{'interaction':_0x5680e4})[_0xeb3d('0x2a')](function(_0x1bd371){var _0x57eed8=path['join'](_0x8b7f8e,_0xeb3d('0x74')+_0x47c67d['id']+'-'+_0x49d4c6+_0xeb3d('0x75'));var _0x35aff5={'path':_0x57eed8,'channel':_0xeb3d('0x6a'),'interactionId':_0x47c67d['id']};return pdf[_0xeb3d('0x76')](_0x1bd371,_0x35aff5);})[_0xeb3d('0x2a')](function(){return new BPromise(function(_0x52b32b,_0x131443){zipdir(_0x8b7f8e,{'saveTo':_0x334b8b},function(_0x5e13e2,_0x4dd5ab){if(_0x5e13e2)return _0x131443(_0x5e13e2);return _0x52b32b(_0x4dd5ab);});})[_0xeb3d('0x2a')](function(){return new BPromise(function(_0x16e8e9,_0x41c34a){rimraf(_0x8b7f8e,function(_0xd895d7){if(_0xd895d7)_0x41c34a(_0xd895d7);return _0x16e8e9();});});})['then'](function(){return _0x58c704[_0xeb3d('0x55')](_0x334b8b,_0x4882f0,function(_0x92c13f){if(_0x92c13f){console[_0xeb3d('0x77')](_0xeb3d('0x78'),_0x92c13f);}else{fs[_0xeb3d('0x79')](_0x334b8b);}});});});}else{return _0x58c704[_0xeb3d('0x15')](0xc8);}})[_0xeb3d('0x2b')](handleError(_0x58c704,null));};
\ No newline at end of file