跳转至

events

feishu.mail.events

EventsNamespace

Bases: Namespace

邮箱事件订阅命名空间。

通过 client.mail.events 访问,封装飞书邮箱事件订阅与取消订阅接口。该接口通常需要 feishu.client.FeishuClient.as_user 派生的用户身份调用。

飞书文档

订阅事件

源代码位于: feishu/mail/events.py
Python
class EventsNamespace(Namespace):
    r"""
    邮箱事件订阅命名空间。

    通过 `client.mail.events` 访问,封装飞书邮箱事件订阅与取消订阅接口。该接口通常需要
    [feishu.client.FeishuClient.as_user][] 派生的用户身份调用。

    飞书文档:
        [订阅事件](https://open.feishu.cn/document/mail-v1/user_mailbox-event/subscribe)
    """

    async def subscribe(self, user_mailbox_id: str, *, event_type: int = 1) -> NestedDict:
        r"""
        订阅指定用户邮箱的邮件相关事件。

        Args:
            user_mailbox_id: 用户邮箱地址,或用户态调用时的 `me`。
            event_type: 事件类型,飞书当前只支持 `1`(邮件相关事件)。

        Returns:
            飞书返回的 `data` 数据体。

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

        飞书文档:
            [订阅事件](https://open.feishu.cn/document/mail-v1/user_mailbox-event/subscribe)

        Examples:
            >>> await client.as_user(user_token).mail.events.subscribe("me")  # doctest:+SKIP
            {...}
        """
        return await self._request_data(
            "POST",
            f"mail/v1/user_mailboxes/{quote_segment(user_mailbox_id)}/event/subscribe",
            json={"event_type": event_type},
        )

    async def unsubscribe(self, user_mailbox_id: str, *, event_type: int = 1) -> NestedDict:
        r"""
        取消订阅指定用户邮箱的邮件相关事件。

        Args:
            user_mailbox_id: 用户邮箱地址,或用户态调用时的 `me`。
            event_type: 事件类型,飞书当前只支持 `1`(邮件相关事件)。

        Returns:
            飞书返回的 `data` 数据体。

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

        飞书文档:
            [取消订阅事件](https://open.feishu.cn/document/mail-v1/user_mailbox-event/unsubscribe)

        Examples:
            >>> await client.as_user(user_token).mail.events.unsubscribe("me")  # doctest:+SKIP
            {...}
        """
        return await self._request_data(
            "POST",
            f"mail/v1/user_mailboxes/{quote_segment(user_mailbox_id)}/event/unsubscribe",
            json={"event_type": event_type},
        )

subscribe async

Python
subscribe(user_mailbox_id: str, *, event_type: int = 1) -> NestedDict

订阅指定用户邮箱的邮件相关事件。

参数:

名称 类型 描述 默认
user_mailbox_id
str

用户邮箱地址,或用户态调用时的 me

必需
event_type
int

事件类型,飞书当前只支持 1(邮件相关事件)。

1

返回:

类型 描述
NestedDict

飞书返回的 data 数据体。

引发:

类型 描述
FeishuError

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

飞书文档

订阅事件

示例:

Python Console Session
>>> await client.as_user(user_token).mail.events.subscribe("me")
{...}
源代码位于: feishu/mail/events.py
Python
async def subscribe(self, user_mailbox_id: str, *, event_type: int = 1) -> NestedDict:
    r"""
    订阅指定用户邮箱的邮件相关事件。

    Args:
        user_mailbox_id: 用户邮箱地址,或用户态调用时的 `me`。
        event_type: 事件类型,飞书当前只支持 `1`(邮件相关事件)。

    Returns:
        飞书返回的 `data` 数据体。

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

    飞书文档:
        [订阅事件](https://open.feishu.cn/document/mail-v1/user_mailbox-event/subscribe)

    Examples:
        >>> await client.as_user(user_token).mail.events.subscribe("me")  # doctest:+SKIP
        {...}
    """
    return await self._request_data(
        "POST",
        f"mail/v1/user_mailboxes/{quote_segment(user_mailbox_id)}/event/subscribe",
        json={"event_type": event_type},
    )

unsubscribe async

Python
unsubscribe(user_mailbox_id: str, *, event_type: int = 1) -> NestedDict

取消订阅指定用户邮箱的邮件相关事件。

参数:

名称 类型 描述 默认
user_mailbox_id
str

用户邮箱地址,或用户态调用时的 me

必需
event_type
int

事件类型,飞书当前只支持 1(邮件相关事件)。

1

返回:

类型 描述
NestedDict

飞书返回的 data 数据体。

引发:

类型 描述
FeishuError

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

飞书文档

取消订阅事件

示例:

Python Console Session
>>> await client.as_user(user_token).mail.events.unsubscribe("me")
{...}
源代码位于: feishu/mail/events.py
Python
async def unsubscribe(self, user_mailbox_id: str, *, event_type: int = 1) -> NestedDict:
    r"""
    取消订阅指定用户邮箱的邮件相关事件。

    Args:
        user_mailbox_id: 用户邮箱地址,或用户态调用时的 `me`。
        event_type: 事件类型,飞书当前只支持 `1`(邮件相关事件)。

    Returns:
        飞书返回的 `data` 数据体。

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

    飞书文档:
        [取消订阅事件](https://open.feishu.cn/document/mail-v1/user_mailbox-event/unsubscribe)

    Examples:
        >>> await client.as_user(user_token).mail.events.unsubscribe("me")  # doctest:+SKIP
        {...}
    """
    return await self._request_data(
        "POST",
        f"mail/v1/user_mailboxes/{quote_segment(user_mailbox_id)}/event/unsubscribe",
        json={"event_type": event_type},
    )