I'm trying to develop a ChatBot in Google Chat, using Google Apps Script. The Chabot shuold retrieve an attachment uploaded (e.g. .PDF file) by the user and move it into a Drive folder. I've read the official documentantion but I suppose the it takes something for granted, because I don't undestrand how to use the "resourceName" of the attachmnent in order to manage the uploaded file and move it where I need. Could someone helps me with an example?
Thanks a Lot!
I'm able to retrieve the 'resourceName' of the object attachment but not to manage it. Here under what I'm doing in Google Apps Script:
function onMessage(event) {
var destination = DriveApp.getFolderById("XXX")
var name = (event.message.hasOwnProperty("attachment") ? name = event.message?.attachment[0]?.name?.trim() : "");
var fileId = "";
if (name != "") {
console.log("attachment");
if (event.message.attachment[0]?.source == "DRIVE_FILE") {
console.log("Google ID " + event.message.attachment[0]?.driveDataRef?.driveFileId)
fileId = event.message.attachment[0]?.driveDataRef?.driveFileId
} else if (event.message.attachment[0]?.source == "UPLOADED_CONTENT") {
console.log("Uploaded Content " + event.message.attachment[0]?.attachmentDataRef?.resourceName)
**var resourceName = event.message.attachment[0]?.attachmentDataRef?.resourceName**
}
DriveApp.getFileById(fileId).moveTo(destination)
}
else {
console.log("No attachment")
}
I suppose that I should use the 'resourceName' but I don't understand how.