This repository has been archived by the owner on Jun 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
loaferui.go
382 lines (358 loc) · 12.1 KB
/
loaferui.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
package loafer
// MakeSlackButton - Make a slack button
func MakeSlackButton(text string, value string, actionID string) SlackBlockButton {
isEmojiSupported := true
return SlackBlockButton{
Type: "button",
Text: &SlackBlockText{
Type: "plain_text",
Text: text,
Emoji: &isEmojiSupported},
Value: value,
ActionID: actionID,
}
}
// MakeSlackTextSection - Make a text section (markdown)
func MakeSlackTextSection(text string) SlackBlockSection {
return SlackBlockSection{
Type: "section",
Text: &SlackBlockText{
Type: "mrkdwn",
Text: text}}
}
// MakeSlackTextFieldsSection - Make a text section (markdown)
func MakeSlackTextFieldsSection(texts []string) SlackBlockTextFields {
textFields := []SlackBlockText{}
for _, t := range texts {
textFields = append(textFields, SlackBlockText{Type: "mrkdwn", Text: t})
}
return SlackBlockTextFields{
Type: "section",
Fields: textFields}
}
// MakeSlackModal - Make a slack button
func MakeSlackModal(title string, callbackID string, blocks ISlackBlockKitUI, submitText string, closeText string, notifyOnClose bool) SlackModal {
return SlackModal{
Type: "modal",
Title: &SlackBlockText{
Type: "plain_text",
Text: title},
Submit: &SlackBlockText{
Type: "plain_text",
Text: submitText},
Close: &SlackBlockText{
Type: "plain_text",
Text: closeText},
Blocks: blocks,
CallbackID: callbackID,
NotifyOnClose: notifyOnClose}
}
// MakeSlackActions - Make slack actions
func MakeSlackActions(actions ISlackBlockKitUI) SlackBlockActions {
return SlackBlockActions{
Type: "actions",
Elements: actions}
}
// MakeSlackModalTextInput - Make slack modal input field
func MakeSlackModalTextInput(label string, placeholder string, actionID string, isMultiline bool, isDispatch bool, maxLength uint16) SlackInputElement {
isEmojiSupported := true
return SlackInputElement{
Type: "input",
BlockID: actionID,
IsDispatchAction: isDispatch,
Element: &SlackBlockAccessory{
Type: "plain_text_input",
IsMultiline: isMultiline,
MaxLength: maxLength,
Placeholder: &SlackBlockText{
Type: "plain_text",
Text: placeholder},
ActionID: actionID},
Label: &SlackBlockText{Type: "plain_text", Text: label, Emoji: &isEmojiSupported}}
}
// MakeSlackModalStaticSelectInput - Make slack static select input field
func MakeSlackModalStaticSelectInput(label string, placeholder string, options []SlackInputOption, initialOption *SlackInputOption, actionID string, isMulti bool, isOptional bool) SlackModalSelect {
selectType := "static_select"
isEmojiSupported := true
if isMulti {
selectType = "multi_static_select"
}
return SlackModalSelect{
Type: "input",
BlockID: actionID,
Optional: isOptional,
Element: &SlackBlockAccessory{
Type: selectType,
Placeholder: &SlackBlockText{
Type: "plain_text",
Text: placeholder,
Emoji: &isEmojiSupported},
Options: options,
InitialOption: initialOption,
ActionID: actionID},
Label: &SlackBlockText{Type: "plain_text", Text: label, Emoji: &isEmojiSupported}}
}
// MakeSlackModalExternalStaticSelectInput - Make slack external static select input field
func MakeSlackModalExternalStaticSelectInput(label string, placeholder string, initialOption *SlackInputOption, actionID string, isMulti bool, minQueryLength uint16, isOptional bool) SlackModalSelect {
selectType := "external_select"
isEmojiSupported := true
minQueryLen := 1
if minQueryLength > 1 {
minQueryLen = int(minQueryLength)
}
if isMulti {
selectType = "multi_external_select"
}
return SlackModalSelect{
Type: "input",
BlockID: actionID,
Optional: isOptional,
Element: &SlackBlockAccessory{
Type: selectType,
Placeholder: &SlackBlockText{
Type: "plain_text",
Text: placeholder,
Emoji: &isEmojiSupported},
MinQueryLength: uint16(minQueryLen),
InitialOption: initialOption,
ActionID: actionID},
Label: &SlackBlockText{Type: "plain_text", Text: label, Emoji: &isEmojiSupported}}
}
// MakeSlackBlockExternalStaticSelectInput - Make slack external static select input field
func MakeSlackBlockExternalStaticSelectInput(label string, placeholder string, initialOptions []SlackInputOption, actionID string, isMulti bool, minQueryLength uint16) SlackBlockSection {
selectType := "external_select"
isEmojiSupported := true
if isMulti {
selectType = "multi_external_select"
}
view := SlackBlockSection{
Type: "section",
Text: &SlackBlockText{
Type: "mrkdwn",
Text: label},
Accessory: &SlackBlockAccessory{
Type: selectType,
Placeholder: &SlackBlockText{
Type: "plain_text",
Text: placeholder,
Emoji: &isEmojiSupported},
MinQueryLength: minQueryLength,
ActionID: actionID}}
if isMulti {
view.Accessory.InitialOptions = initialOptions
} else if len(initialOptions) > 0 {
view.Accessory.InitialOption = &initialOptions[0]
}
return view
}
// MakeSlackBlockStaticSelectInput - Make slack static select input field
func MakeSlackBlockStaticSelectInput(label string, placeholder string, options []SlackInputOption, initialOptions []SlackInputOption, actionID string, isMulti bool) SlackBlockSection {
selectType := "static_select"
isEmojiSupported := true
if isMulti {
selectType = "multi_static_select"
}
view := SlackBlockSection{
Type: "section",
Text: &SlackBlockText{
Type: "mrkdwn",
Text: label},
Accessory: &SlackBlockAccessory{
Type: selectType,
Placeholder: &SlackBlockText{
Type: "plain_text",
Text: placeholder,
Emoji: &isEmojiSupported},
Options: options,
ActionID: actionID}}
if isMulti {
view.Accessory.InitialOptions = initialOptions
} else if len(initialOptions) > 0 {
view.Accessory.InitialOption = &initialOptions[0]
}
return view
}
// MakeSlackBlockButton - Make a slack button
func MakeSlackBlockButton(label string, text string, value string, actionID string) SlackBlockSection {
isEmojiSupported := true
return SlackBlockSection{
Type: "section",
Text: &SlackBlockText{
Type: "mrkdwn",
Text: label},
Accessory: &SlackBlockAccessory{
Type: "button",
ActionID: actionID,
Value: value,
Text: &SlackBlockText{
Type: "plain_text",
Text: text,
Emoji: &isEmojiSupported}}}
}
// MakeSlackModalMultiConversationSelectInput - Make slack multi convo select input field
func MakeSlackModalMultiConversationSelectInput(label string, placeholder string, initialConversations []string, isOptional bool, actionID string) SlackModalSelect {
isEmojiSupported := true
return SlackModalSelect{
Type: "input",
BlockID: actionID,
Optional: isOptional,
Element: &SlackBlockAccessory{
Type: "multi_conversations_select",
Placeholder: &SlackBlockText{
Type: "plain_text",
Text: placeholder,
Emoji: &isEmojiSupported},
InitialConversations: initialConversations,
ActionID: actionID},
Label: &SlackBlockText{Type: "plain_text", Text: label, Emoji: &isEmojiSupported}}
}
// MakeSlackActionExternalStaticSelectInput - Make slack external static select input field
func MakeSlackActionExternalStaticSelectInput(label string, placeholder string, initialOption *SlackInputOption, actionID string, isMulti bool, minQueryLength uint16) SlackActionSelect {
selectType := "external_select"
isEmojiSupported := true
minQueryLen := 1
if minQueryLength > 1 {
minQueryLen = int(minQueryLength)
}
if isMulti {
selectType = "multi_static_select"
}
return SlackActionSelect{
Type: "section",
BlockID: actionID,
Text: SlackBlockText{
Type: "mrkdwn",
Text: label},
Accessory: SlackBlockAccessory{
Type: selectType,
Placeholder: &SlackBlockText{
Type: "plain_text",
Text: placeholder,
Emoji: &isEmojiSupported},
ActionID: actionID,
MinQueryLength: uint16(minQueryLen),
InitialOption: initialOption}}
}
// MakeSlackModalMultiUserSelectInput - Make slack multi user select input field
func MakeSlackModalMultiUserSelectInput(label string, placeholder string, initialUsers []string, actionID string) SlackModalSelect {
isEmojiSupported := true
return SlackModalSelect{
Type: "input",
BlockID: actionID,
Element: &SlackBlockAccessory{
Type: "multi_users_select",
Placeholder: &SlackBlockText{
Type: "plain_text",
Text: placeholder,
Emoji: &isEmojiSupported},
InitialUsers: initialUsers,
ActionID: actionID},
Label: &SlackBlockText{Type: "plain_text", Text: label, Emoji: &isEmojiSupported}}
}
// MakeSlackModalUserSelectInput - Make slack user select input field
func MakeSlackModalUserSelectInput(label string, placeholder string, initialUser string, actionID string) SlackModalSelect {
isEmojiSupported := true
return SlackModalSelect{
Type: "input",
BlockID: actionID,
Element: &SlackBlockAccessory{
Type: "users_select",
Placeholder: &SlackBlockText{
Type: "plain_text",
Text: placeholder,
Emoji: &isEmojiSupported},
InitialUser: initialUser,
ActionID: actionID},
Label: &SlackBlockText{Type: "plain_text", Text: label, Emoji: &isEmojiSupported}}
}
// MakeSlackModalDatePickerInput - Make slack modal datepicker input field
func MakeSlackModalDatePickerInput(label string, placeholder string, initialDate string, actionID string) SlackInputElement {
isEmojiSupported := true
return SlackInputElement{
Type: "input",
Element: &SlackBlockAccessory{
Type: "datepicker",
InitialDate: initialDate,
Placeholder: &SlackBlockText{
Type: "plain_text",
Text: placeholder,
Emoji: &isEmojiSupported},
ActionID: actionID},
Label: &SlackBlockText{Type: "plain_text", Text: label, Emoji: &isEmojiSupported}}
}
// MakeSlackModalCheckboxesInput - Make slack modal checkboxes input field
func MakeSlackModalCheckboxesInput(label string, placeholder string, options []SlackInputOption, initialOptions []SlackInputOption, actionID string) SlackInputElement {
isEmojiSupported := true
return SlackInputElement{
Type: "input",
Element: &SlackBlockAccessory{
Type: "checkboxes",
Options: options,
InitialOptions: initialOptions,
ActionID: actionID},
Label: &SlackBlockText{Type: "plain_text", Text: label, Emoji: &isEmojiSupported}}
}
// MakeSlackModalRadioInput - Make slack modal Radio input field
func MakeSlackModalRadioInput(label string, placeholder string, options []SlackInputOption, actionID string) SlackInputElement {
isEmojiSupported := true
return SlackInputElement{
Type: "input",
Element: &SlackBlockAccessory{
Type: "radio_buttons",
Options: options,
ActionID: actionID},
Label: &SlackBlockText{Type: "plain_text", Text: label, Emoji: &isEmojiSupported}}
}
// MakeSlackInputOption - Make Slack input option
func MakeSlackInputOption(text string, value string) SlackInputOption {
isEmojiSupported := true
return SlackInputOption{
Text: &SlackBlockText{
Type: "plain_text",
Text: text,
Emoji: &isEmojiSupported},
Value: value}
}
// MakeSlackModalTimePickerInput - Make slack modal time picker input field
func MakeSlackModalTimePickerInput(label string, placeholder string, initialTime string, actionID string) SlackInputElement {
isEmojiSupported := true
return SlackInputElement{
Type: "input",
Element: &SlackBlockAccessory{
Type: "timepicker",
InitialTime: initialTime,
ActionID: actionID},
Label: &SlackBlockText{Type: "plain_text", Text: label, Emoji: &isEmojiSupported}}
}
// MakeSlackHeader - Make a slack header section
func MakeSlackHeader(text string) SlackBlockSection {
return SlackBlockSection{
Type: "header",
Text: &SlackBlockText{
Type: "mrkdwn",
Text: text}}
}
// MakeSlackDivider -Make a slack divider
func MakeSlackDivider() SlackDivider {
return SlackDivider{
Type: "divider"}
}
// MakeSlackContext - Make a slack context
func MakeSlackContext(text string) SlackBlockActions {
return SlackBlockActions{
Type: "context",
Elements: []ISlackBlockKitUI{
SlackBlockText{
Type: "mrkdwn",
Text: text}}}
}
// MakeSlackImage - Make a slack image section
func MakeSlackImage(title string, imageURL string, altText string) SlackBlockAccessory {
return SlackBlockAccessory{
Type: "image",
Title: &SlackBlockText{
Type: "mrkdwn",
Text: title},
ImageURL: imageURL,
AltText: altText}
}