セクションを作成する

このガイドでは、Google Chat API の Section リソースで create メソッドを使用して、Google Chat に新しいカスタム セクションを作成する方法について説明します。

セクションを使用すると、会話をグループ化したり、Google Chat のナビゲーション パネルに表示されるスペースのリストをカスタマイズしたりできます。詳しくは、Google Chat でセクションを作成して整理するをご覧ください。

前提条件

Python

セクションを作成する

ユーザー認証を含むセクションを作成するには、リクエストで次の値を渡します。

  • chat.users.sections 認可スコープを指定します。
  • CreateSection メソッドを呼び出します。
  • リクエストの本文に Section リソースを指定します。
    • displayName をセクションの名前(全角 40 文字(半角 80 文字)以内)に設定します。
    • typeCUSTOM_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 のインスタンスを返します。