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.