Overview
ThesendUserMessage() method sends text messages on behalf of the user programmatically. Use it when you want the persona to treat the text as a user turn and respond.
Use addContext() when you want to add application state or user-action context without triggering an immediate persona response.
sendUserMessage() requires SDK version 3.3.0 or higherBasic Usage
Send a message as if the user typed or spoke it:Important Considerations
ThesendUserMessage() method differs from regular user messages in that:
- It does not trigger message events that would normally update your UI
- The message is sent directly to the persona without going through the normal message pipeline
- You need to handle transcript updates separately in your application
Use Cases
Simulating User Input
Providing Context to the LLM
UseaddContext() to provide contextual information that the LLM can use on the next user turn:
addContext() requires SDK version 4.11.0 or higher and an active streaming
session. It throws an error if the client is not streaming or there is no
active session.Triggering Specific Flows
Custom Client-Side Transcription
UsesendUserMessage() to implement your own client-side speech-to-text transcription. Capture and transcribe audio using your preferred service, then send the transcribed messages directly:
With this approach you can use specialized transcription models, handle multiple
languages, or implement custom preprocessing of the audio before sending it to the persona.
Complete Example
Here’s a complete example showing how to usesendUserMessage() with proper transcript management:
Error Handling
ThesendUserMessage() method throws errors in two scenarios:
Next Steps
Events
Learn how to handle message events and build interactive experiences
Interrupt Command
Stop the persona from speaking mid-response

