列出对消息的回应

本指南介绍了如何对 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);
  }
}

await main();

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

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

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