All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.butkoprojects.bots.preprocess.controller.FakeBotApiMethodController Maven / Gradle / Ivy

package io.github.butkoprojects.bots.preprocess.controller;

import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Update;
import reactor.core.publisher.Flux;

import java.util.Collections;
import java.util.List;

public class FakeBotApiMethodController extends BotApiMethodController {

    public FakeBotApiMethodController() {
        super();
    }

    @Override
    public Flux process(Update update ) {
        SendMessage.SendMessageBuilder builder = SendMessage.builder();
        return Flux.fromIterable( Collections.singletonList( builder.text( "default" ).chatId( determineChatId( update ) ).build() ) );
    }

    private String determineChatId(Update update ) {
        return update.hasMessage()
                ? update.getMessage().getChatId().toString()
                : update.getCallbackQuery().getMessage().getChatId().toString();
    }
}