Skip to content

Commit b8c163d

Browse files
committed
Support create card pipe message
1 parent cd72101 commit b8c163d

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

src/Kook.Net.Pipe/KookPipeClient.cs

+21-3
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,31 @@ private static API.KookRestApiClient CreateApiClient(KookRestConfig config) =>
135135
config.DefaultRetryMode, SerializerOptions);
136136

137137
/// <summary>
138-
/// 发送消息内容到管道
138+
/// 发送文本消息内容到管道
139139
/// </summary>
140140
/// <param name="text"> 要发送的消息文本。 </param>
141141
/// <param name="options"> 用于配置请求的选项。 </param>
142142
/// <returns> 返回一个表示异步操作的任务,任务的结果是消息的 ID。 </returns>
143-
public Task<Guid> SendContentAsync(string text, RequestOptions? options = null) =>
144-
PipeClientHelper.SendMessageAsync(this, text, options);
143+
public Task<Guid> SendTextAsync(string text, RequestOptions? options = null) =>
144+
PipeClientHelper.SendTextAsync(this, text, options);
145+
146+
/// <summary>
147+
/// 发送卡片消息内容到管道。
148+
/// </summary>
149+
/// <param name="card"> 要发送的卡片。 </param>
150+
/// <param name="options"> 用于配置请求的选项。 </param>
151+
/// <returns> 返回一个表示异步操作的任务,任务的结果是消息的 ID。 </returns>
152+
public Task<Guid> SendCardAsync(ICard card, RequestOptions? options = null) =>
153+
PipeClientHelper.SendCardsAsync(this, [card], options);
154+
155+
/// <summary>
156+
/// 发送卡片消息内容到管道。
157+
/// </summary>
158+
/// <param name="cards"> 要发送的卡片。 </param>
159+
/// <param name="options"> 用于配置请求的选项。 </param>
160+
/// <returns> 返回一个表示异步操作的任务,任务的结果是消息的 ID。 </returns>
161+
public Task<Guid> SendCardsAsync(IEnumerable<ICard> cards, RequestOptions? options = null) =>
162+
PipeClientHelper.SendCardsAsync(this, cards, options);
145163

146164
/// <summary>
147165
/// 发送消息模板的参数到管道。

src/Kook.Net.Pipe/PipeClientHelper.cs

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Text.Json;
22
using Kook.API.Rest;
3+
using Kook.Rest;
34

45
namespace Kook.Pipe;
56

@@ -13,14 +14,27 @@ public static async Task<Guid> SendMessageAsync<T>(KookPipeClient client, T? par
1314
return response.MessageId;
1415
}
1516

16-
public static async Task<Guid> SendMessageAsync(KookPipeClient client, string text, RequestOptions? options)
17+
public static async Task<Guid> SendTextAsync(KookPipeClient client, string text, RequestOptions? options)
1718
{
1819
CreatePipeMessageParams args = new()
1920
{
2021
Content = text
2122
};
2223
CreateMessageResponse response = await client.ApiClient
23-
.CreatePipeMessageAsync(args, options).ConfigureAwait(false);
24+
.CreatePipeMessageAsync(args, MessageType.KMarkdown, options).ConfigureAwait(false);
25+
return response.MessageId;
26+
}
27+
28+
public static async Task<Guid> SendCardsAsync(KookPipeClient client, IEnumerable<ICard> cards, RequestOptions? options)
29+
{
30+
string json = MessageHelper.SerializeCards(cards);
31+
32+
CreatePipeMessageParams args = new()
33+
{
34+
Content = json
35+
};
36+
CreateMessageResponse response = await client.ApiClient
37+
.CreatePipeMessageAsync(args, MessageType.Card, options).ConfigureAwait(false);
2438
return response.MessageId;
2539
}
2640
}

src/Kook.Net.Rest/KookRestApiClient.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -806,15 +806,16 @@ public async Task<CreateMessageResponse> CreatePipeMessageAsync<T>(T? args, Json
806806
.ConfigureAwait(false);
807807
}
808808

809-
public async Task<CreateMessageResponse> CreatePipeMessageAsync(CreatePipeMessageParams args, RequestOptions? options = null)
809+
public async Task<CreateMessageResponse> CreatePipeMessageAsync(CreatePipeMessageParams args, MessageType type, RequestOptions? options = null)
810810
{
811811
Preconditions.NotNull(args, nameof(args));
812812
Preconditions.NotNullOrEmpty(AuthToken, nameof(AuthToken));
813813
options = RequestOptions.CreateOrClone(options);
814814

815815
BucketIds ids = new(pipeId: AuthToken);
816+
int typeInt = (int)type;
816817
return await SendJsonAsync<CreateMessageResponse>(HttpMethod.Post,
817-
() => $"message/send-pipemsg?access_token={AuthToken}", args, ids, ClientBucketType.SendEdit, false, null, options)
818+
() => $"message/send-pipemsg?access_token={AuthToken}&type={typeInt}", args, ids, ClientBucketType.SendEdit, false, null, options)
818819
.ConfigureAwait(false);
819820
}
820821

0 commit comments

Comments
 (0)