Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/provider baileys #965

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/bot/core/core.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
Expand Down
9 changes: 9 additions & 0 deletions packages/bot/io/events/eventContact.js
Original file line number Diff line number Diff line change
@@ -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 }
3 changes: 3 additions & 0 deletions packages/bot/io/events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -16,6 +17,7 @@ const LIST_ALL = {
ACTION: eventAction(),
ORDER: eventOrder(),
TEMPLATE: eventTemplate(),
CONTACT: eventContact(),
}

const LIST_REGEX = {
Expand All @@ -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 }
38 changes: 36 additions & 2 deletions packages/provider/src/baileys/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class BaileysProvider extends ProviderClass {
gifPlayback: false,
usePairingCode: false,
phoneNumber: null,
useBaileysStore: true,
enabledCalls: false,
useBaileysStore: true
}
vendor
store
Expand Down Expand Up @@ -79,7 +80,7 @@ class BaileysProvider extends ProviderClass {
creds: state.creds,
keys: makeCacheableSignalKeyStore(state.keys, loggerBaileys),
},
browser: ['Chrome (Linux)', '', ''],
browser: [ "Ubuntu", "Chrome", "20.0.04" ],
syncFullHistory: false,
generateHighQualityLinkPreview: true,
getMessage: this.getMessage,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/provider/src/baileys/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"@whiskeysockets/baileys": "6.5.0",
"@whiskeysockets/baileys": "6.6.0",
"wa-sticker-formatter": "4.4.4",
"cache-manager": "5.2.4"
}
Expand Down