Skip to content

Commit

Permalink
feat(openai): 重命名 "WechatOpenAI" → "WechatChatbot"
Browse files Browse the repository at this point in the history
  • Loading branch information
fudiwei committed Jun 4, 2024
1 parent 7909b86 commit ad9b5a1
Show file tree
Hide file tree
Showing 82 changed files with 143 additions and 194 deletions.
5 changes: 3 additions & 2 deletions docs/WechatOpenAI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
using SKIT.FlurlHttpClient.Wechat;
using SKIT.FlurlHttpClient.Wechat.OpenAI;

var options = new WechatOpenAIClientOptions()
var options = new WechatChatbotClientOptions()
{
AppId = "微信智能对话 AppId",
Token = "微信智能对话 Token",
EncodingAESKey = "微信智能对话 EncodingAESKey"
};
var client = WechatOpenAIClientBuilder.Create(options).Build();
var client = WechatChatbotClientBuilder.Create(options).Build();
```

### 请求 & 响应:
Expand All @@ -66,6 +66,7 @@ if (response.IsSuccessful())
else
{
Console.WriteLine("错误代码:" + response.ErrorCode);
Console.WriteLine("错误描述:" + response.ErrorMessage);
Console.WriteLine("返回代码:" + response.ReturnCode);
Console.WriteLine("返回错误:" + response.ReturnError);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Events
/// <![CDATA[ https://developers.weixin.qq.com/doc/aispeech/confapi/thirdkefu/recivemsg.html ]]>
/// </para>
/// </summary>
public class UserEnterEvent : WechatOpenAIEvent
public class UserEnterEvent : WechatChatbotEvent
{
public static class Types
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,43 @@
namespace SKIT.FlurlHttpClient.Wechat.OpenAI
{
/// <summary>
/// 为 <see cref="WechatOpenAIClient"/> 提供回调通知事件的扩展方法。
/// 为 <see cref="WechatChatbotClient"/> 提供回调通知事件的扩展方法。
/// </summary>
public static partial class WechatOpenAIClientEventExtensions
public static partial class WechatChatbotClientEventExtensions
{
/// <summary>
/// <para>从 XML 反序列化得到 <see cref="WechatOpenAIEvent"/> 对象。</para>
/// <para>从 XML 反序列化得到 <see cref="WechatChatbotEvent"/> 对象。</para>
/// </summary>
/// <typeparam name="TEvent"></typeparam>
/// <param name="client"></param>
/// <param name="webhookXml"></param>
/// <returns></returns>
public static TEvent DeserializeEventFromXml<TEvent>(this WechatOpenAIClient client, string webhookXml)
where TEvent : WechatOpenAIEvent, new()
public static TEvent DeserializeEventFromXml<TEvent>(this WechatChatbotClient client, string webhookXml)
where TEvent : WechatChatbotEvent, new()
{
return InnerDeserializeEventFromXml<TEvent>(client, webhookXml);
}

/// <summary>
/// <para>从 XML 反序列化得到 <see cref="WechatOpenAIEvent"/> 对象。</para>
/// <para>从 XML 反序列化得到 <see cref="WechatChatbotEvent"/> 对象。</para>
/// </summary>
/// <param name="client"></param>
/// <param name="webhookXml"></param>
/// <returns></returns>
public static WechatOpenAIEvent DeserializeEventFromXml(this WechatOpenAIClient client, string webhookXml)
public static WechatChatbotEvent DeserializeEventFromXml(this WechatChatbotClient client, string webhookXml)
{
return InnerDeserializeEventFromXml<WechatOpenAIEvent>(client, webhookXml);
return InnerDeserializeEventFromXml<WechatChatbotEvent>(client, webhookXml);
}

/// <summary>
/// 将 <see cref="WechatOpenAIEvent"/> 对象序列化成 XML。
/// 将 <see cref="WechatChatbotEvent"/> 对象序列化成 XML。
/// </summary>
/// <typeparam name="TEvent"></typeparam>
/// <param name="client"></param>
/// <param name="webhookEvent"></param>
/// <returns></returns>
public static string SerializeEventToXml<TEvent>(this WechatOpenAIClient client, TEvent webhookEvent)
where TEvent : WechatOpenAIEvent, new()
public static string SerializeEventToXml<TEvent>(this WechatChatbotClient client, TEvent webhookEvent)
where TEvent : WechatChatbotEvent, new()
{
string xml;

Expand All @@ -49,13 +49,13 @@ public static string SerializeEventToXml<TEvent>(this WechatOpenAIClient client,
}
catch (Exception ex)
{
throw new WechatOpenAIException("Failed to serialize event data. Please see the inner exception for more details.", ex);
throw new WechatChatbotException("Failed to serialize event data. Please see the inner exception for more details.", ex);
}

if (string.IsNullOrEmpty(client.Credentials.EncodingAESKey))
throw new WechatOpenAIException("Failed to encrypt event data, because the push encoding AES key is not set.");
throw new WechatChatbotException("Failed to encrypt event data, because the push encoding AES key is not set.");
if (string.IsNullOrEmpty(client.Credentials.Token))
throw new WechatOpenAIException("Failed to encrypt event data, because the push token is not set.");
throw new WechatChatbotException("Failed to encrypt event data, because the push token is not set.");

try
{
Expand All @@ -69,36 +69,36 @@ public static string SerializeEventToXml<TEvent>(this WechatOpenAIClient client,
}
catch (Exception ex)
{
throw new WechatOpenAIException("Failed to encrypt event data. Please see the inner exception for more details.", ex);
throw new WechatChatbotException("Failed to encrypt event data. Please see the inner exception for more details.", ex);
}

return xml;
}
}

partial class WechatOpenAIClientEventExtensions
partial class WechatChatbotClientEventExtensions
{
private static TEvent InnerDeserializeEventFromXml<TEvent>(this WechatOpenAIClient client, string webhookXml)
where TEvent : WechatOpenAIEvent
private static TEvent InnerDeserializeEventFromXml<TEvent>(this WechatChatbotClient client, string webhookXml)
where TEvent : WechatChatbotEvent
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (webhookXml is null) throw new ArgumentNullException(webhookXml);

try
{
if (!Utilities.WxMsgCryptor.TryParseXml(webhookXml, out string? encryptedXml))
throw new WechatOpenAIException("Failed to decrypt event data, because of the encrypted data is empty.");
throw new WechatChatbotException("Failed to decrypt event data, because of the encrypted data is empty.");

webhookXml = Utilities.WxMsgCryptor.AESDecrypt(cipherText: encryptedXml!, encodingAESKey: client.Credentials.EncodingAESKey!, out _);
return Utilities.XmlHelper.Deserialize<TEvent>(webhookXml);
}
catch (WechatOpenAIException)
catch (WechatChatbotException)
{
throw;
}
catch (Exception ex)
{
throw new WechatOpenAIException("Failed to deserialize event data. Please see the inner exception for more details.", ex);
throw new WechatChatbotException("Failed to deserialize event data. Please see the inner exception for more details.", ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace SKIT.FlurlHttpClient.Wechat.OpenAI
{
public static class WechatOpenAIClientExecuteBotExtensions
public static class WechatChatbotClientExecuteBotExtensions
{
/// <summary>
/// <para>异步调用 [POST] /batchimportskill/{TOKEN} 接口。</para>
Expand All @@ -19,8 +19,7 @@ public static class WechatOpenAIClientExecuteBotExtensions
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete("相关接口或字段于 2023-04-10 下线。")]
public static async Task<Models.BatchImportSkillResponse> ExecuteBatchImportSkillAsync(this WechatOpenAIClient client, Models.BatchImportSkillRequest request, CancellationToken cancellationToken = default)
public static async Task<Models.BatchImportSkillResponse> ExecuteBatchImportSkillAsync(this WechatChatbotClient client, Models.BatchImportSkillRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
Expand All @@ -42,8 +41,7 @@ public static async Task<Models.BatchImportSkillResponse> ExecuteBatchImportSkil
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete("相关接口或字段于 2023-04-10 下线。")]
public static async Task<Models.PublishResponse> ExecutePublishAsync(this WechatOpenAIClient client, Models.PublishRequest request, CancellationToken cancellationToken = default)
public static async Task<Models.PublishResponse> ExecutePublishAsync(this WechatChatbotClient client, Models.PublishRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
Expand All @@ -65,8 +63,7 @@ public static async Task<Models.PublishResponse> ExecutePublishAsync(this Wechat
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete("相关接口或字段于 2023-04-10 下线。")]
public static async Task<Models.PublishProgressResponse> ExecutePublishProgressAsync(this WechatOpenAIClient client, Models.PublishProgressRequest request, CancellationToken cancellationToken = default)
public static async Task<Models.PublishProgressResponse> ExecutePublishProgressAsync(this WechatChatbotClient client, Models.PublishProgressRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
Expand All @@ -88,8 +85,7 @@ public static async Task<Models.PublishProgressResponse> ExecutePublishProgressA
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete("相关接口或字段于 2023-04-10 下线。")]
public static async Task<Models.SetAutoReplyResponse> ExecuteSetAutoReplyAsync(this WechatOpenAIClient client, Models.SetAutoReplyRequest request, CancellationToken cancellationToken = default)
public static async Task<Models.SetAutoReplyResponse> ExecuteSetAutoReplyAsync(this WechatChatbotClient client, Models.SetAutoReplyRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
Expand All @@ -111,8 +107,7 @@ public static async Task<Models.SetAutoReplyResponse> ExecuteSetAutoReplyAsync(t
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete("相关接口或字段于 2023-04-10 下线。")]
public static async Task<Models.LabelBatchSetResponse> ExecuteLabelBatchSetAsync(this WechatOpenAIClient client, Models.LabelBatchSetRequest request, CancellationToken cancellationToken = default)
public static async Task<Models.LabelBatchSetResponse> ExecuteLabelBatchSetAsync(this WechatChatbotClient client, Models.LabelBatchSetRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace SKIT.FlurlHttpClient.Wechat.OpenAI
{
public static class WechatOpenAIClientExecuteDialogExtensions
public static class WechatChatbotClientExecuteDialogExtensions
{
/// <summary>
/// <para>异步调用 [POST] /sign/{TOKEN} 接口。</para>
Expand All @@ -19,8 +19,7 @@ public static class WechatOpenAIClientExecuteDialogExtensions
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete("相关接口或字段于 2023-04-10 下线。")]
public static async Task<Models.SignResponse> ExecuteSignAsync(this WechatOpenAIClient client, Models.SignRequest request, CancellationToken cancellationToken = default)
public static async Task<Models.SignResponse> ExecuteSignAsync(this WechatChatbotClient client, Models.SignRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
Expand All @@ -42,8 +41,7 @@ public static async Task<Models.SignResponse> ExecuteSignAsync(this WechatOpenAI
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete("相关接口或字段于 2023-04-10 下线。")]
public static async Task<Models.AIBotResponse> ExecuteAIBotAsync(this WechatOpenAIClient client, Models.AIBotRequest request, CancellationToken cancellationToken = default)
public static async Task<Models.AIBotResponse> ExecuteAIBotAsync(this WechatChatbotClient client, Models.AIBotRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
Expand All @@ -66,7 +64,7 @@ public static async Task<Models.AIBotResponse> ExecuteAIBotAsync(this WechatOpen
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete("相关接口或字段于 2023-04-07 下线。")]
public static async Task<Models.FeedbackResponse> ExecuteFeedbackAsync(this WechatOpenAIClient client, Models.FeedbackRequest request, CancellationToken cancellationToken = default)
public static async Task<Models.FeedbackResponse> ExecuteFeedbackAsync(this WechatChatbotClient client, Models.FeedbackRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
Expand All @@ -89,7 +87,7 @@ public static async Task<Models.FeedbackResponse> ExecuteFeedbackAsync(this Wech
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete("相关接口或字段于 2023-04-07 下线。")]
public static async Task<Models.GetHotQueryListResponse> ExecuteGetHotQueryListAsync(this WechatOpenAIClient client, Models.GetHotQueryListRequest request, CancellationToken cancellationToken = default)
public static async Task<Models.GetHotQueryListResponse> ExecuteGetHotQueryListAsync(this WechatChatbotClient client, Models.GetHotQueryListRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
Expand All @@ -112,7 +110,7 @@ public static async Task<Models.GetHotQueryListResponse> ExecuteGetHotQueryListA
/// <param name="cancellationToken"></param>
/// <returns></returns>
[Obsolete("相关接口或字段于 2023-04-07 下线。")]
public static async Task<Models.GetHotQueryDetailResponse> ExecuteGetHotQueryDetailAsync(this WechatOpenAIClient client, Models.GetHotQueryDetailRequest request, CancellationToken cancellationToken = default)
public static async Task<Models.GetHotQueryDetailResponse> ExecuteGetHotQueryDetailAsync(this WechatChatbotClient client, Models.GetHotQueryDetailRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
Expand Down
Loading

0 comments on commit ad9b5a1

Please sign in to comment.