forked from GithubBackups/healthchecks
When we don't recognize a message from Telegram, respond with 200 OK so Telegram doesn't keep retrying.
This commit is contained in:
parent
6bf6ab6479
commit
5f908a01e4
@ -61,7 +61,7 @@ class AddTelegramTestCase(BaseTestCase):
|
|||||||
"message": {"chat": {"id": 123, "type": "group"}}
|
"message": {"chat": {"id": 123, "type": "group"}}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
# bad message type
|
# bad chat type
|
||||||
samples.append(json.dumps({
|
samples.append(json.dumps({
|
||||||
"message": {
|
"message": {
|
||||||
"chat": {"id": 123, "type": "invalid"},
|
"chat": {"id": 123, "type": "invalid"},
|
||||||
@ -73,4 +73,10 @@ class AddTelegramTestCase(BaseTestCase):
|
|||||||
r = self.client.post("/integrations/telegram/bot/", sample,
|
r = self.client.post("/integrations/telegram/bot/", sample,
|
||||||
content_type="application/json")
|
content_type="application/json")
|
||||||
|
|
||||||
self.assertEqual(r.status_code, 400)
|
if sample == "":
|
||||||
|
# Bad JSON payload
|
||||||
|
self.assertEqual(r.status_code, 400)
|
||||||
|
else:
|
||||||
|
# JSON decodes but message structure not recognized
|
||||||
|
self.assertEqual(r.status_code, 200)
|
||||||
|
|
||||||
|
@ -838,7 +838,9 @@ def telegram_bot(request):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
except jsonschema.ValidationError:
|
except jsonschema.ValidationError:
|
||||||
return HttpResponseBadRequest()
|
# We don't recognize the message format, but don't want Telegram
|
||||||
|
# retrying this over and over again, so respond with 200 OK
|
||||||
|
return HttpResponse()
|
||||||
|
|
||||||
if "/start" not in doc["message"]["text"]:
|
if "/start" not in doc["message"]["text"]:
|
||||||
return HttpResponse()
|
return HttpResponse()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user