Skip to main content

Receive Live Topics

This example goes over how you can use the Symbl Streaming API to receive Topics, which are what the Symbl API determines to be the most important keywords or phrases used in a conversation. This example uses both the Symbl's Javascript SDK, which is meant to be run using Node.js, and native Javascript which can be run in the browser:

Connect#

The first thing we do is connect to the Web Socket. If you're using the SDK you can use onTopicResponse handler after the connection is established, otherwise you'll have to parse the response in the onmessage callback for the WebSocket.

const {sdk} = require('symbl-node');
const uuid = require('uuid').v4;
(async () => {
try {
// Initialize the SDK
await sdk.init({
appId: appId,
appSecret: appSecret,
basePath: 'https://api.symbl.ai',
})
// Need unique Id
const id = uuid()
// Start Real-time Request (Uses Real-time WebSocket API behind the scenes)
const connection = await sdk.startRealtimeRequest({
id,
insightTypes: ['action_item', 'question'],
config: {
meetingTitle: 'My Test Meeting',
confidenceThreshold: 0.7,
timezoneOffset: 480, // Offset in minutes from UTC
languageCode: 'en-US',
sampleRateHertz: 44100,
},
speaker: {
// Optional, if not specified, will simply not send an email in the end.
userId: 'emailAddress', // Update with valid email
name: 'My name'
},
handlers: {
/**
* When Symbl detects a topic, this callback will be called.
*/
onTopicResponse: (data) => {
console.log('onTopicResponse', JSON.stringify(data, null, 2));
// The topic is found in data.phrase.
console.log('Topic:', data.phrase);
}
}
});
} catch (e) {
console.error(e);
}
})();

Testing#

Create a javascript file named app.js and copy this code into the file. Fill in the placeholder values with the proper values. Use npm to install the required libraries: npm install symbl-node uuid. Now in the terminal run

$ node app.js

If successful you should receive a response in the console.

Handlers Reference#

  • handlers: This object has the callback functions for different events

    • onTopicResponse: This callback provides you with any of the detected topics in real-time as they are detected. As with the onMessageCallback this would also return every topic in case of multiple streams.

      onTopicResponse JSON Response Example#

      [{
      "id": "e69a5556-6729-11eb-ab14-2aee2deabb1b",
      "messageReferences": [{
      "id": "0df44422-0248-47e9-8814-e87f63404f2c",
      "relation": "text instance"
      }],
      "phrases": "auto insurance",
      "rootWords": [{
      "text": "auto"
      }],
      "score": 0.9,
      "type": "topic"
      }]