Skip to content

Commit

Permalink
fix: add call event
Browse files Browse the repository at this point in the history
  • Loading branch information
leifermendez committed Dec 11, 2024
1 parent 7255974 commit 7bce807
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
4 changes: 4 additions & 0 deletions packages/bot/src/core/coreClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,10 @@ class CoreClass<P extends ProviderClass = any, D extends MemoryDB = any> extends
if (LIST_REGEX.REGEX_EVENT_TEMPLATE.test(body)) {
msgToSend = this.flowClass.find(this.generalArgs.listEvents.TEMPLATE) || []
}

if (LIST_REGEX.REGEX_EVENT_CALL.test(body)) {
msgToSend = this.flowClass.find(this.generalArgs.listEvents.CALL) || []
}
}

return exportFunctionsSend(() => sendFlow(msgToSend, from, { forceQueue: true }))
Expand Down
9 changes: 9 additions & 0 deletions packages/bot/src/io/events/eventCall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { generateRef, generateRegex } from '../../utils/hash'

const eventCall = (): string => {
return generateRef('_event_call_')
}

const REGEX_EVENT_CALL = generateRegex(`_event_call`)

export { eventCall, REGEX_EVENT_CALL }
3 changes: 3 additions & 0 deletions packages/bot/src/io/events/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { eventAction } from './eventAction'
import { eventCall, REGEX_EVENT_CALL } from './eventCall'
import { REGEX_EVENT_CUSTOM } from './eventCustom'
import { eventDocument, REGEX_EVENT_DOCUMENT } from './eventDocument'
import { eventLocation, REGEX_EVENT_LOCATION } from './eventLocation'
Expand All @@ -21,6 +22,7 @@ const LIST_ALL = {
ACTION: eventAction(),
ORDER: eventOrder(),
TEMPLATE: eventTemplate(),
CALL: eventCall(),
}

const LIST_REGEX: EventFunctionRegex = {
Expand All @@ -31,6 +33,7 @@ const LIST_REGEX: EventFunctionRegex = {
REGEX_EVENT_ORDER,
REGEX_EVENT_TEMPLATE,
REGEX_EVENT_CUSTOM,
REGEX_EVENT_CALL,
}

export { LIST_ALL, LIST_REGEX }
4 changes: 2 additions & 2 deletions packages/provider-baileys/__tests__/baileysProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { IStickerOptions } from 'wa-sticker-formatter'
import fs from 'fs'
import mime from 'mime-types'
import { utils } from '@builderbot/bot'
import { makeInMemoryStore, useMultiFileAuthState } from '@whiskeysockets/baileys'
import { makeInMemoryStore, useMultiFileAuthState } from '@builderbot/core-baileys'

const phoneNumber = '+123456789'

jest.mock('@whiskeysockets/baileys', () => ({
jest.mock('@builderbot/core-baileys', () => ({
downloadMediaMessage: jest.fn(),
proto: {
Message: {
Expand Down
17 changes: 17 additions & 0 deletions packages/provider-baileys/src/bailey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,23 @@ class BaileysProvider extends ProviderClass<WASocket> {
}
},
},
{
event: 'call',
func: async ([call]) => {
if (call.status === 'offer') {
const payload = {
from: baileyCleanNumber(call.from, true),
body: utils.generateRefProvider('_event_call_'),
call,
}
console.log(`entro llamada`)
this.emit('message', payload)

// Opcional: Rechazar automáticamente la llamada
await this.vendor.rejectCall(call.id, call.from)
}
},
},
]

/**
Expand Down
7 changes: 2 additions & 5 deletions packages/provider-telegram/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
"types": "dist/index.d.ts",
"type": "module",
"scripts": {
"build": "rimraf dist && rollup --config",
"test": "jest --forceExit",
"test:coverage": "jest --coverage",
"test:watch": "jest --watchAll --coverage"
"build": "rimraf dist && rollup --config"
},
"files": [
"./dist/"
Expand Down Expand Up @@ -48,4 +45,4 @@
"telegram": "^2.23.10"
},
"gitHead": "f21e49621dffad2a1226aecea535668016f07b14"
}
}

0 comments on commit 7bce807

Please sign in to comment.