diff --git a/src/App.svelte b/src/App.svelte index 99b50b8..161c13b 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -29,6 +29,10 @@ let categorySearch = ''; let categoryOptions: Array<{ id: string; name: string; box_art_url: string }> = []; let categorySearchTimer: number | undefined; + let chatIdentity: 'streamer' | 'bot' = 'streamer'; + let chatMessage = ''; + let chatBusy = false; + let chatError = ''; let oauthLink = ''; let oauthIdentity: 'streamer' | 'bot' = 'streamer'; let oauthBusy = false; @@ -231,6 +235,25 @@ } } + async function sendChatMessage() { + if (!chatMessage.trim() || chatMessage.length > 500) return; + chatBusy = true; + chatError = ''; + try { + const response = await fetch(`${serverAddress}/api/v1/twitch/chat/message`, { + method: 'POST', + headers: { 'content-type': 'application/json', authorization: `Bearer ${sessionToken}` }, + body: JSON.stringify({ identity: chatIdentity, message: chatMessage }), + }); + if (!response.ok) throw new Error('The selected Twitch identity could not send the message.'); + chatMessage = ''; + } catch (error) { + chatError = error instanceof Error ? error.message : 'Chat message failed.'; + } finally { + chatBusy = false; + } + } + async function createOAuthLink(identity: 'streamer' | 'bot') { oauthBusy = true; oauthError = ''; @@ -339,7 +362,7 @@