> For the complete documentation index, see [llms.txt](https://vector-privacy.gitbook.io/vector-privacy/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vector-privacy.gitbook.io/vector-privacy/vector-sdk/basics/examples.md).

# Examples

Vector SDK Examples & Application

Runnable, self-contained example bots are bundled directly in the SDK crate under `examples/`, each one demonstrating a single concept. Unlike the old standalone example repository, these live alongside the SDK itself, so they are always kept in sync with the current API.

Every example requires a `VECTOR_NSEC` environment variable (the bot's key). A few require additional environment variables noted below.

## Projects Overview

### echo\_bot

The minimal hello-world example. Replies to every message it receives.

* Responds to direct messages and community messages alike
* Demonstrates the basic `on_message` handler

### slash\_command\_bot

A `/command` router demonstrating structured command handling.

* Supports `/ping`, `/echo`, `/roll`, and `/help`
* Demonstrates parsing message text into discrete commands

### ai\_bot

An LLM-backed chatbot wired to any OpenAI-compatible API endpoint.

* Shows a typing indicator while generating a response
* Maintains threaded replies and per-chat conversation history
* Requires an `OPENAI_API_KEY` environment variable

### moderation\_bot

A community moderation bot demonstrating membership events and auto-moderation.

* Welcomes new members when they join a community
* Auto-bans members based on a configurable word filter
* Demonstrates `BotEvent::MemberJoin` and the `Member` moderation API

### whitelist\_bot

A private bot that only joins communities run by trusted accounts.

* Demonstrates the `.whitelist([...])` invite policy
* Rejects invites from any account not explicitly trusted

### file\_bot

A minimal example for sending files.

* Sends a single file, then exits
* Demonstrates `Channel::send_file`

### save\_files\_bot

A minimal example for receiving files.

* Saves every file it receives to disk
* Demonstrates `VectorBot::download_attachment` / `save_attachment`

## Usage

Each example can be run directly from the SDK crate. From the root of the repository:

```bash
VECTOR_NSEC=nsec1... cargo run -p vector-sdk --example echo_bot
```

For examples that require additional environment variables, such as `ai_bot`:

```bash
OPENAI_API_KEY=sk-... VECTOR_NSEC=nsec1... cargo run -p vector-sdk --example ai_bot
```

For a release build:

```bash
VECTOR_NSEC=nsec1... cargo run -p vector-sdk --example echo_bot --release
```

## Contributing

Contributions are welcome. Please feel free to submit pull requests or open issues for any feature requests or bug reports.

## License

This project is licensed under the MIT License. See the [LICENSE](https://github.com/VectorPrivacy/Vector-SDK/blob/mls-groups/LICENSE) file for details.
