إدراج التفاعلات مع رسالة

يوضّح هذا الدليل كيفية استخدام طريقة list على مورد Reaction في Google Chat API لإنشاء قائمة بالتفاعلات مع رسالة معيّنة، مثل 👍 🚲 و وغير وأ.

يمثّل المرجع Reaction رمزًا تعبيريًا يمكن للمستخدمين استخدامه للتفاعل مع رسالة، مثل 👍 🚲 و أد.

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

Python

  • Python 3.6 أو أحدث
  • إنّ أداة إدارة الحِزم pip
  • أحدث مكتبات عملاء Google للغة Python. لتثبيتها أو تحديثها، شغّل الأمر التالي في واجهة سطر الأوامر:

    pip3 install --upgrade google-api-python-client google-auth-oauthlib
    
  • مشروع على Google Cloud تم فيه تفعيل Google Chat API وضبطه لمعرفة الخطوات، يُرجى الاطّلاع على مقالة إنشاء تطبيق Google Chat.
  • تم ضبط التفويض لتطبيق Chat. تتطلب تفاعلات البيانات مصادقة المستخدم مع نطاق التفويض chat.messages.reactions.readonly أو chat.messages.reactions أو chat.messages.readonly أو chat.messages.

إدراج التفاعلات

لإدراج التفاعلات مع رسالة، أدخِل ما يلي في طلبك:

  • حدِّد نطاق تفويض chat.messages.reactions.readonly أو chat.messages.reactions أو chat.messages.readonly أو chat.messages.
  • يمكنك استدعاء [listmethod]/workspace(/chat/api/reference/rest/v1/spaces.messages.reactions/list) على المرجع Reaction.

يعرض المثال التالي التفاعلات مع رسالة محدّدة:

Python

  1. في دليل العمل، أنشِئ ملفًا باسم chat_reactions_list.py.
  2. ضمِّن الرمز التالي في chat_reactions_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.reactions.readonly"]
    
    def main():
        '''
        Authenticates with Chat API via user credentials,
        then lists reactions to a message.
        '''
    
        # 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().reactions().list(
    
            # The message to list reactions to.
            #
            # Replace SPACE with a space name.
            # Obtain the space name from the spaces resource of Chat API,
            # or from a space's URL.
            #
            # Replace MESSAGE with a message name.
            # Obtain the message name from the response body returned
            # after creating a message asynchronously with Chat REST API.
            parent = 'spaces/SPACE/messages/MESSAGE'
    
        ).execute()
    
        # Prints details about the created reactions.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. في التعليمة البرمجية، استبدل ما يلي:

    • SPACE: اسم مساحة يمكنك الحصول عليه من طريقة spaces.list في Chat API أو من عنوان URL الخاص بالمساحة.
    • MESSAGE: اسم رسالة يمكنك الحصول عليه من نص الردّ الذي يتم عرضه بعد إنشاء رسالة بشكل غير متزامن مع Chat API أو من خلال تحديد الاسم المخصّص للرسالة عند إنشائها
  4. في دليل العمل، أنشئ النموذج وقم بتشغيله:

    python3 chat_reactions_list.py
    

تعرض Chat API مجموعة مقسّمة على صفحات من التفاعلات.