vkteams-bot 0.11.5

High-performance VK Teams Bot API toolkit with CLI and MCP server support
Documentation
use tracing::{debug, info};
use vkteams_bot::error::{BotError, Result};
use vkteams_bot::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
    // Load .env file
    dotenvy::dotenv().expect("unable to load .env file");
    // Initialize logger
    let _guard = otlp::init().map_err(|e| BotError::Otlp(e.into()))?;
    info!("Starting...");
    const CODE_STRING: &str = "<!DOCTYPE html>\n<html>\n<head>\n<title>Page Title</title>\n</head>\n<body>\n</body>\n</html>";
    // Send message like text generation
    let bot = Bot::default();
    // Get chat_id from .env
    let chat_id = ChatId::from(
        std::env::var("VKTEAMS_BOT_CHAT_ID").expect("Unable to find VKTEAMS_CHAT_ID in .env file"),
    );
    // Bot action typing
    bot.send_api_request(RequestChatsSendAction::new((
        chat_id.to_owned(),
        ChatActions::Typing,
    )))
    .await?;
    // Send message
    let res = bot
        .send_api_request(
            RequestMessagesSendText::new(chat_id.to_owned())
                .set_text(
                    MessageTextParser::new()
                        .add(MessageTextFormat::Plain("Code below:".to_string()))
                        .next_line()
                        .add(MessageTextFormat::Pre(
                            CODE_STRING.to_string(),
                            Some("html".to_string()),
                        )),
                )?
                .set_keyboard(
                    Keyboard::new()
                        .add_button(&ButtonKeyboard::url(
                            "Button url".to_string(),
                            "https://example.com".to_string(),
                            ButtonStyle::Primary,
                        ))
                        .add_row()
                        .add_button(&ButtonKeyboard::cb(
                            "Callback".to_string(),
                            "CB".to_string(),
                            ButtonStyle::Attention,
                        )),
                )?,
        )
        .await?;
    debug!("Message id: {:?}", res.msg_id);
    bot.send_api_request(RequestChatsSendAction::new((
        chat_id.to_owned(),
        ChatActions::Looking,
    )))
    .await?;
    Ok(())
}