列出对消息的回应

本指南介绍了如何使用 Google Chat API 的 Reaction 资源中的 list() 方法列出消息的表情符号回应,例如 👍、🚲 和 🌞。

Reaction 资源表示用户可用于回应消息的表情符号,例如 👍、🚲 和 🌞。

前提条件

Node.js

列出回应

如需列出消息的表情符号,请在请求中传递以下内容:

  • 指定 chat.messages.reactions.readonlychat.messages.reactionschat.messages.readonlychat.messages 授权范围。
  • 调用 ListReactions() 方法,并传入 parent 作为消息的资源名称。

以下示例列出了指定消息的表情符号:

Node.js

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

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

// This sample shows how to list reactions 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'
  };

  // Make the request
  const pageResult = chatClient.listReactionsAsync(request);

  // Handle the response. Iterating over pageResult will yield results and
  // resolve additional pages automatically.
  for await (const response of pageResult) {
    console.log(response);
  }
}

main().catch(console.error);

如需运行此示例,请替换以下内容:

  • SPACE_NAME:来自空间的 name 的 ID。 您可以通过调用 ListSpaces() 方法或从空间的网址中获取 ID。
  • MESSAGE_NAME:消息的 name 中的 ID。 您可以通过以下方式获取 ID:使用 Chat API 异步创建消息后返回的响应正文,或者创建消息时分配给消息的自定义名称

Chat API 会返回分页的反应列表