Buat kredensial client ID OAuth untuk aplikasi desktop. Untuk menjalankan contoh dalam panduan ini, simpan kredensial sebagai file JSON bernama client_secrets.json ke direktori lokal Anda.
Sebagai panduan, selesaikan langkah-langkah untuk menyiapkan lingkungan Anda dalam
panduan memulai ini.
Untuk membuat reaksi terhadap pesan, teruskan hal berikut dalam
permintaan Anda:
Tentukan cakupan otorisasi chat.messages.reactions.create, chat.messages.reactions, atau
chat.messages.
Panggil metode
CreateReaction(), dengan meneruskan parent sebagai nama resource pesan yang akan direspons, dan reaction sebagai instance
Reaction
dengan kolom unicode adalah emoji standar yang direpresentasikan oleh string
unicode.
Contoh berikut bereaksi terhadap pesan dengan 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);
Untuk menjalankan contoh ini, ganti hal berikut:
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 bisa mendapatkan ID dari isi respons yang ditampilkan setelah membuat
pesan secara asinkron dengan Chat API, atau dengan
nama kustom
yang ditetapkan ke pesan saat pembuatan.
Chat API menampilkan instance
Reaction
yang menjelaskan reaksi yang dibuat.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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"]]