Wyświetlanie listy reakcji na wiadomość

Z tego przewodnika dowiesz się, jak używać metody list() w zasobie Reaction interfejsu Google Chat API, aby wyświetlać reakcje na wiadomość, takie jak 👍, 🚲 i 🌞.

Zasób Reaction reprezentuje emoji, których użytkownicy mogą używać do reagowania na wiadomości, np. 👍, 🚲, i 🌞.

Wymagania wstępne

Node.js

Wyświetlanie reakcji

Aby wyświetlić reakcje na wiadomość, w żądaniu podaj te informacje:

Poniższy przykład pokazuje, jak wyświetlić reakcje na określoną wiadomość:

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();

Aby uruchomić ten przykład, zastąp te elementy:

  • SPACE_NAME: identyfikator z pola name. Możesz go uzyskać, wywołując metodę ListSpaces() lub z adresu URL pokoju.
  • MESSAGE_NAME: identyfikator z pola name wiadomości. Możesz go uzyskać z treści odpowiedzi zwróconej po asynchronicznym utworzeniu wiadomości za pomocą interfejsu Chat API lub z niestandardowej nazwy przypisanej do wiadomości podczas jej tworzenia.

Interfejs Chat API zwraca podzieloną na strony listę reakcji.