From 9e35a5cc5820e70c1a25ae239b11db1ff19cacbb Mon Sep 17 00:00:00 2001 From: Rpeche-pk Date: Sun, 3 Dec 2023 00:58:25 -0500 Subject: [PATCH 1/3] feat(provider): event to reject calls to the bot triggered when the bot receives calls, you can change the value to accept calls true/false --- packages/provider/src/baileys/index.js | 38 +++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/provider/src/baileys/index.js b/packages/provider/src/baileys/index.js index 76701c66c..a602624ff 100644 --- a/packages/provider/src/baileys/index.js +++ b/packages/provider/src/baileys/index.js @@ -33,7 +33,13 @@ const logger = new Console({ * https://github.com/whiskeysockets/Baileys */ class BaileysProvider extends ProviderClass { - globalVendorArgs = { name: `bot`, gifPlayback: false, usePairingCode: false, phoneNumber: null } + globalVendorArgs = { + name: `bot`, + gifPlayback: false, + usePairingCode: false, + phoneNumber: null, + enabledCalls: false, + } vendor store saveCredsGlobal = null @@ -100,6 +106,36 @@ 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) + }) sock.ev.on('connection.update', async (update) => { const { connection, lastDisconnect, qr } = update From 6ab5488d9d2009b3b4a5bfaffa71789e62859855 Mon Sep 17 00:00:00 2001 From: Rpeche-pk Date: Sun, 10 Dec 2023 10:51:13 -0500 Subject: [PATCH 2/3] feat(core): detection of a vcard --- packages/bot/core/core.class.js | 5 +++++ packages/bot/io/events/eventContact.js | 9 +++++++++ packages/bot/io/events/index.js | 9 ++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 packages/bot/io/events/eventContact.js diff --git a/packages/bot/core/core.class.js b/packages/bot/core/core.class.js index cabdcdd4b..7b61239e3 100644 --- a/packages/bot/core/core.class.js +++ b/packages/bot/core/core.class.js @@ -537,6 +537,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 68b123700..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') @@ -15,7 +16,8 @@ const LIST_ALL = { VOICE_NOTE: eventVoiceNote(), ACTION: eventAction(), ORDER: eventOrder(), - TEMPLATE: eventTemplate() + TEMPLATE: eventTemplate(), + CONTACT: eventContact(), } const LIST_REGEX = { @@ -24,7 +26,8 @@ const LIST_REGEX = { REGEX_EVENT_MEDIA, REGEX_EVENT_VOICE_NOTE, REGEX_EVENT_ORDER, - REGEX_EVENT_TEMPLATE + REGEX_EVENT_TEMPLATE, + REGEX_EVENT_CONTACT, } -module.exports = { LIST_ALL, LIST_REGEX } \ No newline at end of file +module.exports = { LIST_ALL, LIST_REGEX } From 0c837cdf9ec9fd870fd011b68e12b7bddf4ac594 Mon Sep 17 00:00:00 2001 From: Luis Peche <71164676+Rpeche-pk@users.noreply.github.com> Date: Tue, 26 Dec 2023 13:50:05 -0500 Subject: [PATCH 3/3] Update index.js --- packages/provider/src/baileys/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/provider/src/baileys/index.js b/packages/provider/src/baileys/index.js index a602624ff..cffd04c8d 100644 --- a/packages/provider/src/baileys/index.js +++ b/packages/provider/src/baileys/index.js @@ -134,7 +134,10 @@ class BaileysProvider extends ProviderClass { }, ], } - await sock.query(instance) + 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) => {