Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index e185151..36629f4 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5d4e=['i.*','c.firstName','Contact.firstName','Contact.lastName','c.email','Contact.email','Contact.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','o.fullname','o.internal','Owner.internal','ui.WhatsappInteractionId\x20IN\x20?','WhatsappInteractionId','push','all','rows','show','params','includeAll','create','destroy','describe','addMessage','WhatsappMessage','ids','findOne','pick','format','YYYY-MM-DD\x20HH:mm:ss','include','addTags','omit','findAll','download','join','root','server','files','tmp','attachments','transcript-%d-%s.zip','fullname','CmContact','Messages','direction','secret','WhatsappAccount','Account','Owner','get','mkdirSync','Whatsapp','N.A.','closedAt','disposition','Attachment','existsSync','createReadStream','createWriteStream','basename','out','System','lastName','renderFile','views','downloadInteraction.ejs','transcript-','.pdf','unlinkSync','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','to-csv','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','./whatsappInteraction.socket','sendStatus','status','end','json','offset','undefined','limit','count','set','reject','update','then','stack','name','send','Users','TagIds','Tags','split','catch','waiting','answered','unmanaged','total','closed','UserId','talking','index','WhatsappInteraction','rawAttributes','fieldName','type','key','model','map','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','sort','where','field','color','from','u.fullname','ui.WhatsappInteractionId','user_has_whatsapp_interactions','whatsapp_interactions','left_join','cm_contacts','users','o.id\x20=\x20i.UserId','whatsapp_accounts','whatsapp_messages','me.WhatsappInteractionId\x20=\x20i.id','whatsapp_interaction_has_tags','it.WhatsappInteractionId\x20=\x20i.id','expr','search','parseSearch','sqlOperator','conditions','find','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','operator','$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','text','start','Tag','forEach','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','body','some','compact','isEmpty','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','isNumeric','i.id\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','Sequelize','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','order','contactName','DESC','t.id\x20IN\x20?','resolve','WhatsappAccountId','user','agent','getWhatsappAccounts','i.WhatsappAccountId\x20IS\x20NULL','i.WhatsappAccountId\x20IN\x20?','role','sequelize','toString','keyBy','merge','a.key','Account.key','a.mandatoryDisposition','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'];(function(_0xbf615d,_0x22bf6c){var _0x2c6a95=function(_0x3fa817){while(--_0x3fa817){_0xbf615d['push'](_0xbf615d['shift']());}};_0x2c6a95(++_0x22bf6c);}(_0x5d4e,0x138));var _0xe5d4=function(_0x122ef9,_0x451d2a){_0x122ef9=_0x122ef9-0x0;var _0x42fba0=_0x5d4e[_0x122ef9];return _0x42fba0;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xe5d4('0x0'));var zipdir=require(_0xe5d4('0x1'));var jsonpatch=require(_0xe5d4('0x2'));var rp=require(_0xe5d4('0x3'));var moment=require(_0xe5d4('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xe5d4('0x5'));var util=require(_0xe5d4('0x6'));var path=require(_0xe5d4('0x7'));var sox=require('sox');var csv=require(_0xe5d4('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0xe5d4('0x9'));var crypto=require(_0xe5d4('0xa'));var jsforce=require(_0xe5d4('0xb'));var deskjs=require(_0xe5d4('0xc'));var toCsv=require(_0xe5d4('0x8'));var querystring=require(_0xe5d4('0xd'));var Papa=require(_0xe5d4('0xe'));var Redis=require(_0xe5d4('0xf'));var authService=require(_0xe5d4('0x10'));var qs=require(_0xe5d4('0x11'));var as=require(_0xe5d4('0x12'));var pdf=require('../../components/export/pdf');var hardwareService=require('../../config/license/hardware');var logger=require(_0xe5d4('0x13'))(_0xe5d4('0x14'));var utils=require(_0xe5d4('0x15'));var config=require(_0xe5d4('0x16'));var licenseUtil=require(_0xe5d4('0x17'));var db=require(_0xe5d4('0x18'))['db'];config[_0xe5d4('0x19')]=_[_0xe5d4('0x1a')](config[_0xe5d4('0x19')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xe5d4('0x19')]));require(_0xe5d4('0x1b'))['register'](socket);function respondWithStatusCode(_0x9af39d,_0x3a3017){_0x3a3017=_0x3a3017||0xcc;return function(_0x3dee9f){if(_0x3dee9f){return _0x9af39d[_0xe5d4('0x1c')](_0x3a3017);}return _0x9af39d[_0xe5d4('0x1d')](_0x3a3017)[_0xe5d4('0x1e')]();};}function respondWithResult(_0x3e0139,_0x1c78fa){_0x1c78fa=_0x1c78fa||0xc8;return function(_0x274b83){if(_0x274b83){return _0x3e0139[_0xe5d4('0x1d')](_0x1c78fa)[_0xe5d4('0x1f')](_0x274b83);}};}function respondWithFilteredResult(_0x12ab5b,_0x915fb7){return function(_0x3a926a){if(_0x3a926a){var _0x435782=typeof _0x915fb7[_0xe5d4('0x20')]===_0xe5d4('0x21')&&typeof _0x915fb7[_0xe5d4('0x22')]===_0xe5d4('0x21');var _0x3253fe=_0x3a926a['count'];var _0x222791=_0x435782?0x0:_0x915fb7[_0xe5d4('0x20')];var _0x4c632f=_0x435782?_0x3a926a[_0xe5d4('0x23')]:_0x915fb7[_0xe5d4('0x20')]+_0x915fb7[_0xe5d4('0x22')];var _0x2f13d9;if(_0x4c632f>=_0x3253fe){_0x4c632f=_0x3253fe;_0x2f13d9=0xc8;}else{_0x2f13d9=0xce;}_0x12ab5b[_0xe5d4('0x1d')](_0x2f13d9);return _0x12ab5b[_0xe5d4('0x24')]('Content-Range',_0x222791+'-'+_0x4c632f+'/'+_0x3253fe)['json'](_0x3a926a);}return null;};}function patchUpdates(_0x2712b5){return function(_0x22283f){try{jsonpatch['apply'](_0x22283f,_0x2712b5,!![]);}catch(_0x1ddbbb){return BPromise[_0xe5d4('0x25')](_0x1ddbbb);}return _0x22283f['save']();};}function saveUpdates(_0x4cec21,_0x3c1a60){return function(_0x2d6e4f){if(_0x2d6e4f){return _0x2d6e4f[_0xe5d4('0x26')](_0x4cec21)[_0xe5d4('0x27')](function(_0x3e266e){return _0x3e266e;});}return null;};}function removeEntity(_0xb124df,_0x1c08b7){return function(_0x456ab2){if(_0x456ab2){return _0x456ab2['destroy']()[_0xe5d4('0x27')](function(){_0xb124df[_0xe5d4('0x1d')](0xcc)[_0xe5d4('0x1e')]();});}};}function handleEntityNotFound(_0x5db1fd,_0xf48273){return function(_0xf35c55){if(!_0xf35c55){_0x5db1fd[_0xe5d4('0x1c')](0x194);}return _0xf35c55;};}function handleError(_0x39478a,_0xbb9fdd){_0xbb9fdd=_0xbb9fdd||0x1f4;return function(_0xb0ae3b){logger['error'](_0xb0ae3b[_0xe5d4('0x28')]);if(_0xb0ae3b[_0xe5d4('0x29')]){delete _0xb0ae3b[_0xe5d4('0x29')];}_0x39478a[_0xe5d4('0x1d')](_0xbb9fdd)[_0xe5d4('0x2a')](_0xb0ae3b);};}function getInteractionUsers(_0x3bbe51,_0x569160){return new BPromise(function(_0x45663b,_0xbcf569){try{if(_0x569160[_0x3bbe51['id']]){_0x3bbe51[_0xe5d4('0x2b')]=_['map'](_0x569160[_0x3bbe51['id']],function(_0x346df4){return{'id':_0x346df4['id'],'fullname':_0x346df4['fullname']};});}}catch(_0x482bc2){_0xbcf569(_0x482bc2);}_0x45663b(_0x3bbe51);});}function getInteractionTags(_0x536d60,_0x49d612){return new BPromise(function(_0x15f33d,_0x1b5cd2){try{if(_0x536d60[_0xe5d4('0x2c')]){_0x536d60[_0xe5d4('0x2d')]=[];_0x536d60[_0xe5d4('0x2c')][_0xe5d4('0x2e')](',')['forEach'](function(_0x548cae){_0x536d60['Tags']['push'](_0x49d612[_0x548cae]);});}delete _0x536d60[_0xe5d4('0x2c')];}catch(_0x2f2e68){_0x1b5cd2(_0x2f2e68);}_0x15f33d(_0x536d60);});}function updateWhatsappInteraction(_0x412872,_0x2ba9c7,_0x48914a){return new BPromise(function(_0x1d344c,_0x1bc823){return getInteractionUsers(_0x412872,_0x48914a)[_0xe5d4('0x27')](function(_0x5dbc05){return getInteractionTags(_0x5dbc05,_0x2ba9c7);})[_0xe5d4('0x27')](function(_0x1e179a){return getStateInteraction(_0x1e179a);})[_0xe5d4('0x27')](function(_0x3510a5){_0x1d344c(_0x3510a5);})[_0xe5d4('0x2f')](function(_0x278484){_0x1bc823(_0x278484);});});}function getStateInteraction(_0x107d4c){return new BPromise(function(_0x475388){_0x107d4c[_0xe5d4('0x30')]=0x0;_0x107d4c['talking']=0x0;_0x107d4c[_0xe5d4('0x31')]=0x0;_0x107d4c[_0xe5d4('0x32')]=0x0;_0x107d4c[_0xe5d4('0x33')]=0x0;if(!_0x107d4c[_0xe5d4('0x34')]&&!_0x107d4c['UserId']){_0x107d4c[_0xe5d4('0x30')]+=0x1;}if(!_0x107d4c[_0xe5d4('0x34')]&&_0x107d4c[_0xe5d4('0x35')]){_0x107d4c[_0xe5d4('0x36')]+=0x1;if(_0x107d4c[_0xe5d4('0x30')]){_0x107d4c['waiting']-=0x1;}}if(_0x107d4c['closed']&&_0x107d4c[_0xe5d4('0x35')]){_0x107d4c[_0xe5d4('0x31')]+=0x1;if(_0x107d4c[_0xe5d4('0x36')]){_0x107d4c[_0xe5d4('0x36')]-=0x1;}}if(_0x107d4c['closed']&&!_0x107d4c[_0xe5d4('0x35')]){_0x107d4c[_0xe5d4('0x32')]+=0x1;if(_0x107d4c[_0xe5d4('0x30')]){_0x107d4c[_0xe5d4('0x30')]-=0x1;}}_0x107d4c[_0xe5d4('0x33')]+=0x1;_0x475388(_0x107d4c);});}exports[_0xe5d4('0x37')]=function(_0x39e17b,_0x1a4123){var _0x2c1445={},_0x333db1={},_0x1f9de9={'count':0x0,'rows':[]};var _0x4f2531=_['map'](db[_0xe5d4('0x38')][_0xe5d4('0x39')],function(_0x4cbd78){return{'name':_0x4cbd78[_0xe5d4('0x3a')],'type':_0x4cbd78[_0xe5d4('0x3b')][_0xe5d4('0x3c')]};});_0x333db1[_0xe5d4('0x3d')]=_[_0xe5d4('0x3e')](_0x4f2531,_0xe5d4('0x29'));_0x333db1[_0xe5d4('0x3f')]=_[_0xe5d4('0x40')](_0x39e17b[_0xe5d4('0x3f')]);_0x333db1[_0xe5d4('0x41')]=_['intersection'](_0x333db1[_0xe5d4('0x3d')],_0x333db1[_0xe5d4('0x3f')]);_0x2c1445[_0xe5d4('0x42')]=_[_0xe5d4('0x43')](_0x333db1[_0xe5d4('0x3d')],qs['fields'](_0x39e17b[_0xe5d4('0x3f')][_0xe5d4('0x44')]));_0x2c1445[_0xe5d4('0x42')]=_0x2c1445[_0xe5d4('0x42')][_0xe5d4('0x45')]?_0x2c1445['attributes']:_0x333db1['model'];if(!_0x39e17b[_0xe5d4('0x3f')][_0xe5d4('0x46')](_0xe5d4('0x47'))){_0x2c1445[_0xe5d4('0x22')]=qs[_0xe5d4('0x22')](_0x39e17b[_0xe5d4('0x3f')][_0xe5d4('0x22')]);_0x2c1445[_0xe5d4('0x20')]=qs['offset'](_0x39e17b[_0xe5d4('0x3f')]['offset']);}_0x2c1445['order']=qs[_0xe5d4('0x48')](_0x39e17b[_0xe5d4('0x3f')]['sort']);_0x2c1445[_0xe5d4('0x49')]=qs[_0xe5d4('0x41')](_['pick'](_0x39e17b['query'],_0x333db1['filters']),_0x4f2531);var _0x2df9ac=[];var _0x50e9ec=squel['select']()[_0xe5d4('0x4a')]('id')['field'](_0xe5d4('0x29'))[_0xe5d4('0x4a')](_0xe5d4('0x4b'))[_0xe5d4('0x4c')]('tools_tags');var _0x1fe8fc=squel['select']()[_0xe5d4('0x4a')]('u.id')[_0xe5d4('0x4a')](_0xe5d4('0x4d'))[_0xe5d4('0x4a')](_0xe5d4('0x4e'))['from'](_0xe5d4('0x4f'),'ui')['left_join']('users','u','u.id\x20=\x20ui.UserId');var _0x470c56=squel['select']()['from'](_0xe5d4('0x50'),'i')[_0xe5d4('0x51')](_0xe5d4('0x52'),'c','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL')[_0xe5d4('0x51')](_0xe5d4('0x53'),'o',_0xe5d4('0x54'))['left_join'](_0xe5d4('0x55'),'a','a.id\x20=\x20i.WhatsappAccountId')[_0xe5d4('0x51')](_0xe5d4('0x56'),'me',_0xe5d4('0x57'))[_0xe5d4('0x51')](_0xe5d4('0x58'),'it',_0xe5d4('0x59'))[_0xe5d4('0x51')]('tools_tags','t','t.id\x20=\x20it.TagId');var _0x110f49=squel[_0xe5d4('0x5a')]();var _0x50999e=[];var _0x5b5a02=squel['expr']();var _0x5eede3;if(_0x39e17b['query'][_0xe5d4('0x5b')]){_0x5eede3=as[_0xe5d4('0x5c')](_0x39e17b['query'][_0xe5d4('0x5b')]);var _0x53bf73=_0x5eede3[_0xe5d4('0x5d')];for(var _0xbb46e=0x0;_0xbb46e<_0x5eede3[_0xe5d4('0x5e')][_0xe5d4('0x45')];_0xbb46e++){var _0x28d0ad=_0x5eede3[_0xe5d4('0x5e')][_0xbb46e];var _0x52365e='i';var _0x5b0dba=_[_0xe5d4('0x5f')](_0x4f2531,[_0xe5d4('0x29'),_0x28d0ad[_0xe5d4('0x4a')]]);if(!_0x5b0dba){switch(_0x28d0ad['field']){case _0xe5d4('0x60'):if(_0x28d0ad[_0xe5d4('0x61')]==0x1){_0x470c56[_0xe5d4('0x62')]('`'+_0x28d0ad[_0xe5d4('0x4a')]+_0xe5d4('0x63'));}else{_0x470c56[_0xe5d4('0x62')]('`'+_0x28d0ad[_0xe5d4('0x4a')]+_0xe5d4('0x64'));}break;case _0xe5d4('0x65'):if(_0x28d0ad[_0xe5d4('0x66')]===_0xe5d4('0x67')){if(_0x28d0ad['value'][_0xe5d4('0x2e')]('\x20')[_0xe5d4('0x45')]>0x1){_0x110f49[_0x53bf73](_0xe5d4('0x68'),qs[_0xe5d4('0x69')](_0x28d0ad[_0xe5d4('0x61')]),null);}else{var _0x186546='%'+_0x28d0ad[_0xe5d4('0x61')]+'%';_0x110f49[_0x53bf73](_0xe5d4('0x6a'),_0x186546,_0x186546,_0x186546);}}else{_0x5b0dba=_['find'](_0x4f2531,[_0xe5d4('0x29'),'ContactId']);_0x28d0ad[_0xe5d4('0x4a')]=_0xe5d4('0x6b');_0x3d7877=as[_0xe5d4('0x6c')](_0x52365e,_0x5b0dba[_0xe5d4('0x3b')],_0x28d0ad);_0x110f49[_0x53bf73](_0x3d7877[_0xe5d4('0x6d')],_0x3d7877[_0xe5d4('0x61')][_0xe5d4('0x6e')],_0x3d7877['value'][_0xe5d4('0x1e')]);}break;case _0xe5d4('0x6f'):var _0x366c58=_0x28d0ad[_0xe5d4('0x61')][_0xe5d4('0x2e')](',')[_0xe5d4('0x3e')](function(_0x5200ae){return Number(_0x5200ae);});_0x366c58[_0xe5d4('0x70')](function(_0x1337e4){_0x5b5a02['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x1337e4+',%');});_0x50999e=_[_0xe5d4('0x71')](_0x50999e,_0x366c58);break;case _0xe5d4('0x72'):if(_0x28d0ad[_0xe5d4('0x66')]===_0xe5d4('0x67')){_0x110f49[_0x53bf73](_0xe5d4('0x73'),'%'+_0x28d0ad[_0xe5d4('0x61')]+'%',null);}else{_0x5b0dba=_['find'](_0x4f2531,[_0xe5d4('0x29'),_0xe5d4('0x35')]);_0x28d0ad[_0xe5d4('0x4a')]='UserId';_0x3d7877=as['buildExpression'](_0x52365e,_0x5b0dba[_0xe5d4('0x3b')],_0x28d0ad);_0x110f49[_0x53bf73](_0x3d7877['text'],_0x3d7877[_0xe5d4('0x61')]['start'],_0x3d7877[_0xe5d4('0x61')][_0xe5d4('0x1e')]);}break;case _0xe5d4('0x74'):_0x3d7877=as[_0xe5d4('0x6c')]('me',null,_0x28d0ad);_0x110f49[_0x53bf73](_0x3d7877[_0xe5d4('0x6d')],_0x3d7877[_0xe5d4('0x61')]['start'],_0x3d7877[_0xe5d4('0x61')][_0xe5d4('0x1e')]);break;}}else{var _0x3d7877=as[_0xe5d4('0x6c')](_0x52365e,_0x5b0dba['type'],_0x28d0ad);_0x110f49[_0x53bf73](_0x3d7877['text'],_0x3d7877[_0xe5d4('0x61')][_0xe5d4('0x6e')],_0x3d7877[_0xe5d4('0x61')][_0xe5d4('0x1e')]);}}}else{var _0x2e74c3=_(_0x39e17b['query'])[_0xe5d4('0x40')]()[_0xe5d4('0x3e')](function(_0x3f3241){return _[_0xe5d4('0x75')](_0x4f2531,[_0xe5d4('0x29'),_0x3f3241])?_0x3f3241:undefined;})[_0xe5d4('0x76')]()[_0xe5d4('0x61')]();if(!_[_0xe5d4('0x77')](_0x2e74c3)){_0x2e74c3['forEach'](function(_0x20399d){if(_0x20399d==='WhatsappAccountId'){_0x470c56[_0xe5d4('0x49')]('i.WhatsappAccountId\x20IN\x20?',[][_0xe5d4('0x78')](_0x39e17b[_0xe5d4('0x3f')][_0x20399d]));}else if(_0x20399d===_0xe5d4('0x79')){var _0x40f8db=JSON[_0xe5d4('0x7a')](_0x39e17b[_0xe5d4('0x3f')][_0x20399d])[_0xe5d4('0x7b')];var _0x299121=JSON['parse'](_0x39e17b[_0xe5d4('0x3f')][_0x20399d])[_0xe5d4('0x7c')];_0x470c56[_0xe5d4('0x49')](_0xe5d4('0x7d'),_0x40f8db,_0x299121);}else{if(_0x39e17b[_0xe5d4('0x3f')][_0x20399d]===_0xe5d4('0x7e')){_0x470c56[_0xe5d4('0x49')]('i.'+_0x20399d+_0xe5d4('0x7f'));}else{_0x470c56['where']('i.'+_0x20399d+_0xe5d4('0x80'),_0x39e17b['query'][_0x20399d]);}}});}if(_0x39e17b[_0xe5d4('0x3f')][_0xe5d4('0x81')]){if(_0x39e17b[_0xe5d4('0x3f')][_0xe5d4('0x81')]==0x1){_0x470c56[_0xe5d4('0x62')](_0xe5d4('0x82'));}else{_0x470c56['having'](_0xe5d4('0x83'));}}if(_0x39e17b[_0xe5d4('0x3f')][_0xe5d4('0x84')]){_0x50999e=_[_0xe5d4('0x85')](_0x39e17b[_0xe5d4('0x3f')][_0xe5d4('0x84')])?_0x39e17b[_0xe5d4('0x3f')][_0xe5d4('0x84')]:new Array(_0x39e17b[_0xe5d4('0x3f')][_0xe5d4('0x84')]);_0x50999e[_0xe5d4('0x70')](function(_0x4288f8){_0x5b5a02['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x4288f8+',%');});}if(_0x39e17b[_0xe5d4('0x3f')][_0xe5d4('0x86')]){var _0x1c25a0=_0x39e17b[_0xe5d4('0x3f')]['filter'][_0xe5d4('0x87')]('\x5c','\x5c\x5c')[_0xe5d4('0x87')](/'/g,'\x27\x27');if(qs[_0xe5d4('0x88')](_0x1c25a0)){_0x110f49['or'](_0xe5d4('0x89'),_0x1c25a0+'%')['or']('i.phone\x20LIKE\x20?',_0x1c25a0+'%');}else{_0x110f49['or'](_0xe5d4('0x8a'),qs[_0xe5d4('0x69')](_0x1c25a0))['or'](_0xe5d4('0x8b'),_0x1c25a0+'%');}}}_0x470c56[_0xe5d4('0x49')](_0x110f49);_0x470c56[_0xe5d4('0x8c')](_0xe5d4('0x8d'));var _0xe931d={'type':db[_0xe5d4('0x8e')][_0xe5d4('0x8f')][_0xe5d4('0x90')],'raw':!![]};var _0x46907a=_0x470c56[_0xe5d4('0x91')]();_0x46907a[_0xe5d4('0x4a')](_0xe5d4('0x8d'));_0x46907a[_0xe5d4('0x4a')](_0xe5d4('0x92'),'unreadMessages');if(_0x2c1445[_0xe5d4('0x93')]){_0x2c1445[_0xe5d4('0x93')][_0xe5d4('0x70')](function(_0x230b3d){var _0x486be1=_0x230b3d[0x0]===_0xe5d4('0x94')?_0x230b3d[0x0]:'i.'+_0x230b3d[0x0];_0x470c56[_0xe5d4('0x93')](_0x486be1,_0x230b3d[0x1]===_0xe5d4('0x95')?![]:!![]);});}if(!_[_0xe5d4('0x77')](_0x50999e)){_0x470c56[_0xe5d4('0x62')](_0x5b5a02);_0x46907a['where'](_0xe5d4('0x96'),_0x50999e);}BPromise[_0xe5d4('0x97')]()[_0xe5d4('0x27')](function(){if(!_0x5eede3){if(_0x39e17b['query'][_0xe5d4('0x98')])return;_0x46907a[_0xe5d4('0x49')]('i.WhatsappAccountId\x20IS\x20NOT\x20NULL');_0x470c56['where']('i.WhatsappAccountId\x20IS\x20NOT\x20NULL');return;}if(_0x39e17b[_0xe5d4('0x99')]['role']!==_0xe5d4('0x9a'))return;return _0x39e17b[_0xe5d4('0x99')][_0xe5d4('0x9b')]({'attributes':['id'],'raw':!![]})[_0xe5d4('0x27')](function(_0x55c437){if(_[_0xe5d4('0x77')](_0x55c437)){_0x46907a[_0xe5d4('0x49')](_0xe5d4('0x9c'));_0x470c56[_0xe5d4('0x49')](_0xe5d4('0x9c'));}else{_0x46907a['where'](_0xe5d4('0x9d'),_[_0xe5d4('0x3e')](_0x55c437,'id'));_0x470c56[_0xe5d4('0x49')](_0xe5d4('0x9d'),_[_0xe5d4('0x3e')](_0x55c437,'id'));}});})[_0xe5d4('0x27')](function(){if(_0x39e17b['user'][_0xe5d4('0x9e')]==='agent'&&!_0x5eede3&&!_0x39e17b['query'][_0xe5d4('0x98')])return[];return db[_0xe5d4('0x9f')][_0xe5d4('0x3f')](_0x46907a['toString'](),_0xe931d);})[_0xe5d4('0x27')](function(_0x4f37b5){_0x1f9de9[_0xe5d4('0x23')]=_0x4f37b5[_0xe5d4('0x45')];if(_0x1f9de9['count']===0x0)return[];return db['sequelize'][_0xe5d4('0x3f')](_0x50e9ec[_0xe5d4('0xa0')](),_0xe931d)[_0xe5d4('0x27')](function(_0x3cbf64){_0x2df9ac=_[_0xe5d4('0xa1')](_0x3cbf64,'id');_0xe931d=_[_0xe5d4('0xa2')](_0xe931d,{'model':db[_0xe5d4('0x38')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x39e17b[_0xe5d4('0x3f')][_0xe5d4('0x44')]){_0x2c1445['attributes'][_0xe5d4('0x70')](function(_0x317c57){_0x470c56[_0xe5d4('0x4a')]('i.'+_0x317c57);});}else{_0x470c56[_0xe5d4('0x4a')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xe5d4('0x60'));_0x470c56[_0xe5d4('0x4a')](_0xe5d4('0xa3'),_0xe5d4('0xa4'));_0x470c56[_0xe5d4('0x4a')](_0xe5d4('0xa5'),_0xe5d4('0xa6'));_0x470c56[_0xe5d4('0x4a')](_0xe5d4('0xa7'),_0xe5d4('0x94'));_0x470c56[_0xe5d4('0x4a')](_0xe5d4('0xa8'));_0x470c56[_0xe5d4('0x4a')](_0xe5d4('0xa9'),_0xe5d4('0xaa'));_0x470c56['field']('c.lastName',_0xe5d4('0xab'));_0x470c56['field'](_0xe5d4('0xac'),_0xe5d4('0xad'));_0x470c56['field']('c.phone',_0xe5d4('0xae'));_0x470c56[_0xe5d4('0x4a')](_0xe5d4('0xaf'),_0xe5d4('0xb0'));_0x470c56[_0xe5d4('0x4a')](_0xe5d4('0xb1'),_0xe5d4('0xb2'));_0x470c56[_0xe5d4('0x4a')](_0xe5d4('0xb3'),'Owner.fullname');_0x470c56[_0xe5d4('0x4a')](_0xe5d4('0xb4'),_0xe5d4('0xb5'));_0x470c56[_0xe5d4('0x4a')]('GROUP_CONCAT(DISTINCT\x20t.id)','TagIds');}if(_0x2c1445[_0xe5d4('0x22')])_0x470c56[_0xe5d4('0x22')](_0x2c1445[_0xe5d4('0x22')]);if(_0x2c1445[_0xe5d4('0x20')])_0x470c56[_0xe5d4('0x20')](_0x2c1445[_0xe5d4('0x20')]);return db[_0xe5d4('0x9f')]['query'](_0x470c56[_0xe5d4('0xa0')](),_0xe931d);})[_0xe5d4('0x27')](function(_0x1fc8d9){if(_0x1fc8d9[_0xe5d4('0x45')]>0x0)_0x1fe8fc[_0xe5d4('0x49')](_0xe5d4('0xb6'),_[_0xe5d4('0x3e')](_0x1fc8d9,'id'));return db[_0xe5d4('0x9f')][_0xe5d4('0x3f')](_0x1fe8fc[_0xe5d4('0xa0')](),_0xe931d)[_0xe5d4('0x27')](function(_0x365f2f){var _0x1f742e=_['groupBy'](_0x365f2f,_0xe5d4('0xb7'));var _0x1ba7fb=[];_0x1fc8d9['forEach'](function(_0x3a5cd9){_0x1ba7fb[_0xe5d4('0xb8')](updateWhatsappInteraction(_0x3a5cd9,_0x2df9ac,_0x1f742e));});return BPromise[_0xe5d4('0xb9')](_0x1ba7fb);});});})['then'](function(_0x34b777){_0x1f9de9[_0xe5d4('0xba')]=_0x34b777;return _0x1f9de9;})[_0xe5d4('0x27')](respondWithFilteredResult(_0x1a4123,_0x2c1445))['catch'](handleError(_0x1a4123,null));};exports[_0xe5d4('0xbb')]=function(_0x227693,_0x35f8c1){var _0x4965c9={'raw':![],'where':{'id':_0x227693[_0xe5d4('0xbc')]['id']}},_0x1f9ada={};_0x1f9ada[_0xe5d4('0x3d')]=_['keys'](db[_0xe5d4('0x38')]['rawAttributes']);_0x1f9ada['query']=_[_0xe5d4('0x40')](_0x227693[_0xe5d4('0x3f')]);_0x1f9ada['filters']=_[_0xe5d4('0x43')](_0x1f9ada['model'],_0x1f9ada[_0xe5d4('0x3f')]);_0x4965c9[_0xe5d4('0x42')]=_[_0xe5d4('0x43')](_0x1f9ada[_0xe5d4('0x3d')],qs[_0xe5d4('0x44')](_0x227693[_0xe5d4('0x3f')][_0xe5d4('0x44')]));_0x4965c9[_0xe5d4('0x42')]=_0x4965c9[_0xe5d4('0x42')][_0xe5d4('0x45')]?_0x4965c9[_0xe5d4('0x42')]:_0x1f9ada[_0xe5d4('0x3d')];if(_0x227693[_0xe5d4('0x3f')][_0xe5d4('0xbd')]){_0x4965c9['include']=[{'all':!![]}];}_0x4965c9=_[_0xe5d4('0xa2')]({},_0x4965c9,_0x227693['options']);return db['WhatsappInteraction']['find'](_0x4965c9)['then'](handleEntityNotFound(_0x35f8c1,null))[_0xe5d4('0x27')](respondWithResult(_0x35f8c1,null))[_0xe5d4('0x2f')](handleError(_0x35f8c1,null));};exports[_0xe5d4('0xbe')]=function(_0x391d75,_0x38e9c8){return db['WhatsappInteraction'][_0xe5d4('0xbe')](_0x391d75[_0xe5d4('0x74')],{})[_0xe5d4('0x27')](respondWithResult(_0x38e9c8,0xc9))[_0xe5d4('0x2f')](handleError(_0x38e9c8,null));};exports[_0xe5d4('0x26')]=function(_0x19895a,_0x266037){if(_0x19895a[_0xe5d4('0x74')]['id']){delete _0x19895a[_0xe5d4('0x74')]['id'];}return db[_0xe5d4('0x38')][_0xe5d4('0x5f')]({'where':{'id':_0x19895a[_0xe5d4('0xbc')]['id']}})['then'](handleEntityNotFound(_0x266037,null))[_0xe5d4('0x27')](saveUpdates(_0x19895a[_0xe5d4('0x74')],null))[_0xe5d4('0x27')](respondWithResult(_0x266037,null))[_0xe5d4('0x2f')](handleError(_0x266037,null));};exports[_0xe5d4('0xbf')]=function(_0x40464c,_0x2dd103){return db['WhatsappInteraction'][_0xe5d4('0x5f')]({'where':{'id':_0x40464c['params']['id']}})[_0xe5d4('0x27')](handleEntityNotFound(_0x2dd103,null))[_0xe5d4('0x27')](removeEntity(_0x2dd103,null))[_0xe5d4('0x2f')](handleError(_0x2dd103,null));};exports[_0xe5d4('0xc0')]=function(_0x5ace69,_0x2c1349){return db[_0xe5d4('0x38')][_0xe5d4('0xc0')]()[_0xe5d4('0x27')](respondWithResult(_0x2c1349,null))[_0xe5d4('0x2f')](handleError(_0x2c1349,null));};exports[_0xe5d4('0xc1')]=function(_0x4ed3c5,_0x470a15,_0x1e9175){return db[_0xe5d4('0xc2')]['find']({'where':{'id':_0x4ed3c5['params']['id']}})[_0xe5d4('0x27')](handleEntityNotFound(_0x470a15,null))[_0xe5d4('0x27')](function(_0x2795bf){if(_0x2795bf){return _0x2795bf[_0xe5d4('0xc1')](_0x4ed3c5[_0xe5d4('0x74')][_0xe5d4('0xc3')],_['omit'](_0x4ed3c5[_0xe5d4('0x74')],[_0xe5d4('0xc3'),'id'])||{});}})['then'](respondWithResult(_0x470a15,null))['catch'](handleError(_0x470a15,null));};exports['getMessages']=function(_0x376e7,_0xe8792f,_0x52161c){var _0x2ab5b3={'raw':![],'where':{}};var _0x56afa0={};var _0x148756={'count':0x0,'rows':[]};return db[_0xe5d4('0x38')][_0xe5d4('0xc4')]({'where':{'id':_0x376e7['params']['id']}})[_0xe5d4('0x27')](handleEntityNotFound(_0xe8792f,null))['then'](function(_0x165edc){if(_0x165edc){_0x56afa0[_0xe5d4('0x3d')]=_[_0xe5d4('0x40')](db[_0xe5d4('0xc2')][_0xe5d4('0x39')]);_0x56afa0[_0xe5d4('0x3f')]=_[_0xe5d4('0x40')](_0x376e7[_0xe5d4('0x3f')]);_0x56afa0[_0xe5d4('0x41')]=_[_0xe5d4('0x43')](_0x56afa0[_0xe5d4('0x3d')],_0x56afa0[_0xe5d4('0x3f')]);_0x2ab5b3['attributes']=_[_0xe5d4('0x43')](_0x56afa0[_0xe5d4('0x3d')],qs[_0xe5d4('0x44')](_0x376e7[_0xe5d4('0x3f')][_0xe5d4('0x44')]));_0x2ab5b3[_0xe5d4('0x42')]=_0x2ab5b3[_0xe5d4('0x42')][_0xe5d4('0x45')]?_0x2ab5b3['attributes']:_0x56afa0[_0xe5d4('0x3d')];if(!_0x376e7[_0xe5d4('0x3f')][_0xe5d4('0x46')](_0xe5d4('0x47'))){_0x2ab5b3[_0xe5d4('0x22')]=qs[_0xe5d4('0x22')](_0x376e7[_0xe5d4('0x3f')][_0xe5d4('0x22')]);_0x2ab5b3['offset']=qs['offset'](_0x376e7[_0xe5d4('0x3f')][_0xe5d4('0x20')]);}_0x2ab5b3[_0xe5d4('0x93')]=qs[_0xe5d4('0x48')](_0x376e7[_0xe5d4('0x3f')][_0xe5d4('0x48')]);_0x2ab5b3[_0xe5d4('0x49')]=qs[_0xe5d4('0x41')](_[_0xe5d4('0xc5')](_0x376e7['query'],_0x56afa0[_0xe5d4('0x41')]));_0x2ab5b3[_0xe5d4('0x49')][_0xe5d4('0xb7')]=_0x165edc['id'];if(_0x376e7[_0xe5d4('0x3f')][_0xe5d4('0x86')]){_0x2ab5b3[_0xe5d4('0x49')]=_[_0xe5d4('0xa2')](_0x2ab5b3['where'],{'$or':_[_0xe5d4('0x3e')](_0x2ab5b3[_0xe5d4('0x42')],function(_0x17f160){var _0x179be3={};_0x179be3[_0x17f160]={'$like':'%'+_0x376e7['query'][_0xe5d4('0x86')]+'%'};return _0x179be3;})});}if(_0x376e7[_0xe5d4('0x3f')][_0xe5d4('0x7b')]){var _0x52964f=_0x376e7['query'][_0xe5d4('0x7b')][_0xe5d4('0x2e')](',');var _0xa22f5e={};_0xa22f5e[_0x52964f[0x0]]={'$gte':moment(_0x52964f[0x1])[_0xe5d4('0xc6')](_0xe5d4('0xc7'))};_0x2ab5b3[_0xe5d4('0x49')]=_['merge'](_0x2ab5b3['where'],_0xa22f5e);}_0x2ab5b3=_[_0xe5d4('0xa2')]({},_0x2ab5b3,_0x376e7['options']);return db['WhatsappMessage'][_0xe5d4('0x23')]({'where':_0x2ab5b3['where']})['then'](function(_0x3c484a){_0x148756['count']=_0x3c484a;if(_0x376e7['query'][_0xe5d4('0xbd')]){_0x2ab5b3[_0xe5d4('0xc8')]=[{'all':!![]}];}return db[_0xe5d4('0xc2')]['findAll'](_0x2ab5b3);})[_0xe5d4('0x27')](function(_0x56d325){_0x148756[_0xe5d4('0xba')]=_0x56d325;return _0x148756;});}})[_0xe5d4('0x27')](respondWithFilteredResult(_0xe8792f,_0x2ab5b3))[_0xe5d4('0x2f')](handleError(_0xe8792f,null));};exports[_0xe5d4('0xc9')]=function(_0x1e8b66,_0xa338da,_0xb8bbee){return db[_0xe5d4('0x38')][_0xe5d4('0x5f')]({'where':{'id':_0x1e8b66[_0xe5d4('0xbc')]['id']}})[_0xe5d4('0x27')](handleEntityNotFound(_0xa338da,null))['then'](function(_0x54a593){if(_0x54a593){return _0x54a593['setTags'](_0x1e8b66[_0xe5d4('0x74')][_0xe5d4('0xc3')],_[_0xe5d4('0xca')](_0x1e8b66['body'],[_0xe5d4('0xc3'),'id'])||{})['spread'](function(){return db[_0xe5d4('0x6f')][_0xe5d4('0xcb')]({'attributes':['id','name',_0xe5d4('0x4b')],'where':{'id':_0x1e8b66[_0xe5d4('0x74')]['ids']}});})[_0xe5d4('0x27')](function(_0x5e2ea0){socket['emit']('whatsappInteractionTags:save',{'id':Number(_0x1e8b66[_0xe5d4('0xbc')]['id']),'tags':_0x5e2ea0||[]});return{'id':Number(_0x1e8b66[_0xe5d4('0xbc')]['id']),'tags':_0x5e2ea0||[]};});}})[_0xe5d4('0x27')](respondWithResult(_0xa338da,null))[_0xe5d4('0x2f')](handleError(_0xa338da,null));};exports['removeTags']=function(_0xb6ceb7,_0x6f13d1,_0x53ebe5){return db[_0xe5d4('0x38')][_0xe5d4('0x5f')]({'where':{'id':_0xb6ceb7['params']['id']}})[_0xe5d4('0x27')](handleEntityNotFound(_0x6f13d1,null))['then'](function(_0x493757){if(_0x493757){return _0x493757['removeTags'](_0xb6ceb7['query'][_0xe5d4('0xc3')]);}})['then'](respondWithStatusCode(_0x6f13d1,null))[_0xe5d4('0x2f')](handleError(_0x6f13d1,null));};exports[_0xe5d4('0xcc')]=function(_0x37bc25,_0x418256){var _0x3c3b09=moment()['unix']()['toString']();var _0x51c93f=path[_0xe5d4('0xcd')](config[_0xe5d4('0xce')],_0xe5d4('0xcf'),_0xe5d4('0xd0'),_0xe5d4('0xd1'));var _0x1b43e2=path[_0xe5d4('0xcd')](config['root'],_0xe5d4('0xcf'),_0xe5d4('0xd0'),_0xe5d4('0xd2'));var _0x31c6d2=path[_0xe5d4('0xcd')](_0x51c93f,_0x3c3b09);var _0x1c4380=util[_0xe5d4('0xc6')](_0xe5d4('0xd3'),_0x37bc25[_0xe5d4('0xbc')]['id'],_0x3c3b09);var _0x383c12=path[_0xe5d4('0xcd')](_0x51c93f,_0x1c4380);var _0x215011=[];_0x215011[_0xe5d4('0xb8')]({'model':db[_0xe5d4('0x72')],'as':_0xe5d4('0x72'),'attributes':['id',_0xe5d4('0xd4')],'raw':!![]});_0x215011['push']({'model':db[_0xe5d4('0xd5')],'as':'Contact','attributes':['id','firstName','lastName'],'raw':!![]});if(_0x37bc25[_0xe5d4('0x3f')][_0xe5d4('0xd2')]){_0x215011['push']({'model':db['Attachment'],'as':'Attachment','raw':!![]});}var _0x57bc1a=[{'model':db['WhatsappMessage'],'as':_0xe5d4('0xd6'),'attributes':['id',_0xe5d4('0x74'),_0xe5d4('0x79'),_0xe5d4('0xd7'),_0xe5d4('0xd8'),_0xe5d4('0x81')],'include':_0x215011}];_0x57bc1a[_0xe5d4('0xb8')]({'model':db[_0xe5d4('0xd9')],'as':_0xe5d4('0xda'),'attributes':['id',_0xe5d4('0x29')]});_0x57bc1a[_0xe5d4('0xb8')]({'model':db[_0xe5d4('0x72')],'as':_0xe5d4('0xdb'),'attributes':['id',_0xe5d4('0xd4')]});return db[_0xe5d4('0x38')][_0xe5d4('0x5f')]({'where':{'id':_0x37bc25[_0xe5d4('0xbc')]['id']},'include':_0x57bc1a})['then'](handleEntityNotFound(_0x418256,null))['then'](function(_0x30c3fb){if(_0x30c3fb){var _0x54a804=_0x30c3fb[_0xe5d4('0xdc')]({'plain':!![]});fs[_0xe5d4('0xdd')](_0x31c6d2);var _0x5285a3={'channel':_0xe5d4('0xde'),'account':_0x54a804[_0xe5d4('0xda')]['name'],'agent':_0x54a804[_0xe5d4('0xdb')]?_0x54a804[_0xe5d4('0xdb')]['fullname']:_0xe5d4('0xdf'),'createdAt':moment(_0x54a804['createdAt'])[_0xe5d4('0xc6')](_0xe5d4('0xc7'))[_0xe5d4('0xa0')](),'closedAt':_0x54a804[_0xe5d4('0x34')]?moment(_0x54a804[_0xe5d4('0xe0')])[_0xe5d4('0xc6')]('YYYY-MM-DD\x20HH:mm:ss')['toString']():'','disposition':_0x54a804[_0xe5d4('0xe1')],'messages':_(_0x54a804[_0xe5d4('0xd6')])[_0xe5d4('0x86')]({'secret':![]})[_0xe5d4('0x3e')](function(_0x156956){if(_0x156956[_0xe5d4('0xe2')]){var _0x5813f8=path[_0xe5d4('0xcd')](_0x1b43e2,_0x156956[_0xe5d4('0xe2')]['basename']);if(fs[_0xe5d4('0xe3')](_0x5813f8)){fs[_0xe5d4('0xe4')](_0x5813f8)['pipe'](fs[_0xe5d4('0xe5')](path['join'](_0x31c6d2,_0x156956[_0xe5d4('0xe2')][_0xe5d4('0xe6')])));}}return{'date':moment(_0x156956[_0xe5d4('0x79')])[_0xe5d4('0xc6')](_0xe5d4('0xc7'))['toString'](),'sender':_0x156956[_0xe5d4('0xd7')]===_0xe5d4('0xe7')?_0x156956['User']?_0x156956[_0xe5d4('0x72')][_0xe5d4('0xd4')]:_0xe5d4('0xe8'):_0x156956['Contact']['firstName']+(_0x156956[_0xe5d4('0x65')][_0xe5d4('0xe9')]?'\x20'+_0x156956['Contact'][_0xe5d4('0xe9')]:''),'body':_0x156956[_0xe5d4('0xe2')]?_0x156956[_0xe5d4('0xe2')][_0xe5d4('0xe6')]:_0x156956[_0xe5d4('0x74')],'direction':_0x156956[_0xe5d4('0xd7')]===_0xe5d4('0xe7')?'A':'C','secret':_0x156956[_0xe5d4('0xd8')],'read':_0x156956[_0xe5d4('0x81')],'attachment':_0x156956[_0xe5d4('0xe2')]};})[_0xe5d4('0x61')]()};return ejs[_0xe5d4('0xea')](path[_0xe5d4('0xcd')](config['root'],_0xe5d4('0xcf'),_0xe5d4('0xeb'),_0xe5d4('0xec')),{'interaction':_0x5285a3})['then'](function(_0x3ff451){var _0x43581d=path['join'](_0x31c6d2,_0xe5d4('0xed')+_0x54a804['id']+'-'+_0x3c3b09+_0xe5d4('0xee'));var _0xdd31d8={'path':_0x43581d,'channel':_0xe5d4('0xde'),'interactionId':_0x54a804['id']};return pdf['createPdfFromHTML'](_0x3ff451,_0xdd31d8);})['then'](function(){return new BPromise(function(_0x3c3686,_0x3f3f0a){zipdir(_0x31c6d2,{'saveTo':_0x383c12},function(_0x5544bb,_0x2f510c){if(_0x5544bb)return _0x3f3f0a(_0x5544bb);return _0x3c3686(_0x2f510c);});})['then'](function(){return new BPromise(function(_0x234476,_0x3f3cab){rimraf(_0x31c6d2,function(_0x48b244){if(_0x48b244)_0x3f3cab(_0x48b244);return _0x234476();});});})[_0xe5d4('0x27')](function(){return _0x418256['download'](_0x383c12,_0x1c4380,function(_0x534c11){if(_0x534c11){console['log']('err',_0x534c11);}else{fs[_0xe5d4('0xef')](_0x383c12);}});});});}else{return _0x418256[_0xe5d4('0x1c')](0xc8);}})[_0xe5d4('0x2f')](handleError(_0x418256,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