Skip to main content

threema_gateway_bot/
lib.rs

1//! # Threema Bot SDK
2//!
3//! A library for building Threema Gateway bots in Rust.
4//!
5//! This library provides the foundational components for building Threema bots
6//! with:
7//!
8//! - **Webhook handling** to receive and validate Threema Gateway messages
9//! - **Configuration system** based on TOML files and env vars, extensible by your bot
10//! - **Rate limiting** and **caching** built-in
11//! - **Command parsing** infrastructure
12//!
13//! The command parsing infrastructure allows for both slash-command style (`/remind 30m`) or
14//! word-command style (`remind 30m`).
15//!
16//! ## Quick Start
17//!
18//! ```rust,no_run
19//! use std::path::Path;
20//! use threema_gateway_bot::{
21//!     config::BotConfig,
22//!     server::{
23//!         BotServer,
24//!         handler::{Action, HandlerResult, MessageContext, MessageHandler, Response, TypingHandle},
25//!     },
26//! };
27//!
28//! // Create a handler struct
29//! struct MyHandler;
30//!
31//! // Implement `MessageHandler` trait for your struct
32//! #[async_trait::async_trait]
33//! impl MessageHandler for MyHandler {
34//!     async fn handle_text(&self, _ctx: &MessageContext, text: &str, typing: &TypingHandle) -> HandlerResult<Action> {
35//!         let text_response = Response::text(format!("You said: {}", text));
36//!         Ok(Action::Respond(vec![text_response]))
37//!     }
38//! }
39//!
40//! // Start bot server
41//! #[tokio::main]
42//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
43//!     let config = BotConfig::load_with_prefix("MYBOT", Path::new("config.toml"))?;
44//!     BotServer::new(config, MyHandler)?.run().await?;
45//!     Ok(())
46//! }
47//! ```
48
49mod client;
50pub mod commands;
51pub mod config;
52mod dedup;
53pub mod errors;
54mod rate_limit;
55pub mod server;
56mod webhook;