use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TextObject {
#[serde(rename = "type")]
pub text_type: TextType,
pub text: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub emoji: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub verbatim: Option<bool>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TextType {
PlainText,
Mrkdwn,
}
impl TextObject {
pub fn plain(text: impl Into<String>) -> Self {
Self {
text_type: TextType::PlainText,
text: text.into(),
emoji: None,
verbatim: None,
}
}
pub fn markdown(text: impl Into<String>) -> Self {
Self {
text_type: TextType::Mrkdwn,
text: text.into(),
emoji: None,
verbatim: None,
}
}
pub fn emoji(mut self, enabled: bool) -> Self {
self.emoji = Some(enabled);
self
}
pub fn verbatim(mut self, enabled: bool) -> Self {
self.verbatim = Some(enabled);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptionObject {
pub text: TextObject,
pub value: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<TextObject>,
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
}
impl OptionObject {
pub fn new(text: impl Into<String>, value: impl Into<String>) -> Self {
Self {
text: TextObject::plain(text),
value: value.into(),
description: None,
url: None,
}
}
pub fn description(mut self, desc: impl Into<String>) -> Self {
self.description = Some(TextObject::plain(desc));
self
}
pub fn url(mut self, url: impl Into<String>) -> Self {
self.url = Some(url.into());
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptionGroupObject {
pub label: TextObject,
pub options: Vec<OptionObject>,
}
impl OptionGroupObject {
pub fn new(label: impl Into<String>) -> Self {
Self {
label: TextObject::plain(label),
options: Vec::new(),
}
}
pub fn option(mut self, option: OptionObject) -> Self {
self.options.push(option);
self
}
pub fn options(mut self, options: Vec<OptionObject>) -> Self {
self.options.extend(options);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConfirmationDialog {
pub title: TextObject,
pub text: TextObject,
pub confirm: TextObject,
pub deny: TextObject,
#[serde(skip_serializing_if = "Option::is_none")]
pub style: Option<String>,
}
impl ConfirmationDialog {
pub fn new(
title: impl Into<String>,
text: impl Into<String>,
confirm: impl Into<String>,
deny: impl Into<String>,
) -> Self {
Self {
title: TextObject::plain(title),
text: TextObject::plain(text),
confirm: TextObject::plain(confirm),
deny: TextObject::plain(deny),
style: None,
}
}
pub fn style(mut self, style: impl Into<String>) -> Self {
self.style = Some(style.into());
self
}
pub fn danger(mut self) -> Self {
self.style = Some("danger".to_string());
self
}
pub fn primary(mut self) -> Self {
self.style = Some("primary".to_string());
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConversationFilter {
#[serde(skip_serializing_if = "Option::is_none")]
pub include: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub exclude_external_shared_channels: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub exclude_bot_users: Option<bool>,
}
impl ConversationFilter {
pub fn new() -> Self {
Self {
include: None,
exclude_external_shared_channels: None,
exclude_bot_users: None,
}
}
pub fn include(mut self, types: Vec<String>) -> Self {
self.include = Some(types);
self
}
pub fn exclude_external_shared_channels(mut self) -> Self {
self.exclude_external_shared_channels = Some(true);
self
}
pub fn exclude_bot_users(mut self) -> Self {
self.exclude_bot_users = Some(true);
self
}
}
impl Default for ConversationFilter {
fn default() -> Self {
Self::new()
}
}