True Object-Oriented Telegram Framework with same design as in https://www.takes.org/
Add teletakes
as maven dependency and telegrambots
dependency:
<dependency>
<groupId>com.g4s8</groupId>
<artifactId>teletakes</artifactId>
<version>0.1</version> <!-- put latest version here -->
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>${telegram.version}</version>
</dependency>
To start Telegram bot you need to instanciate BotSimple
and register it
as a bot via telegrambots
library:
new TelegramBotsApi().registerBot(
new BotSimple(
new TkFork(
new FkMessage(
"hello",
req -> new RsText(
new FormattedText(
"Hello %s", new RqUser(req).value().getFirstName()
)
)
)
)
)
);
This take answers for /version
command:
new TkFork(
new FkCommand(
"/version"
new TkText("1.0")
)
)
This take shows keyboard on user Telegram client:
new TkFixed(
new RsReplyKeyboard(
new RsText("Hello"),
new ListOf<Iterable<Text>>(
new ListOf<>(
new TextOf("Menu"),
new TextOf("Settings")
)
)
)
)
Telegram message can include "inline buttons" with callbacks, where callback is a strings which will be sent sent to a bot on button click. This take will show a button and handle its clicks:
new TkFork(
new FkMessage(
Pattern.compile(".*"),
new TkFixed(
new RsInlineKeyboard(
new RsText("inline buttons"),
new ListOf<Iterable<Map.Entry<String, String>>>(
new ListOf<Map.Entry<String, String>>(
new MapEntry<>("Confirm", "click:on-confirm"),
new MapEntry<>("Cancel", "click:on-cancel")
)
)
)
)
),
new FkCallbackQuery(
"click:on-confirm",
new TkText("Confirmed")
),
new FkCallbackQuery(
"click:on-cancel",
new TkText("Canceled")
)
)