Skip to content

Host callbacks & actions

Two extension points let the bot drive your native app:

  • Callbacks — a callback action forwards (callbackId, payload) to your app.
  • Host slots — a host_slot component reserves a spot the bot names; your app renders a native widget into it.

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;
}
},
);

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
},
);