Tambo Lockup

Sending Thread Messages

Send messages to Tambo to generate a response

Sending thread messages

We recommend using the useTamboThreadInput hook to send messages to the thread.

import { useTamboThreadInput } from "@tambo-ai/react";

const { value, setValue, submit } = useTamboThreadInput();

The value is the value of the message that you want to send.

The setValue is the function that you can use to update the value of the message.

To send a user's message to tambo, you can use the submit function:

You can also pass in an optional options object to the submit function.

setValue("What is the weather like today?");

await submit({
  streamResponse: true, // We recommend streaming the response to the user
});

You can use isPending and error to show a loading state or an error state:

if (isPending) {
  return <div>Loading...</div>;
}
if (error) {
  return <div>Error: {error.message}</div>;
}

You can also use the sendThreadMessage function to send messages to the thread:

const { sendThreadMessage } = useTamboThread();

await sendThreadMessage("What is the weather like today?", {
  streamResponse: true,
});