forked from GithubBackups/healthchecks
settelegramwebhook
now sends a correct "allowed_updates" field.
This commit is contained in:
parent
c6e35c9b39
commit
fc176cd832
@ -14,9 +14,13 @@ class Command(BaseCommand):
|
||||
if settings.TELEGRAM_TOKEN is None:
|
||||
return "Abort: settings.TELEGRAM_TOKEN is not set"
|
||||
|
||||
form = {"url": settings.SITE_ROOT + reverse("hc-telegram-webhook")}
|
||||
form = {
|
||||
"url": settings.SITE_ROOT + reverse("hc-telegram-webhook"),
|
||||
"allowed_updates": ["message"]
|
||||
}
|
||||
|
||||
url = SETWEBHOOK_TMPL % settings.TELEGRAM_TOKEN
|
||||
r = requests.post(url, data=form)
|
||||
r = requests.post(url, json=form)
|
||||
|
||||
if r.status_code != 200:
|
||||
return "Fail: status=%d, %s" % (r.status_code, r.content)
|
||||
|
@ -16,7 +16,7 @@ telegram_callback = {
|
||||
},
|
||||
"text": {"type": "string"}
|
||||
},
|
||||
"required": ["chat"]
|
||||
"required": ["chat", "text"]
|
||||
}
|
||||
},
|
||||
"required": ["message"]
|
||||
|
@ -56,12 +56,9 @@ class AddTelegramTestCase(BaseTestCase):
|
||||
def test_bot_handles_bad_message(self, mock_get):
|
||||
samples = ["", "{}"]
|
||||
|
||||
# text is not string
|
||||
# text is missing
|
||||
samples.append(json.dumps({
|
||||
"message": {
|
||||
"chat": {"id": 123, "type": "invalid"},
|
||||
"text": 123
|
||||
}
|
||||
"message": {"chat": {"id": 123, "type": "group"}}
|
||||
}))
|
||||
|
||||
# bad message type
|
||||
@ -77,16 +74,3 @@ class AddTelegramTestCase(BaseTestCase):
|
||||
content_type="application/json")
|
||||
|
||||
self.assertEqual(r.status_code, 400)
|
||||
|
||||
@patch("hc.api.transports.requests.request")
|
||||
def test_it_handles_missing_text(self, mock_get):
|
||||
data = {
|
||||
"message": {
|
||||
"chat": {"id": 123, "title": "My Group", "type": "group"}
|
||||
}
|
||||
}
|
||||
r = self.client.post("/integrations/telegram/bot/", json.dumps(data),
|
||||
content_type="application/json")
|
||||
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertFalse(mock_get.called)
|
||||
|
@ -823,8 +823,7 @@ def telegram_bot(request):
|
||||
except jsonschema.ValidationError:
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
text = doc["message"].get("text", "")
|
||||
if "/start" not in text:
|
||||
if "/start" not in doc["message"]["text"]:
|
||||
return HttpResponse()
|
||||
|
||||
chat = doc["message"]["chat"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user