Help with setting up discord outgoing webhook

Describe the issue/error/question

I am trying to set up outgoing webhook on my discord server by setting the INTERACTIONS ENDPOINT URL for my discord bot. (Discord Developer Portal)

I seem to have set everything correctly, but for some reason Discord is still not happy with the response of the webhook, and consequently rejects the URL, with the error:

{
    "code": 50035,
    "errors": {
        "interactions_endpoint_url": {
            "_errors": [
                {
                    "code": "APPLICATION_INTERACTIONS_ENDPOINT_URL_INVALID",
                    "message": "The specified interactions endpoint url could not be verified."
                }
            ]
        }
    },
    "message": "Invalid Form Body"
}

Please share the workflow

The thing is, when i tried to replicate this scenario in Replit.com, it works just fine with their URL!
This is the code used there:

const express = require('express');
const bodyParser = require('body-parser');

const { verifyKey, InteractionType, InteractionResponseType } = require("discord-interactions");

const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.post('/', async (req, res) => {
  const signature = req.get("x-signature-ed25519") ;
  const timestamp = req.get("x-signature-timestamp") ;
  const public_key = '<PUBLIC KEY>';
  const data = JSON.stringify(req.body);
  
  const isValidRequest = await verifyKey(data, signature, timestamp, public_key);
  const result = {};
  if(req.body.type) result.type = req.body.type;
  
  if(req.body.type == InteractionType.PING){
    result.type = InteractionResponseType.PONG
  }
  
  if (!isValidRequest) {
    res.type('application/json').status(401).send(result);
  }
  res.type('application/json').status(200).send(result);
  
});

app.listen(3000, () => console.log('server started'));

Can anyone who might have experience with Discord/Express/Nodejs throw some light on the possible issue with my setup or n8n in general?

Thanks.

Information on your n8n setup

  • n8n version: 0.183.0
  • Database you’re using (default: SQLite): Postgres
  • Running n8n with the execution process [own(default), main]: own
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker

Hi @shrey-42, perhaps it’s worth asking on the n8n Discord server as well? I am not usually a fan of cross-posts but in this case you might reach a few folks more familiar with Discord’s API concepts directly on the platform.

Hi,
I have the same issues to link my discord application to my n8n webhook…
Did you find a solution to fix this issu ?
Best,

I’m having the same issue, have you found a solution yet?

same? did you get to a solution?

Yes, put this code in an execution node:

If the execution node gives no output, the verification was successful. You could check this via an IF node as following:
image

1 Like

Hey @MeesJ,

After configuring the Interactions endpoint url, how do I receive the events? Do I need to configure something else?

I have already activated and performed this check with my webhook

One more question, do you know how I can listen to specific triggers?

Example: when someone joins the server, enters a voice room or sends a message on a channel?

Sorry for my late response!

You can just follow the Discord documentation on this after setting up the interactions endpoint URL. It works the same as using the gateway.

This is only possible via the gateway, which currently is an unsupported feature in n8n. There is a community node for it, but it has some issues with triggers making it not work as it should.