Skip to main content

What is the Router SDK?

The Router SDK lets you deploy BoostGPT bots across multiple messaging platforms with a single codebase. It uses the Core SDK internally and provides platform adapters.

Installation

npm install @boostgpt/router

Quick Start

import { Router, DiscordAdapter } from '@boostgpt/router';

const router = new Router({
  apiKey: process.env.BOOSTGPT_API_KEY,
  projectId: process.env.BOOSTGPT_PROJECT_ID,
  defaultBotId: process.env.BOOSTGPT_BOT_ID,
  adapters: [
    new DiscordAdapter({
      discordToken: process.env.DISCORD_TOKEN
    })
  ]
});

router.onMessage(async (message, context) => {
  // Handle commands
  if (message.content === '/help') {
    return 'I can help you! Just ask me anything.';
  }

  // Let AI handle everything else
  return null;
});

await router.start();
console.log('Bot is running!');

Supported Platforms

How It Works

  1. Router receives message from any platform
  2. Your handler runs - Return string for custom response or null for AI
  3. Router uses AI - If you return null, router calls BoostGPT
  4. Response sent back to the platform

Key Features

  • Multi-platform - One codebase for all platforms
  • Command handling - Intercept specific commands
  • Uses Core SDK - All bot features available
  • Type-safe - Full TypeScript support

Message Handler

router.onMessage(async (message, context) => {
  // message.content - User's message
  // message.userId - User ID
  // message.platform - Platform name (discord, telegram, etc.)
  // context.boostgpt - Core SDK instance

  if (message.content === '/ping') {
    return 'Pong!';
  }

  // Return null to let AI handle
  return null;
});

Multi-Platform Example

Deploy to Discord and Telegram simultaneously:
import { Router, DiscordAdapter, TelegramAdapter } from '@boostgpt/router';

const router = new Router({
  apiKey: process.env.BOOSTGPT_API_KEY,
  projectId: process.env.BOOSTGPT_PROJECT_ID,
  defaultBotId: process.env.BOOSTGPT_BOT_ID,
  adapters: [
    new DiscordAdapter({
      discordToken: process.env.DISCORD_TOKEN
    }),
    new TelegramAdapter({
      telegramToken: process.env.TELEGRAM_TOKEN
    })
  ]
});

router.onMessage(async (message, context) => {
  if (message.content === '/start') {
    return 'Welcome! How can I help you?';
  }
  return null;
});

await router.start();

Access Core SDK

Access the Core SDK directly when needed:
router.onMessage(async (message, context) => {
  if (message.content === '/stats') {
    // Use Core SDK
    const bots = await context.boostgpt.listBots();
    return `You have ${bots.response.length} bots`;
  }

  return null;
});

Next Steps