React Native SDK
Conversational AI SDK: deploy customized, interactive voice agents in minutes for React Native apps.
Refer to the Conversational AI overview for an explanation of how Conversational AI works.
Installation
Install the package and its dependencies in your React Native project.
An example app using this SDK with Expo can be found here
Requirements
- React Native with LiveKit dependencies
- Microphone permissions configured for your platform
- Expo compatibility (development builds only)
This SDK was designed and built for use with the Expo framework. Due to its dependency on LiveKit’s WebRTC implementation, it requires development builds and cannot be used with Expo Go.
Setup
Provider Setup
Wrap your app with the ElevenLabsProvider
to enable conversational AI functionality.
Usage
useConversation
A React Native hook for managing connection and audio usage for ElevenLabs Conversational AI.
Initialize conversation
First, initialize the Conversation instance within a component that’s wrapped by ElevenLabsProvider
.
Note that Conversational AI requires microphone access. Consider explaining and requesting permissions in your app’s UI before the Conversation starts, especially on mobile platforms where permission management is crucial.
Options
The Conversation can be initialized with certain options:
- onConnect - Handler called when the conversation WebRTC connection is established.
- onDisconnect - Handler called when the conversation WebRTC connection is ended.
- onMessage - Handler called when a new message is received. These can be tentative or final transcriptions of user voice, replies produced by LLM, or debug messages.
- onError - Handler called when an error is encountered.
- onModeChange - Handler called when the conversation mode changes. This is useful for indicating whether the agent is speaking or listening.
- onStatusChange - Handler called when the conversation status changes.
- onCanSendFeedbackChange - Handler called when the ability to send feedback changes.
- onUnhandledClientToolCall - Handler called when an unhandled client tool call is encountered.
Methods
startSession
The startSession
method kicks off the WebRTC connection and starts using the microphone to communicate with the ElevenLabs Conversational AI agent. The method accepts a configuration object with the agentId
being conditionally required based on whether the agent is public or private.
Public agents
For public agents (i.e. agents that don’t have authentication enabled), only the agentId
is required. The Agent ID can be acquired through the ElevenLabs UI.
Private agents
For private agents, you must pass in a conversationToken
obtained from the ElevenLabs API. Generating this token requires an ElevenLabs API key.
conversationToken
is valid for 10 minutes.Then, pass the token to the startSession
method. Note that only the conversationToken
is required for private agents.
You can optionally pass a user ID to identify the user in the conversation. This can be your own customer identifier. This will be included in the conversation initiation data sent to the server.
endSession
A method to manually end the conversation. The method will disconnect and end the conversation.
sendUserMessage
Send a text message to the agent during an active conversation.
sendContextualUpdate
Sends contextual information to the agent that won’t trigger a response.
sendFeedback
Provide feedback on the conversation quality. This helps improve the agent’s performance.
sendUserActivity
Notifies the agent about user activity to prevent interruptions. Useful for when the user is actively using the app and the agent should pause speaking, i.e. when the user is typing in a chat.
The agent will pause speaking for ~2 seconds after receiving this signal.
Properties
status
A React state containing the current status of the conversation.
isSpeaking
A React state containing information on whether the agent is currently speaking. This is useful for indicating agent status in your UI.
canSendFeedback
A React state indicating whether feedback can be submitted for the current conversation.
Example Implementation
Here’s a complete example of a React Native component using the ElevenLabs Conversational AI SDK:
Platform-Specific Considerations
iOS
Ensure microphone permissions are properly configured in your Info.plist
:
Android
Add microphone permissions to your android/app/src/main/AndroidManifest.xml
:
Consider requesting runtime permissions before starting a conversation: