किसी मैसेज पर मिलने वाली प्रतिक्रियाओं की सूची बनाना

इस गाइड में किसी मैसेज की प्रतिक्रियाओं की सूची बनाने के लिए, Google Chat API के Reaction संसाधन पर list तरीके का इस्तेमाल करने का तरीका बताया गया है, जैसे कि 👍, Liked, और किताबें.

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.readonly, chat.messages.reactions, chat.messages.readonly या chat.messages की अनुमति के दायरे के साथ उपयोगकर्ता की पुष्टि करें.

प्रतिक्रियाओं की सूची बनाना

किसी मैसेज पर दी गई प्रतिक्रियाओं की सूची बनाने के लिए, अपने अनुरोध में यह जानकारी दें:

  • अनुमति देने के लिए chat.messages.reactions.readonly, chat.messages.reactions, chat.messages.readonly या chat.messages का दायरा बताएं.
  • Reaction संसाधन पर [list बताए गए तरीके]/workspace(/chat/api/reference/rest/v1/spaces.messages.reactions/list) को कॉल करें.

यहां दिए गए उदाहरण में, किसी मैसेज पर दी गई प्रतिक्रियाओं की सूची दी गई है:

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

    python3 chat_reactions_list.py
    

Chat API, प्रतिक्रियाओं की पेजांकन वाली एक कैटगरी दिखाता है.