Browse Source

When we don't recognize a message from Telegram, respond with 200 OK so Telegram doesn't keep retrying.

pull/178/head
Pēteris Caune 7 years ago
parent
commit
5f908a01e4
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 11 additions and 3 deletions
  1. +8
    -2
      hc/front/tests/test_add_telegram.py
  2. +3
    -1
      hc/front/views.py

+ 8
- 2
hc/front/tests/test_add_telegram.py View File

@ -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)

+ 3
- 1
hc/front/views.py View File

@ -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()


Loading…
Cancel
Save