Step 3: Add Hydra AI listener
In this step, we'll add a message listener that sends messages to Hydra AI and responds to the user with Hydra's output.
Add Hydra AI message listener
-
Add Hydra AI message handler file
Create a new file called
hydra-message.ts
undersrc/listeners/messages
directory and copy the following code into the file:This handles taking the user's message and sending it to Hydra AI, showing any loading states, and updating the message with Hydra's output.
-
Listen for all messages
Now we can remove the
hello
listener and add a message listener that uses thehydraMessageCallback
function we just created.Replace the contents of
src/listeners/messages/index.ts
with the following:You'll notice that this listener is listening for all messages, and so Hydra will respond to any message in a channel where the app is added. You can edit this file to listen for specific messages or channels if you want!
Try it out!
Now that we're sending messages through Hydra, we can try sending messages to it and having it respond!
We haven't registered any components yet, so Hydra will only be able to respond with text. At this point, the app is essentially an LLM chatbot.
-
Run the app
If it's not running already, run
npm start
to get the app running again. -
Send a message to Hydra
Send a message in a channel where the app is added. You should see a message saying "Thinking..." and then a message with Hydra's response.
In the next step, we'll register the Todo list components and see how Hydra can respond with interactive UI components instead of just text.