Complete reference documentation for the SuperDapp Agents SDK.
import { SuperDappAgent, SuperDappClient, WebhookAgent } from '@superdapp/agents';import type { BotConfig, MessageData, CommandHandler, ApiResponse } from '@superdapp/agents';import { retry, sleep, formatBody, validateConfig } from '@superdapp/agents';The main class for creating and managing AI agents.
new SuperDappAgent(config: BotConfig)config: BotConfig- Agent configurationoptions?: WebhookOptions- Webhook server options
interface BotConfig {
apiToken: string;
baseUrl?: string;
}Register a command handler.
agent.addCommand('/start', async ({ roomId }) => {
await agent.sendConnectionMessage(roomId, 'Hello!');
});Process a webhook request.
app.post('/webhook', async (req, res) => {
await agent.processRequest(req.body);
res.status(200).send('OK');
});Send a message to a connection (DM).
await agent.sendConnectionMessage('room123', 'Hello from the agent!');Send a message to a channel.
await agent.sendChannelMessage('channel123', 'Channel announcement!');sendReplyMarkupMessage(type: 'buttons' | 'multiselect', roomId: string, text: string, actions: ReplyMarkupAction[][]): Promise<void>
Send a message with interactive markup.
const buttons = [
{ text: 'Option 1', callback_data: 'OPTION_1' },
{ text: 'Option 2', callback_data: 'OPTION_2' },
];
await agent.sendReplyMarkupMessage('buttons', 'room123', 'Choose an option:', [
buttons,
]);Get the underlying API client.
const client = agent.getClient();
const info = await client.getBotInfo();Get a list of all registered command names.
const commands = agent.getCommands();
console.log('Available commands:', commands);
// Output: ['/start', '/help', '/ping']The API client for direct SuperDapp API access.
new SuperDappClient(config: BotConfig)// Send connection message
await client.sendConnectionMessage(roomId: string, data: MessageData): Promise<ApiResponse>
// Send channel message
await client.sendChannelMessage(channelId: string, data: MessageData): Promise<ApiResponse>// Join channel
await client.joinChannel(channelId: string): Promise<ApiResponse>
// Leave channel
await client.leaveChannel(channelId: string): Promise<ApiResponse>Lightweight webhook-based agent for simple use cases.
new WebhookAgent();Register a command handler.
const webhookAgent = new WebhookAgent();
webhookAgent.addCommand('/ping', async (message) => {
// Handle ping command
});Register multiple commands at once.
webhookAgent.addCommands({
'/start': async (message) => {
/* handle start */
},
'/help': async (message) => {
/* handle help */
},
'/ping': async (message) => {
/* handle ping */
},
});Register a general message handler.
webhookAgent.onMessage(async (message) => {
// Handle all messages that don't match commands
});Process a webhook request.
app.post('/webhook', async (req, res) => {
await webhookAgent.processRequest(req.body);
res.status(200).send('OK');
});Retry a function with exponential backoff.
const result = await retry(async () => await fetchExternalAPI(), 3, 1000);Wait for a specified number of milliseconds.
await sleep(2000); // Wait 2 secondsFormat message body with markdown support.
const formatted = formatBody('**Bold text** and *italic*');| Variable | Type | Required | Default | Description |
|---|---|---|---|---|
API_TOKEN |
string | Yes | - | SuperDapp API token |
API_BASE_URL |
string | No | https://api.superdapp.ai |
API base URL |
NODE_ENV |
string | No | production |
Environment mode |
The SDK automatically configures SSL based on the NODE_ENV:
development: SSL verification disabledproduction: SSL verification enabled- Not set: SSL verification enabled (secure default)
- Quick Start Guide - Basic setup and usage
- CLI Guide - Command-line interface documentation
- Deployment Guide - Production deployment