diff --git a/src/routes/texting/$chatId.tsx b/src/routes/texting/$chatId.tsx index 670f671..0427dd5 100644 --- a/src/routes/texting/$chatId.tsx +++ b/src/routes/texting/$chatId.tsx @@ -406,6 +406,23 @@ function TextingPage() { return null; } + const showNotification = (persona: string, message: string) => { + if (Notification.permission === 'granted') { + new Notification(persona, { + body: message, + icon: '/assets/pwa/android-chrome-192x192.png' + }); + } else Notification.requestPermission(); + }; + + + useEffect(() => { + const lastMessage = messagesQuery.data?.messages[messagesQuery.data.messages.length - 1]; + if (lastMessage && !lastMessage.isGenerating && lastMessage.role === 'assistant') { + showNotification(messagesQuery.data.chat.personas[0]?.name || 'AI', lastMessage.content); + } + }, [messagesQuery.data, showNotification]); + return (