Crates.io | rustygram |
lib.rs | rustygram |
version | 0.1.4 |
source | src |
created_at | 2023-11-22 14:04:58.12968 |
updated_at | 2024-03-28 14:05:59.632761 |
description | RustyGram is a minimal and blazing fast telegram notification framework for Rust |
homepage | |
repository | https://github.com/ExtremelySunnyYK/rustygram |
max_upload_size | |
id | 1045189 |
size | 474,650 |
⚡rustygram
⚡rustygram is a minimal and blazing fast telegram notification framework using Rust. Abstracts away the Telegram API complexity so your app doesn't have to worry about the underlying implementation.
Easily integrate rustygram into your rust application to quickly send messages to Telegram bots, groups, and channels.
Send asynchronous notifications in a reliable way.
create_bot
- create a bot instance consistsing of Telegram's bot token, and target chat_idsend_message
- call Telegram bot's API sendMessage to send message asynchronouslyfn main() {
let instance = rustygram::create_bot("123456:123456", "-1000000");
if let Err(_) = rustygram::send_message(&instance, "Hello world", None) {
// error handling here...
}
}
MarkdownV2
or HTML
style messageSend message in MarkdownV2
use rustygram::types::{SendMessageOption, SendMessageParseMode};
fn main() {
let instance = rustygram::create_bot("16", "-1s00");
let option = SendMessageOption { parse_mode: Some(SendMessageParseMode::MarkdownV2) };
// note on two spaces at the end of the line for a new line in markdown
if let Err(_) = rustygram::send_message(&instance,
r#"__Hello world__
`Tap to copy this text`
Visit my [website](https://yong-kang.super.site/)"#, Some(option)) {
// error handling here...
}
}
Send messsage in HTML
use rustygram::types::{SendMessageOption, SendMessageParseMode};
fn main() {
let instance = rustygram::create_instance("189:blablabla", "-10");
let option = SendMessageOption { parse_mode: Some(SendMessageParseMode::HTML) };
if let Err(_) = rustygram::send_message(&instance,
r#"<u>Hello world</u>
<code>Tap to copy this text</code>
Visit my <a href="https://yong-kang.super.site/">website</a>"#, Some(option)) {
// error handling here...
}
}
use rustygram::types::{SendMessageOption, SendMessageParseMode};
fn main() {
let instance = rustygram::create_bot("189:blablabla", "-10");
let option = SendMessageOption { parse_mode: Some(SendMessageParseMode::MarkdownV2) };
if let Err(_) = rustygram::send_csv(&instance, "example.csv", Some(option)) {
// error handling here...
}
}
```
- Refer to tests.rs for more reference on how to send a CSV file
## Setting up your environment
1. [Download Rust](http://rustup.rs/).
2. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `189:blablabla`.
3. Initialise the `BOT_TOKEN` environmental variable to your token:
```bash
# Unix-like
$ export BOT_TOKEN=<Your token here>
# Windows command line
$ set BOT_TOKEN=<Your token here>
# Windows PowerShell
$ $env:BOT_TOKEN=<Your token here>
rustygram
currently requires rustc at least version 1.68):# If you're using stable
$ rustup update stable
$ rustup override set stable
# If you're using nightly
$ rustup update nightly
$ rustup override set nightly
cargo new my_bot
, enter the directory and put these lines into your Cargo.toml
:[dependencies]
rustygram = "0.1"
log = "0.4"
pretty_env_logger = "0.4"
tokio = { version = "1.8", features = ["rt-multi-thread", "macros"] }
You can test by define the following two environment variables
TEST_BOT_TOKEN
- telegram bot's tokenTEST_CHAT_ID
- telegram bot's chat idthen execute
cargo test
some tests will send a single, or multiple messages to a specified chat id on behalf
of such telegram bot. Please take a look at src/tests.rs
.
You can utilize this telegram bot @username_to_id_bot
to get your
telegram channel's chat_id
.
See CONRIBUTING.md
.
This project is heavily inspired by teloxide. However it is not a fork of teloxide, but a complete rewrite in order to make it more minimal and faster for the use case of sending notifications on telegram.
The simplistic design is inspired by rustelebot but with more modular and extensible design, also changing the underlying libraries used to be more modern.
MIT, Chia Yong Kang