unreal4u / telegram-api

Complete async capable Telegram bot API implementation for PHP7
https://github.com/unreal4u/telegram-api/wiki
MIT License
784 stars 172 forks source link

How can i set bot commands? #125

Closed askador closed 3 years ago

askador commented 3 years ago

Hello! i need to set bot commands I saw type SetMyCommands but how can i use it?

unreal4u commented 3 years ago

Hi!

I would suggest you take a look at the examples directory: https://github.com/unreal4u/telegram-api/tree/master/examples

There is no example yet of setMyCommands, but you can get yourself a bit familiarized with how this library works this way.

Once you've done that, you'll be able to see that the SetMyCommands method accepts one argument: an array of BotCommand types: https://github.com/unreal4u/telegram-api/blob/master/src/Telegram/Types/BotCommand.php

So to create one BotCommand, you'll have to do something similar to the following:

$botCommand = new BotCommand();
$botCommand->command = 'help';
$botCommand->description = 'Help is what help is for';

$setMyCommands = new SetMyCommands();
$setMyCommands->commands[] = $botCommand;

For more information on SetMyCommands: https://github.com/unreal4u/telegram-api/blob/master/src/Telegram/Methods/SetMyCommands.php

After that, just follow the same flow as the SendMessage example and you're good to go!

Greetings.

askador commented 3 years ago

Thank you!