Skip to main content
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:

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:
  1. Open your bot’s Workspace and select the bot you want to embed.
  2. In the left sidebar, go to Webchat > Deploy Settings.
  3. Copy the Embed code:
Embed code from Dashboard

2. Lay out your project files

Create a src 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
You can instead keep files flat under 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:
Then imports like 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

Create src/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

Add src/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

Create src/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 the WebView.
  • Injects a script that subscribes to window.botpress and sends each event to React Native with postMessage (you read them in onMessage as JSON strings).
  • Intercepts navigation to botpress.com or *.botpress.com when the user closes the widget and runs window.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, add src/botpress/BpWidget.d.ts next to BpWidget.js so imports and props are typed:

8. Render the Webchat widget on a screen

Import BpWidget 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

Next steps

Now that Webchat runs in your app, try styling it in Studio to match your product. For more control over the embed, see Embed Webchat and the Webchat interaction reference.
Last modified on April 2, 2026