Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa guida spiega come utilizzare il metodo
create()
nella risorsa Reaction dell'API Google Chat per aggiungere una reazione a un messaggio, ad esempio 👍, 🚲 e 🌞.
La
risorsa Reaction rappresenta un'emoji che le persone possono usare per reagire a un messaggio, ad esempio 👍, 🚲 e 🌞.
Crea le credenziali dell'ID client OAuth per un'applicazione desktop. Per eseguire l'esempio in questa
guida, salva le credenziali come file JSON denominato client_secrets.json nella
directory locale.
Per indicazioni, completa i passaggi per configurare il tuo ambiente in questa
guida rapida.
Per creare una reazione a un messaggio, passa quanto segue nella richiesta:
Specifica l'ambito di autorizzazione chat.messages.reactions.create, chat.messages.reactions o
chat.messages.
Chiama il metodo
CreateReaction()
passando parent come nome della risorsa del messaggio a cui reagire
e reaction come istanza di
Reaction
in cui il campo unicode è un'emoji standard rappresentata da una stringa Unicode.
Il seguente esempio mostra una reazione a un messaggio con l'emoji 😀:
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);
Per eseguire questo esempio, sostituisci quanto segue:
SPACE_NAME: l'ID del
name dello spazio.
Puoi ottenere l'ID chiamando il metodo
ListSpaces()
o dall'URL dello spazio.
MESSAGE_NAME: l'ID del messaggio
name.
Puoi ottenere l'ID dal corpo della risposta restituito dopo aver creato un messaggio in modo asincrono con l'API Chat o con il nome personalizzato assegnato al messaggio al momento della creazione.
L'API Chat restituisce un'istanza di
Reaction
che descrive la reazione creata.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-02-14 UTC."],[[["This guide demonstrates how to add emoji reactions (👍, 🚲, 🌞) to Google Chat messages using the `create()` method of the Google Chat API."],["It requires a Google Workspace account, a configured Google Cloud project with the Chat API enabled, and the Node.js Cloud Client Library."],["To add a reaction, call the `CreateReaction()` method, providing the message's resource name and the desired emoji's unicode representation."],["A sample Node.js code snippet is included, illustrating the process of creating a reaction using user credentials."],["You need to replace placeholders for space and message names within the code with your specific values to execute the sample successfully."]]],["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"]]