Browse Source

`settelegramwebhook` now sends a correct "allowed_updates" field.

pull/149/head
Pēteris Caune 7 years ago
parent
commit
fc176cd832
4 changed files with 10 additions and 23 deletions
  1. +6
    -2
      hc/api/management/commands/settelegramwebhook.py
  2. +1
    -1
      hc/front/schemas.py
  3. +2
    -18
      hc/front/tests/test_add_telegram.py
  4. +1
    -2
      hc/front/views.py

+ 6
- 2
hc/api/management/commands/settelegramwebhook.py View File

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


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

@ -16,7 +16,7 @@ telegram_callback = {
},
"text": {"type": "string"}
},
"required": ["chat"]
"required": ["chat", "text"]
}
},
"required": ["message"]


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

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

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

@ -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…
Cancel
Save