mobot
mobot is a telegram chat bot written in Rust. Uses a native implementation of the
Telegram Bot API. Docs at https://docs.rs/mobot.
MIT Licensed. Copyright 2023 Mohit Muthanna Cheppudira.
Features implemented so far
- Messages, stickers, and inline queries.
- Routing API for chat and inline query handlers.
- Override POST handlers for testability.
Examples
Hello World
Bot that replies with "Hello world!" to every message. Working example in src/bin/hello.rs.
use *;
async
Counter Bot - Managing state
This bot demonstrates state managenent in your bots. Working example in src/bin/ping.rs.
/// Every Telegram chat session has a unique ID. This is used to identify the
/// chat that the bot is currently in.
///
/// The `ChatState` is a simple counter that is incremented every time a message
/// is received. Every chat session has its own `ChatState`. The `Router` keeps
/// track of the `ChatState` for each chat session.
/// This is our chat handler. We simply increment the counter and reply with a
/// message containing the counter.
async
async
Uptime Bot
Bot that returns server uptime. Working example in src/bin/uptime.rs.
/// The state of the chat. This is a simple counter that is incremented every
/// time a message is received.
/// Get the uptime of the system.
async
/// The handler for the chat. This is a simple function that takes a `chat::Event`
/// and returns a `chat::Action`. It also receives the current `ChatState` for the
/// chat ID.
async
async
Testing
Set your telegram API token and then run bin/hello/rs.
export TELEGRAM_TOKEN=...
RUST_LOG=debug cargo run hello
Dependencies
Need OpenSSL and pkg-config.
sudo apt-get install pkg-config libssl-dev
TODO
- Process handler return actions
- Handler stack
- OpenAI integration