-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |