sendClientResponseText for exactly that: send the full utterance as text, let the server close the user turn, and have the agent reply immediately.
This guide shows how to wire text messages in both Vanilla JS and React. If you’re working directly with the WebSocket API (for example, outside a Node environment), check the Send Text Messages (optional) reference for payload details.
Need to push structured data (form values, button clicks) without ending the turn? See Send JSON data from the client.
1) Vanilla JS example
TheLayercodeClient instance exposes sendClientResponseText. Add a simple form that forwards the entered text and clears the field when submitted.
send-text.html
sendClientResponseText:
- The client sends a
client.response.textmessage (notrigger.turn.endis sent from the SDK). - The server interrupts any active agent audio, emits a
user.transcriptevent, closes the current user turn, and queues the agent response. - The agent receives the text message through the regular webhook path and responds immediately.
2) React example
The React SDK exposes the same capability via theuseLayercodeAgent hook. Grab the sendClientResponseText method from the hook and call it from your form handler.
app/components/TextReplyForm.tsx