6 releases

1.2.2 Apr 12, 2024
1.2.1 Apr 10, 2024
0.3.2-alpha Jul 24, 2024
0.3.0-alpha May 15, 2024
0.1.0 Jan 17, 2024

#649 in Network programming

28 downloads per month

Custom license

130KB
3K SLoC

Static Badge Static Badge Crates.io

safe-vk

Simple library with simple API for creating your own VK bot for conversations in Rust 🦀

Current State

This library doesn’t include all VK API methods yet, but it has enough functionality to wrap around the ComfyUI API or even the oobabooga API. See more in the examples.

Future planning

  • Improving asynchronous code
  • Support more VK API methods
  • More tests
  • Documenting code
  • Simplifying code
  • Making a route for keyboards

Prerequisites

Ensure you have Rust stable version 1.79.0 or nightly version 1.82.0 installed. This library is tested and compatible with these versions.

Overview

  • Works with newest API version 5.199
  • Utilizes routes same as in popular web frameworks
  • has serde_json, tokio and reqwest under the hood

Installation

$ cargo add safe-vk
$ cargo update

Greeting

use safe_vk::{extract::Ctx, responses::Message, Filter, Result, SafeVk};
use std::env;

async fn reply(update: Ctx<Message>) -> Result<()> {
    update.messages().send().random_id(0).message("hi").await?;
    Ok(())
}

#[tokio::main]
async fn main() {
    let token = env::var("TOKEN").expect("TOKEN environment variable not set");

    let bot = SafeVk::new().command("/hello", reply, Filter::Strict);

    safe_vk::start_polling(&token, bot).await.unwrap();
}

More Examples

For more, try to play with examples. To run an example, use the following command in your terminal:

$ TOKEN=YOUR_TOKEN cargo run --example reply
$ TOKEN=YOUR_TOKEN cargo run --example comfyui
$ TOKEN=YOUR_TOKEN cargo run --example oobabooga
$ TOKEN=YOUR_TOKEN cargo run --example macros
$ TOKEN=YOUR_TOKEN cargo run --example keyboard
$ TOKEN=YOUR_TOKEN cargo run --example members
$ TOKEN=YOUR_TOKEN cargo run --example state

Don't forget to include your token !

Motivation

My primary goal with this project is to learn how to work with asynchronous code and understand Rust's strong, safe type system. This project is heavily inspired by the axum crate. Feel free to contribute and propose new ideas! Updates will be made as I have motivation and free time.

License

safe-vk is available under the MIT license. See the MIT License file for more details

Dependencies

~8–20MB
~307K SLoC