建立版面

本指南說明如何使用 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 的例項,詳細說明建立的區段。