Documentation Index
Fetch the complete documentation index at: https://botpress-add-desk-to-botpress-docs.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Why a WebView? Botpress Cloud Webchat is a browser client (
window.botpress). React Native does not run that API natively, so the supported pattern is to run the official Webchat inside a WebView and communicate with postMessage and injectJavaScript.The @botpress/webchat package targets web React. For native apps, use the WebView approach below.Prerequisites
You will need:
- A published bot
- A React Native or Expo project
react-native-webview
1. Copy your Webchat embed code from the dashboard
Before you write any app code, grab the same embed snippet you would use on a website. In the Botpress dashboard:- Open your bot’s Workspace and select the bot you want to embed.
- In the left sidebar, go to Webchat > Deploy Settings.
- Copy the Embed code:

2. Lay out your project files
Create asrc folder at your project root if you do not already have one. A typical layout:
src
botpress
getBotpressWebchat.js
BpWidget.js
BpWidget.d.ts
config
botpressConfig.js
| Path | Purpose |
|---|---|
src/botpress/getBotpressWebchat.js | Builds { html, baseUrl } for the WebView. |
src/botpress/BpWidget.js | WebView component and event bridge (onMessage); blocks marketing site navigation on close. |
src/botpress/BpWidget.d.ts | (Optional, TypeScript only) Types for BpWidget. |
src/config/botpressConfig.js | Webchat URLs and optional botId. Step 4 shows what goes inside export const botpressConfig = { ... }. |
src/ and use relative imports. The examples below assume src/botpress/ and src/config/.
Path alias (optional, Expo / TypeScript): In tsconfig.json, merge into compilerOptions:
import BpWidget from '@/botpress/BpWidget' resolve. If you skip aliases, use relative imports only.
3. Install react-native-webview
From your project root:For bare React Native, follow react-native-webview linking if your setup requires it. Expo users can also see the Expo WebView docs.
4. Save your Studio script URLs in one config file
Createsrc/config/botpressConfig.js and export a single botpressConfig object. Paste the script URLs from Studio > Webchat > Embed (the same values from your embed snippet). The HTML helper and the widget only read botConfig: you pass it in, and you do not duplicate URLs inside getBotpressWebchat.js or BpWidget.js.
Sensitive values:
botId and embed URLs identify your bot. For a public repository, do not commit real values, use placeholders in git or keep this file out of version control.5. Build the HTML page that loads Webchat
Addsrc/botpress/getBotpressWebchat.js. It builds a tiny HTML page (inject script, embed script, full height container) and returns { html, baseUrl } so you can pass it straight into <WebView source={{ baseUrl, html }} />.
getBotpressWebchat.js
6. Show Webchat in a WebView and forward events to React Native
Createsrc/botpress/BpWidget.js. It renders a WebView that loads your HTML, then relays what happens inside the page to your React Native layer:
- Puts the page from
getBotpressWebchat(botConfig)into theWebView. - Injects a script that subscribes to
window.botpressand sends each event to React Native withpostMessage(you read them inonMessageas JSON strings). - Intercepts navigation to
botpress.comor*.botpress.comwhen the user closes the widget and runswindow.botpress.close()instead to close the webchat interface.
BpWidget.js
onMessage format: event.nativeEvent.data is a string. Parse with JSON.parse. Shape: { event: string, data: unknown }.7. Optional: add TypeScript types for the widget
If you use TypeScript, addsrc/botpress/BpWidget.d.ts next to BpWidget.js so imports and props are typed:
8. Render the Webchat widget on a screen
ImportBpWidget and botpressConfig, then render it full screen or inside any View that uses flex: 1. Adjust import paths to your real paths (for example Expo Router app/index.tsx, a root App.js, or src/screens/…).
ChatScreen.tsx
9. Run your app
Open the iOS Simulator, Android emulator, or a physical device from there. Your bot should load inside the WebView when you run the app.
Troubleshooting
| Problem | What to check |
|---|---|
| Blank WebView | embedScriptUrl in botpressConfig.js must be the files.bpcontent.cloud/... URL from Studio. |
Error: embedScriptUrl is required | Set embedScriptUrl in botpressConfig. |
| Close (X) opens the Botpress.com website | Keep onShouldStartLoadWithRequest and closeChatJs in BpWidget.js as shown in that section. |
| Fonts look wrong | Tune appearance in Botpress Studio; avoid forcing global font-family in the HTML shell. |
| Android keyboard covers the composer | In app.json (Expo), under expo.android, set "softwareKeyboardLayoutMode": "resize". Rebuild the native Android app after changing this (not only a Metro refresh). |
