英文:
Is is possible to hide bot_command in text messages when using telegram api?
问题
我正在使用sendMessage
方法来自[telegram API][1]。
我想发送类似这样的内容:
> 一些消息 用于命令的一些文本,另一段文本。
当用户从电报机器人读取此消息时,他可以点击 用于命令的一些文本 ,并且此操作将生成来自用户的消息,应该如下所示:
> none >/一些命令 带文本 >
是否可能实现这样的功能?
因为当我尝试使用 [messageEntity][2] 时它不起作用:
"chat_id": 1,
"text": "/一些命令 文本, 另一段文本",
"entities": [
{
"type" : "bot_command",
"offset": 0,
"length": 18
}
]
}'```
所以电报只解析消息并只能点击 `一些命令` ,而不是带文本的命令。另外,如果我尝试发送不带 `\` 的消息,它根本不会解析。
[1]: https://core.telegram.org/bots/api
[2]: https://core.telegram.org/bots/api#messageentity
<details>
<summary>英文:</summary>
I'm using the `sendMessage` method from [telegram api][1]
I want to send something like this:
> Some message ***some_text_for_command*** , another text.
---
When user will read this message from telegram bot, he can click on ***some_text_for_command*** and this action will generate message from user, which should looks like this:
> ```none
>/some_command with_text
>```
---
Is is possible to realize something like this?
Because, when I try to use [messageEntity][2] is doesn't work:
curl --location --request POST 'https://api.telegram.org/bot{bot_code}/sendMessage'
--header 'Content-Type: application/json'
--data-raw '{
"chat_id": 1,
"text": "/some_command text, another text",
"entities": [
{
"type" : "bot_command",
"offset": 0,
"length": 18
}
]
}'
So telegram just parses message and gives an ability to click only on `some_command`, not for the command with the text. Also if I try to send message without `\`, it should parse it at all.
[1]: https://core.telegram.org/bots/api
[2]: https://core.telegram.org/bots/api#messageentity
</details>
# 答案1
**得分**: 1
不,不幸的是这是不可能的。
----------
有两种方法可以接近您期望的输出。
#### 选项1,命令+键盘
您可以发送一个没有参数的命令,例如`/some_command`,在响应中单击该命令后,显示一个[键盘](https://core.telegram.org/bots/features#keyboards),显示可用于`some_text`的选项。
文档中的示例图像:
[![enter image description here][1]][1]
#### 选项2,内联代码+复制/粘贴
您可以发送一个内联代码块,用户可以按下以复制整个命令,这样用户只需单击并粘贴命令到机器人:
/some_command some_text
<https://stackoverflow.com/questions/59713920/how-to-make-that-when-you-click-on-the-text-it-was-copied-pytelegrambotapi>
[1]: https://i.stack.imgur.com/2BcqZ.png
<details>
<summary>英文:</summary>
No, unfortunately this is not possible.
----------
There are 2 ways to come somehow close to your desired output.
#### Option 1, command + keyboard
You could send a command without a parameter, like `/some_command` where in response on clicking that command you show a [keyboard](https://core.telegram.org/bots/features#keyboards) with the options available for `some_text`
Example image from documenatation on how the keyboard could look like:
[![enter image description here][1]][1]
#### Option 2, inline-code + copy/paste
You could send an inline code block, on which the user can press to copy the whole command, this way the user just have to click and paste the command to the bot:
/some_command some_text
<https://stackoverflow.com/questions/59713920/how-to-make-that-when-you-click-on-the-text-it-was-copied-pytelegrambotapi>
[1]: https://i.stack.imgur.com/2BcqZ.png
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论