เพิ่มความรู้สึกที่มีต่อข้อความ

คู่มือนี้อธิบายวิธีใช้เมธอด create() ในทรัพยากร Reaction ของ Google Chat API เพื่อเพิ่มความรู้สึกที่มีต่อ ข้อความ เช่น 👍, 🚲 และ 🌞

ทรัพยากร Reactionแสดงถึงอีโมจิที่ผู้คนใช้แสดงความรู้สึกที่มีต่อข้อความได้ เช่น 👍, 🚲, และ 🌞

ข้อกำหนดเบื้องต้น

Node.js

เพิ่มความรู้สึกที่มีต่อข้อความ

หากต้องการสร้างความรู้สึกที่มีต่อข้อความ ให้ส่งข้อมูลต่อไปนี้ในคำขอ

  • ระบุขอบเขตการให้สิทธิ์ chat.messages.reactions.create, chat.messages.reactions, หรือ chat.messages
  • เรียกเมธอด CreateReaction() โดยส่ง parent เป็นชื่อทรัพยากรของข้อความที่จะแสดงความรู้สึก และ reaction เป็นอินสแตนซ์ของ Reaction ซึ่งฟิลด์ unicode เป็นอีโมจิมาตรฐานที่แสดงด้วยสตริง Unicode

ตัวอย่างต่อไปนี้แสดงความรู้สึกที่มีต่อข้อความด้วยอีโมจิ 😀

Node.js

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

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

// This sample shows how to create 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 and MESSAGE_NAME here.
    parent: 'spaces/SPACE_NAME/messages/MESSAGE_NAME',
    reaction: {
      // A standard emoji represented by a unicode string.
      emoji: {unicode: '😀'},
    },
  };

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

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

await main();

หากต้องการเรียกใช้ตัวอย่างนี้ ให้แทนที่ข้อมูลต่อไปนี้

Chat API จะแสดงผลอินสแตนซ์ของ Reaction ที่แสดงรายละเอียดความรู้สึกที่สร้างขึ้น