onBeforeSendMessage
Intercept every outgoing message before it's sent to the bot provider. The most common use case is to inject contextual metadata — the active category, the current route, feature flags — into the payload.
Select Context
Choose a category to inject into every outgoing message.
Send via ref
Payload Logs
Send a message to see the injected payload.
Loading chatbot...
Code Example
const [category, setCategory] = useState<Category | null>(null);
<Chatbot
onBeforeSendMessage={(params) => ({
...params,
payload: {
categoryId: category?.id,
categoryName: category?.name,
injectedAt: new Date().toISOString(),
},
})}
{...rest}
/>;
SendMessageParams
The shape received and returned by onBeforeSendMessage:
| Field | Type | Description |
|---|---|---|
text | string | The user's input text |
payload | Record<string, unknown> | (() => Record<string, unknown>) | Metadata sent alongside the message to the bot provider |
blobIds | string[] | Uploaded file blob IDs (optional) |
filePreviewUrls | string[] | Image preview URLs (optional) |
documentNames | string[] | Document names (optional) |
You can modify text (e.g. add a prefix) or inject payload (e.g. add context). The returned object replaces the original params.