Subscribe to Real Time Events

Javascript SDK also lets you subscribe to real-time events when you connect to one of the Endpoints specified in the above sections. These include

  1. Real-Time Transcription
  2. Real-Time Insights
  3. Real-Time Messages
  4. Real-Time Intents

The below example shows how to achieve this.

Initialize SDK#

const {sdk, SpeakerEvent} = require("symbl-node");
sdk.init({
// Your appId and appSecret https://platform.symbl.ai
appId: 'your_appId',
appSecret: 'your_appSecret'
}).then(async () => {
console.log('SDK initialized.');
try {
// You code goes here.
} catch (e) {
console.error(e);
}
}).catch(err => console.error('Error in SDK initialization.', err));

Add the above lines to import and initialize the SDK. Replace the appId and appSecret in the code. You can find the them by signing up on Symbl Developer Platform

Make a phone call#

const connection = await sdk.startEndpoint({
endpoint: {
type: 'pstn', // when making a regular phone call
// Replace this with a real phone number
phoneNumber: '1XXXXXXXXXX' // include country code
}
});
const {connectionId} = connection;
console.log('Successfully connected. Connection Id: ', connectionId);

The above snippet makes a phone call, by calling the startEndpoint with type set to pstn and a valid US/Canada Phone Number phoneNumber. You can also call in via type sip as well and the steps below will still remain the same.

Subscribe to the Live Events#

// Subscribe to connection using connectionId.
sdk.subscribeToConnection(connectionId, (data) => {
const {type} = data;
if (type === 'transcript_response') {
const {payload} = data;
// You get live transcription here!!
process.stdout.write('Live: ' + payload && payload.content + '\r');
} else if (type === 'message_response') {
const {messages} = data;
// You get processed messages in the transcript here!!! Real-time but not live! :)
messages.forEach(message => {
process.stdout.write('Message: ' + message.payload.content + '\n');
});
} else if (type === 'insight_response') {
const {insights} = data;
// See <link here> for more details on Insights
// You get any insights here!!!
insights.forEach(insight => {
process.stdout.write(`Insight: ${insight.type} - ${insight.text} \n\n`);
});
}
});

The above snippet calls the subscribeToConnection which requires the connectionId of the call and a callback function to be passed as the second argument which will be invoked when any of the above events are available to be consumed. The data received will contain type of the event. It can be one of transcript_response, message_response, insight_response.

Lets go over them one by one.

  1. transcript_response : This contains the real-time transcription data which is availabe as soon as its detected.

  2. message_response : This will contain the array of the transcripts of all the speakers which will be logically separated by punctuations or the speakers if Active Speaker Events are pushed.

  3. insight_response : This will contain the array of all the insights detected in real-time. These can be action-items or questions.

There is also a 4th type of event which is intent_response covered in a separate example.

End the call#

// Stop call after 60 seconds to automatically.
setTimeout(async () => {
const connection = await sdk.stopEndpoint({ connectionId });
console.log('Stopped the connection');
console.log('Conversation ID:', connection.conversationId);
}, 60000); // Change the 60000 with higher value if you want this to continue for more time.

To end the call gracefully, we call the stopEndpoint call to stop the call. The code snippet above simply stops the call after 60 seconds.

And we're done! That's how you can consume real-time events using Javascript SDK!

The complete code for the example above can be found here