Skip to content

Commit

Permalink
Merge pull request #12 from dyte-in/fix/add-conversation-id
Browse files Browse the repository at this point in the history
fix: add conversationId to transcriptions
  • Loading branch information
madhugb authored Jan 3, 2024
2 parents 87fc949 + ee3af81 commit 89f82be
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ activateTranscriptions({
sentiment: false,
},
},
symblStreamingMessageCallback: (event) => { // optional. If you need it for a custom use case
console.log('event from symbl')
},
});
```

Expand All @@ -61,7 +64,10 @@ activateTranscriptions({
speaker: {
email: '[email protected]',
}
}
},
symblStreamingMessageCallback: (event) => { // optional. If you need it for a custom use case
console.log('event from symbl')
},
});
```

Expand Down
7 changes: 2 additions & 5 deletions demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ defineCustomElements();
const init = async () => {
try {
const params = new URLSearchParams(window.location.search);
const roomName = params.get('roomName') || '';
const authToken = params.get('authToken') || '';
const symblAccessToken = params.get('symblAccessToken') || '';

if (!authToken || (roomName && !authToken)) {
alert('Please pass authToken (and roomName, if you are using v1 APIs) in query params');
if (!authToken) {
alert('Please pass authToken in query params');
return;
}
if (!symblAccessToken) {
Expand All @@ -27,8 +26,6 @@ const init = async () => {

const meeting = await DyteClient.init({
authToken,
roomName,
apiBase: 'https://api.dyte.io',
defaults: {
audio: false,
video: false,
Expand Down
1 change: 1 addition & 0 deletions src/param_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ActivateTranscriptionsConfig {
symblStartRequestParams?: { // https://docs.symbl.ai/reference/streaming-api-reference#start_request
[key:string]: any,
},
symblStreamingMessageCallback?: (event: any) => void,
}

export interface DeactivateTranscriptionsConfig {
Expand Down
15 changes: 15 additions & 0 deletions src/symbl_transcriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import merge from 'lodash-es/merge';
import audioTranscriptionMiddleware from './audio_middleware';
import { ActivateTranscriptionsConfig, DeactivateTranscriptionsConfig } from './param_types';
import {
getConversationId,
getPeerIdBySymblId,
getWebSocket,
setConversationId,
setPeerIdForSymblId,
setTranscriptions,
setWebSocket,
Expand All @@ -22,6 +24,7 @@ async function activateTranscriptions({
connectionId,
speakerUserId,
symblStartRequestParams = {},
symblStreamingMessageCallback,
}: ActivateTranscriptionsConfig) {
// As a fail-safe, deactivateTranscriptions if activateTranscriptions function is called twice
// eslint-disable-next-line no-use-before-define
Expand All @@ -40,6 +43,11 @@ async function activateTranscriptions({
console.error('Symbl error: ', data);
return;
}
if (data.type === 'message' && data.message.type === 'conversation_created') {
// console.log('Symbl conversation created: ', data);
setConversationId(data.message.data.conversationId);
}

if (data.type === 'message_response') {
data.messages?.forEach((message: any) => {
// console.log('Live transcript (more accurate): ', message.payload.content, data);
Expand All @@ -56,6 +64,7 @@ async function activateTranscriptions({
peerId: meeting.self.id,
displayName: meeting.self.name,
id: message.id,
conversationId: getConversationId(),
},
);
}
Expand All @@ -80,10 +89,16 @@ async function activateTranscriptions({
endTimeISO: data.message.duration?.endTime || new Date().toISOString(),
peerId: meeting.self.id,
displayName: meeting.self.name,
conversationId: getConversationId(),
},
);
}
}

// Call the callback
if (symblStreamingMessageCallback) {
symblStreamingMessageCallback(data);
}
};

// Fired when the WebSocket closes unexpectedly due to an error or lost connetion
Expand Down
11 changes: 11 additions & 0 deletions src/transcriptions_building_blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { BroadcastMessagePayload } from '@dytesdk/web-core';
let ws: WebSocket;

let transcriptions: BroadcastMessagePayload[] = [];
let conversationId: string = '';

const symblIdToPeerIdMap: {[key: string]: string} = {};

Expand All @@ -29,11 +30,21 @@ function setPeerIdForSymblId(symblId: string, peerId: string) {
symblIdToPeerIdMap[symblId] = peerId;
}

function getConversationId() {
return conversationId;
}

function setConversationId(newConversationId: string) {
conversationId = newConversationId;
}

export {
getWebSocket,
setWebSocket,
getTranscriptions,
setTranscriptions,
getPeerIdBySymblId,
setPeerIdForSymblId,
getConversationId,
setConversationId,
};

0 comments on commit 89f82be

Please sign in to comment.