Add Tellvira to React Native
In a native app, the widget runs inside a WebView. Use the same Bot ID as your website snippet.
WebView setup
- Install.
npx expo install react-native-webview - Add the screen. Paste the component into your screen file and replace the four placeholder values (
YOUR_BOT_ID,YOUR_WIDGET_URL,YOUR_API_HOST, andYOUR_ALLOWED_SITE_URL).
import { KeyboardAvoidingView, Platform, SafeAreaView, StatusBar, StyleSheet } from 'react-native';
import { WebView } from 'react-native-webview';
// Replace these values
const BOT_ID = 'YOUR_BOT_ID';
const WIDGET_SCRIPT_URL = 'YOUR_WIDGET_URL';
const API_BASE = 'YOUR_API_HOST';
const SITE_URL = 'YOUR_ALLOWED_SITE_URL'; // must be one of your bot's Allowed domains
const html = `<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>html, body { margin: 0; height: 100%; }</style>
</head>
<body>
<p id="widget-status" role="status" style="padding:24px;font:16px system-ui">Loading chat…</p>
<script
src="${WIDGET_SCRIPT_URL}"
data-bot-id="${BOT_ID}"
onload="window.ChatbotWidget.init({
script: this,
apiBase: '${API_BASE}',
open: true,
onOpenChange: function (open) {
if (!open) window.ReactNativeWebView.postMessage('tellvira-close');
}
}).then(function (widget) {
var s = document.getElementById('widget-status');
if (widget) { s.remove(); } else { s.textContent = 'Chat could not start. Check the Bot ID, Allowed domains, and the API URL.'; }
}).catch(function () {
document.getElementById('widget-status').textContent = 'Chat initialization failed.';
})"
onerror="document.getElementById('widget-status').textContent = 'Could not load the chat script.';"
></script>
</body>
</html>`;
export default function TellviraChatScreen({ navigation, onClose }) {
const close = () => (onClose ? onClose() : navigation?.goBack());
return (
<SafeAreaView style={styles.container}>
<KeyboardAvoidingView
style={styles.flex}
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
>
<WebView
style={styles.flex}
originWhitelist={['*']}
source={{ html, baseUrl: SITE_URL }}
javaScriptEnabled
domStorageEnabled
onMessage={({ nativeEvent }) => {
if (nativeEvent.data === 'tellvira-close') close();
}}
/>
</KeyboardAvoidingView>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
paddingTop: Platform.OS === 'android' ? StatusBar.currentHeight : 0,
},
flex: {
flex: 1,
},
});Notes
- SITE_URL must be one of the bot's Allowed domains in the dashboard, otherwise the chat returns 403.
- Using React Navigation? It works as is (closing the chat calls goBack). Otherwise pass an onClose prop.
- Production must use HTTPS. For local HTTP testing only, add mixedContentMode='always' to the WebView.
For a fully native UI instead of a WebView, use the Chat API.