-
Notifications
You must be signed in to change notification settings - Fork 12
Command System
Amir Ali Omidi edited this page Nov 27, 2017
·
1 revision
We've provided a separate command listener system for your convenience. This system can vary from very static to very dynamic as your liking.
To use this, once you have the TelegramBot instance, you can use the CommandRegistry inside this instance. To register a command, you provide it with a CommandListener and a CommandHandler.
The CommandListener can either be a TextCommandListener or a RegexCommandListener. You can also create your own CommandListener for a more dynamic approach if you so choose.
Example of this:
telegramBot.getCommandRegistry().registerCommand(new RegexCommandListener(Pattern.compile(".*")), command -> {
TextMessage message = command.getBaseMessage();
telegramBot.perform(SendText.builder()
.chatId(ChatId.of(message.getChat()))
.text(command.getArgsAsText())
.callback(textMessage -> System.out.println("It worked!"))
.errorHandler(e -> System.out.println("It didn't work!"))
.build()
);
});