Created
January 2, 2024 04:23
-
-
Save khanhkhuu/c35d5b34c11863c8ed17da8cd5f02be3 to your computer and use it in GitHub Desktop.
Send Google Chat With Image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sendChatWithImage() { | |
// Library ID: 1T03nYHRho6XMWYcaumClcWr6ble65mAT8OLJqRFJ5lukPVogAN2NDl-y | |
const imageID = "YOUR_IMAGE_ID_GOOGLE_DRIVE"; // Image ID (Google Drive) | |
const webhookUrl = 'YOUR_GROUP_CHAT_WEBHOOK_URL'; | |
const resizedImageHeight = 400; // 400px or smaller | |
const res = ImgApp.doResize(imageID, resizedImageHeight); | |
const base64 = Utilities.base64Encode(res.blob.getBytes()); | |
const mimeType = res.blob.getContentType(); | |
const dataUrl = `data:${mimeType};base64,${base64}`; | |
UrlFetchApp.fetch(webhookUrl, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
payload: JSON.stringify({ | |
cardsV2: [ | |
{ | |
cardId: "test", | |
card: { | |
header: { | |
title: "Test gửi hình ảnh" | |
}, | |
"sections": [ | |
{ | |
"header": "Vui lòng bỏ qua tin nhắn này", | |
"widgets": [ | |
{ | |
"image": { | |
"imageUrl": dataUrl | |
} | |
}, | |
] | |
} | |
] | |
} | |
} | |
] | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment