Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Ten przewodnik wyjaśnia, jak używać metody
get()
w zasobie Attachment interfejsu Google Chat API, aby uzyskać metadane załącznika wiadomości. Odpowiedź jest instancją Attachmentzasobu.
Gdy użytkownik wyśle wiadomość do Twojej aplikacji, Google Chat wyśle MESSAGEzdarzenie interakcji.
Zdarzenie interakcji otrzymane przez aplikację zawiera treść żądania, czyli ładunek JSON reprezentujący zdarzenie interakcji, w tym wszelkie załączniki. Dane w załączniku różnią się w zależności od tego, czy załącznik jest przesłaną treścią (plik lokalny), czy plikiem przechowywanym na Dysku. MediaZasób
reprezentuje plik przesłany do Google Chat, np. obraz, film lub dokument.
AttachmentZasób reprezentuje instancję multimediów, czyli plik dołączony do wiadomości. AttachmentZasób zawiera metadane załącznika, np. miejsce jego zapisania.
Utwórz dane logowania konta usługi. Aby uruchomić przykład z tego przewodnika, zapisz dane logowania jako plik JSON o nazwie credentials.json w katalogu lokalnym.
import{createClientWithAppCredentials}from'./authentication-utils.js';// This sample shows how to get attachment metadata with app credentialasyncfunctionmain(){// Create a clientconstchatClient=createClientWithAppCredentials();// Initialize request argument(s)constrequest={// Replace SPACE_NAME, MESSAGE_NAME, and ATTACHMENT_NAME herename:'spaces/SPACE_NAME/messages/MESSAGE_NAME/attachments/ATTACHMENT_NAME',};// Make the requestconstresponse=awaitchatClient.getAttachment(request);// Handle the responseconsole.log(response);}main().catch(console.error);
Aby uruchomić ten przykład, zastąp spaces/SPACE_NAME/messages/
MESSAGE_NAME/attachments/ATTACHMENT_NAME nazwą załącznika do wiadomości.
Interfejs Chat API zwraca instancję Attachment, która zawiera metadane określonego załącznika do wiadomości.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-09-10 UTC."],[[["\u003cp\u003eThis guide explains how to retrieve metadata about a message attachment in Google Chat using the \u003ccode\u003eget()\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eAttachment\u003c/code\u003e resource represents an instance of a file attached to a message and includes metadata like its location.\u003c/p\u003e\n"],["\u003cp\u003eTo get attachment metadata, you need to use the \u003ccode\u003echat.bot\u003c/code\u003e authorization scope and call the \u003ccode\u003eGetAttachment()\u003c/code\u003e method with the attachment's name.\u003c/p\u003e\n"],["\u003cp\u003ePrerequisites include a Google Workspace account, a Google Cloud project, and Node.js setup with necessary libraries and credentials.\u003c/p\u003e\n"]]],["The core actions involve retrieving metadata about a message attachment in Google Chat using the `get()` method. This requires the `chat.bot` authorization scope and calling `GetAttachment()`, providing the attachment's `name`. Before using the `get()` method, you must set up a Google Cloud project, configure the OAuth consent screen, and set up the Google Chat API. The `Attachment` resource represents the file, with metadata detailing its storage. The request triggers a response with `Attachment` details.\n"],null,[]]