Skip to main content

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.

  1. 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}
    />;
  2. SendMessageParams​

    The shape received and returned by onBeforeSendMessage:

    FieldTypeDescription
    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. prefixing text) can also be modified — the returned object replaces the original params.

  3. Further Reading​

    For how payload is received and used by the bot provider, see the Asgard developer docs:

Ready to get started?

Want to see how Asgard fits your team? Talk to us.

Contact us