go-telegram-bot-api / telegram-bot-api

Golang bindings for the Telegram Bot API
https://go-telegram-bot-api.dev
MIT License
5.58k stars 863 forks source link

How can I test webhooks locally? #644

Open realtebo opened 1 year ago

realtebo commented 1 year ago

I need a webhook based interaction, so no listening to changes.

I read I can download telegram bot api server locally and build and run it, and I did.

So, it's up and running using my personal api id and hash.

And now?

See here: https://github.com/tdlib/telegram-bot-api

It states:

logOut

Use this method to log out from the cloud Bot API server before launching the bot locally. You must log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful call, you can immediately log in on a local server, but will not be able to log in back to the cloud Bot API server for 10 minutes. Returns True on success. Requires no parameters.

My question is ..

How can I 'logout' my bot from online api server, as stated in the doc and then tell the bot to use the local bot api server?

nuclearnic commented 1 year ago

To log out your bot you can just do curl -X POST https://api.telegram.org/<api_key:api_hash>/logOut

After that, you should run the Bot API server locally, see https://github.com/tdlib/telegram-bot-api, and then something like this:

botToken := "some-bot-token"
apiUrl := "http://localhost:8081/bot%s/%s"

bot, err := tgbotapi.NewBotAPIWithAPIEndpoint(botToken, apiUrl)