diff --git a/README.md b/README.md index f03cf518..9f4a1076 100644 --- a/README.md +++ b/README.md @@ -230,3 +230,23 @@ To enable Pushover integration, you will need to: subscription type * add the application token and subscription URL to `hc/local_settings.py`, as `PUSHOVER_API_TOKEN` and `PUSHOVER_SUBSCRIPTION_URL` + +### Telegram + +* Create a Telegram bot by talking to the +[BotFather](https://core.telegram.org/bots#6-botfather). Set the bot's name, +description, user picture, and add a "/start" command. +* After creating the bot you will have the bot's name and token. Add them +to your `hc/local_settings.py` file as `TELEGRAM_BOT_NAME` and +`TELEGRAM_TOKEN` fields. +* 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](https://core.telegram.org/bots/api#setwebhook) API call +set the bot's webhook to `https://yourdomain.com/integrations/telegram/bot/`. + + + + + diff --git a/hc/front/tests/test_add_telegram.py b/hc/front/tests/test_add_telegram.py index dd79529b..35b138f1 100644 --- a/hc/front/tests/test_add_telegram.py +++ b/hc/front/tests/test_add_telegram.py @@ -12,7 +12,7 @@ class AddTelegramTestCase(BaseTestCase): def test_instructions_work(self): self.client.login(username="alice@example.org", password="password") r = self.client.get(self.url) - self.assertContains(r, "start@HealthchecksBot") + self.assertContains(r, "start@ExampleBot") def test_it_shows_confirmation(self): payload = signing.dumps((123, "group", "My Group")) diff --git a/hc/front/views.py b/hc/front/views.py index bd67dd6c..5b42cfeb 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -804,7 +804,8 @@ def add_telegram(request): ctx = { "chat_id": chat_id, "chat_type": chat_type, - "chat_name": chat_name + "chat_name": chat_name, + "bot_name": settings.TELEGRAM_BOT_NAME } return render(request, "integrations/add_telegram.html", ctx) diff --git a/hc/settings.py b/hc/settings.py index 9bd00a4b..c2c49766 100644 --- a/hc/settings.py +++ b/hc/settings.py @@ -154,6 +154,7 @@ PUSHBULLET_CLIENT_ID = None PUSHBULLET_CLIENT_SECRET = None # Telegram integration -- override in local_settings.py +TELEGRAM_BOT_NAME = "ExampleBot" TELEGRAM_TOKEN = None if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")): diff --git a/templates/integrations/add_telegram.html b/templates/integrations/add_telegram.html index 00317d62..836795e2 100644 --- a/templates/integrations/add_telegram.html +++ b/templates/integrations/add_telegram.html @@ -42,13 +42,13 @@ 1

From your Telegram client, invite - HealthchecksBot to a group. It will get added + {{ bot_name }} to a group. It will get added as a member with no access to group messages.

Alternatively, if you want notifications sent to yourself directly, start a conversation with - HealthchecksBot. + {{ bot_name }}.

@@ -63,7 +63,7 @@ 2

Type /start command. If there are multiple bots in the group, type - /start@HealthchecksBot instead. + /start@{{ bot_name }} instead.

The bot will respond with a confirmation link.