Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Bu kılavuzda, mesaj ekiyle ilgili meta verileri almak için Google Chat API'nin Attachment kaynağında get() yönteminin nasıl kullanılacağı açıklanmaktadır. Yanıt, Attachment kaynağının bir örneğidir.
Kullanıcı uygulamanıza mesaj gönderdiğinde Google Chat, MESSAGE etkileşim etkinliği gönderir.
Uygulamanızın aldığı etkileşim etkinliği, ekler de dahil olmak üzere etkileşim etkinliğini temsil eden JSON yükü olan bir istek gövdesi içerir. Ekteki veriler, ekin yüklenen içerik (yerel dosya) olup olmadığına veya Drive'da depolanan bir dosya olup olmadığına bağlı olarak farklılık gösterir. MediaKaynak, Google Chat'e yüklenen resim, video ve doküman gibi dosyaları temsil eder.
Attachment kaynağı, bir iletiye eklenmiş bir medya örneğini (dosya) temsil eder. Attachment
kaynağı, ekle ilgili meta verileri (ör. nereye kaydedildiği) içerir.
Hizmet hesabı kimlik bilgileri oluşturun. Bu kılavuzdaki örneği çalıştırmak için kimlik bilgilerini yerel dizininize credentials.json adlı bir JSON dosyası olarak kaydedin.
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);
Bu örneği çalıştırmak için spaces/SPACE_NAME/messages/
MESSAGE_NAME/attachments/ATTACHMENT_NAME yerine ileti eki adını girin.
Chat API, belirtilen ileti ekiyle ilgili meta verileri ayrıntılandıran bir Attachment örneği döndürür.
[[["Anlaması kolay","easyToUnderstand","thumb-up"],["Sorunumu çözdü","solvedMyProblem","thumb-up"],["Diğer","otherUp","thumb-up"]],[["İhtiyacım olan bilgiler yok","missingTheInformationINeed","thumb-down"],["Çok karmaşık / çok fazla adım var","tooComplicatedTooManySteps","thumb-down"],["Güncel değil","outOfDate","thumb-down"],["Çeviri sorunu","translationIssue","thumb-down"],["Örnek veya kod sorunu","samplesCodeIssue","thumb-down"],["Diğer","otherDown","thumb-down"]],["Son güncelleme tarihi: 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,[]]