mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-05-25 01:12:42 -04:00
Send discord message at every profile creation
This commit is contained in:
@@ -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 {
|
||||
|
||||
18
common/src/discord/core.ts
Normal file
18
common/src/discord/core.ts
Normal 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)
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user