rustygram/
lib.rs

1#![forbid(unsafe_code)]
2
3/// High Level Wrapper API of Bot.
4///
5/// This module provides a high-level API for interacting with Telegram's bot API. It provides
6/// functionality for creating a bot with a token and chat ID, and for sending messages.
7///
8/// The `create_bot` function is used to create a new `Bot` instance. The `bot_token` parameter
9/// should be the token provided by the BotFather on Telegram, and `chat_id` should be the ID
10/// of the chat where the bot should send messages.
11///
12/// The `send_message` function is used to send a message to the chat associated with the `Bot`.
13/// The `msg` parameter is the text of the message to send, and the `options` parameter can be
14/// used to specify additional options like parse mode.
15use bot::Bot;
16pub mod bot;
17pub mod errors;
18pub mod tests;
19pub mod types;
20pub mod utils;
21
22/// Create a Bot to interact with APIs.
23/// Returns a `Bot` configured with the provided bot token and chat id.
24///
25/// # Arguments
26/// * `bot_token` - a string of bot token
27/// * `chat_id` - a chat id string to send message
28pub fn create_bot(bot_token: &str, chat_id: &str) -> Bot {
29    Bot::new(bot_token, chat_id)
30}
31
32/// Send message asynchronously.
33/// Return `Result<(), ErrorResult>`.
34///
35/// # Arguments
36///
37/// * `bot` - `Bot` to send message to telegram's chat
38/// * `msg` - message to send
39/// * `options` - options for sending message
40pub async fn send_message(
41    bot: &Bot,
42    msg: &str,
43    options: Option<types::SendMessageOption>,
44) -> Result<(), errors::ErrorResult> {
45    bot.send_message(msg, options).await
46}