forked from hilaily/larkcard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modules.go
135 lines (115 loc) · 2.69 KB
/
modules.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package larkcard
// Reference:
// https://open.larksuite.com/document/uMzMyEjLzMjMx4yMzITM/uYDOxUjL2gTM14iN4ETN
// https://open.feishu.cn/document/ukTMukTMukTM/uMjNwUjLzYDM14yM2ATN
func NewModContent(content string, isMD ...bool) *MContent {
f := NewObjTextPlain
if len(isMD) > 0 && isMD[0] {
f = NewObjTextMD
}
return NewModContentOrigin(f(content), nil)
}
func NewModContentMulti(contents []string, isMD, isShort bool) *MContent {
f := NewObjTextPlain
if isMD {
f = NewObjTextMD
}
var fields []*OField
for _, v := range contents {
fields = append(fields, &OField{
IsShort: isShort,
Text: f(v),
})
}
return NewModContentOrigin(nil, fields)
}
func NewModContentOrigin(text *OText, fields []*OField) *MContent {
return &MContent{
Tag: "div",
Text: text,
Fields: fields,
Extra: nil,
}
}
func NewModDividerLine() *MDividerLine {
return &MDividerLine{
Tag: "hr",
}
}
func NewModImage(imgKey, alt string) *MImage {
return &MImage{
Tag: "img",
ImgKey: imgKey,
Alt: NewObjTextPlain(alt),
}
}
func NewModInteraction(actions ...IElement) *MInteraction {
return &MInteraction{
Tag: "action",
Actions: actions,
}
}
func NewModNotes(elements []IElement) *MNote {
return &MNote{
Tag: "note",
Elements: elements,
}
}
type MContent struct {
Tag string `json:"tag"`
Text *OText `json:"text,omitempty"`
Fields []*OField `json:"fields,omitempty"`
Extra IElement `json:"extra,omitempty"`
}
func (c *MContent) SetExtra(e IElement) *MContent {
c.Extra = e
return c
}
type MDividerLine struct {
Tag string `json:"tag"`
}
type MImage struct {
Tag string `json:"tag"`
ImgKey string `json:"img_key"`
Alt *OText `json:"alt"`
Title *OText `json:"title,omitempty"`
Mode ImageModeType `json:"mode,omitempty"`
Preview *bool `json:"preview,omitempty"`
}
func (i *MImage) SetTitle(title string) *MImage {
i.Title = NewObjTextPlain(title)
return i
}
func (i *MImage) SetMode(mode ImageModeType) *MImage {
i.Mode = mode
return i
}
func (i *MImage) SetPreview(preview bool) *MImage {
i.Preview = &preview
return i
}
type MInteraction struct {
Tag string `json:"tag"`
Actions []IElement `json:"actions"`
Layout *LayoutType `json:"layout,omitempty"`
}
func (i *MInteraction) SetLayout(layout LayoutType) *MInteraction {
i.Layout = &layout
return i
}
type MNote struct {
Tag string `json:"tag"`
Elements []IElement `json:"elements"`
}
type MMD struct {
Tag string `json:"tag"`
Content string `json:"content"`
Href *OURL `json:"href,omitempty"`
}
func newMODMD(content string, href *OURL) *MMD {
return &MMD{
Tag: "markdown",
Content: content,
Href: href,
}
}