> 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/quickstart.md).

# Quickstart

## Installation

To use the Vector Bot Library, add it as a dependency in your `Cargo.toml`:

```rust
[dependencies]
vector_library = { path = "path/to/vector_library" }
```

## Usage

### Sending a Text Message

```rust
use vector_library::VectorBot;
use nostr_sdk::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // Generate new random keys
    let keys = Keys::generate();

    // Create a new VectorBot with default metadata
    let bot = VectorBot::quick(keys).await;

    // Get a chat channel for a specific public key
    let chat_npub = PublicKey::from_bech32("npub1example...")?;
    let chat = bot.get_chat(chat_npub).await;

    // Send a private message
    let success = chat.send_private_message("Hello, world!").await;
    println!("Message sent: {}", success);

    Ok(())
}
```

### Sending an Image

```rust
use vector_library::{VectorBot, AttachmentFile};
use nostr_sdk::prelude::*;
use std::fs;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // Generate new random keys
    let keys = Keys::generate();

    // Create a new VectorBot with default metadata
    let bot = VectorBot::quick(keys).await;

    // Get a chat channel for a specific public key
    let chat_npub = PublicKey::from_bech32("npub1example...")?;
    let chat = bot.get_chat(chat_npub).await;

    // Read image file
    let image_path = "path/to/your/image.png";
    let image_data = fs::read(image_path)?;

    // Create an AttachmentFile
    let attachment = AttachmentFile {
        bytes: image_data,
        img_meta: None, // Optional: Add image metadata if available
        extension: "png".to_string(),
    };

    // Send the image
    let success = chat.send_private_file(Some(attachment)).await;
    println!("Image sent: {}", success);

    Ok(())
}
```

Alternatively, you can use the inherent constructor:

```rust
let attachment = AttachmentFile::from_path("path/to/your/image.png")?;
```

#### Creating an Attachment from in-memory bytes

If you already loaded bytes in memory (e.g., `fs::read`), construct the attachment in a single line. The extension is inferred via magic-number sniffing and falls back to "bin" when unknown.

```rust
use vector_sdk::AttachmentFile;
use std::fs;

let bytes = fs::read("path/to/your/image.png")?;
let attachment = AttachmentFile::from_bytes(bytes);
```

### Typing indicators

Typing indicators provide real-time feedback to recipients that a bot is composing a message. This is useful when a bot needs to retrieve information or is "thinking" before responding.

```rust
use vector_sdk::VectorBot;
use nostr_sdk::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Generate new random keys
    let keys = Keys::generate();

    // Create a new VectorBot with default metadata
    let bot = VectorBot::quick(keys).await;

    // Get a chat channel for a specific public key
    let chat_npub = PublicKey::from_bech32("npub1example...")?;
    let chat = bot.get_chat(chat_npub).await;

    // Send typing indicator (shows "recipient is typing...")
    chat.send_typing_indicator().await;

    // Simulate work (e.g., fetching data, processing)
    tokio::time::sleep(std::time::Duration::from_secs(2)).await;

    // Send the actual message
    let success = chat.send_private_message("Here's my response!").await;
    println!("Message sent: {}", success);

    Ok(())
}
```

For more information about typing indicators and their implementation, see [ADVANCED.md](https://github.com/VectorPrivacy/Vector-SDK/blob/mls-groups/ADVANCED.md#typing-indicators).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://vector-privacy.gitbook.io/vector-privacy/vector-sdk/basics/quickstart.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
