#send-message #telegram-bot #telegram-api

botapi

A mildly competent autogenerated telegram bot api wrapper

33 releases

0.0.37 Apr 1, 2024
0.0.36 Jan 6, 2024
0.0.35 Dec 30, 2023
0.0.29 Oct 15, 2023
0.0.3 Nov 8, 2022

#1013 in Web programming

Download history 2/week @ 2024-01-01 55/week @ 2024-02-26 1/week @ 2024-03-11 169/week @ 2024-04-01

170 downloads per month

MIT license

4.5MB
100K SLoC

botapi-rs

Autogenerated telegram bot api wrapper using api spec from https://github.com/PaulSonOfLars/telegram-bot-api-spec.
Generates a full serde-based telegram bot api wrapper with idiomatic design patterns.

Features

  • Automatically kept up to date with the latest telegram api
  • Minimal fluff and boilerplate
  • Full async support with tokio
  • Support for both long polling and webhooks
  • Automatically generated documentation

Building the docs

Documentation is generated inline during compilation, to view the docs just run

cargo build
cargo doc --open

lib.rs:

Autogenerated telegram bot api wrapper using api spec from https://github.com/PaulSonOfLars/telegram-bot-api-spec. Generates a full serde-based telegram bot api wrapper with idiomatic design patterns.

Features

  • Automatically kept up to date with the latest telegram api
  • Minimal fluff and boilerplate
  • Full async support with tokio
  • Support for both long polling and webhooks
  • Automatically generated documentation

Examples

Use webhooks to fetch updates

use botapi::gen_types::FileData;
use botapi::bot::Bot;
use botapi::ext::{Webhook, BotUrl};
use std::net::{SocketAddr, Ipv4Addr, IpAddr};
use futures_util::StreamExt;
let client = Bot::new("sometoken").unwrap();
Webhook::new(
   &client,
   BotUrl::Host("example.com".to_owned()),
   false,
   SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080),
   None,
)
.get_updates()
.await.unwrap()
.for_each_concurrent(
    None,
    |update| async move {
        //handle update
    },
);
})

Send messages or media

use botapi::gen_types::{FileData, Message, ReplyParametersBuilder};
use botapi::bot::Bot;
let client = Bot::new("sometoken").unwrap();
let bytes = vec![1,2,3];
client
    .build_send_photo(
        message.get_chat().get_id(),
           FileData::Bytes(bytes),
    )
    .caption("If you do not solve this captcha correctly you will be terminated by memetic kill agent")
    .reply_parameters(&ReplyParametersBuilder::new(message.get_message_id()).build())
    .build()
    .await.unwrap();
})

Dependencies

~10–26MB
~408K SLoC