draft wechat plugin users

This commit is contained in:
xbotter 2023-06-29 19:40:01 +08:00
parent e5e322b3d7
commit 21e7c53904
No known key found for this signature in database
GPG key ID: A3F32F44E9F160E1
5 changed files with 33 additions and 5 deletions

View file

@ -21,6 +21,7 @@
<ItemGroup>
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
</ItemGroup>
<ItemGroup>

View file

@ -0,0 +1,24 @@
using BotSharp.Core.Repository.Abstraction;
using EntityFrameworkCore.BootKit;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace BotSharp.Plugin.WeChat.Repository.DbTables
{
[Table("WeChatAccount")]
public class WeChatAccount : DbRecord, IAgentTable
{
[Required]
[MaxLength(18)]
public string WeChatAppId { get; set; }
[Required]
[MaxLength(36)]
public string WeChatOpenId { get; set; }
[Required]
[MaxLength(36)]
public string UserId { get; set; }
}
}

View file

@ -1,3 +1,4 @@
using BotSharp.Abstraction.Agents;
using BotSharp.Abstraction.Conversations;
using BotSharp.Abstraction.Conversations.Models;
using BotSharp.Abstraction.Models;
@ -16,6 +17,7 @@ namespace BotSharp.Plugin.WeChat
private readonly Channel<WeChatMessage> _queue;
private readonly IServiceProvider _service;
private readonly ILogger<WeChatBackgroundService> _logger;
private string WeChatAppId => Senparc.Weixin.Config.SenparcWeixinSetting.WeixinAppId;
public WeChatBackgroundService(
IServiceProvider service,
@ -30,9 +32,10 @@ namespace BotSharp.Plugin.WeChat
private async Task HandleTextMessageAsync(string openid, string message)
{
var scoped = _service.CreateScope().ServiceProvider;
var conversationService = scoped.GetRequiredService<IConversationService>();
var result = await conversationService.SendMessage(openid, Guid.Empty.ToString(), new RoleDialogModel
var result = await conversationService.SendMessage(WeChatAppId, openid, new RoleDialogModel
{
Role = "user",
Text = message,
@ -43,8 +46,7 @@ namespace BotSharp.Plugin.WeChat
private async Task ReplyTextMessageAsync(string openid, string content)
{
var appId = Senparc.Weixin.Config.SenparcWeixinSetting.WeixinAppId;
await Senparc.Weixin.MP.AdvancedAPIs.CustomApi.SendTextAsync(appId, openid, content);
await Senparc.Weixin.MP.AdvancedAPIs.CustomApi.SendTextAsync(WeChatAppId, openid, content);
}
public async Task EnqueueAsync(WeChatMessage message)

View file

@ -57,8 +57,8 @@ if (app.Environment.IsDevelopment())
app.UseSwaggerUI();
}
app.UseAuthentication();
app.UseAuthorization();
//app.UseAuthentication();
//app.UseAuthorization();
app.MapControllers();

View file

@ -62,6 +62,7 @@
},
"WeChat": {
"AgentId": "",
"Token": "#{Token}#",
"EncodingAESKey": "#{EncodingAESKey}#",
"WeixinAppId": "#{WeixinAppId}#",