#new webhook events
6 messages · Page 1 of 1 (latest)
Read the second bullet point
const express = require('express');
const localtunnel = require('localtunnel');
const app = express();
const PORT = 3000;
app.use(express.json());
app.post('/webhook', (req, res) => {
const payload = req.body;
const signature = req.headers['x-signature-ed25519'];
const timestamp = req.headers['x-signature-timestamp'];
if (!signature || !timestamp) {
return res.status(401).send('Unauthorized: Missing signature or timestamp');
}
console.log('Received headers:', {
'X-Signature-Ed25519': signature,
'X-Signature-Timestamp': timestamp
});
if (payload.type === 0) {
console.log('Received PING from Discord');
res.status(204).send();
console.log('Response sent: 204 No Content');
return;
}
if (payload.event && payload.event.type === 'APPLICATION_AUTHORIZED') {
console.log('APPLICATION_AUTHORIZED event received:', payload.event);
}
res.status(204).send();
});
const startLocalTunnel = async () => {
const tunnel = await localtunnel(PORT);
console.log(`LocalTunnel URL: ${tunnel.url}`);
console.log(`Set this URL in your Discord Developer Portal: ${tunnel.url}/webhook`);
tunnel.on('close', () => {
console.log('LocalTunnel closed');
});
};
const startServer = async () => {
app.listen(PORT, async () => {
console.log(`Server is running on port ${PORT}`);
await startLocalTunnel();
});
};
startServer();
^^ code
11-02 13:37:52 Received PING from Discord
11-02 13:37:52 Response sent: 204 No Content
11-02 13:38:09 Received headers: {
11-02 13:38:09 'X-Signature-Ed25519': 'f1c7f5b6b5c22d6f5a08f3aa3902d10dc1b161599d994ff010bf48b0104f32327cc9f00492f9c36c8453f30504b4673bcb582192861f128865085ecb9c7dce02',
11-02 13:38:09 'X-Signature-Timestamp': '1730554689'
11-02 13:38:09 }
11-02 13:38:09 Received PING from Discord
11-02 13:38:09 Response sent: 204 No Content
11-02 13:38:09 Received headers: {
11-02 13:38:09 'X-Signature-Ed25519': 'a4453007da90fa7d3abc902065bdf668fd631e7dacc926b000a3d7bea1a4c9598bd902dbb7f871479d4a74ba3ff1cd7725dda3a216c2c5d7448bb5e4a8dfa40c',
11-02 13:38:09 'X-Signature-Timestamp': '1730554689'
11-02 13:38:09 }
11-02 13:38:09 Received PING from Discord
11-02 13:38:09 Response sent: 204 No Content
^^ logs
this is not how you validate the request
read the page properly it will save you time