Teact
Packages

@teactjs/plugin-sdk

Author your own Teact plugins with definePlugin — register middleware, providers, DI services, and lifecycle hooks.

@teactjs/plugin-sdk is the authoring kit for Teact plugins. Call definePlugin to describe a plugin once and get back a factory you drop into createBot({ plugins }) or teact.config.ts. The plugin host that runs plugins lives in @teactjs/core — this package is only what you need to build one.

bun add @teactjs/plugin-sdk

Exports

ExportKindDescription
definePluginfunctiondefinePlugin({ name, defaultConfig?, setup }) → a PluginFactory.
PluginContexttypeThe context handed to setup.
PluginDefinitiontypeShape of the object passed to definePlugin.
PluginFactorytypeThe returned factory: (config?) => TeactPlugin.
TeactPlugin, ServiceMap, Adapter, MiddlewaretypesRe-exported from @teactjs/core so authors have one import.

PluginContext

setup(ctx) receives a PluginContext<C>. Register everything the plugin contributes here:

MemberSignaturePurpose
configCResolved config (defaultConfig merged under the user's config).
middleware(fn: Middleware) => voidRun on every incoming update.
addProvider(Comp: FunctionComponent<{ children }>) => voidWrap the app tree with a React provider (providers nest in order).
provideService(key: string, value: unknown) => voidRegister a DI service, read later with useService(key).
onStart(fn: (adapter: Adapter) => void | Promise<void>) => voidRun when the bot starts (after the adapter connects).
onStop(fn: () => void | Promise<void>) => voidRun on shutdown.

Example

// my-supabase-plugin.ts
import { definePlugin } from "@teactjs/plugin-sdk";
import { createClient } from "@supabase/supabase-js";

export const supabase = definePlugin<{ url: string; key: string }>({
  name: "supabase",
  setup(ctx) {
    ctx.provideService("supabase", createClient(ctx.config.url, ctx.config.key));
  },
});

Register it, then read the service anywhere with useService:

// teact.config.ts
import { defineConfig } from "@teactjs/core";
import { supabase } from "./my-supabase-plugin";

export default defineConfig({
  plugins: [supabase({ url: process.env.SUPABASE_URL!, key: process.env.SUPABASE_KEY! })],
});
import { useService } from "@teactjs/core";
const db = useService<SupabaseClient>("supabase");

On edge runtimes, teact.config.ts is not loaded — pass plugins directly via createBot({ plugins }).

See the Middleware & plugins guide for the full plugin lifecycle and DI patterns.

On this page