Crates.io | vtg |
lib.rs | vtg |
version | 1.0.6 |
source | src |
created_at | 2024-04-06 18:47:46.305391 |
updated_at | 2024-09-04 15:18:37.309362 |
description | Library for creating VK and Telegram bots |
homepage | https://github.com/valnesfjord/vtg |
repository | https://github.com/valnesfjord/vtg |
max_upload_size | |
id | 1198486 |
size | 1,829,071 |
VTG is a fully functional library for creating bots for both VK and Telegram. Presents unified context and methods, for comfortable work with dual-platform bots.
Example using longpoll client:
use std::env;
use vtg::{
client::start_longpoll_client,
structs::{config::Config, context::UnifyedContext, middleware::MiddlewareChain},
};
async fn catch_new_message(ctx: UnifyedContext) -> UnifyedContext {
ctx
}
#[tokio::main]
async fn main() {
let config = Config {
vk_access_token: env::var("VK_ACCESS_TOKEN").unwrap(),
vk_group_id: env::var("VK_GROUP_ID").unwrap().parse().unwrap(),
tg_access_token: env::var("TG_ACCESS_TOKEN").unwrap(), // token starts with "bot", like: bot1234567890:ABCDEFGHIJKL
..Default::default()
};
let mut middleware_chain = MiddlewareChain::new();
middleware_chain.add_middleware(|ctx| Box::pin(catch_new_message(ctx)));
start_longpoll_client(middleware_chain, config).await;
}
Example using callback server:
use std::env;
use vtg::{
server::start_callback_server,
structs::{
config::{CallbackSettings, Config},
context::UnifyedContext,
middleware::MiddlewareChain,
},
};
async fn catch_new_message(ctx: UnifyedContext) -> UnifyedContext {
ctx
}
#[tokio::main]
async fn main() {
let config = Config {
vk_access_token: env::var("VK_ACCESS_TOKEN").unwrap(),
vk_group_id: env::var("VK_GROUP_ID").unwrap().parse().unwrap(),
tg_access_token: env::var("TG_ACCESS_TOKEN").unwrap(), // token starts with "bot", like: bot1234567890:ABCDEFGHIJKL
vk_api_version: "5.199".to_owned(),
callback: Some(CallbackSettings {
port: 1234,
callback_url: "https://valnesfjord.com".to_string(),
secret: "secret".to_string(),
path: "yourcallbacksecretpathwithoutslashinstartandend".to_string(),
}),
};
let mut middleware_chain = MiddlewareChain::new();
middleware_chain.add_middleware(|ctx| Box::pin(catch_new_message(ctx)));
start_callback_server(middleware_chain, config).await;
}
You can find example bot in the examples folder
You can try test bot, that works in actual version of vtg: tg, vk
You can find the documentation here
Telegram: @valnesfjord Discord: valnesfjord VK: https://vk.com/cyournamec
Contributions are always welcome! If you have any ideas, suggestions, or issues, feel free to contribute. You can fork the repository and create a pull request with your changes, or create an issue if you find any bugs or have suggestions for improvements.
We appreciate your help in making this project better!