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

pro.zackpollard.telegrambot.api.menu.button.builder.UserInputInlineMenuButtonBuilder Maven / Gradle / Ivy

There is a newer version: 1.6.5
Show newest version
package pro.zackpollard.telegrambot.api.menu.button.builder;

import pro.zackpollard.telegrambot.api.menu.AbstractInlineMenuBuilder;
import pro.zackpollard.telegrambot.api.menu.InlineMenuRowBuilder;
import pro.zackpollard.telegrambot.api.menu.button.AbstractButtonBuilder;
import pro.zackpollard.telegrambot.api.menu.button.InlineMenuButton;
import pro.zackpollard.telegrambot.api.menu.button.callback.ButtonCallback;
import pro.zackpollard.telegrambot.api.menu.button.impl.UserInputInlineMenuButton;
import pro.zackpollard.telegrambot.api.utils.Utils;

import java.util.function.BiConsumer;

/**
 * Builder for user input buttons.
 *
 * Methods text(), buttonCallback() and textCallback() must all be called
 *
 * @param  menu builder type
 * @see UserInputInlineMenuButton
 * @see AbstractButtonBuilder#text(String)
 * @see AbstractButtonBuilder#buttonCallback(ButtonCallback)
 * @see UserInputInlineMenuButtonBuilder#textCallback(BiConsumer)
 * @author Mazen Kotb
 */
public class UserInputInlineMenuButtonBuilder
        extends AbstractButtonBuilder, T> {
    private BiConsumer textCallback;

    public UserInputInlineMenuButtonBuilder(InlineMenuRowBuilder parent, int index) {
        super(parent, index);
    }

    public UserInputInlineMenuButtonBuilder(InlineMenuRowBuilder parent, int index, String text) {
        super(parent, index, text);
    }

    @Override
    protected UserInputInlineMenuButtonBuilder instance() {
        return this;
    }

    /**
     * Required. callback to be executed on input
     * @param textCallback callback to be executed on input
     * @return this
     */
    public UserInputInlineMenuButtonBuilder textCallback(BiConsumer textCallback) {
        this.textCallback = textCallback;
        return this;
    }

    @Override
    public InlineMenuRowBuilder build() {
        Utils.validateNotNull(text, callback, textCallback);
        parent.internalAddButton(processButton(new UserInputInlineMenuButton(null, parent.rowIndex(), index, text, textCallback)));
        return parent;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy