Last active
May 18, 2021 08:00
-
-
Save WaffleLapkin/fb96b47e605c19245686efc285a36926 to your computer and use it in GitHub Desktop.
Example of sending files for https://github.com/teloxide/teloxide/issues/384 (2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [dependencies] | |
// teloxide = "0.4" | |
// tokio = { version = "1.6", features = ["macros", "rt-multi-thread"] } | |
// plotters = "0.3" | |
// image = "0.23" | |
#[tokio::main] | |
async fn main() { | |
run().await; | |
} | |
async fn run() { | |
use image::{DynamicImage, ImageBuffer}; | |
use plotters::prelude::*; | |
use teloxide::requests::{Request, Requester}; | |
let token = "TOKEN"; | |
let chat = 218485655i64; | |
let mut img: Vec<u8> = vec![0; 200 * 200 * 3]; | |
{ | |
let mut backend = plotters::prelude::BitMapBackend::with_buffer(&mut img, (200, 200)); | |
backend | |
.draw_rect((50, 50), (150, 150), &RED, true) | |
.expect("Failed to draw a rect"); | |
} | |
let img = DynamicImage::ImageRgb8(ImageBuffer::from_raw(200, 200, img).unwrap()); | |
let mut png: Vec<u8> = Vec::new(); | |
img.write_to(&mut png, image::ImageOutputFormat::Png) | |
.expect("Failed to convert image to png"); | |
let photo = teloxide::types::InputFile::memory("test.png", png); | |
let bot = teloxide::Bot::new(token); | |
bot.send_photo(chat, photo) | |
.send() | |
.await | |
.expect("Failed to send request"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment