From c84d7288c030a48d6c2061c3f7131c9560bb5a45 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Sun, 13 Oct 2024 18:11:40 -0500 Subject: [PATCH] UserLanguage not null --- .../BotSharp.Abstraction/Users/IUserIdentity.cs | 5 ++++- .../BotSharp.Core/Users/Services/UserIdentity.cs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/IUserIdentity.cs b/src/Infrastructure/BotSharp.Abstraction/Users/IUserIdentity.cs index 347e7554..2eb1ec9d 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Users/IUserIdentity.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Users/IUserIdentity.cs @@ -8,7 +8,10 @@ public interface IUserIdentity string FirstName { get; } string LastName { get; } string FullName { get; } - string? UserLanguage { get; } + /// + /// "en-US", "zh-CN" + /// + string UserLanguage { get; } string? Phone { get; } string? AffiliateId { get; } } diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserIdentity.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserIdentity.cs index 531fd286..14f09c0e 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserIdentity.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserIdentity.cs @@ -58,12 +58,12 @@ public class UserIdentity : IUserIdentity } [JsonPropertyName("user_language")] - public string? UserLanguage + public string UserLanguage { get { _contextAccessor.HttpContext.Request.Headers.TryGetValue("User-Language", out var languages); - return languages.FirstOrDefault(); + return languages.FirstOrDefault() ?? "en-US"; } }