حذف تفاعل من رسالة

يشرح هذا الدليل كيفية استخدام طريقة delete على المرجع Reaction. Google Chat API لحذف تفاعل من رسالة، مثل 👍 و🚲 وCPV. لا يؤدي حذف تفاعل إلى حذف الرسالة.

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

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

Python

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

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

حذف تفاعل

لحذف تفاعل من رسالة، عليك تضمين ما يلي في طلبك:

  • تحديد تفويض chat.messages.reactions أو chat.messages النطاق.
  • عليك استدعاء طريقة delete في صفحة مرجع واحد (Reaction)
  • اضبط السمة name على اسم المورد للتفاعل الذي تريد حذفه.

يؤدي المثال التالي إلى حذف التفاعل 👈 من الرسالة:

Python

  1. في دليل العمل، أنشِئ ملفًا باسم "chat_reaction_delete.py".
  2. أدرِج الرمز التالي في chat_reaction_delete.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"]
    
    def main():
        '''
        Authenticates with Chat API via user credentials,
        then deletes a reaction 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().delete(
    
            # The reaction to delete.
            #
            # 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.
            #
            # Replace REACTION with a reaction name.
            # Obtain the reaction name from the reaction resource of Chat API.
            name = 'spaces/SPACE/messages/MESSAGE/reactions/REACTION'
    
        ).execute()
    
    if __name__ == '__main__':
        main()
    
  3. في الرمز، استبدل ما يلي:

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

    python3 chat_reaction_delete.py
    

إذا كانت الاستجابة ناجحة، يكون نص الاستجابة فارغًا، مما يشير إلى أن التفاعل حذف.