Built motion from commit c116dc8b.|2.6.30
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index a7c9dbe..52d0686 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x85b5=['some','isEmpty','WhatsappAccountId','i.WhatsappAccountId\x20IN\x20?','concat','createdAt','$gte','parse','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','filter','replace','isNumeric','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','group','i.id','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','DESC','t.id\x20IN\x20?','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','user','agent','getWhatsappAccounts','i.WhatsappAccountId\x20IS\x20NULL','role','sequelize','toString','keyBy','merge','a.key','Account.key','Account.mandatoryDisposition','CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','i.*','c.firstName','Contact.firstName','c.lastName','Contact.lastName','Contact.email','c.phone','Contact.phone','Contact.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.WhatsappInteractionId\x20IN\x20?','groupBy','WhatsappInteractionId','push','all','show','params','includeAll','include','options','create','describe','addMessage','WhatsappMessage','omit','ids','findOne','format','YYYY-MM-DD\x20HH:mm:ss','findAll','rows','addTags','spread','color','emit','whatsappInteractionTags:save','removeTags','download','unix','root','server','tmp','join','files','attachments','transcript-%d-%s.zip','CmContact','firstName','lastName','Attachment','Messages','secret','Account','Owner','10px','40px','<div\x20class=\x22header\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<h5>Interaction\x20Transcript</h5>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','30px','<hr\x20class=\x22separator\x22/>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22footer\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22left\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22center\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>{{page}}/{{pages}}</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22right\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','%s\x20#%d','Whatsapp','YYYY-MM-DD','N.A.','closedAt','disposition','basename','existsSync','pipe','direction','out','System','renderFile','views','transcript-','.pdf','log','err','unlinkSync','html-pdf','eml-format','zip-dir','request-promise','mustache','path','sox','to-csv','lodash','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','redis','defaults','socket.io-emitter','./whatsappInteraction.socket','register','status','end','count','offset','limit','json','apply','save','update','then','destroy','sendStatus','error','stack','name','send','Users','map','fullname','TagIds','Tags','split','forEach','catch','WhatsappInteraction','rawAttributes','fieldName','query','keys','filters','intersection','model','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','field','from','u.fullname','ui.WhatsappInteractionId','user_has_whatsapp_interactions','select','whatsapp_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','left_join','users','whatsapp_accounts','a.id\x20=\x20i.WhatsappAccountId','whatsapp_messages','it.WhatsappInteractionId\x20=\x20i.id','tools_tags','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)','ContactId','buildExpression','type','text','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','start','body'];(function(_0x3c2b2e,_0x3e6e53){var _0x27a338=function(_0x40d29d){while(--_0x40d29d){_0x3c2b2e['push'](_0x3c2b2e['shift']());}};_0x27a338(++_0x3e6e53);}(_0x85b5,0x7f));var _0x585b=function(_0x5f06f7,_0x4d0d2f){_0x5f06f7=_0x5f06f7-0x0;var _0x334984=_0x85b5[_0x5f06f7];return _0x334984;};'use strict';var pdf=require(_0x585b('0x0'));var emlformat=require(_0x585b('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x585b('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x585b('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x585b('0x4'));var util=require('util');var path=require(_0x585b('0x5'));var sox=require(_0x585b('0x6'));var csv=require(_0x585b('0x7'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x585b('0x8'));var squel=require('squel');var crypto=require(_0x585b('0x9'));var jsforce=require(_0x585b('0xa'));var deskjs=require(_0x585b('0xb'));var toCsv=require(_0x585b('0x7'));var querystring=require('querystring');var Papa=require(_0x585b('0xc'));var Redis=require(_0x585b('0xd'));var authService=require(_0x585b('0xe'));var qs=require(_0x585b('0xf'));var as=require(_0x585b('0x10'));var hardwareService=require(_0x585b('0x11'));var logger=require(_0x585b('0x12'))('api');var utils=require(_0x585b('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0x585b('0x14'));var db=require('../../mysqldb')['db'];config[_0x585b('0x15')]=_[_0x585b('0x16')](config[_0x585b('0x15')],{'host':'localhost','port':0x18eb});var socket=require(_0x585b('0x17'))(new Redis(config[_0x585b('0x15')]));require(_0x585b('0x18'))[_0x585b('0x19')](socket);function respondWithStatusCode(_0x3dcc28,_0x24c960){_0x24c960=_0x24c960||0xcc;return function(_0x394361){if(_0x394361){return _0x3dcc28['sendStatus'](_0x24c960);}return _0x3dcc28[_0x585b('0x1a')](_0x24c960)[_0x585b('0x1b')]();};}function respondWithResult(_0x4c094e,_0x4e2a41){_0x4e2a41=_0x4e2a41||0xc8;return function(_0xd53614){if(_0xd53614){return _0x4c094e['status'](_0x4e2a41)['json'](_0xd53614);}};}function respondWithFilteredResult(_0x2f840e,_0x46a9b5){return function(_0x20c4ba){if(_0x20c4ba){var _0x510921=_0x20c4ba[_0x585b('0x1c')],_0x72fdc4=_0x46a9b5['offset'],_0x14648f=_0x46a9b5[_0x585b('0x1d')]+_0x46a9b5[_0x585b('0x1e')],_0x326a4e;if(_0x14648f>=_0x510921){_0x14648f=_0x510921;_0x326a4e=0xc8;}else{_0x326a4e=0xce;}_0x2f840e[_0x585b('0x1a')](_0x326a4e);return _0x2f840e['set']('Content-Range',_0x72fdc4+'-'+_0x14648f+'/'+_0x510921)[_0x585b('0x1f')](_0x20c4ba);}return null;};}function patchUpdates(_0x56d178){return function(_0x484157){try{jsonpatch[_0x585b('0x20')](_0x484157,_0x56d178,!![]);}catch(_0xb8b33a){return BPromise['reject'](_0xb8b33a);}return _0x484157[_0x585b('0x21')]();};}function saveUpdates(_0x272a8d,_0x48998c){return function(_0x310c9e){if(_0x310c9e){return _0x310c9e[_0x585b('0x22')](_0x272a8d)[_0x585b('0x23')](function(_0x5bf9e4){return _0x5bf9e4;});}return null;};}function removeEntity(_0x1c8a7b,_0x48940e){return function(_0x3c861c){if(_0x3c861c){return _0x3c861c[_0x585b('0x24')]()[_0x585b('0x23')](function(){_0x1c8a7b[_0x585b('0x1a')](0xcc)[_0x585b('0x1b')]();});}};}function handleEntityNotFound(_0x1b1241,_0xd6bf9b){return function(_0x799947){if(!_0x799947){_0x1b1241[_0x585b('0x25')](0x194);}return _0x799947;};}function handleError(_0x47099f,_0x7d8984){_0x7d8984=_0x7d8984||0x1f4;return function(_0x35075c){logger[_0x585b('0x26')](_0x35075c[_0x585b('0x27')]);if(_0x35075c[_0x585b('0x28')]){delete _0x35075c['name'];}_0x47099f[_0x585b('0x1a')](_0x7d8984)[_0x585b('0x29')](_0x35075c);};}function getInteractionUsers(_0x19786,_0x2cf48a){return new BPromise(function(_0x5dad9a,_0x4e9fc8){try{if(_0x2cf48a[_0x19786['id']]){_0x19786[_0x585b('0x2a')]=_[_0x585b('0x2b')](_0x2cf48a[_0x19786['id']],function(_0x5212e3){return{'id':_0x5212e3['id'],'fullname':_0x5212e3[_0x585b('0x2c')]};});}}catch(_0x112fb5){_0x4e9fc8(_0x112fb5);}_0x5dad9a(_0x19786);});}function getInteractionTags(_0x5c9249,_0x47020d){return new BPromise(function(_0x3e700a,_0x2ab871){try{if(_0x5c9249[_0x585b('0x2d')]){_0x5c9249[_0x585b('0x2e')]=[];_0x5c9249[_0x585b('0x2d')][_0x585b('0x2f')](',')[_0x585b('0x30')](function(_0x224fe0){_0x5c9249[_0x585b('0x2e')]['push'](_0x47020d[_0x224fe0]);});}delete _0x5c9249[_0x585b('0x2d')];}catch(_0x15da02){_0x2ab871(_0x15da02);}_0x3e700a(_0x5c9249);});}function updateWhatsappInteraction(_0x1c18b9,_0x4d35f8,_0x388c7d){return new BPromise(function(_0x65cefc,_0x3521d){return getInteractionUsers(_0x1c18b9,_0x388c7d)['then'](function(_0x31c42c){return getInteractionTags(_0x31c42c,_0x4d35f8);})[_0x585b('0x23')](function(_0x6b6d47){_0x65cefc(_0x6b6d47);})[_0x585b('0x31')](function(_0x55d2e7){_0x3521d(_0x55d2e7);});});}exports['index']=function(_0xa29269,_0x7bdaf0){var _0x411914={},_0x31918f={},_0x179502={'count':0x0,'rows':[]};var _0x5d396a=_[_0x585b('0x2b')](db[_0x585b('0x32')][_0x585b('0x33')],function(_0x1390d8){return{'name':_0x1390d8[_0x585b('0x34')],'type':_0x1390d8['type']['key']};});_0x31918f['model']=_[_0x585b('0x2b')](_0x5d396a,_0x585b('0x28'));_0x31918f[_0x585b('0x35')]=_[_0x585b('0x36')](_0xa29269[_0x585b('0x35')]);_0x31918f[_0x585b('0x37')]=_[_0x585b('0x38')](_0x31918f[_0x585b('0x39')],_0x31918f[_0x585b('0x35')]);_0x411914['attributes']=_[_0x585b('0x38')](_0x31918f[_0x585b('0x39')],qs['fields'](_0xa29269[_0x585b('0x35')][_0x585b('0x3a')]));_0x411914[_0x585b('0x3b')]=_0x411914[_0x585b('0x3b')][_0x585b('0x3c')]?_0x411914[_0x585b('0x3b')]:_0x31918f['model'];if(!_0xa29269[_0x585b('0x35')][_0x585b('0x3d')](_0x585b('0x3e'))){_0x411914[_0x585b('0x1e')]=qs[_0x585b('0x1e')](_0xa29269[_0x585b('0x35')][_0x585b('0x1e')]);_0x411914[_0x585b('0x1d')]=qs['offset'](_0xa29269[_0x585b('0x35')][_0x585b('0x1d')]);}_0x411914[_0x585b('0x3f')]=qs['sort'](_0xa29269[_0x585b('0x35')][_0x585b('0x40')]);_0x411914[_0x585b('0x41')]=qs['filters'](_[_0x585b('0x42')](_0xa29269[_0x585b('0x35')],_0x31918f['filters']),_0x5d396a);var _0x4edd57=[];var _0x22e17d=squel['select']()[_0x585b('0x43')]('id')['field'](_0x585b('0x28'))[_0x585b('0x43')]('color')[_0x585b('0x44')]('tools_tags');var _0x56f56b=squel['select']()[_0x585b('0x43')]('u.id')[_0x585b('0x43')](_0x585b('0x45'))['field'](_0x585b('0x46'))[_0x585b('0x44')](_0x585b('0x47'),'ui')['left_join']('users','u','u.id\x20=\x20ui.UserId');var _0x2f1d2e=squel[_0x585b('0x48')]()[_0x585b('0x44')](_0x585b('0x49'),'i')['left_join'](_0x585b('0x4a'),'c',_0x585b('0x4b'))[_0x585b('0x4c')](_0x585b('0x4d'),'o','o.id\x20=\x20i.UserId')[_0x585b('0x4c')](_0x585b('0x4e'),'a',_0x585b('0x4f'))[_0x585b('0x4c')](_0x585b('0x50'),'me','me.WhatsappInteractionId\x20=\x20i.id')['left_join']('whatsapp_interaction_has_tags','it',_0x585b('0x51'))['left_join'](_0x585b('0x52'),'t','t.id\x20=\x20it.TagId');var _0x5f3aca=squel['expr']();var _0x1a5925=[];var _0x429546=squel['expr']();var _0x5116a8;if(_0xa29269[_0x585b('0x35')][_0x585b('0x53')]){_0x5116a8=as[_0x585b('0x54')](_0xa29269['query'][_0x585b('0x53')]);var _0x4ca120=_0x5116a8[_0x585b('0x55')];for(var _0x5f31cb=0x0;_0x5f31cb<_0x5116a8[_0x585b('0x56')]['length'];_0x5f31cb++){var _0x3b96db=_0x5116a8['conditions'][_0x5f31cb];var _0x267bd0='i';var _0x259dac=_[_0x585b('0x57')](_0x5d396a,[_0x585b('0x28'),_0x3b96db[_0x585b('0x43')]]);if(!_0x259dac){switch(_0x3b96db['field']){case _0x585b('0x58'):if(_0x3b96db[_0x585b('0x59')]==0x1){_0x2f1d2e[_0x585b('0x5a')]('`'+_0x3b96db[_0x585b('0x43')]+_0x585b('0x5b'));}else{_0x2f1d2e[_0x585b('0x5a')]('`'+_0x3b96db['field']+_0x585b('0x5c'));}break;case _0x585b('0x5d'):if(_0x3b96db[_0x585b('0x5e')]===_0x585b('0x5f')){if(_0x3b96db['value'][_0x585b('0x2f')]('\x20')[_0x585b('0x3c')]>0x1){_0x5f3aca[_0x4ca120](_0x585b('0x60'),qs['getFullTextValue'](_0x3b96db['value']),null);}else{var _0x582bf1='%'+_0x3b96db['value']+'%';_0x5f3aca[_0x4ca120]('c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?',_0x582bf1,_0x582bf1,_0x582bf1);}}else{_0x259dac=_['find'](_0x5d396a,[_0x585b('0x28'),_0x585b('0x61')]);_0x3b96db[_0x585b('0x43')]='ContactId';_0x565f25=as[_0x585b('0x62')](_0x267bd0,_0x259dac[_0x585b('0x63')],_0x3b96db);_0x5f3aca[_0x4ca120](_0x565f25[_0x585b('0x64')],_0x565f25[_0x585b('0x59')]['start'],_0x565f25[_0x585b('0x59')][_0x585b('0x1b')]);}break;case _0x585b('0x65'):var _0x136ba9=_0x3b96db[_0x585b('0x59')][_0x585b('0x2f')](',')[_0x585b('0x2b')](function(_0x55828f){return Number(_0x55828f);});_0x136ba9[_0x585b('0x30')](function(_0x3c4ee5){_0x429546['or'](_0x585b('0x66'),'%,'+_0x3c4ee5+',%');});_0x1a5925=_[_0x585b('0x67')](_0x1a5925,_0x136ba9);break;case _0x585b('0x68'):if(_0x3b96db[_0x585b('0x5e')]===_0x585b('0x5f')){_0x5f3aca[_0x4ca120](_0x585b('0x69'),'%'+_0x3b96db[_0x585b('0x59')]+'%',null);}else{_0x259dac=_[_0x585b('0x57')](_0x5d396a,[_0x585b('0x28'),_0x585b('0x6a')]);_0x3b96db[_0x585b('0x43')]=_0x585b('0x6a');_0x565f25=as['buildExpression'](_0x267bd0,_0x259dac[_0x585b('0x63')],_0x3b96db);_0x5f3aca[_0x4ca120](_0x565f25['text'],_0x565f25[_0x585b('0x59')][_0x585b('0x6b')],_0x565f25['value'][_0x585b('0x1b')]);}break;case _0x585b('0x6c'):_0x565f25=as['buildExpression']('me',null,_0x3b96db);_0x5f3aca[_0x4ca120](_0x565f25['text'],_0x565f25['value']['start'],_0x565f25['value'][_0x585b('0x1b')]);break;}}else{var _0x565f25=as[_0x585b('0x62')](_0x267bd0,_0x259dac[_0x585b('0x63')],_0x3b96db);_0x5f3aca[_0x4ca120](_0x565f25[_0x585b('0x64')],_0x565f25[_0x585b('0x59')][_0x585b('0x6b')],_0x565f25[_0x585b('0x59')]['end']);}}}else{var _0x4a6496=_(_0xa29269['query'])[_0x585b('0x36')]()[_0x585b('0x2b')](function(_0x42e155){return _[_0x585b('0x6d')](_0x5d396a,[_0x585b('0x28'),_0x42e155])?_0x42e155:undefined;})['compact']()[_0x585b('0x59')]();if(!_[_0x585b('0x6e')](_0x4a6496)){_0x4a6496[_0x585b('0x30')](function(_0xe4ad74){if(_0xe4ad74===_0x585b('0x6f')){_0x2f1d2e['where'](_0x585b('0x70'),[][_0x585b('0x71')](_0xa29269[_0x585b('0x35')][_0xe4ad74]));}else if(_0xe4ad74===_0x585b('0x72')){var _0x1efdaa=JSON['parse'](_0xa29269[_0x585b('0x35')][_0xe4ad74])[_0x585b('0x73')];var _0x3c48df=JSON[_0x585b('0x74')](_0xa29269['query'][_0xe4ad74])[_0x585b('0x75')];_0x2f1d2e[_0x585b('0x41')](_0x585b('0x76'),_0x1efdaa,_0x3c48df);}else{if(_0xa29269[_0x585b('0x35')][_0xe4ad74]===_0x585b('0x77')){_0x2f1d2e[_0x585b('0x41')]('i.'+_0xe4ad74+'\x20IS\x20NULL');}else{_0x2f1d2e[_0x585b('0x41')]('i.'+_0xe4ad74+_0x585b('0x78'),_0xa29269[_0x585b('0x35')][_0xe4ad74]);}}});}if(_0xa29269[_0x585b('0x35')][_0x585b('0x79')]){if(_0xa29269['query'][_0x585b('0x79')]==0x1){_0x2f1d2e[_0x585b('0x5a')](_0x585b('0x7a'));}else{_0x2f1d2e[_0x585b('0x5a')](_0x585b('0x7b'));}}if(_0xa29269[_0x585b('0x35')][_0x585b('0x7c')]){_0x1a5925=_['isArray'](_0xa29269[_0x585b('0x35')][_0x585b('0x7c')])?_0xa29269[_0x585b('0x35')][_0x585b('0x7c')]:new Array(_0xa29269[_0x585b('0x35')]['tag']);_0x1a5925[_0x585b('0x30')](function(_0x16fda5){_0x429546['or'](_0x585b('0x66'),'%,'+_0x16fda5+',%');});}if(_0xa29269[_0x585b('0x35')]['filter']){var _0x284bf9=_0xa29269[_0x585b('0x35')][_0x585b('0x7d')][_0x585b('0x7e')]('\x5c','\x5c\x5c')[_0x585b('0x7e')](/'/g,'\x27\x27');if(qs[_0x585b('0x7f')](_0x284bf9)){_0x5f3aca['or']('i.id\x20LIKE\x20?',_0x284bf9+'%')['or']('i.phone\x20LIKE\x20?',_0x284bf9+'%');}else{_0x5f3aca['or'](_0x585b('0x80'),qs[_0x585b('0x81')](_0x284bf9))['or']('CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?',_0x284bf9+'%');}}}_0x2f1d2e[_0x585b('0x41')](_0x5f3aca);_0x2f1d2e[_0x585b('0x82')](_0x585b('0x83'));var _0x158077={'type':db['Sequelize']['QueryTypes'][_0x585b('0x84')],'raw':!![]};var _0x492b54=_0x2f1d2e[_0x585b('0x85')]();_0x492b54[_0x585b('0x43')]('i.id');_0x492b54['field'](_0x585b('0x86'),_0x585b('0x58'));if(_0x411914[_0x585b('0x3f')]){_0x411914[_0x585b('0x3f')][_0x585b('0x30')](function(_0x33f5c2){var _0x45a24a=_0x33f5c2[0x0]===_0x585b('0x87')?_0x33f5c2[0x0]:'i.'+_0x33f5c2[0x0];_0x2f1d2e['order'](_0x45a24a,_0x33f5c2[0x1]===_0x585b('0x88')?![]:!![]);});}if(!_['isEmpty'](_0x1a5925)){_0x2f1d2e['having'](_0x429546);_0x492b54[_0x585b('0x41')](_0x585b('0x89'),_0x1a5925);}BPromise['resolve']()[_0x585b('0x23')](function(){if(!_0x5116a8){if(_0xa29269[_0x585b('0x35')]['WhatsappAccountId'])return;_0x492b54[_0x585b('0x41')](_0x585b('0x8a'));_0x2f1d2e['where'](_0x585b('0x8a'));return;}if(_0xa29269[_0x585b('0x8b')]['role']!==_0x585b('0x8c'))return;return _0xa29269['user'][_0x585b('0x8d')]({'attributes':['id'],'raw':!![]})[_0x585b('0x23')](function(_0x22367f){if(_[_0x585b('0x6e')](_0x22367f)){_0x492b54[_0x585b('0x41')](_0x585b('0x8e'));_0x2f1d2e[_0x585b('0x41')](_0x585b('0x8e'));}else{_0x492b54[_0x585b('0x41')](_0x585b('0x70'),_[_0x585b('0x2b')](_0x22367f,'id'));_0x2f1d2e[_0x585b('0x41')](_0x585b('0x70'),_[_0x585b('0x2b')](_0x22367f,'id'));}});})['then'](function(){if(_0xa29269[_0x585b('0x8b')][_0x585b('0x8f')]===_0x585b('0x8c')&&!_0x5116a8&&!_0xa29269[_0x585b('0x35')][_0x585b('0x6f')])return[];return db[_0x585b('0x90')][_0x585b('0x35')](_0x492b54[_0x585b('0x91')](),_0x158077);})[_0x585b('0x23')](function(_0x561400){_0x179502[_0x585b('0x1c')]=_0x561400[_0x585b('0x3c')];if(_0x179502[_0x585b('0x1c')]===0x0)return[];return db[_0x585b('0x90')][_0x585b('0x35')](_0x22e17d[_0x585b('0x91')](),_0x158077)['then'](function(_0x4b96cd){_0x4edd57=_[_0x585b('0x92')](_0x4b96cd,'id');_0x158077=_[_0x585b('0x93')](_0x158077,{'model':db['WhatsappInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0xa29269['query'][_0x585b('0x3a')]){_0x411914[_0x585b('0x3b')][_0x585b('0x30')](function(_0x19383c){_0x2f1d2e['field']('i.'+_0x19383c);});}else{_0x2f1d2e[_0x585b('0x43')](_0x585b('0x86'),_0x585b('0x58'));_0x2f1d2e[_0x585b('0x43')](_0x585b('0x94'),_0x585b('0x95'));_0x2f1d2e[_0x585b('0x43')]('a.mandatoryDisposition',_0x585b('0x96'));_0x2f1d2e['field'](_0x585b('0x97'),_0x585b('0x87'));_0x2f1d2e['field'](_0x585b('0x98'));_0x2f1d2e[_0x585b('0x43')](_0x585b('0x99'),_0x585b('0x9a'));_0x2f1d2e[_0x585b('0x43')](_0x585b('0x9b'),_0x585b('0x9c'));_0x2f1d2e['field']('c.email',_0x585b('0x9d'));_0x2f1d2e[_0x585b('0x43')](_0x585b('0x9e'),_0x585b('0x9f'));_0x2f1d2e[_0x585b('0x43')]('c.mobile',_0x585b('0xa0'));_0x2f1d2e['field'](_0x585b('0xa1'),_0x585b('0xa2'));_0x2f1d2e[_0x585b('0x43')](_0x585b('0xa3'),_0x585b('0xa4'));_0x2f1d2e['field'](_0x585b('0xa5'),_0x585b('0xa6'));_0x2f1d2e[_0x585b('0x43')](_0x585b('0xa7'),_0x585b('0x2d'));}if(_0x411914[_0x585b('0x1e')])_0x2f1d2e[_0x585b('0x1e')](_0x411914[_0x585b('0x1e')]);if(_0x411914['offset'])_0x2f1d2e['offset'](_0x411914[_0x585b('0x1d')]);return db['sequelize'][_0x585b('0x35')](_0x2f1d2e['toString'](),_0x158077);})[_0x585b('0x23')](function(_0x275ba1){_0x56f56b['where'](_0x585b('0xa8'),_['map'](_0x275ba1,'id'));return db[_0x585b('0x90')][_0x585b('0x35')](_0x56f56b[_0x585b('0x91')](),_0x158077)[_0x585b('0x23')](function(_0x427867){var _0x45bb09=_[_0x585b('0xa9')](_0x427867,_0x585b('0xaa'));var _0x542f48=[];_0x275ba1[_0x585b('0x30')](function(_0x2d2fa5){_0x542f48[_0x585b('0xab')](updateWhatsappInteraction(_0x2d2fa5,_0x4edd57,_0x45bb09));});return BPromise[_0x585b('0xac')](_0x542f48);});});})[_0x585b('0x23')](function(_0x3f7e30){_0x179502['rows']=_0x3f7e30;return _0x179502;})['then'](respondWithFilteredResult(_0x7bdaf0,_0x411914))[_0x585b('0x31')](handleError(_0x7bdaf0,null));};exports[_0x585b('0xad')]=function(_0x534f43,_0x507319){var _0x12b57b={'raw':![],'where':{'id':_0x534f43[_0x585b('0xae')]['id']}},_0x44b792={};_0x44b792[_0x585b('0x39')]=_['keys'](db[_0x585b('0x32')][_0x585b('0x33')]);_0x44b792['query']=_[_0x585b('0x36')](_0x534f43[_0x585b('0x35')]);_0x44b792['filters']=_[_0x585b('0x38')](_0x44b792[_0x585b('0x39')],_0x44b792[_0x585b('0x35')]);_0x12b57b['attributes']=_[_0x585b('0x38')](_0x44b792['model'],qs[_0x585b('0x3a')](_0x534f43[_0x585b('0x35')]['fields']));_0x12b57b[_0x585b('0x3b')]=_0x12b57b[_0x585b('0x3b')][_0x585b('0x3c')]?_0x12b57b['attributes']:_0x44b792[_0x585b('0x39')];if(_0x534f43[_0x585b('0x35')][_0x585b('0xaf')]){_0x12b57b[_0x585b('0xb0')]=[{'all':!![]}];}_0x12b57b=_[_0x585b('0x93')]({},_0x12b57b,_0x534f43[_0x585b('0xb1')]);return db[_0x585b('0x32')][_0x585b('0x57')](_0x12b57b)['then'](handleEntityNotFound(_0x507319,null))[_0x585b('0x23')](respondWithResult(_0x507319,null))[_0x585b('0x31')](handleError(_0x507319,null));};exports['create']=function(_0x178080,_0xf62aa9){return db[_0x585b('0x32')][_0x585b('0xb2')](_0x178080[_0x585b('0x6c')],{})[_0x585b('0x23')](respondWithResult(_0xf62aa9,0xc9))[_0x585b('0x31')](handleError(_0xf62aa9,null));};exports[_0x585b('0x22')]=function(_0x13f46f,_0x3b074d){if(_0x13f46f['body']['id']){delete _0x13f46f[_0x585b('0x6c')]['id'];}return db[_0x585b('0x32')]['find']({'where':{'id':_0x13f46f[_0x585b('0xae')]['id']}})['then'](handleEntityNotFound(_0x3b074d,null))[_0x585b('0x23')](saveUpdates(_0x13f46f[_0x585b('0x6c')],null))[_0x585b('0x23')](respondWithResult(_0x3b074d,null))[_0x585b('0x31')](handleError(_0x3b074d,null));};exports[_0x585b('0x24')]=function(_0xbf56fa,_0x19770f){return db[_0x585b('0x32')]['find']({'where':{'id':_0xbf56fa[_0x585b('0xae')]['id']}})[_0x585b('0x23')](handleEntityNotFound(_0x19770f,null))[_0x585b('0x23')](removeEntity(_0x19770f,null))[_0x585b('0x31')](handleError(_0x19770f,null));};exports[_0x585b('0xb3')]=function(_0x5551d6,_0x248a9f){return db[_0x585b('0x32')][_0x585b('0xb3')]()[_0x585b('0x23')](respondWithResult(_0x248a9f,null))[_0x585b('0x31')](handleError(_0x248a9f,null));};exports[_0x585b('0xb4')]=function(_0x2be979,_0x20b373,_0x27849c){return db[_0x585b('0xb5')][_0x585b('0x57')]({'where':{'id':_0x2be979[_0x585b('0xae')]['id']}})['then'](handleEntityNotFound(_0x20b373,null))[_0x585b('0x23')](function(_0x130bad){if(_0x130bad){return _0x130bad[_0x585b('0xb4')](_0x2be979['body']['ids'],_[_0x585b('0xb6')](_0x2be979[_0x585b('0x6c')],[_0x585b('0xb7'),'id'])||{});}})[_0x585b('0x23')](respondWithResult(_0x20b373,null))[_0x585b('0x31')](handleError(_0x20b373,null));};exports['getMessages']=function(_0x163bba,_0x51a5ea,_0x167a09){var _0x343bbe={'raw':![],'where':{}};var _0x3c5e6b={};var _0x427cdb={'count':0x0,'rows':[]};return db[_0x585b('0x32')][_0x585b('0xb8')]({'where':{'id':_0x163bba[_0x585b('0xae')]['id']}})[_0x585b('0x23')](handleEntityNotFound(_0x51a5ea,null))[_0x585b('0x23')](function(_0x2a9b73){if(_0x2a9b73){_0x3c5e6b[_0x585b('0x39')]=_['keys'](db[_0x585b('0xb5')][_0x585b('0x33')]);_0x3c5e6b[_0x585b('0x35')]=_[_0x585b('0x36')](_0x163bba[_0x585b('0x35')]);_0x3c5e6b[_0x585b('0x37')]=_[_0x585b('0x38')](_0x3c5e6b['model'],_0x3c5e6b['query']);_0x343bbe[_0x585b('0x3b')]=_['intersection'](_0x3c5e6b['model'],qs[_0x585b('0x3a')](_0x163bba['query'][_0x585b('0x3a')]));_0x343bbe['attributes']=_0x343bbe[_0x585b('0x3b')]['length']?_0x343bbe[_0x585b('0x3b')]:_0x3c5e6b[_0x585b('0x39')];if(!_0x163bba[_0x585b('0x35')][_0x585b('0x3d')](_0x585b('0x3e'))){_0x343bbe[_0x585b('0x1e')]=qs['limit'](_0x163bba['query']['limit']);_0x343bbe['offset']=qs[_0x585b('0x1d')](_0x163bba[_0x585b('0x35')][_0x585b('0x1d')]);}_0x343bbe[_0x585b('0x3f')]=qs[_0x585b('0x40')](_0x163bba['query'][_0x585b('0x40')]);_0x343bbe[_0x585b('0x41')]=qs[_0x585b('0x37')](_[_0x585b('0x42')](_0x163bba[_0x585b('0x35')],_0x3c5e6b['filters']));_0x343bbe[_0x585b('0x41')][_0x585b('0xaa')]=_0x2a9b73['id'];if(_0x163bba[_0x585b('0x35')]['filter']){_0x343bbe[_0x585b('0x41')]=_[_0x585b('0x93')](_0x343bbe[_0x585b('0x41')],{'$or':_[_0x585b('0x2b')](_0x343bbe[_0x585b('0x3b')],function(_0x2d6189){var _0x815629={};_0x815629[_0x2d6189]={'$like':'%'+_0x163bba[_0x585b('0x35')]['filter']+'%'};return _0x815629;})});}if(_0x163bba['query']['$gte']){var _0x4bf958=_0x163bba['query'][_0x585b('0x73')]['split'](',');var _0xa5466b={};_0xa5466b[_0x4bf958[0x0]]={'$gte':moment(_0x4bf958[0x1])[_0x585b('0xb9')](_0x585b('0xba'))};_0x343bbe[_0x585b('0x41')]=_['merge'](_0x343bbe[_0x585b('0x41')],_0xa5466b);}_0x343bbe=_[_0x585b('0x93')]({},_0x343bbe,_0x163bba[_0x585b('0xb1')]);return db['WhatsappMessage']['count']({'where':_0x343bbe['where']})['then'](function(_0x3ded3a){_0x427cdb[_0x585b('0x1c')]=_0x3ded3a;if(_0x163bba['query'][_0x585b('0xaf')]){_0x343bbe[_0x585b('0xb0')]=[{'all':!![]}];}return db[_0x585b('0xb5')][_0x585b('0xbb')](_0x343bbe);})[_0x585b('0x23')](function(_0x1760c0){_0x427cdb[_0x585b('0xbc')]=_0x1760c0;return _0x427cdb;});}})[_0x585b('0x23')](respondWithFilteredResult(_0x51a5ea,_0x343bbe))[_0x585b('0x31')](handleError(_0x51a5ea,null));};exports[_0x585b('0xbd')]=function(_0x2db02d,_0x4649dd,_0x49ba08){return db[_0x585b('0x32')][_0x585b('0x57')]({'where':{'id':_0x2db02d[_0x585b('0xae')]['id']}})[_0x585b('0x23')](handleEntityNotFound(_0x4649dd,null))[_0x585b('0x23')](function(_0x4ef10f){if(_0x4ef10f){return _0x4ef10f['setTags'](_0x2db02d[_0x585b('0x6c')][_0x585b('0xb7')],_['omit'](_0x2db02d[_0x585b('0x6c')],[_0x585b('0xb7'),'id'])||{})[_0x585b('0xbe')](function(){return db[_0x585b('0x65')]['findAll']({'attributes':['id',_0x585b('0x28'),_0x585b('0xbf')],'where':{'id':_0x2db02d[_0x585b('0x6c')][_0x585b('0xb7')]}});})['then'](function(_0x37b5d1){socket[_0x585b('0xc0')](_0x585b('0xc1'),{'id':Number(_0x2db02d[_0x585b('0xae')]['id']),'tags':_0x37b5d1||[]});return{'id':Number(_0x2db02d[_0x585b('0xae')]['id']),'tags':_0x37b5d1||[]};});}})[_0x585b('0x23')](respondWithResult(_0x4649dd,null))[_0x585b('0x31')](handleError(_0x4649dd,null));};exports[_0x585b('0xc2')]=function(_0x505bd6,_0x15b9d5,_0x5a7275){return db[_0x585b('0x32')][_0x585b('0x57')]({'where':{'id':_0x505bd6[_0x585b('0xae')]['id']}})[_0x585b('0x23')](handleEntityNotFound(_0x15b9d5,null))[_0x585b('0x23')](function(_0x3dc482){if(_0x3dc482){return _0x3dc482['removeTags'](_0x505bd6['query'][_0x585b('0xb7')]);}})['then'](respondWithStatusCode(_0x15b9d5,null))[_0x585b('0x31')](handleError(_0x15b9d5,null));};exports[_0x585b('0xc3')]=function(_0x5b2a99,_0x2915f1){var _0x758fe2=moment()[_0x585b('0xc4')]()[_0x585b('0x91')]();var _0x801a3c=path['join'](config[_0x585b('0xc5')],_0x585b('0xc6'),'files',_0x585b('0xc7'));var _0x36ded5=path[_0x585b('0xc8')](config['root'],'server',_0x585b('0xc9'),_0x585b('0xca'));var _0x4f0fb5=path[_0x585b('0xc8')](_0x801a3c,_0x758fe2);var _0x42c96b=util[_0x585b('0xb9')](_0x585b('0xcb'),_0x5b2a99['params']['id'],_0x758fe2);var _0x3688b2=path[_0x585b('0xc8')](_0x801a3c,_0x42c96b);var _0x1ce4d1=[];_0x1ce4d1[_0x585b('0xab')]({'model':db['User'],'as':'User','attributes':['id',_0x585b('0x2c')],'raw':!![]});_0x1ce4d1[_0x585b('0xab')]({'model':db[_0x585b('0xcc')],'as':_0x585b('0x5d'),'attributes':['id',_0x585b('0xcd'),_0x585b('0xce')],'raw':!![]});if(_0x5b2a99[_0x585b('0x35')][_0x585b('0xca')]){_0x1ce4d1[_0x585b('0xab')]({'model':db[_0x585b('0xcf')],'as':_0x585b('0xcf'),'raw':!![]});}var _0x6ccf6f=[{'model':db[_0x585b('0xb5')],'as':_0x585b('0xd0'),'attributes':['id',_0x585b('0x6c'),_0x585b('0x72'),'direction',_0x585b('0xd1'),_0x585b('0x79')],'include':_0x1ce4d1}];_0x6ccf6f[_0x585b('0xab')]({'model':db['WhatsappAccount'],'as':_0x585b('0xd2'),'attributes':['id',_0x585b('0x28')]});_0x6ccf6f[_0x585b('0xab')]({'model':db[_0x585b('0x68')],'as':_0x585b('0xd3'),'attributes':['id','fullname']});return db[_0x585b('0x32')][_0x585b('0x57')]({'where':{'id':_0x5b2a99[_0x585b('0xae')]['id']},'include':_0x6ccf6f})[_0x585b('0x23')](handleEntityNotFound(_0x2915f1,null))[_0x585b('0x23')](function(_0x486c3d){if(_0x486c3d){var _0x590b02=_0x486c3d['get']({'plain':!![]});fs['mkdirSync'](_0x4f0fb5);var _0x4193e8={'format':'A4','border':_0x585b('0xd4'),'header':{'height':_0x585b('0xd5'),'contents':{'first':_0x585b('0xd6')}},'footer':{'height':_0x585b('0xd7'),'contents':{'default':util[_0x585b('0xb9')](_0x585b('0xd8'),util['format'](_0x585b('0xd9'),_0x585b('0xda'),_0x590b02['id']),moment()[_0x585b('0xb9')](_0x585b('0xdb'))[_0x585b('0x91')]())}}};var _0x164c02={'channel':_0x585b('0xda'),'account':_0x590b02['Account'][_0x585b('0x28')],'agent':_0x590b02[_0x585b('0xd3')]?_0x590b02['Owner'][_0x585b('0x2c')]:_0x585b('0xdc'),'createdAt':moment(_0x590b02['createdAt'])[_0x585b('0xb9')](_0x585b('0xba'))[_0x585b('0x91')](),'closedAt':_0x590b02['closed']?moment(_0x590b02[_0x585b('0xdd')])[_0x585b('0xb9')]('YYYY-MM-DD\x20HH:mm:ss')[_0x585b('0x91')]():'','disposition':_0x590b02[_0x585b('0xde')],'messages':_(_0x590b02[_0x585b('0xd0')])['filter']({'secret':![]})[_0x585b('0x2b')](function(_0x299cbd){if(_0x299cbd['Attachment']){var _0x363a0d=path['join'](_0x36ded5,_0x299cbd[_0x585b('0xcf')][_0x585b('0xdf')]);if(fs[_0x585b('0xe0')](_0x363a0d)){fs['createReadStream'](_0x363a0d)[_0x585b('0xe1')](fs['createWriteStream'](path[_0x585b('0xc8')](_0x4f0fb5,_0x299cbd[_0x585b('0xcf')][_0x585b('0xdf')])));}}return{'date':moment(_0x299cbd[_0x585b('0x72')])[_0x585b('0xb9')](_0x585b('0xba'))[_0x585b('0x91')](),'sender':_0x299cbd[_0x585b('0xe2')]===_0x585b('0xe3')?_0x299cbd[_0x585b('0x68')]?_0x299cbd[_0x585b('0x68')]['fullname']:_0x585b('0xe4'):_0x299cbd['Contact']['firstName']+(_0x299cbd[_0x585b('0x5d')][_0x585b('0xce')]?'\x20'+_0x299cbd[_0x585b('0x5d')][_0x585b('0xce')]:''),'body':_0x299cbd[_0x585b('0xcf')]?_0x299cbd[_0x585b('0xcf')][_0x585b('0xdf')]:_0x299cbd[_0x585b('0x6c')],'direction':_0x299cbd[_0x585b('0xe2')]==='out'?'A':'C','secret':_0x299cbd[_0x585b('0xd1')],'read':_0x299cbd['read'],'attachment':_0x299cbd[_0x585b('0xcf')]};})['value']()};return ejs[_0x585b('0xe5')](path[_0x585b('0xc8')](config[_0x585b('0xc5')],_0x585b('0xc6'),_0x585b('0xe6'),'downloadInteraction.html'),{'interaction':_0x164c02})[_0x585b('0x23')](function(_0x13ea2f){return new BPromise(function(_0x4ed53a,_0x19f5cd){pdf[_0x585b('0xb2')](_0x13ea2f,_0x4193e8)['toFile'](path['join'](_0x4f0fb5,_0x585b('0xe7')+_0x590b02['id']+'-'+_0x758fe2+_0x585b('0xe8')),function(_0x50c10e,_0x6e49a7){if(_0x50c10e)return _0x19f5cd(_0x50c10e);_0x4ed53a(_0x6e49a7);});});})[_0x585b('0x23')](function(){return new BPromise(function(_0x489eb6,_0xe4d883){zipdir(_0x4f0fb5,{'saveTo':_0x3688b2},function(_0x313667,_0x2d04a5){if(_0x313667)return _0xe4d883(_0x313667);return _0x489eb6(_0x2d04a5);});})[_0x585b('0x23')](function(){return new BPromise(function(_0x2d787c,_0x353b55){rimraf(_0x4f0fb5,function(_0x5be7fd){if(_0x5be7fd)_0x353b55(_0x5be7fd);return _0x2d787c();});});})[_0x585b('0x23')](function(){return _0x2915f1[_0x585b('0xc3')](_0x3688b2,_0x42c96b,function(_0x249edc){if(_0x249edc){console[_0x585b('0xe9')](_0x585b('0xea'),_0x249edc);}else{fs[_0x585b('0xeb')](_0x3688b2);}});});});}else{return _0x2915f1[_0x585b('0x25')](0xc8);}})[_0x585b('0x31')](handleError(_0x2915f1,null));};
\ No newline at end of file
+var _0x4d4a=['CmContact','lastName','Attachment','Messages','createdAt','direction','secret','WhatsappAccount','Account','Owner','fullname','get','mkdirSync','Whatsapp','N.A.','closed','closedAt','existsSync','createReadStream','createWriteStream','basename','out','System','Contact','firstName','read','renderFile','views','downloadInteraction.ejs','.pdf','createPdfFromHTML','log','err','unlinkSync','zip-dir','moment','bluebird','util','path','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','api','../../config/environment','../../mysqldb','redis','localhost','socket.io-emitter','./whatsappInteraction.socket','register','sendStatus','status','end','json','undefined','limit','count','offset','set','Content-Range','update','then','error','stack','name','send','index','map','WhatsappInteraction','fieldName','type','key','getOptions','findAll','whatsapp','query','user','show','params','keys','filters','intersection','model','attributes','fields','includeAll','options','find','catch','create','body','destroy','describe','addMessage','WhatsappMessage','ids','findOne','hasOwnProperty','nolimit','order','sort','where','pick','WhatsappInteractionId','filter','merge','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','include','rows','addTags','setTags','omit','Tag','color','whatsappInteractionTags:save','removeTags','download','unix','toString','join','server','files','root','attachments','push','User'];(function(_0x204a28,_0x1c2f71){var _0x3388a2=function(_0x4836e9){while(--_0x4836e9){_0x204a28['push'](_0x204a28['shift']());}};_0x3388a2(++_0x1c2f71);}(_0x4d4a,0x124));var _0xa4d4=function(_0x413feb,_0x10477f){_0x413feb=_0x413feb-0x0;var _0x40ee88=_0x4d4a[_0x413feb];return _0x40ee88;};'use strict';var rimraf=require('rimraf');var zipdir=require(_0xa4d4('0x0'));var moment=require(_0xa4d4('0x1'));var BPromise=require(_0xa4d4('0x2'));var util=require(_0xa4d4('0x3'));var path=require(_0xa4d4('0x4'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var Redis=require('ioredis');var interaction=require(_0xa4d4('0x5'));var qs=require(_0xa4d4('0x6'));var pdf=require(_0xa4d4('0x7'));var logger=require('../../config/logger')(_0xa4d4('0x8'));var config=require(_0xa4d4('0x9'));var db=require(_0xa4d4('0xa'))['db'];config[_0xa4d4('0xb')]=_['defaults'](config['redis'],{'host':_0xa4d4('0xc'),'port':0x18eb});var socket=require(_0xa4d4('0xd'))(new Redis(config[_0xa4d4('0xb')]));require(_0xa4d4('0xe'))[_0xa4d4('0xf')](socket);function respondWithStatusCode(_0x33c1bf,_0x4b914b){_0x4b914b=_0x4b914b||0xcc;return function(_0x26c167){if(_0x26c167){return _0x33c1bf[_0xa4d4('0x10')](_0x4b914b);}return _0x33c1bf[_0xa4d4('0x11')](_0x4b914b)[_0xa4d4('0x12')]();};}function respondWithResult(_0x2cc6a6,_0x2b212d){_0x2b212d=_0x2b212d||0xc8;return function(_0x5f3f37){if(_0x5f3f37){return _0x2cc6a6[_0xa4d4('0x11')](_0x2b212d)[_0xa4d4('0x13')](_0x5f3f37);}};}function respondWithFilteredResult(_0x1dc46e,_0x192f26){return function(_0x3bb391){if(_0x3bb391){var _0x2e648b=typeof _0x192f26['offset']===_0xa4d4('0x14')&&typeof _0x192f26[_0xa4d4('0x15')]===_0xa4d4('0x14');var _0x170b55=_0x3bb391[_0xa4d4('0x16')];var _0x1326b5=_0x2e648b?0x0:_0x192f26[_0xa4d4('0x17')];var _0x375975=_0x2e648b?_0x3bb391[_0xa4d4('0x16')]:_0x192f26[_0xa4d4('0x17')]+_0x192f26[_0xa4d4('0x15')];var _0x329f88;if(_0x375975>=_0x170b55){_0x375975=_0x170b55;_0x329f88=0xc8;}else{_0x329f88=0xce;}_0x1dc46e[_0xa4d4('0x11')](_0x329f88);return _0x1dc46e[_0xa4d4('0x18')](_0xa4d4('0x19'),_0x1326b5+'-'+_0x375975+'/'+_0x170b55)[_0xa4d4('0x13')](_0x3bb391);}return null;};}function saveUpdates(_0x41c7e6){return function(_0x5515dd){if(_0x5515dd){return _0x5515dd[_0xa4d4('0x1a')](_0x41c7e6)[_0xa4d4('0x1b')](function(_0x1cf1f6){return _0x1cf1f6;});}return null;};}function removeEntity(_0x5e5027){return function(_0x180b37){if(_0x180b37){return _0x180b37['destroy']()[_0xa4d4('0x1b')](function(){_0x5e5027[_0xa4d4('0x11')](0xcc)[_0xa4d4('0x12')]();});}};}function handleEntityNotFound(_0xcc7aea){return function(_0xb7df0f){if(!_0xb7df0f){_0xcc7aea[_0xa4d4('0x10')](0x194);}return _0xb7df0f;};}function handleError(_0x434513,_0x5ab6f1){_0x5ab6f1=_0x5ab6f1||0x1f4;return function(_0x3c024d){logger[_0xa4d4('0x1c')](_0x3c024d[_0xa4d4('0x1d')]);if(_0x3c024d[_0xa4d4('0x1e')]){delete _0x3c024d['name'];}_0x434513['status'](_0x5ab6f1)[_0xa4d4('0x1f')](_0x3c024d);};}exports[_0xa4d4('0x20')]=function(_0xbef48e,_0x3abe5f){var _0x189aa5={};var _0x171756=_[_0xa4d4('0x21')](db[_0xa4d4('0x22')]['rawAttributes'],function(_0x4836ff){return{'name':_0x4836ff[_0xa4d4('0x23')],'type':_0x4836ff[_0xa4d4('0x24')][_0xa4d4('0x25')]};});_0x189aa5=qs[_0xa4d4('0x26')](_0x171756,_0xbef48e);return interaction[_0xa4d4('0x27')](_0xa4d4('0x28'),_0xbef48e[_0xa4d4('0x29')],_0xbef48e[_0xa4d4('0x2a')],_0x189aa5,_0x171756)[_0xa4d4('0x1b')](respondWithFilteredResult(_0x3abe5f,_0x189aa5))['catch'](handleError(_0x3abe5f,null));};exports[_0xa4d4('0x2b')]=function(_0x90c401,_0x1df1e7){var _0x22453d={'raw':![],'where':{'id':_0x90c401[_0xa4d4('0x2c')]['id']}},_0x4fcc13={};_0x4fcc13['model']=_[_0xa4d4('0x2d')](db[_0xa4d4('0x22')]['rawAttributes']);_0x4fcc13['query']=_['keys'](_0x90c401[_0xa4d4('0x29')]);_0x4fcc13[_0xa4d4('0x2e')]=_[_0xa4d4('0x2f')](_0x4fcc13[_0xa4d4('0x30')],_0x4fcc13['query']);_0x22453d[_0xa4d4('0x31')]=_[_0xa4d4('0x2f')](_0x4fcc13[_0xa4d4('0x30')],qs[_0xa4d4('0x32')](_0x90c401[_0xa4d4('0x29')][_0xa4d4('0x32')]));_0x22453d[_0xa4d4('0x31')]=_0x22453d[_0xa4d4('0x31')]['length']?_0x22453d[_0xa4d4('0x31')]:_0x4fcc13[_0xa4d4('0x30')];if(_0x90c401[_0xa4d4('0x29')][_0xa4d4('0x33')]){_0x22453d['include']=[{'all':!![]}];}_0x22453d=_['merge']({},_0x22453d,_0x90c401[_0xa4d4('0x34')]);return db['WhatsappInteraction'][_0xa4d4('0x35')](_0x22453d)[_0xa4d4('0x1b')](handleEntityNotFound(_0x1df1e7,null))[_0xa4d4('0x1b')](respondWithResult(_0x1df1e7,null))[_0xa4d4('0x36')](handleError(_0x1df1e7,null));};exports[_0xa4d4('0x37')]=function(_0x15ba8d,_0x4288de){return db[_0xa4d4('0x22')][_0xa4d4('0x37')](_0x15ba8d[_0xa4d4('0x38')],{})['then'](respondWithResult(_0x4288de,0xc9))[_0xa4d4('0x36')](handleError(_0x4288de,null));};exports['update']=function(_0x2310c2,_0x516443){if(_0x2310c2[_0xa4d4('0x38')]['id']){delete _0x2310c2[_0xa4d4('0x38')]['id'];}return db[_0xa4d4('0x22')][_0xa4d4('0x35')]({'where':{'id':_0x2310c2[_0xa4d4('0x2c')]['id']}})[_0xa4d4('0x1b')](handleEntityNotFound(_0x516443,null))[_0xa4d4('0x1b')](saveUpdates(_0x2310c2['body'],null))[_0xa4d4('0x1b')](respondWithResult(_0x516443,null))[_0xa4d4('0x36')](handleError(_0x516443,null));};exports[_0xa4d4('0x39')]=function(_0x425815,_0x5e0afa){return db[_0xa4d4('0x22')][_0xa4d4('0x35')]({'where':{'id':_0x425815['params']['id']}})[_0xa4d4('0x1b')](handleEntityNotFound(_0x5e0afa,null))[_0xa4d4('0x1b')](removeEntity(_0x5e0afa,null))[_0xa4d4('0x36')](handleError(_0x5e0afa,null));};exports[_0xa4d4('0x3a')]=function(_0xbf9013,_0x47dfb2){return db[_0xa4d4('0x22')][_0xa4d4('0x3a')]()[_0xa4d4('0x1b')](respondWithResult(_0x47dfb2,null))[_0xa4d4('0x36')](handleError(_0x47dfb2,null));};exports[_0xa4d4('0x3b')]=function(_0x5be48d,_0x520ce3){return db[_0xa4d4('0x3c')][_0xa4d4('0x35')]({'where':{'id':_0x5be48d[_0xa4d4('0x2c')]['id']}})[_0xa4d4('0x1b')](handleEntityNotFound(_0x520ce3,null))[_0xa4d4('0x1b')](function(_0x409eb8){if(_0x409eb8){return _0x409eb8[_0xa4d4('0x3b')](_0x5be48d['body'][_0xa4d4('0x3d')],_['omit'](_0x5be48d[_0xa4d4('0x38')],[_0xa4d4('0x3d'),'id'])||{});}})[_0xa4d4('0x1b')](respondWithResult(_0x520ce3,null))[_0xa4d4('0x36')](handleError(_0x520ce3,null));};exports['getMessages']=function(_0x25f6da,_0x1e47cf){var _0x5a46e6={'raw':![],'where':{}};var _0x375811={};var _0x2662e3={'count':0x0,'rows':[]};return db[_0xa4d4('0x22')][_0xa4d4('0x3e')]({'where':{'id':_0x25f6da[_0xa4d4('0x2c')]['id']}})[_0xa4d4('0x1b')](handleEntityNotFound(_0x1e47cf,null))[_0xa4d4('0x1b')](function(_0x54c35c){if(_0x54c35c){_0x375811['model']=_[_0xa4d4('0x2d')](db['WhatsappMessage']['rawAttributes']);_0x375811[_0xa4d4('0x29')]=_['keys'](_0x25f6da[_0xa4d4('0x29')]);_0x375811[_0xa4d4('0x2e')]=_[_0xa4d4('0x2f')](_0x375811['model'],_0x375811[_0xa4d4('0x29')]);_0x5a46e6[_0xa4d4('0x31')]=_['intersection'](_0x375811['model'],qs[_0xa4d4('0x32')](_0x25f6da['query']['fields']));_0x5a46e6['attributes']=_0x5a46e6[_0xa4d4('0x31')]['length']?_0x5a46e6[_0xa4d4('0x31')]:_0x375811[_0xa4d4('0x30')];if(!_0x25f6da[_0xa4d4('0x29')][_0xa4d4('0x3f')](_0xa4d4('0x40'))){_0x5a46e6[_0xa4d4('0x15')]=qs[_0xa4d4('0x15')](_0x25f6da['query'][_0xa4d4('0x15')]);_0x5a46e6[_0xa4d4('0x17')]=qs['offset'](_0x25f6da[_0xa4d4('0x29')][_0xa4d4('0x17')]);}_0x5a46e6[_0xa4d4('0x41')]=qs[_0xa4d4('0x42')](_0x25f6da['query']['sort']);_0x5a46e6[_0xa4d4('0x43')]=qs[_0xa4d4('0x2e')](_[_0xa4d4('0x44')](_0x25f6da[_0xa4d4('0x29')],_0x375811[_0xa4d4('0x2e')]));_0x5a46e6[_0xa4d4('0x43')][_0xa4d4('0x45')]=_0x54c35c['id'];if(_0x25f6da[_0xa4d4('0x29')][_0xa4d4('0x46')]){_0x5a46e6['where']=_[_0xa4d4('0x47')](_0x5a46e6['where'],{'$or':_[_0xa4d4('0x21')](_0x5a46e6[_0xa4d4('0x31')],function(_0x1dafde){var _0x3c3338={};_0x3c3338[_0x1dafde]={'$like':'%'+_0x25f6da[_0xa4d4('0x29')]['filter']+'%'};return _0x3c3338;})});}if(_0x25f6da[_0xa4d4('0x29')][_0xa4d4('0x48')]){var _0x246baa=_0x25f6da[_0xa4d4('0x29')][_0xa4d4('0x48')][_0xa4d4('0x49')](',');var _0x2656f3={};_0x2656f3[_0x246baa[0x0]]={'$gte':moment(_0x246baa[0x1])[_0xa4d4('0x4a')](_0xa4d4('0x4b'))};_0x5a46e6[_0xa4d4('0x43')]=_['merge'](_0x5a46e6[_0xa4d4('0x43')],_0x2656f3);}_0x5a46e6=_['merge']({},_0x5a46e6,_0x25f6da[_0xa4d4('0x34')]);return db[_0xa4d4('0x3c')][_0xa4d4('0x16')]({'where':_0x5a46e6[_0xa4d4('0x43')]})[_0xa4d4('0x1b')](function(_0x3dc9ea){_0x2662e3[_0xa4d4('0x16')]=_0x3dc9ea;if(_0x25f6da[_0xa4d4('0x29')][_0xa4d4('0x33')]){_0x5a46e6[_0xa4d4('0x4c')]=[{'all':!![]}];}return db[_0xa4d4('0x3c')][_0xa4d4('0x27')](_0x5a46e6);})['then'](function(_0x1f76f7){_0x2662e3[_0xa4d4('0x4d')]=_0x1f76f7;return _0x2662e3;});}})[_0xa4d4('0x1b')](respondWithFilteredResult(_0x1e47cf,_0x5a46e6))[_0xa4d4('0x36')](handleError(_0x1e47cf,null));};exports[_0xa4d4('0x4e')]=function(_0x49ddf3,_0x41eb19){return db[_0xa4d4('0x22')]['find']({'where':{'id':_0x49ddf3['params']['id']}})[_0xa4d4('0x1b')](handleEntityNotFound(_0x41eb19,null))[_0xa4d4('0x1b')](function(_0x299024){if(_0x299024){return _0x299024[_0xa4d4('0x4f')](_0x49ddf3[_0xa4d4('0x38')][_0xa4d4('0x3d')],_[_0xa4d4('0x50')](_0x49ddf3[_0xa4d4('0x38')],[_0xa4d4('0x3d'),'id'])||{})['spread'](function(){return db[_0xa4d4('0x51')]['findAll']({'attributes':['id',_0xa4d4('0x1e'),_0xa4d4('0x52')],'where':{'id':_0x49ddf3['body'][_0xa4d4('0x3d')]}});})['then'](function(_0x2ed397){socket['emit'](_0xa4d4('0x53'),{'id':Number(_0x49ddf3[_0xa4d4('0x2c')]['id']),'tags':_0x2ed397||[]});return{'id':Number(_0x49ddf3[_0xa4d4('0x2c')]['id']),'tags':_0x2ed397||[]};});}})[_0xa4d4('0x1b')](respondWithResult(_0x41eb19,null))['catch'](handleError(_0x41eb19,null));};exports[_0xa4d4('0x54')]=function(_0x152f09,_0x859c25){return db[_0xa4d4('0x22')][_0xa4d4('0x35')]({'where':{'id':_0x152f09[_0xa4d4('0x2c')]['id']}})[_0xa4d4('0x1b')](handleEntityNotFound(_0x859c25,null))['then'](function(_0x2b27d8){if(_0x2b27d8){return _0x2b27d8[_0xa4d4('0x54')](_0x152f09[_0xa4d4('0x29')][_0xa4d4('0x3d')]);}})[_0xa4d4('0x1b')](respondWithStatusCode(_0x859c25,null))[_0xa4d4('0x36')](handleError(_0x859c25,null));};exports[_0xa4d4('0x55')]=function(_0x383b33,_0xcbaaaa){var _0x5d7c4d=moment()[_0xa4d4('0x56')]()[_0xa4d4('0x57')]();var _0x33150b=path[_0xa4d4('0x58')](config['root'],_0xa4d4('0x59'),_0xa4d4('0x5a'),'tmp');var _0x51bcb0=path[_0xa4d4('0x58')](config[_0xa4d4('0x5b')],_0xa4d4('0x59'),'files',_0xa4d4('0x5c'));var _0x57808c=path[_0xa4d4('0x58')](_0x33150b,_0x5d7c4d);var _0x102fe9=util[_0xa4d4('0x4a')]('transcript-%d-%s.zip',_0x383b33[_0xa4d4('0x2c')]['id'],_0x5d7c4d);var _0x2da00a=path['join'](_0x33150b,_0x102fe9);var _0x199c43=[];_0x199c43[_0xa4d4('0x5d')]({'model':db[_0xa4d4('0x5e')],'as':_0xa4d4('0x5e'),'attributes':['id','fullname'],'raw':!![]});_0x199c43[_0xa4d4('0x5d')]({'model':db[_0xa4d4('0x5f')],'as':'Contact','attributes':['id','firstName',_0xa4d4('0x60')],'raw':!![]});if(_0x383b33[_0xa4d4('0x29')][_0xa4d4('0x5c')]){_0x199c43['push']({'model':db[_0xa4d4('0x61')],'as':'Attachment','raw':!![]});}var _0x41ccd7=[{'model':db[_0xa4d4('0x3c')],'as':_0xa4d4('0x62'),'attributes':['id','body',_0xa4d4('0x63'),_0xa4d4('0x64'),_0xa4d4('0x65'),'read'],'include':_0x199c43}];_0x41ccd7[_0xa4d4('0x5d')]({'model':db[_0xa4d4('0x66')],'as':_0xa4d4('0x67'),'attributes':['id',_0xa4d4('0x1e')]});_0x41ccd7['push']({'model':db[_0xa4d4('0x5e')],'as':_0xa4d4('0x68'),'attributes':['id',_0xa4d4('0x69')]});return db[_0xa4d4('0x22')][_0xa4d4('0x35')]({'where':{'id':_0x383b33['params']['id']},'include':_0x41ccd7})[_0xa4d4('0x1b')](handleEntityNotFound(_0xcbaaaa,null))['then'](function(_0xd72089){if(_0xd72089){var _0x31856b=_0xd72089[_0xa4d4('0x6a')]({'plain':!![]});fs[_0xa4d4('0x6b')](_0x57808c);var _0x139631={'channel':_0xa4d4('0x6c'),'account':_0x31856b[_0xa4d4('0x67')]['name'],'agent':_0x31856b['Owner']?_0x31856b[_0xa4d4('0x68')][_0xa4d4('0x69')]:_0xa4d4('0x6d'),'createdAt':moment(_0x31856b[_0xa4d4('0x63')])[_0xa4d4('0x4a')](_0xa4d4('0x4b'))[_0xa4d4('0x57')](),'closedAt':_0x31856b[_0xa4d4('0x6e')]?moment(_0x31856b[_0xa4d4('0x6f')])[_0xa4d4('0x4a')](_0xa4d4('0x4b'))['toString']():'','disposition':_0x31856b['disposition'],'messages':_(_0x31856b[_0xa4d4('0x62')])['filter']({'secret':![]})[_0xa4d4('0x21')](function(_0x3c9a04){if(_0x3c9a04['Attachment']){var _0x3a4e5f=path[_0xa4d4('0x58')](_0x51bcb0,_0x3c9a04['Attachment']['basename']);if(fs[_0xa4d4('0x70')](_0x3a4e5f)){fs[_0xa4d4('0x71')](_0x3a4e5f)['pipe'](fs[_0xa4d4('0x72')](path[_0xa4d4('0x58')](_0x57808c,_0x3c9a04['Attachment'][_0xa4d4('0x73')])));}}return{'date':moment(_0x3c9a04[_0xa4d4('0x63')])[_0xa4d4('0x4a')](_0xa4d4('0x4b'))[_0xa4d4('0x57')](),'sender':_0x3c9a04[_0xa4d4('0x64')]===_0xa4d4('0x74')?_0x3c9a04[_0xa4d4('0x5e')]?_0x3c9a04[_0xa4d4('0x5e')][_0xa4d4('0x69')]:_0xa4d4('0x75'):_0x3c9a04[_0xa4d4('0x76')][_0xa4d4('0x77')]+(_0x3c9a04['Contact'][_0xa4d4('0x60')]?'\x20'+_0x3c9a04['Contact'][_0xa4d4('0x60')]:''),'body':_0x3c9a04[_0xa4d4('0x61')]?_0x3c9a04[_0xa4d4('0x61')][_0xa4d4('0x73')]:_0x3c9a04[_0xa4d4('0x38')],'direction':_0x3c9a04[_0xa4d4('0x64')]==='out'?'A':'C','secret':_0x3c9a04[_0xa4d4('0x65')],'read':_0x3c9a04[_0xa4d4('0x78')],'attachment':_0x3c9a04[_0xa4d4('0x61')]};})['value']()};return ejs[_0xa4d4('0x79')](path['join'](config[_0xa4d4('0x5b')],'server',_0xa4d4('0x7a'),_0xa4d4('0x7b')),{'interaction':_0x139631})['then'](function(_0x3fbff1){var _0x210772=path[_0xa4d4('0x58')](_0x57808c,'transcript-'+_0x31856b['id']+'-'+_0x5d7c4d+_0xa4d4('0x7c'));var _0x595e61={'path':_0x210772,'channel':'Whatsapp','interactionId':_0x31856b['id']};return pdf[_0xa4d4('0x7d')](_0x3fbff1,_0x595e61);})['then'](function(){return new BPromise(function(_0x175a42,_0x337760){zipdir(_0x57808c,{'saveTo':_0x2da00a},function(_0x5c2a17,_0x5dc68b){if(_0x5c2a17)return _0x337760(_0x5c2a17);return _0x175a42(_0x5dc68b);});})[_0xa4d4('0x1b')](function(){return new BPromise(function(_0x2ad63d,_0x3cc7ad){rimraf(_0x57808c,function(_0xee37f6){if(_0xee37f6)_0x3cc7ad(_0xee37f6);return _0x2ad63d();});});})[_0xa4d4('0x1b')](function(){return _0xcbaaaa[_0xa4d4('0x55')](_0x2da00a,_0x102fe9,function(_0x2283fc){if(_0x2283fc){console[_0xa4d4('0x7e')](_0xa4d4('0x7f'),_0x2283fc);}else{fs[_0xa4d4('0x80')](_0x2da00a);}});});});}else{return _0xcbaaaa[_0xa4d4('0x10')](0xc8);}})[_0xa4d4('0x36')](handleError(_0xcbaaaa,null));};
\ No newline at end of file