use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Message {
pub text: Option<String>,
pub markdown: Option<String>,
pub id: Option<String>,
pub arguments: Option<Vec<String>>,
#[serde(flatten)]
pub properties: Option<HashMap<String, serde_json::Value>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MultiformatMessage {
pub text: String,
pub markdown: Option<String>,
#[serde(flatten)]
pub properties: Option<HashMap<String, serde_json::Value>>,
}
impl Message {
pub fn new(text: impl Into<String>) -> Self {
Self {
text: Some(text.into()),
markdown: None,
id: None,
arguments: None,
properties: None,
}
}
pub fn with_markdown(text: impl Into<String>, markdown: impl Into<String>) -> Self {
Self {
text: Some(text.into()),
markdown: Some(markdown.into()),
id: None,
arguments: None,
properties: None,
}
}
pub fn with_arguments(text: impl Into<String>, arguments: Vec<String>) -> Self {
Self {
text: Some(text.into()),
markdown: None,
id: None,
arguments: Some(arguments),
properties: None,
}
}
pub fn add_argument(mut self, arg: impl Into<String>) -> Self {
self.arguments.get_or_insert_with(Vec::new).push(arg.into());
self
}
pub fn with_id(mut self, id: impl Into<String>) -> Self {
self.id = Some(id.into());
self
}
}
impl MultiformatMessage {
pub fn new(text: impl Into<String>) -> Self {
Self {
text: text.into(),
markdown: None,
properties: None,
}
}
pub fn with_markdown(mut self, markdown: impl Into<String>) -> Self {
self.markdown = Some(markdown.into());
self
}
}
impl From<String> for Message {
fn from(text: String) -> Self {
Message::new(text)
}
}
impl From<&str> for Message {
fn from(text: &str) -> Self {
Message::new(text)
}
}
impl From<String> for MultiformatMessage {
fn from(text: String) -> Self {
MultiformatMessage::new(text)
}
}
impl From<&str> for MultiformatMessage {
fn from(text: &str) -> Self {
MultiformatMessage::new(text)
}
}