Skip to main content

Router Class

Constructor

string
required
BoostGPT API key
string
required
BoostGPT project ID
Array<BaseAdapter>
default:"[]"
Array of channel adapter instances
string
Default bot ID for all adapters (can be overridden per adapter)
Function
Global error handler function
boolean
default:"true"
Enable console logging
Example:

Methods

onMessage()

Set a custom message handler for all channels.
Parameters:
Object
Normalized message object:
Object
Context object:
Returns:
  • string - Send this as the response
  • null / undefined - Let BoostGPT handle it automatically
Example:

onError()

Set a custom error handler for all channels.
Parameters:
Error
The error that occurred
Object
The message that caused the error
Object
Context object with channel information
Returns:
  • string - Error message to send to user
Example:

start()

Start all adapters and begin listening for messages.
Returns: Promise<void> Example:

stop()

Stop all adapters and disconnect from channels.
Returns: Promise<void> Example:

getAdapter()

Get a specific adapter by channel name.
Parameters:
string
required
Channel name (‘discord’, ‘telegram’, etc.)
Returns: BaseAdapter | null Example:

sendMessage()

Send a message to a specific user on a specific channel.
Parameters:
string
required
Channel name (‘discord’, ‘telegram’, etc.)
string
required
User/channel ID (format varies by channel)
string
required
Message content to send
Returns: Promise<any> Example:

broadcast()

Broadcast a message to all or specific channels.
Parameters:
string
required
Message to broadcast
Array<string>
Optional array of channel names. If omitted, broadcasts to all channels.
Returns: Promise<Array<Object>> Returns an array of results indicating success/failure for each channel. Example:

getStatus()

Get the current status of the router and all adapters.
Returns:
Example:

addAdapter()

Add a new adapter at runtime.
Parameters:
BaseAdapter
required
Adapter instance to add
Returns: Promise<void> Example:

removeAdapter()

Remove an adapter by channel name.
Parameters:
string
required
Channel name to remove
Returns: Promise<void> Example:

BaseAdapter Class

All channel adapters extend BaseAdapter. Use this to create custom adapters.

Constructor

BoostGPT
required
BoostGPT client instance
string
required
Bot ID for this adapter
string
required
Channel identifier (e.g., ‘discord’, ‘custom’)
string
Override model for this channel
Array<string>
Limit knowledge to specific sources
Array<string>
Limit knowledge to specific tags
number
Override top setting for training data
number
Override max tokens for this channel
string
Use custom OpenAI/Anthropic key
string
Default error message
boolean
default:"true"
Enable logging for this adapter

Methods

setMessageHandler()

Set a custom message handler for this adapter.

start()

Start the adapter (must be implemented by child class).

stop()

Stop the adapter.

sendMessage()

Send a message (must be implemented by child class).

getStatus()

Get adapter status.

Type Definitions

Message Object

Context Object

Adapter Status


Next Steps

Custom Adapters

Build your own channel adapter

Channel Adapters

Configure specific channels

Deployment

Deploy to production

Examples

Real-world implementations