fix(channels): bridge openDM delegates to adapter directly
chat.openDM dispatches via inferAdapterFromUserId, which only recognizes Discord/Slack/Teams/gChat formats and throws for everything else — breaking approval delivery on Telegram (numeric IDs) and the other direct-addressable channels the bridge now wraps. Delegate straight to adapter.openDM + channelIdFromThreadId, and only expose openDM when the underlying adapter implements it. Preserves the adapter's native platform_id encoding (e.g. "telegram:<chatId>") so user_dms caches align with the messaging_groups rows onInbound wrote. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
38
src/channels/chat-sdk-bridge.test.ts
Normal file
38
src/channels/chat-sdk-bridge.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import type { Adapter } from 'chat';
|
||||
|
||||
import { createChatSdkBridge } from './chat-sdk-bridge.js';
|
||||
|
||||
function stubAdapter(partial: Partial<Adapter>): Adapter {
|
||||
return { name: 'stub', ...partial } as unknown as Adapter;
|
||||
}
|
||||
|
||||
describe('createChatSdkBridge', () => {
|
||||
it('omits openDM when the underlying Chat SDK adapter has none', () => {
|
||||
const bridge = createChatSdkBridge({
|
||||
adapter: stubAdapter({}),
|
||||
supportsThreads: false,
|
||||
});
|
||||
expect(bridge.openDM).toBeUndefined();
|
||||
});
|
||||
|
||||
it('exposes openDM when the underlying adapter has one, and delegates directly', async () => {
|
||||
const openDMCalls: string[] = [];
|
||||
const bridge = createChatSdkBridge({
|
||||
adapter: stubAdapter({
|
||||
openDM: async (userId: string) => {
|
||||
openDMCalls.push(userId);
|
||||
return `thread::${userId}`;
|
||||
},
|
||||
channelIdFromThreadId: (threadId: string) => `stub:${threadId.replace(/^thread::/, '')}`,
|
||||
}),
|
||||
supportsThreads: false,
|
||||
});
|
||||
expect(bridge.openDM).toBeDefined();
|
||||
const platformId = await bridge.openDM!('user-42');
|
||||
// Delegation: adapter.openDM → adapter.channelIdFromThreadId, no chat.openDM in between.
|
||||
expect(openDMCalls).toEqual(['user-42']);
|
||||
expect(platformId).toBe('stub:user-42');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user