Delete a reaction from a message

  • This guide explains how to delete reactions (emojis like 👍, 🚲, 🌞) from Google Chat messages using the delete() method.

  • Deleting a reaction does not delete the original message itself.

  • You'll need a Google Workspace account and Node.js to use the Google Chat API for deleting reactions.

  • The guide provides a code sample and instructions to set up your environment and authenticate for using the API.

  • To successfully delete a reaction, you need to provide the specific name of the reaction resource in your API request.

This guide explains how to use the delete() method on the Reaction resource of the Google Chat API to delete a reaction from a message—like 👍, 🚲, and 🌞. Deleting a reaction doesn't delete the message.

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

Prerequisites

Node.js

Delete a reaction

To delete a reaction from a message, pass the following in your request:

  • Specify the chat.messages.reactions or the chat.messages authorization scope.
  • Call the DeleteReaction() method, passing the name as the resource name of the reaction to delete.

The following example deletes the 😀 reaction from a message:

Node.js

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

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

// This sample shows how to delete a reaction 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, MESSAGE_NAME, and REACTION_NAME here
    name: 'spaces/SPACE_NAME/messages/MESSAGE_NAME/reactions/REACTION_NAME',
  };

  // Make the request
  const response = await chatClient.deleteReaction(request);

  // Handle the response
  console.log(response);
}

await main();

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.
  • REACTION_NAME: the ID from the reaction's name. You can obtain the ID by calling the ListReactions() method, or from the response body returned after creating a reaction asynchronously with the Chat API.

If successful, the response body is empty, which indicates that the reaction is deleted.