Add Zalo channel adapter with webhook and send path
This commit is contained in:
@@ -25,6 +25,7 @@ describe('registerChannels', () => {
|
||||
setBlueBubblesHandler: vi.fn(),
|
||||
setLineHandler: vi.fn(),
|
||||
setFeishuHandler: vi.fn(),
|
||||
setZaloHandler: vi.fn(),
|
||||
};
|
||||
|
||||
registerChannels({
|
||||
@@ -59,6 +60,7 @@ describe('registerChannels', () => {
|
||||
setBlueBubblesHandler: vi.fn(),
|
||||
setLineHandler: vi.fn(),
|
||||
setFeishuHandler: vi.fn(),
|
||||
setZaloHandler: vi.fn(),
|
||||
};
|
||||
|
||||
registerChannels({
|
||||
@@ -106,4 +108,38 @@ describe('registerChannels', () => {
|
||||
expect(names).toContain('feishu');
|
||||
expect(gateway.setFeishuHandler).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('registers Zalo adapter when configured', () => {
|
||||
const config = configSchema.parse({
|
||||
telegram: { bot_token: 'test-token', allowed_chat_ids: [1] },
|
||||
models: { default: { provider: 'anthropic', model: 'claude-3' } },
|
||||
zalo: {
|
||||
oa_access_token: 'oa-token',
|
||||
allowed_user_ids: ['uid-1'],
|
||||
},
|
||||
});
|
||||
|
||||
const channelRegistry = new ChannelRegistry();
|
||||
const gateway = {
|
||||
setWebhookHandler: vi.fn(),
|
||||
setGmailHandler: vi.fn(),
|
||||
setTeamsHandler: vi.fn(),
|
||||
setGoogleChatHandler: vi.fn(),
|
||||
setBlueBubblesHandler: vi.fn(),
|
||||
setLineHandler: vi.fn(),
|
||||
setFeishuHandler: vi.fn(),
|
||||
setZaloHandler: vi.fn(),
|
||||
};
|
||||
|
||||
registerChannels({
|
||||
config,
|
||||
channelRegistry,
|
||||
hookEngine: new HookEngine(config.hooks),
|
||||
gateway: gateway as unknown as Parameters<typeof registerChannels>[0]['gateway'],
|
||||
});
|
||||
|
||||
const names = channelRegistry.list().map((adapter) => adapter.name);
|
||||
expect(names).toContain('zalo');
|
||||
expect(gateway.setZaloHandler).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
+15
-1
@@ -1,6 +1,6 @@
|
||||
import type { Config } from '../config/index.js';
|
||||
import type { HookEngine } from '../hooks/index.js';
|
||||
import { ChannelRegistry, TelegramAdapter, WebChatAdapter, DiscordAdapter, SlackAdapter, WhatsAppAdapter, MatrixAdapter, SignalAdapter, MattermostAdapter, TeamsAdapter, GoogleChatAdapter, BlueBubblesAdapter, LineAdapter, FeishuAdapter, PairingManager } from '../channels/index.js';
|
||||
import { ChannelRegistry, TelegramAdapter, WebChatAdapter, DiscordAdapter, SlackAdapter, WhatsAppAdapter, MatrixAdapter, SignalAdapter, MattermostAdapter, TeamsAdapter, GoogleChatAdapter, BlueBubblesAdapter, LineAdapter, FeishuAdapter, ZaloAdapter, PairingManager } from '../channels/index.js';
|
||||
import { CronScheduler, WebhookHandler, GmailWatcher } from '../automation/index.js';
|
||||
import type { GatewayServer } from '../gateway/index.js';
|
||||
|
||||
@@ -182,6 +182,20 @@ export function registerChannels(deps: ChannelsDeps): ChannelsResult {
|
||||
gateway.setFeishuHandler(feishuAdapter);
|
||||
}
|
||||
|
||||
// Register Zalo adapter (if configured)
|
||||
if (config.zalo) {
|
||||
const zaloAdapter = new ZaloAdapter({
|
||||
oaAccessToken: config.zalo.oa_access_token,
|
||||
endpoint: config.zalo.endpoint,
|
||||
webhookToken: config.zalo.webhook_token,
|
||||
allowedUserIds: config.zalo.allowed_user_ids.length > 0 ? config.zalo.allowed_user_ids : undefined,
|
||||
requireMention: config.zalo.require_mention,
|
||||
mentionName: config.zalo.mention_name,
|
||||
});
|
||||
channelRegistry.register(zaloAdapter);
|
||||
gateway.setZaloHandler(zaloAdapter);
|
||||
}
|
||||
|
||||
// Register WebChat adapter (wraps the gateway)
|
||||
const webChatAdapter = new WebChatAdapter({ gateway });
|
||||
channelRegistry.register(webChatAdapter);
|
||||
|
||||
Reference in New Issue
Block a user