Skip to content

Latest commit

 

History

History
110 lines (100 loc) · 3.58 KB

README.md

File metadata and controls

110 lines (100 loc) · 3.58 KB

Teletakes

True Object-Oriented Telegram Framework with same design as in https://www.takes.org/

EO principles respected here DevOps By Rultor.com

CircleCI Build Status Build status

codecov Download Codacy Badge PDD status License

Install

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>

Quick start

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()
                )
            )
        )
      )
    )
 );

Examples

Handle commands

This take answers for /version command:

new TkFork(
   new FkCommand(
     "/version"
     new TkText("1.0")
   )
)

Show keyboard

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")
            )
        )
    )
)

Inline buttons

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")
    )
)