From 9eacb38eb9ace58937a2e38cca462b194c274e88 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Mon, 13 Oct 2025 12:26:40 +0200 Subject: [PATCH] Show bio in discord message of profile creation --- backend/api/src/create-profile.ts | 34 +++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/backend/api/src/create-profile.ts b/backend/api/src/create-profile.ts index ae4f379b..7a1de873 100644 --- a/backend/api/src/create-profile.ts +++ b/backend/api/src/create-profile.ts @@ -9,6 +9,30 @@ import { tryCatch } from 'common/util/try-catch' import { insert } from 'shared/supabase/utils' import {sendDiscordMessage} from "common/discord/core"; +function extractTextFromBio(bio: any): string { + try { + const texts: string[] = [] + const visit = (node: any) => { + if (!node) return + if (Array.isArray(node)) { + for (const item of node) visit(item) + return + } + if (typeof node === 'object') { + for (const [k, v] of Object.entries(node)) { + if (k === 'text' && typeof v === 'string') texts.push(v) + else visit(v as any) + } + } + } + visit(bio) + // Remove extra whitespace and join + return texts.map((t) => t.trim()).filter(Boolean).join(' ') + } catch { + return '' + } +} + export const createProfile: APIHandler<'create-profile'> = async (body, auth) => { const pg = createSupabaseDirectClient() @@ -49,10 +73,12 @@ export const createProfile: APIHandler<'create-profile'> = async (body, auth) => console.error('Failed to track create profile', e) } try { - await sendDiscordMessage( - `**${user.name}** just created a profile at https://www.compassmeet.com/${user.username}`, - 'members', - ) + let message: string = `[**${user.name}**](https://www.compassmeet.com/${user.username}) just created a profile` + if (body.bio) { + const bioText = extractTextFromBio(body.bio) + if (bioText) message += `\n > ${bioText}` + } + await sendDiscordMessage(message, 'members') } catch (e) { console.error('Failed to send discord new profile', e) }