@@ -9,6 +9,30 @@ import { tryCatch } from 'common/util/try-catch'
99import { insert } from 'shared/supabase/utils'
1010import { sendDiscordMessage } from "common/discord/core" ;
1111
12+ function extractTextFromBio ( bio : any ) : string {
13+ try {
14+ const texts : string [ ] = [ ]
15+ const visit = ( node : any ) => {
16+ if ( ! node ) return
17+ if ( Array . isArray ( node ) ) {
18+ for ( const item of node ) visit ( item )
19+ return
20+ }
21+ if ( typeof node === 'object' ) {
22+ for ( const [ k , v ] of Object . entries ( node ) ) {
23+ if ( k === 'text' && typeof v === 'string' ) texts . push ( v )
24+ else visit ( v as any )
25+ }
26+ }
27+ }
28+ visit ( bio )
29+ // Remove extra whitespace and join
30+ return texts . map ( ( t ) => t . trim ( ) ) . filter ( Boolean ) . join ( ' ' )
31+ } catch {
32+ return ''
33+ }
34+ }
35+
1236export const createProfile : APIHandler < 'create-profile' > = async ( body , auth ) => {
1337 const pg = createSupabaseDirectClient ( )
1438
@@ -49,10 +73,12 @@ export const createProfile: APIHandler<'create-profile'> = async (body, auth) =>
4973 console . error ( 'Failed to track create profile' , e )
5074 }
5175 try {
52- await sendDiscordMessage (
53- `**${ user . name } ** just created a profile at https://www.compassmeet.com/${ user . username } ` ,
54- 'members' ,
55- )
76+ let message : string = `[**${ user . name } **](https://www.compassmeet.com/${ user . username } ) just created a profile`
77+ if ( body . bio ) {
78+ const bioText = extractTextFromBio ( body . bio )
79+ if ( bioText ) message += `\n > ${ bioText } `
80+ }
81+ await sendDiscordMessage ( message , 'members' )
5682 } catch ( e ) {
5783 console . error ( 'Failed to send discord new profile' , e )
5884 }
0 commit comments