grammyjs / grammY

The Telegram Bot Framework.
https://grammy.dev
MIT License
2.17k stars 110 forks source link

Treat tg://bot_command text_link entities as commands #537

Closed li-kai closed 6 months ago

li-kai commented 6 months ago

In telegram, you can send /mycommand@mybot as plain text, which results in the update:

{
    ...
    "text": "/mycommand@mybot",
    "entities": [
      {
        "offset": 0,
        "length": 9,
        "type": "bot_command"
      }
    ]
}

However, if you clicked on or copied it from a previous group chat command, it would be sent as a text_link entity:

{
    ...
    "text": "/mycommand@mybot",
    "entities": [
      {
        "offset": 0,
        "length": 24,
        "type": "text_link",
        "url": "tg://bot_command?command=mycommand&bot=mybot"
      }
    ]
}

Since .command is only triggered by "type": "bot_command" and not based on the text content, this will fall through to on('msg:text') handlers.

Imo, text_link entities that are "url": "tg://bot_command should also be treated as commands. But it is up for debate whether the text or ?command= param should be the source of truth.

KnorpelSenf commented 6 months ago

Which Telegram client does that, how do you need to use it in order to get a text link rather than a command, and why don't you just click the command instead?

li-kai commented 6 months ago

On the web client, which if you copy+paste, it places a text_link instead. Then, from there, clicks will act as the same, but continue sending text_links.

rojvv commented 6 months ago

This must be a bug in the web client. Which one specifically are you talking about, A or K?

li-kai commented 6 months ago

This would be K, and this was a bug in the client. I can't seem to reproduce this anymore.