تعديل مساحة

يشرح هذا الدليل كيفية استخدام طريقة patch على مورد Space الخاص بـ Google Chat API لتعديل مساحة تعديل مساحة لتغيير السمات المتعلقة المساحة، مثل الاسم المعروض والوصف والإرشادات المرئية للمستخدم.

تشير رسالة الأشكال البيانية مرجع Space يمثّل مكانًا يمكن فيه للمستخدمين والتطبيقات في Chat إرسال رسائل ومشاركتها والتعاون. تتوفّر عدة أنواع من المساحات:

  • الرسائل المباشرة هي محادثات بين مستخدمين أو مستخدم تطبيق Chat.
  • الدردشات الجماعية هي محادثات بين ثلاثة مستخدمين أو أكثر تطبيقات Chat
  • المساحات المُعنونة هي أماكن دائمة يرسل من خلالها المستخدمون الرسائل ويشاركون الملفات والتعاون.

المتطلبات الأساسية

Python

  • Python 3.6 أو أعلى
  • أداة إدارة حزم pip
  • أحدث مكتبات عملاء Google. لتثبيت التطبيقات أو تحديثها، قم بتشغيل الأمر التالي في واجهة سطر الأوامر:
    pip3 install --upgrade google-api-python-client google-auth-oauthlib
    

Node.js

تعديل مساحة

لتعديل مساحة حالية في 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) في Chat API أو من عنوان 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) في Chat API أو من عنوان URL للمساحة.

  4. في دليل العمل، شغِّل النموذج:

    node update-space.js
    

تعرض Google Chat API مثيلاً Space مورد يعكس التعديلات