Host callbacks & actions
Two extension points let the bot drive your native app:
- Callbacks — a
callbackaction forwards(callbackId, payload)to your app. - Host slots — a
host_slotcomponent reserves a spot the bot names; your app renders a native widget into it.
Advertise your callbacks
Tell the bot which callback ids you support via userContext, so it never emits one your app can’t dispatch:
userContext: { 'supported_callbacks': ['open_design', 'open_paywall', 'open_login'],}Handle callbacks
ChatWidget( configuration: config, onRichContentCallback: (callbackId, payload) { switch (callbackId) { case 'open_design': openDesign(payload?['design']); break; case 'open_paywall': showPaywall(reason: payload?['reason']); break; case 'open_login': requireAuth(); break; } },);window.WidgetChat.init({ secretKey, userId, onCallback: (callbackId, payload) => { if (callbackId === 'open_design') openDesign(payload.design); },});Host slots
The bot returns { "type": "host_slot", "slot_id": "pdf_preview", "payload": { … } }. Your builder maps the id to a widget:
ChatWidget( configuration: config, hostSlotBuilder: (slotId, payload) { if (slotId == 'pdf_preview') return PdfPreview(url: payload?['url']); return const SizedBox.shrink(); // unknown → nothing },);