vaegram 0.2.0

Telegram MTProto client library for users and bots
Documentation
use crate::Client;
use crate::errors::Result;
use crate::methods::accepted;
use crate::raw::functions;
use crate::types::PeerRef;

/// Request built by [`Client::toggle_bot_in_attach_menu`].
#[must_use = "a request does nothing until it is awaited"]
pub struct ToggleBotInAttachMenu<'a> {
    client: &'a Client,
    bot_id: PeerRef,
    enabled: bool,
    write_allowed: bool,
}

impl Client {
    /// Adds a bot to the attachment menu, or removes it if `enabled` is false.
    pub fn toggle_bot_in_attach_menu(&self, bot_id: impl Into<PeerRef>, enabled: bool) -> ToggleBotInAttachMenu<'_> {
        ToggleBotInAttachMenu { client: self, bot_id: bot_id.into(), enabled, write_allowed: false }
    }
}

impl ToggleBotInAttachMenu<'_> {
    /// Lets the bot send messages to the user.
    pub fn write_allowed(mut self) -> Self {
        self.write_allowed = true;
        self
    }

    async fn send(self) -> Result<()> {
        let request = functions::messages::ToggleBotInAttachMenu {
            write_allowed: self.write_allowed,
            bot: self.client.resolve_user(&self.bot_id).await?,
            enabled: self.enabled,
        };
        accepted(self.client.invoke(&request).await?)
    }
}

into_future!(ToggleBotInAttachMenu, ());