mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-07-16 07:59:44 +08:00
feat(openai): 新增智能对话相关接口
This commit is contained in:
parent
a52be8ee2c
commit
eb1b544c6e
@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flurl.Http;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
{
|
||||
public static class WechatOpenAIClientExecuteOpenApiBotExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /openapi/batchimportskill/{TOKEN} 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/skill/batchimportskill.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.OpenApiBatchImportSkillResponse> ExecuteOpenApiBatchImportSkillAsync(this WechatOpenAIClient client, Models.OpenApiBatchImportSkillRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "openapi", "batchimportskill", client.Credentials.PushToken!);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.OpenApiBatchImportSkillResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /openapi/publish/{TOKEN} 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/skill/publish.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.OpenApiPublishResponse> ExecuteOpenApiPublishAsync(this WechatOpenAIClient client, Models.OpenApiPublishRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "openapi", "publish", client.Credentials.PushToken!);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.OpenApiPublishResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /openapi/publish_progress/{TOKEN} 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/skill/publish_progress.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.OpenApiPublishProgressResponse> ExecuteOpenApiPublishProgressAsync(this WechatOpenAIClient client, Models.OpenApiPublishProgressRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "openapi", "publish_progress", client.Credentials.PushToken!);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.OpenApiPublishProgressResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /openapi/setautoreply/{TOKEN} 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/living/setautoreply.html </para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/skill/publish_progress.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.OpenApiSetAutoReplyResponse> ExecuteOpenApiSetAutoReplyAsync(this WechatOpenAIClient client, Models.OpenApiSetAutoReplyRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "openapi", "setautoreply", client.Credentials.PushToken!);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.OpenApiSetAutoReplyResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /openapi/label/batchset/{TOKEN} 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/batchsetlabel.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.OpenApiLabelBatchSetResponse> ExecuteOpenApiLabelBatchSetAsync(this WechatOpenAIClient client, Models.OpenApiLabelBatchSetRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "openapi", "label", "batchset", client.Credentials.PushToken!);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.OpenApiLabelBatchSetResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
@ -27,25 +27,6 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
return await client.SendRequestWithJsonAsync<Models.OpenApiBatchReplyResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /openapi/setautoreply/{TOKEN} 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/living/setautoreply.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.OpenApiBatchSetAutoReplyResponse> ExecuteOpenApiBatchSetAutoReplyAsync(this WechatOpenAIClient client, Models.OpenApiBatchSetAutoReplyRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "openapi", "setautoreply", client.Credentials.PushToken!);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.OpenApiBatchSetAutoReplyResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /openapi/generatereport/{TOKEN} 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/living/setautoreply.html </para>
|
||||
|
@ -96,16 +96,16 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.OpenApiAssetsUploadResponse> ExecuteFileUploadAsync(this WechatOpenAIClient client, Models.FileUploadRequest request, CancellationToken cancellationToken = default)
|
||||
public static async Task<Models.OpenApiAssetsUploadResponse> ExecuteOpenApiAssetsUploadAsync(this WechatOpenAIClient client, Models.OpenApiAssetsUploadRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (request.FileName == null)
|
||||
request.FileName = Guid.NewGuid().ToString("N").ToLower() + ".csv";
|
||||
request.FileName = Guid.NewGuid().ToString("N").ToLower() + ".jpg";
|
||||
|
||||
if (request.FileContentType == null)
|
||||
request.FileContentType = "text/csv";
|
||||
request.FileContentType = "image/jpeg";
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "openapi", "assetsupload", client.Credentials.PushToken!);
|
||||
|
@ -11,6 +11,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /openapi/sendmsg/{TOKEN} 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/thirdkefu/sendmsg.html </para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/sendmsg.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
|
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/batchimportskill/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
[XmlRoot("xml")]
|
||||
public class OpenApiBatchImportSkillRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedXmlable
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Skill
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置技能名称。
|
||||
/// </summary>
|
||||
[XmlElement("skillname")]
|
||||
public string SkillName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置标准问题。
|
||||
/// </summary>
|
||||
[XmlElement("title")]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置相似问题列表。
|
||||
/// </summary>
|
||||
[XmlElement("question")]
|
||||
public List<string> QuestionList { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置机器人回答列表。
|
||||
/// </summary>
|
||||
[XmlElement("answer")]
|
||||
public List<string> AnswerList { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置管理员 ID。
|
||||
/// </summary>
|
||||
[XmlElement("managerid")]
|
||||
public string ManagetId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置技能列表。
|
||||
/// </summary>
|
||||
[XmlElement("skill")]
|
||||
public List<Types.Skill> SkillList { get; set; } = new List<Types.Skill>();
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/batchimportskill/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiBatchImportSkillResponse : WechatOpenAIResponse
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/label/batchset/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
[XmlRoot("xml")]
|
||||
public class OpenApiLabelBatchSetRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedXmlable
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置微信 AppId。
|
||||
/// </summary>
|
||||
[XmlElement("appid")]
|
||||
public string AppId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置标签名称。
|
||||
/// </summary>
|
||||
[XmlElement("category")]
|
||||
public string Category { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置二级标签名称。
|
||||
/// </summary>
|
||||
[XmlElement("label")]
|
||||
public string Label { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置标签分类规则。
|
||||
/// </summary>
|
||||
[XmlElement("desc")]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置要设置标签的 OpenId 列表。
|
||||
/// </summary>
|
||||
[XmlArray("list")]
|
||||
[XmlArrayItem("openid", Type = typeof(string))]
|
||||
public List<string> OpenIdList { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/label/batchset/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiLabelBatchSetResponse : WechatOpenAIResponse
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/publish_progress/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
[XmlRoot("xml")]
|
||||
public class OpenApiPublishProgressRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedXmlable
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置管理员 ID。
|
||||
/// </summary>
|
||||
[XmlElement("managerid")]
|
||||
public string ManagerId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/publish_progress/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiPublishProgressResponse : WechatOpenAIResponse<OpenApiPublishProgressResponse.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置进度(范围:0~100)。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("progress")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("progress")]
|
||||
public int Progress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置状态。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("status")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("status")]
|
||||
public int Status { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/publish/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
[XmlRoot("xml")]
|
||||
public class OpenApiPublishRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedXmlable
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置管理员 ID。
|
||||
/// </summary>
|
||||
[XmlElement("managerid")]
|
||||
public string ManagerId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/publish/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiPublishResponse : WechatOpenAIResponse
|
||||
{
|
||||
}
|
||||
}
|
@ -8,13 +8,13 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
/// <para>表示 [POST] /openapi/setautoreply/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
[XmlRoot("xml")]
|
||||
public class OpenApiBatchSetAutoReplyRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedXmlable
|
||||
public class OpenApiSetAutoReplyRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedXmlable
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置管理员 ID。
|
||||
/// </summary>
|
||||
[XmlElement("managerid")]
|
||||
public string ManagerId { get; set; } = string.Empty;
|
||||
public string ManagetId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置技能名称。
|
||||
@ -25,20 +25,20 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
/// <summary>
|
||||
/// 获取或设置标准问题。
|
||||
/// </summary>
|
||||
[XmlElement("title", IsNullable = true)]
|
||||
[XmlElement("title")]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置自动回答的内容。
|
||||
/// </summary>
|
||||
[XmlElement("content", IsNullable = true)]
|
||||
[XmlElement("content")]
|
||||
public string Content { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置要设置的相似问题列表。
|
||||
/// 获取或设置相似问题列表。
|
||||
/// </summary>
|
||||
[XmlArray("list")]
|
||||
[XmlArrayItem("question", Type = typeof(string))]
|
||||
public List<string> QuestionId { get; set; } = new List<string>();
|
||||
public List<string> QuestionList { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/setautoreply/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiBatchSetAutoReplyResponse : WechatOpenAIResponse
|
||||
public class OpenApiSetAutoReplyResponse : WechatOpenAIResponse
|
||||
{
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ using System.Xml.Serialization;
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/getbindlink/{TOKEN} 接口的请求。</para>
|
||||
/// <para>表示 [POST] /openapi/getbindlist/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
[XmlRoot("xml")]
|
||||
public class OpenApiGetBindListRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedXmlable
|
||||
|
@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/getbindlink/{TOKEN} 接口的响应。</para>
|
||||
/// <para>表示 [POST] /openapi/getbindlist/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiGetBindListResponse : WechatOpenAIResponse
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user