diff --git a/hc/front/tests/test_add_telegram.py b/hc/front/tests/test_add_telegram.py index d92f6a9e..f410bc7f 100644 --- a/hc/front/tests/test_add_telegram.py +++ b/hc/front/tests/test_add_telegram.py @@ -61,7 +61,7 @@ class AddTelegramTestCase(BaseTestCase): "message": {"chat": {"id": 123, "type": "group"}} })) - # bad message type + # bad chat type samples.append(json.dumps({ "message": { "chat": {"id": 123, "type": "invalid"}, @@ -73,4 +73,10 @@ class AddTelegramTestCase(BaseTestCase): r = self.client.post("/integrations/telegram/bot/", sample, 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) + diff --git a/hc/front/views.py b/hc/front/views.py index 727fcb07..89313c06 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -838,7 +838,9 @@ def telegram_bot(request): except ValueError: return HttpResponseBadRequest() 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"]: return HttpResponse()