REFERENCE
SDK Demos
How to use @asgard-js/core and @asgard-js/react, with demos you can try on the page.
Customize Payload
onBeforeSendMessage lets you customize the payload before a message is
sent — attach the current page, user state, feature flags, or any other
context metadata so the bot can respond based on the full picture, not just
the user's text.
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}
/>;SendMessageParamsThe shape received and returned by
onBeforeSendMessage:Field Type Description textstringThe user's input text payloadRecord<string, unknown> | (() => Record<string, unknown>)Metadata sent alongside the message to the bot provider blobIdsstring[]Uploaded file blob IDs (optional) filePreviewUrlsstring[]Image preview URLs (optional) documentNamesstring[]Document names (optional) The most common use is injecting
payload. Other fields (e.g. prefixingtext) can also be modified — the returned object replaces the original params.Further Reading
For how
payloadis received and used by the bot provider, see the Asgard developer docs: