Widget guides / React Native
Chat widget in your React Native app
Add three TypeScript files to your app, mount one component, and visitors get a chat that answers questions about matches, teams and players, with stats and your prices. This guide covers every setting, prop, callback and object the component gives you.
Checklist:
- Get your operator id, public key, widget origin and the wrapper files from your SensibleStats contact.
- Ask your contact to switch mobile on for your account.
- Install the two libraries, add the files, and mount
SensibleStatsChatwith the signed-in visitor's id. - Pass
onAddToSlip, then test an add, a duplicate and a reject. - Pass
onUnavailable, and change the config when the visitor signs in or out.
1. What your visitors get#
- A chat icon in a bottom corner, with a teaser beside it: a short greeting about a game, often with one of your prices and a few suggested questions.
- A chat sheet where visitors ask in their own words and get answers as text and cards: stats, form, line-ups, standings and your prices.
- Add to slip. A price in the chat carries a button that hands the selection to your code (section 7).
Terms used in this guide:
- Wrapper is the three TypeScript files your SensibleStats contact sends you. The component in
them shows our chat page
https://your-widget-host/min a WebView and passes messages between that page and your code. You never build the page URL yourself. - Operator id and public key identify your account to our server.
- Widget origin is the address of our server for your account, shown here as
https://your-widget-host. - Teaser is the short greeting bubble above the chat icon.
- Bet slip (or slip) is the list of selections a visitor collects in your app before placing a bet.
- Price is your odds for one selection.
matchOddsIdis your sportsbook's own id for one selection: one outcome of one market.operatorUserIdis your id for the signed-in visitor (section 5).
2. Before you start#
You need three values and the wrapper files from your SensibleStats contact.
| From us | Example | What it is |
|---|---|---|
| Operator id | YOUR_OPERATOR_ID | Your account in our system. Part of every request. |
| Public key | YOUR_PUBLIC_KEY | Identifies your widget. Safe to ship inside your app. |
| Widget origin | https://your-widget-host | The address of our chat page. Must be https. |
| To us | What it is |
|---|---|
| Switch on mobile | Ask your contact to switch mobile on for your account. Until then the chat does not start and reports mobile_disabled (section 11). There is no list of allowed domains on mobile. |
Your app. The component uses two libraries. These are the versions we test with:
| Package | Tested version |
|---|---|
react-native | 0.88.1 (React 19.3.0) |
react-native-webview | 14.0.1 |
react-native-safe-area-context | 5.11.1 |
iOS 15.1 or later; Android minSdk 24 or later.
3. Add the widget#
-
Install the two libraries and the iOS pods:
npm install react-native-webview react-native-safe-area-context cd ios && pod install -
Put the three files side by side in your app, e.g. under
src/:File What it holds SensibleStatsChat.tsx The SensibleStatsChatcomponent, its props and handle, and the slip types. Import everything from here.SensibleStatsConfig.ts The SensibleStatsConfigtype and the code that builds our page's address from it.SensibleStatsLauncher.tsx Our icon and teaser. SensibleStatsChatdraws it; you never mount it yourself. -
Wrap your app in
SafeAreaProviderand mountSensibleStatsChatat the root of your app, after your navigator. The chat fills its parent, so mounted deeper it would not cover your tab bar or navigation header.
import React, {useMemo, useRef} from 'react';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import {
SensibleStatsChat,
type SensibleStatsChatHandle,
type Selection,
type SensibleStatsConfig,
type SlipResult,
} from './src/SensibleStatsChat';
function chatConfig(userId: string): SensibleStatsConfig {
return {
baseUrl: 'https://your-widget-host',
operatorId: 'YOUR_OPERATOR_ID',
publicKey: 'YOUR_PUBLIC_KEY',
userContext: {operatorUserId: userId},
locale: 'en-GB',
greetingMessage: 'hello',
};
}
async function onAddToSlip(selection: Selection): Promise<SlipResult> {
try {
await mySlip.add(selection.matchOddsId);
return {status: 'added'};
} catch {
return {status: 'rejected', reason: 'not_found'};
}
}
export default function App() {
const chat = useRef<SensibleStatsChatHandle>(null);
const userId = currentUser?.id ?? '';
const config = useMemo(() => chatConfig(userId), [userId]);
return (
<SafeAreaProvider>
<MyNavigator />
<SensibleStatsChat ref={chat} config={config} onAddToSlip={onAddToSlip} />
</SafeAreaProvider>
);
}Names that start with my or My, and currentUser, stand for your own code.
The component keeps one WebView for its whole life. Closing the sheet slides it off screen; the
visitor's draft and conversation stay. Changing a setting reloads the chat, except position,
offset and launcher, which only move or hide the icon. A new config object with the same values
does not reload it. Callback props are read fresh on every call, so inline functions are fine.
WRAPPER_VERSION, exported from SensibleStatsChat.tsx, holds the wrapper's version, '1.0.0'
today. Quote this value when you contact us; your contact tells you when to update.
4. Settings#
SensibleStatsConfig is the config prop. Every field except the first four is optional.
Required#
| Field | Type | What it does |
|---|---|---|
baseUrl | string | https://your-widget-host. Must be https with a host; anything else throws while the component renders. Only the origin is used; any path is replaced. |
operatorId | string | Your operator id. |
publicKey | string | Your public key. |
userContext | {operatorUserId: string} | The signed-in visitor's id in your system. Required on mobile. See section 5. |
An empty operatorId or publicKey makes the chat report auth_failed.
Visitor, language and time#
| Field | Type | Default | What it does |
|---|---|---|---|
locale | language tag, e.g. en-GB, tr | your account's default language (English unless you asked for another) | The language of the chat and its answers. |
timeZone | IANA zone, e.g. Europe/ | the device's zone | Kick-off times and day names follow this zone. |
oddsFormat | 'decimal' | 'american' | 'fractional' | 'decimal' | How prices are written. A visitor who picks a format in the chat's settings keeps their choice. |
Greeting and page#
| Field | Type | Default | What it does |
|---|---|---|---|
greetingMessage | string | none | The chat sends this once when it loads, and the answer becomes the teaser. Use hello. Without it there is no greeting and no teaser. |
page | PageContext | none | The screen the visitor is on, so the greeting can lead with it. Section 6. |
placeholder | string | localized | Text in the empty question box. |
starters | string[] | none | Suggested questions shown in an empty chat. |
Look#
| Field | Type | Default | What it does |
|---|---|---|---|
theme | 'auto' | 'light' | 'dark' | 'auto' | auto follows the device's appearance. A visitor who picks a theme in the chat keeps their choice. |
colors | {light?: ThemeColors, dark?: ThemeColors} | ours | Colours for each theme. Section 10. |
logoUrl | string | our mark | Your logo, shown on the icon and in the sheet header. The icon shows it only for an https: or data: address; until it loads, or if it fails, the icon shows our mark. |
headerTitle | string | SensibleStats | The sheet's title. |
position | 'left' | 'right' | 'right' | Which bottom corner the icon sits in. |
offset | Offset: {x?: number, y?: number} | x: 20, y: 20 | Distance from the side and from the bottom of the screen, in points, on top of the safe-area inset. Each axis you leave out keeps 20. |
radius | number | 16 | Corner radius of the panel. Sent only when it is a finite number of 0 or more. |
launcher | boolean | true | false hides our icon and teaser so you draw your own (section 8). |
launcherLabel | string | "Chat with SensibleStats", localized | The icon's label for screen readers. Until the page answers, the icon's label is English "Open chat". |
pinIcon | 'pin' | 'star' | 'bookmark' | 'pin' | The icon visitors tap to follow a match or price. |
Slip, callbacks and events#
| Field | Type | Default | What it does |
|---|---|---|---|
slipSports | ( | none | The sports your onAddToSlip accepts besides football. Section 7. |
eventText | boolean | false | Adds the visitor's question text to question_asked events. Answer text is never sent. |
Props of SensibleStatsChat:
| Prop | Type | What it does |
|---|---|---|
config | SensibleStatsConfig | The settings above. |
onAddToSlip | ( | Adds a price to your bet slip. Section 7. |
onTeaser | ( | Gives you the teaser to draw yourself. Section 8. |
onStateChange | ( | Called when any of the chat's state changes. Section 8. |
onUnavailable | ( | Tells you the chat cannot start. Section 11. |
onEvent | ( | Every widget event, for your own analytics. Section 9. |
onBridgeMessage | ( | Every raw message between your app and our page, for debugging. Read only; an error it throws is ignored. |
Text values are sent as given; an empty value is left out. A colour that is not hex is dropped (section 10). A value outside the allowed list is ignored by the page and the default applies.
5. The signed-in visitor#
Pass your id for the signed-in visitor in userContext.operatorUserId. Use a random, non-guessable
id that never changes for that account and that you map to the customer on your side (a UUID works).
Never use a customer number, email address or name: the id comes from the visitor's device, and
anyone who knows it can act as that visitor. Spaces at either end are trimmed.
On mobile a signed-in visitor is required. With an empty id the chat does not start: no icon
appears and onUnavailable reports no_user.
With the id, the visitor's chat, followed matches and favourites belong to their account, and the greeting can lead with the teams and markets they bet on.
When the visitor signs in, signs out or switches account, pass a config with the new id, as the
useMemo in section 3 does. A config that gives a different page address reloads the chat on its
own: the old visitor's teaser and state are cleared, calls not yet delivered are dropped, and a
pending tapPrice() resolves null. You do not remount anything. After sign-out the id is empty, so
the chat closes, the icon hides and onUnavailable reports no_user. If you unmount the component
on sign-out instead, no no_user is reported.
To change baseUrl to another origin, mount a new component with a new key. Changing the
origin of a mounted component throws.
<SensibleStatsChat key={config.baseUrl} ref={chat} config={config} />chat.current?.reload() reloads the chat with the same config.
6. The page the visitor is on#
Tell the chat which screen it sits on and the greeting leads with that game, competition or sport.
PageContext:
| Field | Type | Meaning |
|---|---|---|
sport | 'football' | 'basketball' | 'americanfootball' | 'tennis' | Required. |
kind | 'section' | 'competition' | 'match', optional | A sport's front screen, a competition screen, or a match screen. |
matchId | string | number, optional | Your sportsbook's id for the match on a match screen. |
competitionId | string | number, optional | Your sportsbook's id for the competition on a competition screen. |
Set the first screen in config.page. When the visitor moves to another screen, call
chat.current?.setPage(page), or setPage(null) on a screen that is about no sport. If the visitor
has not typed or tapped anything yet, the chat greets again for the new screen.
setPage does not reload the chat; changing config.page does. It only tells the page that is
loaded now: after any reload the chat starts from config.page, so keep config.page current if
you change other settings.
7. Add to slip#
The chat shows your prices with an "Add to slip" button under each one. This is how a tap reaches your slip:
- The visitor taps "Add to slip" under a price.
- The component calls
onAddToSlip(selection).selection.matchOddsIdis your sportsbook's own id for that selection, so you can look it up directly. - Your code adds that selection to your slip and resolves what happened.
- The chat shows the visitor a short note in their language, such as "Added to slip".
You have 10 seconds to answer. No answer in time counts as a failure: the visitor sees "Couldn't add to slip. Try again." We don't cancel your handler at 10 seconds, so give your slip call its own timeout under 10 seconds, and don't add the selection after it fires.
On mobile the football button is always shown. Without onAddToSlip, every tap is answered
{status: 'rejected', reason: 'unsupported'}, so always pass it. If your handler throws, rejects, or
resolves anything that is not one of the shapes below, the component answers the same.
What the component sends: Selection
| Field | Type | Meaning |
|---|---|---|
matchOddsId | number (whole) | Your sportsbook's id for the selection. Look it up in your slip. |
matchId | number (whole) | Your sportsbook's id for the match. |
oddsDecimal | number | The price the visitor saw, as a decimal. |
sport | 'football' | 'basketball' | 'americanfootball' | 'tennis', optional | Absent (or 'football') means football. |
tour | string, optional | Tennis only: the tour the match id belongs to. |
odds | SlipOdds, optional | The same price in your account's odds format (not the visitor's own choice): format (e.g. "american") and text (e.g. "+150"). |
quotedAtUtc | string, optional | ISO time when that price was last confirmed. |
conversationId, insightId | string, optional | Which chat and which card the tap came from. |
display | SlipDisplay, optional | The pick in words, for showing only: home, away, kickoffUtc, market, marketLabel, selection, line, player, each an optional string. Never price or settle a bet from these. |
An optional field the page sends with the wrong type is left out and never stops the selection
reaching you. A selection that lacks matchOddsId, matchId or oddsDecimal never reaches your
handler; the wrapper answers unsupported for you. The same goes for ids that are not whole numbers.
What you resolve: SlipResult
| Resolve | When | The visitor sees (English) |
|---|---|---|
{status: 'added'} or null | The selection is in the slip. You can add slip: {selectionCount, totalOddsDecimal?}; it is accepted but not shown today. | Added to slip |
{status: 'duplicate'} | It was already in the slip. | Already in your slip |
{status: 'price_changed', newOdds: '2.10', accepted: true} | The price moved and you added it at the new price. newOdds is the new price as non-empty text. | Added at 2.10 (was 1.95) |
{status: 'price_changed', newOdds: '2.10', accepted: false} | The price moved and you did not add it. | Price moved to 2.10 (was 1.95). Tap to add. |
{status: 'rejected', reason, message?} | You did not add it. reason is one of the values below. | See below |
reason | Meaning | The visitor sees (English) |
|---|---|---|
login_required | The visitor must sign in first. | Sign in to add to your slip |
suspended | The market is suspended. | Market suspended |
closed | The market or match is closed, e.g. it has started. | Your message, else "This selection can't be added." |
not_found, limit, unsupported | You don't know this selection; the slip is full or a limit is reached; you don't take this kind of selection. | Your message, else "Couldn't add to slip. Try again." |
Other languages show the same notes, translated. message is your own text, shown as is: write it
in the visitor's language. It is ignored for login_required and suspended.
Other sports. Basketball, American football and tennis prices get the button only when
slipSports lists that sport, so a handler that only knows football never receives them:
slipSports: ['basketball', 'tennis'],For these sports the prices come from our own data, so matchOddsId and matchId are our ids, not
your sportsbook's. Find the selection from display (teams, kick-off, market, selection and line)
and tour for tennis, and return not_found when you cannot.
Telling the chat what happened next (optional). These calls on the handle help the chat track
your slip. SlipRef is {matchOddsId: number, sport?: Sport}.
| Call | When |
|---|---|
chat. | The visitor removed a selection from your slip. sport is optional. |
chat. | The visitor placed a bet. Pass the bet's selections; the second argument (BetFields: stake, currency, betId, betType, totalOdds) is optional, and a non-finite stake or totalOdds is left out. |
chat. | The visitor opened a match screen. matchId is a number. |
Calls made before the chat has loaded are kept and sent, in order, once it has.
8. The icon and teaser#
By default the component draws its own icon and teaser while the chat is available and the sheet is
closed. It counts the teaser as seen by itself. To draw them yourself, in your app's design, set
launcher: false and onTeaser:
<SensibleStatsChat
ref={chat}
config={{...config, launcher: false}}
onAddToSlip={onAddToSlip}
onTeaser={teaser => {
setMyTeaser(teaser);
if (teaser) {
chat.current?.teaserShown();
}
}}
/>
<MyChatButton onPress={() => chat.current?.open()} />onTeaser receives a Teaser when there is one, and null when it is gone. It is not called for
the empty state at start.
| Field | Type | Meaning |
|---|---|---|
text | string | null | The greeting line. |
asks | {index: number, label: string}[] | Suggested questions. Show label; pass index to tapAsk. |
cta | string, optional | A button label, e.g. "Build a bet". |
price | TeaserPrice, optional | One price: {matchOddsId: number, marketLabel: string, label: string, odds: string}, the market's name, the selection's name and the price as text. |
Show your icon only while the chat is available: read available from onStateChange or the
handle (section 13). SensibleStatsState has these fields:
| Field | Type | Meaning |
|---|---|---|
available | boolean | The chat has loaded and can open. false until then, and after it reports a reason. |
unavailableReason | UnavailableReason | null | Why it cannot start (section 11), or null. |
teaser | Teaser | null | The current teaser. |
pageTheme | 'light' | 'dark' | null | The theme the chat is showing, so your icon can match it. null until the chat says. |
labels | {launcher: string, dismiss: string} | null | The icon's and the close button's labels in the visitor's language. null until the chat sends them. |
onStateChange is not called for the first render, only for changes after it.
Call these when the visitor acts on your teaser:
| Call | When | What the chat does |
|---|---|---|
teaserShown() | You showed the teaser. | Counts it as seen, once per teaser. |
tapTeaser() | The visitor tapped the teaser text. | Opens the chat. |
tapAsk( | The visitor tapped a suggested question. | Opens the chat and asks it. |
tapCta() | The visitor tapped the button. | Opens the chat on it. |
tapPrice() | The visitor tapped the price. | Checks the price again, then calls your onAddToSlip. Returns Promise<PriceResult | null>. |
dismissTeaser() | The visitor closed the teaser. | Clears it; onTeaser( follows. |
PriceResult is {matchOddsId: number, outcome: PriceOutcome, text: string | null}. text is the
note to show the visitor, or null.
outcome is added (the selection is in the slip: added, already there, or added at a new price),
gone (the price is no longer offered), cool_off (too many requests; try again shortly) or failed
(not added: your handler refused it or did not answer).
tapPrice() resolves null when there is no price, a tap is already waiting, the teaser is
replaced or dismissed first, 15 seconds pass, or the chat reloads or unmounts.
These calls also work while our own icon is showing. Our icon and your calls share one waiting state: a tap from your own button also greys out the price on our teaser and shows its note there.
9. Events for your analytics#
Every visitor action is passed to onEvent as a plain object, so you can forward it to your own
analytics. The chat does not check consent; gate your own sending on it.
Every event carries name, at (epoch ms, when it happened), operatorId and widgetVersion, and
when known language, conversationId, operatorUserId and page. A ? marks a field that can be
absent.
| Event | Fields |
|---|---|
widget_open | source? (launcher, bubble, teaser, host, popup), first? |
widget_close | method (button, escape, host for your close(), native, back), tab, answering, openMs? |
bubble_shown, bubble_click, bubble_dismiss | none |
bubble_ask_click | position |
tab_change | from, to, source? (bar, link, auto) |
question_asked | turnId, source, length, text? (only with eventText), method?, chipId?, position?, actionRef?, retryOf?, matchId? |
answer_received | turnId, conversationId, latencyMs, cardTypes, firstByteMs? |
answer_failed | turnId, code |
answer_stopped | turnId |
add_to_slip_click | matchOddsId, matchId, odds, market?, sport?, factKey?, surface?, turnId? |
add_to_slip_result | the same fields, plus outcome |
pin_click | action (add, remove), target (match, market), matchId?, market?, sport?, surface?, turnId? |
combo_add_click | surface (builder, chat), sport, legs, total, turnId? |
combo_variant_click | surface, sport, legs, total, variant |
combo_swap_click | surface, sport, legs, total |
all_markets_click | matchId, market?, surface |
dashboard_tile_click | entityType, entityId |
sport_switch | sport |
new_conversation | none |
favourite_change | kind, id, outcome, sport?, surface?, before? |
add_to_slip_result.outcome is added, duplicate, price_changed, timeout or the reason you
rejected with. timeout covers any failed add, not only a late one. odds in events is always a
decimal number.
tab, from and to are one of chat, live, matches, builder, following, trends,
games, fixtures, standings, squad, records. question_asked.source is one of typed,
starter, action, tile, preset, live_fact, bubble_ask, retry, match_sheet.
10. Colours#
Each theme has four colours. A colour you leave out keeps ours. The dark theme reads only the dark colours, never the light ones.
ThemeColors is {accent?: string, cta?: string, surface?: string, ink?: string}.
| Colour | Used for | Light default | Dark default |
|---|---|---|---|
accent | Your brand colour: links, highlights and the suggested questions on the teaser. | #17936a | #37c891 |
cta | Price and "Add to slip" buttons. | #f5a623 | #ffb638 |
surface | The chat's background, the icon and the teaser bubble. | #ffffff | #141b24 |
ink | Text, and our mark on the icon. | #14181d | #e8edf2 |
Colours must be hex: #rgb, #rrggbb or #rrggbbaa. Any other value (a name such as red,
rgb(...)) is dropped, so ours applies; in a development build a debug line says which value was
ignored.
Set surface and ink together: the teaser's lines and faint text are then mixed from them.
colors: {
light: {accent: '#0b5fff', cta: '#ffcc00'},
dark: {accent: '#5c93ff', cta: '#ffd633', surface: '#0d1117', ink: '#f0f3f6'},
},The strip around the chat page (behind the status bar and the swipe handle) is white in the light theme and black in the dark theme.
11. When the chat cannot start#
available turns true when the page loads, and back to false if our server then refuses the
chat, so the icon can show for a moment before it hides. When the page reports one of the reasons
below, the component closes the sheet (isOpen is already false when your callback runs), hides
the icon, clears the teaser, sets unavailableReason on the state and the handle, and calls
onUnavailable(reason). It does this every time the page reports it. A reason this version of the
wrapper does not know only hides the icon.
reason | Cause | Fix |
|---|---|---|
no_user | userContext. is empty, for example after sign-out. | Pass the signed-in visitor's id (section 5). |
mobile_disabled | Mobile is not switched on for your account. | Ask your SensibleStats contact to switch mobile on for your account. |
widget_disabled | The widget is off for your account, or the operator id is not one we know. | Check the id. If it is right, ask your contact to switch the widget on. |
auth_failed | The public key is wrong or empty, or the operator id is empty. | Check both values. |
Errors thrown while rendering:
| Message | Cause |
|---|---|
baseUrl needs https and a host: ... | baseUrl is not an https address with a host. |
baseUrl cannot change on reload: mount a new SensibleStatsChat for another origin | The origin of baseUrl changed on a mounted component. Use a new key (section 5). |
12. Platform notes#
- Where to mount. At the root, inside
SafeAreaProvider, after your navigator. The sheet covers its parent and keeps clear of the status bar and home indicator. - Closing the sheet. The visitor closes it by swiping down on the handle at its top, by the chat's own close button, or with Android's back button. Back first goes back inside the chat, and closes the sheet only when the chat has nothing to go back to or does not answer within 300 ms.
- Keyboard. The sheet shrinks to stay above the keyboard.
- Links. Our page and its loads stay inside the WebView. A link to any other address opens
outside your app through the system (
http,https,mailtoandtelonly); other schemes are blocked. Pop-up windows are off. - Crash recovery. If the system ends the WebView's process (low memory, a renderer crash), the component loads the chat again and, if the sheet was open, reopens it. A second crash in the same open session closes the sheet. A first load that fails is retried once after 1.5 seconds.
- Messages. The component accepts messages only from a page on
https://your-widget-host. - Debugging. In a development build (
__DEV__) the WebView can be inspected with Safari's Web Inspector or Chrome'schrome://inspect; in a release build it cannot.
13. Reference#
Pass a ref (useRef<SensibleStatsChatHandle>(null)) to get the handle. Unmount the component to
remove the chat; there is no destroy().
Read-only state:
| Field | Type | Meaning |
|---|---|---|
isOpen | boolean | The sheet is open. |
available, unavailableReason, teaser, pageTheme, labels | see section 8 | The current state. |
Methods:
| Method | Returns | What it does |
|---|---|---|
open(), close() | void | Opens or closes the chat sheet. |
setPage( | void | Sets the screen (section 6); null clears it. |
reload() | void | Loads the chat again with the same config. |
slipRemoved(, betPlaced(, matchOpened( | void | Section 7. |
teaserShown(), tapTeaser(), tapAsk(, tapCta(), dismissTeaser() | void | Section 8. |
tapPrice() | Promise<PriceResult | null> | Section 8. |
Exports from SensibleStatsChat.tsx: the constant WRAPPER_VERSION, and the types
SensibleStatsConfig, ThemeColors, Colors, Offset, PageContext, PageKind, Sport,
SlipSport, Theme, Position, PinIcon, OddsFormat, Selection, SlipResult,
RejectReason, SlipRef, BetFields, PriceResult, PriceOutcome, Teaser, TeaserPrice,
LauncherLabels, PageTheme, SensibleStatsState, SensibleStatsChatHandle,
SensibleStatsChatProps, UnavailableReason, BridgeDirection.