Official Rust SDK for the TOP.TL Telegram directory API.
Add to your Cargo.toml:
[dependencies]
toptl = "1"use toptl::TopTL;
#[tokio::main]
async fn main() -> Result<(), toptl::Error> {
let client = TopTL::new("your-api-key");
// Get listing info
let listing = client.get_listing("mybotusername").await?;
println!("{:?}", listing);
// Check if a user has voted
let result = client.has_voted("mybotusername", 123456789).await?;
println!("Voted: {}", result.voted);
// Get votes
let votes = client.get_votes("mybotusername").await?;
println!("Total votes: {:?}", votes.total);
// Post stats
use toptl::StatsPayload;
let stats = StatsPayload {
server_count: Some(100),
member_count: Some(5000),
shard_count: None,
};
client.post_stats("mybotusername", &stats).await?;
// Global stats
let global = client.get_global_stats().await?;
println!("{:?}", global);
Ok(())
}Automatically post stats on a recurring interval:
use std::sync::Arc;
use std::time::Duration;
use toptl::{TopTL, StatsPayload};
use toptl::autoposter::Autoposter;
#[tokio::main]
async fn main() {
let client = TopTL::new("your-api-key");
let autoposter = Autoposter::new(client, "mybotusername")
.interval(Duration::from_secs(900)) // every 15 minutes
.callback(Arc::new(|| StatsPayload {
server_count: Some(1234),
member_count: Some(56789),
shard_count: None,
}))
.start();
// Runs in the background. Call autoposter.stop().await to stop.
}use toptl::TopTL;
let client = TopTL::builder("your-api-key")
.base_url("https://top.tl/api/v1") // default
.build();MIT - see LICENSE for details.