forked from CatchZeng/dingtalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
markdown.go
47 lines (40 loc) · 970 Bytes
/
markdown.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
package dingtalk
import "encoding/json"
// MarkdownMessage markdown message struct
type MarkdownMessage struct {
MsgType MsgType `json:"msgtype"`
Markdown Markdown `json:"markdown"`
At At `json:"at"`
}
// Markdown markdown struct
type Markdown struct {
Title string `json:"title"`
Text string `json:"text"`
}
// ToByte to byte
func (m *MarkdownMessage) ToByte() ([]byte, error) {
m.MsgType = MsgTypeMarkdown
jsonByte, err := json.Marshal(m)
return jsonByte, err
}
// NewMarkdownMessage new message
func NewMarkdownMessage() *MarkdownMessage {
msg := MarkdownMessage{}
return &msg
}
// SetMarkdown set markdown
func (m *MarkdownMessage) SetMarkdown(title string, text string) *MarkdownMessage {
m.Markdown = Markdown{
Title: title,
Text: text,
}
return m
}
// SetAt set at
func (m *MarkdownMessage) SetAt(atMobiles []string, isAtAll bool) *MarkdownMessage {
m.At = At{
AtMobiles: atMobiles,
IsAtAll: isAtAll,
}
return m
}