Telegram文本输入自动补全及命令式文本点击填入输入框技术问询
Hey there! Let's tackle your two questions about Telegram's input and command interactions:
1. Can we implement auto-completion for user text input in Telegram?
Absolutely, but the approach depends on whether you're working with regular chats or a Telegram Bot:
Native Telegram client auto-completion: The official Telegram app already supports built-in auto-completion for:
@mentions (usernames in the chat)#hashtags (relevant to the chat or your recent activity)- Emojis (typing emoji keywords triggers suggestions)
- Bot commands (when you type
/, it shows a list of registered commands for the Bot in the chat)
Custom auto-completion for Bots: If you want to add custom text auto-completion for your Bot's users, you have two solid options:
- Bot Command Menu: Register your Bot's commands via BotFather (using
/setcommands), and users will see these commands as auto-complete suggestions when they type/in the chat with your Bot. - Inline Query Mode: Enable inline mode for your Bot (via BotFather's
/setinline), so when users type@YourBot [keyword], your Bot can return custom auto-complete options. Users can select an option to insert it directly into their input box or send it as a message. - For more controlled input, you can also use
ReplyKeyboardMarkuporInlineKeyboardMarkupto present predefined options (though this is more of a selection menu than real-time typing auto-completion).
- Bot Command Menu: Register your Bot's commands via BotFather (using
2. How to make clickable custom commands (like \set_something) fill the input box instead of sending directly?
Telegram's default behavior for clickable / commands is to send them immediately, but you can customize this for your own custom commands (like \set_something) using Telegram's internal URL scheme. Here's how:
First, you need to format the custom command as a clickable link in messages sent by your Bot. Use Telegram's tg://input internal protocol, which lets you populate the user's input box with specified text when clicked.
Example formatting (using MarkdownV2):
[\set_something](tg://input?text=\set_something)
Key notes:
- This only works for messages sent by a Bot (regular users can't format text to use this protocol for clickable input filling).
- The
tg://inputprotocol is supported by all official Telegram clients (mobile, desktop, web). When a user clicks the link, it automatically inserts thetextparameter content into their current chat's input box—no need to navigate away or send the message immediately. - If you're using HTML parsing mode instead of MarkdownV2, the equivalent code would be:
<a href="tg://input?text=\set_something">\set_something</a>
内容的提问来源于stack exchange,提问作者Henry Kim

