From 6f7c48c178f6ec7a629fa2af26dc1fd704d6bdb5 Mon Sep 17 00:00:00 2001 From: Chia Yong Kang Date: Thu, 23 Nov 2023 11:37:45 +0800 Subject: [PATCH] added examples --- src/examples/bot.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/examples/bot.rs diff --git a/src/examples/bot.rs b/src/examples/bot.rs new file mode 100644 index 0000000..19323c8 --- /dev/null +++ b/src/examples/bot.rs @@ -0,0 +1,29 @@ +/// Create a new bot using the Telegram bot token and chat ID from the environment variables. +/// +/// # Example +/// +/// ``` +/// use rustygram::bot::Bot; +/// +/// # fn main() -> Result<(), Box> { +/// // Assuming the environment variables are set +/// let bot = create_bot()?; +/// // Use the bot... +/// # Ok(()) +/// # } +/// ``` +fn create_bot() -> Bot { + dotenv().ok(); + let token = env::var("TELEGRAM_BOT_TOKEN").expect("TELEGRAM_BOT_TOKEN not set"); + let chat_id = env::var("TELEGRAM_CHAT_ID").expect("TELEGRAM_CHAT_ID not set"); + Bot::new(token, chat_id) +} + +#[tokio::main] +/// Send a message to the chat associated with the bot. +fn send_message() -> Result<(), ErrorResult> { + let bot = create_bot(); + let msg = "Hello, world!"; + let options = None; + bot.send_message(msg, options) +}