Mascotbot React Native SDK Documentation
Learn how to install and use the Mascotbot SDK with React Native.
Introduction
The MascotBOT SDK provides a set of tools and components to integrate interactive mascots into your React Native applications. This documentation will guide you through the installation process and explain the main mechanisms and hooks available in the SDK.
Installation
To install the MascotBOT SDK, you need to add the package to your project. You can do this using the following command:
You’ll get the latest version of our SDK with integration examples once you subscribe to one of our plans
Ensure that you have the required peer dependencies installed:
Setup
1. Import and Wrap with MascotProvider
To use the SDK, wrap your application with the MascotProvider
component.
2. Create a Rive Instance
To use animated mascots, you’ll need to integrate with a Rive component: For reference see the official Rive documentation to loading files here
Hooks
useMascot
The useMascot
hook provides access to the Rive instance and Rive component.
useMascotPlayback
The useMascotPlayback
hook allows you to control the playback of animations and manage visemes.
Handling Visemes and Audio Playback
To create a synchronized animation and audio experience, you can use the playback.add
method to add visemes. This can be done in various ways, such as fetching from a server, generating in real-time, or any other method suitable for your application.
Adding Visemes
Visemes are visual representations of phonemes. You can add them to the playback to synchronize with the audio.
Controlling Speaking State
By default, the mascot’s is_speaking
state is automatically set to true
while it’s speaking and set to false
when it stops. You can control this behavior by passing options to the useMascotPlayback
hook:
The setSpeakingState
option allows you to disable the automatic management of the is_speaking
state, giving you manual control over when and how the speaking state is set.
API Reference
Components
<MascotProvider>
Root provider for the Mascot library.
<MascotClient>
Provides Rive integration capabilities.
Props:
RiveComponent
: Required. The Rive component implementation to usechildren
: React nodes
<MascotRive>
Displays the animated mascot.
Props:
onPress
: Function called when the mascot is clicked- Additional props are passed to the underlying Rive component
Hooks
useMascot()
Provides access to the mascot context.
useMascotSpeech(options)
Handles speech synthesis and animation.
Options:
apiKey
: Required. Your API key for the Mascot servicebufferSize
: Optional. Buffer size for speech (default: 2)enableTimingEvents
: Optional. Enable timing logs (default: true)apiEndpoint
: Optional. Custom API endpoint
Returns:
speak(text, voice?)
: Function to make the mascot speakstopSpeaking()
: Function to stop speechseekToPosition(position)
: Function to seek to a position in millisecondsisSpeaking
: Boolean indicating if the mascot is currently speakingisLoading
: Boolean indicating if speech is loadingerror
: Error message or nullprogress
: Current playback position in milliseconds
useMascotPlayback(options)
Provides low-level control over mascot animations.
Options:
setSpeakingState
: Optional. Whether to update the speaking state (default: true)
Returns:
add(chunks)
: Function to add viseme chunksstress(stresses)
: Function to add stress chunksplay()
: Function to start playbackseek(time)
: Function to seek to a positionpause()
: Function to pause playbackreset()
: Function to reset playback
Constants
MascotVoices
Object containing all available voice options.