跳至主要内容

onBeforeSendMessage

在每一則訊息送到 bot provider 之前攔截。最常見的用途是注入 context metadata — 目前分類、當前路徑、feature flag — 到 payload 中。

選擇 Context

選擇一個分類,會被注入到所有送出的訊息中。

透過 ref 發送

Payload 日誌

發送一則訊息即可看到被注入的 payload。
聊天機器人載入中…

程式範例

const [category, setCategory] = useState<Category | null>(null);

<Chatbot
onBeforeSendMessage={(params) => ({
...params,
payload: {
categoryId: category?.id,
categoryName: category?.name,
injectedAt: new Date().toISOString(),
},
})}
{...rest}
/>;