MasterNeverDown.FeiShu.Message 1.0.0

dotnet add package MasterNeverDown.FeiShu.Message --version 1.0.0
                    
NuGet\Install-Package MasterNeverDown.FeiShu.Message -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MasterNeverDown.FeiShu.Message" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MasterNeverDown.FeiShu.Message" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MasterNeverDown.FeiShu.Message" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MasterNeverDown.FeiShu.Message --version 1.0.0
                    
#r "nuget: MasterNeverDown.FeiShu.Message, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MasterNeverDown.FeiShu.Message@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MasterNeverDown.FeiShu.Message&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MasterNeverDown.FeiShu.Message&version=1.0.0
                    
Install as a Cake Tool

Vibe.FeiShu.Message

通过 Webhook 地址向飞书自定义机器人发送消息的 .NET 库。

安装

dotnet add package Vibe.FeiShu.Message

支持的框架

  • .NET 6.0+

支持的消息类型

类型 说明
TextMessage 纯文本消息
PostMessage 富文本消息(标题、文字、链接、@人、图片)
ImageMessage 图片消息
ShareChatMessage 分享群名片
InteractiveMessage 交互卡片(传入卡片 JSON)

快速开始

创建客户端

using Vibe.FeiShu.Message;

// 不启用签名验证
using var client = new FeiShuWebhookClient("https://open.feishu.cn/open-apis/bot/v2/hook/YOUR_TOKEN");

// 启用签名验证(推荐)
using var client = new FeiShuWebhookClient(
    webhookUrl: "https://open.feishu.cn/open-apis/bot/v2/hook/YOUR_TOKEN",
    secret: "YOUR_SECRET"
);

在 ASP.NET Core 等场景中,推荐注入外部 HttpClient(传入第三个参数),客户端不会对外部 HttpClient 执行 Dispose。

发送文本消息

var result = await client.SendTextAsync("Hello 飞书!");

if (result.IsSuccess)
    Console.WriteLine("发送成功");
else
    Console.WriteLine($"发送失败:{result.Msg}");

发送富文本消息

using Vibe.FeiShu.Message.Messages;

var post = new PostMessage();
post.Content.WithZhCn(
    new PostBody { Title = "部署通知" }
        .AddLine(
            new PostTextElement("服务已成功部署,"),
            new PostLinkElement("点击查看详情", "https://your-site.com/deploy/123")
        )
        .AddLine(new PostAtElement("all"))  // @所有人
);

await client.SendAsync(post);

发送图片消息

// image_key 通过飞书开放平台上传图片获取
await client.SendImageAsync("img_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");

发送分享群名片

await client.SendShareChatAsync("oc_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

发送交互卡片

// 通过飞书卡片搭建工具生成卡片 JSON
var cardJson = """
{
  "config": { "wide_screen_mode": true },
  "header": { "title": { "tag": "plain_text", "content": "卡片标题" } },
  "elements": [
    { "tag": "div", "text": { "tag": "plain_text", "content": "卡片内容" } }
  ]
}
""";

var card = InteractiveMessage.FromJson(cardJson);
await client.SendAsync(card);

富文本元素类型

类型 说明
PostTextElement(text) 普通文字
PostLinkElement(text, href) 超链接
PostAtElement(userId) @指定用户,userId = "all" 时为 @所有人
PostImageElement(imageKey) 内嵌图片,可指定 Width/Height

签名验证

在飞书机器人配置页面开启「签名校验」后,需传入 Secret:

var client = new FeiShuWebhookClient(webhookUrl, secret: "YOUR_SECRET");

客户端会自动在每次请求时计算 timestampsign 并附加到请求 URL。

响应说明

FeiShuWebhookResponse 属性:

属性 类型 说明
IsSuccess bool Code == 0 时为 true
Code int 飞书返回的错误码,0 表示成功
Msg string 错误描述
StatusCode int HTTP 状态码

许可证

MIT

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 77 5/11/2026