Bridget Integration Guide
Created by Erez Michaeli, Modified on Fri, 5 Dec at 8:20 PM by Erez Michaeli
Bridget Integration Guide
This guide explains how to embed the Bridget widget into your web or mobile application using an <iframe>. The widget URL handles data fetching, theming, and real-time events back to your app.
Make sure your backend already implements the Bridgewise authentication flow and can provide a valid access token to the frontend. The token must be generated according to the Tenant Authentication guideline.
1. High-Level Integration Journey
A typical Bridget integration follows this end-to-end journey:
- Backend authentication
Your backend calls the Bridgewise authentication endpoint with your application credentials and receives an access token that Bridget widgets will use for all data calls. - Token storage and refresh
The access token is stored securely on the backend and refreshed regularly (for example, every 24 hours), or immediately when authentication errors occur. - Frontend requests the token
When a user opens a page that should display Bridget, your frontend calls your backend, retrieves the current access token, and constructs the Bridget widget URL. - Widgets are rendered
The frontend embeds Bridget using an iframe:bridget-chatfor the full chat experience.bridget-teaseras a compact teaser that can open the full chat.
- Events and navigation
The widget sends events to your application usingpostMessage(for example, load, resize, navigation, teaser-trigger). Your app listens for these events to:- Adjust the iframe height dynamically.
- Handle navigation to your own security pages.
- Open the full chat when a teaser question is clicked.
- Monitoring and error handling
Your application logs any relevant widget events and HTTP errors, and reacts to token issues (such as 401/403) by refreshing the token on the backend and reloading the widget if necessary.
2. Quick Start
Minimal Bridget Chat embed:
<iframe id="widget" src="https://embeded.bridgewise.com/en-US/bw/bridget-chat?accessToken=YOUR_TOKEN" style="width:100%; border:0; height:400px;"></iframe>
This example uses the default Bridgewise UI (tenant=bw) and the bridget-chat widget. You can switch to your own tenant and add identifiers, theming, and analytics parameters as described in the following sections.
Replace YOUR_TOKEN with your actual access token and bw with your tenant name (if you are using a custom tenant).
3. URL Structure & Available Widgets
3.1 Base URL Format
All Bridget widgets share the same base URL structure:
https://embeded.bridgewise.com/{language}/{tenant}/{widgetName}?accessToken=...&identifier=...&identifierType=...&mode=...&actionType=...&sessionId=...&userId=...&scoringMethod=...Path parameters
| Name | Location | Required | Format / Default | Description |
|---|---|---|---|---|
language | Path | Yes | en-US, he-IL, etc. | UI language (BCP-47 locale) for the widget. |
tenant | Path | Yes | Your tenant name, or bw | Tenant namespace and theme preset provided by Bridgewise. |
widgetName | Path | Yes | bridget-chat / bridget-teaser | Controls which Bridget widget is rendered. |
Query parameters (shared by all widgets)
| Name | Location | Required | Format / Default | Description |
|---|---|---|---|---|
accessToken | Query | Yes | – | Access token returned by your backend. Used by widgets for data requests. |
identifier | Query | No | e.g. AAPL-Nasdaq | Security/fund identifier for context. Supported formats: ISIN or ticker-exchange. |
identifierType | Query | No | ticker_exchange / isin | Explicit identifier type. |
mode | Query | No | light (default) / dark | Color theme of the widget. |
actionType | Query | No | default / external / prevent | Controls click behavior for links and securities. |
sessionId | Query | Yes | – | Session identifier for analytics correlation. |
userId | Query | Yes | – | User identifier for analytics correlation. |
scoringMethod | Query | No | – | Optional scoring method influencing specific analytics. |
3.2 Available Bridget Widgets
| widgetName | Description | Default URL (vanilla UI) |
|---|---|---|
bridget-chat | Main Bridget app with full chat capabilities. | https://embeded.bridgewise.com/en-US/bw/bridget-chat |
bridget-teaser | Compact teaser block with example questions. | https://embeded.bridgewise.com/en-US/bw/bridget-teaser |
4. Bridget-Specific Parameters
| Name | Format / Default | Description |
|---|---|---|
bridget.username | Any string | User name for personalized interactions. |
bridget.q | Any string | Default prompt message. Skips welcome screen. |
bridget.event-disclaimer | true | Disables default disclaimer modal. Emits event. |
bridget.event-clipboard | true | Disables built-in “copy to clipboard”. Emits event. |
bridget.examples | URI-encoded JSON | Example questions for the Bridget welcome screen. |
teaser.examples | URI-encoded JSON | Example questions for the teaser widget. |
5. Prompt Mapping & Examples
Parameters bridget.q, bridget.examples, and teaser.examples support a text/query mapping format: { t: "Displayed text", q: "Submitted prompt" }.
// Step 1 – define your prompts
const examples = [
{ t: "Hello" },
{ t: "Market recap", q: "Show me the daily market recap with key index moves." }
];
// Step 2 – stringify and encode
const param = encodeURIComponent(JSON.stringify(examples));6. Events & postMessage
Bridget widgets send JSON-serialized messages to window.parent via postMessage.
| Type | Payload | Description |
|---|---|---|
load | { height: number } | Widget fully loaded; provides suggested height. |
resize | { height: number } | Content height changed; use for auto-resize. |
success | { height: number } | Successful state update. |
error | { message, status } | Error inside the widget or underlying services. |
click | { id: string } | Click events (clipboard, disclaimer, etc.). |
hover | { id: string } | Hover events. |
navigate | { href: string } | Emitted when actionType=external. |
security-select | { ticker, exchange } | Security selected. |
bridget-teaser-trigger | { message } | Emitted when a teaser question is clicked. |
7. Handling Navigation
| actionType | Behavior |
|---|---|
default | All links behave natively. |
prevent | All link clicks are disabled. |
external | No in-widget navigation. Emits navigate or security-select. |
8. Theming, Localization, Errors & Security
- Theming: Set
mode=darkorlight. Host iframe should haveborder:0. - Localization: Pass language code in path (e.g.
en-US,he-IL). - Error handling: Listen for
errorevents (e.g. invalid token) and surface a message. - Security: Always validate
event.originishttps://embeded.bridgewise.com.
9. Per-Security Text Customization
Use placeholders in customized text lines: {companyName} and {companyTicker}. When you load the widget with an ?identifier=... parameter, these are automatically replaced.
10. Native Mobile Integration
10.1 iOS (SwiftUI / UIKit)
import SwiftUI
import WebKit
struct WidgetView: UIViewRepresentable {
@Binding var height: CGFloat
let widgetURL: String
func makeCoordinator() -> Coordinator { Coordinator(self) }
func makeUIView(context: Context) -> WKWebView {
let configuration = WKWebViewConfiguration()
let userContentController = WKUserContentController()
let script = """
window.addEventListener('message', function (event) {
if (event.origin !== 'https://embeded.bridgewise.com') return;
window.webkit.messageHandlers.postMessage.postMessage(event.data);
}, false);
"""
let userScript = WKUserScript(source: script, injectionTime: .atDocumentStart, forMainFrameOnly: false)
userContentController.addUserScript(userScript)
userContentController.add(context.coordinator, name: "postMessage")
configuration.userContentController = userContentController
return WKWebView(frame: .zero, configuration: configuration)
}
func updateUIView(_ webView: WKWebView, context: Context) {
if let url = URL(string: widgetURL) { webView.load(URLRequest(url: url)) }
}
class Coordinator: NSObject, WKNavigationDelegate, WKScriptMessageHandler {
var parent: WidgetView
init(_ parent: WidgetView) { self.parent = parent }
func userContentController(_ ucc: WKUserContentController, didReceive message: WKScriptMessage) {
// Parse JSON message from iframe here
}
}
}10.2 Android (WebView)
class WidgetWebView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : WebView(context, attrs) {
init {
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
addJavascriptInterface(PostMessageHandler(), "AndroidInterface")
webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView?, url: String?) {
val script = """
window.addEventListener('message', function (event) {
if (event.origin !== 'https://embeded.bridgewise.com') return;
AndroidInterface.handlePostMessage(typeof event.data === 'string' ? event.data : JSON.stringify(event.data));
}, false);
"""
evaluateJavascript(script, null)
}
}
}
inner class PostMessageHandler {
@JavascriptInterface
fun handlePostMessage(messageData: String) {
// Handle JSON message
}
}
}11. Mobile Integration Notes
- The widget is responsive and adapts to mobile viewports automatically.
- Use
actionType=externalto handle security selections in your app instead of redirecting to Bridgewise. - Listen for
errorevents to handle network or authentication issues gracefully.
12. Optional: Compression for Long Parameters
If your encoded JSON for bridget.examples is too long: Stringify → Gzip → Base64 → Prefix gz_ → URI Encode.
async function compress(str) {
const blob = new Blob([str]);
const stream = blob.stream().pipeThrough(new CompressionStream("gzip"));
const compressed = await new Response(stream).arrayBuffer();
return String.fromCharCode.apply(null, new Uint8Array(compressed));
}
async function encode(data) {
const base64 = btoa(await compress(JSON.stringify(data)));
return encodeURIComponent("gz_" + base64);
}Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article