const discordRoute = httpAction(async (ctx, request) => {
console.log("Received request");
const { isValid, interaction } = await verifyDiscordRequest(request);
console.log("Is request valid", isValid);
if (!isValid || !interaction)
return new Response("Bad request signature.", { status: 401 });
if (interaction.type === InteractionType.Ping)
return new Response(
JSON.stringify({
type: InteractionResponseType.Pong,
}),
{ status: 200 },
);
console.log("Got here");
console.log("interaction type", interaction.type);
if (interaction.type === InteractionType.ApplicationCommand) {
return new Response(
JSON.stringify({
type: InteractionResponseType.ChannelMessageWithSource,
data: { content: "Blah" },
}),
{ headers: { "Content-Type": "application/json" }, status: 200 },
);
}
return new Response("Unknown request", { status: 500 });
});
http.route({
path: "/discord",
method: "POST",
handler: discordRoute,
});
const discordRoute = httpAction(async (ctx, request) => {
console.log("Received request");
const { isValid, interaction } = await verifyDiscordRequest(request);
console.log("Is request valid", isValid);
if (!isValid || !interaction)
return new Response("Bad request signature.", { status: 401 });
if (interaction.type === InteractionType.Ping)
return new Response(
JSON.stringify({
type: InteractionResponseType.Pong,
}),
{ status: 200 },
);
console.log("Got here");
console.log("interaction type", interaction.type);
if (interaction.type === InteractionType.ApplicationCommand) {
return new Response(
JSON.stringify({
type: InteractionResponseType.ChannelMessageWithSource,
data: { content: "Blah" },
}),
{ headers: { "Content-Type": "application/json" }, status: 200 },
);
}
return new Response("Unknown request", { status: 500 });
});
http.route({
path: "/discord",
method: "POST",
handler: discordRoute,
});