use tracing::{debug, info};
use vkteams_bot::error::{BotError, Result};
use vkteams_bot::prelude::*;
#[tokio::main]
async fn main() -> Result<()> {
dotenvy::dotenv().expect("unable to load .env file");
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>";
let bot = Bot::default();
let chat_id = ChatId::from(
std::env::var("VKTEAMS_BOT_CHAT_ID").expect("Unable to find VKTEAMS_CHAT_ID in .env file"),
);
bot.send_api_request(RequestChatsSendAction::new((
chat_id.to_owned(),
ChatActions::Typing,
)))
.await?;
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(())
}