telegrama_rs/lib.rs
1/*!
2 * Telegrama-rs - A small, reliable Rust library for sending Telegram messages via bots
3 *
4 * This library provides a simple way to send messages to Telegram chats via bots.
5 * It handles formatting, escaping, and error recovery automatically.
6 */
7
8pub mod client;
9pub mod configuration;
10pub mod error;
11pub mod formatter;
12
13/// The main entry point for the Telegrama library.
14///
15/// Provides static methods for configuration and sending messages.
16pub struct Telegrama;
17
18impl Telegrama {
19 /// Configure the Telegrama library with the provided settings.
20 ///
21 /// # Examples
22 ///
23 /// ```
24 /// use telegrama_rs::Telegrama;
25 ///
26 /// Telegrama::configure(|config| {
27 /// config.set_bot_token("YOUR_BOT_TOKEN");
28 /// config.set_chat_id("YOUR_CHAT_ID");
29 /// config.set_default_parse_mode("MarkdownV2");
30 /// });
31 /// ```
32 pub fn configure<F>(config_fn: F)
33 where
34 F: FnOnce(&mut configuration::Configuration),
35 {
36 configuration::Configuration::get_instance_mut(config_fn);
37 }
38
39 /// Send a message using the configured settings.
40 ///
41 /// # Arguments
42 ///
43 /// * `message` - The message text to send
44 /// * `options` - Optional parameters to customize the message
45 ///
46 /// # Returns
47 ///
48 /// A `Result` containing the response from the Telegram API
49 ///
50 /// # Examples
51 ///
52 /// ```
53 /// use telegrama_rs::Telegrama;
54 ///
55 /// // Send a simple message
56 /// let result = Telegrama::send_message("Hello from Telegrama-rs!");
57 ///
58 /// // Send a message with options
59 /// let result = Telegrama::send_message(
60 /// "Hello with *formatting*!",
61 /// &[("parse_mode", "MarkdownV2"), ("disable_web_page_preview", "true")]
62 /// );
63 /// ```
64 pub fn send_message<S: AsRef<str>>(
65 message: S,
66 options: &[(&str, &str)],
67 ) -> Result<client::Response, error::Error> {
68 // Create a client and send the message
69 let client = client::Client::new();
70 client.send_message(message.as_ref(), options)
71 }
72}
73
74// Re-export main components for easy access
75pub use client::{Client, Response};
76pub use configuration::{ClientOptions, Configuration, FormattingOptions};
77pub use error::Error;
78pub use formatter::Formatter;
79
80#[cfg(test)]
81mod tests {
82
83
84 #[test]
85 fn test_library_basics() {
86 // Just a simple test to ensure the library compiles
87 assert!(true);
88 }
89}