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

com.github.kshashov.telegram.api.TelegramRequest Maven / Gradle / Ivy

package com.github.kshashov.telegram.api;

import com.github.kshashov.telegram.api.bind.annotation.BotRequest;
import com.pengrad.telegrambot.Callback;
import com.pengrad.telegrambot.TelegramBot;
import com.pengrad.telegrambot.model.Chat;
import com.pengrad.telegrambot.model.Message;
import com.pengrad.telegrambot.model.Update;
import com.pengrad.telegrambot.model.User;
import com.pengrad.telegrambot.request.BaseRequest;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

import javax.annotation.Nullable;
import java.util.Map;

/**
 * Accumulates all available parameters from the initial request, the path pattern and path variables.
 *
 * @see BaseRequest
 */
@Getter
@RequiredArgsConstructor
public class TelegramRequest {
    /**
     * Bot instance that received the current telegram event.
     */
    private final TelegramBot telegramBot;

    /**
     * The initial user request which is currently being processed.
     */
    private final Update update;

    /**
     * Type of the current telegram request.
     */
    private final MessageType messageType;

    /**
     * A path pattern from {@link BotRequest} annotation that matches the current request.
     */
    private final String basePattern;

    /**
     * All path variables parsed from the {@link #basePattern} field.
     */
    private final Map templateVariables;

    /**
     * The first non-empty object, if any, among:
     * 
    *
  • telegram message
  • *
  • telegram edited message
  • *
  • telegram channel post
  • *
  • telegram edited channel post
  • *
*/ private final Message message; /** * The first non-empty object, if any, among: *
    *
  • {@code message.text()}
  • *
  • {@code update.inlineQuery.query()}
  • *
  • {@code update.chosenInlineResult.query()}
  • *
  • {@code update.callbackQuery.data()}
  • *
  • {@code update.shippingQuery.invoicePayload()
  • *
  • {@code update.preCheckoutQuery.invoicePayload()
  • *
*/ private final String text; /** * Сhat instance if it present in the current telegram request. */ private final Chat chat; /** * User instance if it present in the current telegram request. */ private final User user; /** * Callback */ @Nullable @Setter private Callback callback; @Override public String toString() { final StringBuilder sb = new StringBuilder("TelegramRequest{"); sb.append("chat=").append(chat); sb.append(", user=").append(user); sb.append(", text='").append(text).append('\''); sb.append(", messageType=").append(messageType); sb.append('}'); return sb.toString(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy