Skip to content

Commit f595a03

Browse files
morealclaude
andcommitted
Implement createInstance function
Connect createInstance() to InstanceImpl, enabling multi-bot instance creation. The function returns a wrapper object for Deno serve compatibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d42a8ae commit f595a03

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

packages/botkit/src/instance.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type {
2121
} from "@fedify/fedify/federation";
2222
import type { Software } from "@fedify/fedify/nodeinfo";
2323
import type { Bot, BotProfile, PagesOptions } from "./bot.ts";
24+
import { InstanceImpl } from "./instance-impl.ts";
2425
import type { Repository } from "./repository.ts";
2526

2627
/**
@@ -214,7 +215,24 @@ export function createInstance<TContextData = void>(
214215
options: CreateInstanceOptions<TContextData>,
215216
): TContextData extends void ? InstanceWithVoidContextData
216217
: Instance<TContextData> {
217-
// TODO: Implement InstanceImpl and return it here
218-
void options;
219-
throw new Error("createInstance is not yet implemented");
218+
const instance = new InstanceImpl<TContextData>(options);
219+
// Since `deno serve` does not recognize a class instance having fetch(),
220+
// we wrap an InstanceImpl instance with a plain object.
221+
// See also https://github.com/denoland/deno/issues/24062
222+
const wrapper = {
223+
get federation() {
224+
return instance.federation;
225+
},
226+
createBot(
227+
identifierOrDispatcher: string | BotDispatcher<TContextData>,
228+
profile?: BotProfile<TContextData>,
229+
): Bot<TContextData> {
230+
return instance.createBot(identifierOrDispatcher, profile);
231+
},
232+
fetch(request: Request, contextData: TContextData): Promise<Response> {
233+
return instance.fetch(request, contextData);
234+
},
235+
} satisfies Instance<TContextData>;
236+
// @ts-ignore: the wrapper implements InstanceWithVoidContextData
237+
return wrapper;
220238
}

0 commit comments

Comments
 (0)