Skip to content

Telegram Bot API Methods

Michi Palazzo edited this page Jan 29, 2019 · 1 revision

Bot

The Bot class works as a bridge to the Telegram Bot API. Particular attention should be put on execute(TelegramMethod) method since this handles the different API calls. You can find the list of all available TelegramMethods here.

Here are some examples:

Bot bot = Bot.fromToken(token);

SendMessage sendMessage = new SendMessage()
    .chat(-123456789L)
    .text(Text.bold("Hello!"));
TextMessage messageSent = bot.execute(sendMessage);

SendMessage sendMessage2 = new SendMessage()
    .replyToMessage(messageSent)
    .text("World!")
    .disableNotifications();
bot.execute(sendMessage2);

GetChat getChat = new GetChat()
    .chat(-123456789L);
Chat chat = bot.execute(getChat);

GetChat getChat = new GetChat()
    .chat("channel_official");
Channel channel = (Channel) bot.execute(getChat);

SetChatTitle setChatTitle = new SetChatTitle()
    .chat(channel)
    .title("Official Channel");
bot.execute(setChatTitle);

Clone this wiki locally