-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.go
168 lines (143 loc) · 3.47 KB
/
actions.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package go_msteams
type ActionCard struct {
Type string `json:"@type"`
Name string `json:"name"`
Actions []Action `json:"actions"`
Inputs []Input `json:"inputs"`
}
type OpenUriTarget struct {
Uri string `json:"uri"`
Os string `json:"os"`
}
type OpenUri struct {
Type string `json:"@type"`
Name string `json:"name"`
Targets []OpenUriTarget `json:"targets"`
}
type Action interface {
isAction()
}
type Input interface {
isInput()
}
type Header struct {
Name string `json:"name"`
Value string `json:"value"`
}
type HttpPostAction struct {
Type string `json:"@type"`
Name string `json:"name"`
Target string `json:"target"`
Body string `json:"body"`
Headers []Header `json:"headers"`
}
type TextInput struct {
Type string `json:"@type"`
Id string `json:"id"`
Title string `json:"title"`
IsMultiline bool `json:"isMultiline"`
MaxLength int `json:"maxLength"`
}
type DateInput struct {
Type string `json:"@type"`
Id string `json:"id"`
Title string `json:"title"`
IncludeTime bool `json:"includeTime"`
}
type MultilineChoice struct {
Display string `json:"display"`
Value string `json:"value"`
}
type MultilineInput struct {
Type string `json:"@type"`
Id string `json:"id"`
Title string `json:"title"`
Choices []MultilineChoice `json:"choices"`
IsMultiSelect bool `json:"isMultiSelect"`
Style string `json:"style"`
}
type Button interface {
isButton()
}
func (h HttpPostAction) isAction(){}
func (h HttpPostAction) isButton(){}
func (h *HttpPostAction) AddHeader(name string, value string){
h.Headers = append(h.Headers, Header{Value: value, Name: name})
}
func (tp TextInput) isInput(){}
func (tp DateInput) isInput(){}
func (tp MultilineInput) isInput(){}
func (tp *MultilineInput) addChoice(display string, value string){
tp.Choices = append(tp.Choices, MultilineChoice{
Display: display,
Value: value,
})
}
func (a ActionCard) isButton() {}
func (o OpenUri) isButton() {}
func (o OpenUri) isAction() {}
func NewHTTPPostAction(name string,target string, body string) HttpPostAction {
return HttpPostAction{
Type: "HttpPOST",
Name: name,
Target: target,
Body: body,
}
}
func NewTextInput(id string, title string, isMultiline bool, maxLength int) TextInput{
return TextInput{
Type: "TextInput",
Id: id,
Title: title,
IsMultiline: isMultiline,
MaxLength: maxLength,
}
}
func NewDateInput(id string, title string, includeTime bool ) DateInput {
return DateInput{
Type: "DateInput",
Id: id,
Title: title,
IncludeTime: includeTime,
}
}
func NewMultilineInput(id string, title string, isMultiSelect bool) MultilineInput {
return MultilineInput{
Type: "MultichoiceInput",
Id: id,
Title: title,
Choices: []MultilineChoice{},
IsMultiSelect: isMultiSelect,
Style: "",
}
}
func NewActionCard(name string) ActionCard {
return ActionCard{
Type: "ActionCard",
Name: name,
Actions: []Action{},
Inputs: []Input{},
}
}
func (b *ActionCard) AddAction(action Action) {
b.Actions = append(b.Actions, action)
}
func (b *ActionCard) AddInput(input Input) {
b.Inputs = append(b.Inputs, input)
}
func (o *OpenUri) AddTarget(target OpenUriTarget) {
o.Targets = append(o.Targets, target)
}
func NewOpenUri(name string) OpenUri {
return OpenUri{
Type: "OpenUri",
Name: name,
Targets: []OpenUriTarget{},
}
}
func NewOpenUriTarget(uri string, os string) OpenUriTarget {
return OpenUriTarget{
Uri: uri,
Os: os,
}
}