Skip to content

Commit b250fc7

Browse files
committed
Fix user null issue.
1 parent 2904c92 commit b250fc7

File tree

8 files changed

+32
-9
lines changed

8 files changed

+32
-9
lines changed

src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
<PackageIcon>Icon.png</PackageIcon>
99
</PropertyGroup>
1010

11+
<ItemGroup>
12+
<Compile Remove="Infrastructures\**" />
13+
<EmbeddedResource Remove="Infrastructures\**" />
14+
<None Remove="Infrastructures\**" />
15+
</ItemGroup>
16+
1117
<ItemGroup>
1218
<None Include="..\..\..\arts\Icon.png">
1319
<Pack>True</Pack>
@@ -22,8 +28,4 @@
2228
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
2329
</ItemGroup>
2430

25-
<ItemGroup>
26-
<Folder Include="Infrastructures\" />
27-
</ItemGroup>
28-
2931
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace BotSharp.Abstraction.Utilities;
2+
3+
public static class StringExtensions
4+
{
5+
public static string IfNullOrEmptyAs(this string str, string defaultValue)
6+
=> string.IsNullOrEmpty(str) ? defaultValue : str;
7+
}

src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,25 @@
3434
<PackageIconUrl>https://raw.githubusercontent.com/SciSharp/BotSharp/master/docs/static/logos/BotSharp.png</PackageIconUrl>
3535
<PackageLicenseUrl>https://raw.githubusercontent.com/SciSharp/BotSharp/master/LICENSE</PackageLicenseUrl>
3636
<PackageIcon>Icon.png</PackageIcon>
37+
<Nullable>enable</Nullable>
3738
</PropertyGroup>
3839

3940
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
4041
<DefineConstants>TRACE;DEBUG</DefineConstants>
42+
<NoWarn>1701;1702</NoWarn>
4143
</PropertyGroup>
4244

4345
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
4446
<DefineConstants>TRACE;</DefineConstants>
47+
<NoWarn>1701;1702</NoWarn>
48+
</PropertyGroup>
49+
50+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
51+
<NoWarn>1701;1702</NoWarn>
52+
</PropertyGroup>
53+
54+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
55+
<NoWarn>1701;1702</NoWarn>
4556
</PropertyGroup>
4657

4758
<ItemGroup>

src/Infrastructure/BotSharp.Core/Conversations/ConversationController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public async Task<ConversationViewModel> NewConversation([FromRoute] string agen
2626
var service = _services.GetRequiredService<IConversationService>();
2727
var sess = new Conversation
2828
{
29+
UserId = _user.Id,
2930
AgentId = agentId
3031
};
3132
sess = await service.NewConversation(sess);
@@ -49,7 +50,7 @@ public async Task<MessageResponseModel> SendMessage([FromRoute] string agentId,
4950

5051
return new MessageResponseModel
5152
{
52-
Content = result
53+
Text = result
5354
};
5455
}
5556
}

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public async Task<Conversation> NewConversation(Conversation sess)
5353
var db = _services.GetRequiredService<AgentDbContext>();
5454

5555
var record = ConversationRecord.FromConversation(sess);
56-
record.Id = sess.Id ?? Guid.NewGuid().ToString();
57-
record.UserId = sess.UserId ?? _user.Id;
56+
record.Id = sess.Id.IfNullOrEmptyAs(Guid.NewGuid().ToString());
57+
record.UserId = sess.UserId.IfNullOrEmptyAs(_user.Id);
5858
record.Title = "New Conversation";
5959

6060
db.Transaction<IAgentTable>(delegate

src/Infrastructure/BotSharp.Core/Conversations/ViewModels/MessageResponseModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ namespace BotSharp.Core.Conversations.ViewModels;
22

33
public class MessageResponseModel
44
{
5-
public string Content { get; set; }
5+
public string Text { get; set; }
66
}

src/Infrastructure/BotSharp.Core/Using.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
global using BotSharp.Abstraction.Conversations;
1111
global using BotSharp.Abstraction.Knowledges;
1212
global using BotSharp.Abstraction.Users;
13+
global using BotSharp.Abstraction.Utilities;
1314
global using BotSharp.Core.Repository;
1415
global using BotSharp.Core.Repository.Abstraction;
1516
global using BotSharp.Core.Repository.DbTables;

src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
using Microsoft.Extensions.DependencyInjection;
1717
using BotSharp.Abstraction.Conversations;
1818
using BotSharp.Abstraction.Conversations.Models;
19+
using Microsoft.AspNetCore.Authorization;
1920

2021
namespace BotSharp.Plugin.ChatbotUI.Controllers;
2122

23+
[Authorize]
2224
[ApiController]
2325
public class ChatbotUiController : ControllerBase, IApiAdapter
2426
{
@@ -72,7 +74,6 @@ public async Task SendMessage([FromBody] OpenAiMessageInput input)
7274
var sess = new Conversation
7375
{
7476
Id = input.ConversationId,
75-
UserId = Guid.Empty.ToString(),
7677
AgentId = input.AgentId
7778
};
7879
converation = await conversationService.NewConversation(sess);

0 commit comments

Comments
 (0)