-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathFeishuCardKitClient.cs
More file actions
723 lines (625 loc) · 25.4 KB
/
FeishuCardKitClient.cs
File metadata and controls
723 lines (625 loc) · 25.4 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
using System.Collections.Concurrent;
using System.Text;
using System.Text.Json;
using FeishuNetSdk.Im.Dtos;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using WebCodeCli.Domain.Common.Extensions;
using WebCodeCli.Domain.Common.Options;
using WebCodeCli.Domain.Domain.Model.Channels;
namespace WebCodeCli.Domain.Domain.Service.Channels;
/// <summary>
/// 飞书 CardKit 客户端实现
/// </summary>
[ServiceDescription(typeof(IFeishuCardKitClient), ServiceLifetime.Scoped)]
public class FeishuCardKitClient : IFeishuCardKitClient
{
private readonly FeishuOptions _defaultOptions;
private readonly ILogger<FeishuCardKitClient> _logger;
private readonly HttpClient _httpClient;
private readonly string _baseUrl = "https://open.feishu.cn";
private readonly ConcurrentDictionary<string, TokenCacheEntry> _tokenCache = new(StringComparer.Ordinal);
public FeishuCardKitClient(
IOptions<FeishuOptions> options,
ILogger<FeishuCardKitClient> logger,
IHttpClientFactory httpClientFactory)
{
_defaultOptions = options.Value;
_logger = logger;
_httpClient = httpClientFactory.CreateClient("FeishuClient");
_httpClient.Timeout = Timeout.InfiniteTimeSpan;
}
public async Task<string> CreateCardAsync(
string initialContent,
string? title = null,
CancellationToken cancellationToken = default,
FeishuOptions? optionsOverride = null)
{
var effectiveOptions = GetEffectiveOptions(optionsOverride);
var token = await EnsureTokenAsync(effectiveOptions, cancellationToken);
var cardData = new
{
schema = "2.0",
config = new
{
update_multi = true,
streaming_mode = true
},
header = new
{
title = new
{
tag = "plain_text",
content = title ?? effectiveOptions.DefaultCardTitle
}
},
body = new
{
elements = new[]
{
new
{
tag = "markdown",
content = initialContent
}
}
}
};
var payload = new
{
type = "card_json",
data = JsonSerializer.Serialize(cardData)
};
var response = await PostAsync("/open-apis/cardkit/v1/cards", token, payload, effectiveOptions, cancellationToken);
var result = await ParseResponseAsync(response, cancellationToken);
EnsureBusinessSuccess(result, "Create CardKit card");
if (result.TryGetProperty("data", out var data) &&
data.TryGetProperty("card_id", out var cardIdProp))
{
return cardIdProp.GetString() ?? string.Empty;
}
throw new InvalidOperationException("Failed to create card: invalid response");
}
public async Task<bool> UpdateCardAsync(
string cardId,
string content,
int sequence,
CancellationToken cancellationToken = default,
FeishuOptions? optionsOverride = null)
{
try
{
var effectiveOptions = GetEffectiveOptions(optionsOverride);
var token = await EnsureTokenAsync(effectiveOptions, cancellationToken);
var cardData = new
{
schema = "2.0",
config = new
{
update_multi = true,
streaming_mode = true
},
body = new
{
elements = new[]
{
new
{
tag = "markdown",
content = content
}
}
}
};
var payload = new
{
card = new
{
type = "card_json",
data = JsonSerializer.Serialize(cardData)
},
sequence
};
var response = await PutAsync($"/open-apis/cardkit/v1/cards/{cardId}", token, payload, effectiveOptions, cancellationToken);
var result = await ParseResponseAsync(response, cancellationToken);
EnsureBusinessSuccess(result, "Update CardKit card");
if (result.TryGetProperty("code", out var codeProp))
{
var code = codeProp.GetInt32();
if (code == 0) return true;
_logger.LogWarning(
"Update card failed (cardId={CardId}, seq={Sequence}): Code={Code}, Msg={Msg}",
cardId, sequence, code,
result.TryGetProperty("msg", out var msgProp) ? msgProp.GetString() : "Unknown");
return false;
}
return false;
}
catch (Exception ex)
{
_logger.LogError(ex, "Update card failed (cardId={CardId}, seq={Sequence})", cardId, sequence);
return false;
}
}
public async Task<string> SendCardMessageAsync(
string chatId,
string cardId,
CancellationToken cancellationToken = default,
FeishuOptions? optionsOverride = null)
{
var effectiveOptions = GetEffectiveOptions(optionsOverride);
var token = await EnsureTokenAsync(effectiveOptions, cancellationToken);
var payload = new
{
receive_id = chatId,
msg_type = "interactive",
content = JsonSerializer.Serialize(new
{
type = "card",
data = new
{
card_id = cardId
}
})
};
var response = await PostAsync(
"/open-apis/im/v1/messages?receive_id_type=chat_id",
token,
payload,
effectiveOptions,
cancellationToken);
var result = await ParseResponseAsync(response, cancellationToken);
EnsureBusinessSuccess(result, "Send Feishu card message");
return ExtractMessageId(result, "send card message");
}
public async Task<string> SendTextMessageAsync(
string chatId,
string content,
CancellationToken cancellationToken = default,
FeishuOptions? optionsOverride = null)
{
var effectiveOptions = GetEffectiveOptions(optionsOverride);
var token = await EnsureTokenAsync(effectiveOptions, cancellationToken);
var payload = new
{
receive_id = chatId,
msg_type = "text",
content = JsonSerializer.Serialize(new
{
text = content
})
};
var response = await PostAsync(
"/open-apis/im/v1/messages?receive_id_type=chat_id",
token,
payload,
effectiveOptions,
cancellationToken);
var result = await ParseResponseAsync(response, cancellationToken);
EnsureBusinessSuccess(result, "Send Feishu text message");
return ExtractMessageId(result, "send text message");
}
public async Task<string> ReplyCardMessageAsync(
string replyMessageId,
string cardId,
CancellationToken cancellationToken = default,
FeishuOptions? optionsOverride = null)
{
_logger.LogInformation("📤 [FeishuCardKit] ReplyCardMessageAsync: ReplyMessageId={ReplyMessageId}, CardId={CardId}",
replyMessageId, cardId);
var effectiveOptions = GetEffectiveOptions(optionsOverride);
var token = await EnsureTokenAsync(effectiveOptions, cancellationToken);
var payload = new
{
msg_type = "interactive",
content = JsonSerializer.Serialize(new
{
type = "card",
data = new
{
card_id = cardId
}
})
};
_logger.LogInformation("📤 [FeishuCardKit] 发送 POST 请求到 /open-apis/im/v1/messages/{ReplyMessageId}/reply", replyMessageId);
var response = await PostAsync(
$"/open-apis/im/v1/messages/{replyMessageId}/reply",
token,
payload,
effectiveOptions,
cancellationToken);
_logger.LogInformation("📤 [FeishuCardKit] 响应状态码: {StatusCode}", response.StatusCode);
var result = await ParseResponseAsync(response, cancellationToken);
EnsureBusinessSuccess(result, "Reply Feishu card message");
_logger.LogDebug("📤 [FeishuCardKit] 响应内容: {Response}", result);
var messageId = ExtractMessageId(result, "reply card message");
_logger.LogInformation("✅ [FeishuCardKit] 回复成功, MessageId={MessageId}", messageId);
return messageId;
}
public async Task<string> ReplyTextMessageAsync(
string replyMessageId,
string content,
CancellationToken cancellationToken = default,
FeishuOptions? optionsOverride = null)
{
var effectiveOptions = GetEffectiveOptions(optionsOverride);
var token = await EnsureTokenAsync(effectiveOptions, cancellationToken);
var payload = new
{
msg_type = "text",
content = JsonSerializer.Serialize(new
{
text = content
})
};
var response = await PostAsync(
$"/open-apis/im/v1/messages/{replyMessageId}/reply",
token,
payload,
effectiveOptions,
cancellationToken);
var result = await ParseResponseAsync(response, cancellationToken);
EnsureBusinessSuccess(result, "Reply Feishu text message");
return ExtractMessageId(result, "reply text message");
}
public async Task<FeishuStreamingHandle> CreateStreamingHandleAsync(
string chatId,
string? replyMessageId,
string initialContent,
string? title = null,
CancellationToken cancellationToken = default,
FeishuOptions? optionsOverride = null)
{
var effectiveOptions = GetEffectiveOptions(optionsOverride);
// 1. 创建卡片
var cardId = await CreateCardAsync(initialContent, title, cancellationToken, effectiveOptions);
// 2. 发送或回复卡片消息
string messageId;
if (!string.IsNullOrEmpty(replyMessageId))
{
messageId = await ReplyCardMessageAsync(replyMessageId, cardId, cancellationToken, effectiveOptions);
}
else
{
messageId = await SendCardMessageAsync(chatId, cardId, cancellationToken, effectiveOptions);
}
// 3. 创建流式句柄
return new FeishuStreamingHandle(
cardId,
messageId,
content => UpdateCardAsync(cardId, content, Sequence, cancellationToken, effectiveOptions),
content => UpdateCardAsync(cardId, content, Sequence + 1, cancellationToken, effectiveOptions),
effectiveOptions.StreamingThrottleMs
);
}
private int _sequence = 0;
private int Sequence => Interlocked.Increment(ref _sequence);
private string ExtractMessageId(JsonElement result, string operationName)
{
if (result.TryGetProperty("data", out var data) &&
data.TryGetProperty("message_id", out var messageIdProp))
{
return messageIdProp.GetString() ?? string.Empty;
}
_logger.LogError("❌ [FeishuCardKit] 响应中没有 message_id, Operation={Operation}", operationName);
throw new InvalidOperationException($"Failed to {operationName}: invalid response");
}
/// <summary>
/// 获取或刷新访问令牌
/// 使用 SemaphoreSlim 实现异步安全的双重检查锁定
/// </summary>
private async Task<string> EnsureTokenAsync(FeishuOptions options, CancellationToken cancellationToken)
{
var cacheEntry = GetTokenCacheEntry(options);
// 快速路径:token 有效直接返回
if (!string.IsNullOrEmpty(cacheEntry.AccessToken) && DateTime.UtcNow < cacheEntry.TokenExpiresAt)
{
return cacheEntry.AccessToken;
}
await cacheEntry.TokenLock.WaitAsync(cancellationToken);
try
{
// 双重检查
if (!string.IsNullOrEmpty(cacheEntry.AccessToken) && DateTime.UtcNow < cacheEntry.TokenExpiresAt)
{
return cacheEntry.AccessToken;
}
var payload = new
{
app_id = options.AppId,
app_secret = options.AppSecret
};
HttpResponseMessage response;
try
{
response = await PostAsync(
"/open-apis/auth/v3/tenant_access_token/internal",
string.Empty,
payload,
options,
cancellationToken);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to refresh access token for AppId={AppId}", options.AppId);
// 回退:使用上次有效的 token(如果还有效)
if (!string.IsNullOrEmpty(cacheEntry.LastValidToken))
{
_logger.LogWarning("Using fallback token due to refresh failure for AppId={AppId}", options.AppId);
return cacheEntry.LastValidToken;
}
throw;
}
var result = await ParseResponseAsync(response, cancellationToken);
EnsureBusinessSuccess(result, "Refresh Feishu tenant token");
if (result.TryGetProperty("tenant_access_token", out var tokenProp) &&
result.TryGetProperty("expire", out var expireProp))
{
var newToken = tokenProp.GetString() ?? string.Empty;
var expireSeconds = expireProp.GetInt32();
cacheEntry.AccessToken = newToken;
cacheEntry.TokenExpiresAt = DateTime.UtcNow.AddSeconds(expireSeconds - 60);
cacheEntry.LastValidToken = newToken;
_logger.LogDebug("Access token refreshed for AppId={AppId}, expires at {ExpiresAt}", options.AppId, cacheEntry.TokenExpiresAt);
return cacheEntry.AccessToken;
}
// 解析失败但可能还有旧 token 可用
if (!string.IsNullOrEmpty(cacheEntry.LastValidToken))
{
_logger.LogWarning("Token parse failed, using fallback token for AppId={AppId}", options.AppId);
return cacheEntry.LastValidToken;
}
throw new InvalidOperationException("Failed to get access token: invalid response");
}
finally
{
cacheEntry.TokenLock.Release();
}
}
private async Task<HttpResponseMessage> PostAsync(
string path,
string token,
object payload,
FeishuOptions options,
CancellationToken cancellationToken)
{
var request = new HttpRequestMessage(HttpMethod.Post, $"{_baseUrl}{path}");
request.Content = new StringContent(
JsonSerializer.Serialize(payload),
Encoding.UTF8,
"application/json");
if (!string.IsNullOrEmpty(token))
{
request.Headers.Add("Authorization", $"Bearer {token}");
}
return await SendAsync(request, options, cancellationToken);
}
private async Task<HttpResponseMessage> PutAsync(
string path,
string token,
object payload,
FeishuOptions options,
CancellationToken cancellationToken)
{
var request = new HttpRequestMessage(HttpMethod.Put, $"{_baseUrl}{path}");
request.Content = new StringContent(
JsonSerializer.Serialize(payload),
Encoding.UTF8,
"application/json");
if (!string.IsNullOrEmpty(token))
{
request.Headers.Add("Authorization", $"Bearer {token}");
}
return await SendAsync(request, options, cancellationToken);
}
private async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
FeishuOptions options,
CancellationToken cancellationToken)
{
if (options.HttpTimeoutSeconds <= 0)
{
return await _httpClient.SendAsync(request, cancellationToken);
}
using var timeoutCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
timeoutCts.CancelAfter(TimeSpan.FromSeconds(options.HttpTimeoutSeconds));
return await _httpClient.SendAsync(request, timeoutCts.Token);
}
private async Task<JsonElement> ParseResponseAsync(
HttpResponseMessage response,
CancellationToken cancellationToken)
{
var content = await response.Content.ReadAsStringAsync(cancellationToken);
if (!response.IsSuccessStatusCode)
{
_logger.LogError(
"API request failed: Status={Status}, Content={Content}",
response.StatusCode,
content);
throw new HttpRequestException($"API request failed: {response.StatusCode}");
}
return JsonDocument.Parse(content).RootElement;
}
private void EnsureBusinessSuccess(JsonElement result, string operationName)
{
if (!result.TryGetProperty("code", out var codeProp))
{
return;
}
var code = codeProp.GetInt32();
if (code == 0)
{
return;
}
var message = result.TryGetProperty("msg", out var msgProp)
? msgProp.GetString()
: "Unknown error";
throw new InvalidOperationException($"{operationName} failed: {message} (code: {code})");
}
private FeishuOptions GetEffectiveOptions(FeishuOptions? optionsOverride)
{
return optionsOverride ?? _defaultOptions;
}
private TokenCacheEntry GetTokenCacheEntry(FeishuOptions options)
{
var cacheKey = $"{options.AppId}\n{options.AppSecret}";
return _tokenCache.GetOrAdd(cacheKey, _ => new TokenCacheEntry());
}
/// <summary>
/// 发送原始JSON卡片消息(帮助功能专用)
/// 通过 CardKit 创建卡片,避免JSON格式问题
/// </summary>
public async Task<string> SendRawCardAsync(
string chatId,
string cardJson,
CancellationToken cancellationToken = default,
FeishuOptions? optionsOverride = null)
{
_logger.LogInformation("📤 [FeishuCardKit] 通过CardKit发送卡片");
// 1. 先用 CardKit API 创建卡片
var effectiveOptions = GetEffectiveOptions(optionsOverride);
var token = await EnsureTokenAsync(effectiveOptions, cancellationToken);
var createCardPayload = new
{
type = "card_json",
data = cardJson
};
var createResponse = await PostAsync(
"/open-apis/cardkit/v1/cards",
token,
createCardPayload,
effectiveOptions,
cancellationToken);
var createResult = await ParseResponseAsync(createResponse, cancellationToken);
EnsureBusinessSuccess(createResult, "Create raw CardKit card");
if (!createResult.TryGetProperty("data", out var createData) ||
!createData.TryGetProperty("card_id", out var cardIdProp))
{
throw new InvalidOperationException("Failed to create card via CardKit");
}
var cardId = cardIdProp.GetString() ?? string.Empty;
_logger.LogInformation("📤 [FeishuCardKit] CardKit创建成功: CardId={CardId}", cardId);
// 2. 再发送卡片消息
return await SendCardMessageAsync(chatId, cardId, cancellationToken, effectiveOptions);
}
/// <summary>
/// 回复 V2 DTO 卡片消息(帮助功能专用)
/// </summary>
public Task<string> ReplyElementsCardAsync(
string replyMessageId,
ElementsCardV2Dto card,
CancellationToken cancellationToken = default,
FeishuOptions? optionsOverride = null)
{
var cardJson = SerializeElementsCard(card);
return ReplyRawCardAsync(replyMessageId, cardJson, cancellationToken, optionsOverride);
}
/// <summary>
/// 回复原始JSON卡片消息(帮助功能专用)
/// 参考 OpenCowork 实现:先创建卡片获取 card_id,再发送
/// </summary>
public async Task<string> ReplyRawCardAsync(
string replyMessageId,
string cardJson,
CancellationToken cancellationToken = default,
FeishuOptions? optionsOverride = null)
{
_logger.LogInformation("📤 [FeishuCardKit] 回复交互式卡片, ReplyMessageId={ReplyMessageId}", replyMessageId);
_logger.LogDebug("📤 [FeishuCardKit] 卡片JSON: {CardJson}", cardJson);
try
{
var effectiveOptions = GetEffectiveOptions(optionsOverride);
var token = await EnsureTokenAsync(effectiveOptions, cancellationToken);
// 步骤1: 使用 CardKit API 创建卡片,获取 card_id
_logger.LogInformation("📤 [FeishuCardKit] 步骤1: 创建卡片...");
var createCardPayload = new
{
type = "card_json",
data = cardJson // cardJson 是字符串
};
var createResponse = await PostAsync(
"/open-apis/cardkit/v1/cards",
token,
createCardPayload,
effectiveOptions,
cancellationToken);
var createContent = await createResponse.Content.ReadAsStringAsync(cancellationToken);
_logger.LogDebug("📤 [FeishuCardKit] 创建卡片响应: {Response}", createContent);
if (!createResponse.IsSuccessStatusCode)
{
_logger.LogError("❌ [FeishuCardKit] 创建卡片失败: {Content}", createContent);
throw new HttpRequestException($"Create card failed: {createResponse.StatusCode}");
}
var createResult = JsonDocument.Parse(createContent).RootElement;
EnsureBusinessSuccess(createResult, "Create reply CardKit card");
if (!createResult.TryGetProperty("data", out var createData) ||
!createData.TryGetProperty("card_id", out var cardIdProp))
{
_logger.LogError("❌ [FeishuCardKit] 响应中没有 card_id");
throw new InvalidOperationException("Failed to get card_id from response");
}
var cardId = cardIdProp.GetString() ?? string.Empty;
_logger.LogInformation("📤 [FeishuCardKit] 步骤1: 卡片创建成功, CardId={CardId}", cardId);
// 步骤2: 使用消息 API 回复卡片(发送 card_id)
_logger.LogInformation("📤 [FeishuCardKit] 步骤2: 回复卡片消息...");
var replyPayload = new
{
msg_type = "interactive",
content = JsonSerializer.Serialize(new
{
type = "card",
data = new { card_id = cardId }
})
};
var replyResponse = await PostAsync(
$"/open-apis/im/v1/messages/{replyMessageId}/reply",
token,
replyPayload,
effectiveOptions,
cancellationToken);
var replyContent = await replyResponse.Content.ReadAsStringAsync(cancellationToken);
_logger.LogDebug("📤 [FeishuCardKit] 回复消息响应: {Response}", replyContent);
if (!replyResponse.IsSuccessStatusCode)
{
_logger.LogError("❌ [FeishuCardKit] 回复消息失败: {Content}", replyContent);
throw new HttpRequestException($"Reply message failed: {replyResponse.StatusCode}");
}
var replyResult = JsonDocument.Parse(replyContent).RootElement;
EnsureBusinessSuccess(replyResult, "Reply raw Feishu card message");
if (replyResult.TryGetProperty("data", out var data) &&
data.TryGetProperty("message_id", out var messageIdProp))
{
var messageId = messageIdProp.GetString() ?? string.Empty;
_logger.LogInformation("✅ [FeishuCardKit] 卡片回复成功, MessageId={MessageId}", messageId);
return messageId;
}
_logger.LogError("❌ [FeishuCardKit] 响应中没有 message_id");
throw new InvalidOperationException("Failed to get message_id from response");
}
catch (Exception ex)
{
_logger.LogError(ex, "❌ [FeishuCardKit] ReplyRawCardAsync 失败");
throw;
}
}
private sealed class TokenCacheEntry
{
public string AccessToken { get; set; } = string.Empty;
public DateTime TokenExpiresAt { get; set; } = DateTime.MinValue;
public string? LastValidToken { get; set; }
public SemaphoreSlim TokenLock { get; } = new(1, 1);
}
private static string SerializeElementsCard(ElementsCardV2Dto card)
{
var payload = new
{
schema = string.IsNullOrWhiteSpace(card.Schema) ? "2.0" : card.Schema,
config = card.Config,
header = card.Header,
card_link = card.CardLink,
body = card.Body
};
return JsonSerializer.Serialize(payload);
}
}