Skip to main content
Version: 3.6.0

Usage Examples

Adjust Message​

import OptaveJavaScriptSDK from '@optave/client-sdk';

const client = new OptaveJavaScriptSDK({
websocketUrl: 'wss://ws-{{tenant}}.oco.optave.{{tld}}',
authenticationUrl: 'https://{{tenant}}.oco.optave.{{tld}}/auth/oauth2/token',
clientId: 'tenant-client-id-here',
clientSecret: 'tenant-client-secret-here',
});

// Listen for messages from the WebSocket. Received superpowers should be handled here
client.on('message', payload => {
const message = JSON.parse(payload);
const { actionType, state, action } = message;

// Handle response depending on actionType, state, and action
});

// Handle errors
client.on('error', error => {
console.error('Error:', error);
});

// After the connection is opened, send an adjust message
client.on('open', () => {
const params = { your-payload-here }
client.adjust(params);
});

// Authenticate and open the WebSocket connection
const token = await client.authenticate();
client.openConnection(token);

Customer Interaction Message​

import OptaveJavaScriptSDK from '@optave/client-sdk';

const client = new OptaveJavaScriptSDK({
websocketUrl: 'wss://ws-{{tenant}}.oco.optave.{{tld}}',
authenticationUrl: 'https://{{tenant}}.oco.optave.{{tld}}/auth/oauth2/token',
clientId: 'tenant-client-id-here',
clientSecret: 'tenant-client-secret-here',
});

// Listen for messages from the WebSocket. Received superpowers should be handled here
client.on('message', payload => {
const message = JSON.parse(payload);
const { actionType, state, action } = message;

// Handle response depending on actionType, state, and action
});

// Handle errors
client.on('error', error => {
console.error('Error:', error);
});

// After the connection is opened, send a customer interaction message
client.on('open', () => {
const params = { your-payload-here }
client.customerInteraction(params);
});

// Authenticate and open the WebSocket connection
const token = await client.authenticate();
client.openConnection(token);

Elevate Message​

import OptaveJavaScriptSDK from '@optave/client-sdk';

const client = new OptaveJavaScriptSDK({
websocketUrl: 'wss://ws-{{tenant}}.oco.optave.{{tld}}',
authenticationUrl: 'https://{{tenant}}.oco.optave.{{tld}}/auth/oauth2/token',
clientId: 'tenant-client-id-here',
clientSecret: 'tenant-client-secret-here',
});

// Listen for messages from the WebSocket. Received superpowers should be handled here
client.on('message', payload => {
const message = JSON.parse(payload);
const { actionType, state, action } = message;

// Handle response depending on actionType, state, and action
});

// Handle errors
client.on('error', error => {
console.error('Error:', error);
});

// After the connection is opened, send an elevate message
client.on('open', () => {
const params = { your-payload-here }
client.elevate(params);
});

// Authenticate and open the WebSocket connection
const token = await client.authenticate();
client.openConnection(token);

Insights Message​

import OptaveJavaScriptSDK from '@optave/client-sdk';

const client = new OptaveJavaScriptSDK({
websocketUrl: 'wss://ws-{{tenant}}.oco.optave.{{tld}}',
authenticationUrl: 'https://{{tenant}}.oco.optave.{{tld}}/auth/oauth2/token',
clientId: 'tenant-client-id-here',
clientSecret: 'tenant-client-secret-here',
});

// Listen for messages from the WebSocket. Received superpowers should be handled here
client.on('message', payload => {
const message = JSON.parse(payload);
const { actionType, state, action } = message;

// Handle response depending on actionType, state, and action
});

// Handle errors
client.on('error', error => {
console.error('Error:', error);
});

// After the connection is opened, send an insights message
client.on('open', () => {
const params = { your-payload-here }
client.insights(params);
});

// Authenticate and open the WebSocket connection
const token = await client.authenticate();
client.openConnection(token);

Recommend Message​

import OptaveJavaScriptSDK from '@optave/client-sdk';

const client = new OptaveJavaScriptSDK({
websocketUrl: 'wss://ws-{{tenant}}.oco.optave.{{tld}}',
authenticationUrl: 'https://{{tenant}}.oco.optave.{{tld}}/auth/oauth2/token',
clientId: 'tenant-client-id-here',
clientSecret: 'tenant-client-secret-here',
});

// Listen for messages from the WebSocket. Received superpowers should be handled here
client.on('message', payload => {
const message = JSON.parse(payload);
const { actionType, state, action } = message;

// Handle response depending on actionType, state, and action
});

// Handle errors
client.on('error', error => {
console.error('Error:', error);
});

// After the connection is opened, send an recommend message
client.on('open', () => {
const params = { your-payload-here }
client.recommend(params);
});

// Authenticate and open the WebSocket connection
const token = await client.authenticate();
client.openConnection(token);

Summarize Message​

import OptaveJavaScriptSDK from '@optave/client-sdk';

const client = new OptaveJavaScriptSDK({
websocketUrl: 'wss://ws-{{tenant}}.oco.optave.{{tld}}',
authenticationUrl: 'https://{{tenant}}.oco.optave.{{tld}}/auth/oauth2/token',
clientId: 'tenant-client-id-here',
clientSecret: 'tenant-client-secret-here',
});

// Listen for messages from the WebSocket. Received superpowers should be handled here
client.on('message', payload => {
const message = JSON.parse(payload);
const { actionType, state, action } = message;

// Handle response depending on actionType, state, and action
});

// Handle errors
client.on('error', error => {
console.error('Error:', error);
});

// After the connection is opened, send an summarize message
client.on('open', () => {
const params = { your-payload-here }
client.summarize(params);
});

// Authenticate and open the WebSocket connection
const token = await client.authenticate();
client.openConnection(token);

Translate Message​

import OptaveJavaScriptSDK from '@optave/client-sdk';

const client = new OptaveJavaScriptSDK({
websocketUrl: 'wss://ws-{{tenant}}.oco.optave.{{tld}}',
authenticationUrl: 'https://{{tenant}}.oco.optave.{{tld}}/auth/oauth2/token',
clientId: 'tenant-client-id-here',
clientSecret: 'tenant-client-secret-here',
});

// Listen for messages from the WebSocket. Received superpowers should be handled here
client.on('message', payload => {
const message = JSON.parse(payload);
const { actionType, state, action } = message;

// Handle response depending on actionType, state, and action
});

// Handle errors
client.on('error', error => {
console.error('Error:', error);
});

// After the connection is opened, send an translate message
client.on('open', () => {
const params = { your-payload-here }
client.translate(params);
});

// Authenticate and open the WebSocket connection
const token = await client.authenticate();
client.openConnection(token);