showcase/shell-docs/src/content/reference/channels/functions/defineChannelCommand.mdx
defineChannelCommand preserves a command definition and infers structured
options when the provider supplies them.
function defineChannelCommand<Schema extends ObjectSchema>(
command: ChannelCommand<Schema>,
): ChannelCommand<Schema>;
interface ChannelCommand<Schema extends ObjectSchema> {
name: string;
description?: string;
options?: Schema;
handler(
context: CommandContext<InferSchemaOutput<Schema>>,
): void | Promise<void>;
}
import { defineChannelCommand } from "@copilotkit/channels";
export const triage = defineChannelCommand({
name: "triage",
description: "Triage the current conversation.",
async handler({ thread, text, user, platform }) {
await thread.runAgent({
prompt: text || "Triage this conversation.",
context: [
{ description: "Provider", value: platform },
{
description: "Invoking user",
value: user?.name ?? user?.id ?? "unknown",
},
],
});
},
});
Register it with createChannel({ commands: [triage] }) or
channel.onCommand(triage) before startup.
| Field | Type | Notes |
|---|---|---|
thread | Thread | Conversation where the command was invoked. |
command | string | Normalized name: no leading slash, lowercase, hyphens and underscores route equivalently. |
text | string | Raw argument text. Managed Slack and Teams use this field. |
options | TOptions | Structured options when a provider supplies them; empty on managed Slack and Teams. |
user | PlatformUser | undefined | Invoking provider user. |
platform | string | Native provider ("slack" or "teams") on managed command ingress. |
openModal | function or undefined | Omitted by the managed Slack and Teams adapter. |
Slack must also register the native slash command in the Slack app. Teams
routes messages matching /name or /name arguments. See
Commands and reactions.