frencisdrame frencisdrame - 7 months ago 293
PHP Question

Telegram bot - Get user response (command) from keyboard without slash

I want get a command from custom keyboard, without slash.

I read in other issue and inthe documentation, that this is not possible, the commands must always start with the ‘/’ symbol.

But in many bots i see that is possible.

For example @TriviaBot

I thought to get the string before the trigger start and add "/" to the string but without success.

Other solutions?

PS: I'm developing my bot in php using this API

https://github.com/irazasyed/telegram-bot-sdk

Answer

Telegram Bot Commands must be start with a slash /.

However, its are sent to bot as standard message, so the effective bot behavior is totally delegate to it.

If you want to use a string as command, you can do it simply processing the text message. I.e.:

if( $text == 'myCommand' )
{
    // Do Something...
}

Obviously, you have to consider possible ambiguities with a not-command message.

Comments