How does the agent retrieve the topic set in the s...
# ask-ai
b
How does the agent retrieve the topic set in the send method of useChat in livekit/components-react?
t
Thanks for reaching out, RikuKomiya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! The
useChat
hook in LiveKit's
@livekit/components-react
package is a handy way to send messages on a specific topic using the
send
method. By default, it sends messages on the
lk.chat
topic, but you can easily switch it up by setting a
channelTopic
in the
ChatOptions
when you call
useChat
. Here’s a quick example:
Copy code
const { send, chatMessages } = useChat({ channelTopic: 'custom-topic' });
send('Hello on custom topic!');
Any messages you send on that topic will automatically show up and stack in the
chatMessages
array. One thing to keep in mind: there isn’t a built-in way to dynamically fetch or list all active topics in the room. So, everyone needs to know the topic name ahead of time to set up a handler and receive those messages. If you’re looking to get a bit more advanced, you can pair
useDataChannel
with
useChat
to juggle multiple topics. Feel free to reach out if you want me to walk you through it or if you have any other questions—I’m here to help! Sources: packages/core/src/observables/dataChannel.ts | Sending text | LiveKit Docs | src/components/reaction-bar.tsx