Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implementation for getStickerSet #230

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

CuriouslyCurious
Copy link

It uses a similar structure to how getFile is implemented. Might not be the prettiest implementation but it seemingly works.

Basically you call get_sticker_set() from a sticker object to send a request for the sticker set it is from.

A code snippet that should showcase it working:

use std::env;

use futures::StreamExt;
use telegram_bot::*;

#[tokio::main]
async fn main() -> Result<(), Error> {
    let token = env::var("TELEGRAM_BOT_TOKEN").expect("TELEGRAM_BOT_TOKEN not set");
    let api = Api::new(token);

    // Fetch new updates via long poll method
    let mut stream = api.stream();
    while let Some(update) = stream.next().await {
        // If the received update contains a new message...
        let update = update?;
        if let UpdateKind::Message(message) = update.kind {
            if let MessageKind::Sticker{ ref data, .. } = message.kind {
                // Print received text message to stdout.
                match &data.set_name {
                    Some(_) => {
                        let set = api.send(data.get_sticker_set()).await?;
                        println!("{:?}", set);
                        ()
                    }
                    None => {
                        api.send(message.text_reply(format!(
                            "The sticker you sent me is not part of a sticker set."
                        ))).await?;
                        ()
                    }
                };
            }
        }
    }
    Ok(())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant