-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathFeishuHelpCardBuilder.cs
More file actions
1122 lines (1061 loc) · 39.5 KB
/
FeishuHelpCardBuilder.cs
File metadata and controls
1122 lines (1061 loc) · 39.5 KB
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
using System.Text.Json;
using FeishuNetSdk.CallbackEvents;
using FeishuNetSdk.Extensions;
using FeishuNetSdk.Im.Dtos;
using WebCodeCli.Domain.Domain.Model.Channels;
namespace WebCodeCli.Domain.Domain.Service.Channels;
/// <summary>
/// 飞书帮助卡片构建器
/// 构建各类帮助卡片的JSON
/// </summary>
public class FeishuHelpCardBuilder
{
// ========== 新的实现:使用 ElementsCardV2Dto 和 SetCard 扩展方法 ==========
/// <summary>
/// 构建命令选择卡片(卡片1)- 使用 ElementsCardV2Dto
/// </summary>
public ElementsCardV2Dto BuildCommandListCardV2(List<FeishuCommandCategory> categories, bool showRefreshButton = true)
{
var elements = new List<object>();
// 顶部操作按钮组
if (showRefreshButton)
{
elements.Add(new
{
tag = "column_set",
flex_mode = "none",
background_style = "default",
columns = new[]
{
new
{
tag = "column",
width = "weighted",
weight = 1,
vertical_align = "top",
elements = new[]
{
new
{
tag = "button",
text = new { tag = "plain_text", content = "🔄 更新命令列表" },
type = "default",
behaviors = new[]
{
new
{
type = "callback",
value = new { action = "refresh_commands" }
}
}
}
}
},
new
{
tag = "column",
width = "weighted",
weight = 1,
vertical_align = "top",
elements = new[]
{
new
{
tag = "button",
text = new { tag = "plain_text", content = "📋 会话管理" },
type = "primary",
behaviors = new[]
{
new
{
type = "callback",
value = new { action = "open_session_manager" }
}
}
}
}
}
}
});
}
// 每个分组显示为分类按钮,避免首页元素超限
foreach (var category in categories)
{
if (category.Commands.Count == 0)
continue;
elements.Add(BuildCategoryActionRow(category));
}
return new ElementsCardV2Dto
{
Header = new ElementsCardV2Dto.HeaderSuffix
{
Template = "blue",
Title = new HeaderTitleElement { Content = "🤖 当前 CLI 命令帮助" }
},
Config = new ElementsCardV2Dto.ConfigSuffix
{
EnableForward = true,
UpdateMulti = true
},
Body = new ElementsCardV2Dto.BodySuffix
{
Elements = elements.ToArray()
}
};
}
/// <summary>
/// 构建过滤后的搜索卡片 - 使用 ElementsCardV2Dto
/// </summary>
public ElementsCardV2Dto BuildFilteredCardV2(List<FeishuCommandCategory> categories, string keyword)
{
var elements = new List<object>
{
new
{
tag = "div",
text = new
{
tag = "lark_md",
content = $"🔍 搜索结果:**{keyword}**\n\n点击下方按钮返回完整列表"
}
},
new
{
tag = "column_set",
flex_mode = "none",
background_style = "default",
columns = new[]
{
new
{
tag = "column",
width = "weighted",
weight = 1,
vertical_align = "top",
elements = new[]
{
new
{
tag = "button",
text = new { tag = "plain_text", content = "📋 显示全部命令" },
type = "default",
behaviors = new[]
{
new
{
type = "callback",
value = new { action = "back_to_list" }
}
}
}
}
}
}
},
new { tag = "hr" }
};
var allCommands = categories.SelectMany(c => c.Commands).ToList();
if (allCommands.Count > 0)
{
elements.Add(new
{
tag = "div",
text = new { tag = "lark_md", content = $"**找到 {allCommands.Count} 个匹配命令:**" }
});
foreach (var command in allCommands)
{
elements.Add(BuildCommandActionRow(command));
}
}
else
{
elements.Add(new
{
tag = "div",
text = new { tag = "lark_md", content = "❌ 未找到匹配的命令,请尝试其他关键词" }
});
}
return new ElementsCardV2Dto
{
Header = new ElementsCardV2Dto.HeaderSuffix
{
Template = "turquoise",
Title = new HeaderTitleElement { Content = "🔍 命令搜索" }
},
Config = new ElementsCardV2Dto.ConfigSuffix
{
EnableForward = true,
UpdateMulti = true
},
Body = new ElementsCardV2Dto.BodySuffix
{
Elements = elements.ToArray()
}
};
}
/// <summary>
/// 构建分类命令卡片(卡片1-2)- 展示某个分类下的命令按钮
/// </summary>
public ElementsCardV2Dto BuildCategoryCommandsCardV2(FeishuCommandCategory category)
{
var elements = new List<object>
{
new
{
tag = "div",
text = new
{
tag = "lark_md",
content = $"**{SanitizeMarkdown(category.Name)}**\n共 {category.Commands.Count} 条命令,点击右侧按钮进入执行卡片"
}
},
new
{
tag = "column_set",
flex_mode = "none",
background_style = "default",
columns = new[]
{
new
{
tag = "column",
width = "weighted",
weight = 1,
vertical_align = "top",
elements = new[]
{
new
{
tag = "button",
text = new { tag = "plain_text", content = "📋 返回分类列表" },
type = "default",
behaviors = new[]
{
new
{
type = "callback",
value = new { action = "back_to_list" }
}
}
}
}
}
}
},
new { tag = "hr" }
};
foreach (var command in category.Commands)
{
elements.Add(BuildCommandActionRow(command));
}
return new ElementsCardV2Dto
{
Header = new ElementsCardV2Dto.HeaderSuffix
{
Template = "blue",
Title = new HeaderTitleElement { Content = $"📁 {category.Name}" }
},
Config = new ElementsCardV2Dto.ConfigSuffix
{
EnableForward = true,
UpdateMulti = true
},
Body = new ElementsCardV2Dto.BodySuffix
{
Elements = elements.ToArray()
}
};
}
/// <summary>
/// 构建执行卡片(卡片2)- 使用 ElementsCardV2Dto
/// </summary>
public ElementsCardV2Dto BuildExecuteCardV2(FeishuCommand command)
{
var elements = new List<object>
{
new DivElement().SetText(new LarkMdElement($"**📝 命令说明:**\n{command.Description}")),
new DivElement().SetText(new LarkMdElement($"**💡 用法示例:**\n`{command.Usage}`")),
new HrElement(),
// 命令输入框
new
{
tag = "input",
input_type = "text",
name = "command_input",
label = new { tag = "plain_text", content = "点编辑后enter发送" },
placeholder = new { tag = "plain_text", content = "编辑命令..." },
default_value = string.IsNullOrWhiteSpace(command.ExecuteText) ? command.Name : command.ExecuteText,
behaviors = new[]
{
new{
type = "callback",
value = new {
// 回传交互数据。支持 object 数据类型。开放平台 SDK 仅支持 object 类型的回传交互数据。
action = "execute_command" // 自定义的请求回调交互参数。
}
}
}
},
new ColumnSetElement
{
FlexMode = "none",
BackgroundStyle = "default",
Columns = new[]
{
new ColumnElement
{
Width = "weighted",
Weight = 1,
VerticalAlign = "top",
Elements = new Element[]
{
new FormButtonElement(
Name: "cancel_btn",
Text: new PlainTextElement("❌ 返回"),
Type: "default",
ActionType: "request")
{
Behaviors = new Behaviors[]
{
new CallbackBehaviors(new { action = "back_to_list" })
}
}
}
}
}
}
};
return new ElementsCardV2Dto
{
Header = new ElementsCardV2Dto.HeaderSuffix
{
Template = "purple",
Title = new HeaderTitleElement { Content = $"⚙️ 执行命令:{command.Name}" }
},
Config = new ElementsCardV2Dto.ConfigSuffix
{
EnableForward = true,
UpdateMulti = true
},
Body = new ElementsCardV2Dto.BodySuffix
{
Elements = elements.ToArray()
}
};
}
public ElementsCardV2Dto BuildBindWebUserCardV2(string[] bindableUsernames)
{
var hint = bindableUsernames.Length > 0
? $"可绑定用户:{string.Join("、", bindableUsernames)}"
: "请联系管理员确认可用的 Web 用户名";
var elements = new List<object>
{
new
{
tag = "div",
text = new
{
tag = "lark_md",
content = $"## 🔐 绑定 Web 用户\n绑定后,飞书将共享 Web 端的会话、项目和工作区。\n\n{hint}"
}
},
new { tag = "hr" },
new
{
tag = "form",
name = "bind_web_user_form",
elements = new object[]
{
new
{
tag = "input",
input_type = "text",
name = "web_username",
label = new { tag = "plain_text", content = "Web 用户名" },
placeholder = new { tag = "plain_text", content = "请输入 Web 用户名" }
},
new
{
tag = "input",
input_type = "password",
name = "web_password",
label = new { tag = "plain_text", content = "Web 密码" },
placeholder = new { tag = "plain_text", content = "请输入 Web 密码" }
},
new
{
tag = "column_set",
flex_mode = "none",
background_style = "default",
horizontal_spacing = "default",
columns = new object[]
{
new
{
tag = "column",
width = "auto",
vertical_align = "top",
elements = new object[]
{
new
{
tag = "button",
text = new { tag = "plain_text", content = "绑定" },
type = "primary",
action_type = "form_submit",
name = "bind_web_user_submit",
value = new { action = "bind_web_user" }
}
}
},
new
{
tag = "column",
width = "auto",
vertical_align = "top",
elements = new object[]
{
new
{
tag = "button",
text = new { tag = "plain_text", content = "取消" },
type = "default",
action_type = "form_reset",
name = "bind_web_user_reset"
}
}
}
}
}
}
}
};
return new ElementsCardV2Dto
{
Header = new ElementsCardV2Dto.HeaderSuffix
{
Template = "blue",
Title = new HeaderTitleElement { Content = "🔐 绑定 Web 用户" }
},
Config = new ElementsCardV2Dto.ConfigSuffix
{
EnableForward = true,
UpdateMulti = true
},
Body = new ElementsCardV2Dto.BodySuffix
{
Elements = elements.ToArray()
}
};
}
public string BuildBindWebUserCard(string[] bindableUsernames)
{
var hint = bindableUsernames.Length > 0
? $"可绑定用户:{string.Join("、", bindableUsernames)}"
: "请联系管理员确认可用的 Web 用户名";
var card = new
{
schema = "2.0",
config = new { enable_forward = true, update_multi = true },
header = new
{
template = "blue",
title = new { tag = "plain_text", content = "🔐 绑定 Web 用户" }
},
body = new
{
elements = new object[]
{
new
{
tag = "div",
text = new
{
tag = "lark_md",
content = $"## 🔐 绑定 Web 用户\n绑定后,飞书将共享 Web 端的会话、项目和工作区。\n\n{hint}"
}
},
new { tag = "hr" },
new
{
tag = "form",
name = "bind_web_user_form",
elements = new object[]
{
new
{
tag = "input",
input_type = "text",
name = "web_username",
label = new { tag = "plain_text", content = "Web 用户名" },
placeholder = new { tag = "plain_text", content = "请输入 Web 用户名" }
},
new
{
tag = "input",
input_type = "password",
name = "web_password",
label = new { tag = "plain_text", content = "Web 密码" },
placeholder = new { tag = "plain_text", content = "请输入 Web 密码" }
},
new
{
tag = "column_set",
flex_mode = "none",
background_style = "default",
horizontal_spacing = "default",
columns = new object[]
{
new
{
tag = "column",
width = "auto",
vertical_align = "top",
elements = new object[]
{
new
{
tag = "button",
text = new { tag = "plain_text", content = "绑定" },
type = "primary",
action_type = "form_submit",
name = "bind_web_user_submit",
value = new { action = "bind_web_user" }
}
}
},
new
{
tag = "column",
width = "auto",
vertical_align = "top",
elements = new object[]
{
new
{
tag = "button",
text = new { tag = "plain_text", content = "取消" },
type = "default",
action_type = "form_reset",
name = "bind_web_user_reset"
}
}
}
}
}
}
}
}
}
};
return JsonSerializer.Serialize(card);
}
/// <summary>
/// 构建SDK类型的卡片响应(用于回调)- 使用 SetCard 扩展方法
/// </summary>
public CardActionTriggerResponseDto BuildCardActionResponseV2(ElementsCardV2Dto card, string toastMessage, string toastType = "info")
{
var response = new CardActionTriggerResponseDto();
if (!string.IsNullOrEmpty(toastMessage))
{
response.Toast = new CardActionTriggerResponseDto.ToastSuffix
{
Content = toastMessage,
Type = toastType switch
{
"success" => CardActionTriggerResponseDto.ToastSuffix.ToastType.Success,
"error" => CardActionTriggerResponseDto.ToastSuffix.ToastType.Error,
"warning" => CardActionTriggerResponseDto.ToastSuffix.ToastType.Warning,
_ => CardActionTriggerResponseDto.ToastSuffix.ToastType.Info
}
};
}
if (card != null)
{
response.SetCard(card);
}
return response;
}
/// <summary>
/// 构建SDK类型的仅Toast响应(用于回调)
/// </summary>
public CardActionTriggerResponseDto BuildCardActionToastOnlyResponse(string toastMessage, string toastType = "info")
{
return BuildCardActionResponseV2(null!, toastMessage, toastType);
}
// ========== 原来的实现(用于初始发送卡片) ==========
/// <summary>
/// 构建命令选择卡片(卡片1)- 用于初始发送
/// </summary>
/// <param name="categories">命令分组列表</param>
/// <param name="showRefreshButton">是否显示刷新按钮</param>
/// <returns>飞书卡片JSON</returns>
public string BuildCommandListCard(List<FeishuCommandCategory> categories, bool showRefreshButton = true)
{
var elements = new List<object>();
// 顶部操作按钮组
if (showRefreshButton)
{
elements.Add(new
{
tag = "column_set",
flex_mode = "none",
background_style = "default",
columns = new[]
{
new
{
tag = "column",
width = "weighted",
weight = 1,
vertical_align = "top",
elements = new[]
{
new
{
tag = "button",
text = new { tag = "plain_text", content = "🔄 更新命令列表" },
type = "default",
behaviors = new[]
{
new
{
type = "callback",
value = new { action = "refresh_commands" }
}
}
}
}
},
new
{
tag = "column",
width = "weighted",
weight = 1,
vertical_align = "top",
elements = new[]
{
new
{
tag = "button",
text = new { tag = "plain_text", content = "📋 会话管理" },
type = "primary",
behaviors = new[]
{
new
{
type = "callback",
value = new { action = "open_session_manager" }
}
}
}
}
}
}
});
}
// 每个分组显示为分类按钮,避免首页元素超限
foreach (var category in categories)
{
if (category.Commands.Count == 0)
continue;
elements.Add(BuildCategoryActionRow(category));
}
var card = new
{
schema = "2.0",
config = new { enable_forward = true, update_multi = true },
header = new
{
template = "blue",
title = new { tag = "plain_text", content = "🤖 当前 CLI 命令帮助" }
},
body = new { elements = elements }
};
return JsonSerializer.Serialize(card);
}
/// <summary>
/// 构建执行卡片(卡片2)
/// </summary>
/// <param name="command">选中的命令</param>
/// <returns>飞书卡片JSON</returns>
// public string BuildExecuteCard(FeishuCommand command)
// {
// var formElements = new List<object>
// {
// new
// {
// tag = "div",
// text = new { tag = "lark_md", content = $"**📝 命令说明:**\n{command.Description}" }
// },
// new
// {
// tag = "div",
// text = new { tag = "lark_md", content = $"**💡 用法示例:**\n`{command.Usage}`" }
// },
// new { tag = "hr" },
// // 使用匿名对象创建输入框(因为需要 placeholder 和 default_value 属性)
// new
// {
// tag = "input",
// name = "command_input",
// placeholder = "编辑命令...",
// default_value = command.Name.StartsWith("/") ? command.Name : $"claude {command.Name}"
// },
// new
// {
// tag = "column_set",
// flex_mode = "none",
// background_style = "default",
// columns = new[]
// {
// new
// {
// tag = "column",
// width = "weighted",
// weight = 1,
// vertical_align = "top",
// elements = new[]
// {
// // 使用 SDK 的表单按钮
// new FormButtonElement(
// Name: "cancel_button",
// Text: new PlainTextElement("❌ 取消"),
// Type: "default",
// ActionType: "request",
// Behaviors: new Behaviors[]
// {
// new CallbackBehaviors(
// Value: JsonSerializer.Serialize(new { action = "back_to_list" })
// )
// }
// )
// }
// },
// new
// {
// tag = "column",
// width = "weighted",
// weight = 1,
// vertical_align = "top",
// elements = new[]
// {
// // 使用 SDK 的表单按钮
// new FormButtonElement(
// Name: "execute_button",
// Text: new PlainTextElement("✅ 执行命令"),
// Type: "primary",
// ActionType: "form_submit"
// )
// }
// }
// }
// }
// };
// // 使用 SDK 的 FormContainerElement
// var formContainer = new FormContainerElement(
// Name: "execute_command_form",
// Elements: formElements.ToArray()
// );
// var card = new
// {
// schema = "2.0",
// config = new { enable_forward = true, update_multi = true },
// header = new
// {
// template = "purple",
// title = new { tag = "plain_text", content = $"⚙️ 执行命令:{command.Name}" }
// },
// body = new { elements = new object[] { formContainer } }
// };
// return JsonSerializer.Serialize(card);
// }
/// <summary>
/// 构建过滤后的搜索卡片
/// </summary>
/// <param name="categories">过滤后的命令分组</param>
/// <param name="keyword">搜索关键词</param>
/// <returns>飞书卡片JSON</returns>
public string BuildFilteredCard(List<FeishuCommandCategory> categories, string keyword)
{
var elements = new List<object>();
// 过滤说明
elements.Add(new
{
tag = "div",
text = new { tag = "lark_md", content = $"🔍 搜索结果:**{keyword}**\n\n点击下方按钮返回完整列表" }
});
// 返回按钮 - 使用 column_set + button 而非 action 标签
elements.Add(new
{
tag = "column_set",
flex_mode = "none",
background_style = "default",
columns = new[]
{
new
{
tag = "column",
width = "weighted",
weight = 1,
vertical_align = "top",
elements = new[]
{
new
{
tag = "button",
text = new { tag = "plain_text", content = "📋 显示全部命令" },
type = "default",
behaviors = new[]
{
new
{
type = "callback",
value = new { action = "back_to_list" }
}
}
}
}
}
}
});
elements.Add(new { tag = "hr" });
// 匹配的命令(不分组,直接显示)
var allCommands = categories.SelectMany(c => c.Commands).ToList();
if (allCommands.Count > 0)
{
elements.Add(new
{
tag = "div",
text = new { tag = "lark_md", content = $"**找到 {allCommands.Count} 个匹配命令:**" }
});
foreach (var command in allCommands)
{
elements.Add(BuildCommandActionRow(command));
}
}
else
{
elements.Add(new
{
tag = "div",
text = new { tag = "lark_md", content = "❌ 未找到匹配的命令,请尝试其他关键词" }
});
}
var card = new
{
schema = "2.0",
config = new { enable_forward = true },
header = new
{
template = "turquoise",
title = new { tag = "plain_text", content = "🔍 命令搜索" }
},
body = new { elements = elements }
};
return JsonSerializer.Serialize(card);
}
/// <summary>
/// 构建带toast的卡片响应
/// </summary>
/// <param name="cardJson">卡片JSON</param>
/// <param name="toastMessage">toast消息</param>
/// <param name="toastType">toast类型</param>
/// <returns>飞书响应对象</returns>
public object BuildToastResponse(string cardJson, string toastMessage, string toastType = "info")
{
return new
{
toast = new
{
type = toastType,
content = toastMessage
},
card = new
{
type = "raw",
data = JsonSerializer.Deserialize<Dictionary<string, object>>(cardJson)
}
};
}
/// <summary>
/// 构建仅toast的响应
/// </summary>
/// <param name="toastMessage">toast消息</param>
/// <param name="toastType">toast类型</param>
/// <returns>飞书响应对象</returns>
public object BuildToastOnlyResponse(string toastMessage, string toastType = "info")
{
return new
{
toast = new
{
type = toastType,
content = toastMessage
}
};
}
private static string BuildCategoryPreviewMarkdown(FeishuCommandCategory category)
{
var lines = category.Commands
.Take(5)
.Select(cmd => $"- `{SanitizeMarkdown(cmd.Name)}`:{SanitizeMarkdown(cmd.Description)}")
.ToList();
if (category.Commands.Count > 5)
{
lines.Add($"- ... 共 {category.Commands.Count} 条,可点右侧选择");
}
var detail = lines.Count > 0 ? "\n" + string.Join("\n", lines) : string.Empty;
return $"**{SanitizeMarkdown(category.Name)}**{detail}";
}
private static object BuildCategoryActionRow(FeishuCommandCategory category)
{
return new
{
tag = "column_set",
flex_mode = "none",
background_style = "default",
columns = new object[]
{
new
{
tag = "column",
width = "weighted",
weight = 5,
vertical_align = "top",
elements = new object[]
{
new
{
tag = "div",
text = new
{
tag = "lark_md",
content = $"**{SanitizeMarkdown(category.Name)}**\n共 {category.Commands.Count} 条命令"
}
}
}
},
new
{
tag = "column",
width = "auto",
vertical_align = "top",
elements = new object[]
{
new
{
tag = "button",