Skip to content

Instantly share code, notes, and snippets.

@optozorax
Created March 10, 2020 10:49
Show Gist options
  • Save optozorax/51f0b26a607721884f22abde37831d76 to your computer and use it in GitHub Desktop.
Save optozorax/51f0b26a607721884f22abde37831d76 to your computer and use it in GitHub Desktop.
Inline sticker telegram bot teloxide
[package]
name = "fyass"
version = "0.1.0"
authors = ["optozorax <optozorax@gmail.com>"]
edition = "2018"
[dependencies]
teloxide = { git = "https://github.com/teloxide/teloxide", branch = "dev" }
log = "0.4.8"
tokio = "0.2.11"
pretty_env_logger = "0.4.0"
reqwest = { verion = "*", default-features = false, features = ["socks"] }
use teloxide::types::*;
use teloxide::prelude::*;
#[tokio::main]
async fn main() {
teloxide::enable_logging!();
log::info!("Starting ping_pong_bot!");
let proxy = reqwest::Proxy::all("socks5://proxy:PassWord1023@p.sb30.ru:443").expect("Creating proxy");
let client = reqwest::Client::builder()
.proxy(proxy)
.build()
.expect("creating reqwest::Client");
let bot = Bot::from_env_with_client(client);
Dispatcher::new(bot)
.inline_queries_handler(|rx: DispatcherHandlerRx<InlineQuery>| {
rx.for_each(|message| async move {
let stickers = [
"CAACAgIAAxkBAAMxXmdY_Ssn6E61-907MMNfVZIFd5oAAiMAA3lx3hbatLjZRpEzkRgE",
"CAACAgIAAxkBAAM1XmdaZcMlEDa-75LVKWwEEVeDLRkAAqAAA6tXxAtpwuGr-UylexgE",
"CAACAgIAAxkBAAM3Xmda0Kc4utK7UbfabZy0kVFC1pQAAvUAA3tOKhBCNQABQEpab2YYBA",
];
message.bot.answer_inline_query(message.update.id.clone(),
stickers.iter().enumerate().map(|(i, x)| InlineQueryResult::CachedSticker(InlineQueryResultCachedSticker {
id: format!("5364356453645365345633456346543{}", i),
sticker_file_id: (*x).to_string(),
reply_markup: None,
input_message_content: None,
})).collect::<Vec<InlineQueryResult>>()
).send().await.log_on_error().await;
log::info!("inline: {:?}", message.update);
})
})
.messages_handler(|rx: DispatcherHandlerRx<Message>| {
rx.for_each(|message| async move {
log::info!("message: {:#?}", message);
message.answer("ну здарова").send().await.log_on_error().await;
})
})
.dispatch()
.await;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment