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

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

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

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

Node.js

  • บัญชี Google Workspace สำหรับธุรกิจหรือองค์กร ที่มีสิทธิ์เข้าถึง Google Chat

เพิ่มรีแอ็กชันต่อข้อความ

หากต้องการสร้างรีแอ็กชันต่อข้อความ ให้ส่งข้อมูลต่อไปนี้ในคำขอ

  • ระบุขอบเขตการให้สิทธิ์ 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);
}

main().catch(console.error);

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

  • SPACE_NAME: รหัสจากnameของพื้นที่ทำงาน คุณรับรหัสได้โดยการเรียกใช้เมธอด ListSpaces() หรือจาก URL ของพื้นที่ทำงาน
  • MESSAGE_NAME: รหัสจากnameของข้อความ คุณขอรับรหัสได้จากเนื้อหาการตอบกลับที่ส่งคืนหลังจากสร้างข้อความแบบไม่พร้อมกันด้วย Chat API หรือด้วยชื่อที่กำหนดเองที่กำหนดให้กับข้อความตอนสร้าง

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