Send discord message at every profile creation

This commit is contained in:
MartinBraquet
2025-09-28 20:47:31 +02:00
parent f021101322
commit 501c92c350
3 changed files with 30 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ import {createSupabaseDirectClient} from 'shared/supabase/init'
import {insert} from 'shared/supabase/utils'
import {convertPrivateUser, convertUser} from 'common/supabase/users'
import {getBucket} from "shared/firebase-utils";
import {sendDiscordNewUser} from "common/discord/core";
export const createUser: APIHandler<'create-user'> = async (
props,
@@ -123,7 +124,16 @@ export const createUser: APIHandler<'create-user'> = async (
log('created user ', {username: user.username, firebaseId: auth.uid})
const continuation = async () => {
await track(auth.uid, 'create profile', {username: user.username})
try {
await track(auth.uid, 'create profile', {username: user.username})
} catch (e) {
console.log('Failed to track create profile', e)
}
try {
await sendDiscordNewUser(user)
} catch (e) {
console.log('Failed to send discord new user', e)
}
}
return {

View File

@@ -0,0 +1,18 @@
import {User} from "common/user";
export const sendDiscordNewUser = async (user: User) => {
const webhookUrl = process.env.DISCORD_WEBHOOK_NEW_USERS
if (!webhookUrl) return
const response = await fetch(webhookUrl!, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({content: `**${user.name}** just created a profile at https://www.compassmeet.com/${user.username}`}),
})
if (!response.ok) {
const text = await response.text()
console.error(text)
}
}

View File

@@ -18,6 +18,7 @@ export const secrets = (
'RESEND_KEY',
'COMPASS_API_KEY',
'NEXT_PUBLIC_FIREBASE_API_KEY',
'DISCORD_WEBHOOK_NEW_USERS',
// Some typescript voodoo to keep the string literal types while being not readonly.
] as const
).concat()