[GH-ISSUE #115] Integration with Telegram #78

Closed
opened 2026-02-25 23:41:05 +03:00 by kerem · 24 comments
Owner

Originally created by @dvorobiev on GitHub (Mar 1, 2017).
Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/115

It would be cool to add integration with a Telegram, as was done with Slack

Originally created by @dvorobiev on GitHub (Mar 1, 2017). Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/115 It would be cool to add integration with a Telegram, as was done with Slack
kerem closed this issue 2026-02-25 23:41:05 +03:00
Author
Owner

@cuu508 commented on GitHub (Mar 2, 2017):

I agree, it would be great to have a Telegram integration.

I've been poking around the Telegram Bot API. Here's the UI flow I think I would be able to implement:

  • From your Telegram client, invite "HealthchecksBot" to a group. It gets added as a member with no access to group messages

members

  • type /start command (or /start@HealthchecksBot if multiple bots present) in the group. Bot responds with a confirmation link.

mstart

  • Click/tap on confirmation link, healthchecks.io opens in browser asking you to confirm the new integration. Select "Done" and it's done.

Sounds good? Are there maybe examples of Telegram bots where the initial setup is more streamlined?

This would work for 1-to-1 chats and for groups. I could not find a good solution for channels – bot accounts can only be added as administrators not as regular users, so there are privacy problems.

<!-- gh-comment-id:283618477 --> @cuu508 commented on GitHub (Mar 2, 2017): I agree, it would be great to have a Telegram integration. I've been poking around the Telegram Bot API. Here's the UI flow I think I would be able to implement: * From your Telegram client, invite "HealthchecksBot" to a group. It gets added as a member with no access to group messages ![members](https://cloud.githubusercontent.com/assets/661859/23503388/3db07f84-ff44-11e6-8c57-0032be321731.png) * type `/start` command (or `/start@HealthchecksBot` if multiple bots present) in the group. Bot responds with a confirmation link. ![mstart](https://cloud.githubusercontent.com/assets/661859/23503485/a22f53cc-ff44-11e6-9094-71ce84204a34.png) * Click/tap on confirmation link, healthchecks.io opens in browser asking you to confirm the new integration. Select "Done" and it's done. Sounds good? Are there maybe examples of Telegram bots where the initial setup is more streamlined? This would work for 1-to-1 chats and for groups. I could not find a good solution for channels – bot accounts can only be added as administrators not as regular users, so there are privacy problems.
Author
Owner

@snakewa commented on GitHub (Mar 4, 2017):

So far I have a work around for this is to use HornBot(@bullhorn_bot) to bridge the webhook integration.

Add HornBot to a group and you will get a webhook url

fill it to webhook integration up and down's field and here is a example for the body field:
{"text":"$NAME status is changed to $STATUS"}
And it should work:
screen shot 2017-03-04 at 6 53 53 pm

Of course it will be nice to have an official bot or integration

<!-- gh-comment-id:284145090 --> @snakewa commented on GitHub (Mar 4, 2017): So far I have a work around for this is to use HornBot(@bullhorn_bot) to bridge the webhook integration. Add HornBot to a group and you will get a webhook url fill it to webhook integration up and down's field and here is a example for the body field: `{"text":"$NAME status is changed to $STATUS"} ` And it should work: <img width="708" alt="screen shot 2017-03-04 at 6 53 53 pm" src="https://cloud.githubusercontent.com/assets/83506/23578294/b53134e2-010e-11e7-8087-697a0febe520.png"> Of course it will be nice to have an official bot or integration
Author
Owner

@bellini666 commented on GitHub (Apr 3, 2017):

+1, this would be great!

<!-- gh-comment-id:291152935 --> @bellini666 commented on GitHub (Apr 3, 2017): +1, this would be great!
Author
Owner

@cuu508 commented on GitHub (May 11, 2017):

A preliminary version of Telegram integration is ready for testing on healthchecks.io.

@brain-1 @snakewa @hackedbellini when/if you get a chance, would be great to test it out!

<!-- gh-comment-id:300751685 --> @cuu508 commented on GitHub (May 11, 2017): A preliminary version of Telegram integration is ready for testing on healthchecks.io. @brain-1 @snakewa @hackedbellini when/if you get a chance, would be great to test it out!
Author
Owner

@iphoting commented on GitHub (May 11, 2017):

Consider allowing the bot name to be customised, next to telegram token.

<!-- gh-comment-id:300776650 --> @iphoting commented on GitHub (May 11, 2017): Consider allowing the bot name to be customised, next to telegram token.
Author
Owner

@cuu508 commented on GitHub (May 11, 2017):

Good point. Also I should update README with the manual steps involved in setting up the bot -- talking to the Botfather, generating access token, setting webhook address.

<!-- gh-comment-id:300782378 --> @cuu508 commented on GitHub (May 11, 2017): Good point. Also I should update README with the manual steps involved in setting up the bot -- talking to the Botfather, generating access token, setting webhook address.
Author
Owner

@Braintelligence commented on GitHub (Dec 27, 2017):

@cuu508 I'm sorry to dig this up, but for some reason I can't get Telegram to work on a self-hosted installation. I provided the TELEGRAM_BOT_NAME and TELEGRAM_TOKEN in the settings.py and the integration appears online but /starting the bot doesn't do anything.

How can I debug this? =/

<!-- gh-comment-id:354129904 --> @Braintelligence commented on GitHub (Dec 27, 2017): @cuu508 I'm sorry to dig this up, but for some reason I can't get Telegram to work on a self-hosted installation. I provided the TELEGRAM_BOT_NAME and TELEGRAM_TOKEN in the settings.py and the integration appears online but `/start`ing the bot doesn't do anything. How can I debug this? =/
Author
Owner

@cuu508 commented on GitHub (Dec 27, 2017):

From README:

Now the tricky part: when a Telegram user talks to your bot, Telegram will use a webhook to forward received messages to your healthchecks instance. For this to work, your healthchecks instance needs to be publicly accessible over HTTPS. Using the setWebhook API call set the bot's webhook to https://yourdomain.com/integrations/telegram/bot/.

Did you complete this step? If yes, can you see Telegram's requests to https://yourdomain.com/integrations/telegram/bot/ in your webserver's access logs?

<!-- gh-comment-id:354132795 --> @cuu508 commented on GitHub (Dec 27, 2017): From README: > Now the tricky part: when a Telegram user talks to your bot, Telegram will use a webhook to forward received messages to your healthchecks instance. For this to work, your healthchecks instance needs to be publicly accessible over HTTPS. Using the setWebhook API call set the bot's webhook to https://yourdomain.com/integrations/telegram/bot/. Did you complete this step? If yes, can you see Telegram's requests to `https://yourdomain.com/integrations/telegram/bot/` in your webserver's access logs?
Author
Owner

@Braintelligence commented on GitHub (Dec 27, 2017):

The step Using the setWebhook API call set the bot's webhook to https://yourdomain.com/integrations/telegram/bot/. is actually new to me. I didn't need to do this for other self-hosted apps that integrate Telegram.
How do I go about doing this manually? Do I need to create some JSCode and run it? Or is there a bot command for accessing the API?

<!-- gh-comment-id:354133391 --> @Braintelligence commented on GitHub (Dec 27, 2017): The step `Using the setWebhook API call set the bot's webhook to https://yourdomain.com/integrations/telegram/bot/.` is actually new to me. I didn't need to do this for other self-hosted apps that integrate Telegram. How do I go about doing this manually? Do I need to create some JSCode and run it? Or is there a bot command for accessing the API?
Author
Owner

@cuu508 commented on GitHub (Dec 27, 2017):

There are some examples in Telegram's documentation here: https://core.telegram.org/bots/webhooks
For example, using curl: curl -F “url=https://<YOURDOMAIN.EXAMPLE>/<WEBHOOKLOCATION>" https://api.telegram.org/bot<YOURTOKEN>/setWebhook

To make this easier, I wrote a small Django management command which will take care of this step. With SITE_NAME and TELEGRAM_TOKEN set to correct values, run:

./manage.py settelegramwebhook

If all goes well, the command will print out:

Done, Telegram's webhook set to: https://67acfd1a.ngrok.io/integrations/telegram/bot/

(I was testing this locally and was using ngrok proxy so Telegram can talk to my local healthchecks instance)

After this step you can try sending /start to the bot again.
If the settelegramwebhook command works for you, I will update README with similar instructions.

<!-- gh-comment-id:354139539 --> @cuu508 commented on GitHub (Dec 27, 2017): There are some examples in Telegram's documentation here: https://core.telegram.org/bots/webhooks For example, using curl: `curl -F “url=https://<YOURDOMAIN.EXAMPLE>/<WEBHOOKLOCATION>" https://api.telegram.org/bot<YOURTOKEN>/setWebhook` To make this easier, I wrote a small Django management command which will take care of this step. With `SITE_NAME` and `TELEGRAM_TOKEN` set to correct values, run: ./manage.py settelegramwebhook If all goes well, the command will print out: Done, Telegram's webhook set to: https://67acfd1a.ngrok.io/integrations/telegram/bot/ (I was testing this locally and was using ngrok proxy so Telegram can talk to my local healthchecks instance) After this step you can try sending `/start` to the bot again. If the `settelegramwebhook` command works for you, I will update README with similar instructions.
Author
Owner

@Braintelligence commented on GitHub (Dec 27, 2017):

This worked, thanks a lot!

<!-- gh-comment-id:354181510 --> @Braintelligence commented on GitHub (Dec 27, 2017): This worked, thanks a lot!
Author
Owner

@Jacq commented on GitHub (Feb 13, 2019):

Is it possible to use the polling approach instead of the webhook by using the getUpdates method? https://core.telegram.org/bots/api#getting-updates

Thanks for the great work!
Cheers

<!-- gh-comment-id:463415831 --> @Jacq commented on GitHub (Feb 13, 2019): Is it possible to use the polling approach instead of the webhook by using the getUpdates method? https://core.telegram.org/bots/api#getting-updates Thanks for the great work! Cheers
Author
Owner

@cuu508 commented on GitHub (Feb 14, 2019):

It's only webhooks at the moment.
Are you running it in an environment where inbound http requests from Telegram are not possible?

<!-- gh-comment-id:463538811 --> @cuu508 commented on GitHub (Feb 14, 2019): It's only webhooks at the moment. Are you running it in an environment where inbound http requests from Telegram are not possible?
Author
Owner

@Jacq commented on GitHub (Feb 14, 2019):

Yes mainly for security reasons no external ports/services are exposed, I was testing healthchechks to monitor some cron jobs.

<!-- gh-comment-id:463540921 --> @Jacq commented on GitHub (Feb 14, 2019): Yes mainly for security reasons no external ports/services are exposed, I was testing healthchechks to monitor some cron jobs.
Author
Owner

@cuu508 commented on GitHub (Feb 14, 2019):

For a one-off, you could add the integration manually in Django admin.

  1. Create a telegram bot, get its token
  2. Add the bot to a group and send them a dummy message
  3. Go to https://api.telegram.org/botXXX:YYYY/getUpdates and look up the group's id
  4. Add a new channel in https://your-healthchecks-instance.internal/admin/api/channel/add/

In the new channel form, use these values:

  • Project: look up your project's id
  • Kind: Telegram
  • Value: {"id": group-id-here, "type": "group", "name": "group name here"}

You should then see the integration the Healthchecks dashboard, and can then assign checks to it.

<!-- gh-comment-id:463548932 --> @cuu508 commented on GitHub (Feb 14, 2019): For a one-off, you could add the integration manually in Django admin. 1. Create a telegram bot, get its token 2. Add the bot to a group and send them a dummy message 3. Go to https://api.telegram.org/botXXX:YYYY/getUpdates and look up the group's id 4. Add a new channel in https://your-healthchecks-instance.internal/admin/api/channel/add/ In the new channel form, use these values: * Project: look up your project's id * Kind: Telegram * Value: {"id": group-id-here, "type": "group", "name": "group name here"} You should then see the integration the Healthchecks dashboard, and can then assign checks to it.
Author
Owner

@esturniolo commented on GitHub (Feb 21, 2021):

Hi. Sorry for bring this old post, but I can't make it work.

I add manually all that you say, but I get always Received status code 404 with a message: "Not Found"
But if I send a manual request curl -X POST "https://api.telegram.org/botXXX:YYYYYY/sendMessage" -d "chat_id=-478151423&text=my sample text", it works and I receive the message in the group where is the Bot.

Do you have any idea about this?

I tried with differents bots and projects with the same luck.

Thanks.

For a one-off, you could add the integration manually in Django admin.

1. Create a telegram bot, get its token

2. Add the bot to a group and send them a dummy message

3. Go to https://api.telegram.org/botXXX:YYYY/getUpdates and look up the group's id

4. Add a new channel in https://your-healthchecks-instance.internal/admin/api/channel/add/

In the new channel form, use these values:

* Project: look up your project's id

* Kind: Telegram

* Value: {"id": group-id-here, "type": "group", "name": "group name here"}

You should then see the integration the Healthchecks dashboard, and can then assign checks to it.

<!-- gh-comment-id:782921532 --> @esturniolo commented on GitHub (Feb 21, 2021): Hi. Sorry for bring this old post, but I can't make it work. I add manually all that you say, but I get always `Received status code 404 with a message: "Not Found"` But if I send a manual request `curl -X POST "https://api.telegram.org/botXXX:YYYYYY/sendMessage" -d "chat_id=-478151423&text=my sample text"`, it works and I receive the message in the group where is the Bot. Do you have any idea about this? I tried with differents bots and projects with the same luck. Thanks. > For a one-off, you could add the integration manually in Django admin. > > 1. Create a telegram bot, get its token > > 2. Add the bot to a group and send them a dummy message > > 3. Go to https://api.telegram.org/botXXX:YYYY/getUpdates and look up the group's id > > 4. Add a new channel in https://your-healthchecks-instance.internal/admin/api/channel/add/ > > > In the new channel form, use these values: > > * Project: look up your project's id > > * Kind: Telegram > > * Value: {"id": group-id-here, "type": "group", "name": "group name here"} > > > You should then see the integration the Healthchecks dashboard, and can then assign checks to it.
Author
Owner

@cuu508 commented on GitHub (Mar 2, 2021):

@esturniolo have you set settings.TELEGRAM_TOKEN?

<!-- gh-comment-id:788807565 --> @cuu508 commented on GitHub (Mar 2, 2021): @esturniolo have you set `settings.TELEGRAM_TOKEN`?
Author
Owner

@cuu508 commented on GitHub (Mar 5, 2021):

It depends on the Dockerfile you are using.
If you are using the Dockerfile from this repository with Docker Compose, you would put it in the .env file

<!-- gh-comment-id:791615228 --> @cuu508 commented on GitHub (Mar 5, 2021): It depends on the Dockerfile you are using. If you are using [the Dockerfile from this repository](https://github.com/healthchecks/healthchecks/tree/9fd9c8e4efd0c87c015215ae56eada88a7d07b6b/docker) with Docker Compose, you would put it in the [.env file](https://github.com/healthchecks/healthchecks/blob/9fd9c8e4efd0c87c015215ae56eada88a7d07b6b/docker/.env#L57)
Author
Owner

@zkmusa commented on GitHub (Apr 19, 2021):

For a one-off, you could add the integration manually in Django admin.

  1. Create a telegram bot, get its token
  2. Add the bot to a group and send them a dummy message
  3. Go to https://api.telegram.org/botXXX:YYYY/getUpdates and look up the group's id
  4. Add a new channel in https://your-healthchecks-instance.internal/admin/api/channel/add/

In the new channel form, use these values:

  • Project: look up your project's id
  • Kind: Telegram
  • Value: {"id": group-id-here, "type": "group", "name": "group name here"}

You should then see the integration the Healthchecks dashboard, and can then assign checks to it.

Thank you. This worked for me.

<!-- gh-comment-id:822850650 --> @zkmusa commented on GitHub (Apr 19, 2021): > For a one-off, you could add the integration manually in Django admin. > > 1. Create a telegram bot, get its token > 2. Add the bot to a group and send them a dummy message > 3. Go to https://api.telegram.org/botXXX:YYYY/getUpdates and look up the group's id > 4. Add a new channel in https://your-healthchecks-instance.internal/admin/api/channel/add/ > > In the new channel form, use these values: > > * Project: look up your project's id > * Kind: Telegram > * Value: {"id": group-id-here, "type": "group", "name": "group name here"} > > You should then see the integration the Healthchecks dashboard, and can then assign checks to it. Thank you. This worked for me.
Author
Owner

@cgarnier commented on GitHub (Mar 7, 2022):

I use the docker image, i never been able to make works the telegram integration. I think, the doc is just not complete.

I made work telegram notification through the webhook integration.

<!-- gh-comment-id:1061016192 --> @cgarnier commented on GitHub (Mar 7, 2022): I use the docker image, i never been able to make works the telegram integration. I think, the doc is just not complete. I made work telegram notification through the webhook integration.
Author
Owner

@cuu508 commented on GitHub (Mar 7, 2022):

Hi @cgarnier, in case you remember – what problem did you run into when setting up the Telegram integration?

<!-- gh-comment-id:1061018106 --> @cuu508 commented on GitHub (Mar 7, 2022): Hi @cgarnier, in case you remember – what problem did you run into when setting up the Telegram integration?
Author
Owner

@cgarnier commented on GitHub (Mar 7, 2022):

I start by reading this /integrations/add_telegram/ doc. I follow the bot link but it bring nowhere ( https://t.me/Backup%20Bot ).
I dont understand how to find that bot.

<!-- gh-comment-id:1061025135 --> @cgarnier commented on GitHub (Mar 7, 2022): I start by reading this `/integrations/add_telegram/` doc. I follow the bot link but it bring nowhere ( https://t.me/Backup%20Bot ). I dont understand how to find that bot.
Author
Owner

@cuu508 commented on GitHub (Mar 7, 2022):

Have you seen the instructions in README? https://github.com/healthchecks/healthchecks#telegram

<!-- gh-comment-id:1061040962 --> @cuu508 commented on GitHub (Mar 7, 2022): Have you seen the instructions in README? https://github.com/healthchecks/healthchecks#telegram
Author
Owner

@retifrav commented on GitHub (Mar 11, 2022):

The step Using the setWebhook API call set the bot's webhook to https://yourdomain.com/integrations/telegram/bot/. is actually new to me. I didn't need to do this for other self-hosted apps that integrate Telegram.

Indeed, sending a message via Telegram bot is merely sending a POST HTTP request to Telegram's API, there is no need to register a webhook and rely on the Telegram bot backend service, which Healthchecks is apparently implementing behind the scenes. The latter can be convenient though, if you'd like several users to be able to add this bot to their chats.

So if you need to get Telegram notifications for only one recipient (personal chat, group chat or a channel), then you can use a Webhook integration instead. Also nothing stops you from adding several Webhook integrations with the same bot but different chat_id's.

You can take a look at how I did it here: #618.


...oops, didn't read the thread carefully, this has been already suggested above.

<!-- gh-comment-id:1065040118 --> @retifrav commented on GitHub (Mar 11, 2022): > The step Using the setWebhook API call set the bot's webhook to https://yourdomain.com/integrations/telegram/bot/. is actually new to me. I didn't need to do this for other self-hosted apps that integrate Telegram. Indeed, sending a message via Telegram bot is merely sending a POST HTTP request to Telegram's API, there is no need to register a webhook and rely on the Telegram bot backend service, which Healthchecks is apparently implementing behind the scenes. The latter can be convenient though, if you'd like several users to be able to add this bot to their chats. So if you need to get Telegram notifications for only one recipient (*personal chat, group chat or a channel*), then you can use a Webhook integration instead. Also nothing stops you from adding several Webhook integrations with the same bot but different `chat_id`'s. You can take a look at how I did it here: #618. --- ...oops, didn't read the thread carefully, this has been [already suggested](#issuecomment-463548932) above.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/healthchecks#78
No description provided.