Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Panduan ini menjelaskan cara menggunakan metode
get()
pada resource Attachment dari
Google Chat API untuk mendapatkan metadata tentang lampiran pesan. Responsnya adalah
instance dari
resource Attachment.
Saat pengguna mengirim pesan ke aplikasi Anda, Google Chat akan mengirimkan
peristiwa interaksi MESSAGE.
Peristiwa interaksi yang diterima oleh aplikasi Anda mencakup isi permintaan, yang merupakan
payload JSON yang merepresentasikan peristiwa interaksi, termasuk lampiran apa pun. Data dalam lampiran berbeda-beda, bergantung pada apakah lampiran tersebut adalah konten yang diupload (file lokal) atau file yang disimpan di Drive. Resource
Media
merepresentasikan file yang diupload ke Google Chat, seperti gambar, video, dan dokumen.
Resource Attachment
mewakili instance media—file—yang dilampirkan ke pesan. Resource Attachment
mencakup metadata tentang lampiran, seperti
tempat lampiran disimpan.
Buat kredensial akun layanan. Untuk menjalankan contoh dalam panduan ini, simpan kredensial sebagai file JSON bernama credentials.json ke direktori lokal Anda.
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);
Untuk menjalankan contoh ini, ganti spaces/SPACE_NAME/messages/
MESSAGE_NAME/attachments/ATTACHMENT_NAME dengan
nama lampiran pesan.
Chat API menampilkan instance
Attachment
yang menjelaskan metadata tentang lampiran pesan yang ditentukan.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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,[]]