Skip to content

飞书群公告 API(租户级)

接口名称

飞书群公告 API -(IFeishuTenantV1ChatGroupAnnouncement)

功能描述

群公告是群组中的公告文档,采用飞书云文档承载,每个群组只有一个群公告,每篇群公告都有唯一的 chat_id 作为标识。 当前接口使用租户令牌访问,适应于租户应用场景。

参考文档

函数列表

函数名称功能描述认证方式HTTP 方法
GetNoticeInfoByIdAsync获取群公告基本信息租户令牌GET
GetNoticeBlocksListByIdAsync分页获取群公告块列表租户令牌GET
CreateNoticeBlockAsync创建群公告块租户令牌POST
UpdateNoticeBlockAsync更新群公告块租户令牌PATCH
GetBlockContentByIdAsync获取群公告块内容租户令牌GET
GetBlockContentPageListByIdAsync分页获取块子内容租户令牌GET
DeleteBlockByIdAsync删除群公告块租户令牌DELETE

函数详细内容

获取群公告基本信息

函数名称:获取群公告基本信息

函数签名

csharp
Task<FeishuApiResult<GetAnnouncementResult>?> GetNoticeInfoByIdAsync(
    [Path] string chat_id,
    [Query("user_id_type")] string user_id_type = "open_id",
    CancellationToken cancellationToken = default);

认证:租户令牌

参数

参数类型必填说明
chat_idstring群 ID,示例:"oc_a0553eda9014c201e6969b478895c230"
user_id_typestring用户 ID 类型,默认值:"open_id"

响应

json
{
  "code": 0,
  "msg": "success",
  "data": {
    "title": "群公告标题",
    "create_time": "1690000000",
    "edit_time": "1690100000",
    "owner_id": "ou_xxxxxxxx",
    "revision": 5,
    "block_id": "doxcnxxxxxxxx"
  }
}

代码示例

csharp
public class AnnouncementService
{
    private readonly IFeishuTenantV1ChatGroupAnnouncement _announcementClient;

    public AnnouncementService(IFeishuTenantV1ChatGroupAnnouncement announcementClient)
    {
        _announcementClient = announcementClient;
    }

    public async Task DisplayAnnouncementInfoAsync(string chatId)
    {
        var result = await _announcementClient.GetNoticeInfoByIdAsync(chatId);
        if (result?.Data != null)
        {
            Console.WriteLine($"公告标题: {result.Data.title}");
            Console.WriteLine($"最后编辑时间: {result.Data.edit_time}");
            Console.WriteLine($"版本号: {result.Data.revision}");
        }
    }
}

分页获取群公告块列表

函数名称:分页获取群公告块列表

函数签名

csharp
Task<FeishuApiPageListResult<AnnouncementBlock>?> GetNoticeBlocksListByIdAsync(
    [Path] string chat_id,
    [Query("page_size")] int? page_size = 10,
    [Query("page_token")] string? page_token = null,
    [Query("revision_id")] int? revision_id = -1,
    [Query("user_id_type")] string user_id_type = "open_id",
    CancellationToken cancellationToken = default);

认证:租户令牌

参数

参数类型必填说明
chat_idstring群 ID
page_sizeint?分页大小,默认值:10
page_tokenstring?分页标记
revision_idint?群公告版本,-1 表示最新版本,默认值:-1
user_id_typestring用户 ID 类型,默认值:"open_id"

响应

json
{
  "code": 0,
  "msg": "success",
  "data": {
    "items": [
      {
        "block_id": "doxcnxxx",
        "block_type": 1,
        "content": "公告内容文本"
      }
    ],
    "has_more": false
  }
}

说明:获取群公告所有块的富文本内容并分页返回。查询历史版本需要持有编辑权限。


创建群公告块

函数名称:创建群公告块

函数签名

csharp
Task<FeishuApiResult<CreateBlockResult>?> CreateNoticeBlockAsync(
    [Path] string chat_id,
    [Path] string block_id,
    [Body] CreateBlockRequest createBlockRequest,
    [Query("revision_id")] int revision_id = -1,
    [Query("client_token")] string? client_token = null,
    [Query("user_id_type")] string user_id_type = "open_id",
    CancellationToken cancellationToken = default);

认证:租户令牌

参数

参数类型必填说明
chat_idstring群 ID
block_idstring父块 ID,填 chat_id 表示对根节点创建子块
createBlockRequestCreateBlockRequest创建块请求体
revision_idint群公告版本,-1 表示最新版本,默认值:-1
client_tokenstring?幂等操作标识
user_id_typestring用户 ID 类型,默认值:"open_id"

响应

json
{
  "code": 0,
  "msg": "success",
  "data": {
    "block_id": "doxcnNewBlock",
    "revision": 6
  }
}

更新群公告块

函数名称:更新群公告块

函数签名

csharp
Task<FeishuApiResult<BatchUpdateResult>?> UpdateNoticeBlockAsync(
    [Path] string chat_id,
    [Body] BlocksBatchUpdateRequest batchUpdateRequest,
    [Query("revision_id")] int revision_id = -1,
    [Query("client_token")] string? client_token = null,
    [Query("user_id_type")] string user_id_type = "open_id",
    CancellationToken cancellationToken = default);

认证:租户令牌

参数

参数类型必填说明
chat_idstring群 ID
batchUpdateRequestBlocksBatchUpdateRequest批量更新块内容请求体
revision_idint群公告版本,默认值:-1
client_tokenstring?幂等操作标识
user_id_typestring用户 ID 类型,默认值:"open_id"

响应

json
{
  "code": 0,
  "msg": "success",
  "data": {
    "revision": 7
  }
}

说明:批量更新块的富文本内容。


获取群公告块内容

函数名称:获取群公告块内容

函数签名

csharp
Task<FeishuApiResult<GetBlockContentListResult>?> GetBlockContentByIdAsync(
    [Path] string chat_id,
    [Path] string block_id,
    [Query("revision_id")] int? revision_id = -1,
    [Query("user_id_type")] string? user_id_type = "open_id",
    CancellationToken cancellationToken = default);

认证:租户令牌

参数

参数类型必填说明
chat_idstring群 ID
block_idstringBlock 唯一标识,示例:"doxcnO6UW6wAw2qIcYf4hZabcef"
revision_idint?群公告版本,默认值:-1
user_id_typestring?用户 ID 类型,默认值:"open_id"

响应

json
{
  "code": 0,
  "msg": "success",
  "data": {
    "block_id": "doxcnxxx",
    "block_type": 1,
    "content": {
      "elements": [
        {
          "type": "text",
          "text": "块内容文本"
        }
      ]
    }
  }
}

分页获取块子内容

函数名称:分页获取块子内容

函数签名

csharp
Task<FeishuApiPageListResult<AnnouncementBlock>?> GetBlockContentPageListByIdAsync(
    [Path] string chat_id,
    [Path] string block_id,
    [Query("page_size")] int? page_size = 10,
    [Query("page_token")] string? page_token = null,
    [Query("revision_id")] int? revision_id = -1,
    [Query("user_id_type")] string? user_id_type = "open_id",
    CancellationToken cancellationToken = default);

认证:租户令牌

参数

参数类型必填说明
chat_idstring群 ID
block_idstringBlock 唯一标识
page_sizeint?分页大小,默认值:10
page_tokenstring?分页标记
revision_idint?群公告版本,默认值:-1
user_id_typestring?用户 ID 类型,默认值:"open_id"

响应

json
{
  "code": 0,
  "msg": "success",
  "data": {
    "items": [
      {
        "block_id": "doxcnChild1",
        "block_type": 2
      }
    ],
    "has_more": false
  }
}

删除群公告块

函数名称:删除群公告块

函数签名

csharp
Task<FeishuApiResult<DeleteAnnouncementBlockResult>?> DeleteBlockByIdAsync(
    [Path] string chat_id,
    [Path] string block_id,
    [Body] DeleteAnnouncementBlockRequest deleteRequest,
    [Query("user_id_type")] string? user_id_type = "open_id",
    [Query("client_token")] string? client_token = null,
    CancellationToken cancellationToken = default);

认证:租户令牌

参数

参数类型必填说明
chat_idstring群 ID
block_idstringBlock 唯一标识
deleteRequestDeleteAnnouncementBlockRequest删除请求体
user_id_typestring?用户 ID 类型,默认值:"open_id"
client_tokenstring?幂等操作标识

响应

json
{
  "code": 0,
  "msg": "success",
  "data": {
    "revision": 8
  }
}

说明:指定需要操作的块,删除其指定范围的子块。操作成功后返回群公告版本号。