vaegram 0.3.0

Telegram MTProto client library for users and bots
Documentation
use crate::Client;
use crate::errors::{Error, Result};
use crate::raw::functions;
use crate::types::{BusinessBotRights, BusinessRecipients, PeerRef};

impl Client {
    /// Connects a bot to the account's business profile, or updates its rights and recipients.
    ///
    /// Fails with `Error::InvalidArgument` unless `recipients` selects at least one kind of chat or user, or sets
    /// `exclude_selected`: on its own that picks every private chat, and with `exclude_users` every one but theirs.
    pub async fn update_connected_bot(
        &self,
        bot_id: impl Into<PeerRef>,
        rights: BusinessBotRights,
        recipients: &BusinessRecipients,
    ) -> Result<()> {
        if !(recipients.existing_chats
            || recipients.new_chats
            || recipients.contacts
            || recipients.non_contacts
            || recipients.exclude_selected
            || !recipients.users.is_empty())
        {
            return Err(Error::InvalidArgument("update_connected_bot needs at least one kind of recipient"));
        }
        let (bot, recipients) = (self.resolve_user(&bot_id.into()).await?, recipients.write_bot(self).await?);
        let rights = Some(rights.write());
        let request = functions::account::UpdateConnectedBot { deleted: false, rights, bot, recipients };
        self.invoke(&request).await.map(drop)
    }
}