更新區段

本指南說明如何使用 Google Chat API 的 Section 資源中的 patch 方法,更新 Google Chat 中的自訂版面。

你只能更新類型為 CUSTOM_SECTION 的章節。詳情請參閱「在 Google Chat 中建立及整理區段」。

必要條件

Python

更新區段

如要使用使用者驗證更新部分內容,請在要求中傳遞下列項目:

  • 指定 chat.users.sections 授權範圍。
  • 呼叫 UpdateSection 方法。
  • 在要求主體中,提供 Section 資源和欄位遮罩:
    • 設定要更新的區段 name
    • displayName 設為區段的新名稱。
    • updateMask 設為 displayName

以下範例會更新章節:

Python

from google.cloud import chat_v1
from google.protobuf import field_mask_pb2

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

    # Initialize request
    request = chat_v1.UpdateSectionRequest(
        section=chat_v1.Section(
            name="SECTION_NAME",
            display_name="NEW_SECTION_DISPLAY_NAME"
        ),
        update_mask=field_mask_pb2.FieldMask(paths=["display_name"])
    )

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

    print(response)

如要執行這個範例,請替換下列項目:

  • SECTION_NAME:區段的資源名稱。您可以呼叫 ListSections 方法來取得資源名稱。
  • NEW_SECTION_DISPLAY_NAME:區段的新名稱。

Chat API 會傳回更新後的 Section 執行個體。