Class: Conversation
Properties
speaker
• Readonly
speaker: string
defaultCountry
▪ Static
Readonly
defaultCountry: "us" = "us"
defaultModel
▪ Static
Readonly
defaultModel: "en" = "en"
validCountries
▪ Static
Readonly
validCountries: Set<string> = new Set(["fr", "us"])
validModels
▪ Static
Readonly
validModels: Set<string> = new Set(["es", "fr", "en"])
Events Methods
onClose
▸ onClose(callback
: () => void): Conversation
Subscribe to Conversation onClose
event.
example
const uhlive = new Uhlive("my-token");
const conversation = uhlive.join("test");
conversation.onClose(() => {
// Choose what to do when the conversation is closed.
})
Parameters:
Name | Type |
---|---|
callback | () => void |
Returns: Conversation
onEntityFound
▸ onEntityFound(entityName
: EntityEvent | "*", callback
: (entity: Entity,entityName: EntityEvent) => void): Conversation
This event is triggered when the specified entity has been found or the wildcard is used and any entity is found.
example
const uhlive = new Uhlive("my-token");
const myConversation = uhlive.join("my-conversation");
myConversation.onEntityFound("LocationCity", (entity) => {
// Do something with `entity`...
});
Parameters:
Name | Type |
---|---|
entityName | EntityEvent | "*" |
callback | (entity: Entity,entityName: EntityEvent) => void |
Returns: Conversation
onEntityRelationFound
▸ onEntityRelationFound(relationName
: EntitiesRelationEvent | "*", callback
: (entities: EntityRef[]) => void): Conversation
This event is triggered when an entity with possible relations is found. It is emitted event if only one entity is found.
example
const uhlive = new Uhlive("my-token");
const myConversation = uhlive.join("my-conversation");
myConversation.onEntityRelationFound("CreditCard", (relation) => {
// Do something with `relation`...
});
Parameters:
Name | Type |
---|---|
relationName | EntitiesRelationEvent | "*" |
callback | (entities: EntityRef[]) => void |
Returns: Conversation
onError
▸ onError(callback
: (payload: any) => void): Conversation
Subscribe to Conversation onError
event.
example
const uhlive = new Uhlive("my-token");
const conversation = uhlive.join("test");
conversation.onError((msg) => console.log(msg))
Parameters:
Name | Type |
---|---|
callback | (payload: any) => void |
Returns: Conversation
onSegmentDecoded
▸ onSegmentDecoded(callback
: (transcript: SegmentDecoded) => void): Conversation
The onSegmentDecoded
event is triggered when a final transcript is received.
example
const uhlive = new Uhlive("my-token");
const myConversation = uhlive.join("my-conversation");
myConversation.onSegmentDecoded((transcript) => {
// Do something with `transcript`...
});
Parameters:
Name | Type |
---|---|
callback | (transcript: SegmentDecoded) => void |
Returns: Conversation
onSegmentNormalized
▸ onSegmentNormalized(callback
: (transcript: SegmentNormalized) => void): Conversation
The onSegmentNormalized
event is triggered when a segment has been normalized.
example
const uhlive = new Uhlive("my-token");
const myConversation = uhlive.join("my-conversation");
myConversation.onSegmentNormalized((transcript) => {
// Do something with `transcript`...
});
Parameters:
Name | Type |
---|---|
callback | (transcript: SegmentNormalized) => void |
Returns: Conversation
onSpeakerJoined
▸ onSpeakerJoined(callback
: (payload: SpeakerJoined) => void): Conversation
The speaker_joined
event is triggered when a speaker join the conversation. It is sent to everyone except the speaker itself. Note that users connected in read-only mode (observers) don't emit this event.
example
const uhlive = new Uhlive("my-token");
const myConversation = uhlive.join("my-conversation");
myConversation.onSpeakerJoined((payload) => {
// Do something with `payload`...
});
Parameters:
Name | Type |
---|---|
callback | (payload: SpeakerJoined) => void |
Returns: Conversation
onSpeakerLeft
▸ onSpeakerLeft(callback
: (payload: SpeakerLeft) => void): Conversation
The speaker_left
event is triggered when a speaker leaves, or more abruptly, closes its connection. This event is published after all remaining transcript events of this speaker have been published. Note that users connected in read-only mode (observers) don't emit this event.
example
const uhlive = new Uhlive("my-token");
const myConversation = uhlive.join("my-conversation");
myConversation.onSpeakerLeft((speaker) => {
// Do something with `speaker`...
});
Parameters:
Name | Type |
---|---|
callback | (payload: SpeakerLeft) => void |
Returns: Conversation
onTagsFound
▸ onTagsFound(callback
: (payload: TagsFound) => void): Conversation
The tags_found
event is triggered when a tag is found for the current conversation.
example
const uhlive = new Uhlive("my-token");
const myConversation = uhlive.join("my-conversation");
myConversation.onWordsDecoded((transcript) => {
// Do something with `transcript`...
});
Parameters:
Name | Type |
---|---|
callback | (payload: TagsFound) => void |
Returns: Conversation
onWordsDecoded
▸ onWordsDecoded(callback
: (transcript: WordsDecoded) => void): Conversation
The words_decoded
event is triggered when an interim transcript is received. Following words_decoded
events for the same audio are susceptible to be different, until a final transcript is sent with the segment_decoded
event.
example
const uhlive = new Uhlive("my-token");
const myConversation = uhlive.join("my-conversation");
myConversation.onWordsDecoded((transcript) => {
// Do something with `transcript`...
});
Parameters:
Name | Type |
---|---|
callback | (transcript: WordsDecoded) => void |
Returns: Conversation
Other Methods
getId
▸ getId(): string
Get the id of the conversation.
example
const conversation = new Conversation("1234", "Bob", socket, options);
conversation.getId(); // returns "1234"
Returns: string
publish
▸ publish(eventName
: string, ...args
: unknown[]): void
Publish an event for the current conversation.
example
const uhlive = new Uhlive("my-token");
const conversation = uhlive.join("my-conversation");
conversation.publish("my-event", {payload: "bob"});
Parameters:
Name | Type |
---|---|
eventName | string |
...args | unknown[] |
Returns: void
Recording Methods
isRecording
▸ isRecording(): boolean
Get the recording status of the conversation.
example
const uhlive = new Uhlive("my-token");
uhlive
.join("my-conversation")
.isRecording(); // true
example
const uhlive = new Uhlive("my-token");
uhlive
.join("my-conversation", {readonly: true})
.isRecording(); // false
Returns: boolean