Skip to content

Commit

Permalink
增加飞书机器人接入
Browse files Browse the repository at this point in the history
  • Loading branch information
239573049 committed Mar 24, 2024
1 parent 89eb981 commit eff7854
Show file tree
Hide file tree
Showing 27 changed files with 6,413 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,39 @@ public class ChatApplicationDto
/// AI模型类型
/// </summary>
public string ChatType { get; set; }

/// <summary>
/// 扩展字段
/// </summary>
public Dictionary<string, string> Extend { get; set; } = new();

public void SetFeishuAppId(string appId)
{
Extend["FeishuAppId"] = appId;
}

public string? GetFeishuAppId()
{
return Extend.TryGetValue("FeishuAppId", out var appId) ? appId : null;
}

public void SetFeishuAppSecret(string appSecret)
{
Extend["FeishuAppSecret"] = appSecret;
}

public string? GetFeishuAppSecret()
{
return Extend.TryGetValue("FeishuAppSecret", out var appSecret) ? appSecret : null;
}

public string SetBotName(string botName)
{
return Extend["BotName"] = botName;
}

public string? GetBotName()
{
return Extend.TryGetValue("BotName", out var botName) ? botName : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ public class UpdateChatApplicationInput
/// 关联的知识库
/// </summary>
public List<long> WikiIds { get; set; }

/// <summary>
/// 扩展字段
/// </summary>
public Dictionary<string, string> Extend { get; set; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
<PackageReference Include="Masa.Utils.Models.Config" Version="$(MasaFrameworkPackageVersion)" />
</ItemGroup>

<ItemGroup>
<Folder Include="Feishu\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace FastWiki.Service.Contracts.Model.Dto;

public class FeiShuChatResult : FeiShuChatResultBase
{
public object data { get; set; }
}
public class FeiShuChatResult<T> : FeiShuChatResultBase
{
public T data { get; set; }
}
public abstract class FeiShuChatResultBase
{
public int code { get; set; }
public string msg { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Text.Json.Serialization;

namespace FastWiki.Service.Contracts.Feishu.Dto;

public sealed class FeiShuChatToken
{
[JsonPropertyName("tenant_access_token")]
public string TenantAccessToken { get; set; }

[JsonPropertyName("user_access_token")]
public string UserAccessToken { get; set; }

[JsonPropertyName("expire")] public int Expire { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace FastWiki.Service.Contracts.Model.Dto;

public sealed class FeishuChatEvent
{
public FeishuChatSender sender { get; set; }
public FeishuChatMessage message { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace FastWiki.Service.Contracts.Model.Dto;

public class FeishuChatHeader
{
public string event_id { get; set; }
public string event_type { get; set; }
public string create_time { get; set; }
public string token { get; set; }
public string app_id { get; set; }
public string tenant_key { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace FastWiki.Service.Contracts.Model.Dto;

public sealed class FeishuChatId
{
public string union_id { get; set; }
public string user_id { get; set; }
public string open_id { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Text.Json.Serialization;

namespace FastWiki.Service.Contracts.Model.Dto;

public sealed class FeishuChatInput
{
public string schema { get; set; }
public FeishuChatHeader header { get; set; }

[JsonPropertyName("event")]
public FeishuChatEvent _event { get; set; }

public string? challenge { get; set; }
public string? encrypt { get; set; }

public string? type { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace FastWiki.Service.Contracts.Model.Dto;

public sealed class FeishuChatMention
{
public string key { get; set; }
public FeishuChatId id { get; set; }
public string name { get; set; }
public string tenant_key { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace FastWiki.Service.Contracts.Model.Dto;

public sealed class FeishuChatMessage
{
public string message_id { get; set; }
public string root_id { get; set; }
public string parent_id { get; set; }
public string create_time { get; set; }
public string update_time { get; set; }
public string chat_id { get; set; }
public string chat_type { get; set; }
public string message_type { get; set; }
public string content { get; set; }
public FeishuChatMention[] mentions { get; set; }
public string user_agent { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace FastWiki.Service.Contracts.Model.Dto;

public class FeishuChatSendMessageInput(string content, string msg_type, string receive_id)
{
public string content { get; set; } = content;

public string msg_type { get; set; } = msg_type;

public string receive_id { get; set; } = receive_id;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace FastWiki.Service.Contracts.Model.Dto;

public class FeishuChatSender
{
public FeishuChatSenderId sender_id { get; set; }
public string sender_type { get; set; }
public string tenant_key { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace FastWiki.Service.Contracts.Model.Dto;

public class FeishuChatSenderId
{
public string union_id { get; set; }
public string user_id { get; set; }
public string open_id { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace FastWiki.Service.Contracts.Model.Dto;

public sealed class FeishuChatUserInput
{
public string text { get; set; }
}
11 changes: 9 additions & 2 deletions src/Service/FastWiki.Service/DataAccess/WikiDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ private static void ConfigEntities(ModelBuilder modelBuilder)
.HasConversion(
v => JsonSerializer.Serialize(v, new JsonSerializerOptions()),
v => JsonSerializer.Deserialize<List<long>>(v, new JsonSerializerOptions()));

entity.Property(x => x.Extend)
.HasConversion(
v => JsonSerializer.Serialize(v, new JsonSerializerOptions()),
v => v.IsNullOrEmpty()
? new Dictionary<string, string>()
: JsonSerializer.Deserialize<Dictionary<string, string>>(v, new JsonSerializerOptions()));
});

modelBuilder.Entity<ChatDialog>(entity =>
Expand Down Expand Up @@ -169,9 +176,9 @@ private static void ConfigEntities(ModelBuilder modelBuilder)

var user = new User("admin", "admin", "Aa123456",
"https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", "[email protected]", "13049809673", false);

user.SetAdminRole();

// 默认初始账号
modelBuilder.Entity<User>().HasData(user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@ protected ChatApplication()
public ChatApplication(string id) : base(id)
{
Opener =
"""
FastWiki本项目是一个高性能、基于最新技术栈的知识库系统,专为大规模信息检索和智能搜索设计。
利用微软Semantic Kernel进行深度学习和自然语言处理,结合.NET 8和`MasaBlazor`前端框架,后台采用`MasaFramework`,实现了一个高效、易用、可扩展的智能向量搜索平台。
我们的目标是提供一个能够理解和处理复杂查询的智能搜索解决方案,帮助用户快速准确地获取所需信息。采用Apache-2.0,您也可以完全商用不会有任何版权纠纷
[Github](https://github.com/239573049/fast-wiki)
[Gitee](https://gitee.com/hejiale010426/fast-wiki)
[项目文档](https://docs.token-ai.cn/)
"""
FastWiki本项目是一个高性能、基于最新技术栈的知识库系统,专为大规模信息检索和智能搜索设计。
利用微软Semantic Kernel进行深度学习和自然语言处理,结合.NET 8和`MasaBlazor`前端框架,后台采用`MasaFramework`,实现了一个高效、易用、可扩展的智能向量搜索平台。
我们的目标是提供一个能够理解和处理复杂查询的智能搜索解决方案,帮助用户快速准确地获取所需信息。采用Apache-2.0,您也可以完全商用不会有任何版权纠纷
[Github](https://github.com/239573049/fast-wiki)
[Gitee](https://gitee.com/hejiale010426/fast-wiki)
[项目文档](https://docs.token-ai.cn/)
当前AI提供了Avalonia中文文档知识库功能!
""";
当前AI提供了Avalonia中文文档知识库功能!
""";

Template =
""""
使用 <data></data> 标记中的内容作为你的知识:
<data>
{{quote}}
</data>
回答要求:
- 如果你不清楚答案,你需要澄清。
- 避免提及你是从 <data></data> 获取的知识。
- 保持答案与 <data></data> 中描述的一致。
- 使用 Markdown 语法优化回答格式。
- 使用与问题相同的语言回答。
- 如果 Markdown中有图片则正常显示。
问题:"""{{question}}"""
"""";
""""
使用 <data></data> 标记中的内容作为你的知识:
<data>
{{quote}}
</data>
回答要求:
- 如果你不清楚答案,你需要澄清。
- 避免提及你是从 <data></data> 获取的知识。
- 保持答案与 <data></data> 中描述的一致。
- 使用 Markdown 语法优化回答格式。
- 使用与问题相同的语言回答。
- 如果 Markdown中有图片则正常显示。
问题:"""{{question}}"""
"""";
}

public string Name { get; set; }
Expand Down Expand Up @@ -80,7 +80,7 @@ 利用微软Semantic Kernel进行深度学习和自然语言处理,结合.NET
/// 关联的知识库
/// </summary>
public List<long> WikiIds { get; set; } = new();

/// <summary>
/// 引用上限
/// </summary>
Expand All @@ -106,4 +106,10 @@ 利用微软Semantic Kernel进行深度学习和自然语言处理,结合.NET
/// AI模型类型
/// </summary>
public string ChatType { get; set; }

/// <summary>
/// 扩展字段
/// </summary>
public Dictionary<string, string> Extend { get; set; } = new();

}
Loading

0 comments on commit eff7854

Please sign in to comment.