⚡rustygram is a minimal and blazing fast telegram notification framework for Rust

Overview

⚡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.

Highlights

  • Easily integrate rustygram into your app to quickly send messages to Telegram bots, groups, and channels if you have the chat ID.

  • Send asynchronous notifications in a reliable way.

API overview

  • create_bot - create a bot instance consistsing of Telegram's bot token, and target chat_id
  • send_message - call Telegram bot's API sendMessage to send message asynchronously

Examples

Send in simple way

fn main() {
 let instance = rustygram::create_bot("123456:123456", "-1000000");
 if let Err(_) = rustygram::send_message(&instance, "Hello world", None) {
  // error handling here...
 }
}

Send in MarkdownV2 or HTML style message

Send 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...
 }
}

Setting up your environment

  1. Download Rust.
  2. Create a new bot using @Botfather to get a token in the format 189:blablabla.
  3. Initialise the BOT_TOKEN environmental variable to your token:
# 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>
  1. Make sure that your Rust compiler is up to date (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
  1. Run 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"] }

Tests

You can test by define the following two environment variables

  • TEST_BOT_TOKEN - telegram bot's token
  • TEST_CHAT_ID - telegram bot's chat id

then execute

cargo test

some tests will send a single, or multiple messages to specified chat id on behalf of such telegram bot. Please take a look at src/tests.rs.

Note

You can utilize this telegram bot @username_to_id_bot in order to get your telegram channel's chat_id.

Contributing

See CONRIBUTING.md.

Acknowledgements

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.

License

MIT, Chia Yong Kang

You might also like...
Telegram bot for searching in Arch User Repository ( AUR ); Implemented using rust.

AurSearchBot A Telegram Inline Search Bot Written in Rust Introduction Telegram Bot that can search AUR ( Arch User Repository ) in inline mode. This

A simple twitter - telegram forwarder written in Rust.

twitter-telegram-forwarder A simple twitter - telegram forwarder written in Rust. Example channel: https://t.me/nanabunnonijyuuni_tweet How to use it

Autogenerated wrapper for the Telegram Bot API written in Rust.
Autogenerated wrapper for the Telegram Bot API written in Rust.

An Elegant Rust Client for Telegram Bot API crates.io • docs.rs Table of contents Introduction Key Features Installation Getting Started Documentation

A simple Telegram bot that eats anonymous channel messages, written in Rust.

tgbot-nochanmsg By Asuna Right Control When creating your bot from botfather, it's not bad to disable privacy mode, because it needs to access the mes

A Telegram bot written in Rust.

Knight-Bot Table of Contents About Support chat Installation Setting up your environment Build manually Commands Commands on TODO list Find this bot A

Small Rust program for sending messages to Telegram channels.

tg-send: a small Rust program for sending Telegram messages Send messages to a group/channel via the Bot API from the command line; it's super simple

Source code for the Telegram channel @pixiv_daily
Source code for the Telegram channel @pixiv_daily

PixivDaily (Rust) This repository contains the source code of the program running the Telegram channel @pixiv_daily. Usage First, you'll need to clone

IITC-CE Telegram Chat Spam Protection

ADA AntiBot This bot bans spammers in Telegram chat. Run To run you should export environment variables: TELOXIDE_TOKEN - telegram bot token TELEGRAM_

Telegram Bot Template with Cloudflare Workers

cf-workers-telegram-bot-template Usage This template starts you off with a src/lib.rs file, acting as an entrypoint for requests hitting your Worker.

Owner
Chia Yong Kang
Having fun in web3, defi 🌍
Chia Yong Kang
Telegram bot help you to run Rust code in Telegram via Rust playground

RPG_BOT (Rust Playground Bot) Telegram bot help you to run Rust code in Telegram via Rust playground Bot interface The bot supports 3 straightforward

TheAwiteb 8 Dec 6, 2022
Matrix Bot for Bitcoin Push Notification Service

BPNS Matrix Bot Description Matrix Bot for Bitcoin Push Notification Service. Requirements Rust (1.57.0+) BPNS Server Matrix account Build cargo build

BPNS 0 Mar 14, 2022
Single-operator public liveness notification

Single-operator public liveness notification

Charlotte Som 1 Feb 16, 2022
🚀 Fleet is the blazing fast build tool for Rust

Fleet is the blazing fast build tool for Rust. Compiling with Fleet is up-to 5x faster than with cargo.

Dimension 2.2k Jan 6, 2023
Parses go-ethereum logs and pipes them to telegram

parrot Middleware that accepts logs via stdin and redirects them to Telegram, based on a configurable set of conditions.

null 6 Jul 25, 2022
This is a simple Telegram bot with interface to Firefly III to process and store simple transactions.

Firefly Telegram Bot Fireflies are free, so beautiful. (Les lucioles sont libres, donc belles.) ― Charles de Leusse, Les Contes de la nuit This is a s

null 13 Dec 14, 2022
Uradhura is a telegram bot that fetches information and media from reddit

Pathetic little Telegram bot that fetches information from Reddit posts(with gif, image(post with single image) and video)

The Penguins Org 3 May 28, 2022
A Simple, But amazing telegram bot, Made using the Rust language!

Telegram bot in Rust A fun Telegram bot made using Rust language.

Deep Alchemy 2 Dec 21, 2021
This is a Telegram bot I'm working on in my free time to learn Rust.

Maldness Bot This is a Telegram bot I'm working on in my free time to learn Rust. Building docker build -t . should be enough.

Sergey Kislyakov 10 May 13, 2022
Rust telegram bot library for many runtimes

Telbot Telbot provides telegram bot types and api wrappers. Specifically, telbot now supports: telbot-types: basic telegram types / requests / respons

kiwiyou 17 Dec 3, 2022