I read the older issue too about it being fixed when used with callbacks instead of the one shows in the tutorial but it did nothing for me. I have multiple console logs so I know the code is reaching the sections I want it to.
const nacl = require('tweetnacl');
exports.handler = async (event) => {
// Checking signature (requirement 1.)
// Your public key can be found on your application in the Developer Portal
console.log(event)
const PUBLIC_KEY = process.env.PUBLIC_KEY;
const signature = event.headers['x-signature-ed25519'];
const timestamp = event.headers['x-signature-timestamp'];
const strBody = event.body; // should be string, for successful sign
const isVerified = nacl.sign.detached.verify(
Buffer.from(`${timestamp}${strBody}`),
Buffer.from(signature, 'hex'),
Buffer.from(PUBLIC_KEY, 'hex')
);
if (!isVerified) {
return {
statusCode: 401,
body: JSON.stringify('invalid request signature'),
};
}
// Replying to ping (requirement 2.)
const body = JSON.parse(strBody);
const id = body.id;
const token = body.token;
console.log(body)
// const interaction_url = `https://discord.com/api/v10/interactions/${id}/${token}/callback`;
if (body.type === 1) {
return {
statusCode: 200,
body: JSON.stringify({ "type": 1 }),
}
}
if (body.data.name === 'foo') {
console.log("Inside foo")
return (
JSON.stringify({
"type": 4,
"data": { "content": "bar" }
})
)
}
else {
console.log("Either no handler present of such kind or event error")
return {
statusCode: 404 // If no handler implemented for Discord's request
}
}
};
Node version: 18.12.1
I read the older issue too about it being fixed when used with callbacks instead of the one shows in the tutorial but it did nothing for me. I have multiple console logs so I know the code is reaching the sections I want it to.