The reply.message
element allows you to reply to a user event with a text message,
providing options for text formatting and templating.
You can use the reply.message element in two ways: as a simple string or as a YAML mapping structure. Both representations achieve the same result:
String Representation:
reply:
- message: "Hello"
YAML Mapping Structure:
reply:
- message:
text: "Hello"
The reply.message
element can have the following options:
${state.key}
expressions,
“go” style uses the Go template engine, and “no” ignores templates and returns text as is.Example:
reply:
- message:
text: "**Hello,** ${user.first_name}!"
parseMode: "MarkdownV2"
template: "default"
In this example, the bot replies with a formatted message using the MarkdownV2 parse mode and default template style.
See for details about parse-mode: https://core.telegram.org/bots/api#formatting-options
Default Interpolator:
The default interpolator uses ${key} syntax to render values into the string. Possible keys include:
state.<key>
: Get the state value for the key.secret.<key>
: Get the secret value for the key.message.id
: Current message ID (the message that triggered this event).message.text
: Current message text.message.from.id
: Telegram ID of the message sender.chat.id
: Current Telegram chat ID.chat.type
: Type of chat (“private”, “group”, “supergroup”, or “channel”).Go Interpolator:
The Go interpolator uses the GoLang template format. Possible template variables include:
Update
: Current Telegram update object.State
: Key-value pairs of the user’s state.Secrets
: Key-value pairs of bot secrets.Data
: JSON object loaded by the data-loader.No Template Engine:
The “no” template engine renders text as is without any interpolation.
Default interpolator:
reply:
- message:
text: "Hello, ${user.first_name}! You are ${state.age} years old."
template: "default"
Go template engine:
reply:
- message:
text: "Hello, {{.Update.Message.From.FirstName}}! You are {{.State.age}} years old."
template: "go"
No Template Engine:
reply:
- message:
text: "This is plain text with no template. {{Render}} ${this text as is}."
template: "no"
Explore further to understand the full potential of text formatting and templating options in your bot replies.
state.<key>
- get state value for key;secret.<key>
- get secret value for key;message.id
- get current message id;message.text
for current message text;message.from.id
- Telegram id of message sender;chat.id
- current Telegram chat id;chat.type
- Type of chat, can be either “private”, “group”, “supergroup” or “channel”;chat.title
- Title for supergroups, channels and group chats;chat.first_name
- FirstName of the other party in a private chat;chat.last_name
- LastName of the other party in a private chat;chat.username
- UserName for private chats, supergroups and channels if available;user.id
- ID of user who sent this message;user.is_bot
- true if sender is bot;user.first_name
- FirstName user’s or bot’s last name;user.last_name
- LastName user’s or bot’s last name;user.username
- UserName user’s or bot’s username;user.language_code
- LanguageCode IETF language tag of the user’s language;Update
- current telegram update object as https://pkg.go.dev/github.com/go-telegram-bot-api/telegram-bot-api/v5#UpdateState
- key value pairs of user’s stateSecrets
- key value pairs of bot secretsData
- json object loaded by data-loader