إدراج الرسائل

يشرح هذا الدليل كيفية استخدام طريقة list على مورد Message الخاص بـ Google Chat API للاطّلاع على قائمة رسائل مرقّمة وقابلة للفلترة في مساحة

تشير رسالة الأشكال البيانية مرجع Message يمثل نص أو بطاقة في Google Chat. يمكنك create أو get أو update أو delete رسالة في Google Chat API من خلال طلب الطرق المقابلة. لمعرفة المزيد من المعلومات عن الرسائل النصية ورسائل البطاقة، يمكنك الاطّلاع على نظرة عامة على رسائل Google Chat

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

Python

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

إدراج الرسائل

لإدراج الرسائل باستخدام مصادقة المستخدم، تمرير ما يلي في طلبك:

يسرد المثال التالي الرسائل في "مساحة Chat" المُرسَلة بعد 16 آذار (مارس) 2023:

Python

  1. في دليل العمل، أنشِئ ملفًا باسم "chat_messages_list.py".
  2. أدرِج الرمز التالي في chat_messages_list.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.messages.readonly"]
    
    def main():
        '''
        Authenticates with Chat API via user credentials,
        then lists messages in a space sent after March 16, 2023.
        '''
    
        # 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().messages().list(
    
              # The space for which to list messages.
              parent = 'spaces/SPACE',
    
              # An optional filter that returns messages
              # created after March 16, 2023.
              filter = 'createTime > "2023-03-16T00:00:00-00:00"'
    
          ).execute()
    
        # Prints the list of messages.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. في الرمز، استبدِل SPACE باسم مساحة التي يمكنك الحصول عليها من طريقة واحدة (spaces.list) في Chat API أو من عنوان URL للمساحة.

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

    python3 chat_messages_list.py
    

تعرض Google Chat API قائمة بالرسائل المُرسَلة في المساحة المحدَّدة بعد 16 آذار (مارس) 2023