From 435b415b31d2ee840642334975c21ffecbdd9cdc Mon Sep 17 00:00:00 2001 From: gavrielc Date: Wed, 1 Apr 2026 12:39:16 +0300 Subject: [PATCH] fix: patch Baileys 6.x getPlatformId bug for pairing codes Baileys 6.x getPlatformId sends charCode (49) instead of enum value (1), causing "couldn't link device" errors during pairing. Monkey-patch the function until we migrate to Baileys 7.x where this is fixed upstream. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/channels/whatsapp.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/channels/whatsapp.ts b/src/channels/whatsapp.ts index 195424c..40c37ba 100644 --- a/src/channels/whatsapp.ts +++ b/src/channels/whatsapp.ts @@ -16,6 +16,19 @@ import type { GroupMetadata, WAMessageKey, WASocket, proto as ProtoTypes } from import { createRequire } from 'module'; const { proto } = createRequire(import.meta.url)('@whiskeysockets/baileys') as { proto: typeof ProtoTypes }; +// TODO: Migrate to Baileys 7.x and remove this monkey-patch. +// Fix Baileys 6.x bug: getPlatformId sends charCode (49) instead of enum value (1). +// Fixed in Baileys 7.x but not backported. Without this, pairing codes fail with +// "couldn't link device" because WhatsApp receives an invalid platform ID. +import * as generics from '@whiskeysockets/baileys/lib/Utils/generics.js'; +(generics as any).getPlatformId = (browser: string): string => { + const platformType = + proto.DeviceProps.PlatformType[ + browser.toUpperCase() as keyof typeof proto.DeviceProps.PlatformType + ]; + return platformType ? platformType.toString() : '1'; +}; + import { ASSISTANT_HAS_OWN_NUMBER, ASSISTANT_NAME,