CopilotKitDocs
  • Docs
  • Reference
  • Cookbook
Get Intelligence free
CopilotKitDocs
DocsReferenceCookbook
DocsReferenceCookbook

@copilotkit/bot

bindcreateBotdefineBotCommanddefineBotToolrenderToIR

@copilotkit/bot-slack

ReferencebotFunctions

defineBotCommand

Define a typed slash command — name, optional Standard Schema options, and a handler receiving CommandContext.


Overview

defineBotCommand defines a slash command with full type inference: ctx.options is inferred from the options schema. Commands are registered via createBot({ commands }) or bot.onCommand, and routed to the matching handler when the platform delivers an invocation.

Signature

import { defineBotCommand } from "@copilotkit/bot";

function defineBotCommand<Schema extends ObjectSchema>(
  command: BotCommand<Schema>,
): BotCommand<Schema>;

Parameters

Prop

Type

CommandContext

Prop

Type

Prop

Type

Prop

Type

Prop

Type

Prop

Type

Prop

Type

Usage

import { defineBotCommand } from "@copilotkit/bot";
import { z } from "zod";

const triage = defineBotCommand({
  name: "triage",
  description: "Summarize and file the current thread.",
  options: z.object({ priority: z.enum(["low", "high"]).optional() }),
  async handler({ thread, text }) {
    await thread.runAgent({ prompt: `Triage: ${text}` });
  },
});

A slash command's text is never posted to the channel, so it isn't in the history the adapter reconstructs — pass it to the agent explicitly with runAgent({ prompt }).

Behavior

  • Declare commands with the platform — platforms only deliver commands they know about. On Slack, every command must also be declared in the app configuration (the manifest's slash_commands section, or "Slash Commands" in the app settings); an undeclared command is silently dropped, even over Socket Mode. See the Slack quickstart.
  • Matching is case-insensitive and ignores the leading slash; commands delivered by the platform but not registered on the bot are ignored.
  • Up-front registration — on start(), declared commands are forwarded to adapters that implement registerCommands (e.g. a Discord-style application-command API); adapters without it, including Slack, are skipped.

Related

  • createBot — registering commands (commands option / onCommand)
  • Thread — runAgent({ prompt })
  • defineBotTool — the tool analog
10d3939