Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Panduan ini menjelaskan cara menggunakan metode
delete()
pada resource Reaction Google Chat API untuk menghapus reaksi dari
pesan—seperti 👍, 🚲, dan 🌞. Menghapus reaksi tidak akan menghapus pesan.
Resource Reaction
mewakili emoji yang dapat digunakan orang untuk bereaksi terhadap pesan, seperti 👍, 🚲,
dan 🌞.
Buat kredensial client ID OAuth untuk aplikasi desktop. Untuk menjalankan contoh dalam panduan ini, simpan kredensial sebagai file JSON bernama credentials.json ke direktori lokal Anda.
Untuk mendapatkan panduan, selesaikan langkah-langkah penyiapan lingkungan Anda dalam
panduan memulai cepat ini.
import{createClientWithUserCredentials}from'./authentication-utils.js';constUSER_AUTH_OAUTH_SCOPES=['https://www.googleapis.com/auth/chat.messages.reactions'];// This sample shows how to delete a reaction to a message with user credentialasyncfunctionmain(){// Create a clientconstchatClient=awaitcreateClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);// Initialize request argument(s)constrequest={// Replace SPACE_NAME, MESSAGE_NAME, and REACTION_NAME herename:'spaces/SPACE_NAME/messages/MESSAGE_NAME/reactions/REACTION_NAME'};// Make the requestconstresponse=awaitchatClient.deleteReaction(request);// Handle the responseconsole.log(response);}main().catch(console.error);
Untuk menjalankan contoh ini, ganti berikut ini:
SPACE_NAME: ID dari
name ruang.
Anda bisa mendapatkan ID dengan memanggil metode
ListSpaces()
atau dari URL ruang.
MESSAGE_NAME: ID dari
name pesan.
Anda dapat memperoleh ID dari isi respons yang ditampilkan setelah membuat
pesan secara asinkron dengan Chat API, atau dengan
nama kustom
yang ditetapkan ke pesan saat pembuatan.
REACTION_NAME: ID dari
name reaksi.
Anda dapat memperoleh ID dengan memanggil metode
ListReactions(), atau dari isi respons yang ditampilkan setelah membuat reaksi
secara asinkron dengan Chat API.
Jika berhasil, isi respons akan kosong, yang menunjukkan bahwa reaksi telah dihapus.
[null,null,["Terakhir diperbarui pada 2025-08-29 UTC."],[[["\u003cp\u003eThis guide explains how to delete reactions (emojis like 👍, 🚲, 🌞) from Google Chat messages using the \u003ccode\u003edelete()\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eDeleting a reaction does not delete the original message itself.\u003c/p\u003e\n"],["\u003cp\u003eYou'll need a Google Workspace account and Node.js to use the Google Chat API for deleting reactions.\u003c/p\u003e\n"],["\u003cp\u003eThe guide provides a code sample and instructions to set up your environment and authenticate for using the API.\u003c/p\u003e\n"],["\u003cp\u003eTo successfully delete a reaction, you need to provide the specific name of the reaction resource in your API request.\u003c/p\u003e\n"]]],["This guide details deleting reactions from Google Chat messages using the `delete()` method on the `Reaction` resource. Key steps include setting up a Google Workspace account, enabling the Google Chat API, and installing the Node.js Cloud Client Library. To delete a reaction, specify the `chat.messages.reactions` or `chat.messages` scope, and call `DeleteReaction()`, providing the reaction's `name`. The guide includes a Node.js code sample that demonstrates the deletion, requiring the space, message, and reaction IDs. A successful deletion results in an empty response.\n"],null,["# Delete a reaction from a message\n\nThis guide explains how to use the\n[`delete()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.DeleteReaction)\nmethod on the `Reaction` resource of the Google Chat API to delete a reaction from\na message---like 👍, 🚲, and 🌞. Deleting a reaction doesn't delete the message.\n\nThe\n[`Reaction` resource](/workspace/chat/api/reference/rest/v1/spaces.messages.reactions)\nrepresents an emoji that people can use to react to a message, such as 👍, 🚲,\nand 🌞.\n\nPrerequisites\n-------------\n\n\n### Node.js\n\n- A Business or Enterprise [Google Workspace](https://support.google.com/a/answer/6043576) account with access to [Google Chat](https://workspace.google.com/products/chat/).\n\n\u003c!-- --\u003e\n\n- Set up your environment:\n - [Create a Google Cloud project](/workspace/guides/create-project).\n - [Configure the OAuth consent screen](/workspace/guides/configure-oauth-consent).\n - [Enable and configure the Google Chat API](/workspace/chat/configure-chat-api) with a name, icon, and description for your Chat app.\n - Install the Node.js [Cloud Client Library](/workspace/chat/libraries?tab=nodejs#cloud-client-libraries).\n - [Create OAuth client ID credentials](/workspace/chat/authenticate-authorize-chat-user#step-2:) for a desktop application. To run the sample in this guide, save the credentials as a JSON file named `credentials.json` to your local directory.\n\n For guidance, complete the steps for setting up your environment in this [quickstart](/workspace/chat/api/guides/quickstart/nodejs\n #set-up-environment).\n- [Choose an authorization scope](/workspace/chat/authenticate-authorize#asynchronous-chat-calls) that supports user authentication.\n\n\n| The code samples in this page use the gRPC API interface with the Google Cloud client libraries. Alternatively, you can use the REST API interface. For more information about the gRPC and REST interfaces, see [Google Chat API overview](/workspace/chat/api/reference).\n\n\u003cbr /\u003e\n\nDelete a reaction\n-----------------\n\nTo delete a reaction from a message, pass the following in your request:\n\n- Specify the `chat.messages.reactions` or the `chat.messages` authorization scope.\n- Call the [`DeleteReaction()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.DeleteReaction) method, passing the `name` as the resource name of the reaction to delete.\n\nThe following example deletes the 😀 reaction from a message: \n\n### Node.js\n\nchat/client-libraries/cloud/delete-reaction-user-cred.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/chat/client-libraries/cloud/delete-reaction-user-cred.js) \n\n```javascript\nimport {createClientWithUserCredentials} from './authentication-utils.js';\n\nconst USER_AUTH_OAUTH_SCOPES = ['https://www.googleapis.com/auth/chat.messages.reactions'];\n\n// This sample shows how to delete a reaction to a message with user credential\nasync function main() {\n // Create a client\n const chatClient = await createClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);\n\n // Initialize request argument(s)\n const request = {\n // Replace SPACE_NAME, MESSAGE_NAME, and REACTION_NAME here\n name: 'spaces/SPACE_NAME/messages/MESSAGE_NAME/reactions/REACTION_NAME'\n };\n\n // Make the request\n const response = await chatClient.deleteReaction(request);\n\n // Handle the response\n console.log(response);\n}\n\nmain().catch(console.error);\n```\n\nTo run this sample, replace the following:\n\n- \u003cvar translate=\"no\"\u003eSPACE_NAME\u003c/var\u003e: the ID from the space's [`name`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Space.FIELDS.string.google.chat.v1.Space.name). You can obtain the ID by calling the [`ListSpaces()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.ListSpaces) method or from the space's URL.\n- \u003cvar translate=\"no\"\u003eMESSAGE_NAME\u003c/var\u003e: the ID from the message's [`name`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Message.FIELDS.string.google.chat.v1.Message.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](/workspace/chat/create-messages#name_a_created_message) assigned to the message at creation.\n- \u003cvar translate=\"no\"\u003eREACTION_NAME\u003c/var\u003e: the ID from the reaction's [`name`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Reaction.FIELDS.string.google.chat.v1.Reaction.name). You can obtain the ID by calling the [`ListReactions()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.ListReactions) method, or from the response body returned after creating a reaction asynchronously with the Chat API.\n\nIf successful, the response body is empty, which indicates that the reaction is\ndeleted.\n\nRelated topics\n--------------\n\n- [Add a reaction to a message](/workspace/chat/create-reactions).\n- [List reactions for a message](/workspace/chat/list-reactions)."]]