Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index bed5bd6..889f181 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xfcb2=['includeAll','include','merge','create','update','body','addMessage','WhatsappMessage','find','ids','nolimit','limit','sort','where','WhatsappInteractionId','filter','map','$gte','YYYY-MM-DD\x20HH:mm:ss','options','rows','addTags','setTags','omit','spread','Tag','emit','removeTags','download','unix','toString','join','root','server','files','format','User','fullname','push','CmContact','firstName','attachments','Attachment','Messages','direction','read','WhatsappAccount','Account','Owner','get','mkdirSync','Whatsapp','N.A.','createdAt','closedAt','disposition','createReadStream','pipe','createWriteStream','out','System','Contact','lastName','basename','secret','value','renderFile','views','transcript-','.pdf','createPdfFromHTML','log','err','unlinkSync','rimraf','zip-dir','moment','bluebird','path','ejs','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','defaults','redis','localhost','socket.io-emitter','./whatsappInteraction.socket','register','sendStatus','status','end','json','offset','count','Content-Range','destroy','then','error','stack','name','index','rawAttributes','fieldName','key','getOptions','findAll','whatsapp','query','catch','show','params','model','keys','WhatsappInteraction','filters','intersection','attributes','fields','length'];(function(_0x260223,_0x1deaf3){var _0x4ee3bb=function(_0x35fc9f){while(--_0x35fc9f){_0x260223['push'](_0x260223['shift']());}};_0x4ee3bb(++_0x1deaf3);}(_0xfcb2,0x1be));var _0x2fcb=function(_0x59884f,_0x266770){_0x59884f=_0x59884f-0x0;var _0xcb7fd1=_0xfcb2[_0x59884f];return _0xcb7fd1;};'use strict';var rimraf=require(_0x2fcb('0x0'));var zipdir=require(_0x2fcb('0x1'));var moment=require(_0x2fcb('0x2'));var BPromise=require(_0x2fcb('0x3'));var util=require('util');var path=require(_0x2fcb('0x4'));var ejs=require(_0x2fcb('0x5'));var fs=require('fs');var _=require(_0x2fcb('0x6'));var Redis=require(_0x2fcb('0x7'));var interaction=require(_0x2fcb('0x8'));var qs=require(_0x2fcb('0x9'));var pdf=require(_0x2fcb('0xa'));var logger=require(_0x2fcb('0xb'))(_0x2fcb('0xc'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];config['redis']=_[_0x2fcb('0xd')](config[_0x2fcb('0xe')],{'host':_0x2fcb('0xf'),'port':0x18eb});var socket=require(_0x2fcb('0x10'))(new Redis(config['redis']));require(_0x2fcb('0x11'))[_0x2fcb('0x12')](socket);function respondWithStatusCode(_0x444bcb,_0x2172ca){_0x2172ca=_0x2172ca||0xcc;return function(_0x1ffbdd){if(_0x1ffbdd){return _0x444bcb[_0x2fcb('0x13')](_0x2172ca);}return _0x444bcb[_0x2fcb('0x14')](_0x2172ca)[_0x2fcb('0x15')]();};}function respondWithResult(_0x3c47d9,_0x3284dc){_0x3284dc=_0x3284dc||0xc8;return function(_0x38f93c){if(_0x38f93c){return _0x3c47d9[_0x2fcb('0x14')](_0x3284dc)[_0x2fcb('0x16')](_0x38f93c);}};}function respondWithFilteredResult(_0x559a5d,_0x5d94f1){return function(_0x52aae4){if(_0x52aae4){var _0xc68a4e=typeof _0x5d94f1[_0x2fcb('0x17')]==='undefined'&&typeof _0x5d94f1['limit']==='undefined';var _0xb42905=_0x52aae4['count'];var _0x48c2bf=_0xc68a4e?0x0:_0x5d94f1[_0x2fcb('0x17')];var _0x65eb40=_0xc68a4e?_0x52aae4[_0x2fcb('0x18')]:_0x5d94f1[_0x2fcb('0x17')]+_0x5d94f1['limit'];var _0x16deb6;if(_0x65eb40>=_0xb42905){_0x65eb40=_0xb42905;_0x16deb6=0xc8;}else{_0x16deb6=0xce;}_0x559a5d[_0x2fcb('0x14')](_0x16deb6);return _0x559a5d['set'](_0x2fcb('0x19'),_0x48c2bf+'-'+_0x65eb40+'/'+_0xb42905)[_0x2fcb('0x16')](_0x52aae4);}return null;};}function saveUpdates(_0x3f7bdb){return function(_0x8d4f80){if(_0x8d4f80){return _0x8d4f80['update'](_0x3f7bdb)['then'](function(_0x35e0ce){return _0x35e0ce;});}return null;};}function removeEntity(_0x5a1c0c){return function(_0xb74aa7){if(_0xb74aa7){return _0xb74aa7[_0x2fcb('0x1a')]()[_0x2fcb('0x1b')](function(){_0x5a1c0c[_0x2fcb('0x14')](0xcc)[_0x2fcb('0x15')]();});}};}function handleEntityNotFound(_0x15a828){return function(_0xd37b0f){if(!_0xd37b0f){_0x15a828['sendStatus'](0x194);}return _0xd37b0f;};}function handleError(_0x238cfd,_0x52245e){_0x52245e=_0x52245e||0x1f4;return function(_0x43c311){logger[_0x2fcb('0x1c')](_0x43c311[_0x2fcb('0x1d')]);if(_0x43c311[_0x2fcb('0x1e')]){delete _0x43c311[_0x2fcb('0x1e')];}_0x238cfd[_0x2fcb('0x14')](_0x52245e)['send'](_0x43c311);};}exports[_0x2fcb('0x1f')]=function(_0x57f475,_0x250d8e){var _0x175c23={};var _0x40bdf7=_['map'](db['WhatsappInteraction'][_0x2fcb('0x20')],function(_0x4dbcaa){return{'name':_0x4dbcaa[_0x2fcb('0x21')],'type':_0x4dbcaa['type'][_0x2fcb('0x22')]};});_0x175c23=qs[_0x2fcb('0x23')](_0x40bdf7,_0x57f475);return interaction[_0x2fcb('0x24')](_0x2fcb('0x25'),_0x57f475[_0x2fcb('0x26')],_0x57f475['user'],_0x175c23,_0x40bdf7)[_0x2fcb('0x1b')](respondWithFilteredResult(_0x250d8e,_0x175c23))[_0x2fcb('0x27')](handleError(_0x250d8e,null));};exports[_0x2fcb('0x28')]=function(_0x4c772d,_0x5cde93){var _0xe8e05={'raw':![],'where':{'id':_0x4c772d[_0x2fcb('0x29')]['id']}},_0x2e8e03={};_0x2e8e03[_0x2fcb('0x2a')]=_[_0x2fcb('0x2b')](db[_0x2fcb('0x2c')][_0x2fcb('0x20')]);_0x2e8e03[_0x2fcb('0x26')]=_['keys'](_0x4c772d[_0x2fcb('0x26')]);_0x2e8e03[_0x2fcb('0x2d')]=_[_0x2fcb('0x2e')](_0x2e8e03[_0x2fcb('0x2a')],_0x2e8e03[_0x2fcb('0x26')]);_0xe8e05[_0x2fcb('0x2f')]=_[_0x2fcb('0x2e')](_0x2e8e03[_0x2fcb('0x2a')],qs[_0x2fcb('0x30')](_0x4c772d[_0x2fcb('0x26')][_0x2fcb('0x30')]));_0xe8e05[_0x2fcb('0x2f')]=_0xe8e05[_0x2fcb('0x2f')][_0x2fcb('0x31')]?_0xe8e05[_0x2fcb('0x2f')]:_0x2e8e03['model'];if(_0x4c772d[_0x2fcb('0x26')][_0x2fcb('0x32')]){_0xe8e05[_0x2fcb('0x33')]=[{'all':!![]}];}_0xe8e05=_[_0x2fcb('0x34')]({},_0xe8e05,_0x4c772d['options']);return db[_0x2fcb('0x2c')]['find'](_0xe8e05)[_0x2fcb('0x1b')](handleEntityNotFound(_0x5cde93,null))[_0x2fcb('0x1b')](respondWithResult(_0x5cde93,null))['catch'](handleError(_0x5cde93,null));};exports[_0x2fcb('0x35')]=function(_0x32d0ba,_0x1fbcb5){return db[_0x2fcb('0x2c')][_0x2fcb('0x35')](_0x32d0ba['body'],{})['then'](respondWithResult(_0x1fbcb5,0xc9))[_0x2fcb('0x27')](handleError(_0x1fbcb5,null));};exports[_0x2fcb('0x36')]=function(_0x433b7c,_0xe96131){if(_0x433b7c[_0x2fcb('0x37')]['id']){delete _0x433b7c['body']['id'];}return db['WhatsappInteraction']['find']({'where':{'id':_0x433b7c['params']['id']}})[_0x2fcb('0x1b')](handleEntityNotFound(_0xe96131,null))[_0x2fcb('0x1b')](saveUpdates(_0x433b7c[_0x2fcb('0x37')],null))[_0x2fcb('0x1b')](respondWithResult(_0xe96131,null))[_0x2fcb('0x27')](handleError(_0xe96131,null));};exports['destroy']=function(_0x9380a5,_0x4235cf){return db['WhatsappInteraction']['find']({'where':{'id':_0x9380a5['params']['id']}})[_0x2fcb('0x1b')](handleEntityNotFound(_0x4235cf,null))[_0x2fcb('0x1b')](removeEntity(_0x4235cf,null))['catch'](handleError(_0x4235cf,null));};exports['describe']=function(_0x1bb594,_0x568ac6){return db[_0x2fcb('0x2c')]['describe']()['then'](respondWithResult(_0x568ac6,null))[_0x2fcb('0x27')](handleError(_0x568ac6,null));};exports[_0x2fcb('0x38')]=function(_0x49a192,_0x7204e2){return db[_0x2fcb('0x39')][_0x2fcb('0x3a')]({'where':{'id':_0x49a192[_0x2fcb('0x29')]['id']}})[_0x2fcb('0x1b')](handleEntityNotFound(_0x7204e2,null))[_0x2fcb('0x1b')](function(_0x4e0a84){if(_0x4e0a84){return _0x4e0a84[_0x2fcb('0x38')](_0x49a192[_0x2fcb('0x37')][_0x2fcb('0x3b')],_['omit'](_0x49a192['body'],['ids','id'])||{});}})['then'](respondWithResult(_0x7204e2,null))[_0x2fcb('0x27')](handleError(_0x7204e2,null));};exports['getMessages']=function(_0x36d09f,_0x3e78f0){var _0x18680f={'raw':![],'where':{}};var _0x1e033f={};var _0x5028a0={'count':0x0,'rows':[]};return db['WhatsappInteraction']['findOne']({'where':{'id':_0x36d09f['params']['id']}})[_0x2fcb('0x1b')](handleEntityNotFound(_0x3e78f0,null))[_0x2fcb('0x1b')](function(_0x1fc275){if(_0x1fc275){_0x1e033f[_0x2fcb('0x2a')]=_['keys'](db[_0x2fcb('0x39')]['rawAttributes']);_0x1e033f['query']=_[_0x2fcb('0x2b')](_0x36d09f[_0x2fcb('0x26')]);_0x1e033f[_0x2fcb('0x2d')]=_['intersection'](_0x1e033f[_0x2fcb('0x2a')],_0x1e033f['query']);_0x18680f[_0x2fcb('0x2f')]=_[_0x2fcb('0x2e')](_0x1e033f[_0x2fcb('0x2a')],qs[_0x2fcb('0x30')](_0x36d09f[_0x2fcb('0x26')]['fields']));_0x18680f[_0x2fcb('0x2f')]=_0x18680f[_0x2fcb('0x2f')][_0x2fcb('0x31')]?_0x18680f['attributes']:_0x1e033f[_0x2fcb('0x2a')];if(!_0x36d09f[_0x2fcb('0x26')]['hasOwnProperty'](_0x2fcb('0x3c'))){_0x18680f[_0x2fcb('0x3d')]=qs[_0x2fcb('0x3d')](_0x36d09f['query'][_0x2fcb('0x3d')]);_0x18680f['offset']=qs[_0x2fcb('0x17')](_0x36d09f[_0x2fcb('0x26')][_0x2fcb('0x17')]);}_0x18680f['order']=qs['sort'](_0x36d09f[_0x2fcb('0x26')][_0x2fcb('0x3e')]);_0x18680f['where']=qs['filters'](_['pick'](_0x36d09f[_0x2fcb('0x26')],_0x1e033f['filters']));_0x18680f[_0x2fcb('0x3f')][_0x2fcb('0x40')]=_0x1fc275['id'];if(_0x36d09f['query'][_0x2fcb('0x41')]){_0x18680f[_0x2fcb('0x3f')]=_[_0x2fcb('0x34')](_0x18680f[_0x2fcb('0x3f')],{'$or':_[_0x2fcb('0x42')](_0x18680f[_0x2fcb('0x2f')],function(_0x2d6451){var _0x38bb9c={};_0x38bb9c[_0x2d6451]={'$like':'%'+_0x36d09f[_0x2fcb('0x26')][_0x2fcb('0x41')]+'%'};return _0x38bb9c;})});}if(_0x36d09f['query'][_0x2fcb('0x43')]){var _0x1b83b2=_0x36d09f[_0x2fcb('0x26')][_0x2fcb('0x43')]['split'](',');var _0x33d4fd={};_0x33d4fd[_0x1b83b2[0x0]]={'$gte':moment(_0x1b83b2[0x1])['format'](_0x2fcb('0x44'))};_0x18680f[_0x2fcb('0x3f')]=_['merge'](_0x18680f[_0x2fcb('0x3f')],_0x33d4fd);}_0x18680f=_[_0x2fcb('0x34')]({},_0x18680f,_0x36d09f[_0x2fcb('0x45')]);return db['WhatsappMessage']['count']({'where':_0x18680f[_0x2fcb('0x3f')]})[_0x2fcb('0x1b')](function(_0x4d6ce8){_0x5028a0[_0x2fcb('0x18')]=_0x4d6ce8;if(_0x36d09f['query'][_0x2fcb('0x32')]){_0x18680f[_0x2fcb('0x33')]=[{'all':!![]}];}return db[_0x2fcb('0x39')][_0x2fcb('0x24')](_0x18680f);})[_0x2fcb('0x1b')](function(_0x4badc9){_0x5028a0[_0x2fcb('0x46')]=_0x4badc9;return _0x5028a0;});}})[_0x2fcb('0x1b')](respondWithFilteredResult(_0x3e78f0,_0x18680f))['catch'](handleError(_0x3e78f0,null));};exports[_0x2fcb('0x47')]=function(_0x107023,_0x1e0562){return db[_0x2fcb('0x2c')]['find']({'where':{'id':_0x107023['params']['id']}})['then'](handleEntityNotFound(_0x1e0562,null))['then'](function(_0x579f51){if(_0x579f51){return _0x579f51[_0x2fcb('0x48')](_0x107023[_0x2fcb('0x37')]['ids'],_[_0x2fcb('0x49')](_0x107023['body'],[_0x2fcb('0x3b'),'id'])||{})[_0x2fcb('0x4a')](function(){return db[_0x2fcb('0x4b')]['findAll']({'attributes':['id','name','color'],'where':{'id':_0x107023['body']['ids']}});})[_0x2fcb('0x1b')](function(_0x12a3ca){socket[_0x2fcb('0x4c')]('whatsappInteractionTags:save',{'id':Number(_0x107023['params']['id']),'tags':_0x12a3ca||[]});return{'id':Number(_0x107023[_0x2fcb('0x29')]['id']),'tags':_0x12a3ca||[]};});}})[_0x2fcb('0x1b')](respondWithResult(_0x1e0562,null))[_0x2fcb('0x27')](handleError(_0x1e0562,null));};exports['removeTags']=function(_0x3b7d70,_0xf1f56){return db['WhatsappInteraction']['find']({'where':{'id':_0x3b7d70[_0x2fcb('0x29')]['id']}})[_0x2fcb('0x1b')](handleEntityNotFound(_0xf1f56,null))[_0x2fcb('0x1b')](function(_0xcd88d5){if(_0xcd88d5){return _0xcd88d5[_0x2fcb('0x4d')](_0x3b7d70[_0x2fcb('0x26')][_0x2fcb('0x3b')]);}})[_0x2fcb('0x1b')](respondWithStatusCode(_0xf1f56,null))[_0x2fcb('0x27')](handleError(_0xf1f56,null));};exports[_0x2fcb('0x4e')]=function(_0x54322e,_0x22d931){var _0x528a79=moment()[_0x2fcb('0x4f')]()[_0x2fcb('0x50')]();var _0x4e1e97=path[_0x2fcb('0x51')](config[_0x2fcb('0x52')],_0x2fcb('0x53'),_0x2fcb('0x54'),'tmp');var _0x3a40e5=path[_0x2fcb('0x51')](config[_0x2fcb('0x52')],_0x2fcb('0x53'),_0x2fcb('0x54'),'attachments');var _0x5847a5=path['join'](_0x4e1e97,_0x528a79);var _0xdc0e61=util[_0x2fcb('0x55')]('transcript-%d-%s.zip',_0x54322e[_0x2fcb('0x29')]['id'],_0x528a79);var _0x2bc744=path[_0x2fcb('0x51')](_0x4e1e97,_0xdc0e61);var _0x1a2014=[];_0x1a2014['push']({'model':db[_0x2fcb('0x56')],'as':'User','attributes':['id',_0x2fcb('0x57')],'raw':!![]});_0x1a2014[_0x2fcb('0x58')]({'model':db[_0x2fcb('0x59')],'as':'Contact','attributes':['id',_0x2fcb('0x5a'),'lastName'],'raw':!![]});if(_0x54322e[_0x2fcb('0x26')][_0x2fcb('0x5b')]){_0x1a2014['push']({'model':db['Attachment'],'as':_0x2fcb('0x5c'),'raw':!![]});}var _0x5b86ac=[{'model':db[_0x2fcb('0x39')],'as':_0x2fcb('0x5d'),'attributes':['id',_0x2fcb('0x37'),'createdAt',_0x2fcb('0x5e'),'secret',_0x2fcb('0x5f')],'include':_0x1a2014}];_0x5b86ac['push']({'model':db[_0x2fcb('0x60')],'as':_0x2fcb('0x61'),'attributes':['id',_0x2fcb('0x1e')]});_0x5b86ac['push']({'model':db[_0x2fcb('0x56')],'as':_0x2fcb('0x62'),'attributes':['id','fullname']});return db[_0x2fcb('0x2c')][_0x2fcb('0x3a')]({'where':{'id':_0x54322e[_0x2fcb('0x29')]['id']},'include':_0x5b86ac})[_0x2fcb('0x1b')](handleEntityNotFound(_0x22d931,null))[_0x2fcb('0x1b')](function(_0x1bb583){if(_0x1bb583){var _0x3bfa86=_0x1bb583[_0x2fcb('0x63')]({'plain':!![]});fs[_0x2fcb('0x64')](_0x5847a5);var _0x182c4d={'channel':_0x2fcb('0x65'),'account':_0x3bfa86[_0x2fcb('0x61')][_0x2fcb('0x1e')],'agent':_0x3bfa86[_0x2fcb('0x62')]?_0x3bfa86[_0x2fcb('0x62')][_0x2fcb('0x57')]:_0x2fcb('0x66'),'createdAt':moment(_0x3bfa86[_0x2fcb('0x67')])[_0x2fcb('0x55')](_0x2fcb('0x44'))['toString'](),'closedAt':_0x3bfa86['closed']?moment(_0x3bfa86[_0x2fcb('0x68')])['format'](_0x2fcb('0x44'))[_0x2fcb('0x50')]():'','disposition':_0x3bfa86[_0x2fcb('0x69')],'messages':_(_0x3bfa86['Messages'])['filter']({'secret':![]})['map'](function(_0x491c88){if(_0x491c88[_0x2fcb('0x5c')]){var _0xf4c4eb=path[_0x2fcb('0x51')](_0x3a40e5,_0x491c88['Attachment']['basename']);if(fs['existsSync'](_0xf4c4eb)){fs[_0x2fcb('0x6a')](_0xf4c4eb)[_0x2fcb('0x6b')](fs[_0x2fcb('0x6c')](path[_0x2fcb('0x51')](_0x5847a5,_0x491c88[_0x2fcb('0x5c')]['basename'])));}}return{'date':moment(_0x491c88[_0x2fcb('0x67')])[_0x2fcb('0x55')](_0x2fcb('0x44'))[_0x2fcb('0x50')](),'sender':_0x491c88['direction']===_0x2fcb('0x6d')?_0x491c88[_0x2fcb('0x56')]?_0x491c88['User'][_0x2fcb('0x57')]:_0x2fcb('0x6e'):_0x491c88[_0x2fcb('0x6f')][_0x2fcb('0x5a')]+(_0x491c88[_0x2fcb('0x6f')][_0x2fcb('0x70')]?'\x20'+_0x491c88[_0x2fcb('0x6f')][_0x2fcb('0x70')]:''),'body':_0x491c88[_0x2fcb('0x5c')]?_0x491c88[_0x2fcb('0x5c')][_0x2fcb('0x71')]:_0x491c88['body'],'direction':_0x491c88[_0x2fcb('0x5e')]===_0x2fcb('0x6d')?'A':'C','secret':_0x491c88[_0x2fcb('0x72')],'read':_0x491c88[_0x2fcb('0x5f')],'attachment':_0x491c88[_0x2fcb('0x5c')]};})[_0x2fcb('0x73')]()};return ejs[_0x2fcb('0x74')](path[_0x2fcb('0x51')](config[_0x2fcb('0x52')],_0x2fcb('0x53'),_0x2fcb('0x75'),'downloadInteraction.ejs'),{'interaction':_0x182c4d})[_0x2fcb('0x1b')](function(_0x28d5ec){var _0x5f0035=path[_0x2fcb('0x51')](_0x5847a5,_0x2fcb('0x76')+_0x3bfa86['id']+'-'+_0x528a79+_0x2fcb('0x77'));var _0x2a4091={'path':_0x5f0035,'channel':_0x2fcb('0x65'),'interactionId':_0x3bfa86['id']};return pdf[_0x2fcb('0x78')](_0x28d5ec,_0x2a4091);})[_0x2fcb('0x1b')](function(){return new BPromise(function(_0x576c1b,_0xf3d19){zipdir(_0x5847a5,{'saveTo':_0x2bc744},function(_0xabe564,_0x56d876){if(_0xabe564)return _0xf3d19(_0xabe564);return _0x576c1b(_0x56d876);});})[_0x2fcb('0x1b')](function(){return new BPromise(function(_0x17b10c,_0x3cde11){rimraf(_0x5847a5,function(_0x5b19d8){if(_0x5b19d8)_0x3cde11(_0x5b19d8);return _0x17b10c();});});})[_0x2fcb('0x1b')](function(){return _0x22d931['download'](_0x2bc744,_0xdc0e61,function(_0x2e1a1d){if(_0x2e1a1d){console[_0x2fcb('0x79')](_0x2fcb('0x7a'),_0x2e1a1d);}else{fs[_0x2fcb('0x7b')](_0x2bc744);}});});});}else{return _0x22d931['sendStatus'](0xc8);}})[_0x2fcb('0x27')](handleError(_0x22d931,null));};
\ No newline at end of file
+var _0x934b=['set','Content-Range','destroy','then','error','stack','name','send','index','type','key','getOptions','findAll','query','user','catch','show','model','WhatsappInteraction','rawAttributes','keys','filters','attributes','intersection','fields','length','include','merge','options','find','create','body','update','params','describe','addMessage','WhatsappMessage','omit','ids','getMessages','findOne','sort','where','pick','$gte','format','YYYY-MM-DD\x20HH:mm:ss','includeAll','rows','addTags','setTags','spread','Tag','color','emit','whatsappInteractionTags:save','removeTags','download','unix','toString','join','root','server','files','tmp','attachments','transcript-%d-%s.zip','push','User','Contact','firstName','lastName','Attachment','Messages','createdAt','direction','read','WhatsappAccount','Account','get','mkdirSync','Owner','fullname','closed','closedAt','basename','existsSync','createReadStream','pipe','createWriteStream','out','System','secret','value','renderFile','views','downloadInteraction.ejs','Whatsapp','createPdfFromHTML','log','err','rimraf','zip-dir','moment','bluebird','path','ejs','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','../../config/environment','redis','localhost','socket.io-emitter','./whatsappInteraction.socket','register','sendStatus','status','end','json','offset','undefined','limit','count'];(function(_0x2becba,_0x4ea656){var _0x90b5dd=function(_0x26ae2b){while(--_0x26ae2b){_0x2becba['push'](_0x2becba['shift']());}};_0x90b5dd(++_0x4ea656);}(_0x934b,0xe4));var _0xb934=function(_0x36f5cb,_0x2a720f){_0x36f5cb=_0x36f5cb-0x0;var _0x58d6ce=_0x934b[_0x36f5cb];return _0x58d6ce;};'use strict';var rimraf=require(_0xb934('0x0'));var zipdir=require(_0xb934('0x1'));var moment=require(_0xb934('0x2'));var BPromise=require(_0xb934('0x3'));var util=require('util');var path=require(_0xb934('0x4'));var ejs=require(_0xb934('0x5'));var fs=require('fs');var _=require(_0xb934('0x6'));var Redis=require(_0xb934('0x7'));var interaction=require(_0xb934('0x8'));var qs=require(_0xb934('0x9'));var pdf=require(_0xb934('0xa'));var logger=require(_0xb934('0xb'))('api');var config=require(_0xb934('0xc'));var db=require('../../mysqldb')['db'];config[_0xb934('0xd')]=_['defaults'](config[_0xb934('0xd')],{'host':_0xb934('0xe'),'port':0x18eb});var socket=require(_0xb934('0xf'))(new Redis(config[_0xb934('0xd')]));require(_0xb934('0x10'))[_0xb934('0x11')](socket);function respondWithStatusCode(_0x275c3f,_0x552155){_0x552155=_0x552155||0xcc;return function(_0x4ab59d){if(_0x4ab59d){return _0x275c3f[_0xb934('0x12')](_0x552155);}return _0x275c3f[_0xb934('0x13')](_0x552155)[_0xb934('0x14')]();};}function respondWithResult(_0x1c7234,_0x4b1bab){_0x4b1bab=_0x4b1bab||0xc8;return function(_0x431934){if(_0x431934){return _0x1c7234[_0xb934('0x13')](_0x4b1bab)[_0xb934('0x15')](_0x431934);}};}function respondWithFilteredResult(_0xd5fab4,_0x516d6a){return function(_0x3590d9){if(_0x3590d9){var _0x24ce2f=typeof _0x516d6a[_0xb934('0x16')]===_0xb934('0x17')&&typeof _0x516d6a[_0xb934('0x18')]===_0xb934('0x17');var _0x512642=_0x3590d9[_0xb934('0x19')];var _0x1ea202=_0x24ce2f?0x0:_0x516d6a[_0xb934('0x16')];var _0x15f749=_0x24ce2f?_0x3590d9[_0xb934('0x19')]:_0x516d6a[_0xb934('0x16')]+_0x516d6a[_0xb934('0x18')];var _0x122b4a;if(_0x15f749>=_0x512642){_0x15f749=_0x512642;_0x122b4a=0xc8;}else{_0x122b4a=0xce;}_0xd5fab4['status'](_0x122b4a);return _0xd5fab4[_0xb934('0x1a')](_0xb934('0x1b'),_0x1ea202+'-'+_0x15f749+'/'+_0x512642)[_0xb934('0x15')](_0x3590d9);}return null;};}function saveUpdates(_0x4d2de5){return function(_0x474d89){if(_0x474d89){return _0x474d89['update'](_0x4d2de5)['then'](function(_0xde2c30){return _0xde2c30;});}return null;};}function removeEntity(_0xf0c0d){return function(_0x2cfdc4){if(_0x2cfdc4){return _0x2cfdc4[_0xb934('0x1c')]()[_0xb934('0x1d')](function(){_0xf0c0d[_0xb934('0x13')](0xcc)[_0xb934('0x14')]();});}};}function handleEntityNotFound(_0x2db191){return function(_0x46ff39){if(!_0x46ff39){_0x2db191[_0xb934('0x12')](0x194);}return _0x46ff39;};}function handleError(_0x8b21f6,_0x269644){_0x269644=_0x269644||0x1f4;return function(_0x36416c){logger[_0xb934('0x1e')](_0x36416c[_0xb934('0x1f')]);if(_0x36416c[_0xb934('0x20')]){delete _0x36416c['name'];}_0x8b21f6[_0xb934('0x13')](_0x269644)[_0xb934('0x21')](_0x36416c);};}exports[_0xb934('0x22')]=function(_0x3a8ed3,_0x103329){var _0x1c8078={};var _0x4517e0=_['map'](db['WhatsappInteraction']['rawAttributes'],function(_0x214c23){return{'name':_0x214c23['fieldName'],'type':_0x214c23[_0xb934('0x23')][_0xb934('0x24')]};});_0x1c8078=qs[_0xb934('0x25')](_0x4517e0,_0x3a8ed3);return interaction[_0xb934('0x26')]('whatsapp',_0x3a8ed3[_0xb934('0x27')],_0x3a8ed3[_0xb934('0x28')],_0x1c8078,_0x4517e0)[_0xb934('0x1d')](respondWithFilteredResult(_0x103329,_0x1c8078))[_0xb934('0x29')](handleError(_0x103329,null));};exports[_0xb934('0x2a')]=function(_0xf30b02,_0x402e3f){var _0x50e0f5={'raw':![],'where':{'id':_0xf30b02['params']['id']}},_0x26c32b={};_0x26c32b[_0xb934('0x2b')]=_['keys'](db[_0xb934('0x2c')][_0xb934('0x2d')]);_0x26c32b['query']=_[_0xb934('0x2e')](_0xf30b02[_0xb934('0x27')]);_0x26c32b[_0xb934('0x2f')]=_['intersection'](_0x26c32b[_0xb934('0x2b')],_0x26c32b[_0xb934('0x27')]);_0x50e0f5[_0xb934('0x30')]=_[_0xb934('0x31')](_0x26c32b[_0xb934('0x2b')],qs[_0xb934('0x32')](_0xf30b02[_0xb934('0x27')][_0xb934('0x32')]));_0x50e0f5[_0xb934('0x30')]=_0x50e0f5[_0xb934('0x30')][_0xb934('0x33')]?_0x50e0f5[_0xb934('0x30')]:_0x26c32b[_0xb934('0x2b')];if(_0xf30b02[_0xb934('0x27')]['includeAll']){_0x50e0f5[_0xb934('0x34')]=[{'all':!![]}];}_0x50e0f5=_[_0xb934('0x35')]({},_0x50e0f5,_0xf30b02[_0xb934('0x36')]);return db['WhatsappInteraction'][_0xb934('0x37')](_0x50e0f5)[_0xb934('0x1d')](handleEntityNotFound(_0x402e3f,null))[_0xb934('0x1d')](respondWithResult(_0x402e3f,null))[_0xb934('0x29')](handleError(_0x402e3f,null));};exports[_0xb934('0x38')]=function(_0x26a08e,_0x43f6a5){return db[_0xb934('0x2c')]['create'](_0x26a08e[_0xb934('0x39')],{})[_0xb934('0x1d')](respondWithResult(_0x43f6a5,0xc9))[_0xb934('0x29')](handleError(_0x43f6a5,null));};exports[_0xb934('0x3a')]=function(_0x76fbf5,_0x1db6d2){if(_0x76fbf5[_0xb934('0x39')]['id']){delete _0x76fbf5['body']['id'];}return db[_0xb934('0x2c')]['find']({'where':{'id':_0x76fbf5[_0xb934('0x3b')]['id']}})[_0xb934('0x1d')](handleEntityNotFound(_0x1db6d2,null))[_0xb934('0x1d')](saveUpdates(_0x76fbf5[_0xb934('0x39')],null))[_0xb934('0x1d')](respondWithResult(_0x1db6d2,null))[_0xb934('0x29')](handleError(_0x1db6d2,null));};exports[_0xb934('0x1c')]=function(_0x41fb3e,_0x3203aa){return db[_0xb934('0x2c')]['find']({'where':{'id':_0x41fb3e[_0xb934('0x3b')]['id']}})[_0xb934('0x1d')](handleEntityNotFound(_0x3203aa,null))[_0xb934('0x1d')](removeEntity(_0x3203aa,null))[_0xb934('0x29')](handleError(_0x3203aa,null));};exports[_0xb934('0x3c')]=function(_0xcffc90,_0x2d3265){return db['WhatsappInteraction']['describe']()[_0xb934('0x1d')](respondWithResult(_0x2d3265,null))[_0xb934('0x29')](handleError(_0x2d3265,null));};exports[_0xb934('0x3d')]=function(_0x28b3af,_0x4f9054){return db[_0xb934('0x3e')]['find']({'where':{'id':_0x28b3af[_0xb934('0x3b')]['id']}})[_0xb934('0x1d')](handleEntityNotFound(_0x4f9054,null))[_0xb934('0x1d')](function(_0x2cb12d){if(_0x2cb12d){return _0x2cb12d['addMessage'](_0x28b3af[_0xb934('0x39')]['ids'],_[_0xb934('0x3f')](_0x28b3af[_0xb934('0x39')],[_0xb934('0x40'),'id'])||{});}})[_0xb934('0x1d')](respondWithResult(_0x4f9054,null))[_0xb934('0x29')](handleError(_0x4f9054,null));};exports[_0xb934('0x41')]=function(_0x567ed8,_0x4119a6){var _0xb65684={'raw':![],'where':{}};var _0x2d8070={};var _0x5f41ee={'count':0x0,'rows':[]};return db[_0xb934('0x2c')][_0xb934('0x42')]({'where':{'id':_0x567ed8[_0xb934('0x3b')]['id']}})[_0xb934('0x1d')](handleEntityNotFound(_0x4119a6,null))[_0xb934('0x1d')](function(_0x470a2e){if(_0x470a2e){_0x2d8070[_0xb934('0x2b')]=_[_0xb934('0x2e')](db[_0xb934('0x3e')]['rawAttributes']);_0x2d8070[_0xb934('0x27')]=_[_0xb934('0x2e')](_0x567ed8[_0xb934('0x27')]);_0x2d8070[_0xb934('0x2f')]=_[_0xb934('0x31')](_0x2d8070['model'],_0x2d8070[_0xb934('0x27')]);_0xb65684['attributes']=_[_0xb934('0x31')](_0x2d8070['model'],qs[_0xb934('0x32')](_0x567ed8['query']['fields']));_0xb65684[_0xb934('0x30')]=_0xb65684[_0xb934('0x30')][_0xb934('0x33')]?_0xb65684[_0xb934('0x30')]:_0x2d8070[_0xb934('0x2b')];if(!_0x567ed8[_0xb934('0x27')]['hasOwnProperty']('nolimit')){_0xb65684[_0xb934('0x18')]=qs[_0xb934('0x18')](_0x567ed8['query'][_0xb934('0x18')]);_0xb65684['offset']=qs[_0xb934('0x16')](_0x567ed8[_0xb934('0x27')]['offset']);}_0xb65684['order']=qs[_0xb934('0x43')](_0x567ed8[_0xb934('0x27')][_0xb934('0x43')]);_0xb65684[_0xb934('0x44')]=qs[_0xb934('0x2f')](_[_0xb934('0x45')](_0x567ed8[_0xb934('0x27')],_0x2d8070[_0xb934('0x2f')]));_0xb65684[_0xb934('0x44')]['WhatsappInteractionId']=_0x470a2e['id'];if(_0x567ed8[_0xb934('0x27')]['filter']){_0xb65684[_0xb934('0x44')]=_[_0xb934('0x35')](_0xb65684[_0xb934('0x44')],{'$or':_['map'](_0xb65684[_0xb934('0x30')],function(_0x48ae08){var _0xcfef17={};_0xcfef17[_0x48ae08]={'$like':'%'+_0x567ed8[_0xb934('0x27')]['filter']+'%'};return _0xcfef17;})});}if(_0x567ed8['query'][_0xb934('0x46')]){var _0x509247=_0x567ed8[_0xb934('0x27')][_0xb934('0x46')]['split'](',');var _0x5ae47c={};_0x5ae47c[_0x509247[0x0]]={'$gte':moment(_0x509247[0x1])[_0xb934('0x47')](_0xb934('0x48'))};_0xb65684[_0xb934('0x44')]=_[_0xb934('0x35')](_0xb65684[_0xb934('0x44')],_0x5ae47c);}_0xb65684=_[_0xb934('0x35')]({},_0xb65684,_0x567ed8['options']);return db['WhatsappMessage']['count']({'where':_0xb65684[_0xb934('0x44')]})[_0xb934('0x1d')](function(_0x18c4d0){_0x5f41ee['count']=_0x18c4d0;if(_0x567ed8[_0xb934('0x27')][_0xb934('0x49')]){_0xb65684[_0xb934('0x34')]=[{'all':!![]}];}return db[_0xb934('0x3e')][_0xb934('0x26')](_0xb65684);})[_0xb934('0x1d')](function(_0x2ccd57){_0x5f41ee[_0xb934('0x4a')]=_0x2ccd57;return _0x5f41ee;});}})['then'](respondWithFilteredResult(_0x4119a6,_0xb65684))['catch'](handleError(_0x4119a6,null));};exports[_0xb934('0x4b')]=function(_0x571297,_0x24f179){return db[_0xb934('0x2c')]['find']({'where':{'id':_0x571297[_0xb934('0x3b')]['id']}})[_0xb934('0x1d')](handleEntityNotFound(_0x24f179,null))[_0xb934('0x1d')](function(_0x55a508){if(_0x55a508){return _0x55a508[_0xb934('0x4c')](_0x571297['body'][_0xb934('0x40')],_[_0xb934('0x3f')](_0x571297[_0xb934('0x39')],[_0xb934('0x40'),'id'])||{})[_0xb934('0x4d')](function(){return db[_0xb934('0x4e')][_0xb934('0x26')]({'attributes':['id',_0xb934('0x20'),_0xb934('0x4f')],'where':{'id':_0x571297[_0xb934('0x39')][_0xb934('0x40')]}});})[_0xb934('0x1d')](function(_0x4976c2){socket[_0xb934('0x50')](_0xb934('0x51'),{'id':Number(_0x571297['params']['id']),'tags':_0x4976c2||[]});return{'id':Number(_0x571297[_0xb934('0x3b')]['id']),'tags':_0x4976c2||[]};});}})[_0xb934('0x1d')](respondWithResult(_0x24f179,null))[_0xb934('0x29')](handleError(_0x24f179,null));};exports['removeTags']=function(_0x9cee34,_0x2584fd){return db['WhatsappInteraction'][_0xb934('0x37')]({'where':{'id':_0x9cee34['params']['id']}})[_0xb934('0x1d')](handleEntityNotFound(_0x2584fd,null))[_0xb934('0x1d')](function(_0x170f87){if(_0x170f87){return _0x170f87[_0xb934('0x52')](_0x9cee34['query'][_0xb934('0x40')]);}})['then'](respondWithStatusCode(_0x2584fd,null))['catch'](handleError(_0x2584fd,null));};exports[_0xb934('0x53')]=function(_0x25064e,_0x1feef5){var _0x3ed5e2=moment()[_0xb934('0x54')]()[_0xb934('0x55')]();var _0x17a0ad=path[_0xb934('0x56')](config[_0xb934('0x57')],_0xb934('0x58'),_0xb934('0x59'),_0xb934('0x5a'));var _0x281a14=path['join'](config[_0xb934('0x57')],_0xb934('0x58'),_0xb934('0x59'),_0xb934('0x5b'));var _0xb0eb06=path[_0xb934('0x56')](_0x17a0ad,_0x3ed5e2);var _0x154c39=util[_0xb934('0x47')](_0xb934('0x5c'),_0x25064e[_0xb934('0x3b')]['id'],_0x3ed5e2);var _0x3c11fd=path['join'](_0x17a0ad,_0x154c39);var _0x2467bc=[];_0x2467bc[_0xb934('0x5d')]({'model':db[_0xb934('0x5e')],'as':'User','attributes':['id','fullname'],'raw':!![]});_0x2467bc[_0xb934('0x5d')]({'model':db['CmContact'],'as':_0xb934('0x5f'),'attributes':['id',_0xb934('0x60'),_0xb934('0x61')],'raw':!![]});if(_0x25064e[_0xb934('0x27')][_0xb934('0x5b')]){_0x2467bc[_0xb934('0x5d')]({'model':db[_0xb934('0x62')],'as':_0xb934('0x62'),'raw':!![]});}var _0x3efa21=[{'model':db['WhatsappMessage'],'as':_0xb934('0x63'),'attributes':['id',_0xb934('0x39'),_0xb934('0x64'),_0xb934('0x65'),'secret',_0xb934('0x66')],'include':_0x2467bc}];_0x3efa21[_0xb934('0x5d')]({'model':db[_0xb934('0x67')],'as':_0xb934('0x68'),'attributes':['id',_0xb934('0x20')]});_0x3efa21[_0xb934('0x5d')]({'model':db[_0xb934('0x5e')],'as':'Owner','attributes':['id','fullname']});return db[_0xb934('0x2c')][_0xb934('0x37')]({'where':{'id':_0x25064e[_0xb934('0x3b')]['id']},'include':_0x3efa21})['then'](handleEntityNotFound(_0x1feef5,null))[_0xb934('0x1d')](function(_0x346aeb){if(_0x346aeb){var _0x3c7eba=_0x346aeb[_0xb934('0x69')]({'plain':!![]});fs[_0xb934('0x6a')](_0xb0eb06);var _0x18ad00={'channel':'Whatsapp','account':_0x3c7eba[_0xb934('0x68')]['name'],'agent':_0x3c7eba[_0xb934('0x6b')]?_0x3c7eba['Owner'][_0xb934('0x6c')]:'N.A.','createdAt':moment(_0x3c7eba['createdAt'])[_0xb934('0x47')](_0xb934('0x48'))[_0xb934('0x55')](),'closedAt':_0x3c7eba[_0xb934('0x6d')]?moment(_0x3c7eba[_0xb934('0x6e')])[_0xb934('0x47')](_0xb934('0x48'))[_0xb934('0x55')]():'','disposition':_0x3c7eba['disposition'],'messages':_(_0x3c7eba[_0xb934('0x63')])['filter']({'secret':![]})['map'](function(_0x682c88){if(_0x682c88[_0xb934('0x62')]){var _0x2f99ce=path[_0xb934('0x56')](_0x281a14,_0x682c88[_0xb934('0x62')][_0xb934('0x6f')]);if(fs[_0xb934('0x70')](_0x2f99ce)){fs[_0xb934('0x71')](_0x2f99ce)[_0xb934('0x72')](fs[_0xb934('0x73')](path[_0xb934('0x56')](_0xb0eb06,_0x682c88[_0xb934('0x62')][_0xb934('0x6f')])));}}return{'date':moment(_0x682c88[_0xb934('0x64')])[_0xb934('0x47')](_0xb934('0x48'))['toString'](),'sender':_0x682c88[_0xb934('0x65')]===_0xb934('0x74')?_0x682c88['User']?_0x682c88[_0xb934('0x5e')][_0xb934('0x6c')]:_0xb934('0x75'):_0x682c88['Contact'][_0xb934('0x60')]+(_0x682c88['Contact']['lastName']?'\x20'+_0x682c88[_0xb934('0x5f')]['lastName']:''),'body':_0x682c88[_0xb934('0x62')]?_0x682c88[_0xb934('0x62')][_0xb934('0x6f')]:_0x682c88[_0xb934('0x39')],'direction':_0x682c88[_0xb934('0x65')]===_0xb934('0x74')?'A':'C','secret':_0x682c88[_0xb934('0x76')],'read':_0x682c88[_0xb934('0x66')],'attachment':_0x682c88[_0xb934('0x62')]};})[_0xb934('0x77')]()};return ejs[_0xb934('0x78')](path[_0xb934('0x56')](config[_0xb934('0x57')],_0xb934('0x58'),_0xb934('0x79'),_0xb934('0x7a')),{'interaction':_0x18ad00})[_0xb934('0x1d')](function(_0x251d4e){var _0x355610=path[_0xb934('0x56')](_0xb0eb06,'transcript-'+_0x3c7eba['id']+'-'+_0x3ed5e2+'.pdf');var _0x195fa5={'path':_0x355610,'channel':_0xb934('0x7b'),'interactionId':_0x3c7eba['id']};return pdf[_0xb934('0x7c')](_0x251d4e,_0x195fa5);})[_0xb934('0x1d')](function(){return new BPromise(function(_0x2a622d,_0x519545){zipdir(_0xb0eb06,{'saveTo':_0x3c11fd},function(_0x40cede,_0x622182){if(_0x40cede)return _0x519545(_0x40cede);return _0x2a622d(_0x622182);});})[_0xb934('0x1d')](function(){return new BPromise(function(_0x382072,_0x36b155){rimraf(_0xb0eb06,function(_0x50bb81){if(_0x50bb81)_0x36b155(_0x50bb81);return _0x382072();});});})[_0xb934('0x1d')](function(){return _0x1feef5[_0xb934('0x53')](_0x3c11fd,_0x154c39,function(_0x337fe4){if(_0x337fe4){console[_0xb934('0x7d')](_0xb934('0x7e'),_0x337fe4);}else{fs['unlinkSync'](_0x3c11fd);}});});});}else{return _0x1feef5[_0xb934('0x12')](0xc8);}})[_0xb934('0x29')](handleError(_0x1feef5,null));};
\ No newline at end of file