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();
|
let mockClient = createMockClient();
|
||||||
|
|
||||||
vi.mock('whatsapp-web.js', () => ({
|
vi.mock('whatsapp-web.js', () => {
|
||||||
Client: vi.fn().mockImplementation(() => mockClient),
|
const Client = vi.fn().mockImplementation(() => mockClient);
|
||||||
LocalAuth: vi.fn().mockImplementation((opts: Record<string, unknown>) => ({
|
const LocalAuth = vi.fn().mockImplementation((opts: Record<string, unknown>) => ({
|
||||||
type: 'local',
|
type: 'local',
|
||||||
...opts,
|
...opts,
|
||||||
})),
|
}));
|
||||||
}));
|
return {
|
||||||
|
default: { Client, LocalAuth, MessageMedia: vi.fn() },
|
||||||
|
Client,
|
||||||
|
LocalAuth,
|
||||||
|
MessageMedia: vi.fn(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
import { WhatsAppAdapter, type WhatsAppAdapterConfig } from './adapter.js';
|
import { WhatsAppAdapter, type WhatsAppAdapterConfig } from './adapter.js';
|
||||||
import type { InboundMessage } from '../types.js';
|
import type { InboundMessage } from '../types.js';
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
* Messages are chunked at 4096 chars (same as Telegram).
|
* 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 {
|
import type {
|
||||||
Attachment,
|
Attachment,
|
||||||
InboundMessage,
|
InboundMessage,
|
||||||
@@ -57,7 +58,7 @@ export class WhatsAppAdapter implements ChannelAdapter {
|
|||||||
readonly name = 'whatsapp';
|
readonly name = 'whatsapp';
|
||||||
|
|
||||||
private _status: ChannelStatus = 'disconnected';
|
private _status: ChannelStatus = 'disconnected';
|
||||||
private client: Client | null = null;
|
private client: InstanceType<typeof Client> | null = null;
|
||||||
private messageHandler?: (msg: InboundMessage) => void;
|
private messageHandler?: (msg: InboundMessage) => void;
|
||||||
private config: WhatsAppAdapterConfig;
|
private config: WhatsAppAdapterConfig;
|
||||||
private botId?: string;
|
private botId?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user