スペースを更新する

このガイドでは、次の Space リソースで patch メソッドを使用する方法について説明します。 スペースを更新します。スペースを更新して、スペースに関する属性 スペースでユーザーに表示されます。

Space リソース ユーザーと Chat アプリがメッセージを送信し、 ファイルの共有、共同編集を行えますスペースにはいくつかのタイプがあります。

  • ダイレクト メッセージ(DM)とは、2 人のユーザーまたはユーザー間の会話で、 作成することもできます。
  • グループ チャットとは、3 人以上のユーザーと Chat 用アプリ。
  • 名前付きスペースは、メッセージの送信、ファイルの共有、 考えています

前提条件

Python

  • Python 3.6 以降
  • pip パッケージ管理ツール
  • 最新の Google クライアント ライブラリ。インストールまたは更新する手順は次のとおりです。 コマンドライン インターフェースで次のコマンドを実行します。
    pip3 install --upgrade google-api-python-client google-auth-oauthlib
    

Node.js

  • Node.js 14 以降
  • npm パッケージ管理ツール
  • 最新の Google クライアント ライブラリ。インストールまたは更新する手順は次のとおりです。 コマンドライン インターフェースで次のコマンドを実行します。
    npm install @google-cloud/local-auth @googleapis/chat
    

スペースの更新

Google Chat の既存のスペースを更新するには、次のオプションを渡します。 リクエスト内:

  • chat.spaces 認可スコープを指定します。
  • 呼び出し patch メソッド Space リソースに対する権限。イン スペース name フィールド、updateMask を指定します。 更新するフィールドを指定することができます。 body は、更新されたスペース情報に置き換えます。

表示名、スペースの種類、履歴の状態、 できます。更新できるすべてのフィールドを確認するには、以下をご覧ください。 リファレンス ドキュメントをご覧ください。

既存のスペースの spaceDetails フィールドを更新する方法は次のとおりです。

Python

  1. 作業ディレクトリに、chat_space_update.py という名前のファイルを作成します。
  2. chat_space_update.py に次のコードを含めます。

    from google_auth_oauthlib.flow import InstalledAppFlow
    from googleapiclient.discovery import build
    
    # Define your app's authorization scopes.
    # When modifying these scopes, delete the file token.json, if it exists.
    SCOPES = ["https://www.googleapis.com/auth/chat.spaces"]
    
    def main():
        '''
        Authenticates with Chat API via user credentials,
        then updates the specified space description and guidelines.
        '''
    
        # Authenticate with Google Workspace
        # and get user authorization.
        flow = InstalledAppFlow.from_client_secrets_file(
                          'client_secrets.json', SCOPES)
        creds = flow.run_local_server()
    
        # Build a service endpoint for Chat API.
        chat = build('chat', 'v1', credentials=creds)
    
        # Use the service endpoint to call Chat API.
        result = chat.spaces().patch(
    
          # The space to update, and the updated space details.
          #
          # Replace {space} with a space name.
          # Obtain the space name from the spaces resource of Chat API,
          # or from a space's URL.
          name='spaces/SPACE',
          updateMask='spaceDetails',
          body={
    
            'spaceDetails': {
              'description': 'This description was updated with Chat API!',
              'guidelines': 'These guidelines were updated with Chat API!'
            }
    
          }
    
        ).execute()
    
        # Prints details about the updated space.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. コードで SPACE をスペース名に置き換えます。スペースには こちらの spaces.list メソッド スペースの URL から取得できます。

  4. 作業ディレクトリでサンプルをビルドして実行します。

    python3 chat_space_update.py
    

Node.js

  1. 作業ディレクトリに、update-space.js という名前のファイルを作成します。
  2. update-space.js に次のコードを含めます。

    const chat = require('@googleapis/chat');
    const {authenticate} = require('@google-cloud/local-auth');
    
    /**
    * Updates a Chat space with the description and guidelines.
    * @return {!Promise<!Object>}
    */
    async function updateSpace() {
      const scopes = [
        'https://www.googleapis.com/auth/chat.spaces',
      ];
    
      const authClient =
          await authenticate({scopes, keyfilePath: 'client_secrets.json'});
    
      const chatClient = await chat.chat({version: 'v1', auth: authClient});
    
      return await chatClient.spaces.patch({
        name: 'spaces/SPACE',
        updateMask: 'spaceDetails',
        requestBody: {
          spaceDetails: {
            description: 'This description was updated with Chat API!',
            guidelines: 'These guidelines were updated with Chat API!'
          },
        }
      });
    }
    
    updateSpace().then(console.log);
    
  3. コードで SPACE をスペース名に置き換えます。スペースには こちらの spaces.list メソッド スペースの URL から取得できます。

  4. 作業ディレクトリでサンプルを実行します。

    node update-space.js
    

Google Chat API は、メッセージに関連付けられた 更新を反映した Space リソース