Skip to content

Commit

Permalink
added examples
Browse files Browse the repository at this point in the history
  • Loading branch information
yongkangc committed Nov 23, 2023
1 parent 53b28c3 commit 6f7c48c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/examples/bot.rs
Original file line number Diff line number Diff line change
@@ -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<dyn std::error::Error>> {
/// // 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)
}

0 comments on commit 6f7c48c

Please sign in to comment.