fix: resolve whatsapp-web.js ESM import for Node.js v25
whatsapp-web.js lacks proper ESM named exports, causing SyntaxError on import. Switch to default import with destructuring, use InstanceType for the Client type annotation, and update test mock to provide both default and named exports.
This commit is contained in:
@@ -32,13 +32,19 @@ function createMockClient() {
|
||||
|
||||
let mockClient = createMockClient();
|
||||
|
||||
vi.mock('whatsapp-web.js', () => ({
|
||||
Client: vi.fn().mockImplementation(() => mockClient),
|
||||
LocalAuth: vi.fn().mockImplementation((opts: Record<string, unknown>) => ({
|
||||
vi.mock('whatsapp-web.js', () => {
|
||||
const Client = vi.fn().mockImplementation(() => mockClient);
|
||||
const LocalAuth = vi.fn().mockImplementation((opts: Record<string, unknown>) => ({
|
||||
type: 'local',
|
||||
...opts,
|
||||
})),
|
||||
}));
|
||||
}));
|
||||
return {
|
||||
default: { Client, LocalAuth, MessageMedia: vi.fn() },
|
||||
Client,
|
||||
LocalAuth,
|
||||
MessageMedia: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
import { WhatsAppAdapter, type WhatsAppAdapterConfig } from './adapter.js';
|
||||
import type { InboundMessage } from '../types.js';
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
* Messages are chunked at 4096 chars (same as Telegram).
|
||||
*/
|
||||
|
||||
import { Client, LocalAuth, MessageMedia } from 'whatsapp-web.js';
|
||||
import WhatsApp from 'whatsapp-web.js';
|
||||
const { Client, LocalAuth, MessageMedia } = WhatsApp;
|
||||
import type {
|
||||
Attachment,
|
||||
InboundMessage,
|
||||
@@ -57,7 +58,7 @@ export class WhatsAppAdapter implements ChannelAdapter {
|
||||
readonly name = 'whatsapp';
|
||||
|
||||
private _status: ChannelStatus = 'disconnected';
|
||||
private client: Client | null = null;
|
||||
private client: InstanceType<typeof Client> | null = null;
|
||||
private messageHandler?: (msg: InboundMessage) => void;
|
||||
private config: WhatsAppAdapterConfig;
|
||||
private botId?: string;
|
||||
|
||||
Reference in New Issue
Block a user