Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index 33bacd0..36629f4 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xb5fa=['lastName','renderFile','views','downloadInteraction.ejs','transcript-','createPdfFromHTML','log','err','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../mysqldb','redis','localhost','socket.io-emitter','./whatsappInteraction.socket','register','sendStatus','status','end','json','offset','undefined','limit','count','set','apply','reject','update','then','error','stack','name','Users','TagIds','Tags','split','push','catch','waiting','talking','answered','unmanaged','total','UserId','closed','index','map','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','sort','pick','select','field','color','from','tools_tags','u.id','u.fullname','user_has_whatsapp_interactions','users','u.id\x20=\x20ui.UserId','left_join','cm_contacts','whatsapp_accounts','whatsapp_messages','me.WhatsappInteractionId\x20=\x20i.id','whatsapp_interaction_has_tags','it.WhatsappInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','search','parseSearch','sqlOperator','conditions','length','find','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','operator','$substring','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','text','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','buildExpression','body','some','compact','isEmpty','forEach','i.WhatsappAccountId\x20IN\x20?','createdAt','$gte','$lte','where','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','tag','isArray','filter','replace','i.id\x20LIKE\x20?','i.phone\x20LIKE\x20?','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','Sequelize','QueryTypes','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','order','contactName','DESC','t.id\x20IN\x20?','resolve','WhatsappAccountId','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','role','user','i.WhatsappAccountId\x20IS\x20NULL','agent','sequelize','keyBy','merge','WhatsappInteraction','a.key','Account.key','Account.mandatoryDisposition','c.firstName','Contact.firstName','Contact.lastName','c.email','Contact.email','c.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','toString','ui.WhatsappInteractionId\x20IN\x20?','groupBy','WhatsappInteractionId','all','rows','params','includeAll','options','create','describe','WhatsappMessage','addMessage','ids','omit','getMessages','nolimit','format','findAll','setTags','emit','whatsappInteractionTags:save','removeTags','download','root','server','files','tmp','join','attachments','transcript-%d-%s.zip','fullname','CmContact','firstName','Attachment','Messages','direction','secret','WhatsappAccount','Account','Owner','get','mkdirSync','Whatsapp','N.A.','YYYY-MM-DD\x20HH:mm:ss','closedAt','disposition','existsSync','createReadStream','pipe','createWriteStream','basename','out','System'];(function(_0x37c096,_0x3abf0f){var _0x29c4f3=function(_0x436e67){while(--_0x436e67){_0x37c096['push'](_0x37c096['shift']());}};_0x29c4f3(++_0x3abf0f);}(_0xb5fa,0xf8));var _0xab5f=function(_0x52326e,_0x18f7b5){_0x52326e=_0x52326e-0x0;var _0x39b11e=_0xb5fa[_0x52326e];return _0x39b11e;};'use strict';var emlformat=require(_0xab5f('0x0'));var rimraf=require(_0xab5f('0x1'));var zipdir=require(_0xab5f('0x2'));var jsonpatch=require(_0xab5f('0x3'));var rp=require(_0xab5f('0x4'));var moment=require(_0xab5f('0x5'));var BPromise=require(_0xab5f('0x6'));var Mustache=require(_0xab5f('0x7'));var util=require(_0xab5f('0x8'));var path=require(_0xab5f('0x9'));var sox=require(_0xab5f('0xa'));var csv=require(_0xab5f('0xb'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0xab5f('0xc'));var crypto=require(_0xab5f('0xd'));var jsforce=require('jsforce');var deskjs=require(_0xab5f('0xe'));var toCsv=require(_0xab5f('0xb'));var querystring=require(_0xab5f('0xf'));var Papa=require(_0xab5f('0x10'));var Redis=require(_0xab5f('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xab5f('0x12'));var as=require('../../components/parsers/advancedSearch');var pdf=require(_0xab5f('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xab5f('0x14'))(_0xab5f('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xab5f('0x16'))['db'];config[_0xab5f('0x17')]=_['defaults'](config[_0xab5f('0x17')],{'host':_0xab5f('0x18'),'port':0x18eb});var socket=require(_0xab5f('0x19'))(new Redis(config[_0xab5f('0x17')]));require(_0xab5f('0x1a'))[_0xab5f('0x1b')](socket);function respondWithStatusCode(_0x4319c7,_0x425053){_0x425053=_0x425053||0xcc;return function(_0x32def2){if(_0x32def2){return _0x4319c7[_0xab5f('0x1c')](_0x425053);}return _0x4319c7[_0xab5f('0x1d')](_0x425053)[_0xab5f('0x1e')]();};}function respondWithResult(_0x177e6d,_0x22588b){_0x22588b=_0x22588b||0xc8;return function(_0x3d5485){if(_0x3d5485){return _0x177e6d[_0xab5f('0x1d')](_0x22588b)[_0xab5f('0x1f')](_0x3d5485);}};}function respondWithFilteredResult(_0x340190,_0x4aca7d){return function(_0x2caadb){if(_0x2caadb){var _0x4da25e=typeof _0x4aca7d[_0xab5f('0x20')]===_0xab5f('0x21')&&typeof _0x4aca7d[_0xab5f('0x22')]===_0xab5f('0x21');var _0x4c344f=_0x2caadb[_0xab5f('0x23')];var _0x413412=_0x4da25e?0x0:_0x4aca7d[_0xab5f('0x20')];var _0x1bc5ae=_0x4da25e?_0x2caadb[_0xab5f('0x23')]:_0x4aca7d[_0xab5f('0x20')]+_0x4aca7d['limit'];var _0x3fca4c;if(_0x1bc5ae>=_0x4c344f){_0x1bc5ae=_0x4c344f;_0x3fca4c=0xc8;}else{_0x3fca4c=0xce;}_0x340190[_0xab5f('0x1d')](_0x3fca4c);return _0x340190[_0xab5f('0x24')]('Content-Range',_0x413412+'-'+_0x1bc5ae+'/'+_0x4c344f)[_0xab5f('0x1f')](_0x2caadb);}return null;};}function patchUpdates(_0x134a23){return function(_0x811e76){try{jsonpatch[_0xab5f('0x25')](_0x811e76,_0x134a23,!![]);}catch(_0x297dff){return BPromise[_0xab5f('0x26')](_0x297dff);}return _0x811e76['save']();};}function saveUpdates(_0x55daaf,_0x3c5847){return function(_0x3f3bae){if(_0x3f3bae){return _0x3f3bae[_0xab5f('0x27')](_0x55daaf)[_0xab5f('0x28')](function(_0x3fb403){return _0x3fb403;});}return null;};}function removeEntity(_0x49972a,_0x3db1a6){return function(_0x38d793){if(_0x38d793){return _0x38d793['destroy']()[_0xab5f('0x28')](function(){_0x49972a[_0xab5f('0x1d')](0xcc)[_0xab5f('0x1e')]();});}};}function handleEntityNotFound(_0x391fec,_0x4fee82){return function(_0x144281){if(!_0x144281){_0x391fec[_0xab5f('0x1c')](0x194);}return _0x144281;};}function handleError(_0x1e1fa9,_0x239229){_0x239229=_0x239229||0x1f4;return function(_0x5e43a5){logger[_0xab5f('0x29')](_0x5e43a5[_0xab5f('0x2a')]);if(_0x5e43a5[_0xab5f('0x2b')]){delete _0x5e43a5[_0xab5f('0x2b')];}_0x1e1fa9[_0xab5f('0x1d')](_0x239229)['send'](_0x5e43a5);};}function getInteractionUsers(_0x5c6229,_0x7f5308){return new BPromise(function(_0x464287,_0x290df8){try{if(_0x7f5308[_0x5c6229['id']]){_0x5c6229[_0xab5f('0x2c')]=_['map'](_0x7f5308[_0x5c6229['id']],function(_0x56a8e9){return{'id':_0x56a8e9['id'],'fullname':_0x56a8e9['fullname']};});}}catch(_0x5f2c8e){_0x290df8(_0x5f2c8e);}_0x464287(_0x5c6229);});}function getInteractionTags(_0x494c4b,_0xcfaa90){return new BPromise(function(_0x312140,_0x18ca34){try{if(_0x494c4b[_0xab5f('0x2d')]){_0x494c4b[_0xab5f('0x2e')]=[];_0x494c4b[_0xab5f('0x2d')][_0xab5f('0x2f')](',')['forEach'](function(_0x2acdfc){_0x494c4b[_0xab5f('0x2e')][_0xab5f('0x30')](_0xcfaa90[_0x2acdfc]);});}delete _0x494c4b[_0xab5f('0x2d')];}catch(_0x2ba2e6){_0x18ca34(_0x2ba2e6);}_0x312140(_0x494c4b);});}function updateWhatsappInteraction(_0x42af45,_0x4e86d2,_0x39c74d){return new BPromise(function(_0x529c2d,_0x3e02f6){return getInteractionUsers(_0x42af45,_0x39c74d)['then'](function(_0x55c8ab){return getInteractionTags(_0x55c8ab,_0x4e86d2);})['then'](function(_0x4e7fc1){return getStateInteraction(_0x4e7fc1);})[_0xab5f('0x28')](function(_0x56e0f3){_0x529c2d(_0x56e0f3);})[_0xab5f('0x31')](function(_0x137502){_0x3e02f6(_0x137502);});});}function getStateInteraction(_0x41023a){return new BPromise(function(_0x6fb3fc){_0x41023a[_0xab5f('0x32')]=0x0;_0x41023a[_0xab5f('0x33')]=0x0;_0x41023a[_0xab5f('0x34')]=0x0;_0x41023a[_0xab5f('0x35')]=0x0;_0x41023a[_0xab5f('0x36')]=0x0;if(!_0x41023a['closed']&&!_0x41023a[_0xab5f('0x37')]){_0x41023a['waiting']+=0x1;}if(!_0x41023a[_0xab5f('0x38')]&&_0x41023a[_0xab5f('0x37')]){_0x41023a[_0xab5f('0x33')]+=0x1;if(_0x41023a['waiting']){_0x41023a[_0xab5f('0x32')]-=0x1;}}if(_0x41023a[_0xab5f('0x38')]&&_0x41023a[_0xab5f('0x37')]){_0x41023a[_0xab5f('0x34')]+=0x1;if(_0x41023a[_0xab5f('0x33')]){_0x41023a[_0xab5f('0x33')]-=0x1;}}if(_0x41023a[_0xab5f('0x38')]&&!_0x41023a['UserId']){_0x41023a[_0xab5f('0x35')]+=0x1;if(_0x41023a[_0xab5f('0x32')]){_0x41023a[_0xab5f('0x32')]-=0x1;}}_0x41023a[_0xab5f('0x36')]+=0x1;_0x6fb3fc(_0x41023a);});}exports[_0xab5f('0x39')]=function(_0x141a34,_0x41184c){var _0x1d1f7d={},_0x4aaaa3={},_0x484fde={'count':0x0,'rows':[]};var _0x24878b=_[_0xab5f('0x3a')](db['WhatsappInteraction'][_0xab5f('0x3b')],function(_0x579946){return{'name':_0x579946[_0xab5f('0x3c')],'type':_0x579946[_0xab5f('0x3d')]['key']};});_0x4aaaa3[_0xab5f('0x3e')]=_['map'](_0x24878b,_0xab5f('0x2b'));_0x4aaaa3[_0xab5f('0x3f')]=_[_0xab5f('0x40')](_0x141a34[_0xab5f('0x3f')]);_0x4aaaa3[_0xab5f('0x41')]=_[_0xab5f('0x42')](_0x4aaaa3['model'],_0x4aaaa3[_0xab5f('0x3f')]);_0x1d1f7d[_0xab5f('0x43')]=_[_0xab5f('0x42')](_0x4aaaa3[_0xab5f('0x3e')],qs[_0xab5f('0x44')](_0x141a34[_0xab5f('0x3f')]['fields']));_0x1d1f7d[_0xab5f('0x43')]=_0x1d1f7d[_0xab5f('0x43')]['length']?_0x1d1f7d[_0xab5f('0x43')]:_0x4aaaa3['model'];if(!_0x141a34[_0xab5f('0x3f')][_0xab5f('0x45')]('nolimit')){_0x1d1f7d[_0xab5f('0x22')]=qs[_0xab5f('0x22')](_0x141a34[_0xab5f('0x3f')][_0xab5f('0x22')]);_0x1d1f7d[_0xab5f('0x20')]=qs[_0xab5f('0x20')](_0x141a34[_0xab5f('0x3f')][_0xab5f('0x20')]);}_0x1d1f7d['order']=qs[_0xab5f('0x46')](_0x141a34[_0xab5f('0x3f')][_0xab5f('0x46')]);_0x1d1f7d['where']=qs[_0xab5f('0x41')](_[_0xab5f('0x47')](_0x141a34[_0xab5f('0x3f')],_0x4aaaa3[_0xab5f('0x41')]),_0x24878b);var _0x3e699e=[];var _0x14e815=squel[_0xab5f('0x48')]()[_0xab5f('0x49')]('id')[_0xab5f('0x49')](_0xab5f('0x2b'))[_0xab5f('0x49')](_0xab5f('0x4a'))[_0xab5f('0x4b')](_0xab5f('0x4c'));var _0x5f1018=squel[_0xab5f('0x48')]()[_0xab5f('0x49')](_0xab5f('0x4d'))[_0xab5f('0x49')](_0xab5f('0x4e'))['field']('ui.WhatsappInteractionId')[_0xab5f('0x4b')](_0xab5f('0x4f'),'ui')['left_join'](_0xab5f('0x50'),'u',_0xab5f('0x51'));var _0x85fd96=squel[_0xab5f('0x48')]()['from']('whatsapp_interactions','i')[_0xab5f('0x52')](_0xab5f('0x53'),'c','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL')[_0xab5f('0x52')](_0xab5f('0x50'),'o','o.id\x20=\x20i.UserId')['left_join'](_0xab5f('0x54'),'a','a.id\x20=\x20i.WhatsappAccountId')[_0xab5f('0x52')](_0xab5f('0x55'),'me',_0xab5f('0x56'))[_0xab5f('0x52')](_0xab5f('0x57'),'it',_0xab5f('0x58'))[_0xab5f('0x52')](_0xab5f('0x4c'),'t',_0xab5f('0x59'));var _0x454932=squel['expr']();var _0x36db0a=[];var _0x493235=squel['expr']();var _0x43a51b;if(_0x141a34['query'][_0xab5f('0x5a')]){_0x43a51b=as[_0xab5f('0x5b')](_0x141a34[_0xab5f('0x3f')][_0xab5f('0x5a')]);var _0x1b9cbd=_0x43a51b[_0xab5f('0x5c')];for(var _0x269eb8=0x0;_0x269eb8<_0x43a51b[_0xab5f('0x5d')][_0xab5f('0x5e')];_0x269eb8++){var _0x51b5d5=_0x43a51b[_0xab5f('0x5d')][_0x269eb8];var _0x201896='i';var _0x1d8952=_[_0xab5f('0x5f')](_0x24878b,['name',_0x51b5d5[_0xab5f('0x49')]]);if(!_0x1d8952){switch(_0x51b5d5[_0xab5f('0x49')]){case _0xab5f('0x60'):if(_0x51b5d5[_0xab5f('0x61')]==0x1){_0x85fd96[_0xab5f('0x62')]('`'+_0x51b5d5['field']+_0xab5f('0x63'));}else{_0x85fd96[_0xab5f('0x62')]('`'+_0x51b5d5['field']+_0xab5f('0x64'));}break;case _0xab5f('0x65'):if(_0x51b5d5[_0xab5f('0x66')]===_0xab5f('0x67')){if(_0x51b5d5[_0xab5f('0x61')][_0xab5f('0x2f')]('\x20')[_0xab5f('0x5e')]>0x1){_0x454932[_0x1b9cbd]('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xab5f('0x68')](_0x51b5d5[_0xab5f('0x61')]),null);}else{var _0x2d10e6='%'+_0x51b5d5[_0xab5f('0x61')]+'%';_0x454932[_0x1b9cbd](_0xab5f('0x69'),_0x2d10e6,_0x2d10e6,_0x2d10e6);}}else{_0x1d8952=_[_0xab5f('0x5f')](_0x24878b,['name','ContactId']);_0x51b5d5[_0xab5f('0x49')]=_0xab5f('0x6a');_0x15b9b1=as['buildExpression'](_0x201896,_0x1d8952[_0xab5f('0x3d')],_0x51b5d5);_0x454932[_0x1b9cbd](_0x15b9b1[_0xab5f('0x6b')],_0x15b9b1['value'][_0xab5f('0x6c')],_0x15b9b1[_0xab5f('0x61')][_0xab5f('0x1e')]);}break;case _0xab5f('0x6d'):var _0x5dde1b=_0x51b5d5['value'][_0xab5f('0x2f')](',')[_0xab5f('0x3a')](function(_0x1e4cd6){return Number(_0x1e4cd6);});_0x5dde1b['forEach'](function(_0x41fab8){_0x493235['or'](_0xab5f('0x6e'),'%,'+_0x41fab8+',%');});_0x36db0a=_['union'](_0x36db0a,_0x5dde1b);break;case _0xab5f('0x6f'):if(_0x51b5d5[_0xab5f('0x66')]===_0xab5f('0x67')){_0x454932[_0x1b9cbd](_0xab5f('0x70'),'%'+_0x51b5d5[_0xab5f('0x61')]+'%',null);}else{_0x1d8952=_[_0xab5f('0x5f')](_0x24878b,[_0xab5f('0x2b'),_0xab5f('0x37')]);_0x51b5d5[_0xab5f('0x49')]=_0xab5f('0x37');_0x15b9b1=as[_0xab5f('0x71')](_0x201896,_0x1d8952['type'],_0x51b5d5);_0x454932[_0x1b9cbd](_0x15b9b1[_0xab5f('0x6b')],_0x15b9b1[_0xab5f('0x61')][_0xab5f('0x6c')],_0x15b9b1[_0xab5f('0x61')]['end']);}break;case _0xab5f('0x72'):_0x15b9b1=as[_0xab5f('0x71')]('me',null,_0x51b5d5);_0x454932[_0x1b9cbd](_0x15b9b1['text'],_0x15b9b1[_0xab5f('0x61')][_0xab5f('0x6c')],_0x15b9b1['value']['end']);break;}}else{var _0x15b9b1=as[_0xab5f('0x71')](_0x201896,_0x1d8952[_0xab5f('0x3d')],_0x51b5d5);_0x454932[_0x1b9cbd](_0x15b9b1[_0xab5f('0x6b')],_0x15b9b1[_0xab5f('0x61')][_0xab5f('0x6c')],_0x15b9b1[_0xab5f('0x61')][_0xab5f('0x1e')]);}}}else{var _0x58442f=_(_0x141a34[_0xab5f('0x3f')])[_0xab5f('0x40')]()[_0xab5f('0x3a')](function(_0x610c3e){return _[_0xab5f('0x73')](_0x24878b,[_0xab5f('0x2b'),_0x610c3e])?_0x610c3e:undefined;})[_0xab5f('0x74')]()[_0xab5f('0x61')]();if(!_[_0xab5f('0x75')](_0x58442f)){_0x58442f[_0xab5f('0x76')](function(_0x5ca3b1){if(_0x5ca3b1==='WhatsappAccountId'){_0x85fd96['where'](_0xab5f('0x77'),[]['concat'](_0x141a34[_0xab5f('0x3f')][_0x5ca3b1]));}else if(_0x5ca3b1===_0xab5f('0x78')){var _0x5ec60c=JSON['parse'](_0x141a34[_0xab5f('0x3f')][_0x5ca3b1])[_0xab5f('0x79')];var _0x14e83f=JSON['parse'](_0x141a34[_0xab5f('0x3f')][_0x5ca3b1])[_0xab5f('0x7a')];_0x85fd96[_0xab5f('0x7b')](_0xab5f('0x7c'),_0x5ec60c,_0x14e83f);}else{if(_0x141a34[_0xab5f('0x3f')][_0x5ca3b1]===_0xab5f('0x7d')){_0x85fd96[_0xab5f('0x7b')]('i.'+_0x5ca3b1+_0xab5f('0x7e'));}else{_0x85fd96[_0xab5f('0x7b')]('i.'+_0x5ca3b1+_0xab5f('0x7f'),_0x141a34['query'][_0x5ca3b1]);}}});}if(_0x141a34['query'][_0xab5f('0x80')]){if(_0x141a34['query'][_0xab5f('0x80')]==0x1){_0x85fd96['having'](_0xab5f('0x81'));}else{_0x85fd96[_0xab5f('0x62')]('`unreadMessages`\x20>\x200');}}if(_0x141a34['query'][_0xab5f('0x82')]){_0x36db0a=_[_0xab5f('0x83')](_0x141a34[_0xab5f('0x3f')][_0xab5f('0x82')])?_0x141a34[_0xab5f('0x3f')][_0xab5f('0x82')]:new Array(_0x141a34[_0xab5f('0x3f')]['tag']);_0x36db0a['forEach'](function(_0x2c29e7){_0x493235['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x2c29e7+',%');});}if(_0x141a34[_0xab5f('0x3f')][_0xab5f('0x84')]){var _0x5d4ed8=_0x141a34[_0xab5f('0x3f')][_0xab5f('0x84')][_0xab5f('0x85')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs['isNumeric'](_0x5d4ed8)){_0x454932['or'](_0xab5f('0x86'),_0x5d4ed8+'%')['or'](_0xab5f('0x87'),_0x5d4ed8+'%');}else{_0x454932['or']('MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs['getFullTextValue'](_0x5d4ed8))['or'](_0xab5f('0x88'),_0x5d4ed8+'%');}}}_0x85fd96[_0xab5f('0x7b')](_0x454932);_0x85fd96[_0xab5f('0x89')](_0xab5f('0x8a'));var _0x12430f={'type':db[_0xab5f('0x8b')][_0xab5f('0x8c')]['SELECT'],'raw':!![]};var _0x23acfb=_0x85fd96['clone']();_0x23acfb[_0xab5f('0x49')](_0xab5f('0x8a'));_0x23acfb[_0xab5f('0x49')](_0xab5f('0x8d'),_0xab5f('0x60'));if(_0x1d1f7d[_0xab5f('0x8e')]){_0x1d1f7d['order'][_0xab5f('0x76')](function(_0x12f94e){var _0x12756c=_0x12f94e[0x0]===_0xab5f('0x8f')?_0x12f94e[0x0]:'i.'+_0x12f94e[0x0];_0x85fd96[_0xab5f('0x8e')](_0x12756c,_0x12f94e[0x1]===_0xab5f('0x90')?![]:!![]);});}if(!_['isEmpty'](_0x36db0a)){_0x85fd96[_0xab5f('0x62')](_0x493235);_0x23acfb[_0xab5f('0x7b')](_0xab5f('0x91'),_0x36db0a);}BPromise[_0xab5f('0x92')]()['then'](function(){if(!_0x43a51b){if(_0x141a34['query'][_0xab5f('0x93')])return;_0x23acfb[_0xab5f('0x7b')](_0xab5f('0x94'));_0x85fd96[_0xab5f('0x7b')](_0xab5f('0x94'));return;}if(_0x141a34['user'][_0xab5f('0x95')]!=='agent')return;return _0x141a34[_0xab5f('0x96')]['getWhatsappAccounts']({'attributes':['id'],'raw':!![]})[_0xab5f('0x28')](function(_0x502538){if(_[_0xab5f('0x75')](_0x502538)){_0x23acfb[_0xab5f('0x7b')](_0xab5f('0x97'));_0x85fd96[_0xab5f('0x7b')](_0xab5f('0x97'));}else{_0x23acfb[_0xab5f('0x7b')](_0xab5f('0x77'),_[_0xab5f('0x3a')](_0x502538,'id'));_0x85fd96[_0xab5f('0x7b')](_0xab5f('0x77'),_[_0xab5f('0x3a')](_0x502538,'id'));}});})[_0xab5f('0x28')](function(){if(_0x141a34[_0xab5f('0x96')][_0xab5f('0x95')]===_0xab5f('0x98')&&!_0x43a51b&&!_0x141a34['query'][_0xab5f('0x93')])return[];return db['sequelize'][_0xab5f('0x3f')](_0x23acfb['toString'](),_0x12430f);})[_0xab5f('0x28')](function(_0x81d183){_0x484fde[_0xab5f('0x23')]=_0x81d183[_0xab5f('0x5e')];if(_0x484fde['count']===0x0)return[];return db[_0xab5f('0x99')]['query'](_0x14e815['toString'](),_0x12430f)['then'](function(_0x5d349e){_0x3e699e=_[_0xab5f('0x9a')](_0x5d349e,'id');_0x12430f=_[_0xab5f('0x9b')](_0x12430f,{'model':db[_0xab5f('0x9c')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x141a34[_0xab5f('0x3f')][_0xab5f('0x44')]){_0x1d1f7d[_0xab5f('0x43')]['forEach'](function(_0x32c470){_0x85fd96[_0xab5f('0x49')]('i.'+_0x32c470);});}else{_0x85fd96[_0xab5f('0x49')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xab5f('0x60'));_0x85fd96[_0xab5f('0x49')](_0xab5f('0x9d'),_0xab5f('0x9e'));_0x85fd96[_0xab5f('0x49')]('a.mandatoryDisposition',_0xab5f('0x9f'));_0x85fd96[_0xab5f('0x49')]('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',_0xab5f('0x8f'));_0x85fd96[_0xab5f('0x49')]('i.*');_0x85fd96[_0xab5f('0x49')](_0xab5f('0xa0'),_0xab5f('0xa1'));_0x85fd96['field']('c.lastName',_0xab5f('0xa2'));_0x85fd96[_0xab5f('0x49')](_0xab5f('0xa3'),_0xab5f('0xa4'));_0x85fd96['field'](_0xab5f('0xa5'),'Contact.phone');_0x85fd96[_0xab5f('0x49')](_0xab5f('0xa6'),_0xab5f('0xa7'));_0x85fd96[_0xab5f('0x49')](_0xab5f('0xa8'),_0xab5f('0xa9'));_0x85fd96[_0xab5f('0x49')](_0xab5f('0xaa'),_0xab5f('0xab'));_0x85fd96[_0xab5f('0x49')](_0xab5f('0xac'),_0xab5f('0xad'));_0x85fd96[_0xab5f('0x49')](_0xab5f('0xae'),_0xab5f('0x2d'));}if(_0x1d1f7d[_0xab5f('0x22')])_0x85fd96[_0xab5f('0x22')](_0x1d1f7d['limit']);if(_0x1d1f7d[_0xab5f('0x20')])_0x85fd96['offset'](_0x1d1f7d[_0xab5f('0x20')]);return db[_0xab5f('0x99')]['query'](_0x85fd96[_0xab5f('0xaf')](),_0x12430f);})[_0xab5f('0x28')](function(_0x22b3d9){if(_0x22b3d9[_0xab5f('0x5e')]>0x0)_0x5f1018[_0xab5f('0x7b')](_0xab5f('0xb0'),_[_0xab5f('0x3a')](_0x22b3d9,'id'));return db[_0xab5f('0x99')][_0xab5f('0x3f')](_0x5f1018[_0xab5f('0xaf')](),_0x12430f)[_0xab5f('0x28')](function(_0x2fbc0f){var _0x323cd8=_[_0xab5f('0xb1')](_0x2fbc0f,_0xab5f('0xb2'));var _0x3f54f7=[];_0x22b3d9[_0xab5f('0x76')](function(_0x43e7f8){_0x3f54f7[_0xab5f('0x30')](updateWhatsappInteraction(_0x43e7f8,_0x3e699e,_0x323cd8));});return BPromise[_0xab5f('0xb3')](_0x3f54f7);});});})['then'](function(_0x5b2035){_0x484fde[_0xab5f('0xb4')]=_0x5b2035;return _0x484fde;})[_0xab5f('0x28')](respondWithFilteredResult(_0x41184c,_0x1d1f7d))[_0xab5f('0x31')](handleError(_0x41184c,null));};exports['show']=function(_0x24cd3c,_0x3dab9a){var _0xe05cfd={'raw':![],'where':{'id':_0x24cd3c[_0xab5f('0xb5')]['id']}},_0x12e073={};_0x12e073['model']=_['keys'](db[_0xab5f('0x9c')][_0xab5f('0x3b')]);_0x12e073['query']=_['keys'](_0x24cd3c[_0xab5f('0x3f')]);_0x12e073[_0xab5f('0x41')]=_[_0xab5f('0x42')](_0x12e073[_0xab5f('0x3e')],_0x12e073['query']);_0xe05cfd[_0xab5f('0x43')]=_['intersection'](_0x12e073[_0xab5f('0x3e')],qs[_0xab5f('0x44')](_0x24cd3c[_0xab5f('0x3f')][_0xab5f('0x44')]));_0xe05cfd[_0xab5f('0x43')]=_0xe05cfd[_0xab5f('0x43')][_0xab5f('0x5e')]?_0xe05cfd['attributes']:_0x12e073[_0xab5f('0x3e')];if(_0x24cd3c[_0xab5f('0x3f')][_0xab5f('0xb6')]){_0xe05cfd['include']=[{'all':!![]}];}_0xe05cfd=_[_0xab5f('0x9b')]({},_0xe05cfd,_0x24cd3c[_0xab5f('0xb7')]);return db[_0xab5f('0x9c')][_0xab5f('0x5f')](_0xe05cfd)[_0xab5f('0x28')](handleEntityNotFound(_0x3dab9a,null))[_0xab5f('0x28')](respondWithResult(_0x3dab9a,null))[_0xab5f('0x31')](handleError(_0x3dab9a,null));};exports['create']=function(_0x3e57c6,_0x18ff4e){return db[_0xab5f('0x9c')][_0xab5f('0xb8')](_0x3e57c6[_0xab5f('0x72')],{})[_0xab5f('0x28')](respondWithResult(_0x18ff4e,0xc9))['catch'](handleError(_0x18ff4e,null));};exports['update']=function(_0x17fd76,_0x1b419c){if(_0x17fd76[_0xab5f('0x72')]['id']){delete _0x17fd76[_0xab5f('0x72')]['id'];}return db['WhatsappInteraction'][_0xab5f('0x5f')]({'where':{'id':_0x17fd76['params']['id']}})[_0xab5f('0x28')](handleEntityNotFound(_0x1b419c,null))[_0xab5f('0x28')](saveUpdates(_0x17fd76[_0xab5f('0x72')],null))[_0xab5f('0x28')](respondWithResult(_0x1b419c,null))[_0xab5f('0x31')](handleError(_0x1b419c,null));};exports['destroy']=function(_0x52a486,_0x595b26){return db['WhatsappInteraction'][_0xab5f('0x5f')]({'where':{'id':_0x52a486['params']['id']}})[_0xab5f('0x28')](handleEntityNotFound(_0x595b26,null))[_0xab5f('0x28')](removeEntity(_0x595b26,null))[_0xab5f('0x31')](handleError(_0x595b26,null));};exports[_0xab5f('0xb9')]=function(_0x217a50,_0xfa5759){return db['WhatsappInteraction']['describe']()[_0xab5f('0x28')](respondWithResult(_0xfa5759,null))[_0xab5f('0x31')](handleError(_0xfa5759,null));};exports['addMessage']=function(_0x303f60,_0x46e581,_0x176553){return db[_0xab5f('0xba')][_0xab5f('0x5f')]({'where':{'id':_0x303f60[_0xab5f('0xb5')]['id']}})[_0xab5f('0x28')](handleEntityNotFound(_0x46e581,null))[_0xab5f('0x28')](function(_0x1cce17){if(_0x1cce17){return _0x1cce17[_0xab5f('0xbb')](_0x303f60[_0xab5f('0x72')][_0xab5f('0xbc')],_[_0xab5f('0xbd')](_0x303f60[_0xab5f('0x72')],[_0xab5f('0xbc'),'id'])||{});}})[_0xab5f('0x28')](respondWithResult(_0x46e581,null))['catch'](handleError(_0x46e581,null));};exports[_0xab5f('0xbe')]=function(_0x1a5a12,_0x2a7196,_0x34d741){var _0x5ce2a2={'raw':![],'where':{}};var _0xe88324={};var _0x2d0cee={'count':0x0,'rows':[]};return db[_0xab5f('0x9c')]['findOne']({'where':{'id':_0x1a5a12[_0xab5f('0xb5')]['id']}})['then'](handleEntityNotFound(_0x2a7196,null))[_0xab5f('0x28')](function(_0x23a906){if(_0x23a906){_0xe88324['model']=_[_0xab5f('0x40')](db['WhatsappMessage'][_0xab5f('0x3b')]);_0xe88324[_0xab5f('0x3f')]=_[_0xab5f('0x40')](_0x1a5a12[_0xab5f('0x3f')]);_0xe88324[_0xab5f('0x41')]=_[_0xab5f('0x42')](_0xe88324[_0xab5f('0x3e')],_0xe88324[_0xab5f('0x3f')]);_0x5ce2a2[_0xab5f('0x43')]=_[_0xab5f('0x42')](_0xe88324[_0xab5f('0x3e')],qs['fields'](_0x1a5a12['query'][_0xab5f('0x44')]));_0x5ce2a2['attributes']=_0x5ce2a2[_0xab5f('0x43')][_0xab5f('0x5e')]?_0x5ce2a2['attributes']:_0xe88324[_0xab5f('0x3e')];if(!_0x1a5a12[_0xab5f('0x3f')]['hasOwnProperty'](_0xab5f('0xbf'))){_0x5ce2a2['limit']=qs[_0xab5f('0x22')](_0x1a5a12[_0xab5f('0x3f')]['limit']);_0x5ce2a2[_0xab5f('0x20')]=qs[_0xab5f('0x20')](_0x1a5a12[_0xab5f('0x3f')]['offset']);}_0x5ce2a2[_0xab5f('0x8e')]=qs[_0xab5f('0x46')](_0x1a5a12['query'][_0xab5f('0x46')]);_0x5ce2a2[_0xab5f('0x7b')]=qs[_0xab5f('0x41')](_[_0xab5f('0x47')](_0x1a5a12[_0xab5f('0x3f')],_0xe88324[_0xab5f('0x41')]));_0x5ce2a2[_0xab5f('0x7b')][_0xab5f('0xb2')]=_0x23a906['id'];if(_0x1a5a12['query'][_0xab5f('0x84')]){_0x5ce2a2[_0xab5f('0x7b')]=_[_0xab5f('0x9b')](_0x5ce2a2[_0xab5f('0x7b')],{'$or':_[_0xab5f('0x3a')](_0x5ce2a2[_0xab5f('0x43')],function(_0xae2ddb){var _0x2924f9={};_0x2924f9[_0xae2ddb]={'$like':'%'+_0x1a5a12[_0xab5f('0x3f')]['filter']+'%'};return _0x2924f9;})});}if(_0x1a5a12['query']['$gte']){var _0x3efd43=_0x1a5a12['query'][_0xab5f('0x79')][_0xab5f('0x2f')](',');var _0x3ed2a8={};_0x3ed2a8[_0x3efd43[0x0]]={'$gte':moment(_0x3efd43[0x1])[_0xab5f('0xc0')]('YYYY-MM-DD\x20HH:mm:ss')};_0x5ce2a2[_0xab5f('0x7b')]=_['merge'](_0x5ce2a2[_0xab5f('0x7b')],_0x3ed2a8);}_0x5ce2a2=_[_0xab5f('0x9b')]({},_0x5ce2a2,_0x1a5a12['options']);return db[_0xab5f('0xba')]['count']({'where':_0x5ce2a2[_0xab5f('0x7b')]})[_0xab5f('0x28')](function(_0x505047){_0x2d0cee[_0xab5f('0x23')]=_0x505047;if(_0x1a5a12['query']['includeAll']){_0x5ce2a2['include']=[{'all':!![]}];}return db[_0xab5f('0xba')][_0xab5f('0xc1')](_0x5ce2a2);})[_0xab5f('0x28')](function(_0x1f9abf){_0x2d0cee[_0xab5f('0xb4')]=_0x1f9abf;return _0x2d0cee;});}})[_0xab5f('0x28')](respondWithFilteredResult(_0x2a7196,_0x5ce2a2))[_0xab5f('0x31')](handleError(_0x2a7196,null));};exports['addTags']=function(_0x10c60d,_0x4be3c4,_0x4da443){return db[_0xab5f('0x9c')]['find']({'where':{'id':_0x10c60d[_0xab5f('0xb5')]['id']}})['then'](handleEntityNotFound(_0x4be3c4,null))[_0xab5f('0x28')](function(_0x2eb968){if(_0x2eb968){return _0x2eb968[_0xab5f('0xc2')](_0x10c60d[_0xab5f('0x72')][_0xab5f('0xbc')],_[_0xab5f('0xbd')](_0x10c60d[_0xab5f('0x72')],[_0xab5f('0xbc'),'id'])||{})['spread'](function(){return db[_0xab5f('0x6d')][_0xab5f('0xc1')]({'attributes':['id','name','color'],'where':{'id':_0x10c60d[_0xab5f('0x72')][_0xab5f('0xbc')]}});})[_0xab5f('0x28')](function(_0x11ab73){socket[_0xab5f('0xc3')](_0xab5f('0xc4'),{'id':Number(_0x10c60d[_0xab5f('0xb5')]['id']),'tags':_0x11ab73||[]});return{'id':Number(_0x10c60d[_0xab5f('0xb5')]['id']),'tags':_0x11ab73||[]};});}})[_0xab5f('0x28')](respondWithResult(_0x4be3c4,null))[_0xab5f('0x31')](handleError(_0x4be3c4,null));};exports[_0xab5f('0xc5')]=function(_0x5dc376,_0x332556,_0x1f4e9b){return db[_0xab5f('0x9c')][_0xab5f('0x5f')]({'where':{'id':_0x5dc376[_0xab5f('0xb5')]['id']}})['then'](handleEntityNotFound(_0x332556,null))[_0xab5f('0x28')](function(_0x3b1a93){if(_0x3b1a93){return _0x3b1a93[_0xab5f('0xc5')](_0x5dc376[_0xab5f('0x3f')][_0xab5f('0xbc')]);}})[_0xab5f('0x28')](respondWithStatusCode(_0x332556,null))[_0xab5f('0x31')](handleError(_0x332556,null));};exports[_0xab5f('0xc6')]=function(_0x562b48,_0xb29308){var _0x544cfb=moment()['unix']()[_0xab5f('0xaf')]();var _0x46e175=path['join'](config[_0xab5f('0xc7')],_0xab5f('0xc8'),_0xab5f('0xc9'),_0xab5f('0xca'));var _0x1d1c17=path[_0xab5f('0xcb')](config[_0xab5f('0xc7')],'server',_0xab5f('0xc9'),_0xab5f('0xcc'));var _0x172b67=path[_0xab5f('0xcb')](_0x46e175,_0x544cfb);var _0x56ddfa=util[_0xab5f('0xc0')](_0xab5f('0xcd'),_0x562b48[_0xab5f('0xb5')]['id'],_0x544cfb);var _0x5898d0=path[_0xab5f('0xcb')](_0x46e175,_0x56ddfa);var _0x4a09b4=[];_0x4a09b4['push']({'model':db['User'],'as':_0xab5f('0x6f'),'attributes':['id',_0xab5f('0xce')],'raw':!![]});_0x4a09b4[_0xab5f('0x30')]({'model':db[_0xab5f('0xcf')],'as':'Contact','attributes':['id',_0xab5f('0xd0'),'lastName'],'raw':!![]});if(_0x562b48[_0xab5f('0x3f')][_0xab5f('0xcc')]){_0x4a09b4[_0xab5f('0x30')]({'model':db[_0xab5f('0xd1')],'as':_0xab5f('0xd1'),'raw':!![]});}var _0x20ffaa=[{'model':db[_0xab5f('0xba')],'as':_0xab5f('0xd2'),'attributes':['id',_0xab5f('0x72'),_0xab5f('0x78'),_0xab5f('0xd3'),_0xab5f('0xd4'),_0xab5f('0x80')],'include':_0x4a09b4}];_0x20ffaa[_0xab5f('0x30')]({'model':db[_0xab5f('0xd5')],'as':_0xab5f('0xd6'),'attributes':['id',_0xab5f('0x2b')]});_0x20ffaa[_0xab5f('0x30')]({'model':db[_0xab5f('0x6f')],'as':_0xab5f('0xd7'),'attributes':['id',_0xab5f('0xce')]});return db[_0xab5f('0x9c')]['find']({'where':{'id':_0x562b48[_0xab5f('0xb5')]['id']},'include':_0x20ffaa})[_0xab5f('0x28')](handleEntityNotFound(_0xb29308,null))['then'](function(_0x115ef9){if(_0x115ef9){var _0x8ff3ac=_0x115ef9[_0xab5f('0xd8')]({'plain':!![]});fs[_0xab5f('0xd9')](_0x172b67);var _0x490af7={'channel':_0xab5f('0xda'),'account':_0x8ff3ac[_0xab5f('0xd6')][_0xab5f('0x2b')],'agent':_0x8ff3ac['Owner']?_0x8ff3ac[_0xab5f('0xd7')][_0xab5f('0xce')]:_0xab5f('0xdb'),'createdAt':moment(_0x8ff3ac[_0xab5f('0x78')])[_0xab5f('0xc0')](_0xab5f('0xdc'))[_0xab5f('0xaf')](),'closedAt':_0x8ff3ac[_0xab5f('0x38')]?moment(_0x8ff3ac[_0xab5f('0xdd')])[_0xab5f('0xc0')]('YYYY-MM-DD\x20HH:mm:ss')[_0xab5f('0xaf')]():'','disposition':_0x8ff3ac[_0xab5f('0xde')],'messages':_(_0x8ff3ac[_0xab5f('0xd2')])[_0xab5f('0x84')]({'secret':![]})['map'](function(_0xa331c){if(_0xa331c[_0xab5f('0xd1')]){var _0x3fb6fd=path[_0xab5f('0xcb')](_0x1d1c17,_0xa331c['Attachment']['basename']);if(fs[_0xab5f('0xdf')](_0x3fb6fd)){fs[_0xab5f('0xe0')](_0x3fb6fd)[_0xab5f('0xe1')](fs[_0xab5f('0xe2')](path[_0xab5f('0xcb')](_0x172b67,_0xa331c['Attachment'][_0xab5f('0xe3')])));}}return{'date':moment(_0xa331c[_0xab5f('0x78')])[_0xab5f('0xc0')](_0xab5f('0xdc'))[_0xab5f('0xaf')](),'sender':_0xa331c[_0xab5f('0xd3')]===_0xab5f('0xe4')?_0xa331c[_0xab5f('0x6f')]?_0xa331c[_0xab5f('0x6f')]['fullname']:_0xab5f('0xe5'):_0xa331c[_0xab5f('0x65')]['firstName']+(_0xa331c[_0xab5f('0x65')][_0xab5f('0xe6')]?'\x20'+_0xa331c[_0xab5f('0x65')][_0xab5f('0xe6')]:''),'body':_0xa331c[_0xab5f('0xd1')]?_0xa331c['Attachment'][_0xab5f('0xe3')]:_0xa331c[_0xab5f('0x72')],'direction':_0xa331c['direction']===_0xab5f('0xe4')?'A':'C','secret':_0xa331c[_0xab5f('0xd4')],'read':_0xa331c['read'],'attachment':_0xa331c[_0xab5f('0xd1')]};})['value']()};return ejs[_0xab5f('0xe7')](path[_0xab5f('0xcb')](config[_0xab5f('0xc7')],_0xab5f('0xc8'),_0xab5f('0xe8'),_0xab5f('0xe9')),{'interaction':_0x490af7})[_0xab5f('0x28')](function(_0xe3a487){var _0x2f61d8=path[_0xab5f('0xcb')](_0x172b67,_0xab5f('0xea')+_0x8ff3ac['id']+'-'+_0x544cfb+'.pdf');var _0x408566={'path':_0x2f61d8,'channel':_0xab5f('0xda'),'interactionId':_0x8ff3ac['id']};return pdf[_0xab5f('0xeb')](_0xe3a487,_0x408566);})[_0xab5f('0x28')](function(){return new BPromise(function(_0x3eb0ae,_0x195bcf){zipdir(_0x172b67,{'saveTo':_0x5898d0},function(_0x186440,_0x55e0df){if(_0x186440)return _0x195bcf(_0x186440);return _0x3eb0ae(_0x55e0df);});})[_0xab5f('0x28')](function(){return new BPromise(function(_0x32058f,_0x3d1ef7){rimraf(_0x172b67,function(_0x257dcb){if(_0x257dcb)_0x3d1ef7(_0x257dcb);return _0x32058f();});});})[_0xab5f('0x28')](function(){return _0xb29308[_0xab5f('0xc6')](_0x5898d0,_0x56ddfa,function(_0x580990){if(_0x580990){console[_0xab5f('0xec')](_0xab5f('0xed'),_0x580990);}else{fs[_0xab5f('0xee')](_0x5898d0);}});});});}else{return _0xb29308[_0xab5f('0x1c')](0xc8);}})[_0xab5f('0x31')](handleError(_0xb29308,null));};
\ No newline at end of file
+var _0xf536=['existsSync','pipe','createWriteStream','System','out','value','renderFile','views','downloadInteraction.ejs','transcript-','.pdf','createPdfFromHTML','err','sendStatus','zip-dir','bluebird','path','ejs','lodash','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','api','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','end','status','json','offset','undefined','limit','count','set','update','then','destroy','error','stack','name','send','map','WhatsappInteraction','rawAttributes','fieldName','type','key','findAll','query','user','catch','params','model','keys','filters','intersection','attributes','fields','length','includeAll','include','merge','options','create','body','describe','addMessage','WhatsappMessage','find','omit','ids','getMessages','findOne','hasOwnProperty','nolimit','sort','where','pick','filter','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','rows','setTags','spread','Tag','color','emit','whatsappInteractionTags:save','removeTags','download','unix','toString','join','root','server','files','tmp','attachments','transcript-%d-%s.zip','push','User','fullname','Contact','firstName','Attachment','Messages','createdAt','direction','secret','read','WhatsappAccount','Account','Owner','mkdirSync','N.A.','closed','closedAt','disposition','basename'];(function(_0x9e97ca,_0x3ad9db){var _0x5d1649=function(_0xcf9dc7){while(--_0xcf9dc7){_0x9e97ca['push'](_0x9e97ca['shift']());}};_0x5d1649(++_0x3ad9db);}(_0xf536,0x106));var _0x6f53=function(_0x565d34,_0x4176da){_0x565d34=_0x565d34-0x0;var _0x3751e7=_0xf536[_0x565d34];return _0x3751e7;};'use strict';var rimraf=require('rimraf');var zipdir=require(_0x6f53('0x0'));var moment=require('moment');var BPromise=require(_0x6f53('0x1'));var util=require('util');var path=require(_0x6f53('0x2'));var ejs=require(_0x6f53('0x3'));var fs=require('fs');var _=require(_0x6f53('0x4'));var Redis=require('ioredis');var interaction=require(_0x6f53('0x5'));var qs=require(_0x6f53('0x6'));var pdf=require(_0x6f53('0x7'));var logger=require('../../config/logger')(_0x6f53('0x8'));var config=require('../../config/environment');var db=require(_0x6f53('0x9'))['db'];config[_0x6f53('0xa')]=_[_0x6f53('0xb')](config[_0x6f53('0xa')],{'host':_0x6f53('0xc'),'port':0x18eb});var socket=require(_0x6f53('0xd'))(new Redis(config['redis']));require('./whatsappInteraction.socket')[_0x6f53('0xe')](socket);function respondWithStatusCode(_0x2d11b1,_0x2951d9){_0x2951d9=_0x2951d9||0xcc;return function(_0x2dc75d){if(_0x2dc75d){return _0x2d11b1['sendStatus'](_0x2951d9);}return _0x2d11b1['status'](_0x2951d9)[_0x6f53('0xf')]();};}function respondWithResult(_0x376839,_0x2a64da){_0x2a64da=_0x2a64da||0xc8;return function(_0x2aaa19){if(_0x2aaa19){return _0x376839[_0x6f53('0x10')](_0x2a64da)[_0x6f53('0x11')](_0x2aaa19);}};}function respondWithFilteredResult(_0x575fbc,_0x2e49fa){return function(_0x369ea5){if(_0x369ea5){var _0x957ce6=typeof _0x2e49fa[_0x6f53('0x12')]===_0x6f53('0x13')&&typeof _0x2e49fa[_0x6f53('0x14')]===_0x6f53('0x13');var _0x832520=_0x369ea5[_0x6f53('0x15')];var _0xb71688=_0x957ce6?0x0:_0x2e49fa['offset'];var _0x54b0f4=_0x957ce6?_0x369ea5['count']:_0x2e49fa[_0x6f53('0x12')]+_0x2e49fa['limit'];var _0x556730;if(_0x54b0f4>=_0x832520){_0x54b0f4=_0x832520;_0x556730=0xc8;}else{_0x556730=0xce;}_0x575fbc[_0x6f53('0x10')](_0x556730);return _0x575fbc[_0x6f53('0x16')]('Content-Range',_0xb71688+'-'+_0x54b0f4+'/'+_0x832520)[_0x6f53('0x11')](_0x369ea5);}return null;};}function saveUpdates(_0x5f2ac7){return function(_0x345b94){if(_0x345b94){return _0x345b94[_0x6f53('0x17')](_0x5f2ac7)[_0x6f53('0x18')](function(_0x10bf7b){return _0x10bf7b;});}return null;};}function removeEntity(_0x43d2ab){return function(_0x1f0f4f){if(_0x1f0f4f){return _0x1f0f4f[_0x6f53('0x19')]()[_0x6f53('0x18')](function(){_0x43d2ab[_0x6f53('0x10')](0xcc)[_0x6f53('0xf')]();});}};}function handleEntityNotFound(_0x114e24){return function(_0x5381aa){if(!_0x5381aa){_0x114e24['sendStatus'](0x194);}return _0x5381aa;};}function handleError(_0x43cc6b,_0x34525c){_0x34525c=_0x34525c||0x1f4;return function(_0x496d9a){logger[_0x6f53('0x1a')](_0x496d9a[_0x6f53('0x1b')]);if(_0x496d9a[_0x6f53('0x1c')]){delete _0x496d9a[_0x6f53('0x1c')];}_0x43cc6b['status'](_0x34525c)[_0x6f53('0x1d')](_0x496d9a);};}exports['index']=function(_0x580077,_0x439f68){var _0x41cbd6={};var _0x3e8445=_[_0x6f53('0x1e')](db[_0x6f53('0x1f')][_0x6f53('0x20')],function(_0x253194){return{'name':_0x253194[_0x6f53('0x21')],'type':_0x253194[_0x6f53('0x22')][_0x6f53('0x23')]};});_0x41cbd6=qs['getOptions'](_0x3e8445,_0x580077);return interaction[_0x6f53('0x24')]('whatsapp',_0x580077[_0x6f53('0x25')],_0x580077[_0x6f53('0x26')],_0x41cbd6,_0x3e8445)['then'](respondWithFilteredResult(_0x439f68,_0x41cbd6))[_0x6f53('0x27')](handleError(_0x439f68,null));};exports['show']=function(_0x340209,_0x1f27ba){var _0x3de5ab={'raw':![],'where':{'id':_0x340209[_0x6f53('0x28')]['id']}},_0x134bdd={};_0x134bdd[_0x6f53('0x29')]=_[_0x6f53('0x2a')](db[_0x6f53('0x1f')][_0x6f53('0x20')]);_0x134bdd['query']=_[_0x6f53('0x2a')](_0x340209[_0x6f53('0x25')]);_0x134bdd[_0x6f53('0x2b')]=_[_0x6f53('0x2c')](_0x134bdd[_0x6f53('0x29')],_0x134bdd[_0x6f53('0x25')]);_0x3de5ab[_0x6f53('0x2d')]=_[_0x6f53('0x2c')](_0x134bdd['model'],qs[_0x6f53('0x2e')](_0x340209['query'][_0x6f53('0x2e')]));_0x3de5ab[_0x6f53('0x2d')]=_0x3de5ab['attributes'][_0x6f53('0x2f')]?_0x3de5ab[_0x6f53('0x2d')]:_0x134bdd['model'];if(_0x340209['query'][_0x6f53('0x30')]){_0x3de5ab[_0x6f53('0x31')]=[{'all':!![]}];}_0x3de5ab=_[_0x6f53('0x32')]({},_0x3de5ab,_0x340209[_0x6f53('0x33')]);return db['WhatsappInteraction']['find'](_0x3de5ab)[_0x6f53('0x18')](handleEntityNotFound(_0x1f27ba,null))[_0x6f53('0x18')](respondWithResult(_0x1f27ba,null))[_0x6f53('0x27')](handleError(_0x1f27ba,null));};exports['create']=function(_0x143f10,_0x9fdf24){return db['WhatsappInteraction'][_0x6f53('0x34')](_0x143f10[_0x6f53('0x35')],{})[_0x6f53('0x18')](respondWithResult(_0x9fdf24,0xc9))[_0x6f53('0x27')](handleError(_0x9fdf24,null));};exports[_0x6f53('0x17')]=function(_0x3ee064,_0x4edb74){if(_0x3ee064[_0x6f53('0x35')]['id']){delete _0x3ee064[_0x6f53('0x35')]['id'];}return db[_0x6f53('0x1f')]['find']({'where':{'id':_0x3ee064[_0x6f53('0x28')]['id']}})[_0x6f53('0x18')](handleEntityNotFound(_0x4edb74,null))[_0x6f53('0x18')](saveUpdates(_0x3ee064[_0x6f53('0x35')],null))[_0x6f53('0x18')](respondWithResult(_0x4edb74,null))['catch'](handleError(_0x4edb74,null));};exports[_0x6f53('0x19')]=function(_0x16f855,_0x39479d){return db['WhatsappInteraction']['find']({'where':{'id':_0x16f855[_0x6f53('0x28')]['id']}})[_0x6f53('0x18')](handleEntityNotFound(_0x39479d,null))[_0x6f53('0x18')](removeEntity(_0x39479d,null))[_0x6f53('0x27')](handleError(_0x39479d,null));};exports[_0x6f53('0x36')]=function(_0x38b37c,_0xdb7a5c){return db[_0x6f53('0x1f')][_0x6f53('0x36')]()[_0x6f53('0x18')](respondWithResult(_0xdb7a5c,null))[_0x6f53('0x27')](handleError(_0xdb7a5c,null));};exports[_0x6f53('0x37')]=function(_0x271838,_0x82585c){return db[_0x6f53('0x38')][_0x6f53('0x39')]({'where':{'id':_0x271838['params']['id']}})[_0x6f53('0x18')](handleEntityNotFound(_0x82585c,null))['then'](function(_0x5f4887){if(_0x5f4887){return _0x5f4887[_0x6f53('0x37')](_0x271838['body']['ids'],_[_0x6f53('0x3a')](_0x271838['body'],[_0x6f53('0x3b'),'id'])||{});}})[_0x6f53('0x18')](respondWithResult(_0x82585c,null))[_0x6f53('0x27')](handleError(_0x82585c,null));};exports[_0x6f53('0x3c')]=function(_0x5499a9,_0x526e2c){var _0x14ea14={'raw':![],'where':{}};var _0x190082={};var _0x3193ad={'count':0x0,'rows':[]};return db[_0x6f53('0x1f')][_0x6f53('0x3d')]({'where':{'id':_0x5499a9[_0x6f53('0x28')]['id']}})['then'](handleEntityNotFound(_0x526e2c,null))[_0x6f53('0x18')](function(_0x70ccc0){if(_0x70ccc0){_0x190082[_0x6f53('0x29')]=_[_0x6f53('0x2a')](db[_0x6f53('0x38')][_0x6f53('0x20')]);_0x190082[_0x6f53('0x25')]=_['keys'](_0x5499a9[_0x6f53('0x25')]);_0x190082['filters']=_[_0x6f53('0x2c')](_0x190082[_0x6f53('0x29')],_0x190082['query']);_0x14ea14[_0x6f53('0x2d')]=_[_0x6f53('0x2c')](_0x190082[_0x6f53('0x29')],qs['fields'](_0x5499a9[_0x6f53('0x25')]['fields']));_0x14ea14[_0x6f53('0x2d')]=_0x14ea14[_0x6f53('0x2d')][_0x6f53('0x2f')]?_0x14ea14[_0x6f53('0x2d')]:_0x190082[_0x6f53('0x29')];if(!_0x5499a9['query'][_0x6f53('0x3e')](_0x6f53('0x3f'))){_0x14ea14[_0x6f53('0x14')]=qs['limit'](_0x5499a9[_0x6f53('0x25')]['limit']);_0x14ea14['offset']=qs['offset'](_0x5499a9['query']['offset']);}_0x14ea14['order']=qs[_0x6f53('0x40')](_0x5499a9[_0x6f53('0x25')]['sort']);_0x14ea14[_0x6f53('0x41')]=qs[_0x6f53('0x2b')](_[_0x6f53('0x42')](_0x5499a9['query'],_0x190082['filters']));_0x14ea14[_0x6f53('0x41')]['WhatsappInteractionId']=_0x70ccc0['id'];if(_0x5499a9[_0x6f53('0x25')][_0x6f53('0x43')]){_0x14ea14[_0x6f53('0x41')]=_[_0x6f53('0x32')](_0x14ea14['where'],{'$or':_[_0x6f53('0x1e')](_0x14ea14[_0x6f53('0x2d')],function(_0x1a9a4d){var _0x32f2c5={};_0x32f2c5[_0x1a9a4d]={'$like':'%'+_0x5499a9[_0x6f53('0x25')][_0x6f53('0x43')]+'%'};return _0x32f2c5;})});}if(_0x5499a9[_0x6f53('0x25')]['$gte']){var _0x226746=_0x5499a9['query'][_0x6f53('0x44')][_0x6f53('0x45')](',');var _0x40b1db={};_0x40b1db[_0x226746[0x0]]={'$gte':moment(_0x226746[0x1])[_0x6f53('0x46')](_0x6f53('0x47'))};_0x14ea14[_0x6f53('0x41')]=_[_0x6f53('0x32')](_0x14ea14['where'],_0x40b1db);}_0x14ea14=_['merge']({},_0x14ea14,_0x5499a9[_0x6f53('0x33')]);return db[_0x6f53('0x38')][_0x6f53('0x15')]({'where':_0x14ea14[_0x6f53('0x41')]})[_0x6f53('0x18')](function(_0xbabe0f){_0x3193ad[_0x6f53('0x15')]=_0xbabe0f;if(_0x5499a9[_0x6f53('0x25')][_0x6f53('0x30')]){_0x14ea14[_0x6f53('0x31')]=[{'all':!![]}];}return db[_0x6f53('0x38')][_0x6f53('0x24')](_0x14ea14);})[_0x6f53('0x18')](function(_0x43b0a6){_0x3193ad[_0x6f53('0x48')]=_0x43b0a6;return _0x3193ad;});}})['then'](respondWithFilteredResult(_0x526e2c,_0x14ea14))['catch'](handleError(_0x526e2c,null));};exports['addTags']=function(_0x1782df,_0x23b697){return db[_0x6f53('0x1f')][_0x6f53('0x39')]({'where':{'id':_0x1782df[_0x6f53('0x28')]['id']}})[_0x6f53('0x18')](handleEntityNotFound(_0x23b697,null))[_0x6f53('0x18')](function(_0x209fb5){if(_0x209fb5){return _0x209fb5[_0x6f53('0x49')](_0x1782df['body']['ids'],_[_0x6f53('0x3a')](_0x1782df[_0x6f53('0x35')],[_0x6f53('0x3b'),'id'])||{})[_0x6f53('0x4a')](function(){return db[_0x6f53('0x4b')]['findAll']({'attributes':['id',_0x6f53('0x1c'),_0x6f53('0x4c')],'where':{'id':_0x1782df[_0x6f53('0x35')][_0x6f53('0x3b')]}});})[_0x6f53('0x18')](function(_0x3d94f0){socket[_0x6f53('0x4d')](_0x6f53('0x4e'),{'id':Number(_0x1782df[_0x6f53('0x28')]['id']),'tags':_0x3d94f0||[]});return{'id':Number(_0x1782df[_0x6f53('0x28')]['id']),'tags':_0x3d94f0||[]};});}})[_0x6f53('0x18')](respondWithResult(_0x23b697,null))[_0x6f53('0x27')](handleError(_0x23b697,null));};exports[_0x6f53('0x4f')]=function(_0x71109b,_0x14f1d2){return db[_0x6f53('0x1f')][_0x6f53('0x39')]({'where':{'id':_0x71109b['params']['id']}})[_0x6f53('0x18')](handleEntityNotFound(_0x14f1d2,null))['then'](function(_0x31f969){if(_0x31f969){return _0x31f969[_0x6f53('0x4f')](_0x71109b[_0x6f53('0x25')][_0x6f53('0x3b')]);}})['then'](respondWithStatusCode(_0x14f1d2,null))[_0x6f53('0x27')](handleError(_0x14f1d2,null));};exports[_0x6f53('0x50')]=function(_0x490abc,_0x423ab5){var _0x5bd71a=moment()[_0x6f53('0x51')]()[_0x6f53('0x52')]();var _0x27eeaa=path[_0x6f53('0x53')](config[_0x6f53('0x54')],_0x6f53('0x55'),_0x6f53('0x56'),_0x6f53('0x57'));var _0x4e086a=path['join'](config[_0x6f53('0x54')],_0x6f53('0x55'),_0x6f53('0x56'),_0x6f53('0x58'));var _0x215834=path[_0x6f53('0x53')](_0x27eeaa,_0x5bd71a);var _0x1a584b=util[_0x6f53('0x46')](_0x6f53('0x59'),_0x490abc[_0x6f53('0x28')]['id'],_0x5bd71a);var _0x5172df=path[_0x6f53('0x53')](_0x27eeaa,_0x1a584b);var _0x33220d=[];_0x33220d[_0x6f53('0x5a')]({'model':db[_0x6f53('0x5b')],'as':_0x6f53('0x5b'),'attributes':['id',_0x6f53('0x5c')],'raw':!![]});_0x33220d[_0x6f53('0x5a')]({'model':db['CmContact'],'as':_0x6f53('0x5d'),'attributes':['id',_0x6f53('0x5e'),'lastName'],'raw':!![]});if(_0x490abc[_0x6f53('0x25')][_0x6f53('0x58')]){_0x33220d['push']({'model':db[_0x6f53('0x5f')],'as':'Attachment','raw':!![]});}var _0x4fbcf6=[{'model':db[_0x6f53('0x38')],'as':_0x6f53('0x60'),'attributes':['id',_0x6f53('0x35'),_0x6f53('0x61'),_0x6f53('0x62'),_0x6f53('0x63'),_0x6f53('0x64')],'include':_0x33220d}];_0x4fbcf6[_0x6f53('0x5a')]({'model':db[_0x6f53('0x65')],'as':_0x6f53('0x66'),'attributes':['id','name']});_0x4fbcf6[_0x6f53('0x5a')]({'model':db[_0x6f53('0x5b')],'as':_0x6f53('0x67'),'attributes':['id',_0x6f53('0x5c')]});return db[_0x6f53('0x1f')][_0x6f53('0x39')]({'where':{'id':_0x490abc[_0x6f53('0x28')]['id']},'include':_0x4fbcf6})[_0x6f53('0x18')](handleEntityNotFound(_0x423ab5,null))[_0x6f53('0x18')](function(_0x309189){if(_0x309189){var _0x19203e=_0x309189['get']({'plain':!![]});fs[_0x6f53('0x68')](_0x215834);var _0x22f504={'channel':'Whatsapp','account':_0x19203e['Account'][_0x6f53('0x1c')],'agent':_0x19203e['Owner']?_0x19203e[_0x6f53('0x67')][_0x6f53('0x5c')]:_0x6f53('0x69'),'createdAt':moment(_0x19203e['createdAt'])[_0x6f53('0x46')](_0x6f53('0x47'))['toString'](),'closedAt':_0x19203e[_0x6f53('0x6a')]?moment(_0x19203e[_0x6f53('0x6b')])[_0x6f53('0x46')](_0x6f53('0x47'))[_0x6f53('0x52')]():'','disposition':_0x19203e[_0x6f53('0x6c')],'messages':_(_0x19203e[_0x6f53('0x60')])['filter']({'secret':![]})['map'](function(_0x27a1b7){if(_0x27a1b7[_0x6f53('0x5f')]){var _0x5aea7c=path[_0x6f53('0x53')](_0x4e086a,_0x27a1b7[_0x6f53('0x5f')][_0x6f53('0x6d')]);if(fs[_0x6f53('0x6e')](_0x5aea7c)){fs['createReadStream'](_0x5aea7c)[_0x6f53('0x6f')](fs[_0x6f53('0x70')](path[_0x6f53('0x53')](_0x215834,_0x27a1b7[_0x6f53('0x5f')][_0x6f53('0x6d')])));}}return{'date':moment(_0x27a1b7[_0x6f53('0x61')])[_0x6f53('0x46')](_0x6f53('0x47'))[_0x6f53('0x52')](),'sender':_0x27a1b7[_0x6f53('0x62')]==='out'?_0x27a1b7[_0x6f53('0x5b')]?_0x27a1b7[_0x6f53('0x5b')][_0x6f53('0x5c')]:_0x6f53('0x71'):_0x27a1b7['Contact']['firstName']+(_0x27a1b7[_0x6f53('0x5d')]['lastName']?'\x20'+_0x27a1b7[_0x6f53('0x5d')]['lastName']:''),'body':_0x27a1b7[_0x6f53('0x5f')]?_0x27a1b7[_0x6f53('0x5f')][_0x6f53('0x6d')]:_0x27a1b7['body'],'direction':_0x27a1b7[_0x6f53('0x62')]===_0x6f53('0x72')?'A':'C','secret':_0x27a1b7[_0x6f53('0x63')],'read':_0x27a1b7[_0x6f53('0x64')],'attachment':_0x27a1b7[_0x6f53('0x5f')]};})[_0x6f53('0x73')]()};return ejs[_0x6f53('0x74')](path[_0x6f53('0x53')](config[_0x6f53('0x54')],_0x6f53('0x55'),_0x6f53('0x75'),_0x6f53('0x76')),{'interaction':_0x22f504})[_0x6f53('0x18')](function(_0x5df115){var _0x5163b9=path[_0x6f53('0x53')](_0x215834,_0x6f53('0x77')+_0x19203e['id']+'-'+_0x5bd71a+_0x6f53('0x78'));var _0x23b8d1={'path':_0x5163b9,'channel':'Whatsapp','interactionId':_0x19203e['id']};return pdf[_0x6f53('0x79')](_0x5df115,_0x23b8d1);})[_0x6f53('0x18')](function(){return new BPromise(function(_0x33ac95,_0x1ee07b){zipdir(_0x215834,{'saveTo':_0x5172df},function(_0x127fc1,_0x18f50e){if(_0x127fc1)return _0x1ee07b(_0x127fc1);return _0x33ac95(_0x18f50e);});})[_0x6f53('0x18')](function(){return new BPromise(function(_0x5774ef,_0x1ce885){rimraf(_0x215834,function(_0x515a4c){if(_0x515a4c)_0x1ce885(_0x515a4c);return _0x5774ef();});});})['then'](function(){return _0x423ab5[_0x6f53('0x50')](_0x5172df,_0x1a584b,function(_0x808474){if(_0x808474){console['log'](_0x6f53('0x7a'),_0x808474);}else{fs['unlinkSync'](_0x5172df);}});});});}else{return _0x423ab5[_0x6f53('0x7b')](0xc8);}})[_0x6f53('0x27')](handleError(_0x423ab5,null));};
\ No newline at end of file