列出訊息回應

本指南說明如何使用 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:來自聊天室的 ID。name。您可以呼叫 ListSpaces() 方法,或從空間的網址取得 ID。
  • MESSAGE_NAME:訊息 name 中的 ID。您可以透過使用 Chat API 非同步建立訊息後傳回的回應主體,或透過建立訊息時指派給訊息的自訂名稱,取得 ID。

Chat API 會傳回分頁列出的回應清單