Discord Webhooks?

So, I was playing around with webhooks, thinking I had finally found a way to link Sonarr’s updates to my little group’s main chat system, without having an awkward push notification system.

But I’m not sure if they’re working too well.

First off, Discord uses JSON, so the PUT feature is out the window. The post however, gives a 400 error, as follows:

Invalid request Validation failed: -- Unable to post to webhook: REST request failed: [400] [POST] at [https://discordapp.com/api/webhooks/...]

I’m not privy to the webhook structure or how you’re sending this stuff out, so unfortunately there wasn’t too much for me to do, /but/, while digging through the forums I did find a thread about the webhooks and slack (similar to Discord), that was using a mediator to better configure the hook. The new URL then became:

https://projectfive.nl/inc/slackpush.php?slack=https://discordapp.com/api/webhooks/...&type=sonarr

And I was ecstatic, as Sonarr was reporting a successful test! However, it seemed to be a bit too early to celebrate, as despite the success, the messages are not making it to Discord.

So! Rambling aside, I was wondering how much work it would be to either A) expand the webhooks to properly interface with whatever it is Discord is doing, or B) add some direct connection service/profile to Discord, either directly or perhaps something a bot could utilize. Cheers, and as always, thanks for the amazing work you guys have done.

The webhook notifications in Sonarr sends a specific structured message to the endpoint specified, the content is JSON with a structure similar to:

{
  "eventType": "Grab",
  "series": {
    "id": 1
    ...
  },
  "episodes"" [
    {
      "id": 1
      ...
    }
  ]
}

You can use http://requestb.in/ to get the actual message if you want to see it. PUT and POST are just different ways to send it to the server, they both send JSON.

Unless Discord and Slack have the same API endpoint for sending notifications then that wouldn’t work. Sonarr reports a success because it was able to send the request to the server you told it to, but that server failed to send it to Discord (not all that surprising because it’s for Slack, not Discord).

It would need to be a custom implementation, same as Slack notifications in Sonarr are. A bot would take Sonarr’s Webhook message and convert that the structure that Discord needs and then send it to the Discord API. The effort required to add it to Sonarr probably wouldn’t be too high, but not something we’ll be looking at adding immediately. I’ve created an issue on Github and anyone could implement it.

Understood. Thanks for the heads up and quick response!

2 Likes

While looking into this, I found the Discord API docs section that showed you can append ‘/slack’ to the end of the Webhook URL provided to you and it will execute Slack-compatible webhooks. I haven’t played with it beyond sending a test message but seemed to work.

It works! \o/ The magic slack flag was all that was missing, so thanks for that final piece of the puzzle.

This workaround seems to be satisfactory, so this topic can be marked as resolved for now. Cheers!

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.