跳转至

comments

feishu.task.comments

CommentsNamespace

Bases: Namespace

任务评论(Comment)接口命名空间。

通过 client.task.comments 访问,封装飞书任务 v2 中评论的创建与列举。评论挂载在某个资源上, 由 resource_type(默认 task)与 resource_id(任务的 guid)共同定位。

通常无需直接实例化,应通过 client.task.comments 访问。

飞书文档

创建评论

源代码位于: feishu/task/comments.py
Python
class CommentsNamespace(Namespace):
    r"""
    任务评论(Comment)接口命名空间。

    通过 `client.task.comments` 访问,封装飞书任务 v2 中评论的创建与列举。评论挂载在某个资源上,
    由 `resource_type`(默认 `task`)与 `resource_id`(任务的 `guid`)共同定位。

    通常无需直接实例化,应通过 `client.task.comments` 访问。

    飞书文档:
        [创建评论](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/task-v2/comment/create)
    """

    async def create(
        self,
        resource_id: str,
        content: str,
        *,
        resource_type: str = "task",
        user_id_type: str | None = None,
    ) -> NestedDict:
        r"""
        在任务上创建评论。

        Args:
            resource_id: 被评论资源的 ID;当 `resource_type` 为 `task` 时即任务的 `guid`。
            content: 评论内容文本。
            resource_type: 被评论资源的类型,默认 `task`。
            user_id_type: 用户 ID 的类型,如 `open_id`、`union_id`、`user_id`;为空时使用接口默认值。

        Returns:
            创建结果数据,含 `comment` 字段,内含 `id`、`content`、`creator`、`resource_id`、`resource_type`、
            `created_at` 等信息。

        Raises:
            feishu.errors.FeishuError: 请求失败或返回错误码时抛出。

        飞书文档:
            [创建评论](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/task-v2/comment/create)

        Examples:
            >>> await client.task.comments.create("d116...", "已完成初稿")  # doctest:+SKIP
            {'comment': {'id': '7654...', 'content': '已完成初稿', 'resource_id': 'd116...'}}
        """
        params: dict[str, Any] = {}
        if user_id_type is not None:
            params["user_id_type"] = user_id_type
        body = {"content": content, "resource_type": resource_type, "resource_id": resource_id}
        return await self._request_data("POST", "task/v2/comments", params=params, json=body)

    async def list(
        self,
        resource_id: str,
        *,
        resource_type: str = "task",
        user_id_type: str | None = None,
        page_size: int = 50,
        max_items: int | None = None,
    ) -> builtins.list[NestedDict]:
        r"""
        列举某个任务下的评论。

        自动翻页并汇总目标资源上的评论。

        Args:
            resource_id: 资源 ID;当 `resource_type` 为 `task` 时即任务的 `guid`。
            resource_type: 资源类型,默认 `task`。
            user_id_type: 用户 ID 的类型,如 `open_id`、`union_id`、`user_id`;为空时使用接口默认值。
            page_size: 每页数量。默认为 50;超过 [feishu.consts.MAX_PAGE_SIZE][] 时由客户端收敛。
            max_items: 最多返回的评论数量,`None` 表示不限制。默认为 `None`。

        Returns:
            评论对象列表(`data.items`);无评论时返回空列表。

        Raises:
            feishu.errors.FeishuError: 请求失败或返回错误码时抛出。

        飞书文档:
            [获取评论列表](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/task-v2/comment/list)

        Examples:
            >>> await client.task.comments.list("d116...")  # doctest:+SKIP
            [{'id': '7654...', 'content': '已完成初稿'}]
        """
        params: dict[str, Any] = {"resource_type": resource_type, "resource_id": resource_id}
        if user_id_type is not None:
            params["user_id_type"] = user_id_type
        return await self._client.paginate_get(
            "task/v2/comments", params=params, page_size=page_size, max_items=max_items
        )

create async

Python
create(resource_id: str, content: str, *, resource_type: str = 'task', user_id_type: str | None = None) -> NestedDict

在任务上创建评论。

参数:

名称 类型 描述 默认
resource_id
str

被评论资源的 ID;当 resource_typetask 时即任务的 guid

必需
content
str

评论内容文本。

必需
resource_type
str

被评论资源的类型,默认 task

'task'
user_id_type
str | None

用户 ID 的类型,如 open_idunion_iduser_id;为空时使用接口默认值。

None

返回:

类型 描述
NestedDict

创建结果数据,含 comment 字段,内含 idcontentcreatorresource_idresource_type

NestedDict

created_at 等信息。

引发:

类型 描述
FeishuError

请求失败或返回错误码时抛出。

飞书文档

创建评论

示例:

Python Console Session
>>> await client.task.comments.create("d116...", "已完成初稿")
{'comment': {'id': '7654...', 'content': '已完成初稿', 'resource_id': 'd116...'}}
源代码位于: feishu/task/comments.py
Python
async def create(
    self,
    resource_id: str,
    content: str,
    *,
    resource_type: str = "task",
    user_id_type: str | None = None,
) -> NestedDict:
    r"""
    在任务上创建评论。

    Args:
        resource_id: 被评论资源的 ID;当 `resource_type` 为 `task` 时即任务的 `guid`。
        content: 评论内容文本。
        resource_type: 被评论资源的类型,默认 `task`。
        user_id_type: 用户 ID 的类型,如 `open_id`、`union_id`、`user_id`;为空时使用接口默认值。

    Returns:
        创建结果数据,含 `comment` 字段,内含 `id`、`content`、`creator`、`resource_id`、`resource_type`、
        `created_at` 等信息。

    Raises:
        feishu.errors.FeishuError: 请求失败或返回错误码时抛出。

    飞书文档:
        [创建评论](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/task-v2/comment/create)

    Examples:
        >>> await client.task.comments.create("d116...", "已完成初稿")  # doctest:+SKIP
        {'comment': {'id': '7654...', 'content': '已完成初稿', 'resource_id': 'd116...'}}
    """
    params: dict[str, Any] = {}
    if user_id_type is not None:
        params["user_id_type"] = user_id_type
    body = {"content": content, "resource_type": resource_type, "resource_id": resource_id}
    return await self._request_data("POST", "task/v2/comments", params=params, json=body)

list async

Python
list(resource_id: str, *, resource_type: str = 'task', user_id_type: str | None = None, page_size: int = 50, max_items: int | None = None) -> list[NestedDict]

列举某个任务下的评论。

自动翻页并汇总目标资源上的评论。

参数:

名称 类型 描述 默认
resource_id
str

资源 ID;当 resource_typetask 时即任务的 guid

必需
resource_type
str

资源类型,默认 task

'task'
user_id_type
str | None

用户 ID 的类型,如 open_idunion_iduser_id;为空时使用接口默认值。

None
page_size
int

每页数量。默认为 50;超过 [feishu.consts.MAX_PAGE_SIZE][] 时由客户端收敛。

50
max_items
int | None

最多返回的评论数量,None 表示不限制。默认为 None

None

返回:

类型 描述
list[NestedDict]

评论对象列表(data.items);无评论时返回空列表。

引发:

类型 描述
FeishuError

请求失败或返回错误码时抛出。

飞书文档

获取评论列表

示例:

Python Console Session
>>> await client.task.comments.list("d116...")
[{'id': '7654...', 'content': '已完成初稿'}]
源代码位于: feishu/task/comments.py
Python
async def list(
    self,
    resource_id: str,
    *,
    resource_type: str = "task",
    user_id_type: str | None = None,
    page_size: int = 50,
    max_items: int | None = None,
) -> builtins.list[NestedDict]:
    r"""
    列举某个任务下的评论。

    自动翻页并汇总目标资源上的评论。

    Args:
        resource_id: 资源 ID;当 `resource_type` 为 `task` 时即任务的 `guid`。
        resource_type: 资源类型,默认 `task`。
        user_id_type: 用户 ID 的类型,如 `open_id`、`union_id`、`user_id`;为空时使用接口默认值。
        page_size: 每页数量。默认为 50;超过 [feishu.consts.MAX_PAGE_SIZE][] 时由客户端收敛。
        max_items: 最多返回的评论数量,`None` 表示不限制。默认为 `None`。

    Returns:
        评论对象列表(`data.items`);无评论时返回空列表。

    Raises:
        feishu.errors.FeishuError: 请求失败或返回错误码时抛出。

    飞书文档:
        [获取评论列表](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/task-v2/comment/list)

    Examples:
        >>> await client.task.comments.list("d116...")  # doctest:+SKIP
        [{'id': '7654...', 'content': '已完成初稿'}]
    """
    params: dict[str, Any] = {"resource_type": resource_type, "resource_id": resource_id}
    if user_id_type is not None:
        params["user_id_type"] = user_id_type
    return await self._client.paginate_get(
        "task/v2/comments", params=params, page_size=page_size, max_items=max_items
    )