ferrisgram 0.2.1

An elegent rust client for the Telegram Bot API.
Documentation
// WARNING: THIS CODE IS AUTOGENERATED.
// DO NOT EDIT!!!

#![allow(clippy::too_many_arguments)]
use serde::Serialize;

use crate::error::Result;
use crate::types::ForumTopic;
use crate::Bot;

impl Bot {
    /// Use this method to create a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns information about the created topic as a ForumTopic object.
    /// <https://core.telegram.org/bots/api#createforumtopic>
    pub fn create_forum_topic(&self, chat_id: i64, name: String) -> CreateForumTopicBuilder {
        CreateForumTopicBuilder::new(self, chat_id, name)
    }
}

#[derive(Serialize)]
pub struct CreateForumTopicBuilder<'a> {
    #[serde(skip)]
    bot: &'a Bot,
    /// Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
    pub chat_id: i64,
    /// Topic name, 1-128 characters
    pub name: String,
    /// Color of the topic icon in RGB format. Currently, must be one of 7322096 (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), 9367192 (0x8EEE98), 16749490 (0xFF93B2), or 16478047 (0xFB6F5F)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub icon_color: Option<i64>,
    /// Unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub icon_custom_emoji_id: Option<String>,
}

impl<'a> CreateForumTopicBuilder<'a> {
    pub fn new(bot: &'a Bot, chat_id: i64, name: String) -> Self {
        Self {
            bot,
            chat_id,
            name,
            icon_color: None,
            icon_custom_emoji_id: None,
        }
    }

    pub fn chat_id(mut self, chat_id: i64) -> Self {
        self.chat_id = chat_id;
        self
    }

    pub fn name(mut self, name: String) -> Self {
        self.name = name;
        self
    }

    pub fn icon_color(mut self, icon_color: i64) -> Self {
        self.icon_color = Some(icon_color);
        self
    }

    pub fn icon_custom_emoji_id(mut self, icon_custom_emoji_id: String) -> Self {
        self.icon_custom_emoji_id = Some(icon_custom_emoji_id);
        self
    }

    pub async fn send(self) -> Result<ForumTopic> {
        let form = serde_json::to_value(&self)?;
        self.bot.get("createForumTopic", Some(&form)).await
    }
}