mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2026-11-27 05:43:14 +00:00
1.6 KiB
1.6 KiB
HelloBot
HelloBot is a small long-polling example that greets the chat or sender when a message addresses the bot by username.
Trigger and replies
The bot greets messages whose text contains its primary username or an active alias
returned by getMe. The match includes the leading @ and ignores case.
- In a private chat, it replies with a MarkdownV2 text mention of the user.
- In a group or supergroup, it greets the group and links its title to a public username or invite link when one is available.
- For a message sent to a group on behalf of a channel, it greets the sender channel instead.
- In a channel, it greets the channel and includes the sender chat when Telegram supplies one.
- In a business chat, it mentions the underlying private-chat user.
Every received update is also printed to standard output for demonstration and debugging.
Setup
- Create a bot with BotFather and keep its token private.
- Add the bot to each chat where it should respond. Explicit username mentions work with Telegram's normal group privacy mode.
- For channel posts, make the bot a channel administrator and allow it to post messages. Admin access may also make a private group invite link available; otherwise the group reply falls back to an unlinked title.
Run
From the repository root, pass the token as the first positional argument:
./gradlew :HelloBot:run --args="BOT_TOKEN"
The token is required. Additional command-line arguments are ignored. The bot runs until the process is stopped and uses long polling, so no webhook setup is needed.