Idea: Commands to Class detection define
Currently to create a command it must be a class with the same name like the command + "Command" in the command directory. e.g.: Command -> /foobar Class -> FooBarCommand
But if you want to start a command with a number or an spezialchar in the commandname you can't create this command.
The idea is that you can set a list of classes and in this class you have a property or method with is call to detect if it is the called command.
e.g.:
$bot->setCommands([Foo::class, Bar::class]);
or
$bot->addCommand(new FooBar());
or
$bot->addCommand('/123foo456bar', FooBar::class);
....
class FooBar extends UserCommand
{
$command = '/123foo456bar';
....
}
For downgrade compability the current process can be the default, if no command is found. So the command is not limited by the rules of filenameing oder classnaming.
This part of the library needs much more refactoring. As workaround you could create your own class GenericmessageCommand. Just copy the original file and change method "execute" to your own. And don't forget to add path to your classes
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
//// Add an additional commands path
telegram->addCommandsPath('path/to/your/commands');
If you have any doubts about this way just try to think about:
- User could edit already sent message (you need to handle it)
- You could add keyboard to your message (you need to handle it)
- You could create step-by-step logic without prefixing every command to bot (you need to handle it)
No, it's not. Just check GenericCommand.php.