-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.go
56 lines (46 loc) · 1.08 KB
/
message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package dingtalk
// 钉钉消息
type Message struct {
MsgType string `json:"msgtype"`
Markdown *MessagePartialMarkdown `json:"markdown,omitempty"`
Text *MessagePartialText `json:"text,omitempty"`
At *MessagePartialAt `json:"at,omitempty"`
}
// 钉钉消息AT部分
type MessagePartialAt struct {
AtMobiles []string `json:"atMobiles"`
AtDingtalkIds []string `json:"atDingtalkIds"`
IsAtAll bool `json:"isAtAll"`
}
// 钉钉消息文本部分
type MessagePartialText struct {
Content string `json:"content"`
}
// 钉钉消息Markdown部分
type MessagePartialMarkdown struct {
Title string `json:"title"`
Text string `json:"text"`
}
// 创建一条Markdown消息
func NewMarkdownMessage(title, text string) Message {
partial := &MessagePartialMarkdown{
Text: text,
Title: title,
}
msg := Message{
MsgType: "markdown",
Markdown: partial,
}
return msg
}
// 创建一条文本消息
func NewTextMessage(content string) Message {
partial := &MessagePartialText{
Content: content,
}
msg := Message{
MsgType: "text",
Text: partial,
}
return msg
}