martynovskyi / telegram-bot-api-reactive

Reactive implementation of Telegram Bot api based on Spring Reactor project.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unit Tests

Telegram Bot API based on Spring Reactor

  • Java 21
  • WebClient
  • Mono and Flux

Currently, code/package structure is not finalized. Pretty raw implementations

Supported methods

Configuration

application.yml

telegram:
  bots:
    - name: example_bot # unique | required | 
      token: 5151515151:ask-bot-father # required | bot token from BotFather
    - name: other_bot
      token: 0101010101:ask-bot-father

Usage

@Slf4j
@Component
@RequiredArgsConstructor
public class Example {
    private final BotFactory botFactory;

    public void sayHello(String recipientId) {
        Optional<Bot> testBot = botFactory.get("test_bot");
        testBot.ifPresent(bot ->
                bot.sendMessage(recipientId)
                        .setText("Hello 👋")
                        .subscribe(response ->
                                log.info("Said hello to {}, is Ok {}", recipientId, response.isOk())
                        ));
    }
}

Implementation details

Client

Interface and Implementation

This is implementation of Telegram Bot API. Here build and executes all requests to Telegram.

This layer uses method DTOs from com.motokyi.tg.bot_api.api.method.payload package

Bot

Interface and Implementation

This is abstraction built on top of Client. It allows to use chained construction to setup requests to Bot Api

This layer uses methods from com.motokyi.tg.bot_api.api.method package. These methods are DTOs enhanced with the ability to self-execution and chained setters.

About

Reactive implementation of Telegram Bot api based on Spring Reactor project.


Languages

Language:Java 100.0%