List reactions for a message

This guide explains how to use the list() method on the Reaction resource of the Google Chat API to list reactions for a message—like 👍, 🚲, and 🌞.

The Reaction resource represents an emoji that people can use to react to a message, such as 👍, 🚲, and 🌞.

Prerequisites

Node.js

List reactions

To list the reactions for a message, pass the following in your request:

  • Specify the chat.messages.reactions.readonly , chat.messages.reactions , chat.messages.readonly , or chat.messages authorization scope.
  • Call the ListReactions() method, passing the parent as the resource name of the message.

The following example lists reactions for a specified message:

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 
 ); 

To run this sample, replace the following:

  • SPACE_NAME : the ID from the space's name . You can obtain the ID by calling the ListSpaces() method or from the space's URL.
  • MESSAGE_NAME : the ID from the message's name . You can obtain the ID from the response body returned after creating a message asynchronously with the Chat API, or with the custom name assigned to the message at creation.

The Chat API returns a paginated list of reactions .

Design a Mobile Site
View Site in Mobile | Classic
Share by: