-
Notifications
You must be signed in to change notification settings - Fork 0
/
internal.go
1252 lines (1114 loc) · 31.8 KB
/
internal.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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package feishu
// PostTagType 标签
type PostTagType string
const (
// TextPostTagType text
TextPostTagType PostTagType = "text"
// APostTagType a
APostTagType PostTagType = "a"
// AtPostTagType at
AtPostTagType PostTagType = "at"
// ImgPostTagType img
ImgPostTagType PostTagType = "img"
)
// PostTag 标签
type PostTag interface {
// ToPostTagMessage for JSON serialization
ToPostTagMessage() map[string]interface{}
}
// TextTag 文本标签
type TextTag struct {
// Text 文本内容
Text string
// UnEscape 表示是不是 unescape 解码,默认为 false ,不用可以不填
UnEscape bool
}
// NewTextTag create TextTag
func NewTextTag(text string) *TextTag {
return &TextTag{
Text: text,
}
}
// SetUnEscape set TextTag UnEscape
func (tag *TextTag) SetUnEscape(unEscape bool) *TextTag {
tag.UnEscape = unEscape
return tag
}
func (tag *TextTag) ToPostTagMessage() map[string]interface{} {
msg := map[string]interface{}{}
msg["tag"] = TextPostTagType
msg["text"] = tag.Text
msg["un_escape"] = tag.UnEscape
return msg
}
// ATag a链接标签
type ATag struct {
// Text 文本内容
Text string
// Href 默认的链接地址
Href string
}
// NewATag create ATag
func NewATag(text, href string) *ATag {
return &ATag{
text,
href,
}
}
func (tag *ATag) ToPostTagMessage() map[string]interface{} {
msg := map[string]interface{}{}
msg["tag"] = APostTagType
msg["text"] = tag.Text
msg["href"] = tag.Href
return msg
}
// AtTag at标签
type AtTag struct {
// UserId open_id,union_id或user_id
UserId string
// UserName 用户姓名
UserName string
}
// NewAtAllAtTag create at_all AtTag
func NewAtAllAtTag() *AtTag {
return &AtTag{
UserId: "all",
UserName: "所有人",
}
}
// NewAtTag create AtTag
func NewAtTag(userId string) *AtTag {
return &AtTag{
UserId: userId,
}
}
// SetUserName set UserName
func (tag *AtTag) SetUserName(username string) *AtTag {
tag.UserName = username
return tag
}
func (tag *AtTag) ToPostTagMessage() map[string]interface{} {
msg := map[string]interface{}{}
msg["tag"] = AtPostTagType
msg["user_id"] = tag.UserId
msg["user_name"] = tag.UserName
return msg
}
// ImgTag img tag
type ImgTag struct {
ImageKey string
}
// NewImgTag create ImgTag
func NewImgTag(imgKey string) *ImgTag {
return &ImgTag{
imgKey,
}
}
func (tag *ImgTag) ToPostTagMessage() map[string]interface{} {
return map[string]interface{}{
"tag": ImgPostTagType,
"image_key": tag.ImageKey,
}
}
// PostTags post tag list
type PostTags struct {
// PostTags post tag
PostTags []PostTag
}
// NewPostTags create PostTags
func NewPostTags(tags ...PostTag) *PostTags {
return &PostTags{
PostTags: tags,
}
}
// AddTags add post PostTag
func (tag *PostTags) AddTags(tags ...PostTag) *PostTags {
tag.PostTags = append(tag.PostTags, tags...)
return tag
}
// ToMessageMap to array message map
func (tag *PostTags) ToMessageMap() []map[string]interface{} {
var postTags []map[string]interface{}
for _, tags := range tag.PostTags {
postTags = append(postTags, tags.ToPostTagMessage())
}
return postTags
}
// PostItems 富文本 段落
type PostItems struct {
// Title 标题
Title string
// Content 段落
Content []*PostTags
}
// NewPostItems create PostItems
func NewPostItems(title string, content ...*PostTags) *PostItems {
return &PostItems{
Title: title,
Content: content,
}
}
// AddContent add PostItems Content
func (items *PostItems) AddContent(content ...*PostTags) *PostItems {
items.Content = append(items.Content, content...)
return items
}
func (items *PostItems) ToMessageMap() map[string]interface{} {
var contentList [][]map[string]interface{}
for _, content := range items.Content {
contentList = append(contentList, content.ToMessageMap())
}
msg := map[string]interface{}{}
msg["title"] = items.Title
msg["content"] = contentList
return msg
}
// LangPostItem language post item
type LangPostItem struct {
// Lang language
Lang string
// Item PostItems
Item *PostItems
}
// NewZhCnLangPostItem create zh_cn language post item
func NewZhCnLangPostItem(item *PostItems) *LangPostItem {
return NewLangPostItem("zh_cn", item)
}
// NewLangPostItem create LangPostItem
func NewLangPostItem(lang string, item *PostItems) *LangPostItem {
return &LangPostItem{
lang,
item,
}
}
func (post *LangPostItem) ToMessageMap() map[string]interface{} {
return map[string]interface{}{
post.Lang: post.Item.ToMessageMap(),
}
}
// CardInternal card message internal
type CardInternal interface {
// ToMessage to message map
ToMessage() map[string]interface{}
}
// CardConfig 卡片属性
type CardConfig struct {
// EnableForward 是否允许卡片被转发,默认 true
EnableForward bool
// UpdateMulti 是否为共享卡片,默认为false
UpdateMulti bool
// WideScreenMode 是否根据屏幕宽度动态调整消息卡片宽度,默认值为true
//
// 2021/03/22之后,此字段废弃,所有卡片均升级为自适应屏幕宽度的宽版卡片
WideScreenMode bool
}
// NewCardConfig create CardConfig
func NewCardConfig() *CardConfig {
return &CardConfig{
EnableForward: true,
UpdateMulti: true,
WideScreenMode: true,
}
}
// SetEnableForward set EnableForward
func (config *CardConfig) SetEnableForward(enableForward bool) *CardConfig {
config.EnableForward = enableForward
return config
}
// SetUpdateMulti set UpdateMulti
func (config *CardConfig) SetUpdateMulti(updateMulti bool) *CardConfig {
config.UpdateMulti = updateMulti
return config
}
// SetWideScreenMode set WideScreenMode
func (config *CardConfig) SetWideScreenMode(wideScreenMode bool) *CardConfig {
config.WideScreenMode = wideScreenMode
return config
}
func (config *CardConfig) ToMessage() map[string]interface{} {
return map[string]interface{}{
"wide_screen_mode": config.WideScreenMode,
"enable_forward": config.EnableForward,
"update_multi": config.UpdateMulti,
}
}
// CardTitle 标题
type CardTitle struct {
// Content 内容
Content string
// I18n i18n替换content
//
// "i18n": {
// "zh_cn": "中文文本",
// "en_us": "English text",
// "ja_jp": "日本語文案"
// }
I18n map[string]string
}
// NewCardTitle create CardTitle
func NewCardTitle(content string, i18n map[string]string) *CardTitle {
return &CardTitle{
Content: content,
I18n: i18n,
}
}
// SetI18n set I18n
func (title *CardTitle) SetI18n(i18n map[string]string) *CardTitle {
title.I18n = i18n
return title
}
func (title *CardTitle) ToMessage() map[string]interface{} {
return map[string]interface{}{
"content": title.Content,
"i18n": title.I18n,
"tag": "plain_text",
}
}
// CardHeaderTemplate CardHeader.Template
type CardHeaderTemplate string
const (
// Blue CardHeader.Template blue
Blue CardHeaderTemplate = "blue"
// Wathet CardHeader.Template wathet
Wathet CardHeaderTemplate = "wathet"
// Turquoise CardHeader.Template turquoise
Turquoise CardHeaderTemplate = "turquoise"
// Green CardHeader.Template green
Green CardHeaderTemplate = "green"
// Yellow CardHeader.Template yellow
Yellow CardHeaderTemplate = "yellow"
// Orange CardHeader.Template orange
Orange CardHeaderTemplate = "orange"
// Red CardHeader.Template red
Red CardHeaderTemplate = "red"
// Carmine CardHeader.Template carmine
Carmine CardHeaderTemplate = "carmine"
// Violet CardHeader.Template violet
Violet CardHeaderTemplate = "violet"
// Purple CardHeader.Template purple
Purple CardHeaderTemplate = "purple"
// Indigo CardHeader.Template indigo
Indigo CardHeaderTemplate = "indigo"
// Grey CardHeader.Template grey
Grey CardHeaderTemplate = "grey"
)
// CardHeader 卡片标题
type CardHeader struct {
Title *CardTitle
Template CardHeaderTemplate
}
// NewCardHeader create CardHeader
func NewCardHeader(title *CardTitle) *CardHeader {
return &CardHeader{
Title: title,
}
}
// SetTemplate set Template
func (header *CardHeader) SetTemplate(template CardHeaderTemplate) *CardHeader {
header.Template = template
return header
}
func (header *CardHeader) ToMessage() map[string]interface{} {
return map[string]interface{}{
"title": header.Title.ToMessage(),
"template": header.Template,
}
}
// CardContent 卡片内容
type CardContent interface {
CardInternal
// GetContentTag 卡片内容 tag标签
GetContentTag() string
}
// CardElement 内容模块
type CardElement struct {
// Text 单个文本展示,和fields至少要有一个
Text *CardText
// Fields 多个文本展示,和text至少要有一个
Fields []*CardField
// Extra 附加的元素展示在文本内容右侧
//
// 可附加的元素包括image、button、selectMenu、overflow、datePicker
Extra CardInternal
}
// NewCardElement create CardElement
func NewCardElement(text *CardText, fields ...*CardField) *CardElement {
return &CardElement{
Text: text,
Fields: fields,
}
}
// AddFields add CardElement.Fields
func (card *CardElement) AddFields(field ...*CardField) *CardElement {
card.Fields = append(card.Fields, field...)
return card
}
// SetExtra set CardElement.Extra
func (card *CardElement) SetExtra(extra CardInternal) *CardElement {
card.Extra = extra
return card
}
func (card *CardElement) GetContentTag() string {
return "div"
}
func (card *CardElement) ToMessage() map[string]interface{} {
msg := map[string]interface{}{}
var fields []map[string]interface{}
for _, field := range card.Fields {
fields = append(fields, field.ToMessage())
}
msg["tag"] = card.GetContentTag()
if card.Text != nil {
msg["text"] = card.Text.ToMessage()
}
msg["fields"] = fields
if card.Extra != nil {
msg["extra"] = card.Extra.ToMessage()
}
return msg
}
// CardMarkdown Markdown模块
type CardMarkdown struct {
// Content 使用已支持的markdown语法构造markdown内容
Content string
// Href 差异化跳转
Href *UrlElement
// UrlVal 绑定变量
UrlVal string
}
// NewCardMarkdown create CardMarkdown
func NewCardMarkdown(content string) *CardMarkdown {
return &CardMarkdown{
Content: content,
}
}
// SetHref set CardMarkdown.Href
func (card *CardMarkdown) SetHref(url *UrlElement) *CardMarkdown {
card.Href = url
return card
}
func (card *CardMarkdown) GetContentTag() string {
return "markdown"
}
func (card *CardMarkdown) ToMessage() map[string]interface{} {
msg := map[string]interface{}{}
msg["tag"] = card.GetContentTag()
msg["content"] = card.Content
if card.Href != nil {
href := map[string]map[string]interface{}{
card.UrlVal: card.Href.ToMessage(),
}
msg["href"] = href
}
return msg
}
// CardHr 分割线模块
type CardHr struct {
}
// NewCardHr create CardHr
func NewCardHr() *CardHr {
return &CardHr{}
}
func (hr *CardHr) GetContentTag() string {
return "hr"
}
func (hr *CardHr) ToMessage() map[string]interface{} {
return map[string]interface{}{
"tag": hr.GetContentTag(),
}
}
// CardImgMode CardImg.Mode
type CardImgMode string
const (
// FitHorizontal 平铺模式,宽度撑满卡片完整展示上传的图片。 该属性会覆盖
FitHorizontal CardImgMode = "fit_horizontal"
// CropCenter 居中裁剪模式,对长图会限高,并居中裁剪后展示
CropCenter CardImgMode = "crop_center"
)
// CardImg 图片模块
type CardImg struct {
// ImgKey 图片资源
ImgKey string
// Alt hover图片时弹出的Tips文案,content取值为空时则不展示
Alt *CardText
// Title 图片标题
Title *CardText
// CustomWidth 自定义图片的最大展示宽度
CustomWidth int
// CompactWidth 是否展示为紧凑型的图片 默认为false
CompactWidth bool
// Mode 图片显示模式 默认 crop_center
Mode CardImgMode
// Preview 点击后是否放大图片,缺省为true
Preview bool
}
// NewCardImg create CardImg
func NewCardImg(ImgKey string, Alt *CardText) *CardImg {
return &CardImg{
ImgKey: ImgKey,
Alt: Alt,
CompactWidth: false,
Mode: CropCenter,
Preview: true,
}
}
// SetTitle set CardImg.Title
func (img *CardImg) SetTitle(title *CardText) *CardImg {
img.Title = title
return img
}
// SetCustomWidth set CardImg.CustomWidth
func (img *CardImg) SetCustomWidth(customWidth int) *CardImg {
img.CustomWidth = customWidth
return img
}
// SetCompactWidth set CardImg.CompactWidth
func (img *CardImg) SetCompactWidth(compactWidth bool) *CardImg {
img.CompactWidth = compactWidth
return img
}
// SetMode set CardImg.Mode
func (img *CardImg) SetMode(mode CardImgMode) *CardImg {
img.Mode = mode
return img
}
// SetPreview set CardImg.Preview
func (img *CardImg) SetPreview(preview bool) *CardImg {
img.Preview = preview
return img
}
func (img *CardImg) GetContentTag() string {
return "img"
}
func (img *CardImg) ToMessage() map[string]interface{} {
msg := map[string]interface{}{}
msg["tag"] = img.GetContentTag()
msg["img_key"] = img.ImgKey
msg["alt"] = img.Alt.ToMessage()
if img.Title != nil {
msg["title"] = img.Title.ToMessage()
}
if img.CustomWidth != 0 {
msg["custom_width"] = img.CustomWidth
}
msg["compact_width"] = img.CompactWidth
msg["mode"] = img.Mode
msg["preview"] = img.Preview
return msg
}
// CardNote 备注模块,用于展示次要信息
//
// 使用备注模块来展示用于辅助说明或备注的次要信息,支持小尺寸的图片和文本
type CardNote struct {
// Elements 备注信息 text对象或image元素
Elements []CardInternal
}
// NewCardNote create CardNote
func NewCardNote(elements ...CardInternal) *CardNote {
return &CardNote{
Elements: elements,
}
}
// AddElements add CardNote.Elements
func (note *CardNote) AddElements(elements ...CardInternal) *CardNote {
note.Elements = append(note.Elements, elements...)
return note
}
func (note *CardNote) GetContentTag() string {
return "note"
}
func (note *CardNote) ToMessage() map[string]interface{} {
msg := map[string]interface{}{}
var eles []map[string]interface{}
for _, ele := range note.Elements {
eles = append(eles, ele.ToMessage())
}
msg["tag"] = note.GetContentTag()
msg["elements"] = eles
return msg
}
// CardField 用于内容模块的field字段
type CardField struct {
// Short 是否并排布局
Short bool
// Text 国际化文本内容
Text *CardText
}
// NewCardField create CardField
func NewCardField(short bool, text *CardText) *CardField {
return &CardField{
short,
text,
}
}
func (field *CardField) ToMessage() map[string]interface{} {
return map[string]interface{}{
"is_short": field.Short,
"text": field.Text.ToMessage(),
}
}
// CardTextTag 卡片内容-可内嵌的非交互元素-text-tag属性
type CardTextTag string
const (
// Text 文本
Text CardTextTag = "plain_text"
// Md markdown
Md CardTextTag = "lark_md"
)
// CardText 卡片内容-可内嵌的非交互元素-text
type CardText struct {
// Tag 元素标签
Tag CardTextTag
// Content 文本内容
Content string
// Lines 内容显示行数
Lines int
}
// NewCardText create CardText
func NewCardText(tag CardTextTag, content string) *CardText {
return &CardText{
Tag: tag,
Content: content,
}
}
// SetLines set CardText Lines
func (text *CardText) SetLines(lines int) *CardText {
text.Lines = lines
return text
}
func (text *CardText) ToMessage() map[string]interface{} {
return map[string]interface{}{
"tag": text.Tag,
"content": text.Content,
"lines": text.Lines,
}
}
// CardImage 作为图片元素被使用
// 可用于内容块的extra字段和备注块的elements字段。
type CardImage struct {
// ImageKey 图片资源
ImageKey string
// Alt 图片hover说明
Alt *CardText
// Preview 点击后是否放大图片,缺省为true
Preview bool
}
// NewCardImage create CardImage
func NewCardImage(imageKye string, alt *CardText) *CardImage {
return &CardImage{
ImageKey: imageKye,
Alt: alt,
Preview: true,
}
}
// SetPreview set Preview
func (image *CardImage) SetPreview(preview bool) *CardImage {
image.Preview = preview
return image
}
func (image *CardImage) GetContentTag() string {
return "img"
}
func (image *CardImage) ToMessage() map[string]interface{} {
return map[string]interface{}{
"tag": image.GetContentTag(),
"img_key": image.ImageKey,
"alt": image.Alt.ToMessage(),
"preview": image.Preview,
}
}
// LayoutAction 交互元素布局
type LayoutAction string
const (
// Bisected 二等分布局,每行两列交互元素
Bisected LayoutAction = "bisected"
// Trisection 三等分布局,每行三列交互元素
Trisection LayoutAction = "trisection"
// Flow 流式布局元素会按自身大小横向排列并在空间不够的时候折行
Flow LayoutAction = "flow"
)
// CardAction 交互模块
type CardAction struct {
// Actions 交互元素
Actions []ActionElement
// Layout 交互元素布局
Layout LayoutAction
}
// NewCardAction create CardAction
func NewCardAction(actions ...ActionElement) *CardAction {
return &CardAction{
Actions: actions,
}
}
// AddAction add CardAction.Actions
func (action *CardAction) AddAction(actions ...ActionElement) *CardAction {
action.Actions = append(action.Actions, actions...)
return action
}
// SetLayout set CardAction.Layout
func (action *CardAction) SetLayout(layout LayoutAction) *CardAction {
action.Layout = layout
return action
}
func (action *CardAction) GetContentTag() string {
return "action"
}
func (action *CardAction) ToMessage() map[string]interface{} {
msg := map[string]interface{}{}
var actions []map[string]interface{}
for _, a := range action.Actions {
actions = append(actions, a.ToMessage())
}
msg["tag"] = action.GetContentTag()
msg["actions"] = actions
msg["layout"] = action.Layout
return msg
}
// ActionElement 交互元素
type ActionElement interface {
CardInternal
// GetActionTag ActionElement tag
GetActionTag() string
}
// DatePickerTag DatePickerActionElement.Tag
type DatePickerTag string
const (
// DatePicker 日期
DatePicker DatePickerTag = "date_picker"
// PickerTime 时间
PickerTime DatePickerTag = "picker_time"
// PickerDatetime 日期+时间
PickerDatetime DatePickerTag = "picker_datetime"
)
// DatePickerActionElement 提供时间选择的功能
//
// 可用于内容块的extra字段和交互块的actions字段。
type DatePickerActionElement struct {
// Tag tag
Tag DatePickerTag
// InitialDate 日期模式的初始值 格式"yyyy-MM-dd"
InitialDate string
// InitialTime 时间模式的初始值 格式"HH:mm"
InitialTime string
// InitialDatetime 日期时间模式的初始值 格式"yyyy-MM-dd HH:mm"
InitialDatetime string
// Placeholder 占位符,无初始值时必填
Placeholder *CardText
// Value 用户选定后返回业务方的数据 JSON
Value map[string]interface{}
// Confirm 二次确认的弹框
Confirm *ConfirmElement
}
// NewDatePickerActionElement create DatePickerActionElement
func NewDatePickerActionElement(tag DatePickerTag) *DatePickerActionElement {
return &DatePickerActionElement{Tag: tag}
}
// SetInitialDate set DatePickerActionElement.InitialDate
func (datePicker *DatePickerActionElement) SetInitialDate(initialDate string) *DatePickerActionElement {
datePicker.InitialDate = initialDate
return datePicker
}
// SetInitialTime set DatePickerActionElement.InitialTime
func (datePicker *DatePickerActionElement) SetInitialTime(initialTime string) *DatePickerActionElement {
datePicker.InitialTime = initialTime
return datePicker
}
// SetInitialDatetime set DatePickerActionElement.InitialDatetime
func (datePicker *DatePickerActionElement) SetInitialDatetime(initialDatetime string) *DatePickerActionElement {
datePicker.InitialDatetime = initialDatetime
return datePicker
}
// SetPlaceholder set DatePickerActionElement.Placeholder
func (datePicker *DatePickerActionElement) SetPlaceholder(placeholder *CardText) *DatePickerActionElement {
datePicker.Placeholder = placeholder
return datePicker
}
// SetValue set DatePickerActionElement.Value
func (datePicker *DatePickerActionElement) SetValue(value map[string]interface{}) *DatePickerActionElement {
datePicker.Value = value
return datePicker
}
// SetConfirm set DatePickerActionElement.Confirm
func (datePicker *DatePickerActionElement) SetConfirm(confirm *ConfirmElement) *DatePickerActionElement {
datePicker.Confirm = confirm
return datePicker
}
func (datePicker *DatePickerActionElement) GetActionTag() string {
return string(datePicker.Tag)
}
func (datePicker *DatePickerActionElement) ToMessage() map[string]interface{} {
msg := map[string]interface{}{}
msg["tag"] = datePicker.Tag
if len(datePicker.InitialDate) > 0 {
msg["initial_date"] = datePicker.InitialDate
}
if len(datePicker.InitialTime) > 0 {
msg["initial_time"] = datePicker.InitialTime
}
if len(datePicker.InitialDatetime) > 0 {
msg["initial_datetime"] = datePicker.InitialDatetime
}
if datePicker.Placeholder != nil {
msg["placeholder"] = datePicker.Placeholder.ToMessage()
}
if len(datePicker.Value) > 0 {
msg["value"] = datePicker.Value
}
if datePicker.Confirm != nil {
msg["confirm"] = datePicker.Confirm.ToMessage()
}
return msg
}
// OverflowActionElement 提供折叠的按钮型菜单
//
// overflow属于交互元素的一种,可用于内容块的extra字段和交互块的actions字段。
type OverflowActionElement struct {
// Options 待选选项
Options []*OptionElement
// Value 用户选定后返回业务方的数据
Value map[string]interface{}
// Confirm 二次确认的弹框
Confirm *ConfirmElement
}
// NewOverflowActionElement create OverflowActionElement
func NewOverflowActionElement(options ...*OptionElement) *OverflowActionElement {
return &OverflowActionElement{
Options: options,
}
}
// AddOptions add OverflowActionElement.Options
func (overflow *OverflowActionElement) AddOptions(options ...*OptionElement) *OverflowActionElement {
overflow.Options = append(overflow.Options, options...)
return overflow
}
// SetValue set OverflowActionElement.Value
func (overflow *OverflowActionElement) SetValue(value map[string]interface{}) *OverflowActionElement {
overflow.Value = value
return overflow
}
// SetConfirm set OverflowActionElement.Confirm
func (overflow *OverflowActionElement) SetConfirm(confirm *ConfirmElement) *OverflowActionElement {
overflow.Confirm = confirm
return overflow
}
func (overflow *OverflowActionElement) GetActionTag() string {
return "overflow"
}
func (overflow *OverflowActionElement) ToMessage() map[string]interface{} {
msg := map[string]interface{}{}
msg["tag"] = overflow.GetActionTag()
var options []map[string]interface{}
for _, option := range overflow.Options {
options = append(options, option.ToMessage())
}
msg["options"] = options
if len(overflow.Value) > 0 {
msg["value"] = overflow.Value
}
if overflow.Confirm != nil {
msg["confirm"] = overflow.Confirm.ToMessage()
}
return msg
}
// SelectMenuTag SelectMenuActionElement tag
type SelectMenuTag string
const (
// SelectStatic SelectMenuActionElement select_static tag 选项模式
SelectStatic SelectMenuTag = "select_static"
// SelectPerson SelectMenuActionElement select_person tag 选人模式
SelectPerson SelectMenuTag = "select_person"
)
// SelectMenuActionElement 作为selectMenu元素被使用,提供选项菜单的功能
type SelectMenuActionElement struct {
// Tag tag
Tag SelectMenuTag
// Placeholder 占位符,无默认选项时必须有
Placeholder *CardText
// InitialOption 默认选项的value字段值。select_person模式下不支持此配置。
InitialOption string
// Options 待选选项
Options []*OptionElement
// Value 用户选定后返回业务方的数据 key-value形式的json结构,且key为String类型
Value map[string]interface{}
// Confirm 二次确认的弹框
Confirm *ConfirmElement
}
// NewSelectMenuActionElement create SelectMenuActionElement
func NewSelectMenuActionElement(tag SelectMenuTag) *SelectMenuActionElement {
return &SelectMenuActionElement{
Tag: tag,
Options: []*OptionElement{},
}
}
// SetPlaceholder set SelectMenuActionElement.Placeholder
func (selectMenu *SelectMenuActionElement) SetPlaceholder(placeholder *CardText) *SelectMenuActionElement {
selectMenu.Placeholder = placeholder
return selectMenu
}
// SetInitialOption set SelectMenuActionElement.InitialOption
func (selectMenu *SelectMenuActionElement) SetInitialOption(initialOption string) *SelectMenuActionElement {
selectMenu.InitialOption = initialOption
return selectMenu
}
// SetOptions set SelectMenuActionElement.Options
func (selectMenu *SelectMenuActionElement) SetOptions(options ...*OptionElement) *SelectMenuActionElement {
selectMenu.Options = options
return selectMenu
}
// AddOptions add SelectMenuActionElement.Options
func (selectMenu *SelectMenuActionElement) AddOptions(options ...*OptionElement) *SelectMenuActionElement {
selectMenu.Options = append(selectMenu.Options, options...)
return selectMenu
}
// SetValue set SelectMenuActionElement.Value
func (selectMenu *SelectMenuActionElement) SetValue(value map[string]interface{}) *SelectMenuActionElement {
selectMenu.Value = value
return selectMenu
}
// SetConfirm set SelectMenuActionElement.Confirm
func (selectMenu *SelectMenuActionElement) SetConfirm(confirm *ConfirmElement) *SelectMenuActionElement {
selectMenu.Confirm = confirm
return selectMenu
}
func (selectMenu *SelectMenuActionElement) GetActionTag() string {
return string(selectMenu.Tag)
}
func (selectMenu *SelectMenuActionElement) ToMessage() map[string]interface{} {
msg := map[string]interface{}{}
msg["tag"] = selectMenu.Tag
if selectMenu.Placeholder != nil {
msg["placeholder"] = selectMenu.Placeholder.ToMessage()
}
msg["initial_option"] = selectMenu.InitialOption
if len(selectMenu.Options) > 0 {
var options []map[string]interface{}
for _, option := range selectMenu.Options {
options = append(options, option.ToMessage())
}
msg["options"] = options
}