mirror of
https://github.com/healthchecks/healthchecks.git
synced 2024-11-24 16:26:49 +00:00
52ab8c4703
This results in changes in other places too: * curl.post() does not accept `data` as positional arg, it must now be a keyword argument * we need asserts and if clauses in a few places to make sure we are not passing `None` in the arguments to hc.lib.curl.request
33 lines
935 B
Python
33 lines
935 B
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from django.conf import settings
|
|
from django.core.management.base import BaseCommand
|
|
from django.urls import reverse
|
|
|
|
from hc.lib import curl
|
|
|
|
SETWEBHOOK_TMPL = "https://api.telegram.org/bot%s/setWebhook"
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Set up telegram bot's webhook address"
|
|
|
|
def handle(self, **options: Any) -> str:
|
|
if settings.TELEGRAM_TOKEN is None:
|
|
return "Abort: settings.TELEGRAM_TOKEN is not set"
|
|
|
|
form = {
|
|
"url": settings.SITE_ROOT + reverse("hc-telegram-webhook"),
|
|
"allowed_updates": ["message", "channel_post"],
|
|
}
|
|
|
|
url = SETWEBHOOK_TMPL % settings.TELEGRAM_TOKEN
|
|
r = curl.post(url, json=form)
|
|
|
|
if r.status_code != 200:
|
|
return "Fail: status=%d, %s" % (r.status_code, r.content.decode())
|
|
|
|
return "Done, Telegram's webhook set to: %s" % form["url"]
|