# Sending Thread Messages URL: /concepts/message-threads/sending-messages ### Sending thread messages We recommend using the `useTamboThreadInput` hook to send messages to the thread. ```tsx 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. ```tsx setValue("What is the weather like today?"); await submit({ streamResponse: true, // We recommend streaming the response to the user }); ``` import { Card, Cards } from "fumadocs-ui/components/card"; Learn more about streaming. You can use `isPending` and `error` to show a loading state or an error state: ```tsx if (isPending) { return
Loading...
; } ``` ```tsx if (error) { return
Error: {error.message}
; } ``` You can also use the `sendThreadMessage` function to send messages to the thread: ```tsx const { sendThreadMessage } = useTamboThread(); await sendThreadMessage("What is the weather like today?", { streamResponse: true, }); ``` ### Adding Context to Messages When sending messages, you can include additional context that will be sent along with the user's message. This is useful for providing extra information that tambo should consider when generating a response. #### With `useTamboThreadInput` ```tsx await submit({ streamResponse: true, additionalContext: { pageInfo: { url: "/weather", }, location: "San Francisco", units: "fahrenheit", }, }); ``` #### With `sendThreadMessage` ```tsx await sendThreadMessage("What is the weather like today?", { streamResponse: true, additionalContext: { pageInfo: { url: "/weather", }, location: "San Francisco", units: "fahrenheit", }, }); ``` The `additionalContext` parameter accepts a `Record` object, allowing you to pass any structured data as context. #### Context Helpers Tambo can automatically include context helpers with every message when they are configured. Configure helpers either: * Globally on `TamboProvider` via the `contextHelpers` prop, or * Locally on a page/layout using `TamboContextHelpersProvider` (active only while mounted) **Prebuilt helpers include:** * **currentTimeContextHelper**: Returns current timestamp * **currentPageContextHelper**: Returns current page URL/title information You can also define custom context helpers and register them either globally with `TamboProvider` or locally with `TamboContextHelpersProvider`. Any active helpers will be automatically merged into the message context. If the same key is registered in multiple places at different times, the most recently mounted registration takes precedence while it’s mounted. Learn more about additionalContext. Your manual `additionalContext` will be merged with any resolved helper results. For example, if the `currentTimeContextHelper` context helper is passed, the above code would result in a combined context like: ```json { "pageInfo": { "url": "/weather" }, "location": "San Francisco", "units": "fahrenheit", "userTime": { "timestamp": "2025-01-15T20:30:00.000Z" } } ```