rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.69k stars 1.19k forks source link

Add wiki page for Webhook bot #1198

Closed geriko2000 closed 2 months ago

geriko2000 commented 1 year ago

This wiki does not have a page about the bot's webhook and how to set it up. It is very difficult to navigate, you need to climb into the source codes of the code and look for information yourself. Please add information. by connecting the bot in webhook mode

Pyr0x1 commented 1 year ago

I second this, trying to switch to webhook mode from long polling, but I am struggling with it... by reading some comments in the issues I am not even sure webhook mode is working at the moment.

loolzaaa commented 1 year ago

Webhook bots work correctly. What's a problem with it?

Some example:

public class ServiceWebhookBot extends TelegramWebhookBot {
    // ...
}
// For serverless version (AWS Lambda + AWS Gateway)
TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class, new ServerlessWebhook());
// For simple server version
// TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class, new DefaultWebhook());
SetWebhook setWebhook = SetWebhook.builder().url(WEBHOOK_URL).build();
telegramBotsApi.registerBot(new ServiceWebhookBot(BOT_TOKEN), setWebhook);

BOT_TOKEN - environment variable with bot token WEBHOOK_URL - environment variable with webhook url (telegram server sent requests with updates to it)

WARNING: Telegram server sent webhooks only to https://... urls!

Some old implementations here: https://github.com/loolzaaa/telegram-service-bot

slavikf1 commented 10 months ago

@loolzaaa what I miss personally is how to initialize an extension of a SpringWebhookBot bot so it would be serverless (i.e. using a Spring-application controllers).

There are not examples of that and above-mentioned useful example is not mentioned in wiki.

ylazakovich commented 3 months ago

https://github.com/ylazakovich/path-of-exile-starter/blob/main/modules/telegram/src/main/java/io/starter/telegram/model/telegram/Telegram.java#L16

you can try to use this example of implementation Spring and Webhook with current version of telegram api

rubenlagus commented 2 months ago

Added here: https://rubenlagus.github.io/TelegramBotsDocumentation/lesson-9.html