MOBOT
MOBOT is a Telegram chat framework written in Rust. It comes with a fully native implementation of the
Telegram Bot API.
Features
- Raw Telegram API with support for Messages, Channels, Stickers, Callbacks, and more.
- Web framework style Routing API with support for message-based routing and nested handler stacks.
- Easy application state management. MOBOT makes sure your handler gets the right state for each chat.
- Integrated test infrastructure (
FakeBot), to simplify writing unit tests for your bots. - Support for progress bars, inline keyboards, "Typing..." indicators, etc. See demo video below.
Demo Video
This is a demo of a devops bot built with the MOBOT framework.
https://github.com/0xfe/mobot/assets/241299/22b3c420-6acd-43f9-81f8-eb957ff24288
Hello World!
Add mobot to your Cargo.toml.
cargo add mobot
Example Bot that replies with "Hello world!" to every message. Working example in src/bin/hello.rs.
use *;
async
Documentation
See full API documentation at https://docs.rs/mobot.
See examples in src/bin.
Testing
MOBOT is packaged with fake::FakeAPI, a library to simplify unit testing your bots. FakeAPI can be
plugged into mobot::Client using the with_post_handler hook. See example below from router_test.rs.
async
Extending MOBOT
Adding new Telegram API calls
Adding support for additional APIs is straightforward. It involves creating structs for the request
and response, and adding a method to API. Make sure to derive the BotRequest trait. For
example, to add support for the sendSticker Telegram API:
Create SendStickerRequest
Add the send_sticker method call to API
Test and send me a Pull Request
- Add a test in
tests/. If necessary updatelib/fake.rsfor client testing. - Add example code to
src/bin/. - Commit and send me a PR!
External Dependencies
This crate requires OpenSSL and pkg-config:
- On Linux:
sudo apt-get install pkg-config libssl-dev - On Mac: nothing to do!
TODO
- Default logging handler
- Default auth handler
- Dialoge/script framework
License
MIT License Copyright 2023 Mohit Muthanna Cheppudira
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.