Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Z tego przewodnika dowiesz się, jak używać metody create() w zasobie Reaction interfejsu Google Chat API, aby dodać reakcję do wiadomości, np. 👍, 🚲 i 🌞.
ReactionZasób
reprezentuje emotikon, którego użytkownicy mogą używać do reagowania na wiadomości, np. 👍, 🚲 i 🌞.
Utwórz dane logowania identyfikatora klienta OAuth dla aplikacji na komputery. Aby uruchomić przykład w tym przewodniku, zapisz dane logowania jako plik JSON o nazwie credentials.json w katalogu lokalnym.
Aby uzyskać wskazówki, wykonaj czynności związane z konfigurowaniem środowiska opisane w tym krótkim przewodniku.
Aby utworzyć reakcję na wiadomość, w żądaniu przekaż te informacje:
Określ zakres autoryzacji chat.messages.reactions.create, chat.messages.reactions lub chat.messages.
Wywołaj metodę
CreateReaction()
, przekazując parent jako nazwę zasobu wiadomości, na którą chcesz zareagować, a reaction jako instancję
Reaction
, w której pole unicode jest standardowym emotikonem reprezentowanym przez ciąg znaków Unicode.
W tym przykładzie na wiadomość reagujemy emotikonem 😀:
import{createClientWithUserCredentials}from'./authentication-utils.js';constUSER_AUTH_OAUTH_SCOPES=['https://www.googleapis.com/auth/chat.messages.reactions.create'];// This sample shows how to create reaction to a message with user credentialasyncfunctionmain(){// Create a clientconstchatClient=awaitcreateClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);// Initialize request argument(s)constrequest={// Replace SPACE_NAME and MESSAGE_NAME here.parent:'spaces/SPACE_NAME/messages/MESSAGE_NAME',reaction:{// A standard emoji represented by a unicode string.emoji:{unicode:'😀'},},};// Make the requestconstresponse=awaitchatClient.createReaction(request);// Handle the responseconsole.log(response);}main().catch(console.error);
Aby uruchomić ten przykład, zastąp te elementy:
SPACE_NAME: identyfikator z przestrzeni name.
Możesz go uzyskać, wywołując metodę
ListSpaces()
lub z adresu URL pokoju.
MESSAGE_NAME: identyfikator z elementu name wiadomości.
Identyfikator możesz uzyskać z treści odpowiedzi zwróconej po utworzeniu wiadomości asynchronicznie za pomocą interfejsu Chat API lub za pomocą niestandardowej nazwy przypisanej do wiadomości podczas jej tworzenia.
Interfejs Chat API zwraca instancję Reaction
zawierającą szczegóły utworzonej reakcji.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-09-10 UTC."],[[["\u003cp\u003eThis guide demonstrates how to add emoji reactions (👍, 🚲, 🌞) to Google Chat messages using the \u003ccode\u003ecreate()\u003c/code\u003e method of the Google Chat API.\u003c/p\u003e\n"],["\u003cp\u003eIt requires a Google Workspace account, a configured Google Cloud project with the Chat API enabled, and the Node.js Cloud Client Library.\u003c/p\u003e\n"],["\u003cp\u003eTo add a reaction, call the \u003ccode\u003eCreateReaction()\u003c/code\u003e method, providing the message's resource name and the desired emoji's unicode representation.\u003c/p\u003e\n"],["\u003cp\u003eA sample Node.js code snippet is included, illustrating the process of creating a reaction using user credentials.\u003c/p\u003e\n"],["\u003cp\u003eYou need to replace placeholders for space and message names within the code with your specific values to execute the sample successfully.\u003c/p\u003e\n"]]],["To add a reaction to a message using the Google Chat API, utilize the `CreateReaction()` method. Specify the message's resource name as the `parent` and provide a `Reaction` instance with a Unicode emoji string in the `unicode` field. Ensure you have the `chat.messages.reactions.create`, `chat.messages.reactions`, or `chat.messages` authorization scope. You must have a Google Workspace account, a configured Google Cloud project, and have set up the Node.js environment, including OAuth client ID credentials. The API returns the created `Reaction` details.\n"],null,[]]