2022-11-21 11:30:38 +08:00
|
|
|
using System;
|
2021-10-09 15:17:35 +08:00
|
|
|
using System.Net.Http;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Flurl.Http;
|
|
|
|
|
|
|
|
namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
|
|
|
{
|
2022-11-21 11:30:38 +08:00
|
|
|
public static class WechatOpenAIClientExecuteThirdKefuExtensions
|
2021-10-09 15:17:35 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
2021-10-11 22:53:34 +08:00
|
|
|
/// <para>异步调用 [POST] /sendmsg/{TOKEN} 接口。</para>
|
2021-10-09 15:17:35 +08:00
|
|
|
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/thirdkefu/sendmsg.html </para>
|
2021-10-11 11:53:22 +08:00
|
|
|
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/sendmsg.html </para>
|
2021-10-09 15:17:35 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="client"></param>
|
|
|
|
/// <param name="request"></param>
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
/// <returns></returns>
|
2022-11-21 11:30:38 +08:00
|
|
|
public static async Task<Models.SendMessageResponse> ExecuteSendMessageAsync(this WechatOpenAIClient client, Models.SendMessageRequest request, CancellationToken cancellationToken = default)
|
2021-10-09 15:17:35 +08:00
|
|
|
{
|
|
|
|
if (client is null) throw new ArgumentNullException(nameof(client));
|
|
|
|
if (request is null) throw new ArgumentNullException(nameof(request));
|
|
|
|
|
2021-10-09 16:57:16 +08:00
|
|
|
if (request.AppId == null)
|
|
|
|
request.AppId = client.Credentials.AppId;
|
|
|
|
|
2021-10-09 15:17:35 +08:00
|
|
|
IFlurlRequest flurlReq = client
|
2021-10-11 22:53:34 +08:00
|
|
|
.CreateRequest(request, HttpMethod.Post, "sendmsg", client.Credentials.Token!);
|
2021-10-09 15:17:35 +08:00
|
|
|
|
2022-11-21 11:30:38 +08:00
|
|
|
return await client.SendRequestWithJsonAsync<Models.SendMessageResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
2021-10-09 15:17:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2021-10-11 22:53:34 +08:00
|
|
|
/// <para>异步调用 [POST] /kefustate/get/{TOKEN} 接口。</para>
|
2021-10-09 15:17:35 +08:00
|
|
|
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/thirdkefu/getstate.html </para>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="client"></param>
|
|
|
|
/// <param name="request"></param>
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
/// <returns></returns>
|
2022-11-21 11:30:38 +08:00
|
|
|
public static async Task<Models.KefuStateGetResponse> ExecuteKefuStateGetAsync(this WechatOpenAIClient client, Models.KefuStateGetRequest request, CancellationToken cancellationToken = default)
|
2021-10-09 15:17:35 +08:00
|
|
|
{
|
|
|
|
if (client is null) throw new ArgumentNullException(nameof(client));
|
|
|
|
if (request is null) throw new ArgumentNullException(nameof(request));
|
|
|
|
|
2021-10-09 16:57:16 +08:00
|
|
|
if (request.AppId == null)
|
|
|
|
request.AppId = client.Credentials.AppId;
|
|
|
|
|
2021-10-09 15:17:35 +08:00
|
|
|
IFlurlRequest flurlReq = client
|
2021-10-11 22:53:34 +08:00
|
|
|
.CreateRequest(request, HttpMethod.Post, "kefustate", "get", client.Credentials.Token!);
|
2021-10-09 15:17:35 +08:00
|
|
|
|
2022-11-21 11:30:38 +08:00
|
|
|
return await client.SendRequestWithJsonAsync<Models.KefuStateGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
2021-10-09 15:17:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2021-10-11 22:53:34 +08:00
|
|
|
/// <para>异步调用 [POST] /kefustate/change/{TOKEN} 接口。</para>
|
2021-10-09 15:17:35 +08:00
|
|
|
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/thirdkefu/getstate.html </para>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="client"></param>
|
|
|
|
/// <param name="request"></param>
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
/// <returns></returns>
|
2022-11-21 11:30:38 +08:00
|
|
|
public static async Task<Models.KefuStateChangeResponse> ExecuteKefuStateChangeAsync(this WechatOpenAIClient client, Models.KefuStateChangeRequest request, CancellationToken cancellationToken = default)
|
2021-10-09 15:17:35 +08:00
|
|
|
{
|
|
|
|
if (client is null) throw new ArgumentNullException(nameof(client));
|
|
|
|
if (request is null) throw new ArgumentNullException(nameof(request));
|
|
|
|
|
2021-10-09 16:57:16 +08:00
|
|
|
if (request.AppId == null)
|
|
|
|
request.AppId = client.Credentials.AppId;
|
|
|
|
|
2021-10-09 15:17:35 +08:00
|
|
|
IFlurlRequest flurlReq = client
|
2021-10-11 22:53:34 +08:00
|
|
|
.CreateRequest(request, HttpMethod.Post, "kefustate", "change", client.Credentials.Token!);
|
2021-10-09 15:17:35 +08:00
|
|
|
|
2022-11-21 11:30:38 +08:00
|
|
|
return await client.SendRequestWithJsonAsync<Models.KefuStateChangeResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
2021-10-09 15:17:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|