dingtalk_stream/frames/up_message/
mod.rs1pub mod callback_message;
2use serde::{Deserialize, Serialize};
3
4pub mod robot_message;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[serde(tag = "msgtype")]
8pub enum MessageContent {
9 #[serde(rename = "text")]
10 Text { text: MessageContentText },
11 #[serde(rename = "picture")]
12 Picture { picture: MessageContentPicture },
13 #[serde(rename = "markdown")]
14 Markdown { markdown: MessageContentMarkdown },
15 #[serde(rename = "link")]
16 Link { link: MessageContentLink },
17}
18
19impl MessageContent {
20 pub(crate) fn to_up_msg(&self) -> crate::Result<(&'static str, String)> {
21 Ok(match self {
22 MessageContent::Text { text } => ("sampleText", serde_json::to_string(text)?),
23 MessageContent::Picture { picture } => {
24 ("sampleImageMsg", serde_json::to_string(picture)?)
25 }
26 MessageContent::Markdown { markdown } => {
27 ("sampleMarkdown", serde_json::to_string(markdown)?)
28 }
29 MessageContent::Link { .. } => ("sampleLink", serde_json::to_string(&())?),
30 })
31 }
32}
33
34impl<T: Into<String>> From<T> for MessageContent {
35 fn from(value: T) -> Self {
36 Self::Text {
37 text: MessageContentText::from(value),
38 }
39 }
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct MessageContentText {
44 pub content: String,
45}
46
47impl From<MessageContentText> for MessageContent {
48 fn from(value: MessageContentText) -> Self {
49 Self::Text { text: value }
50 }
51}
52
53impl<T: Into<String>> From<T> for MessageContentText {
54 fn from(value: T) -> Self {
55 Self {
56 content: value.into(),
57 }
58 }
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct MessageContentPicture {
63 #[serde(rename = "photoURL")]
64 photo_url: String,
65}
66
67impl From<MessageContentPicture> for MessageContent {
68 fn from(value: MessageContentPicture) -> Self {
69 Self::Picture { picture: value }
70 }
71}
72
73impl<T: Into<String>> From<T> for MessageContentPicture {
74 fn from(value: T) -> Self {
75 Self {
76 photo_url: value.into(),
77 }
78 }
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
82pub struct MessageContentMarkdown {
83 pub title: String,
84 pub text: String,
85}
86
87impl From<MessageContentMarkdown> for MessageContent {
88 fn from(value: MessageContentMarkdown) -> Self {
89 Self::Markdown { markdown: value }
90 }
91}
92
93impl<Title: Into<String>, Text: Into<String>> From<(Title, Text)> for MessageContentMarkdown {
94 fn from((title, text): (Title, Text)) -> Self {
95 Self {
96 title: title.into(),
97 text: text.into(),
98 }
99 }
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize)]
103pub struct MessageContentLink {
104 pub title: String,
105 pub text: String,
106 #[serde(rename = "messageUrl")]
107 pub message_url: Option<String>,
108 #[serde(rename = "picUrl")]
109 pub pic_url: Option<String>,
110}
111
112impl From<MessageContentLink> for MessageContent {
113 fn from(value: MessageContentLink) -> Self {
114 Self::Link { link: value }
115 }
116}