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

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

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

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

Node.js

  • आपके पास Business या Enterprise वर्शन वाला Google Workspace खाता होना चाहिए. साथ ही, आपके पास Google Chat को ऐक्सेस करने की अनुमति होनी चाहिए.

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

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

  • chat.messages.reactions.readonly, chat.messages.reactions, chat.messages.readonly या chat.messages के लिए अनुमति का दायरा तय करें.
  • ListReactions() तरीके को कॉल करें. साथ ही, parent को मैसेज के संसाधन के नाम के तौर पर पास करें.

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

Node.js

chat/client-libraries/cloud/list-reactions-user-cred.js
import {createClientWithUserCredentials} from './authentication-utils.js';

const USER_AUTH_OAUTH_SCOPES = ['https://www.googleapis.com/auth/chat.messages.reactions.readonly'];

// This sample shows how to list reactions to a message with user credential
async function main() {
  // Create a client
  const chatClient = await createClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);

  // Initialize request argument(s)
  const request = {
    // Replace SPACE_NAME and MESSAGE_NAME here.
    parent: 'spaces/SPACE_NAME/messages/MESSAGE_NAME'
  };

  // Make the request
  const pageResult = chatClient.listReactionsAsync(request);

  // Handle the response. Iterating over pageResult will yield results and
  // resolve additional pages automatically.
  for await (const response of pageResult) {
    console.log(response);
  }
}

main().catch(console.error);

इस सैंपल को चलाने के लिए, इन्हें बदलें:

  • SPACE_NAME: स्पेस के name का आईडी. आईडी पाने के लिए, ListSpaces() तरीके का इस्तेमाल करें या स्पेस के यूआरएल से आईडी पाएं.
  • MESSAGE_NAME: मैसेज के name से मिला आईडी. Chat API की मदद से एसिंक्रोनस तरीके से मैसेज बनाने के बाद, आपको जवाब के मुख्य हिस्से से आईडी मिल सकता है. इसके अलावा, मैसेज बनाते समय असाइन किए गए कस्टम नाम से भी आईडी मिल सकता है.

Chat API, पेज के हिसाब से प्रतिक्रियाओं की सूची दिखाता है.