Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / api / smsInteraction / smsInteraction.controller.js
index 10852fc..7c821fa 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf72b=['toFile','transcript-','.pdf','err','unlinkSync','html-pdf','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','sendStatus','status','end','json','count','offset','limit','set','apply','save','update','then','destroy','error','stack','name','send','map','fullname','TagIds','Tags','split','forEach','push','SmsInteraction','rawAttributes','fieldName','type','key','query','keys','filters','intersection','attributes','model','hasOwnProperty','order','sort','select','field','color','from','tools_tags','u.id','u.fullname','ui.SmsInteractionId','left_join','users','u.id\x20=\x20ui.UserId','sms_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','sms_accounts','me.SmsInteractionId\x20=\x20i.id','sms_interaction_has_tags','t.id\x20=\x20it.TagId','expr','parseSearch','search','sqlOperator','conditions','length','find','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','operator','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','ContactId','text','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','buildExpression','body','start','some','compact','isEmpty','SmsAccountId','where','i.SmsAccountId\x20IN\x20?','concat','createdAt','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20>\x200','tag','filter','replace','\x27\x27\x27\x27','i.id\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','Sequelize','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','t.id\x20IN\x20?','resolve','journey','i.SmsAccountId\x20IS\x20NOT\x20NULL','user','getSmsAccounts','i.SmsAccountId\x20IS\x20NULL','sequelize','toString','keyBy','merge','fields','a.key','Account.mandatoryDisposition','i.*','c.firstName','Contact.firstName','c.lastName','c.email','Contact.email','c.phone','Contact.phone','c.mobile','Contact.mobile','Contact.fax','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.SmsInteractionId\x20IN\x20?','all','rows','catch','show','includeAll','create','params','describe','addMessage','SmsMessage','ids','omit','getMessages','findOne','nolimit','SmsInteractionId','format','YYYY-MM-DD\x20HH:mm:ss','options','include','findAll','addTags','setTags','spread','emit','removeTags','download','join','root','server','files','tmp','attachments','transcript-%d-%s.zip','User','CmContact','firstName','lastName','Messages','direction','secret','SmsAccount','Account','get','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>','30px','%s\x20#%d','Sms','Owner','N.A.','closed','closedAt','disposition','out','System','Contact','renderFile','downloadInteraction.html'];(function(_0x34a284,_0x207084){var _0x2ec13b=function(_0x197011){while(--_0x197011){_0x34a284['push'](_0x34a284['shift']());}};_0x2ec13b(++_0x207084);}(_0xf72b,0x1d9));var _0xbf72=function(_0x3ff937,_0x3f6a9e){_0x3ff937=_0x3ff937-0x0;var _0x106dc2=_0xf72b[_0x3ff937];return _0x106dc2;};'use strict';var pdf=require(_0xbf72('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xbf72('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xbf72('0x2'));var rp=require(_0xbf72('0x3'));var moment=require('moment');var BPromise=require(_0xbf72('0x4'));var Mustache=require(_0xbf72('0x5'));var util=require(_0xbf72('0x6'));var path=require(_0xbf72('0x7'));var sox=require(_0xbf72('0x8'));var csv=require(_0xbf72('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xbf72('0xa'));var squel=require(_0xbf72('0xb'));var crypto=require(_0xbf72('0xc'));var jsforce=require(_0xbf72('0xd'));var deskjs=require(_0xbf72('0xe'));var toCsv=require(_0xbf72('0x9'));var querystring=require('querystring');var Papa=require(_0xbf72('0xf'));var Redis=require('ioredis');var authService=require(_0xbf72('0x10'));var qs=require(_0xbf72('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbf72('0x12'));var logger=require(_0xbf72('0x13'))(_0xbf72('0x14'));var utils=require(_0xbf72('0x15'));var config=require(_0xbf72('0x16'));var db=require(_0xbf72('0x17'))['db'];config[_0xbf72('0x18')]=_[_0xbf72('0x19')](config['redis'],{'host':_0xbf72('0x1a'),'port':0x18eb});var socket=require(_0xbf72('0x1b'))(new Redis(config[_0xbf72('0x18')]));require('./smsInteraction.socket')[_0xbf72('0x1c')](socket);function respondWithStatusCode(_0x4f4fa5,_0x5625b3){_0x5625b3=_0x5625b3||0xcc;return function(_0x4a79df){if(_0x4a79df){return _0x4f4fa5[_0xbf72('0x1d')](_0x5625b3);}return _0x4f4fa5[_0xbf72('0x1e')](_0x5625b3)[_0xbf72('0x1f')]();};}function respondWithResult(_0x723eb1,_0x39d0cd){_0x39d0cd=_0x39d0cd||0xc8;return function(_0x160d61){if(_0x160d61){return _0x723eb1['status'](_0x39d0cd)[_0xbf72('0x20')](_0x160d61);}};}function respondWithFilteredResult(_0xeb7183,_0x2a8609){return function(_0x3d4dea){if(_0x3d4dea){var _0x27dadc=_0x3d4dea[_0xbf72('0x21')],_0x5b5fc9=_0x2a8609[_0xbf72('0x22')],_0x51d4c9=_0x2a8609[_0xbf72('0x22')]+_0x2a8609[_0xbf72('0x23')],_0x1b8d73;if(_0x51d4c9>=_0x27dadc){_0x51d4c9=_0x27dadc;_0x1b8d73=0xc8;}else{_0x1b8d73=0xce;}_0xeb7183[_0xbf72('0x1e')](_0x1b8d73);return _0xeb7183[_0xbf72('0x24')]('Content-Range',_0x5b5fc9+'-'+_0x51d4c9+'/'+_0x27dadc)[_0xbf72('0x20')](_0x3d4dea);}return null;};}function patchUpdates(_0x42a193){return function(_0xcd9c0b){try{jsonpatch[_0xbf72('0x25')](_0xcd9c0b,_0x42a193,!![]);}catch(_0x3486f3){return BPromise['reject'](_0x3486f3);}return _0xcd9c0b[_0xbf72('0x26')]();};}function saveUpdates(_0x1de926,_0x536071){return function(_0x35c40f){if(_0x35c40f){return _0x35c40f[_0xbf72('0x27')](_0x1de926)[_0xbf72('0x28')](function(_0x4c7f3d){return _0x4c7f3d;});}return null;};}function removeEntity(_0x44f3f9,_0x428361){return function(_0x44d456){if(_0x44d456){return _0x44d456[_0xbf72('0x29')]()['then'](function(){_0x44f3f9[_0xbf72('0x1e')](0xcc)[_0xbf72('0x1f')]();});}};}function handleEntityNotFound(_0x1c8b8b,_0x54fdfe){return function(_0x3b3171){if(!_0x3b3171){_0x1c8b8b[_0xbf72('0x1d')](0x194);}return _0x3b3171;};}function handleError(_0x3df816,_0x1a2f55){_0x1a2f55=_0x1a2f55||0x1f4;return function(_0x15d60d){logger[_0xbf72('0x2a')](_0x15d60d[_0xbf72('0x2b')]);if(_0x15d60d[_0xbf72('0x2c')]){delete _0x15d60d[_0xbf72('0x2c')];}_0x3df816[_0xbf72('0x1e')](_0x1a2f55)[_0xbf72('0x2d')](_0x15d60d);};}function getInteractionUsers(_0x20e747,_0x4a6ccf){return new BPromise(function(_0xb648f2,_0x37a233){try{if(_0x4a6ccf[_0x20e747['id']]){_0x20e747['Users']=_[_0xbf72('0x2e')](_0x4a6ccf[_0x20e747['id']],function(_0x475a54){return{'id':_0x475a54['id'],'fullname':_0x475a54[_0xbf72('0x2f')]};});}}catch(_0x28850d){_0x37a233(_0x28850d);}_0xb648f2(_0x20e747);});}function getInteractionTags(_0xb1ee4e,_0x82c0f0){return new BPromise(function(_0x35ecdc,_0x209b2b){try{if(_0xb1ee4e[_0xbf72('0x30')]){_0xb1ee4e[_0xbf72('0x31')]=[];_0xb1ee4e[_0xbf72('0x30')][_0xbf72('0x32')](',')[_0xbf72('0x33')](function(_0x3ad363){_0xb1ee4e['Tags'][_0xbf72('0x34')](_0x82c0f0[_0x3ad363]);});}delete _0xb1ee4e[_0xbf72('0x30')];}catch(_0x3f47e6){_0x209b2b(_0x3f47e6);}_0x35ecdc(_0xb1ee4e);});}function updateSmsInteraction(_0x479cfe,_0x586537,_0x5c8bb4){return new BPromise(function(_0x2755c3,_0x80d176){return getInteractionUsers(_0x479cfe,_0x5c8bb4)[_0xbf72('0x28')](function(_0x52d979){return getInteractionTags(_0x52d979,_0x586537);})[_0xbf72('0x28')](function(_0x4c9662){_0x2755c3(_0x4c9662);})['catch'](function(_0x1158d3){_0x80d176(_0x1158d3);});});}exports['index']=function(_0x13ab4f,_0x202497){var _0x5c2f60={},_0x4aac2f={},_0x424669={'count':0x0,'rows':[]};var _0xc5edc4=_[_0xbf72('0x2e')](db[_0xbf72('0x35')][_0xbf72('0x36')],function(_0x26c91c){return{'name':_0x26c91c[_0xbf72('0x37')],'type':_0x26c91c[_0xbf72('0x38')][_0xbf72('0x39')]};});_0x4aac2f['model']=_[_0xbf72('0x2e')](_0xc5edc4,_0xbf72('0x2c'));_0x4aac2f[_0xbf72('0x3a')]=_[_0xbf72('0x3b')](_0x13ab4f['query']);_0x4aac2f[_0xbf72('0x3c')]=_[_0xbf72('0x3d')](_0x4aac2f['model'],_0x4aac2f[_0xbf72('0x3a')]);_0x5c2f60['attributes']=_['intersection'](_0x4aac2f['model'],qs['fields'](_0x13ab4f[_0xbf72('0x3a')]['fields']));_0x5c2f60['attributes']=_0x5c2f60[_0xbf72('0x3e')]['length']?_0x5c2f60[_0xbf72('0x3e')]:_0x4aac2f[_0xbf72('0x3f')];if(!_0x13ab4f['query'][_0xbf72('0x40')]('nolimit')){_0x5c2f60['limit']=qs[_0xbf72('0x23')](_0x13ab4f[_0xbf72('0x3a')][_0xbf72('0x23')]);_0x5c2f60[_0xbf72('0x22')]=qs[_0xbf72('0x22')](_0x13ab4f[_0xbf72('0x3a')][_0xbf72('0x22')]);}_0x5c2f60[_0xbf72('0x41')]=qs['sort'](_0x13ab4f[_0xbf72('0x3a')][_0xbf72('0x42')]);_0x5c2f60['where']=qs[_0xbf72('0x3c')](_['pick'](_0x13ab4f['query'],_0x4aac2f[_0xbf72('0x3c')]),_0xc5edc4);var _0x15e4c7=[];var _0x3992fd=squel[_0xbf72('0x43')]()[_0xbf72('0x44')]('id')['field']('name')['field'](_0xbf72('0x45'))[_0xbf72('0x46')](_0xbf72('0x47'));var _0x2a679a=squel['select']()['field'](_0xbf72('0x48'))['field'](_0xbf72('0x49'))[_0xbf72('0x44')](_0xbf72('0x4a'))[_0xbf72('0x46')]('user_has_sms_interactions','ui')[_0xbf72('0x4b')](_0xbf72('0x4c'),'u',_0xbf72('0x4d'));var _0x1da27a=squel['select']()[_0xbf72('0x46')](_0xbf72('0x4e'),'i')['left_join'](_0xbf72('0x4f'),'c',_0xbf72('0x50'))[_0xbf72('0x4b')](_0xbf72('0x4c'),'o',_0xbf72('0x51'))[_0xbf72('0x4b')](_0xbf72('0x52'),'a','a.id\x20=\x20i.SmsAccountId')['left_join']('sms_messages','me',_0xbf72('0x53'))['left_join'](_0xbf72('0x54'),'it','it.SmsInteractionId\x20=\x20i.id')['left_join']('tools_tags','t',_0xbf72('0x55'));var _0x15a271=squel[_0xbf72('0x56')]();var _0x3304b1=[];var _0x3d36de=squel[_0xbf72('0x56')]();var _0x530663;if(_0x13ab4f[_0xbf72('0x3a')]['search']){_0x530663=as[_0xbf72('0x57')](_0x13ab4f['query'][_0xbf72('0x58')]);var _0x199473=_0x530663[_0xbf72('0x59')];for(var _0x1fd1f8=0x0;_0x1fd1f8<_0x530663[_0xbf72('0x5a')][_0xbf72('0x5b')];_0x1fd1f8++){var _0x578b07=_0x530663[_0xbf72('0x5a')][_0x1fd1f8];var _0x3f6b6f='i';var _0x5c54fe=_[_0xbf72('0x5c')](_0xc5edc4,[_0xbf72('0x2c'),_0x578b07[_0xbf72('0x44')]]);if(!_0x5c54fe){switch(_0x578b07['field']){case _0xbf72('0x5d'):if(_0x578b07[_0xbf72('0x5e')]==0x1){_0x1da27a[_0xbf72('0x5f')]('`'+_0x578b07[_0xbf72('0x44')]+_0xbf72('0x60'));}else{_0x1da27a['having']('`'+_0x578b07[_0xbf72('0x44')]+_0xbf72('0x61'));}break;case'Contact':if(_0x578b07[_0xbf72('0x62')]==='$substring'){if(_0x578b07['value'][_0xbf72('0x32')]('\x20')[_0xbf72('0x5b')]>0x1){_0x15a271[_0x199473](_0xbf72('0x63'),qs[_0xbf72('0x64')](_0x578b07[_0xbf72('0x5e')]),null);}else{var _0x527061='%'+_0x578b07['value']+'%';_0x15a271[_0x199473]('c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?',_0x527061,_0x527061,_0x527061);}}else{_0x5c54fe=_[_0xbf72('0x5c')](_0xc5edc4,[_0xbf72('0x2c'),_0xbf72('0x65')]);_0x578b07[_0xbf72('0x44')]='ContactId';_0x537398=as['buildExpression'](_0x3f6b6f,_0x5c54fe[_0xbf72('0x38')],_0x578b07);_0x15a271[_0x199473](_0x537398[_0xbf72('0x66')],_0x537398[_0xbf72('0x5e')]['start'],_0x537398[_0xbf72('0x5e')]['end']);}break;case _0xbf72('0x67'):var _0x3da80c=_0x578b07['value'][_0xbf72('0x32')](',')[_0xbf72('0x2e')](function(_0x55ac06){return Number(_0x55ac06);});_0x3da80c[_0xbf72('0x33')](function(_0x46f908){_0x3d36de['or'](_0xbf72('0x68'),'%,'+_0x46f908+',%');});_0x3304b1=_['union'](_0x3304b1,_0x3da80c);break;case'User':if(_0x578b07['operator']===_0xbf72('0x69')){_0x15a271[_0x199473](_0xbf72('0x6a'),'%'+_0x578b07[_0xbf72('0x5e')]+'%',null);}else{_0x5c54fe=_[_0xbf72('0x5c')](_0xc5edc4,[_0xbf72('0x2c'),_0xbf72('0x6b')]);_0x578b07[_0xbf72('0x44')]=_0xbf72('0x6b');_0x537398=as[_0xbf72('0x6c')](_0x3f6b6f,_0x5c54fe['type'],_0x578b07);_0x15a271[_0x199473](_0x537398[_0xbf72('0x66')],_0x537398[_0xbf72('0x5e')]['start'],_0x537398[_0xbf72('0x5e')][_0xbf72('0x1f')]);}break;case _0xbf72('0x6d'):_0x537398=as[_0xbf72('0x6c')]('me',null,_0x578b07);_0x15a271[_0x199473](_0x537398[_0xbf72('0x66')],_0x537398[_0xbf72('0x5e')][_0xbf72('0x6e')],_0x537398[_0xbf72('0x5e')][_0xbf72('0x1f')]);break;}}else{var _0x537398=as['buildExpression'](_0x3f6b6f,_0x5c54fe[_0xbf72('0x38')],_0x578b07);_0x15a271[_0x199473](_0x537398[_0xbf72('0x66')],_0x537398[_0xbf72('0x5e')][_0xbf72('0x6e')],_0x537398[_0xbf72('0x5e')][_0xbf72('0x1f')]);}}}else{var _0x3f2c1f=_(_0x13ab4f[_0xbf72('0x3a')])['keys']()[_0xbf72('0x2e')](function(_0x2cb706){return _[_0xbf72('0x6f')](_0xc5edc4,[_0xbf72('0x2c'),_0x2cb706])?_0x2cb706:undefined;})[_0xbf72('0x70')]()[_0xbf72('0x5e')]();if(!_[_0xbf72('0x71')](_0x3f2c1f)){_0x3f2c1f['forEach'](function(_0x428902){if(_0x428902===_0xbf72('0x72')){_0x1da27a[_0xbf72('0x73')](_0xbf72('0x74'),[][_0xbf72('0x75')](_0x13ab4f[_0xbf72('0x3a')][_0x428902]));}else if(_0x428902===_0xbf72('0x76')){var _0x25b7ea=JSON['parse'](_0x13ab4f[_0xbf72('0x3a')][_0x428902])[_0xbf72('0x77')];var _0x17ab12=JSON['parse'](_0x13ab4f[_0xbf72('0x3a')][_0x428902])[_0xbf72('0x78')];_0x1da27a['where'](_0xbf72('0x79'),_0x25b7ea,_0x17ab12);}else{if(_0x13ab4f[_0xbf72('0x3a')][_0x428902]==='null'){_0x1da27a[_0xbf72('0x73')]('i.'+_0x428902+_0xbf72('0x7a'));}else{_0x1da27a['where']('i.'+_0x428902+_0xbf72('0x7b'),_0x13ab4f[_0xbf72('0x3a')][_0x428902]);}}});}if(_0x13ab4f[_0xbf72('0x3a')][_0xbf72('0x7c')]){if(_0x13ab4f[_0xbf72('0x3a')][_0xbf72('0x7c')]==0x1){_0x1da27a[_0xbf72('0x5f')]('`unreadMessages`\x20=\x200');}else{_0x1da27a[_0xbf72('0x5f')](_0xbf72('0x7d'));}}if(_0x13ab4f['query'][_0xbf72('0x7e')]){_0x3304b1=_['isArray'](_0x13ab4f['query'][_0xbf72('0x7e')])?_0x13ab4f[_0xbf72('0x3a')][_0xbf72('0x7e')]:new Array(_0x13ab4f[_0xbf72('0x3a')][_0xbf72('0x7e')]);_0x3304b1[_0xbf72('0x33')](function(_0x50f70c){_0x3d36de['or'](_0xbf72('0x68'),'%,'+_0x50f70c+',%');});}if(_0x13ab4f[_0xbf72('0x3a')][_0xbf72('0x7f')]){var _0x33257f=_0x13ab4f['query'][_0xbf72('0x7f')][_0xbf72('0x80')]('\x5c','\x5c\x5c')[_0xbf72('0x80')]('\x27\x27',_0xbf72('0x81'));if(qs['isNumeric'](_0x33257f)){_0x15a271['or'](_0xbf72('0x82'),_0x33257f+'%')['or']('i.phone\x20LIKE\x20?',_0x33257f+'%');}else{_0x15a271['or'](_0xbf72('0x83'),qs[_0xbf72('0x64')](_0x33257f))['or'](_0xbf72('0x84'),_0x33257f+'%');}}}_0x1da27a['where'](_0x15a271);_0x1da27a[_0xbf72('0x85')](_0xbf72('0x86'));var _0x289dcc={'type':db[_0xbf72('0x87')][_0xbf72('0x88')][_0xbf72('0x89')],'raw':!![]};var _0x36a3dc=_0x1da27a[_0xbf72('0x8a')]();_0x36a3dc[_0xbf72('0x44')](_0xbf72('0x86'));_0x36a3dc[_0xbf72('0x44')](_0xbf72('0x8b'),'unreadMessages');if(_0x5c2f60[_0xbf72('0x41')]){_0x5c2f60[_0xbf72('0x41')][_0xbf72('0x33')](function(_0x594b73){_0x1da27a[_0xbf72('0x41')]('i.'+_0x594b73[0x0],_0x594b73[0x1]==='DESC'?![]:!![]);});}if(!_[_0xbf72('0x71')](_0x3304b1)){_0x1da27a[_0xbf72('0x5f')](_0x3d36de);_0x36a3dc[_0xbf72('0x73')](_0xbf72('0x8c'),_0x3304b1);}BPromise[_0xbf72('0x8d')]()[_0xbf72('0x28')](function(){if(!_0x530663){if(_0x13ab4f['query'][_0xbf72('0x72')]||_0x13ab4f['query'][_0xbf72('0x8e')])return;_0x36a3dc['where'](_0xbf72('0x8f'));_0x1da27a[_0xbf72('0x73')](_0xbf72('0x8f'));return;}return _0x13ab4f[_0xbf72('0x90')][_0xbf72('0x91')]({'attributes':['id'],'raw':!![]})[_0xbf72('0x28')](function(_0x3ba2f9){if(_[_0xbf72('0x71')](_0x3ba2f9)){_0x36a3dc[_0xbf72('0x73')](_0xbf72('0x92'));_0x1da27a[_0xbf72('0x73')](_0xbf72('0x92'));}else{_0x36a3dc[_0xbf72('0x73')](_0xbf72('0x74'),_[_0xbf72('0x2e')](_0x3ba2f9,'id'));_0x1da27a['where']('i.SmsAccountId\x20IN\x20?',_[_0xbf72('0x2e')](_0x3ba2f9,'id'));}});})['then'](function(){db[_0xbf72('0x93')][_0xbf72('0x3a')](_0x36a3dc['toString'](),_0x289dcc)[_0xbf72('0x28')](function(_0xffecec){_0x424669[_0xbf72('0x21')]=_0xffecec['length'];if(_0x424669[_0xbf72('0x21')]===0x0)return[];return db['sequelize'][_0xbf72('0x3a')](_0x3992fd[_0xbf72('0x94')](),_0x289dcc)['then'](function(_0x2e0923){_0x15e4c7=_[_0xbf72('0x95')](_0x2e0923,'id');_0x289dcc=_[_0xbf72('0x96')](_0x289dcc,{'model':db[_0xbf72('0x35')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x13ab4f[_0xbf72('0x3a')][_0xbf72('0x97')]){_0x5c2f60[_0xbf72('0x3e')][_0xbf72('0x33')](function(_0x55b183){_0x1da27a['field']('i.'+_0x55b183);});}else{_0x1da27a[_0xbf72('0x44')](_0xbf72('0x8b'),_0xbf72('0x5d'));_0x1da27a['field'](_0xbf72('0x98'),'Account.key');_0x1da27a[_0xbf72('0x44')]('a.mandatoryDisposition',_0xbf72('0x99'));_0x1da27a[_0xbf72('0x44')](_0xbf72('0x9a'));_0x1da27a['field'](_0xbf72('0x9b'),_0xbf72('0x9c'));_0x1da27a['field'](_0xbf72('0x9d'),'Contact.lastName');_0x1da27a[_0xbf72('0x44')](_0xbf72('0x9e'),_0xbf72('0x9f'));_0x1da27a[_0xbf72('0x44')](_0xbf72('0xa0'),_0xbf72('0xa1'));_0x1da27a['field'](_0xbf72('0xa2'),_0xbf72('0xa3'));_0x1da27a[_0xbf72('0x44')]('c.fax',_0xbf72('0xa4'));_0x1da27a[_0xbf72('0x44')]('o.fullname','Owner.fullname');_0x1da27a['field'](_0xbf72('0xa5'),_0xbf72('0xa6'));_0x1da27a[_0xbf72('0x44')](_0xbf72('0xa7'),'TagIds');}if(_0x5c2f60[_0xbf72('0x23')])_0x1da27a['limit'](_0x5c2f60[_0xbf72('0x23')]);if(_0x5c2f60[_0xbf72('0x22')])_0x1da27a[_0xbf72('0x22')](_0x5c2f60['offset']);return db[_0xbf72('0x93')]['query'](_0x1da27a[_0xbf72('0x94')](),_0x289dcc);})[_0xbf72('0x28')](function(_0x2b7772){_0x2a679a['where'](_0xbf72('0xa8'),_['map'](_0x2b7772,'id'));return db['sequelize'][_0xbf72('0x3a')](_0x2a679a[_0xbf72('0x94')](),_0x289dcc)['then'](function(_0x5a2710){var _0x45e0b6=_['groupBy'](_0x5a2710,'SmsInteractionId');var _0x2fa244=[];_0x2b7772[_0xbf72('0x33')](function(_0x2d390d){_0x2fa244['push'](updateSmsInteraction(_0x2d390d,_0x15e4c7,_0x45e0b6));});return BPromise[_0xbf72('0xa9')](_0x2fa244);});});})[_0xbf72('0x28')](function(_0x4ffdc5){_0x424669[_0xbf72('0xaa')]=_0x4ffdc5;return _0x424669;})['then'](respondWithFilteredResult(_0x202497,_0x5c2f60));})[_0xbf72('0xab')](handleError(_0x202497,null));};exports[_0xbf72('0xac')]=function(_0x5bc71f,_0xcdfdca){var _0x126df6={'raw':![],'where':{'id':_0x5bc71f['params']['id']}},_0x1294c3={};_0x1294c3[_0xbf72('0x3f')]=_[_0xbf72('0x3b')](db[_0xbf72('0x35')][_0xbf72('0x36')]);_0x1294c3['query']=_[_0xbf72('0x3b')](_0x5bc71f[_0xbf72('0x3a')]);_0x1294c3[_0xbf72('0x3c')]=_[_0xbf72('0x3d')](_0x1294c3[_0xbf72('0x3f')],_0x1294c3[_0xbf72('0x3a')]);_0x126df6[_0xbf72('0x3e')]=_['intersection'](_0x1294c3[_0xbf72('0x3f')],qs['fields'](_0x5bc71f[_0xbf72('0x3a')][_0xbf72('0x97')]));_0x126df6['attributes']=_0x126df6[_0xbf72('0x3e')][_0xbf72('0x5b')]?_0x126df6[_0xbf72('0x3e')]:_0x1294c3['model'];if(_0x5bc71f[_0xbf72('0x3a')][_0xbf72('0xad')]){_0x126df6['include']=[{'all':!![]}];}_0x126df6=_[_0xbf72('0x96')]({},_0x126df6,_0x5bc71f['options']);return db[_0xbf72('0x35')]['find'](_0x126df6)[_0xbf72('0x28')](handleEntityNotFound(_0xcdfdca,null))[_0xbf72('0x28')](respondWithResult(_0xcdfdca,null))[_0xbf72('0xab')](handleError(_0xcdfdca,null));};exports[_0xbf72('0xae')]=function(_0x17318e,_0x197fc7){return db[_0xbf72('0x35')][_0xbf72('0xae')](_0x17318e[_0xbf72('0x6d')],{})[_0xbf72('0x28')](respondWithResult(_0x197fc7,0xc9))[_0xbf72('0xab')](handleError(_0x197fc7,null));};exports[_0xbf72('0x27')]=function(_0x3d21dc,_0x2f6ffe){if(_0x3d21dc[_0xbf72('0x6d')]['id']){delete _0x3d21dc[_0xbf72('0x6d')]['id'];}return db[_0xbf72('0x35')]['find']({'where':{'id':_0x3d21dc['params']['id']}})[_0xbf72('0x28')](handleEntityNotFound(_0x2f6ffe,null))[_0xbf72('0x28')](saveUpdates(_0x3d21dc['body'],null))[_0xbf72('0x28')](respondWithResult(_0x2f6ffe,null))[_0xbf72('0xab')](handleError(_0x2f6ffe,null));};exports['destroy']=function(_0x2b3de2,_0x59a0c1){return db['SmsInteraction']['find']({'where':{'id':_0x2b3de2[_0xbf72('0xaf')]['id']}})['then'](handleEntityNotFound(_0x59a0c1,null))['then'](removeEntity(_0x59a0c1,null))[_0xbf72('0xab')](handleError(_0x59a0c1,null));};exports[_0xbf72('0xb0')]=function(_0x3dc0a4,_0x35517f){return db[_0xbf72('0x35')][_0xbf72('0xb0')]()[_0xbf72('0x28')](respondWithResult(_0x35517f,null))[_0xbf72('0xab')](handleError(_0x35517f,null));};exports[_0xbf72('0xb1')]=function(_0x7d6f18,_0x54993a,_0x3c7929){return db[_0xbf72('0xb2')][_0xbf72('0x5c')]({'where':{'id':_0x7d6f18['params']['id']}})[_0xbf72('0x28')](handleEntityNotFound(_0x54993a,null))[_0xbf72('0x28')](function(_0x2e3519){if(_0x2e3519){return _0x2e3519[_0xbf72('0xb1')](_0x7d6f18['body'][_0xbf72('0xb3')],_[_0xbf72('0xb4')](_0x7d6f18[_0xbf72('0x6d')],[_0xbf72('0xb3'),'id'])||{});}})['then'](respondWithResult(_0x54993a,null))[_0xbf72('0xab')](handleError(_0x54993a,null));};exports[_0xbf72('0xb5')]=function(_0x42663e,_0x812ece,_0x375054){var _0x1e716f={'raw':![],'where':{}};var _0x52d372={};var _0x47da7d={'count':0x0,'rows':[]};return db[_0xbf72('0x35')][_0xbf72('0xb6')]({'where':{'id':_0x42663e[_0xbf72('0xaf')]['id']}})['then'](handleEntityNotFound(_0x812ece,null))[_0xbf72('0x28')](function(_0x2c5779){if(_0x2c5779){_0x52d372['model']=_[_0xbf72('0x3b')](db[_0xbf72('0xb2')]['rawAttributes']);_0x52d372[_0xbf72('0x3a')]=_[_0xbf72('0x3b')](_0x42663e['query']);_0x52d372['filters']=_[_0xbf72('0x3d')](_0x52d372[_0xbf72('0x3f')],_0x52d372[_0xbf72('0x3a')]);_0x1e716f[_0xbf72('0x3e')]=_['intersection'](_0x52d372[_0xbf72('0x3f')],qs[_0xbf72('0x97')](_0x42663e[_0xbf72('0x3a')]['fields']));_0x1e716f['attributes']=_0x1e716f['attributes'][_0xbf72('0x5b')]?_0x1e716f[_0xbf72('0x3e')]:_0x52d372[_0xbf72('0x3f')];if(!_0x42663e[_0xbf72('0x3a')]['hasOwnProperty'](_0xbf72('0xb7'))){_0x1e716f[_0xbf72('0x23')]=qs[_0xbf72('0x23')](_0x42663e[_0xbf72('0x3a')][_0xbf72('0x23')]);_0x1e716f[_0xbf72('0x22')]=qs[_0xbf72('0x22')](_0x42663e[_0xbf72('0x3a')][_0xbf72('0x22')]);}_0x1e716f[_0xbf72('0x41')]=qs['sort'](_0x42663e[_0xbf72('0x3a')][_0xbf72('0x42')]);_0x1e716f[_0xbf72('0x73')]=qs[_0xbf72('0x3c')](_['pick'](_0x42663e['query'],_0x52d372[_0xbf72('0x3c')]));_0x1e716f[_0xbf72('0x73')][_0xbf72('0xb8')]=_0x2c5779['id'];if(_0x42663e[_0xbf72('0x3a')][_0xbf72('0x7f')]){_0x1e716f['where']=_['merge'](_0x1e716f[_0xbf72('0x73')],{'$or':_[_0xbf72('0x2e')](_0x1e716f[_0xbf72('0x3e')],function(_0x465a51){var _0x2fd92a={};_0x2fd92a[_0x465a51]={'$like':'%'+_0x42663e[_0xbf72('0x3a')][_0xbf72('0x7f')]+'%'};return _0x2fd92a;})});}if(_0x42663e[_0xbf72('0x3a')][_0xbf72('0x77')]){var _0x250cb5=_0x42663e[_0xbf72('0x3a')]['$gte'][_0xbf72('0x32')](',');var _0x49dac9={};_0x49dac9[_0x250cb5[0x0]]={'$gte':moment(_0x250cb5[0x1])[_0xbf72('0xb9')](_0xbf72('0xba'))};_0x1e716f['where']=_[_0xbf72('0x96')](_0x1e716f['where'],_0x49dac9);}_0x1e716f=_[_0xbf72('0x96')]({},_0x1e716f,_0x42663e[_0xbf72('0xbb')]);return db['SmsMessage'][_0xbf72('0x21')]({'where':_0x1e716f[_0xbf72('0x73')]})[_0xbf72('0x28')](function(_0x11fcad){_0x47da7d['count']=_0x11fcad;if(_0x42663e['query'][_0xbf72('0xad')]){_0x1e716f[_0xbf72('0xbc')]=[{'all':!![]}];}return db[_0xbf72('0xb2')][_0xbf72('0xbd')](_0x1e716f);})[_0xbf72('0x28')](function(_0x7b2e81){_0x47da7d[_0xbf72('0xaa')]=_0x7b2e81;return _0x47da7d;});}})[_0xbf72('0x28')](respondWithFilteredResult(_0x812ece,_0x1e716f))[_0xbf72('0xab')](handleError(_0x812ece,null));};exports[_0xbf72('0xbe')]=function(_0xbeac16,_0x27c6a3,_0x1306b9){return db[_0xbf72('0x35')]['find']({'where':{'id':_0xbeac16[_0xbf72('0xaf')]['id']}})['then'](handleEntityNotFound(_0x27c6a3,null))[_0xbf72('0x28')](function(_0x369ae8){if(_0x369ae8){return _0x369ae8[_0xbf72('0xbf')](_0xbeac16['body'][_0xbf72('0xb3')],_[_0xbf72('0xb4')](_0xbeac16[_0xbf72('0x6d')],[_0xbf72('0xb3'),'id'])||{})[_0xbf72('0xc0')](function(){return db['Tag'][_0xbf72('0xbd')]({'attributes':['id',_0xbf72('0x2c'),_0xbf72('0x45')],'where':{'id':_0xbeac16[_0xbf72('0x6d')][_0xbf72('0xb3')]}});})[_0xbf72('0x28')](function(_0x4fa0f1){socket[_0xbf72('0xc1')]('smsInteractionTags:save',{'id':Number(_0xbeac16['params']['id']),'tags':_0x4fa0f1||[]});return{'id':Number(_0xbeac16[_0xbf72('0xaf')]['id']),'tags':_0x4fa0f1||[]};});}})[_0xbf72('0x28')](respondWithResult(_0x27c6a3,null))[_0xbf72('0xab')](handleError(_0x27c6a3,null));};exports['removeTags']=function(_0x59ce68,_0x4af0b4,_0x29a1bd){return db[_0xbf72('0x35')][_0xbf72('0x5c')]({'where':{'id':_0x59ce68[_0xbf72('0xaf')]['id']}})[_0xbf72('0x28')](handleEntityNotFound(_0x4af0b4,null))[_0xbf72('0x28')](function(_0x35f0cc){if(_0x35f0cc){return _0x35f0cc[_0xbf72('0xc2')](_0x59ce68[_0xbf72('0x3a')][_0xbf72('0xb3')]);}})[_0xbf72('0x28')](respondWithStatusCode(_0x4af0b4,null))['catch'](handleError(_0x4af0b4,null));};exports[_0xbf72('0xc3')]=function(_0x810cdf,_0x15f8f4){var _0x47defd=moment()['unix']()[_0xbf72('0x94')]();var _0x49e3a4=path[_0xbf72('0xc4')](config[_0xbf72('0xc5')],_0xbf72('0xc6'),_0xbf72('0xc7'),_0xbf72('0xc8'));var _0x57d05b=path[_0xbf72('0xc4')](config['root'],_0xbf72('0xc6'),'files',_0xbf72('0xc9'));var _0x16d4cd=path['join'](_0x49e3a4,_0x47defd);var _0x2ac801=util['format'](_0xbf72('0xca'),_0x810cdf[_0xbf72('0xaf')]['id'],_0x47defd);var _0x7dbb1=path['join'](_0x49e3a4,_0x2ac801);var _0x445842=[];_0x445842['push']({'model':db[_0xbf72('0xcb')],'as':_0xbf72('0xcb'),'attributes':['id',_0xbf72('0x2f')],'raw':!![]});_0x445842['push']({'model':db[_0xbf72('0xcc')],'as':'Contact','attributes':['id',_0xbf72('0xcd'),_0xbf72('0xce')],'raw':!![]});var _0x47d1fb=[{'model':db[_0xbf72('0xb2')],'as':_0xbf72('0xcf'),'attributes':['id',_0xbf72('0x6d'),_0xbf72('0x76'),_0xbf72('0xd0'),_0xbf72('0xd1'),_0xbf72('0x7c')],'include':_0x445842}];_0x47d1fb[_0xbf72('0x34')]({'model':db[_0xbf72('0xd2')],'as':_0xbf72('0xd3'),'attributes':['id',_0xbf72('0x2c')]});_0x47d1fb[_0xbf72('0x34')]({'model':db[_0xbf72('0xcb')],'as':'Owner','attributes':['id','fullname']});return db[_0xbf72('0x35')]['find']({'where':{'id':_0x810cdf[_0xbf72('0xaf')]['id']},'include':_0x47d1fb})['then'](handleEntityNotFound(_0x15f8f4,null))['then'](function(_0x1a3f8c){if(_0x1a3f8c){var _0x5f71ba=_0x1a3f8c[_0xbf72('0xd4')]({'plain':!![]});fs[_0xbf72('0xd5')](_0x16d4cd);var _0xc70212={'format':'A4','border':_0xbf72('0xd6'),'header':{'height':'40px','contents':{'first':_0xbf72('0xd7')}},'footer':{'height':_0xbf72('0xd8'),'contents':{'default':util[_0xbf72('0xb9')]('<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[_0xbf72('0xb9')](_0xbf72('0xd9'),'Sms',_0x5f71ba['id']),moment()[_0xbf72('0xb9')]('YYYY-MM-DD')[_0xbf72('0x94')]())}}};var _0x383749={'channel':_0xbf72('0xda'),'account':_0x5f71ba[_0xbf72('0xd3')][_0xbf72('0x2c')],'agent':_0x5f71ba[_0xbf72('0xdb')]?_0x5f71ba[_0xbf72('0xdb')][_0xbf72('0x2f')]:_0xbf72('0xdc'),'createdAt':moment(_0x5f71ba[_0xbf72('0x76')])[_0xbf72('0xb9')](_0xbf72('0xba'))[_0xbf72('0x94')](),'closedAt':_0x5f71ba[_0xbf72('0xdd')]?moment(_0x5f71ba[_0xbf72('0xde')])['format'](_0xbf72('0xba'))['toString']():'','disposition':_0x5f71ba[_0xbf72('0xdf')],'messages':_(_0x5f71ba[_0xbf72('0xcf')])[_0xbf72('0x7f')]({'secret':![]})[_0xbf72('0x2e')](function(_0x29dfd1){return{'date':moment(_0x29dfd1[_0xbf72('0x76')])[_0xbf72('0xb9')](_0xbf72('0xba'))[_0xbf72('0x94')](),'sender':_0x29dfd1[_0xbf72('0xd0')]===_0xbf72('0xe0')?_0x29dfd1[_0xbf72('0xcb')]?_0x29dfd1[_0xbf72('0xcb')][_0xbf72('0x2f')]:_0xbf72('0xe1'):_0x29dfd1[_0xbf72('0xe2')][_0xbf72('0xcd')]+(_0x29dfd1[_0xbf72('0xe2')]['lastName']?'\x20'+_0x29dfd1[_0xbf72('0xe2')][_0xbf72('0xce')]:''),'body':_0x29dfd1[_0xbf72('0x6d')],'direction':_0x29dfd1[_0xbf72('0xd0')]==='out'?'A':'C','secret':_0x29dfd1[_0xbf72('0xd1')],'read':_0x29dfd1[_0xbf72('0x7c')]};})[_0xbf72('0x5e')]()};return ejs[_0xbf72('0xe3')](path[_0xbf72('0xc4')](config[_0xbf72('0xc5')],_0xbf72('0xc6'),'views',_0xbf72('0xe4')),{'interaction':_0x383749})[_0xbf72('0x28')](function(_0x5c77b4){return new BPromise(function(_0x2c14c9,_0xe82795){pdf[_0xbf72('0xae')](_0x5c77b4,_0xc70212)[_0xbf72('0xe5')](path[_0xbf72('0xc4')](_0x16d4cd,_0xbf72('0xe6')+_0x5f71ba['id']+'-'+_0x47defd+_0xbf72('0xe7')),function(_0x1af909,_0x588469){if(_0x1af909)return _0xe82795(_0x1af909);_0x2c14c9(_0x588469);});});})[_0xbf72('0x28')](function(){return new BPromise(function(_0x3b5558,_0xc3eb94){zipdir(_0x16d4cd,{'saveTo':_0x7dbb1},function(_0x2fbc9f,_0x40bf3d){if(_0x2fbc9f)return _0xc3eb94(_0x2fbc9f);return _0x3b5558(_0x40bf3d);});})[_0xbf72('0x28')](function(){return new BPromise(function(_0x308385,_0x24e1fd){rimraf(_0x16d4cd,function(_0xd71399){if(_0xd71399)_0x24e1fd(_0xd71399);return _0x308385();});});})[_0xbf72('0x28')](function(){return _0x15f8f4[_0xbf72('0xc3')](_0x7dbb1,_0x2ac801,function(_0xd36e9a){if(_0xd36e9a){console['log'](_0xbf72('0xe8'),_0xd36e9a);}else{fs[_0xbf72('0xe9')](_0x7dbb1);}});});});}else{return _0x15f8f4['sendStatus'](0xc8);}})['catch'](handleError(_0x15f8f4,null));};
\ No newline at end of file
+var _0xb3dc=['intersection','attributes','fields','length','nolimit','sort','where','pick','filters','select','field','color','tools_tags','u.id','u.fullname','ui.SmsInteractionId','from','user_has_sms_interactions','left_join','users','u.id\x20=\x20ui.UserId','sms_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','a.id\x20=\x20i.SmsAccountId','me.SmsInteractionId\x20=\x20i.id','sms_interaction_has_tags','expr','search','parseSearch','sqlOperator','conditions','find','unreadMessages','value','having','`\x20>\x200','Contact','operator','$substring','split','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','buildExpression','text','keys','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','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','isNumeric','i.phone\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','group','i.id','Sequelize','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','order','DESC','t.id\x20IN\x20?','resolve','i.SmsAccountId\x20IS\x20NOT\x20NULL','agent','user','getSmsAccounts','i.SmsAccountId\x20IS\x20NULL','sequelize','toString','keyBy','merge','a.key','Account.key','c.firstName','Contact.firstName','c.lastName','c.email','Contact.email','c.phone','Contact.phone','c.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','ui.SmsInteractionId\x20IN\x20?','SmsInteractionId','push','all','params','rawAttributes','includeAll','include','options','create','body','describe','addMessage','ids','getMessages','findOne','hasOwnProperty','format','YYYY-MM-DD\x20HH:mm:ss','SmsMessage','findAll','rows','setTags','omit','spread','emit','smsInteractionTags:save','download','unix','join','files','tmp','server','attachments','transcript-%d-%s.zip','fullname','CmContact','firstName','lastName','direction','secret','SmsAccount','Owner','get','Sms','Account','N.A.','closedAt','disposition','out','System','renderFile','root','views','downloadInteraction.ejs','transcript-','err','unlinkSync','eml-format','rimraf','zip-dir','moment','bluebird','mustache','path','sox','to-csv','ejs','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../components/export/pdf','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsInteraction.socket','register','status','offset','undefined','limit','count','Content-Range','json','apply','update','then','destroy','end','sendStatus','error','stack','name','Users','map','TagIds','Tags','forEach','catch','waiting','talking','answered','unmanaged','closed','UserId','total','index','SmsInteraction','fieldName','type','key','model','query'];(function(_0x59fbb4,_0x4b63ee){var _0x19a8d8=function(_0x2847b8){while(--_0x2847b8){_0x59fbb4['push'](_0x59fbb4['shift']());}};_0x19a8d8(++_0x4b63ee);}(_0xb3dc,0xab));var _0xcb3d=function(_0x4607a4,_0x2cc9c9){_0x4607a4=_0x4607a4-0x0;var _0x1d7679=_0xb3dc[_0x4607a4];return _0x1d7679;};'use strict';var emlformat=require(_0xcb3d('0x0'));var rimraf=require(_0xcb3d('0x1'));var zipdir=require(_0xcb3d('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xcb3d('0x3'));var BPromise=require(_0xcb3d('0x4'));var Mustache=require(_0xcb3d('0x5'));var util=require('util');var path=require(_0xcb3d('0x6'));var sox=require(_0xcb3d('0x7'));var csv=require(_0xcb3d('0x8'));var ejs=require(_0xcb3d('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0xcb3d('0xa'));var crypto=require(_0xcb3d('0xb'));var jsforce=require(_0xcb3d('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xcb3d('0xd'));var Papa=require(_0xcb3d('0xe'));var Redis=require(_0xcb3d('0xf'));var authService=require(_0xcb3d('0x10'));var qs=require(_0xcb3d('0x11'));var as=require(_0xcb3d('0x12'));var pdf=require(_0xcb3d('0x13'));var hardwareService=require(_0xcb3d('0x14'));var logger=require(_0xcb3d('0x15'))(_0xcb3d('0x16'));var utils=require(_0xcb3d('0x17'));var config=require(_0xcb3d('0x18'));var licenseUtil=require('../../config/license/util');var db=require(_0xcb3d('0x19'))['db'];config[_0xcb3d('0x1a')]=_[_0xcb3d('0x1b')](config[_0xcb3d('0x1a')],{'host':_0xcb3d('0x1c'),'port':0x18eb});var socket=require(_0xcb3d('0x1d'))(new Redis(config[_0xcb3d('0x1a')]));require(_0xcb3d('0x1e'))[_0xcb3d('0x1f')](socket);function respondWithStatusCode(_0x6abbc8,_0x5b36e8){_0x5b36e8=_0x5b36e8||0xcc;return function(_0x7b3a96){if(_0x7b3a96){return _0x6abbc8['sendStatus'](_0x5b36e8);}return _0x6abbc8[_0xcb3d('0x20')](_0x5b36e8)['end']();};}function respondWithResult(_0x49808b,_0x4c7037){_0x4c7037=_0x4c7037||0xc8;return function(_0x433ec2){if(_0x433ec2){return _0x49808b['status'](_0x4c7037)['json'](_0x433ec2);}};}function respondWithFilteredResult(_0x57d92a,_0x274b35){return function(_0x37ad9f){if(_0x37ad9f){var _0x242a1b=typeof _0x274b35[_0xcb3d('0x21')]===_0xcb3d('0x22')&&typeof _0x274b35[_0xcb3d('0x23')]===_0xcb3d('0x22');var _0x2acce1=_0x37ad9f['count'];var _0x5b47b1=_0x242a1b?0x0:_0x274b35['offset'];var _0x424cea=_0x242a1b?_0x37ad9f[_0xcb3d('0x24')]:_0x274b35['offset']+_0x274b35[_0xcb3d('0x23')];var _0x5e3186;if(_0x424cea>=_0x2acce1){_0x424cea=_0x2acce1;_0x5e3186=0xc8;}else{_0x5e3186=0xce;}_0x57d92a[_0xcb3d('0x20')](_0x5e3186);return _0x57d92a['set'](_0xcb3d('0x25'),_0x5b47b1+'-'+_0x424cea+'/'+_0x2acce1)[_0xcb3d('0x26')](_0x37ad9f);}return null;};}function patchUpdates(_0x3fde17){return function(_0x4d0fd7){try{jsonpatch[_0xcb3d('0x27')](_0x4d0fd7,_0x3fde17,!![]);}catch(_0x35429c){return BPromise['reject'](_0x35429c);}return _0x4d0fd7['save']();};}function saveUpdates(_0x4b3dc4,_0x2f97dd){return function(_0x177a12){if(_0x177a12){return _0x177a12[_0xcb3d('0x28')](_0x4b3dc4)[_0xcb3d('0x29')](function(_0x3419c8){return _0x3419c8;});}return null;};}function removeEntity(_0x56002a,_0x16738f){return function(_0x21f84f){if(_0x21f84f){return _0x21f84f[_0xcb3d('0x2a')]()['then'](function(){_0x56002a[_0xcb3d('0x20')](0xcc)[_0xcb3d('0x2b')]();});}};}function handleEntityNotFound(_0x21f128,_0x347eac){return function(_0x1e80f2){if(!_0x1e80f2){_0x21f128[_0xcb3d('0x2c')](0x194);}return _0x1e80f2;};}function handleError(_0x59cabd,_0x21749b){_0x21749b=_0x21749b||0x1f4;return function(_0x27cef2){logger[_0xcb3d('0x2d')](_0x27cef2[_0xcb3d('0x2e')]);if(_0x27cef2[_0xcb3d('0x2f')]){delete _0x27cef2[_0xcb3d('0x2f')];}_0x59cabd['status'](_0x21749b)['send'](_0x27cef2);};}function getInteractionUsers(_0x3a4884,_0x1d4014){return new BPromise(function(_0x42ccc1,_0xcc6fd4){try{if(_0x1d4014[_0x3a4884['id']]){_0x3a4884[_0xcb3d('0x30')]=_[_0xcb3d('0x31')](_0x1d4014[_0x3a4884['id']],function(_0x10203a){return{'id':_0x10203a['id'],'fullname':_0x10203a['fullname']};});}}catch(_0x303b63){_0xcc6fd4(_0x303b63);}_0x42ccc1(_0x3a4884);});}function getInteractionTags(_0x49e868,_0x68c5c3){return new BPromise(function(_0x231532,_0x2c0b5a){try{if(_0x49e868[_0xcb3d('0x32')]){_0x49e868[_0xcb3d('0x33')]=[];_0x49e868['TagIds']['split'](',')[_0xcb3d('0x34')](function(_0x4de29c){_0x49e868[_0xcb3d('0x33')]['push'](_0x68c5c3[_0x4de29c]);});}delete _0x49e868[_0xcb3d('0x32')];}catch(_0x44b3e9){_0x2c0b5a(_0x44b3e9);}_0x231532(_0x49e868);});}function updateSmsInteraction(_0x4134f7,_0x4780a2,_0x18a3bb){return new BPromise(function(_0x49104c,_0x159ba6){return getInteractionUsers(_0x4134f7,_0x18a3bb)['then'](function(_0xa630b){return getInteractionTags(_0xa630b,_0x4780a2);})[_0xcb3d('0x29')](function(_0x443420){return getStateInteraction(_0x443420);})[_0xcb3d('0x29')](function(_0x30716a){_0x49104c(_0x30716a);})[_0xcb3d('0x35')](function(_0x498a7d){_0x159ba6(_0x498a7d);});});}function getStateInteraction(_0x45466d){return new BPromise(function(_0x131ef9){_0x45466d[_0xcb3d('0x36')]=0x0;_0x45466d[_0xcb3d('0x37')]=0x0;_0x45466d[_0xcb3d('0x38')]=0x0;_0x45466d[_0xcb3d('0x39')]=0x0;_0x45466d['total']=0x0;if(!_0x45466d['closed']&&!_0x45466d['UserId']){_0x45466d[_0xcb3d('0x36')]+=0x1;}if(!_0x45466d[_0xcb3d('0x3a')]&&_0x45466d['UserId']){_0x45466d[_0xcb3d('0x37')]+=0x1;if(_0x45466d[_0xcb3d('0x36')]){_0x45466d['waiting']-=0x1;}}if(_0x45466d[_0xcb3d('0x3a')]&&_0x45466d[_0xcb3d('0x3b')]){_0x45466d[_0xcb3d('0x38')]+=0x1;if(_0x45466d[_0xcb3d('0x37')]){_0x45466d[_0xcb3d('0x37')]-=0x1;}}if(_0x45466d[_0xcb3d('0x3a')]&&!_0x45466d['UserId']){_0x45466d[_0xcb3d('0x39')]+=0x1;if(_0x45466d['waiting']){_0x45466d[_0xcb3d('0x36')]-=0x1;}}_0x45466d[_0xcb3d('0x3c')]+=0x1;_0x131ef9(_0x45466d);});}exports[_0xcb3d('0x3d')]=function(_0x12da25,_0x3b2f30){var _0x163f2d={},_0x5d5e7e={},_0x22dc29={'count':0x0,'rows':[]};var _0x6c5eac=_['map'](db[_0xcb3d('0x3e')]['rawAttributes'],function(_0x307528){return{'name':_0x307528[_0xcb3d('0x3f')],'type':_0x307528[_0xcb3d('0x40')][_0xcb3d('0x41')]};});_0x5d5e7e[_0xcb3d('0x42')]=_[_0xcb3d('0x31')](_0x6c5eac,_0xcb3d('0x2f'));_0x5d5e7e[_0xcb3d('0x43')]=_['keys'](_0x12da25[_0xcb3d('0x43')]);_0x5d5e7e['filters']=_[_0xcb3d('0x44')](_0x5d5e7e[_0xcb3d('0x42')],_0x5d5e7e[_0xcb3d('0x43')]);_0x163f2d[_0xcb3d('0x45')]=_[_0xcb3d('0x44')](_0x5d5e7e['model'],qs[_0xcb3d('0x46')](_0x12da25['query'][_0xcb3d('0x46')]));_0x163f2d[_0xcb3d('0x45')]=_0x163f2d[_0xcb3d('0x45')][_0xcb3d('0x47')]?_0x163f2d['attributes']:_0x5d5e7e[_0xcb3d('0x42')];if(!_0x12da25[_0xcb3d('0x43')]['hasOwnProperty'](_0xcb3d('0x48'))){_0x163f2d[_0xcb3d('0x23')]=qs[_0xcb3d('0x23')](_0x12da25[_0xcb3d('0x43')][_0xcb3d('0x23')]);_0x163f2d[_0xcb3d('0x21')]=qs['offset'](_0x12da25[_0xcb3d('0x43')][_0xcb3d('0x21')]);}_0x163f2d['order']=qs[_0xcb3d('0x49')](_0x12da25[_0xcb3d('0x43')][_0xcb3d('0x49')]);_0x163f2d[_0xcb3d('0x4a')]=qs['filters'](_[_0xcb3d('0x4b')](_0x12da25[_0xcb3d('0x43')],_0x5d5e7e[_0xcb3d('0x4c')]),_0x6c5eac);var _0x38c555=[];var _0x4cea0f=squel[_0xcb3d('0x4d')]()[_0xcb3d('0x4e')]('id')['field']('name')[_0xcb3d('0x4e')](_0xcb3d('0x4f'))['from'](_0xcb3d('0x50'));var _0x399a96=squel[_0xcb3d('0x4d')]()['field'](_0xcb3d('0x51'))[_0xcb3d('0x4e')](_0xcb3d('0x52'))['field'](_0xcb3d('0x53'))[_0xcb3d('0x54')](_0xcb3d('0x55'),'ui')[_0xcb3d('0x56')](_0xcb3d('0x57'),'u',_0xcb3d('0x58'));var _0x4f7419=squel[_0xcb3d('0x4d')]()[_0xcb3d('0x54')](_0xcb3d('0x59'),'i')[_0xcb3d('0x56')](_0xcb3d('0x5a'),'c',_0xcb3d('0x5b'))[_0xcb3d('0x56')](_0xcb3d('0x57'),'o',_0xcb3d('0x5c'))[_0xcb3d('0x56')]('sms_accounts','a',_0xcb3d('0x5d'))[_0xcb3d('0x56')]('sms_messages','me',_0xcb3d('0x5e'))[_0xcb3d('0x56')](_0xcb3d('0x5f'),'it','it.SmsInteractionId\x20=\x20i.id')['left_join'](_0xcb3d('0x50'),'t','t.id\x20=\x20it.TagId');var _0xb28e38=squel[_0xcb3d('0x60')]();var _0x2fca4d=[];var _0x38ea30=squel['expr']();var _0x4bcd56;if(_0x12da25[_0xcb3d('0x43')][_0xcb3d('0x61')]){_0x4bcd56=as[_0xcb3d('0x62')](_0x12da25[_0xcb3d('0x43')][_0xcb3d('0x61')]);var _0x59ada1=_0x4bcd56[_0xcb3d('0x63')];for(var _0x4ac205=0x0;_0x4ac205<_0x4bcd56[_0xcb3d('0x64')]['length'];_0x4ac205++){var _0x171776=_0x4bcd56['conditions'][_0x4ac205];var _0x35dcf7='i';var _0x38c961=_[_0xcb3d('0x65')](_0x6c5eac,[_0xcb3d('0x2f'),_0x171776[_0xcb3d('0x4e')]]);if(!_0x38c961){switch(_0x171776[_0xcb3d('0x4e')]){case _0xcb3d('0x66'):if(_0x171776[_0xcb3d('0x67')]==0x1){_0x4f7419[_0xcb3d('0x68')]('`'+_0x171776['field']+'`\x20=\x200');}else{_0x4f7419[_0xcb3d('0x68')]('`'+_0x171776['field']+_0xcb3d('0x69'));}break;case _0xcb3d('0x6a'):if(_0x171776[_0xcb3d('0x6b')]===_0xcb3d('0x6c')){if(_0x171776['value'][_0xcb3d('0x6d')]('\x20')[_0xcb3d('0x47')]>0x1){_0xb28e38[_0x59ada1](_0xcb3d('0x6e'),qs[_0xcb3d('0x6f')](_0x171776[_0xcb3d('0x67')]),null);}else{var _0x3f5323='%'+_0x171776[_0xcb3d('0x67')]+'%';_0xb28e38[_0x59ada1](_0xcb3d('0x70'),_0x3f5323,_0x3f5323,_0x3f5323);}}else{_0x38c961=_[_0xcb3d('0x65')](_0x6c5eac,[_0xcb3d('0x2f'),_0xcb3d('0x71')]);_0x171776['field']=_0xcb3d('0x71');_0x4bcdd0=as['buildExpression'](_0x35dcf7,_0x38c961[_0xcb3d('0x40')],_0x171776);_0xb28e38[_0x59ada1](_0x4bcdd0['text'],_0x4bcdd0[_0xcb3d('0x67')][_0xcb3d('0x72')],_0x4bcdd0[_0xcb3d('0x67')][_0xcb3d('0x2b')]);}break;case _0xcb3d('0x73'):var _0x21ace9=_0x171776['value'][_0xcb3d('0x6d')](',')[_0xcb3d('0x31')](function(_0x2f5b37){return Number(_0x2f5b37);});_0x21ace9[_0xcb3d('0x34')](function(_0x1bf9ec){_0x38ea30['or'](_0xcb3d('0x74'),'%,'+_0x1bf9ec+',%');});_0x2fca4d=_[_0xcb3d('0x75')](_0x2fca4d,_0x21ace9);break;case _0xcb3d('0x76'):if(_0x171776[_0xcb3d('0x6b')]===_0xcb3d('0x6c')){_0xb28e38[_0x59ada1]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0x171776[_0xcb3d('0x67')]+'%',null);}else{_0x38c961=_[_0xcb3d('0x65')](_0x6c5eac,[_0xcb3d('0x2f'),_0xcb3d('0x3b')]);_0x171776[_0xcb3d('0x4e')]=_0xcb3d('0x3b');_0x4bcdd0=as[_0xcb3d('0x77')](_0x35dcf7,_0x38c961[_0xcb3d('0x40')],_0x171776);_0xb28e38[_0x59ada1](_0x4bcdd0[_0xcb3d('0x78')],_0x4bcdd0[_0xcb3d('0x67')]['start'],_0x4bcdd0[_0xcb3d('0x67')][_0xcb3d('0x2b')]);}break;case'body':_0x4bcdd0=as[_0xcb3d('0x77')]('me',null,_0x171776);_0xb28e38[_0x59ada1](_0x4bcdd0[_0xcb3d('0x78')],_0x4bcdd0[_0xcb3d('0x67')]['start'],_0x4bcdd0[_0xcb3d('0x67')][_0xcb3d('0x2b')]);break;}}else{var _0x4bcdd0=as[_0xcb3d('0x77')](_0x35dcf7,_0x38c961[_0xcb3d('0x40')],_0x171776);_0xb28e38[_0x59ada1](_0x4bcdd0[_0xcb3d('0x78')],_0x4bcdd0[_0xcb3d('0x67')][_0xcb3d('0x72')],_0x4bcdd0[_0xcb3d('0x67')]['end']);}}}else{var _0x23f6de=_(_0x12da25['query'])[_0xcb3d('0x79')]()[_0xcb3d('0x31')](function(_0x126e6d){return _[_0xcb3d('0x7a')](_0x6c5eac,[_0xcb3d('0x2f'),_0x126e6d])?_0x126e6d:undefined;})['compact']()[_0xcb3d('0x67')]();if(!_[_0xcb3d('0x7b')](_0x23f6de)){_0x23f6de[_0xcb3d('0x34')](function(_0x86a6c){if(_0x86a6c===_0xcb3d('0x7c')){_0x4f7419[_0xcb3d('0x4a')](_0xcb3d('0x7d'),[][_0xcb3d('0x7e')](_0x12da25[_0xcb3d('0x43')][_0x86a6c]));}else if(_0x86a6c===_0xcb3d('0x7f')){var _0x3ac31f=JSON[_0xcb3d('0x80')](_0x12da25[_0xcb3d('0x43')][_0x86a6c])[_0xcb3d('0x81')];var _0x5d27fe=JSON[_0xcb3d('0x80')](_0x12da25[_0xcb3d('0x43')][_0x86a6c])[_0xcb3d('0x82')];_0x4f7419[_0xcb3d('0x4a')](_0xcb3d('0x83'),_0x3ac31f,_0x5d27fe);}else{if(_0x12da25[_0xcb3d('0x43')][_0x86a6c]===_0xcb3d('0x84')){_0x4f7419[_0xcb3d('0x4a')]('i.'+_0x86a6c+_0xcb3d('0x85'));}else{_0x4f7419[_0xcb3d('0x4a')]('i.'+_0x86a6c+_0xcb3d('0x86'),_0x12da25[_0xcb3d('0x43')][_0x86a6c]);}}});}if(_0x12da25[_0xcb3d('0x43')][_0xcb3d('0x87')]){if(_0x12da25['query'][_0xcb3d('0x87')]==0x1){_0x4f7419['having'](_0xcb3d('0x88'));}else{_0x4f7419[_0xcb3d('0x68')](_0xcb3d('0x89'));}}if(_0x12da25['query'][_0xcb3d('0x8a')]){_0x2fca4d=_[_0xcb3d('0x8b')](_0x12da25[_0xcb3d('0x43')]['tag'])?_0x12da25[_0xcb3d('0x43')][_0xcb3d('0x8a')]:new Array(_0x12da25['query'][_0xcb3d('0x8a')]);_0x2fca4d[_0xcb3d('0x34')](function(_0x49c14f){_0x38ea30['or'](_0xcb3d('0x74'),'%,'+_0x49c14f+',%');});}if(_0x12da25[_0xcb3d('0x43')][_0xcb3d('0x8c')]){var _0x42808e=_0x12da25[_0xcb3d('0x43')][_0xcb3d('0x8c')][_0xcb3d('0x8d')]('\x5c','\x5c\x5c')[_0xcb3d('0x8d')](/'/g,'\x27\x27');if(qs[_0xcb3d('0x8e')](_0x42808e)){_0xb28e38['or']('i.id\x20LIKE\x20?',_0x42808e+'%')['or'](_0xcb3d('0x8f'),_0x42808e+'%');}else{_0xb28e38['or'](_0xcb3d('0x90'),qs[_0xcb3d('0x6f')](_0x42808e))['or']('CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?',_0x42808e+'%');}}}_0x4f7419['where'](_0xb28e38);_0x4f7419[_0xcb3d('0x91')](_0xcb3d('0x92'));var _0x3871d0={'type':db[_0xcb3d('0x93')][_0xcb3d('0x94')][_0xcb3d('0x95')],'raw':!![]};var _0x1781f0=_0x4f7419[_0xcb3d('0x96')]();_0x1781f0['field'](_0xcb3d('0x92'));_0x1781f0[_0xcb3d('0x4e')](_0xcb3d('0x97'),_0xcb3d('0x66'));if(_0x163f2d[_0xcb3d('0x98')]){_0x163f2d[_0xcb3d('0x98')][_0xcb3d('0x34')](function(_0x2e851d){var _0x24d98e=_0x2e851d[0x0]==='contactName'?_0x2e851d[0x0]:'i.'+_0x2e851d[0x0];_0x4f7419[_0xcb3d('0x98')](_0x24d98e,_0x2e851d[0x1]===_0xcb3d('0x99')?![]:!![]);});}if(!_[_0xcb3d('0x7b')](_0x2fca4d)){_0x4f7419['having'](_0x38ea30);_0x1781f0[_0xcb3d('0x4a')](_0xcb3d('0x9a'),_0x2fca4d);}BPromise[_0xcb3d('0x9b')]()[_0xcb3d('0x29')](function(){if(!_0x4bcd56){if(_0x12da25[_0xcb3d('0x43')][_0xcb3d('0x7c')])return;_0x1781f0[_0xcb3d('0x4a')](_0xcb3d('0x9c'));_0x4f7419['where'](_0xcb3d('0x9c'));return;}if(_0x12da25['user']['role']!==_0xcb3d('0x9d'))return;return _0x12da25[_0xcb3d('0x9e')][_0xcb3d('0x9f')]({'attributes':['id'],'raw':!![]})[_0xcb3d('0x29')](function(_0x4922c1){if(_[_0xcb3d('0x7b')](_0x4922c1)){_0x1781f0[_0xcb3d('0x4a')](_0xcb3d('0xa0'));_0x4f7419[_0xcb3d('0x4a')](_0xcb3d('0xa0'));}else{_0x1781f0['where'](_0xcb3d('0x7d'),_[_0xcb3d('0x31')](_0x4922c1,'id'));_0x4f7419['where']('i.SmsAccountId\x20IN\x20?',_[_0xcb3d('0x31')](_0x4922c1,'id'));}});})['then'](function(){if(_0x12da25[_0xcb3d('0x9e')]['role']===_0xcb3d('0x9d')&&!_0x4bcd56&&!_0x12da25[_0xcb3d('0x43')][_0xcb3d('0x7c')])return[];return db[_0xcb3d('0xa1')][_0xcb3d('0x43')](_0x1781f0[_0xcb3d('0xa2')](),_0x3871d0);})[_0xcb3d('0x29')](function(_0x1d2395){_0x22dc29[_0xcb3d('0x24')]=_0x1d2395[_0xcb3d('0x47')];if(_0x22dc29[_0xcb3d('0x24')]===0x0)return[];return db[_0xcb3d('0xa1')]['query'](_0x4cea0f[_0xcb3d('0xa2')](),_0x3871d0)[_0xcb3d('0x29')](function(_0x4cb8c3){_0x38c555=_[_0xcb3d('0xa3')](_0x4cb8c3,'id');_0x3871d0=_[_0xcb3d('0xa4')](_0x3871d0,{'model':db[_0xcb3d('0x3e')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x12da25['query'][_0xcb3d('0x46')]){_0x163f2d['attributes'][_0xcb3d('0x34')](function(_0x1d5cb4){_0x4f7419['field']('i.'+_0x1d5cb4);});}else{_0x4f7419[_0xcb3d('0x4e')](_0xcb3d('0x97'),_0xcb3d('0x66'));_0x4f7419['field'](_0xcb3d('0xa5'),_0xcb3d('0xa6'));_0x4f7419[_0xcb3d('0x4e')]('a.mandatoryDisposition','Account.mandatoryDisposition');_0x4f7419[_0xcb3d('0x4e')]('CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','contactName');_0x4f7419[_0xcb3d('0x4e')]('i.*');_0x4f7419['field'](_0xcb3d('0xa7'),_0xcb3d('0xa8'));_0x4f7419['field'](_0xcb3d('0xa9'),'Contact.lastName');_0x4f7419['field'](_0xcb3d('0xaa'),_0xcb3d('0xab'));_0x4f7419[_0xcb3d('0x4e')](_0xcb3d('0xac'),_0xcb3d('0xad'));_0x4f7419[_0xcb3d('0x4e')](_0xcb3d('0xae'),'Contact.mobile');_0x4f7419[_0xcb3d('0x4e')](_0xcb3d('0xaf'),_0xcb3d('0xb0'));_0x4f7419['field'](_0xcb3d('0xb1'),_0xcb3d('0xb2'));_0x4f7419[_0xcb3d('0x4e')](_0xcb3d('0xb3'),_0xcb3d('0xb4'));_0x4f7419[_0xcb3d('0x4e')]('GROUP_CONCAT(DISTINCT\x20t.id)',_0xcb3d('0x32'));}if(_0x163f2d[_0xcb3d('0x23')])_0x4f7419[_0xcb3d('0x23')](_0x163f2d['limit']);if(_0x163f2d[_0xcb3d('0x21')])_0x4f7419['offset'](_0x163f2d['offset']);return db['sequelize'][_0xcb3d('0x43')](_0x4f7419['toString'](),_0x3871d0);})[_0xcb3d('0x29')](function(_0x273150){if(_0x273150[_0xcb3d('0x47')]>0x0)_0x399a96[_0xcb3d('0x4a')](_0xcb3d('0xb5'),_[_0xcb3d('0x31')](_0x273150,'id'));return db[_0xcb3d('0xa1')][_0xcb3d('0x43')](_0x399a96['toString'](),_0x3871d0)['then'](function(_0x2ff16e){var _0x2d3884=_['groupBy'](_0x2ff16e,_0xcb3d('0xb6'));var _0x19b4af=[];_0x273150['forEach'](function(_0x3b72ef){_0x19b4af[_0xcb3d('0xb7')](updateSmsInteraction(_0x3b72ef,_0x38c555,_0x2d3884));});return BPromise[_0xcb3d('0xb8')](_0x19b4af);});});})[_0xcb3d('0x29')](function(_0xacd8db){_0x22dc29['rows']=_0xacd8db;return _0x22dc29;})['then'](respondWithFilteredResult(_0x3b2f30,_0x163f2d))[_0xcb3d('0x35')](handleError(_0x3b2f30,null));};exports['show']=function(_0x6d217f,_0x2b11cf){var _0x4f670b={'raw':![],'where':{'id':_0x6d217f[_0xcb3d('0xb9')]['id']}},_0x2d0c06={};_0x2d0c06[_0xcb3d('0x42')]=_[_0xcb3d('0x79')](db[_0xcb3d('0x3e')][_0xcb3d('0xba')]);_0x2d0c06[_0xcb3d('0x43')]=_[_0xcb3d('0x79')](_0x6d217f[_0xcb3d('0x43')]);_0x2d0c06[_0xcb3d('0x4c')]=_[_0xcb3d('0x44')](_0x2d0c06[_0xcb3d('0x42')],_0x2d0c06[_0xcb3d('0x43')]);_0x4f670b[_0xcb3d('0x45')]=_[_0xcb3d('0x44')](_0x2d0c06[_0xcb3d('0x42')],qs['fields'](_0x6d217f['query'][_0xcb3d('0x46')]));_0x4f670b['attributes']=_0x4f670b['attributes'][_0xcb3d('0x47')]?_0x4f670b[_0xcb3d('0x45')]:_0x2d0c06['model'];if(_0x6d217f[_0xcb3d('0x43')][_0xcb3d('0xbb')]){_0x4f670b[_0xcb3d('0xbc')]=[{'all':!![]}];}_0x4f670b=_[_0xcb3d('0xa4')]({},_0x4f670b,_0x6d217f[_0xcb3d('0xbd')]);return db['SmsInteraction']['find'](_0x4f670b)['then'](handleEntityNotFound(_0x2b11cf,null))['then'](respondWithResult(_0x2b11cf,null))[_0xcb3d('0x35')](handleError(_0x2b11cf,null));};exports[_0xcb3d('0xbe')]=function(_0x409ebc,_0x31085b){return db['SmsInteraction']['create'](_0x409ebc[_0xcb3d('0xbf')],{})[_0xcb3d('0x29')](respondWithResult(_0x31085b,0xc9))[_0xcb3d('0x35')](handleError(_0x31085b,null));};exports[_0xcb3d('0x28')]=function(_0x2a2470,_0xb1870c){if(_0x2a2470[_0xcb3d('0xbf')]['id']){delete _0x2a2470[_0xcb3d('0xbf')]['id'];}return db['SmsInteraction'][_0xcb3d('0x65')]({'where':{'id':_0x2a2470[_0xcb3d('0xb9')]['id']}})[_0xcb3d('0x29')](handleEntityNotFound(_0xb1870c,null))['then'](saveUpdates(_0x2a2470['body'],null))[_0xcb3d('0x29')](respondWithResult(_0xb1870c,null))[_0xcb3d('0x35')](handleError(_0xb1870c,null));};exports['destroy']=function(_0x37b5d7,_0x4e3e65){return db[_0xcb3d('0x3e')][_0xcb3d('0x65')]({'where':{'id':_0x37b5d7['params']['id']}})[_0xcb3d('0x29')](handleEntityNotFound(_0x4e3e65,null))[_0xcb3d('0x29')](removeEntity(_0x4e3e65,null))[_0xcb3d('0x35')](handleError(_0x4e3e65,null));};exports['describe']=function(_0x10ba8f,_0x11610f){return db[_0xcb3d('0x3e')][_0xcb3d('0xc0')]()[_0xcb3d('0x29')](respondWithResult(_0x11610f,null))[_0xcb3d('0x35')](handleError(_0x11610f,null));};exports[_0xcb3d('0xc1')]=function(_0x5ddcab,_0x29f6dc,_0x1b59c5){return db['SmsMessage'][_0xcb3d('0x65')]({'where':{'id':_0x5ddcab[_0xcb3d('0xb9')]['id']}})[_0xcb3d('0x29')](handleEntityNotFound(_0x29f6dc,null))[_0xcb3d('0x29')](function(_0x3c116d){if(_0x3c116d){return _0x3c116d['addMessage'](_0x5ddcab['body'][_0xcb3d('0xc2')],_['omit'](_0x5ddcab[_0xcb3d('0xbf')],[_0xcb3d('0xc2'),'id'])||{});}})['then'](respondWithResult(_0x29f6dc,null))['catch'](handleError(_0x29f6dc,null));};exports[_0xcb3d('0xc3')]=function(_0x5a86d0,_0x310d3c,_0x3491a9){var _0x3986e6={'raw':![],'where':{}};var _0x14b9f3={};var _0x3c88cc={'count':0x0,'rows':[]};return db[_0xcb3d('0x3e')][_0xcb3d('0xc4')]({'where':{'id':_0x5a86d0[_0xcb3d('0xb9')]['id']}})[_0xcb3d('0x29')](handleEntityNotFound(_0x310d3c,null))[_0xcb3d('0x29')](function(_0x39f587){if(_0x39f587){_0x14b9f3[_0xcb3d('0x42')]=_['keys'](db['SmsMessage'][_0xcb3d('0xba')]);_0x14b9f3[_0xcb3d('0x43')]=_[_0xcb3d('0x79')](_0x5a86d0[_0xcb3d('0x43')]);_0x14b9f3[_0xcb3d('0x4c')]=_[_0xcb3d('0x44')](_0x14b9f3[_0xcb3d('0x42')],_0x14b9f3[_0xcb3d('0x43')]);_0x3986e6['attributes']=_['intersection'](_0x14b9f3[_0xcb3d('0x42')],qs[_0xcb3d('0x46')](_0x5a86d0[_0xcb3d('0x43')][_0xcb3d('0x46')]));_0x3986e6[_0xcb3d('0x45')]=_0x3986e6[_0xcb3d('0x45')][_0xcb3d('0x47')]?_0x3986e6[_0xcb3d('0x45')]:_0x14b9f3[_0xcb3d('0x42')];if(!_0x5a86d0[_0xcb3d('0x43')][_0xcb3d('0xc5')](_0xcb3d('0x48'))){_0x3986e6[_0xcb3d('0x23')]=qs['limit'](_0x5a86d0[_0xcb3d('0x43')][_0xcb3d('0x23')]);_0x3986e6[_0xcb3d('0x21')]=qs[_0xcb3d('0x21')](_0x5a86d0[_0xcb3d('0x43')][_0xcb3d('0x21')]);}_0x3986e6[_0xcb3d('0x98')]=qs['sort'](_0x5a86d0['query']['sort']);_0x3986e6[_0xcb3d('0x4a')]=qs[_0xcb3d('0x4c')](_[_0xcb3d('0x4b')](_0x5a86d0['query'],_0x14b9f3[_0xcb3d('0x4c')]));_0x3986e6['where'][_0xcb3d('0xb6')]=_0x39f587['id'];if(_0x5a86d0[_0xcb3d('0x43')]['filter']){_0x3986e6['where']=_[_0xcb3d('0xa4')](_0x3986e6[_0xcb3d('0x4a')],{'$or':_[_0xcb3d('0x31')](_0x3986e6[_0xcb3d('0x45')],function(_0x2cc29d){var _0x10d345={};_0x10d345[_0x2cc29d]={'$like':'%'+_0x5a86d0[_0xcb3d('0x43')][_0xcb3d('0x8c')]+'%'};return _0x10d345;})});}if(_0x5a86d0['query'][_0xcb3d('0x81')]){var _0x727478=_0x5a86d0[_0xcb3d('0x43')]['$gte']['split'](',');var _0x44c297={};_0x44c297[_0x727478[0x0]]={'$gte':moment(_0x727478[0x1])[_0xcb3d('0xc6')](_0xcb3d('0xc7'))};_0x3986e6['where']=_[_0xcb3d('0xa4')](_0x3986e6[_0xcb3d('0x4a')],_0x44c297);}_0x3986e6=_['merge']({},_0x3986e6,_0x5a86d0[_0xcb3d('0xbd')]);return db[_0xcb3d('0xc8')][_0xcb3d('0x24')]({'where':_0x3986e6[_0xcb3d('0x4a')]})[_0xcb3d('0x29')](function(_0x4095a9){_0x3c88cc[_0xcb3d('0x24')]=_0x4095a9;if(_0x5a86d0[_0xcb3d('0x43')]['includeAll']){_0x3986e6[_0xcb3d('0xbc')]=[{'all':!![]}];}return db[_0xcb3d('0xc8')][_0xcb3d('0xc9')](_0x3986e6);})['then'](function(_0x10aa49){_0x3c88cc[_0xcb3d('0xca')]=_0x10aa49;return _0x3c88cc;});}})[_0xcb3d('0x29')](respondWithFilteredResult(_0x310d3c,_0x3986e6))['catch'](handleError(_0x310d3c,null));};exports['addTags']=function(_0x1cabd8,_0x1ba650,_0x86fed1){return db[_0xcb3d('0x3e')][_0xcb3d('0x65')]({'where':{'id':_0x1cabd8[_0xcb3d('0xb9')]['id']}})[_0xcb3d('0x29')](handleEntityNotFound(_0x1ba650,null))[_0xcb3d('0x29')](function(_0x36dc72){if(_0x36dc72){return _0x36dc72[_0xcb3d('0xcb')](_0x1cabd8[_0xcb3d('0xbf')][_0xcb3d('0xc2')],_[_0xcb3d('0xcc')](_0x1cabd8['body'],[_0xcb3d('0xc2'),'id'])||{})[_0xcb3d('0xcd')](function(){return db[_0xcb3d('0x73')][_0xcb3d('0xc9')]({'attributes':['id',_0xcb3d('0x2f'),_0xcb3d('0x4f')],'where':{'id':_0x1cabd8[_0xcb3d('0xbf')][_0xcb3d('0xc2')]}});})[_0xcb3d('0x29')](function(_0x3c183e){socket[_0xcb3d('0xce')](_0xcb3d('0xcf'),{'id':Number(_0x1cabd8[_0xcb3d('0xb9')]['id']),'tags':_0x3c183e||[]});return{'id':Number(_0x1cabd8[_0xcb3d('0xb9')]['id']),'tags':_0x3c183e||[]};});}})[_0xcb3d('0x29')](respondWithResult(_0x1ba650,null))[_0xcb3d('0x35')](handleError(_0x1ba650,null));};exports['removeTags']=function(_0x525621,_0x563a7f,_0x4cd487){return db['SmsInteraction'][_0xcb3d('0x65')]({'where':{'id':_0x525621[_0xcb3d('0xb9')]['id']}})['then'](handleEntityNotFound(_0x563a7f,null))[_0xcb3d('0x29')](function(_0x55cb3b){if(_0x55cb3b){return _0x55cb3b['removeTags'](_0x525621[_0xcb3d('0x43')]['ids']);}})[_0xcb3d('0x29')](respondWithStatusCode(_0x563a7f,null))[_0xcb3d('0x35')](handleError(_0x563a7f,null));};exports[_0xcb3d('0xd0')]=function(_0x113d3d,_0x46c97a){var _0x11af58=moment()[_0xcb3d('0xd1')]()[_0xcb3d('0xa2')]();var _0x5590f9=path[_0xcb3d('0xd2')](config['root'],'server',_0xcb3d('0xd3'),_0xcb3d('0xd4'));var _0x5772a6=path[_0xcb3d('0xd2')](config['root'],_0xcb3d('0xd5'),_0xcb3d('0xd3'),_0xcb3d('0xd6'));var _0x565eb7=path[_0xcb3d('0xd2')](_0x5590f9,_0x11af58);var _0x4ffbb6=util[_0xcb3d('0xc6')](_0xcb3d('0xd7'),_0x113d3d[_0xcb3d('0xb9')]['id'],_0x11af58);var _0x286b0c=path[_0xcb3d('0xd2')](_0x5590f9,_0x4ffbb6);var _0x2d2854=[];_0x2d2854[_0xcb3d('0xb7')]({'model':db[_0xcb3d('0x76')],'as':'User','attributes':['id',_0xcb3d('0xd8')],'raw':!![]});_0x2d2854[_0xcb3d('0xb7')]({'model':db[_0xcb3d('0xd9')],'as':_0xcb3d('0x6a'),'attributes':['id',_0xcb3d('0xda'),_0xcb3d('0xdb')],'raw':!![]});var _0x244402=[{'model':db[_0xcb3d('0xc8')],'as':'Messages','attributes':['id','body',_0xcb3d('0x7f'),_0xcb3d('0xdc'),_0xcb3d('0xdd'),_0xcb3d('0x87')],'include':_0x2d2854}];_0x244402[_0xcb3d('0xb7')]({'model':db[_0xcb3d('0xde')],'as':'Account','attributes':['id',_0xcb3d('0x2f')]});_0x244402[_0xcb3d('0xb7')]({'model':db[_0xcb3d('0x76')],'as':_0xcb3d('0xdf'),'attributes':['id',_0xcb3d('0xd8')]});return db['SmsInteraction'][_0xcb3d('0x65')]({'where':{'id':_0x113d3d[_0xcb3d('0xb9')]['id']},'include':_0x244402})[_0xcb3d('0x29')](handleEntityNotFound(_0x46c97a,null))[_0xcb3d('0x29')](function(_0x15ffd6){if(_0x15ffd6){var _0x212fdf=_0x15ffd6[_0xcb3d('0xe0')]({'plain':!![]});fs['mkdirSync'](_0x565eb7);var _0x325df8={'channel':_0xcb3d('0xe1'),'account':_0x212fdf[_0xcb3d('0xe2')][_0xcb3d('0x2f')],'agent':_0x212fdf['Owner']?_0x212fdf[_0xcb3d('0xdf')][_0xcb3d('0xd8')]:_0xcb3d('0xe3'),'createdAt':moment(_0x212fdf[_0xcb3d('0x7f')])[_0xcb3d('0xc6')]('YYYY-MM-DD\x20HH:mm:ss')['toString'](),'closedAt':_0x212fdf['closed']?moment(_0x212fdf[_0xcb3d('0xe4')])[_0xcb3d('0xc6')](_0xcb3d('0xc7'))['toString']():'','disposition':_0x212fdf[_0xcb3d('0xe5')],'messages':_(_0x212fdf['Messages'])[_0xcb3d('0x8c')]({'secret':![]})[_0xcb3d('0x31')](function(_0x2fa9ac){return{'date':moment(_0x2fa9ac[_0xcb3d('0x7f')])[_0xcb3d('0xc6')](_0xcb3d('0xc7'))[_0xcb3d('0xa2')](),'sender':_0x2fa9ac[_0xcb3d('0xdc')]===_0xcb3d('0xe6')?_0x2fa9ac[_0xcb3d('0x76')]?_0x2fa9ac[_0xcb3d('0x76')][_0xcb3d('0xd8')]:_0xcb3d('0xe7'):_0x2fa9ac['Contact'][_0xcb3d('0xda')]+(_0x2fa9ac[_0xcb3d('0x6a')][_0xcb3d('0xdb')]?'\x20'+_0x2fa9ac['Contact'][_0xcb3d('0xdb')]:''),'body':_0x2fa9ac[_0xcb3d('0xbf')],'direction':_0x2fa9ac[_0xcb3d('0xdc')]===_0xcb3d('0xe6')?'A':'C','secret':_0x2fa9ac['secret'],'read':_0x2fa9ac[_0xcb3d('0x87')]};})[_0xcb3d('0x67')]()};return ejs[_0xcb3d('0xe8')](path[_0xcb3d('0xd2')](config[_0xcb3d('0xe9')],_0xcb3d('0xd5'),_0xcb3d('0xea'),_0xcb3d('0xeb')),{'interaction':_0x325df8})[_0xcb3d('0x29')](function(_0x4ded2b){var _0x15e6c2=path[_0xcb3d('0xd2')](_0x565eb7,_0xcb3d('0xec')+_0x212fdf['id']+'-'+_0x11af58+'.pdf');var _0x57f9e6={'path':_0x15e6c2,'channel':_0xcb3d('0xe1'),'interactionId':_0x212fdf['id']};return pdf['createPdfFromHTML'](_0x4ded2b,_0x57f9e6);})[_0xcb3d('0x29')](function(){return new BPromise(function(_0x1fe7fa,_0x234aae){zipdir(_0x565eb7,{'saveTo':_0x286b0c},function(_0x3b59be,_0x44e684){if(_0x3b59be)return _0x234aae(_0x3b59be);return _0x1fe7fa(_0x44e684);});})[_0xcb3d('0x29')](function(){return new BPromise(function(_0x43410c,_0x59ea63){rimraf(_0x565eb7,function(_0x22f801){if(_0x22f801)_0x59ea63(_0x22f801);return _0x43410c();});});})[_0xcb3d('0x29')](function(){return _0x46c97a[_0xcb3d('0xd0')](_0x286b0c,_0x4ffbb6,function(_0x343889){if(_0x343889){console['log'](_0xcb3d('0xed'),_0x343889);}else{fs[_0xcb3d('0xee')](_0x286b0c);}});});});}else{return _0x46c97a[_0xcb3d('0x2c')](0xc8);}})[_0xcb3d('0x35')](handleError(_0x46c97a,null));};
\ No newline at end of file