이 가이드에서는 Google Chat API의 Attachment 리소스에서 get() 메서드를 사용하여 메시지 첨부파일에 관한 메타데이터를 가져오는 방법을 설명합니다. 응답은 Attachment 리소스의 인스턴스입니다.
사용자가 앱에 메시지를 보내면 Google Chat에서 MESSAGE 상호작용 이벤트를 디스패치합니다.
앱에서 수신한 상호작용 이벤트에는 첨부파일을 비롯한 상호작용 이벤트를 나타내는 JSON 페이로드인 요청 본문이 포함됩니다. 첨부파일의 데이터는 첨부파일이 업로드된 콘텐츠 (로컬 파일)인지 아니면 Drive에 저장된 파일인지에 따라 다릅니다. Media 리소스는 이미지, 동영상, 문서와 같이 Google Chat에 업로드된 파일을 나타냅니다.
Attachment 리소스는 메시지에 첨부된 미디어(파일) 인스턴스를 나타냅니다. Attachment 리소스에는 첨부파일이 저장된 위치와 같은 첨부파일에 관한 메타데이터가 포함됩니다.
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);
이 샘플을 실행하려면 spaces/SPACE_NAME/messages/
MESSAGE_NAME/attachments/ATTACHMENT_NAME을 메시지 첨부파일 이름으로 바꿉니다.
Chat API는 지정된 메시지 첨부파일에 관한 메타데이터를 자세히 설명하는 Attachment 인스턴스를 반환합니다.
[null,null,["최종 업데이트: 2025-08-29(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,["# Get metadata about a message attachment\n\nThis guide explains how to use the\n[`get()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.GetAttachment)\nmethod on the `Attachment` resource of the\nGoogle Chat API to get metadata about a message attachment. The response is an\ninstance of the\n[`Attachment` resource](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Attachment).\n\nWhen the user sends a message to your app, Google Chat dispatches a\n[`MESSAGE` interaction event](/workspace/chat/events#message).\nThe interaction event received by your app includes a request body, which is the\nJSON payload representing the interaction event, including any attachments. The\ndata in the attachment is different depending on whether the attachment is\nuploaded content (a local file) or is a file stored on Drive. The\n[`Media` resource](/workspace/chat/api/reference/rest/v1/media)\nrepresents a file uploaded to Google Chat, like images, videos, and documents.\nThe\n[`Attachment` resource](/workspace/chat/api/reference/rest/v1/spaces.messages.attachments)\nrepresents an instance of media---a file---attached to a message. The `Attachment`\nresource includes the metadata about the attachment, such as\nwhere it's saved.\n\nPrerequisites\n-------------\n\n\n### Node.js\n\n- A Business or Enterprise [Google Workspace](https://support.google.com/a/answer/6043576) account with access to [Google Chat](https://workspace.google.com/products/chat/).\n\n\u003c!-- --\u003e\n\n- Set up your environment:\n - [Create a Google Cloud project](/workspace/guides/create-project).\n - [Configure the OAuth consent screen](/workspace/guides/configure-oauth-consent).\n - [Enable and configure the Google Chat API](/workspace/chat/configure-chat-api) with a name, icon, and description for your Chat app.\n - Install the Node.js [Cloud Client Library](/workspace/chat/libraries?tab=nodejs#cloud-client-libraries).\n - [Create service account credentials](/workspace/chat/authenticate-authorize-chat-app#create-service-account). To run the sample in this guide, save the credentials as a JSON file named `credentials.json` to your local directory.\n- [Choose an authorization scope](/workspace/chat/authenticate-authorize#asynchronous-chat-calls) that supports app authentication.\n\n\n| The code samples in this page use the gRPC API interface with the Google Cloud client libraries. Alternatively, you can use the REST API interface. For more information about the gRPC and REST interfaces, see [Google Chat API overview](/workspace/chat/api/reference).\n\n\u003cbr /\u003e\n\nGet a message attachment\n------------------------\n\nTo asynchronously get metadata about a message attachment in Google Chat, pass\nthe following in your request:\n\n- Specify the `chat.bot` authorization scope.\n- Call the [`GetAttachment()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.GetAttachment) method, passing the `name` of the message attachment.\n\nHere's how to get metadata about a message attachment: \n\n### Node.js\n\nchat/client-libraries/cloud/get-attachment-app-cred.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/chat/client-libraries/cloud/get-attachment-app-cred.js) \n\n```javascript\nimport {createClientWithAppCredentials} from './authentication-utils.js';\n\n// This sample shows how to get attachment metadata with app credential\nasync function main() {\n // Create a client\n const chatClient = createClientWithAppCredentials();\n\n // Initialize request argument(s)\n const request = {\n // Replace SPACE_NAME, MESSAGE_NAME, and ATTACHMENT_NAME here\n name: 'spaces/SPACE_NAME/messages/MESSAGE_NAME/attachments/ATTACHMENT_NAME'\n };\n\n // Make the request\n const response = await chatClient.getAttachment(request);\n\n // Handle the response\n console.log(response);\n}\n\nmain().catch(console.error);\n```\n\nTo run this sample, replace `spaces/`\u003cvar translate=\"no\"\u003eSPACE_NAME\u003c/var\u003e`/messages/\n`\u003cvar translate=\"no\"\u003eMESSAGE_NAME\u003c/var\u003e`/attachments/`\u003cvar translate=\"no\"\u003eATTACHMENT_NAME\u003c/var\u003e with the\nmessage attachment name.\n\nThe Chat API returns an instance of\n[`Attachment`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Attachment)\nthat details the metadata about the specified message attachment.\n\nRelated topics\n--------------\n\n- [Upload media as a file attachment](/workspace/chat/upload-media-attachments)\n- [Download media as a file attachment](/workspace/chat/download-media-attachments)"]]