FreppeBot Documentation

Everything you need to know about setting up, configuring, and extending FreppeBot.

Introduction

FreppeBot is a self-hosted AI assistant framework. Unlike hosted solutions, you control everything: the AI model, the data, and the functionality.

Key features:

Installation

Requirements: Node.js 18+ and npm.

git clone https://github.com/freppebot/freppebot.git
cd freppebot
npm install

Run the interactive setup wizard:

npm run setup

This creates config.json with your AI provider keys, platform tokens, and bot personality.

Start the bot:

npm start

Configuration

All settings are stored in config.json. The setup wizard generates this file, but you can edit it manually.

Bot Settings

Field Description Default
bot.name The bot's display name FreppeBot
bot.commandPrefix Prefix for commands !
bot.logLevel Logging level: error, warn, info, debug info
bot.systemPrompt Instructions for AI personality and behavior Default prompt
bot.personality Personality settings (style, tone, useEmojis) See example

Platform Settings

Field Description
platforms.discord.enabled Enable Discord adapter
platforms.discord.token Discord bot token from Developer Portal
platforms.discord.allowedUsers Array of user IDs (empty = allow all)
platforms.discord.adminUsers Array of admin user IDs
platforms.telegram.* Same structure for Telegram

Plugin Settings

Field Description
plugins.hotReload Auto-reload plugins when files change (default: true)
plugins.disabled Array of plugin names to disable

AI Settings

Field Description
ai.defaultProvider Which provider to use: openrouter, openai, anthropic, kimi
ai.defaultModel Model identifier (e.g., anthropic/claude-sonnet-4.5 or openai/gpt-5.2)
ai.openrouterKey Your OpenRouter API key

How It Works

FreppeBot has a modular architecture with four main components:

1. Core Engine

The FreppeBot class in src/core/bot.js orchestrates everything. It initializes the database, AI manager, plugin loader, and platform adapters.

2. Message Router

When a message arrives, the router (src/core/router.js) decides how to handle it:

3. AI Manager

The AI manager (src/ai/manager.js) abstracts different AI providers. It handles message formatting, tool call parsing, and provider-specific quirks.

4. Plugin System

Plugins provide commands (user-invoked) and tools (AI-invoked). The loader scans plugins/ folders and registers everything automatically.

5. Utilities

Additional utilities provide essential functionality:

AI Providers

FreppeBot supports multiple AI backends:

Provider Models Notes
OpenRouter 100+ models Recommended. Single API key for Claude, GPT-5, Llama, etc.
OpenAI GPT-5.2, GPT-5.2 Pro Direct connection to OpenAI API
Anthropic Claude Sonnet 4.5, Opus 4.5 Direct connection to Anthropic API
Kimi Kimi k2.5, v1/v2 Moonshot AI's models

Set your preferred provider in config.json under ai.defaultProvider.

Platform Adapters

Adapters connect FreppeBot to messaging platforms.

Discord

Uses Discord.js. Requires a bot token from the Discord Developer Portal.

Telegram

Uses node-telegram-bot-api. Get a token from BotFather.

Both adapters normalize messages into a common format before passing them to the router.

Plugin System

Plugins are the primary way to extend FreppeBot. Each plugin can provide:

Plugins live in two folders:

Core Plugins & Commands

These plugins are always loaded and provide essential functionality:

Built-in Commands

Command Description Admin Only?
!help Show available commands and help information
!plugins List all loaded plugins with their commands and tools
!health / !status Show bot health status, statistics, and system information
!backup Create a manual database backup
!backup list List all available backups
!backup delete <file> Delete a specific backup file

Built-in Core Plugins

These plugins are part of FreppeBot core and are always loaded. They cannot be disabled.

Plugin Commands AI Tools Description
memory !remember, !recall remember, recall Stores and recalls information across conversations
reminder !remind, !reminders setReminder, listReminders Sets timed reminders that notify users
system !status, !sysinfo getSystemInfo Bot and system information
files !ls, !cat readFile, writeFile, listDirectory File operations (admin only)
shell !shell executeCommand Execute shell commands (admin only)
os !run, !read, !write readFile, writeFile, runCommand OS-level operations (admin only)
web !fetch fetchUrl, webSearch Fetches and reads web pages

Community Plugins

These plugins are included with FreppeBot but are optional. They can be disabled via plugins.disabled in config.json. Located in plugins/community/.

Plugin Commands AI Tools API Key
🌤️ weather !weather <location> getWeather ❌ Free
💰 crypto !price <symbol>, !trending getCryptoPrice, getTrending ❌ Free
🎵 spotify !song <query>, !artist <name> searchMusic ✅ Spotify API
📅 calendar !event, !agenda addEvent, getEvents ❌ Local
🔗 urlshortener !shorten <url> shortenUrl ❌ Free
📧 email !email to@x.com Subject | Body sendEmail ✅ SMTP
🐦 twitter !tweet, !trends postTweet, getTrends ✅ Twitter API
🎨 imagegen !imagine <prompt> generateImage ✅ OpenAI API
📝 notes !note, !notes saveNote, getNotes ❌ Local
🔐 password !password [length] generatePassword ❌ Local
📱 qrcode !qr <text> generateQRCode ❌ Free API
🌐 translate !translate <text> to <lang> translateText ❌ Free API
🔍 brave !search <query> webSearch ✅ Brave API
🐙 github !github <query>, !github-init, !github-commit, !github-push searchGitHub, createFolder, createFile, initializeGitRepository, gitCommit, gitPush, createGitHubRepository ✅ GitHub Token (for repo creation)
📰 news !news [topic] getNews ✅ NewsAPI
🎬 reddit !reddit <subreddit> searchReddit ❌ Free
📈 stocks !stock <symbol> getStockPrice ❌ Free (Yahoo Finance)

Note: Community plugins can be disabled by adding their name to plugins.disabled array in config.json.

Create a Plugin

Create a new file in plugins/community/:

// plugins/community/hello.js
const { Plugin } = require('../../src/plugins/sdk');

module.exports = new Plugin({
    name: 'hello',
    description: 'A simple greeting plugin',
    version: '1.0.0',

    // Commands are triggered by users
    commands: {
        greet: {
            description: 'Greet someone',
            handler: async (ctx, args) => {
                const name = args[0] || 'friend';
                return `Hello, ${name}!`;
            },
        },
    },

    // Tools are called by the AI
    tools: {
        sayHello: {
            description: 'Greet a person by name',
            parameters: {
                name: { 
                    type: 'string', 
                    description: 'Name to greet' 
                },
            },
            execute: async (params, ctx) => {
                return { 
                    message: `Hello, ${params.name}!` 
                };
            },
        },
    },
});

After saving, the plugin auto-loads (if hot reload is enabled) or loads on next restart.

Tip: The ctx object gives you access to the message, user info, bot instance, and memory store.

Plugin Manager

FreppeBot includes a plugin manager (similar to npm) for downloading and managing plugins from URLs.

Installation

Use the plugin manager via npm scripts:

npm run plugin <command>

Or install globally to use the freppe command:

npm install -g .
freppe <command>

Download Plugins

Download and install plugins from URLs:

# From raw GitHub file
npm run plugin download https://raw.githubusercontent.com/user/repo/main/plugin.js

# From GitHub blob URL (auto-converted)
npm run plugin download https://github.com/user/repo/blob/main/plugin.js

# Force overwrite existing plugin
npm run plugin download <url> --force

The plugin manager automatically:

List Plugins

View all installed plugins:

npm run plugin list

Shows plugin name, version, description, installation date, and source URL.

Remove Plugins

Uninstall a plugin:

npm run plugin remove <plugin-name>

This removes the plugin file and updates the metadata.

Update Plugins

Update a plugin to the latest version from its original URL:

npm run plugin update <plugin-name>

The plugin manager remembers the original URL and re-downloads from it.

Plugin Validation

Before installation, plugins are validated to ensure:

Metadata Storage

Plugin metadata is stored in plugins/community/.freppe-plugins.json:

This metadata enables features like automatic updates and source tracking.

Security Features

FreppeBot includes multiple layers of security to protect your bot and prevent abuse:

Rate Limiting

Prevents API abuse and cost spikes by limiting requests per user:

Rate limits are tracked per user and reset automatically after the time window expires.

Command Cooldowns

Prevents command spam and accidental duplicate executions:

Input Validation

All user input is validated and sanitized before processing:

Access Control

Fine-grained access control for commands and features:

Error Handling

Secure error handling that protects system information:

Health Monitoring

FreppeBot includes comprehensive health monitoring to track bot performance and system status.

Health Command

Use !health or !status to view a detailed health report:

!health

The health report includes:

Tracked Metrics

The health monitor automatically tracks:

Metric Description
Messages Processed Total number of messages handled
Commands Executed Total number of commands run
Errors Number of errors encountered
Last Error Most recent error message and timestamp
System Resources CPU cores, memory usage, platform info

Use Cases

Database Backups

FreppeBot automatically creates backups of your database to prevent data loss.

Automatic Backups

The bot creates backups automatically:

Backups are created silently in the background and don't impact bot performance.

Manual Backups

Create a backup on demand using the backup command:

!backup

This creates an immediate backup and shows you the filename and size.

Backup Management

List all available backups:

!backup list

This shows all backups with their sizes and creation dates.

Delete a specific backup (admin only):

!backup delete freppebot-backup-2024-01-01T12-00-00.db

Restoring Backups

To restore from a backup:

  1. Stop the bot
  2. Copy the backup file to data/freppebot.db
  3. Restart the bot

Note: The bot automatically creates a backup of the current database before restoring, so you can always revert if needed.

Backup Best Practices

Docker Deployment

FreppeBot includes a Dockerfile and docker-compose.yml for easy deployment.

Quick Start

# Build and run
docker compose up -d

# View logs
docker compose logs -f

# Stop the bot
docker compose down

Volume Mounts

Make sure to mount your configuration and data directories:

volumes:
  - ./config.json:/app/config.json
  - ./data:/app/data

This ensures your configuration and database persist across container restarts.

Environment Variables

You can also use environment variables for configuration (see docker-compose.yml for details).

Production Deployment

For production deployments, consider:

Troubleshooting

Common issues and their solutions:

Bot Not Responding

If the bot isn't responding to messages:

  1. Check health status: Run !health to see adapter connection status
  2. Check logs: Review data/freppebot.log for errors
  3. Verify API keys: Ensure your AI provider API key is valid in config.json
  4. Check permissions:
    • Discord: Ensure bot has "Send Messages" and "Read Message History" permissions
    • Telegram: Ensure bot is started and token is correct
  5. User whitelist: If allowedUsers is set, ensure your user ID is included

Rate Limit Errors

If you see rate limit messages:

Command Cooldown Messages

If commands are on cooldown:

Database Issues

If you encounter database errors:

  1. Check file exists: Ensure data/freppebot.db exists
  2. Check permissions: Bot needs read/write access to data/ directory
  3. Check disk space: Ensure sufficient disk space for database operations
  4. Restore from backup: Use a backup if database is corrupted
  5. View database stats: Use !health to see database size and stats

Plugin Not Loading

If a plugin isn't working:

  1. Check file location: Plugin must be in plugins/core/ or plugins/community/
  2. Check syntax: Ensure JavaScript syntax is valid
  3. Check disabled list: Verify plugin isn't in plugins.disabled array
  4. Check logs: Look for plugin loading errors in data/freppebot.log
  5. Hot reload: If hot reload is enabled, changes should apply automatically
  6. Restart bot: Sometimes a full restart is needed

AI Provider Errors

If AI responses fail:

Memory/Reminder Issues

If memories or reminders aren't working:

Getting Help

If you're still having issues: