router.post("/interactions", async (req, env: env, ctx: ExecutionContext) => { const body = await req.text(); const valid = await verifyRequest(req, body, env); if (!valid) return new Response("Bad request signature.", { status: 401 }); const interaction = JSON.parse(body) as APIInteraction; switch (interaction.type) { case InteractionType.Ping: console.log("ping type") return new JsonResponse({ type: InteractionResponseType.Pong, }); case InteractionType.ApplicationCommand: switch (interaction.data.type) { case ApplicationCommandType.ChatInput: console.log("slash command") return await handleCommand( interaction as APIChatInputApplicationCommandInteraction, env, ctx, commands ); default: return; } case InteractionType.MessageComponent: switch (interaction.data.component_type) { case ComponentType.Button: console.log("Button") return handleButtons( interaction as APIMessageComponentButtonInteraction, env, ctx, buttons ); } case InteractionType.ModalSubmit: console.log("Modal") return handleModals( interaction as APIModalSubmitInteraction, env, ctx, modals ); case InteractionType.ApplicationCommandAutocomplete: console.log("Autocomplete") return handleAutocompletes( interaction as APIApplicationCommandAutocompleteInteraction, env, ctx, autocompletes ) // Unknown default: console.log("Unknown type") return new Response(null, { status: 501 }); } });