Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(engine): answer an unanswered Baileys call-link request with 503

Yudhi Armyndharis7a7c7f556262
diff --git a/src/engine/adapters/baileys-messaging.ts b/src/engine/adapters/baileys-messaging.ts
index eb8513c6f..d113c6771 100644
--- a/src/engine/adapters/baileys-messaging.ts
+++ b/src/engine/adapters/baileys-messaging.ts
@@ -433,11 +433,11 @@ export class BaileysMessaging {
// link is that token behind one of the library's two exported prefixes. Note the audio prefix
// WhatsApp itself uses is `/voice/`, which is also what whatsapp-web.js calls the same thing.
//
- // timeoutMs is passed so the library can retire its own pending query, and the call is ALSO
- // wrapped: baileys' query() swallows its timeout, so an unanswered request would otherwise
- // resolve to nothing and be indistinguishable from a refusal.
+ // No timeoutMs is passed: given one, baileys' query() arms its own timer before ours and rejects
+ // with a raw 408 Boom, which answers 500. Without it the library's wait resolves nothing after its
+ // own 60 s, so the wrap below is the deadline that answers, with a 503.
const token = await this.confirmed(
- this.sock().createCallLink(type, { startTime: Math.floor(startTime / 1000) }, this.queryBudgetMs),
+ this.sock().createCallLink(type, { startTime: Math.floor(startTime / 1000) }),
'the call link',
);
if (!token) {
diff --git a/src/engine/adapters/create-call-link.spec.ts b/src/engine/adapters/create-call-link.spec.ts
index 2c9ff7653..71667251e 100644
--- a/src/engine/adapters/create-call-link.spec.ts
+++ b/src/engine/adapters/create-call-link.spec.ts
@@ -63,7 +63,7 @@ describe('BaileysMessaging.createCallLink', () => {
expect(link).toBe('https://call.whatsapp.com/video/TOKEN123');
// Baileys takes the start time in SECONDS, and its own type is 'audio' | 'video'.
- expect(createCallLink).toHaveBeenCalledWith('video', { startTime: START_S }, expect.any(Number));
+ expect(createCallLink).toHaveBeenCalledWith('video', { startTime: START_S });
});
it("uses WhatsApp's /voice/ prefix for an audio link", async () => {
@@ -71,7 +71,7 @@ describe('BaileysMessaging.createCallLink', () => {
const link = await makeMessaging({ createCallLink }).createCallLink('audio', START_MS);
expect(link).toBe('https://call.whatsapp.com/voice/TOKEN456');
- expect(createCallLink).toHaveBeenCalledWith('audio', { startTime: START_S }, expect.any(Number));
+ expect(createCallLink).toHaveBeenCalledWith('audio', { startTime: START_S });
});
// The failure that would otherwise be silent: a prefix with nothing after it is a dead link that
@@ -89,6 +89,22 @@ describe('BaileysMessaging.createCallLink', () => {
EngineTransportError,
);
});
+
+ it('answers 503 when the library would time the query out on its own', async () => {
+ // Baileys' query() given a timeoutMs arms its own timer first and rejects with a raw 408 Boom,
+ // which is not an HTTP error; without one, its wait resolves nothing and the deadline answers.
+ const createCallLink = jest.fn(
+ (_type: string, _event: unknown, timeoutMs?: number) =>
+ new Promise<never>((_resolve, reject) => {
+ if (timeoutMs) {
+ setTimeout(() => reject(Object.assign(new Error('Timed Out'), { output: { statusCode: 408 } })), timeoutMs);
+ }
+ }),
+ );
+ await expect(makeMessaging({ createCallLink }, 15).createCallLink('video', START_MS)).rejects.toBeInstanceOf(
+ EngineTransportError,
+ );
+ });
});
describe('WwebjsProfile.createCallLink', () => {