메시지에 반응 추가

이 가이드에서는 Google Chat API의 Reaction 리소스에서 create() 메서드를 사용하여 👍, 🚲, 🌞과 같은 메시지에 반응을 추가하는 방법을 설명합니다.

Reaction 리소스 는 사용자가 👍, 🚲, 🌞과 같은 메시지에 반응하는 데 사용할 수 있는 그림 이모티콘을 나타냅니다.

기본 요건

Node.js

메시지에 반응 추가

메시지에 대한 반응을 만들려면 요청에 다음을 전달합니다.

  • chat.messages.reactions.create, chat.messages.reactions 또는 chat.messages 승인 범위를 지정합니다.
  • CreateReaction() 메서드를 호출하여 parent를 반응할 메시지의 리소스 이름으로 전달하고 reactionReaction 의 인스턴스로 전달합니다. 여기서 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 인스턴스를 반환합니다.