Skip to content

Slash commands and acknowledgements ​

The bridge opts into platform slash commands on request and reacts to the incoming message while the agent works. See Channel agent for service setup and the full option reference.

Slash commands ​

The Discord, Slack, and Telegram adapters emit a shared ChannelCommandEvent for platform slash-command invocations (/ask …), carrying the command name without the slash and the argument text. The service ignores them by default; opt in with commands: true:

ts
const service = createChannelAgent({
  channel,
  agent,
  commands: true,
})

An accepted command runs the agent with the prompt /<name> <text>; bot-authored commands are always ignored. For per-name control, pass options instead of true:

ts
const service = createChannelAgent({
  channel,
  agent,
  commands: {
    shouldHandle: async (event) => event.name !== 'admin',
    commands: {
      ask: {
        createPrompt: ({ event }) => `Research carefully: ${event.text}`,
        createSession: () => undefined, // run /ask without memory
      },
    },
  },
})

Every field of a per-command handler is optional: anything omitted falls back to the shared createPrompt, createSession, and renderOutcome behavior, and shouldHandle adds an extra filter for that name on top of the shared one.

Register the command on each platform ​

The bridge only handles invocations the platform delivers — register the command itself first:

  • Slack: register the command under Slash Commands in your app config and run the app in Socket Mode; the payload arrives as a slash_commands envelope and is acknowledged automatically.
  • Discord: register the application command (through the developer portal or a registration script). The gateway handles chat-input interactions; the reply is delivered as a regular channel message.
  • Telegram: commands (/ask@botname, /ask) are messages with a bot_command entity; the adapter emits a command event for those addressed to this bot. Publish the command list through BotFather or setMyCommands.

Bot-authored commands are always ignored, and commands run through the same pipeline as messages: filtering, acknowledgement reactions, sessions, streaming, and interactions all apply.

Acknowledgement reactions ​

React to the incoming message while the agent works on it. A string is shorthand for the acceptance reaction; false disables acknowledgements:

ts
const service = createChannelAgent({
  channel,
  agent,
  acknowledge: '👀',
})

Both reactions require channel.capabilities.reactions and channel.react. For the full lifecycle, pass options: completeReaction is added once a final response is delivered, and clearOnCompletion (default true when a completion reaction is configured) removes the acceptance reaction again wherever the adapter supports removals:

ts
const service = createChannelAgent({
  channel,
  agent,
  acknowledge: {
    reaction: '👀',
    completeReaction: '✅',
    clearOnCompletion: true,
  },
})

Behaviour and limits: only events that pass shouldHandle are acknowledged (filtered, bot-authored, and lifecycle events never get reactions); all three standard adapters support reactions; a failed acknowledgement is reported through onError with the acknowledge stage and never interrupts the run; false (or omitting the option) disables acknowledgements.

Continue with ​

Built for Anvia.