forked from CatchZeng/dingtalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text.go
45 lines (38 loc) · 839 Bytes
/
text.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
package dingtalk
import "encoding/json"
// TextMessage text message struct
type TextMessage struct {
MsgType MsgType `json:"msgtype"`
Text Text `json:"text"`
At At `json:"at"`
}
// Text text struct
type Text struct {
Content string `json:"content"`
}
// ToByte to byte
func (m *TextMessage) ToByte() ([]byte, error) {
m.MsgType = MsgTypeText
jsonByte, err := json.Marshal(m)
return jsonByte, err
}
// NewTextMessage new message
func NewTextMessage() *TextMessage {
msg := TextMessage{}
return &msg
}
// SetContent set content
func (m *TextMessage) SetContent(content string) *TextMessage {
m.Text = Text{
Content: content,
}
return m
}
// SetAt set at
func (m *TextMessage) SetAt(atMobiles []string, isAtAll bool) *TextMessage {
m.At = At{
AtMobiles: atMobiles,
IsAtAll: isAtAll,
}
return m
}