更新部分

本指南介绍了如何对 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实例。