Agent SDK (beta)
Client-side JavaScript SDK to build custom agent-side integrations

Overview

Our Agent SDK can be used to build 100% customized agent-side integrations into your own products and services.

Quick start

Navigate to our Agent SDK Demo Page and open up our Cobrowse.io Online Demo in another browser tab to generate your Demo ID.
This Demo Page uses our Agent UI component library, our Agent SDK, and ties it together into an Agent SDK Examples project which you can run locally.

Authentication

If you are using the Agent SDK just to communicate over postMessage to an embedded IFrame, a JWT is not required.
Device and Session listing via the Agent SDK requires a JSON Web Token (JWT) for authentication. Learn how to generate a JWT for your account at Authentication (JWTs).

Features

The Agent SDK can be used to:
    List Devices and/or Sessions matching your filter criteria
      Build your own 100% customized dashboard or device list
      Show only a single user's devices in the context of a support ticket or chat
    Subscribe to events on Devices and Sessions
      Create a smart connect button, that changes color when the devices goes online/offline
    Interact with embedded Cobrowse.io iFrames
      Get notified in the parent page when a session begins and ends
      Attach a button in the parent page to end the session, or select the agent's tool
      Programmatically end the session before the parent page closes

List devices and sessions (JWT required)

1
import CobrowseAPI from 'cobrowse-agent-sdk';
2
3
(async function() {
4
const cobrowse = new CobrowseAPI();
5
cobrowse.token = 'jwt token'; // generate a JWT (see docs)
6
7
// list devices and sessions
8
const [devices, sessions] = await Promise.all([
9
cobrowse.devices.list(),
10
cobrowse.sessions.list({state:['active', 'ended'], activated: new Date(0)})
11
]);
12
13
// subscribe to updates for these resources
14
devices.forEach(device => device.subscribe());
15
sessions.forEach(sessions => sessions.subscribe());
16
17
// listen for updates
18
devices.forEach(device => device.on('updated', (d) => console.log(d)));
19
sessions.forEach(session => session.on('updated', (s) => console.log(s)));
20
21
// get details for a single device
22
if (devices.length > 0) {
23
console.log('last active', devices[0].last_active);
24
console.log('custom data', JSON.stringify(devices[0].custom_data));
25
}
26
}());
Copied!

Attach context to iFrame (no JWT required)

1
import CobrowseAPI from 'cobrowse-agent-sdk';
2
3
(async function() {
4
const cobrowse = new CobrowseAPI(); // JWT not required
5
6
// attach to iframe (make sure it has loaded!)
7
const frameEl = document.getElementById('myIframe');
8
const ctx = await cobrowse.attachContext(frameEl);
9
10
// listen for updates to session
11
ctx.on('session.updated', (session) => {
12
console.log('session was updated', session);
13
if (session.ended) {
14
console.log('session has ended');
15
ctx.destroy();
16
}
17
});
18
19
// interact with iframe
20
await ctx.setTool('laser');
21
// await ctx.clearAnnotations();
22
// await ctx.endSession();
23
}());
Copied!
The Agent SDK is currently in beta release. Some APIs may change.
Last modified 6mo ago