Browse Source

Experimental `settelegramwebhook` management command

pull/149/head
Pēteris Caune 7 years ago
parent
commit
ebbc898d02
2 changed files with 25 additions and 1 deletions
  1. +24
    -0
      hc/api/management/commands/settelegramwebhook.py
  2. +1
    -1
      hc/front/urls.py

+ 24
- 0
hc/api/management/commands/settelegramwebhook.py View File

@ -0,0 +1,24 @@
from django.conf import settings
from django.core.management.base import BaseCommand
from django.urls import reverse
import requests
SETWEBHOOK_TMPL = "https://api.telegram.org/bot%s/setWebhook"
class Command(BaseCommand):
help = "Set up telegram bot's webhook address"
def handle(self, *args, **options):
if settings.TELEGRAM_TOKEN is None:
return "Abort: settings.TELEGRAM_TOKEN is not set"
form = {"url": settings.SITE_ROOT + reverse("hc-telegram-webhook")}
url = SETWEBHOOK_TMPL % settings.TELEGRAM_TOKEN
r = requests.post(url, data=form)
if r.status_code != 200:
return "Fail: status=%d, %s" % (r.status_code, r.content)
return "Done, Telegram's webhook set to: %s" % form["url"]

+ 1
- 1
hc/front/urls.py View File

@ -27,7 +27,7 @@ channel_urls = [
url(r'^add_pushover/$', views.add_pushover, name="hc-add-pushover"),
url(r'^add_opsgenie/$', views.add_opsgenie, name="hc-add-opsgenie"),
url(r'^add_victorops/$', views.add_victorops, name="hc-add-victorops"),
url(r'^telegram/bot/$', views.telegram_bot),
url(r'^telegram/bot/$', views.telegram_bot, name="hc-telegram-webhook"),
url(r'^add_telegram/$', views.add_telegram, name="hc-add-telegram"),
url(r'^add_sms/$', views.add_sms, name="hc-add-sms"),
url(r'^([\w-]+)/checks/$', views.channel_checks, name="hc-channel-checks"),


Loading…
Cancel
Save