diff --git a/packages/bot/core/core.class.js b/packages/bot/core/core.class.js index 1d18665d8..f79a7ec9a 100644 --- a/packages/bot/core/core.class.js +++ b/packages/bot/core/core.class.js @@ -571,6 +571,11 @@ class CoreClass extends EventEmitter { if (LIST_REGEX.REGEX_EVENT_TEMPLATE.test(body)) { msgToSend = this.flowClass.find(this.generalArgs.listEvents.TEMPLATE) || [] } + + //todo agregar evento para detectar un vcard + if (LIST_REGEX.REGEX_EVENT_CONTACT.test(body)) { + msgToSend = this.flowClass.find(this.generalArgs.listEvents.CONTACT) || [] + } } return exportFunctionsSend(() => sendFlow(msgToSend, from, { forceQueue: true })) diff --git a/packages/bot/io/events/eventContact.js b/packages/bot/io/events/eventContact.js new file mode 100644 index 000000000..aa1e81af9 --- /dev/null +++ b/packages/bot/io/events/eventContact.js @@ -0,0 +1,9 @@ +const { generateRef } = require('../../utils/hash') + +const eventContact = () => { + return generateRef('_event_contact_') +} + +const REGEX_EVENT_CONTACT = /^_event_contact__[\w\d]{8}-(?:[\w\d]{4}-){3}[\w\d]{12}$/ + +module.exports = { eventContact, REGEX_EVENT_CONTACT } diff --git a/packages/bot/io/events/index.js b/packages/bot/io/events/index.js index d6a0e8219..609672a0a 100644 --- a/packages/bot/io/events/index.js +++ b/packages/bot/io/events/index.js @@ -4,6 +4,7 @@ const { eventMedia, REGEX_EVENT_MEDIA } = require('./eventMedia') const { eventVoiceNote, REGEX_EVENT_VOICE_NOTE } = require('./eventVoiceNote') const { eventOrder, REGEX_EVENT_ORDER } = require('./eventOrder') const { eventTemplate, REGEX_EVENT_TEMPLATE } = require('./eventTemplate') +const { eventContact, REGEX_EVENT_CONTACT } = require('./eventContact') const { eventWelcome } = require('./eventWelcome') const { eventAction } = require('./eventAction') @@ -16,6 +17,7 @@ const LIST_ALL = { ACTION: eventAction(), ORDER: eventOrder(), TEMPLATE: eventTemplate(), + CONTACT: eventContact(), } const LIST_REGEX = { @@ -25,6 +27,7 @@ const LIST_REGEX = { REGEX_EVENT_VOICE_NOTE, REGEX_EVENT_ORDER, REGEX_EVENT_TEMPLATE, + REGEX_EVENT_CONTACT, } module.exports = { LIST_ALL, LIST_REGEX } diff --git a/packages/provider/src/baileys/index.js b/packages/provider/src/baileys/index.js index 94029b5a2..b9973e83d 100644 --- a/packages/provider/src/baileys/index.js +++ b/packages/provider/src/baileys/index.js @@ -38,6 +38,7 @@ class BaileysProvider extends ProviderClass { gifPlayback: false, usePairingCode: false, phoneNumber: null, + enabledCalls: false, useBaileysStore: true, } vendor @@ -108,6 +109,39 @@ class BaileysProvider extends ProviderClass { ]) } } + //TODO PERMITE RECHAZAR LLAMADAS - SE GATILLA CUANDO EL BOT RECIBE UNA LLAMADA + sock.ev.on('call', async (callEvent) => { + // Verificar si la funcionalidad está activada + if (!this.globalVendorArgs.enabledCalls) return + + const [callData] = callEvent + const { from, id, status } = callData + + if (status !== 'offer') return + const instance = { + tag: 'call', + attrs: { + from: sock.user.id, + to: from, + id: sock.generateMessageTag(), + }, + content: [ + { + tag: 'reject', + attrs: { + 'call-id': id, + 'call-creator': from, + count: '0', + }, + content: undefined, + }, + ], + } + await sock.query(instance); + if (callEvent[0].status == 'offer') { + return this.vendor.sendMessage(callEvent[0].from, {text:"¿Me estás llamando? Sólo recuerda, ¡Soy un robot!"}) + } + }) sock.ev.on('connection.update', async (update) => { const { connection, lastDisconnect, qr } = update