diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fe2c3a1..9d8ebac6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file. - Indicate a started check with a progress spinner under status icon (#338) - Added "Docs > Reliability Tips" page - Spike.sh integration (#402) +- Updated Discord integration to use discord.com instead of discordapp.com ### Bug Fixes - Removing Pager Team integration, project appears to be discontinued diff --git a/hc/api/models.py b/hc/api/models.py index ebadaa5b..08bbde94 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -585,7 +585,14 @@ class Channel(models.Model): def discord_webhook_url(self): assert self.kind == "discord" doc = json.loads(self.value) - return doc["webhook"]["url"] + url = doc["webhook"]["url"] + + # Discord migrated to discord.com, + # and is dropping support for discordapp.com on 7 November 2020 + if url.startswith("https://discordapp.com/"): + url = "https://discord.com/" + url[23:] + + return url @property def discord_webhook_id(self): diff --git a/hc/api/tests/test_notify.py b/hc/api/tests/test_notify.py index d8649cd1..b7ec1c8b 100644 --- a/hc/api/tests/test_notify.py +++ b/hc/api/tests/test_notify.py @@ -569,6 +569,22 @@ class NotifyTestCase(BaseTestCase): fields = {f["title"]: f["value"] for f in attachment["fields"]} self.assertEqual(fields["Last Ping"], "an hour ago") + @patch("hc.api.transports.requests.request") + def test_discord_rewrites_discordapp_com(self, mock_post): + v = json.dumps({"webhook": {"url": "https://discordapp.com/foo"}}) + self._setup_data("discord", v) + mock_post.return_value.status_code = 200 + + self.channel.notify(self.check) + assert Notification.objects.count() == 1 + + args, kwargs = mock_post.call_args + url = args[1] + + # discordapp.com is deprecated. For existing webhook URLs, wwe should + # rewrite discordapp.com to discord.com: + self.assertEqual(url, "https://discord.com/foo/slack") + @patch("hc.api.transports.requests.request") def test_pushbullet(self, mock_post): self._setup_data("pushbullet", "fake-token")