Getting started
Learn how to integrate Odea AI avatars into your website with a few lines of code. Odea allows you to easily embed an AI avatar in your web app and interact with it through configurable options, handling events, and sending messages.
Quick Start Example
Here's a quick example of how to embed an Odea AI avatar directly into your HTML file:
<!-- index.html -->
<script type="module" defer src="https://odea.io/scripts/odea-embed.js"></script>
<script type="module">
Odea.embed({ avatarId: "program:PETEEMBEDDEMO" });
</script>
This will embed the AI avatar using the avatarId
provided, and start it automatically once it's ready.
Embed Options
For a detailed list of options, see the embed() method.
Example Usage
Here's how you can use the OdeaEmbedAPI
to embed an avatar in your project.
Basic Example
window.Odea.embed({
avatarId: "program:PETEEMBEDDEMO",
onError(error) {
console.error("An error occurred:", error);
},
onUserSpeech(speech) {
console.log("User said:", speech);
}
});
In this example:
- We embed an avatar with the ID
program:PETEEMBEDDEMO
. - We set up a callback to handle errors, and log user speeches.
- The avatar interaction will begin automatically when it's ready.
Note: To control the start manually, use onReady
and start()
(see the "Starting the Chat Manually" section below).
Getting an Avatar ID
You can get an avatarId
from Odea's platform. Users can create their own custom avatar or choose an existing one from Odea's collection or from avatars created by other users. To create or select an avatar:
- Visit the Odea website and log in.
- Navigate to the Avatars section.
- Choose an avatar from the available collection or create your own personalized avatar.
- Once selected or created, you will receive an
avatarId
that you can use to embed the avatar into your web project.
Each avatar has a unique avatarId
, which you will use in the embed()
method, as shown in the examples above.
Embed an Avatar in a Custom Container
If you want to embed the avatar in a specific container element rather than appending it to the body, you can provide a container
parameter.
const containerElement = document.getElementById("avatar-container");
window.Odea.embed({
avatarId: "program:PETEEMBEDDEMO",
container: containerElement, // Inject embed into a specific DOM element
embedClasses: "custom-class"
});
In this example, the avatar is embedded inside a specific container with a custom CSS class.
Starting a Chat Manually
By default, the chat interaction starts automatically once the avatar is ready. If you want full control over when the interaction begins, you can disable automatic start and use onReady
with the start()
method.
window.Odea.embed({
avatarId: "program:PETEEMBEDDEMO",
options: {
autoStart: false, // Disable automatic start
},
onReady() {
console.log("Avatar is ready. Starting interaction...");
window.Odea.start(); // Start manually when ready
},
});
⚠️ Important!
You should call this method only after the onReady()
callback is triggered. If called before the avatar is ready, it will have no effect.
API Reference
The OdeaEmbedAPI
allows you to embed an Odea avatar and interact with it via configuration options, events, and specialized callbacks.
Methods
embed(options: { ... }): void
Embeds an Odea avatar into the DOM and sets up event handlers.
Options Parameter | Type | Default | Description |
---|---|---|---|
avatarId | string | Required. The ID of the avatar to be displayed. | |
embedClasses | string | "" | CSS classes to be added to the embed element. |
container | HTMLElement | The DOM element where the embed should be injected. If not provided, it will append to body . | |
options | object | Configuration options for embed controls and behavior. | |
├ autoStart | boolean | true | If true , starts the avatar interaction automatically when it is ready. |
├ devMode | boolean | false | If true , an error overlay will be shown to help debug errors with your embed avatar. |
├ showSubtitles | boolean | false | If true , shows subtitles for avatar and user speeches without toggle. |
├ timeoutMs | number | Duration of inactivity in milliseconds before triggering onEnded . | |
├ spinner | object | Customization for the loading spinner appearance. | |
└ colorHex | string | #FF7300 | Hex color code to set the spinner color. |
├ startButton | boolean | object | false | Controls start button visibility and customization. If false , the button won't be shown. |
├ text | string | Start Chat | Custom text for the start button. |
├ backgroundColorHex | string | #FF7300 | Hex color code for the button's background color. |
└ textColorHex | string | #FFFFFF | Hex color code for the button's text color. |
├ showSubtitles | boolean | false | If true , shows subtitles for avatar and user speeches without toggle. |
└ controls | boolean | object | false | If true , enables all controls. If an object, selectively enables specific controls in the embed. |
├ subtitles | boolean | false | Enables subtitles with toggle control for avatar and user speeches. |
├ share | boolean | false | Displays a share button for sharing the avatar's link. |
└ microphonePicker | boolean | false | Enables a microphone picker for input device selection. |
onEnded | function() | Callback function triggered when the user has not interacted for a specified timeoutMs . | |
onError | function(error: string) | Callback function to handle errors from the embed (e.g., network issues or rendering errors). | |
onReady | function() | Callback function triggered when the avatar is ready to interact with. | |
onStarted | function() | Callback function triggered when the avatar interaction has started. | |
onUserSpeech | function(speech: string) | Callback function triggered when the avatar receives a user speech. |
start(): void
If you have disabled automatic start by setting autoStart
to false
, you should call this method to start the interaction with the AI avatar. You should call this method only after the onReady()
callback is triggered. Otherwise, it will have no effect.
Events
The Odea embed emits events that you can listen to via callbacks provided in the embed
function. Here's an overview of the available events and callbacks:
Event | Description | Callback |
---|---|---|
AVATAR_READY | Fired when the avatar is fully loaded and ready for interaction. | onReady() |
CHAT_STARTED | Fired when the avatar interaction has started. | onStarted() |
CHAT_ENDED | Fired when the user is inactive for timeoutMs . | onEnded() |
ERROR | Fired when an error occurs, such as a network issue or rendering error. The error message is passed as an argument. | onError(error: string) |
USER_SPEECH | Fired when the user say something. The speech is passed as an argument. | onUserSpeech(speech: string) |
Handling Events
onReady
Triggered when the avatar is fully loaded and ready for interaction.
window.Odea.embed({
avatarId: "program:PETEEMBEDDEMO",
onReady() {
console.log("Avatar is ready.");
}
});
onError
Called when an error occurs within the embed.
window.Odea.embed({
avatarId: "program:PETEEMBEDDEMO",
onError(error) {
console.error("An error occurred:", error);
}
});
onStarted
Called when the avatar interaction has started.
window.Odea.embed({
avatarId: "program:PETEEMBEDDEMO",
onStarted() {
console.log("Started");
},
});
onEnded
Called when the user has not interacted with the avatar within the specified timeoutMs. This resets the chat to its initial state. If startButton
is set, the user may click on it to start again. Otherwise, call Odea.start()
to start again.
window.Odea.embed({
avatarId: "program:PETEEMBEDDEMO",
options: {
timeoutMs: 60000 // Trigger onEnded after 60 seconds
},
onEnded() {
console.log("User inactive. Resetting interaction.");
},
});
onUserSpeech
Triggered when the user say something.
window.Odea.embed({
avatarId: "program:PETEEMBEDDEMO",
onUserSpeech(speech) {
console.log("User speech:", speech);
}
});