Create the ChatBubble instance
Subscribe to updates to the badge counter in the chat bubble.
Usage:
bubble.onBadgeCountUpdate.subscribe(count => console.log(`Count updated: ${count}`))
When you subscribe to the badge count update, the callback is invoked right away with the current badge count value.
Subscribe to any events that are sent from the server. From within a bot, an event can be
emitted to the chat bubble, by doing emit "name", to: :chat_bubble
in BubbleScript.
Subscribe to nudges that are sent from the server. Nudges are sent in response to visitor events, mainly page views.
Open the websocket connection to the server.
Close the connection to the server, if it was opened.
Return the current config. This is the Config object that was passed in, augmented with all the default parameters.
Return the current user ID of this connection
Return the locally known information about the user.
Retrieve the URL for the webview that can be embedded to show the bot's conversation(s).
Returns null
when not connected or when the configured but does not have a publicly
accessible web interface.
Signal the server that the user has discarded a nudge. The given nudge will not be triggered again for this user.
Signal the server that the user has engaged with a nudge.
Signal the server that the user has seen the nudge.
Register a push token for the current connection.
Valid push types are web-push
, firebase
, pushwoosh
and expo
.
Report the opened state of the chat back to the chat bubble
While the chat is opened, nudges will be suspended from triggering.
Send a page scroll percentage to the server
Nudges can be triggered when the page has scrolled to a certain percentage.
Send a page view event to the server.
Use this to track on which page of the website your user is currently visiting. In the backend this is used to show a realtime view of current visitors.
The URL of the current page. This parameter needs to be a valid URL, in the form of scheme://hostname/path
. For native apps, use something like app://app-package-name/current-screen
. If your native app supports Android app links or iOS Universal links, you can also send these.
The title of the current page or app screen.
Generated using TypeDoc
ChatBubble
The ChatBubble class is the high-level container class that allows you to render a Chat Bubble in your web page or React Native app.
Main entry point for interfacing with all functions related to the Botsquad chat bubble. Its main purposes are the following:
Getting started
Instantiate this class with a Config object; then call ChatBubble.connect to establish the connection to the server.
Example code:
import { ChatBubble } from '@botsquad/sdk' const config = { // required: botId: '66a8fe768ea6fea876f987ea', userAgent: 'testApp/1.0 (Android; 8)', // optional: locale: 'nl_NL', timezone: 'Europe/Amsterdam', userToken: '<userToken that was sent on the previous connect()>', hostname: 'bsqd.me' } const bubble = new ChatBubble(config) // initiate the connection. const info = await bubble.connect() // information that is returned: const { userToken, userInfo, badgeCount, bot: { id, title, profilePicture } } = info console.log(`Connected with user token: ${userToken}`) bubble.on('badgeCountUpdate', badgeCount => { console.log('Got new badge count: ' + badgeCount) }) // page change bubble.sendPageView('http://pageurl.com', 'page title') // nudges bubble.on('nudge', nudge => { const { message, profilePicture, caption } = nudge // show the nudge if (caption) { // show nudge with title bar and (optionally) a picture } else { // show basic message-only nudge } }) // dismiss the nudge bubble.nudgeDismiss(nudge) // engage with the nudge await bubble.nudgeEngage(nudge) // open the chat by visiting the webview URL: bubble.getWebviewUrl() // configure push token await bubble.configurePushToken('pushwoosh', '<token data>') // send extra user information to the bot await bubble.putUserInfo({ first_name: "john", last_name: "doe", visitor_id: "12345" })