TelegramEx.Command (TelegramEx v1.3.0)

Copy Markdown View Source

Helpers for defining and registering Telegram bot commands.

defcommand/3 defines a regular handle_message/2 clause for messages that start with a Telegram command and stores metadata for setMyCommands.

register_all/2 is called by TelegramEx.Server on startup. It reads command metadata from the bot module and its routers, then sends the list to Telegram using setMyCommands.

See Commands for examples and binding rules.

Fields

  • :command - The command name (string)
  • :description - Command description used by Telegram clients
  • :message - The original message struct (TelegramEx.Types.Message.t())

Summary

Types

t()

Command struct type.

Functions

Defines a command handler and adds the command to the module metadata.

Registers all commands defined in a bot module and its routers.

Types

t()

@type t() :: %TelegramEx.Command{
  command: String.t(),
  description: String.t() | nil,
  message: TelegramEx.Types.Message.t()
}

Command struct type.

Contains all fields related to a Telegram command.

Functions

defcommand(command_name, opts, list)

(macro)

Defines a command handler and adds the command to the module metadata.

The command name should be passed without the leading slash. :description is required because Telegram requires it for setMyCommands.

See Commands for full examples.

register_all(token, module)

@spec register_all(String.t(), module()) :: :ok | {:error, term()}

Registers all commands defined in a bot module and its routers.