From 88748627c4061803d9a1a45394b7901fccdd6792 Mon Sep 17 00:00:00 2001 From: Ariel Mannes Date: Tue, 8 Jul 2025 10:52:19 +0300 Subject: [PATCH] add 'participant' to protocol messages in order to support interactive agent assist --- src/websocket/bot-conversation.ts | 14 ++++++++++---- src/websocket/types.ts | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/websocket/bot-conversation.ts b/src/websocket/bot-conversation.ts index cae52f2..8959e07 100644 --- a/src/websocket/bot-conversation.ts +++ b/src/websocket/bot-conversation.ts @@ -141,7 +141,7 @@ export class BotConversationWebSocket extends EventEmitter2 implements BotConver case VaicToBotMessageName.userStreamStart: this.userAudio = new PassThrough(); this.emit('userStream', this.userAudio, { message: msgJson }); - await this.send(BotToVaicMessageName.userStreamStarted); + await this.send(BotToVaicMessageName.userStreamStarted, { participant: msgJson.participant }); break; case VaicToBotMessageName.userStreamChunk: this.userAudio?.write(Buffer.from(msgJson.audioChunk!, 'base64')); @@ -149,7 +149,7 @@ export class BotConversationWebSocket extends EventEmitter2 implements BotConver case VaicToBotMessageName.userStreamStop: this.#log('user stream stopped'); this.userAudio?.end(); - await this.send(BotToVaicMessageName.userStreamStopped); + await this.send(BotToVaicMessageName.userStreamStopped, { participant: msgJson.participant }); delete this.userAudio; break; case VaicToBotMessageName.activities: @@ -191,16 +191,18 @@ export class BotConversationWebSocket extends EventEmitter2 implements BotConver } } - sendHypothesis(text: string) { + sendHypothesis(text: string, participant?: string) { return this.send(BotToVaicMessageName.userStreamSpeechHypothesis, { + participant, alternatives: [{ text: text.toLowerCase() }] }); } - sendRecognition(text: string, confidence: number) { + sendRecognition(text: string, confidence: number, participant?: string) { return this.send(BotToVaicMessageName.userStreamSpeechRecognition, { + participant, alternatives: [{ text: text.toLowerCase(), confidence @@ -208,6 +210,10 @@ export class BotConversationWebSocket extends EventEmitter2 implements BotConver }); } + sendCommitted(participant?: string) { + return this.send(BotToVaicMessageName.userStreamSpeechCommitted, { participant }); + } + async playTextMessage(text: string, params?: Record) { return this.sendActivity({ type: BotActivityType.message, diff --git a/src/websocket/types.ts b/src/websocket/types.ts index f890601..58a17be 100644 --- a/src/websocket/types.ts +++ b/src/websocket/types.ts @@ -98,6 +98,7 @@ export interface ProtocolMessage extends PlayAudioOptions { expectAudioMessages?: boolean; supportedMediaFormats?: string[]; caller?: string; + participant?: string activities?: BotActivity[]; audioChunk?: string; [key: string]: unknown;