创建版块

本指南介绍了如何使用 Google Chat API 的 Section 资源中的 create 方法在 Google Chat 中创建新的自定义栏目。

版块可帮助用户对对话进行分组,并自定义 Google Chat 导航面板中显示的聊天室列表。如需了解详情,请参阅在 Google Chat 中创建和整理版块

前提条件

Python

创建版块

如需创建包含用户身份验证的部分,请在请求中传递以下内容:

  • 指定 chat.users.sections 授权范围。
  • 调用 CreateSection 方法。
  • 在请求正文中,提供 Section 资源:
    • displayName 设置为版块的名称(最多 80 个字符)。
    • type 设置为 CUSTOM_SECTION

以下示例会创建一个部分:

Python

from google.cloud import chat_v1

def create_section():
    # Create a client
    client = chat_v1.ChatServiceClient()

    # Initialize request
    request = chat_v1.CreateSectionRequest(
        parent="users/me",
        section=chat_v1.Section(
            display_name="SECTION_DISPLAY_NAME",
            type=chat_v1.Section.SectionType.CUSTOM_SECTION
        )
    )

    # Make the request
    response = client.create_section(request=request)

    print(response)

如需运行此示例,请替换以下内容:

  • SECTION_DISPLAY_NAME:新部分的名称。

Chat API 会返回一个 Section 实例,其中详细说明了已创建的部分。