跳转至

utils

feishu.utils

async_delete async

Python
async_delete(dest: str, data: Dict | None = None, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, **kwargs) -> NestedDict

向指定目的地发送 DELETE 请求。

Parameters:

Name Type Description Default

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

headers

Dict | None

请求头。默认为 {}

None

params

Dict | None

请求参数。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

Examples:

Python Console Session
>>> import asyncio
>>> loop = asyncio.get_event_loop()
>>> loop.run_until_complete(
...     async_delete(
...         'im/v1/messages/:message_id',
...         app_id='cli_slkdjalasdkjasd',
...         app_secret='dskLLdkasdjlasdKK'
...     )
... )
NestedDict(
  ('code'): 0
  ('msg'): 'success'
  ('data'): NestedDict()
)
Source code in feishu/utils/async_request.py
Python
async def async_delete(
    dest: str,
    data: Dict | None = None,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送 DELETE 请求。

    Args:
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        headers: 请求头。默认为 `{}`。
        params: 请求参数。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。

    Examples:
        >>> import asyncio
        >>> loop = asyncio.get_event_loop()
        >>> loop.run_until_complete(
        ...     async_delete(
        ...         'im/v1/messages/:message_id',
        ...         app_id='cli_slkdjalasdkjasd',
        ...         app_secret='dskLLdkasdjlasdKK'
        ...     )
        ... )  # doctest:+SKIP
        NestedDict(
          ('code'): 0
          ('msg'): 'success'
          ('data'): NestedDict()
        )
    """
    return await async_request(
        "DELETE",
        dest,
        data=data,
        params=params,
        headers=headers,
        timeout=timeout,
        token=token,
        app_id=app_id,
        app_secret=app_secret,
        **kwargs,
    )

async_get async

Python
async_get(dest: str, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, **kwargs) -> NestedDict

向指定目的地发送 GET 请求。

Parameters:

Name Type Description Default

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

headers

Dict | None

请求头。默认为 {}

None

params

Dict | None

请求参数。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

Examples:

Python Console Session
>>> import asyncio
>>> loop = asyncio.get_event_loop()
>>> loop.run_until_complete(
...     async_get(
...         'im/v1/messages/:message_id',
...         app_id='cli_slkdjalasdkjasd',
...         app_secret='dskLLdkasdjlasdKK'
...     )
... )
NestedDict(
  ('code'): 0
  ('msg'): 'success'
  ('data'): NestedDict(
    ('items'): [NestedDict(
      ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
      ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
      ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
      ('thread_id'): 'omt_d4be107c616a'
      ('msg_type'): 'card'
      ('create_time'): '1635675360'
      ('update_time'): '1635675360'
      ('deleted'): False
      ('updated'): False
      ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
      ('sender'): NestedDict(
        ('id'): 'cli_9f427eec54ae901b'
        ('id_type'): 'app_id'
        ('sender_type'): 'app'
        ('tenant_key'): '736588c9260f175e'
      )
      ('body'): NestedDict(
        ('content'): '{"text":"@_user_1 test content"}'
      )
      ('mentions'): [NestedDict(
        ('key'): '@_user_1'
        ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
        ('id_type'): 'open_id'
        ('name'): 'Chang'
        ('tenant_key'): '736588c9260f175e'
      )]
    ('upper_message_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
    )]
  )
)
Source code in feishu/utils/async_request.py
Python
async def async_get(
    dest: str,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送 GET 请求。

    Args:
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        headers: 请求头。默认为 `{}`。
        params: 请求参数。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。

    Examples:
        >>> import asyncio
        >>> loop = asyncio.get_event_loop()
        >>> loop.run_until_complete(
        ...     async_get(
        ...         'im/v1/messages/:message_id',
        ...         app_id='cli_slkdjalasdkjasd',
        ...         app_secret='dskLLdkasdjlasdKK'
        ...     )
        ... )  # doctest:+SKIP
        NestedDict(
          ('code'): 0
          ('msg'): 'success'
          ('data'): NestedDict(
            ('items'): [NestedDict(
              ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
              ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
              ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
              ('thread_id'): 'omt_d4be107c616a'
              ('msg_type'): 'card'
              ('create_time'): '1635675360'
              ('update_time'): '1635675360'
              ('deleted'): False
              ('updated'): False
              ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
              ('sender'): NestedDict(
                ('id'): 'cli_9f427eec54ae901b'
                ('id_type'): 'app_id'
                ('sender_type'): 'app'
                ('tenant_key'): '736588c9260f175e'
              )
              ('body'): NestedDict(
                ('content'): '{"text":"@_user_1 test content"}'
              )
              ('mentions'): [NestedDict(
                ('key'): '@_user_1'
                ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
                ('id_type'): 'open_id'
                ('name'): 'Chang'
                ('tenant_key'): '736588c9260f175e'
              )]
            ('upper_message_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
            )]
          )
        )
    """
    return await async_request(
        "GET",
        dest,
        headers=headers,
        params=params,
        timeout=timeout,
        token=token,
        app_id=app_id,
        app_secret=app_secret,
        **kwargs,
    )

async_patch async

Python
async_patch(dest: str, data: Dict | None = None, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, **kwargs) -> NestedDict

向指定目的地发送 PUT 请求。

Parameters:

Name Type Description Default

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

headers

Dict | None

请求头。默认为 {}

None

params

Dict | None

请求参数。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

Examples:

Python Console Session
>>> import asyncio
>>> data = {"content": "{\"text\":\"test content\"}"}
>>> loop = asyncio.get_event_loop()
>>> loop.run_until_complete(
...     async_patch(
...         'im/v1/messages/:message_id',
...         data=data,
...         app_id='cli_slkdjalasdkjasd',
...         app_secret='dskLLdkasdjlasdKK'
...     )
... )
NestedDict(
  ('code'): 0
  ('msg'): 'success'
  ('data'): NestedDict()
)
Source code in feishu/utils/async_request.py
Python
async def async_patch(
    dest: str,
    data: Dict | None = None,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送 PUT 请求。

    Args:
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        headers: 请求头。默认为 `{}`。
        params: 请求参数。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。

    Examples:
        >>> import asyncio
        >>> data = {"content": "{\"text\":\"test content\"}"}
        >>> loop = asyncio.get_event_loop()
        >>> loop.run_until_complete(
        ...     async_patch(
        ...         'im/v1/messages/:message_id',
        ...         data=data,
        ...         app_id='cli_slkdjalasdkjasd',
        ...         app_secret='dskLLdkasdjlasdKK'
        ...     )
        ... )  # doctest:+SKIP
        NestedDict(
          ('code'): 0
          ('msg'): 'success'
          ('data'): NestedDict()
        )
    """
    return await async_request(
        "PATCH",
        dest,
        data=data,
        params=params,
        headers=headers,
        timeout=timeout,
        token=token,
        app_id=app_id,
        app_secret=app_secret,
        **kwargs,
    )

async_post async

Python
async_post(dest: str, data: Dict | None = None, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, **kwargs) -> NestedDict

向指定目的地发送 POST 请求。

Parameters:

Name Type Description Default

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

headers

Dict | None

请求头。默认为 {}

None

params

Dict | None

请求参数。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

Examples:

Python Console Session
>>> import asyncio
>>> data = {
...     "receive_id_type": "open_id",
...     "receive_id": "ou_7d8a6e6df7621556ce0d21922b676706ccs",
...     "msg_type": "text",
...     "content": "{\"text\":\"test content\"}",
...     "uuid": "a0d69e20-1dd1-458b-k525-dfeca4015204"
... }
>>> loop = asyncio.get_event_loop()
>>> loop.run_until_complete(
...     async_post(
...         'im/v1/messages',
...         data=data,
...         app_id='cli_slkdjalasdkjasd',
...         app_secret='dskLLdkasdjlasdKK'
...     )
... )
NestedDict(
  ('code'): 0
  ('msg'): 'success'
  ('data'): NestedDict(
    ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
    ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
    ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
    ('thread_id'): 'omt_d4be107c616a'
    ('msg_type'): 'card'
    ('create_time'): '1635675360'
    ('update_time'): '1635675360'
    ('deleted'): False
    ('updated'): False
    ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
    ('sender'): NestedDict(
      ('id'): 'cli_9f427eec54ae901b'
      ('id_type'): 'app_id'
      ('sender_type'): 'app'
      ('tenant_key'): '736588c9260f175e'
    )
    ('body'): NestedDict(
      ('content'): '{"text":"@_user_1 test content"}'
    )
    ('mentions'): [NestedDict(
      ('key'): '@_user_1'
      ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
      ('id_type'): 'open_id'
      ('name'): 'Chang'
      ('tenant_key'): '736588c9260f175e'
    )]
    ('upper_message_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
  )
)
Source code in feishu/utils/async_request.py
Python
async def async_post(
    dest: str,
    data: Dict | None = None,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送 POST 请求。

    Args:
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        headers: 请求头。默认为 `{}`。
        params: 请求参数。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。

    Examples:
        >>> import asyncio
        >>> data = {
        ...     "receive_id_type": "open_id",
        ...     "receive_id": "ou_7d8a6e6df7621556ce0d21922b676706ccs",
        ...     "msg_type": "text",
        ...     "content": "{\"text\":\"test content\"}",
        ...     "uuid": "a0d69e20-1dd1-458b-k525-dfeca4015204"
        ... }
        >>> loop = asyncio.get_event_loop()
        >>> loop.run_until_complete(
        ...     async_post(
        ...         'im/v1/messages',
        ...         data=data,
        ...         app_id='cli_slkdjalasdkjasd',
        ...         app_secret='dskLLdkasdjlasdKK'
        ...     )
        ... )  # doctest:+SKIP
        NestedDict(
          ('code'): 0
          ('msg'): 'success'
          ('data'): NestedDict(
            ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
            ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
            ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
            ('thread_id'): 'omt_d4be107c616a'
            ('msg_type'): 'card'
            ('create_time'): '1635675360'
            ('update_time'): '1635675360'
            ('deleted'): False
            ('updated'): False
            ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
            ('sender'): NestedDict(
              ('id'): 'cli_9f427eec54ae901b'
              ('id_type'): 'app_id'
              ('sender_type'): 'app'
              ('tenant_key'): '736588c9260f175e'
            )
            ('body'): NestedDict(
              ('content'): '{"text":"@_user_1 test content"}'
            )
            ('mentions'): [NestedDict(
              ('key'): '@_user_1'
              ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
              ('id_type'): 'open_id'
              ('name'): 'Chang'
              ('tenant_key'): '736588c9260f175e'
            )]
            ('upper_message_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
          )
        )
    """
    return await async_request(
        "POST",
        dest,
        data=data,
        params=params,
        headers=headers,
        timeout=timeout,
        token=token,
        app_id=app_id,
        app_secret=app_secret,
        **kwargs,
    )

async_put async

Python
async_put(dest: str, data: Dict | None = None, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, **kwargs) -> NestedDict

向指定目的地发送 PUT 请求。

Parameters:

Name Type Description Default

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

headers

Dict | None

请求头。默认为 {}

None

params

Dict | None

请求参数。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

Examples:

Python Console Session
>>> import asyncio
>>> data = {"msg_type": "text", "content": "{\"text\":\"test content\"}"}
>>> loop = asyncio.get_event_loop()
>>> loop.run_until_complete(
...     async_put(
...         'im/v1/messages/:message_id',
...         data=data,
...         app_id='cli_slkdjalasdkjasd',
...         app_secret='dskLLdkasdjlasdKK'
...     )
... )
NestedDict(
  ('code'): 0
  ('msg'): 'success'
  ('data'): NestedDict(
    ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
    ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
    ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
    ('thread_id'): 'omt_d4be107c616a'
    ('msg_type'): 'card'
    ('create_time'): '1635675360'
    ('update_time'): '1635675420'
    ('deleted'): False
    ('updated'): True
    ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
    ('sender'): NestedDict(
      ('id'): 'cli_9f427eec54ae901b'
      ('id_type'): 'app_id'
      ('sender_type'): 'app'
      ('tenant_key'): '736588c9260f175e'
    )
    ('body'): NestedDict(
      ('content'): '{"text":"@_user_1 test content"}'
    )
    ('mentions'): [NestedDict(
      ('key'): '@_user_1'
      ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
      ('id_type'): 'open_id'
      ('name'): 'Chang'
      ('tenant_key'): '736588c9260f175e'
    )]
    ('upper_message_id'): 'om_40eb06e7b84dc71c03e00ida3c754892'
  )
)
Source code in feishu/utils/async_request.py
Python
async def async_put(
    dest: str,
    data: Dict | None = None,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送 PUT 请求。

    Args:
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        headers: 请求头。默认为 `{}`。
        params: 请求参数。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。

    Examples:
        >>> import asyncio
        >>> data = {"msg_type": "text", "content": "{\"text\":\"test content\"}"}
        >>> loop = asyncio.get_event_loop()
        >>> loop.run_until_complete(
        ...     async_put(
        ...         'im/v1/messages/:message_id',
        ...         data=data,
        ...         app_id='cli_slkdjalasdkjasd',
        ...         app_secret='dskLLdkasdjlasdKK'
        ...     )
        ... )  # doctest:+SKIP
        NestedDict(
          ('code'): 0
          ('msg'): 'success'
          ('data'): NestedDict(
            ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
            ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
            ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
            ('thread_id'): 'omt_d4be107c616a'
            ('msg_type'): 'card'
            ('create_time'): '1635675360'
            ('update_time'): '1635675420'
            ('deleted'): False
            ('updated'): True
            ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
            ('sender'): NestedDict(
              ('id'): 'cli_9f427eec54ae901b'
              ('id_type'): 'app_id'
              ('sender_type'): 'app'
              ('tenant_key'): '736588c9260f175e'
            )
            ('body'): NestedDict(
              ('content'): '{"text":"@_user_1 test content"}'
            )
            ('mentions'): [NestedDict(
              ('key'): '@_user_1'
              ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
              ('id_type'): 'open_id'
              ('name'): 'Chang'
              ('tenant_key'): '736588c9260f175e'
            )]
            ('upper_message_id'): 'om_40eb06e7b84dc71c03e00ida3c754892'
          )
        )
    """
    return await async_request(
        "PUT",
        dest,
        data=data,
        params=params,
        headers=headers,
        timeout=timeout,
        token=token,
        app_id=app_id,
        app_secret=app_secret,
        **kwargs,
    )

decrypt

Python
decrypt(request: str | dict) -> NestedDict

解密飞书请求

Parameters:

Name Type Description Default

request

str | dict

飞书请求

required
飞书文档

配置 Encrypt Key

Source code in feishu/utils/crypto.py
Python
def decrypt(request: str | dict) -> NestedDict:
    r"""
    解密飞书请求

    Args:
        request: 飞书请求

    飞书文档:
        [配置 Encrypt Key](https://open.feishu.cn/document/server-docs/event-subscription-guide/event-subscription-configure-/configure-encrypt-key)
    """  # noqa: E501
    if isinstance(request, str):
        encrypted = request
    if isinstance(request, dict):
        encrypted = request["encrypt"]
    return NestedDict.from_jsons(AESCipher(variables.ENCRYPT_KEY).decrypt(encrypted))  # type: ignore[arg-type]

authorize

Python
authorize(func: Callable) -> Callable

授权装饰器,用于自动注入 app_id 和 app_secret。

Source code in feishu/utils/decorators.py
Python
def authorize(func: Callable) -> Callable:
    r"""
    授权装饰器,用于自动注入 app_id 和 app_secret。
    """

    @wraps(func)
    def wrapper(*args, **kwargs):
        # Check if token, app_id, and app_secret are provided in kwargs
        token = kwargs.get("token")
        app_id = kwargs.get("app_id")
        app_secret = kwargs.get("app_secret")

        # If not provided, raise an error or fetch them from somewhere else
        if token is None:
            if app_id is None:
                if not hasattr(variables, "APP_ID") and variables.APP_ID:
                    raise ValueError("app_id is not provided and not found in variables")
                app_id = kwargs["app_id"] = variables.APP_ID
            if app_secret is None:
                if not hasattr(variables, "APP_SECRET") and variables.APP_SECRET:
                    raise ValueError("app_secret is not provided and not found in variables")
                app_secret = kwargs["app_secret"] = variables.APP_SECRET

        # Call the original function with provided authorization details
        return func(*args, **kwargs)

    return wrapper

flexible_decorator

Python
flexible_decorator(maybe_decorator: Optional[Callable] = None)

元装饰器,使得装饰器可以在不接受参数时直接使用,也可以接受参数。

Examples:

For decorator defined as follows:

Python Console Session
1
2
3
4
5
>>> @flexible_decorator
... def decorator(*args, **kwargs):
...     def wrapper(func, *args, **kwargs):
...         pass
...     return wrapper

The following two are equivalent:

Python Console Session
1
2
3
>>> @decorator
... def func(*args, **kwargs):
...     pass
Python Console Session
1
2
3
>>> @decorator()
... def func(*args, **kwargs):
...     pass
Source code in feishu/utils/decorators.py
Python
def flexible_decorator(maybe_decorator: Optional[Callable] = None):
    r"""
    元装饰器,使得装饰器可以在不接受参数时直接使用,也可以接受参数。

    Examples:
        For decorator defined as follows:

        >>> @flexible_decorator
        ... def decorator(*args, **kwargs):
        ...     def wrapper(func, *args, **kwargs):
        ...         pass
        ...     return wrapper

        The following two are equivalent:

        >>> @decorator
        ... def func(*args, **kwargs):
        ...     pass

        >>> @decorator()
        ... def func(*args, **kwargs):
        ...     pass
    """

    def decorator(func: Callable):
        @wraps(func)
        def wrapper(*args, **kwargs):
            if len(args) == 1 and isfunction(args[0]):
                return func(**kwargs)(args[0])
            return func(*args, **kwargs)

        return wrapper

    if maybe_decorator is None:
        return decorator
    return decorator(maybe_decorator)

pagination

Python
pagination(early_stop: Callable | None = None)

分页装饰器,用于收集分页数据。

Parameters:

Name Type Description Default

early_stop

Callable | None

判断是否提前停止的函数。默认为 None。 该函数应当接受两个参数,分别是累积的所有数据,和即将添加的数据。 如果返回 True,则停止将数据添加到累积的数据中,并返回结果。

None

注意: 该装饰器会读取函数参数中的 stop_on_pagestop_on_accum 参数,如果没有提供则使用默认值。

Source code in feishu/utils/decorators.py
Python
@flexible_decorator
def pagination(early_stop: Callable | None = None):
    r"""
    分页装饰器,用于收集分页数据。

    Args:
        early_stop: 判断是否提前停止的函数。默认为 `None`。
            该函数应当接受两个参数,分别是累积的所有数据,和即将添加的数据。
            如果返回 `True`,则停止将数据添加到累积的数据中,并返回结果。

    注意:
        该装饰器会读取函数参数中的 `stop_on_page` 和 `stop_on_accum` 参数,如果没有提供则使用默认值。
    """

    def decorator(func: Callable | Callable[..., Awaitable[NestedDict]]) -> Callable:
        # Zhiyuan: Can pagination work with async functions?
        @wraps(func)
        async def wrapper_async(*args, **kwargs):
            _early_stop = kwargs.pop("early_stop", early_stop)
            max_num_items = kwargs.pop("max_num_items", None)
            early_break = False
            kwargs.pop("page_token", None)
            all_items = []
            page_token = None

            while True:
                response = await func(*args, **kwargs, page_token=page_token)
                items = response["data"]["items"]
                if max_num_items is not None:
                    items = items[: max_num_items - len(all_items)]
                    if not items:
                        early_break = True
                        break
                if _early_stop is not None:
                    for item in items:
                        if _early_stop(all_items, item):
                            early_break = True
                            break
                        all_items.append(item)
                else:
                    all_items.extend(items)
                if early_break or not response["data"].get("has_more"):
                    break
                page_token = response["data"]["page_token"]

            response["data"]["items"] = all_items
            return response

        @wraps(func)
        def wrapper_sync(*args, **kwargs):
            _early_stop = kwargs.pop("early_stop", early_stop)
            max_num_items = kwargs.pop("max_num_items", None)
            early_break = False
            kwargs.pop("page_token", None)
            all_items = []
            page_token = None

            while True:
                response = func(*args, **kwargs, page_token=page_token)
                items = response["data"]["items"]
                if max_num_items is not None:
                    items = items[: max_num_items - len(all_items)]
                    if not items:
                        early_break = True
                        break
                if _early_stop is not None:
                    for item in items:
                        if _early_stop(all_items, item):
                            early_break = True
                            break
                        all_items.append(item)
                else:
                    all_items.extend(items)
                if early_break or not response["data"].get("has_more"):
                    break
                page_token = response["data"]["page_token"]

            response["data"]["items"] = all_items
            return response

        return wrapper_async if asyncio.iscoroutinefunction(func) else wrapper_sync

    return decorator

delete

Python
delete(dest: str, data: Dict | None = None, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, **kwargs) -> NestedDict

向指定目的地发送 DELETE 请求。

Parameters:

Name Type Description Default

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

headers

Dict | None

请求头。默认为 {}

None

params

Dict | None

请求参数。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

Examples:

Python Console Session
>>> delete(
...     'im/v1/messages/:message_id',
...     app_id='cli_slkdjalasdkjasd',
...     app_secret='dskLLdkasdjlasdKK'
... )
NestedDict(
  ('code'): 0
  ('msg'): 'success'
  ('data'): NestedDict()
)
Source code in feishu/utils/request.py
Python
def delete(
    dest: str,
    data: Dict | None = None,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送 DELETE 请求。

    Args:
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        headers: 请求头。默认为 `{}`。
        params: 请求参数。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。

    Examples:
        >>> delete(
        ...     'im/v1/messages/:message_id',
        ...     app_id='cli_slkdjalasdkjasd',
        ...     app_secret='dskLLdkasdjlasdKK'
        ... )  # doctest:+SKIP
        NestedDict(
          ('code'): 0
          ('msg'): 'success'
          ('data'): NestedDict()
        )
    """
    return request(
        "DELETE",
        dest,
        data=data,
        params=params,
        headers=headers,
        timeout=timeout,
        token=token,
        app_id=app_id,
        app_secret=app_secret,
        **kwargs,
    )

get

Python
get(dest: str, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, **kwargs) -> NestedDict

向指定目的地发送 GET 请求。

Parameters:

Name Type Description Default

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

headers

Dict | None

请求头。默认为 {}

None

params

Dict | None

请求参数。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

Examples:

Python Console Session
>>> get(
...     'im/v1/messages/:message_id',
...     app_id='cli_slkdjalasdkjasd',
...     app_secret='dskLLdkasdjlasdKK'
... )
NestedDict(
  ('code'): 0
  ('msg'): 'success'
  ('data'): NestedDict(
    ('items'): [NestedDict(
      ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
      ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
      ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
      ('thread_id'): 'omt_d4be107c616a'
      ('msg_type'): 'card'
      ('create_time'): '1635675360'
      ('update_time'): '1635675360'
      ('deleted'): False
      ('updated'): False
      ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
      ('sender'): NestedDict(
        ('id'): 'cli_9f427eec54ae901b'
        ('id_type'): 'app_id'
        ('sender_type'): 'app'
        ('tenant_key'): '736588c9260f175e'
      )
      ('body'): NestedDict(
        ('content'): '{"text":"@_user_1 test content"}'
      )
      ('mentions'): [NestedDict(
        ('key'): '@_user_1'
        ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
        ('id_type'): 'open_id'
        ('name'): 'Chang'
        ('tenant_key'): '736588c9260f175e'
      )]
    ('upper_message_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
    )]
  )
)
Source code in feishu/utils/request.py
Python
def get(
    dest: str,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送 GET 请求。

    Args:
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        headers: 请求头。默认为 `{}`。
        params: 请求参数。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。

    Examples:
        >>> get(
        ...     'im/v1/messages/:message_id',
        ...     app_id='cli_slkdjalasdkjasd',
        ...     app_secret='dskLLdkasdjlasdKK'
        ... )  # doctest:+SKIP
        NestedDict(
          ('code'): 0
          ('msg'): 'success'
          ('data'): NestedDict(
            ('items'): [NestedDict(
              ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
              ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
              ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
              ('thread_id'): 'omt_d4be107c616a'
              ('msg_type'): 'card'
              ('create_time'): '1635675360'
              ('update_time'): '1635675360'
              ('deleted'): False
              ('updated'): False
              ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
              ('sender'): NestedDict(
                ('id'): 'cli_9f427eec54ae901b'
                ('id_type'): 'app_id'
                ('sender_type'): 'app'
                ('tenant_key'): '736588c9260f175e'
              )
              ('body'): NestedDict(
                ('content'): '{"text":"@_user_1 test content"}'
              )
              ('mentions'): [NestedDict(
                ('key'): '@_user_1'
                ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
                ('id_type'): 'open_id'
                ('name'): 'Chang'
                ('tenant_key'): '736588c9260f175e'
              )]
            ('upper_message_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
            )]
          )
        )
    """
    return request(
        "GET",
        dest,
        headers=headers,
        params=params,
        timeout=timeout,
        token=token,
        app_id=app_id,
        app_secret=app_secret,
        **kwargs,
    )

patch

Python
patch(dest: str, data: Dict | None = None, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, **kwargs) -> NestedDict

向指定目的地发送 PUT 请求。

Parameters:

Name Type Description Default

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

headers

Dict | None

请求头。默认为 {}

None

params

Dict | None

请求参数。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

Examples:

Python Console Session
>>> data = {"content": "{\"text\":\"test content\"}"}
>>> patch(
...     'im/v1/messages/:message_id',
...     data=data,
...     app_id='cli_slkdjalasdkjasd',
...     app_secret='dskLLdkasdjlasdKK'
... )
NestedDict(
  ('code'): 0
  ('msg'): 'success'
  ('data'): NestedDict()
)
Source code in feishu/utils/request.py
Python
def patch(
    dest: str,
    data: Dict | None = None,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送 PUT 请求。

    Args:
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        headers: 请求头。默认为 `{}`。
        params: 请求参数。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。

    Examples:
        >>> data = {"content": "{\"text\":\"test content\"}"}
        >>> patch(
        ...     'im/v1/messages/:message_id',
        ...     data=data,
        ...     app_id='cli_slkdjalasdkjasd',
        ...     app_secret='dskLLdkasdjlasdKK'
        ... )  # doctest:+SKIP
        NestedDict(
          ('code'): 0
          ('msg'): 'success'
          ('data'): NestedDict()
        )
    """
    return request(
        "PATCH",
        dest,
        data=data,
        params=params,
        headers=headers,
        timeout=timeout,
        token=token,
        app_id=app_id,
        app_secret=app_secret,
        **kwargs,
    )

post

Python
post(dest: str, data: Dict | None = None, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, **kwargs) -> NestedDict

向指定目的地发送 POST 请求。

Parameters:

Name Type Description Default

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

headers

Dict | None

请求头。默认为 {}

None

params

Dict | None

请求参数。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

Examples:

Python Console Session
>>> data = {
...     "receive_id_type": "open_id",
...     "receive_id": "ou_7d8a6e6df7621556ce0d21922b676706ccs",
...     "msg_type": "text",
...     "content": "{\"text\":\"test content\"}",
...     "uuid": "a0d69e20-1dd1-458b-k525-dfeca4015204"
... }
>>> post(
...     'im/v1/messages',
...     data=data,
...     app_id='cli_slkdjalasdkjasd',
...     app_secret='dskLLdkasdjlasdKK'
... )
NestedDict(
  ('code'): 0
  ('msg'): 'success'
  ('data'): NestedDict(
    ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
    ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
    ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
    ('thread_id'): 'omt_d4be107c616a'
    ('msg_type'): 'card'
    ('create_time'): '1635675360'
    ('update_time'): '1635675360'
    ('deleted'): False
    ('updated'): False
    ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
    ('sender'): NestedDict(
      ('id'): 'cli_9f427eec54ae901b'
      ('id_type'): 'app_id'
      ('sender_type'): 'app'
      ('tenant_key'): '736588c9260f175e'
    )
    ('body'): NestedDict(
      ('content'): '{"text":"@_user_1 test content"}'
    )
    ('mentions'): [NestedDict(
      ('key'): '@_user_1'
      ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
      ('id_type'): 'open_id'
      ('name'): 'Chang'
      ('tenant_key'): '736588c9260f175e'
    )]
    ('upper_message_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
  )
)
Source code in feishu/utils/request.py
Python
def post(
    dest: str,
    data: Dict | None = None,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送 POST 请求。

    Args:
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        headers: 请求头。默认为 `{}`。
        params: 请求参数。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。

    Examples:
        >>> data = {
        ...     "receive_id_type": "open_id",
        ...     "receive_id": "ou_7d8a6e6df7621556ce0d21922b676706ccs",
        ...     "msg_type": "text",
        ...     "content": "{\"text\":\"test content\"}",
        ...     "uuid": "a0d69e20-1dd1-458b-k525-dfeca4015204"
        ... }
        >>> post(
        ...     'im/v1/messages',
        ...     data=data,
        ...     app_id='cli_slkdjalasdkjasd',
        ...     app_secret='dskLLdkasdjlasdKK'
        ... )  # doctest:+SKIP
        NestedDict(
          ('code'): 0
          ('msg'): 'success'
          ('data'): NestedDict(
            ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
            ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
            ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
            ('thread_id'): 'omt_d4be107c616a'
            ('msg_type'): 'card'
            ('create_time'): '1635675360'
            ('update_time'): '1635675360'
            ('deleted'): False
            ('updated'): False
            ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
            ('sender'): NestedDict(
              ('id'): 'cli_9f427eec54ae901b'
              ('id_type'): 'app_id'
              ('sender_type'): 'app'
              ('tenant_key'): '736588c9260f175e'
            )
            ('body'): NestedDict(
              ('content'): '{"text":"@_user_1 test content"}'
            )
            ('mentions'): [NestedDict(
              ('key'): '@_user_1'
              ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
              ('id_type'): 'open_id'
              ('name'): 'Chang'
              ('tenant_key'): '736588c9260f175e'
            )]
            ('upper_message_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
          )
        )
    """
    return request(
        "POST",
        dest,
        data=data,
        params=params,
        headers=headers,
        timeout=timeout,
        token=token,
        app_id=app_id,
        app_secret=app_secret,
        **kwargs,
    )

put

Python
put(dest: str, data: Dict | None = None, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, **kwargs) -> NestedDict

向指定目的地发送 PUT 请求。

Parameters:

Name Type Description Default

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

headers

Dict | None

请求头。默认为 {}

None

params

Dict | None

请求参数。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

Examples:

Python Console Session
>>> data = {"msg_type": "text", "content": "{\"text\":\"test content\"}"}
>>> put(
...     'im/v1/messages/:message_id',
...     data=data,
...     app_id='cli_slkdjalasdkjasd',
...     app_secret='dskLLdkasdjlasdKK'
... )
NestedDict(
  ('code'): 0
  ('msg'): 'success'
  ('data'): NestedDict(
    ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
    ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
    ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
    ('thread_id'): 'omt_d4be107c616a'
    ('msg_type'): 'card'
    ('create_time'): '1635675360'
    ('update_time'): '1635675420'
    ('deleted'): False
    ('updated'): True
    ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
    ('sender'): NestedDict(
      ('id'): 'cli_9f427eec54ae901b'
      ('id_type'): 'app_id'
      ('sender_type'): 'app'
      ('tenant_key'): '736588c9260f175e'
    )
    ('body'): NestedDict(
      ('content'): '{"text":"@_user_1 test content"}'
    )
    ('mentions'): [NestedDict(
      ('key'): '@_user_1'
      ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
      ('id_type'): 'open_id'
      ('name'): 'Chang'
      ('tenant_key'): '736588c9260f175e'
    )]
    ('upper_message_id'): 'om_40eb06e7b84dc71c03e00ida3c754892'
  )
)
Source code in feishu/utils/request.py
Python
def put(
    dest: str,
    data: Dict | None = None,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送 PUT 请求。

    Args:
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        headers: 请求头。默认为 `{}`。
        params: 请求参数。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。

    Examples:
        >>> data = {"msg_type": "text", "content": "{\"text\":\"test content\"}"}
        >>> put(
        ...     'im/v1/messages/:message_id',
        ...     data=data,
        ...     app_id='cli_slkdjalasdkjasd',
        ...     app_secret='dskLLdkasdjlasdKK'
        ... )  # doctest:+SKIP
        NestedDict(
          ('code'): 0
          ('msg'): 'success'
          ('data'): NestedDict(
            ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
            ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
            ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
            ('thread_id'): 'omt_d4be107c616a'
            ('msg_type'): 'card'
            ('create_time'): '1635675360'
            ('update_time'): '1635675420'
            ('deleted'): False
            ('updated'): True
            ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
            ('sender'): NestedDict(
              ('id'): 'cli_9f427eec54ae901b'
              ('id_type'): 'app_id'
              ('sender_type'): 'app'
              ('tenant_key'): '736588c9260f175e'
            )
            ('body'): NestedDict(
              ('content'): '{"text":"@_user_1 test content"}'
            )
            ('mentions'): [NestedDict(
              ('key'): '@_user_1'
              ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
              ('id_type'): 'open_id'
              ('name'): 'Chang'
              ('tenant_key'): '736588c9260f175e'
            )]
            ('upper_message_id'): 'om_40eb06e7b84dc71c03e00ida3c754892'
          )
        )
    """
    return request(
        "PUT",
        dest,
        data=data,
        params=params,
        headers=headers,
        timeout=timeout,
        token=token,
        app_id=app_id,
        app_secret=app_secret,
        **kwargs,
    )