mirror of
https://github.com/ArthurDanjou/website.git
synced 2026-01-14 12:14:42 +01:00
Add discord webhook message
This commit is contained in:
@@ -7,6 +7,13 @@ const MessageValidator = z.object({
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { message } = await readValidatedBody(event, MessageValidator)
|
||||
const { user } = await requireUserSession(event)
|
||||
|
||||
await sendDiscordWebhookMessage({
|
||||
title: 'New guestbook message ✨',
|
||||
description: `**${user.username}** as signed the book : "*${message}*"`,
|
||||
color: 15893567,
|
||||
})
|
||||
|
||||
return await usePrisma().guestbookMessage.upsert({
|
||||
where: {
|
||||
email: user.email,
|
||||
|
||||
@@ -7,6 +7,13 @@ const SuggestionValidator = z.object({
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { content } = await readValidatedBody(event, SuggestionValidator)
|
||||
const { user } = await requireUserSession(event)
|
||||
|
||||
await sendDiscordWebhookMessage({
|
||||
title: 'New suggestion ✨',
|
||||
description: `**${user.username}** as requested **${content}** for the talents page.`,
|
||||
color: 15237114,
|
||||
})
|
||||
|
||||
return await usePrisma().suggestion.upsert({
|
||||
where: {
|
||||
email: user.email,
|
||||
|
||||
29
src/server/utils/discord.ts
Normal file
29
src/server/utils/discord.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable node/prefer-global/process */
|
||||
interface WebhookContent {
|
||||
title: string
|
||||
description: string
|
||||
color: number
|
||||
}
|
||||
|
||||
export async function sendDiscordWebhookMessage(content: WebhookContent) {
|
||||
const id = process.env.NUXT_DISCORD_ID
|
||||
const token = process.env.NUXT_DISCORD_TOKEN
|
||||
await $fetch(`https://discordapp.com/api/webhooks/${id}/${token}`, {
|
||||
method: 'POST',
|
||||
body: {
|
||||
embeds: [
|
||||
{
|
||||
title: content.title,
|
||||
description: content.description,
|
||||
color: content.color,
|
||||
url: 'https://arthurdanjou.fr/talents',
|
||||
footer: {
|
||||
text: 'Powered by Nuxt',
|
||||
},
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
],
|
||||
username: 'ArtDanjRobot - Website',
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user