API Reference
This section provides detailed documentation for the TDoge SDK API.
Overview
TDoge SDK provides a simple yet powerful API for integrating interactive talking avatars into your applications. The API is designed to be intuitive and easy to use while providing all the functionality you need.
Core Concepts
TDoge Instance
The main entry point for the SDK is the TDoge class. You create an instance of this class to start using the SDK:
import { TDoge } from 'tdoge-sdk';
const tdoge = new TDoge({
showOnlyAvatar: true,
host: "https://tapi.anispark.xyz/tdoge-core"
});
Interaction Modes
The SDK supports two main interaction modes:
- AI Chat Mode: For conversational interactions
- Direct TTS Mode: For simple voice commands
API Reference
Constructor Options
| Option | Type | Default | Description |
|---|---|---|---|
showOnlyAvatar | boolean | true | Show only the avatar without additional UI |
host | string | - | Required. The host URL for the TDoge service |
style | object | - | Custom styling options for the avatar container |
Example with style options:
const tdoge = new TDoge({
showOnlyAvatar: true,
host: "https://tapi.anispark.xyz/tdoge-core",
style: {
width: '400px',
height: '400px',
borderRadius: '20px',
backgroundColor: '#f0f0f0'
}
});
Core Methods
mount(element)
Mounts the TDoge instance to a DOM element.
element: String selector or DOM element
unmount()
Unmounts the TDoge instance.
ask(content)
Sends a text message to the avatar in AI Chat mode.
content: String message to send
say(content)
Direct execution of a command without generating a response (Direct TTS mode).
content: String command to execute
on(event, callback)
Listens for events from the TDoge instance.
event: String event namecallback: Function to call when the event is triggered
off(event, callback)
Removes an event listener from the TDoge instance.
event: String event namecallback: Function to remove
Events
The SDK emits various events that you can listen to:
// Listen for mount event
tdoge.on('mount', () => {
console.log('TDoge is mounted!');
});
// Listen for unmount event
tdoge.on('unmount', () => {
console.log('TDoge is unmounted!');
});
// Listen for say events
tdoge.on('say', (text) => {
console.log('Saying:', text);
});
// Listen for ask events
tdoge.on('ask', (text) => {
console.log('Asking:', text);
});
// Listen for error events
tdoge.on('error', (error) => {
console.error('Error:', error);
});
Type Definitions
The SDK is written in TypeScript and provides comprehensive type definitions:
interface TDogeOptions {
showOnlyAvatar?: boolean;
host: string;
}
interface TDoge {
mount(element: string | HTMLElement): Promise<void>;
unmount(): void;
ask(content: string, noGenerateResponse?: boolean): Promise<void>;
say(content: string): Promise<void>;
on(event: string, callback: Function): void;
off(event: string, callback: Function): void;
}
Best Practices
- Always check for browser compatibility before initializing the SDK
- Handle errors appropriately using try-catch blocks
- Clean up resources by calling
unmount()when the component is destroyed - Use the appropriate interaction mode for your use case
Error Handling
try {
const tdoge = new TDoge({
showOnlyAvatar: true,
host: "https://tapi.anispark.xyz/tdoge-core"
});
await tdoge.mount("#app");
} catch (error) {
console.error('Failed to initialize TDoge:', error);
}