@@ -42,72 +42,87 @@ export const Route = createFileRoute('/api/discord/interactions')({
4242 server : {
4343 handlers : {
4444 POST : async ( { request } : { request : Request } ) => {
45- if ( ! DISCORD_PUBLIC_KEY ) {
46- return new Response (
47- JSON . stringify ( { error : 'Discord public key not configured' } ) ,
48- { status : 500 , headers : { 'Content-Type' : 'application/json' } } ,
49- )
50- }
45+ try {
46+ if ( ! DISCORD_PUBLIC_KEY ) {
47+ console . error ( '[Discord] DISCORD_PUBLIC_KEY not configured' )
48+ return new Response (
49+ JSON . stringify ( { error : 'Discord public key not configured' } ) ,
50+ { status : 500 , headers : { 'Content-Type' : 'application/json' } } ,
51+ )
52+ }
5153
52- const signature = request . headers . get ( 'X-Signature-Ed25519' )
53- const timestamp = request . headers . get ( 'X-Signature-Timestamp' )
54+ const signature = request . headers . get ( 'X-Signature-Ed25519' )
55+ const timestamp = request . headers . get ( 'X-Signature-Timestamp' )
5456
55- if ( ! signature || ! timestamp ) {
56- return new Response (
57- JSON . stringify ( { error : 'Missing signature headers' } ) ,
58- { status : 401 , headers : { 'Content-Type' : 'application/json' } } ,
59- )
60- }
57+ if ( ! signature || ! timestamp ) {
58+ console . error ( '[Discord] Missing signature headers' )
59+ return new Response (
60+ JSON . stringify ( { error : 'Missing signature headers' } ) ,
61+ { status : 401 , headers : { 'Content-Type' : 'application/json' } } ,
62+ )
63+ }
6164
62- const body = await request . text ( )
65+ const body = await request . text ( )
6366
64- const isValid = await verifyKey (
65- body ,
66- signature ,
67- timestamp ,
68- DISCORD_PUBLIC_KEY ,
69- )
67+ const isValid = await verifyKey (
68+ body ,
69+ signature ,
70+ timestamp ,
71+ DISCORD_PUBLIC_KEY ,
72+ )
7073
71- if ( ! isValid ) {
72- return new Response ( JSON . stringify ( { error : 'Invalid signature' } ) , {
73- status : 401 ,
74- headers : { 'Content-Type' : 'application/json' } ,
75- } )
76- }
74+ if ( ! isValid ) {
75+ console . error ( '[Discord] Invalid signature' )
76+ return new Response (
77+ JSON . stringify ( { error : 'Invalid signature' } ) ,
78+ { status : 401 , headers : { 'Content-Type' : 'application/json' } } ,
79+ )
80+ }
7781
78- const interaction : Interaction = JSON . parse ( body )
82+ const interaction : Interaction = JSON . parse ( body )
83+ console . log ( '[Discord] Interaction type:' , interaction . type )
7984
80- // Handle PING (Discord uses this to verify endpoint)
81- if ( interaction . type === InteractionType . PING ) {
82- return new Response (
83- JSON . stringify ( { type : InteractionResponseType . PONG } ) ,
84- { status : 200 , headers : { 'Content-Type' : 'application/json' } } ,
85- )
86- }
85+ // Handle PING (Discord uses this to verify endpoint)
86+ if ( interaction . type === InteractionType . PING ) {
87+ console . log ( '[Discord] Responding to PING' )
88+ return new Response (
89+ JSON . stringify ( { type : InteractionResponseType . PONG } ) ,
90+ { status : 200 , headers : { 'Content-Type' : 'application/json' } } ,
91+ )
92+ }
8793
88- // Handle slash commands
89- if ( interaction . type === InteractionType . APPLICATION_COMMAND ) {
90- const commandName = interaction . data ?. name
91-
92- let response
93- switch ( commandName ) {
94- case 'tanstack' :
95- response = handleStatusCommand ( )
96- break
97- default :
98- response = handleUnknownCommand ( commandName || 'unknown' )
94+ // Handle slash commands
95+ if ( interaction . type === InteractionType . APPLICATION_COMMAND ) {
96+ const commandName = interaction . data ?. name
97+ console . log ( '[Discord] Command:' , commandName )
98+
99+ let response
100+ switch ( commandName ) {
101+ case 'tanstack' :
102+ response = handleStatusCommand ( )
103+ break
104+ default :
105+ response = handleUnknownCommand ( commandName || 'unknown' )
106+ }
107+
108+ return new Response ( JSON . stringify ( response ) , {
109+ status : 200 ,
110+ headers : { 'Content-Type' : 'application/json' } ,
111+ } )
99112 }
100113
101- return new Response ( JSON . stringify ( response ) , {
102- status : 200 ,
103- headers : { 'Content-Type' : 'application/json' } ,
104- } )
114+ console . error ( '[Discord] Unknown interaction type:' , interaction . type )
115+ return new Response (
116+ JSON . stringify ( { error : 'Unknown interaction type' } ) ,
117+ { status : 400 , headers : { 'Content-Type' : 'application/json' } } ,
118+ )
119+ } catch ( error ) {
120+ console . error ( '[Discord] Handler error:' , error )
121+ return new Response (
122+ JSON . stringify ( { error : 'Internal server error' } ) ,
123+ { status : 500 , headers : { 'Content-Type' : 'application/json' } } ,
124+ )
105125 }
106-
107- return new Response (
108- JSON . stringify ( { error : 'Unknown interaction type' } ) ,
109- { status : 400 , headers : { 'Content-Type' : 'application/json' } } ,
110- )
111126 } ,
112127 } ,
113128 } ,
0 commit comments