किसी मैसेज पर दी गई प्रतिक्रिया को मिटाना

इस गाइड में किसी मैसेज से किसी प्रतिक्रिया को मिटाने के लिए, Google Chat API के Reaction संसाधन पर delete तरीके का इस्तेमाल करने का तरीका बताया गया है. जैसे, 👍, शानदार

Reaction संसाधन, इमोजी के बारे में बताता है. इसका इस्तेमाल लोग किसी मैसेज पर प्रतिक्रिया देने के लिए कर सकते हैं. जैसे, 👍, 🗣, और ・.

ज़रूरी शर्तें

Python

  • Python 3.6 या इससे नया वर्शन
  • pip पैकेज मैनेजमेंट टूल
  • Python के लिए नई 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 के अनुमति का दायरा बताएं.
  • Reaction संसाधन पर delete वाला तरीका कॉल करें.
  • जिस प्रतिक्रिया को मिटाना है उसके संसाधन के नाम के लिए 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: स्पेस का नाम, जिसे Chat API में spaces.list तरीके से या स्पेस के यूआरएल से पाया जा सकता है.
    • MESSAGE: यह एक मैसेज है, जिसे Chat API की मदद से एसिंक्रोनस तरीके से मैसेज बनाने के बाद रिस्पॉन्स के मुख्य हिस्से से पाया जा सकता है. इसके अलावा, मैसेज बनाते समय इसे असाइन किए गए कस्टम नाम से भी इसे पाया जा सकता है.
    • REACTION: प्रतिक्रिया का एक नाम होता है. इसे Chat API में spaces.messages.reactions.list तरीके से या Chat API की मदद से एसिंक्रोनस तरीके से कोई प्रतिक्रिया बनाने के बाद नतीजे के मुख्य हिस्से से पाया जा सकता है.
  4. अपनी वर्किंग डायरेक्ट्री में, यह सैंपल बनाएं और चलाएं:

    python3 chat_reaction_delete.py
    

कार्रवाई पूरी होने पर, जवाब का मुख्य हिस्सा खाली रहता है. इससे पता चलता है कि प्रतिक्रिया मिटा दी गई है.