Skip to content

TelegramBotCommands #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
noplanman opened this issue Jun 26, 2016 · 1 comment
Closed

TelegramBotCommands #231

noplanman opened this issue Jun 26, 2016 · 1 comment

Comments

@noplanman
Copy link
Member

Being able to manipulate the existing commands is something that has been requested quite a few times already.
The main question being: "How can I disable all integrated commands?".
Currently, the easiest solution is to create dummy commands that aren't enabled, and thus aren't available to the bot.

For this reason it would be very helpful to have a dedicated TelegramBotCommands class that handles all things commands (in the same way that TelegramBotLog handles all log related functionality).

This will allow a user to easily add/remove custom or internal commands to their bot.

Let's bring together some ideas how we could make this easy for the users to make use of!

Without delving too deep into how this can be implemented, something like this would be the idea:

// Like the Logger, the Commander is now a singleton with static methods.
TelegramBotCommander::addCustomPath('/path/to/custom/commands');

// Here we pass a callback that returns an array of the available commands.
TelegramBotCommander::filterCommands('command_filter_callback');

// In our callback we can easily choose which custom commands are enabled.

// Example 1: remove 'whoami', 'echo' and 'weather' commands.
function command_filter_callback($commands)
{
  foreach(['whoami', 'echo', 'weather'] as $command) {
    unset($commands[$command]);
  }
  return $commands;
}

// Example 2: only enable 'help' and 'whoami' commands.
function command_filter_callback($commands)
{
  return ['help', 'whoami'];
}

NOTE!: This is just a rough pseudo code example. It will become more complex than this, as we will also have to account for System and Admin commands in some way.

(Maybe we could also implement different user rights, but I think that's for some time in the future)

@noplanman
Copy link
Member Author

Closing off here, as commands have been moved to example repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants