Sample code snippets
Build the experience that you want for your support agents with our powerful agent SDK. Here are some examples of commonly required functionality.
Our agent SDK is a powerful toolkit to build the experience that you want for your support agents. Here we have put together a number of examples of commonly required functionality.
List only relevant sessions or devices using filters
Using our custom data mechanism you can add metadata that lets you link Cobrowse device and session records with your users. You can use this same data to filter when listing resources via our agent SDK.
You can construct a filter query for a custom data entry by prepending "filter_" to the key of your custom data. For example, user_id
becomes filter_user_id
:
The same system applied to both Session resources and Device resources. See the API reference for the available parameters:
API ReferenceListen for updates on a session or device
Often it's useful to know when the state of a session or device resource changes so you can provide a user interface that updates in real time. This is possible through our agent SDK.
Subscribing to Session resources
Subscribing to Device resources
Control an IFrame embedded in my support agents' portal
When integrating Cobrowse to your own custom helpdesk or CRM, many customers need to control some aspects within the Cobrowse IFrames, such as switch the agent tool, or ending the session. We provide an easy mechanism for this (no JWT required!)
See the API reference for full details on what you can do using an IFrame context. You may also find the embed documentation useful:
IFrame embedsAccess and update the session in the IFrame
Sometimes it's useful to access the session that was created in an IFrame in order to modify some properties that cannot be directly controlled through the IFrame methods. First you'll need to get the access to the session from the IFrame:
Then at some point later, when you want to make a change to the session, you use the session object that was passed in the session.updated
event. Note: you will need to configure a JWT in the agent SDK to call some methods that require authentication on the session object.
Add extra data to a session from the agent side
Sometimes the data that you want to associate with a session may not be available from the user-side to use with the device side SDKs. In this case it is possible to add custom data from the agent side that will remain associated with a session.
See the links below for more on how to generate a token or choose the best link to embed.
IFrame embedsAuthentication (JWTs)Completely replace the session UI with my own design
Cobrowse is designed to be fully customizable, including the agent side experience. We've put together a small example to show how to build your own in-session UI. Find the full source code on GitHub, or try the demo here.
Check the number of active sessions
It's often useful to know how many active sessions are in progress. The sample below provides a basic way to list all active
sessions for your account.
Note: if you have more than 1000 concurrently active
sessions you will need to add paging to this example to count them all.
End the session after a chat/interaction, or after the browser is closed
There's multiple ways to end a Cobrowse session, which one to use will depend on your use case. The options include:
Using the device-side SDKs to call
session.end()
(the exact syntax will depend on the SDK used)Using the default agent-side UI by clicking the red "hang-up" icon
Using the agent SDK APIs to programatically end the session, either via the IFrame context, or via an API call with a JWT.
Letting the server end the session after a timeout. If the device or agent closes the app or browser the server will clean up sessions automatically after approximately 5 minutes of inactivity.
Leave without ending the session
Sometimes it's useful to be able to leave the session without ending it, for example when a supervisor is monitoring a number of ongoing sessions needs to switch between them. You can simply close the tab or remove the IFrame without ending the session to achieve this.
Last updated