From acf28251ba3ba387d9c585d0e3882b53c8878d7c Mon Sep 17 00:00:00 2001 From: pierrick Date: Thu, 11 Dec 2025 03:20:40 +0000 Subject: [PATCH] feat: remove attendance chat app --- solutions/attendance-chat-app/README.md | 23 -- solutions/attendance-chat-app/final/Code.gs | 183 ---------------- .../attendance-chat-app/final/appsscript.json | 13 -- solutions/attendance-chat-app/step-3/Code.gs | 31 --- .../step-3/appsscript.json | 5 - solutions/attendance-chat-app/step-4/Code.gs | 31 --- .../step-4/appsscript.json | 5 - solutions/attendance-chat-app/step-5/Code.gs | 72 ------- .../step-5/appsscript.json | 5 - solutions/attendance-chat-app/step-6/Code.gs | 198 ------------------ .../step-6/appsscript.json | 13 -- 11 files changed, 579 deletions(-) delete mode 100644 solutions/attendance-chat-app/README.md delete mode 100644 solutions/attendance-chat-app/final/Code.gs delete mode 100644 solutions/attendance-chat-app/final/appsscript.json delete mode 100644 solutions/attendance-chat-app/step-3/Code.gs delete mode 100644 solutions/attendance-chat-app/step-3/appsscript.json delete mode 100644 solutions/attendance-chat-app/step-4/Code.gs delete mode 100644 solutions/attendance-chat-app/step-4/appsscript.json delete mode 100644 solutions/attendance-chat-app/step-5/Code.gs delete mode 100644 solutions/attendance-chat-app/step-5/appsscript.json delete mode 100644 solutions/attendance-chat-app/step-6/Code.gs delete mode 100644 solutions/attendance-chat-app/step-6/appsscript.json diff --git a/solutions/attendance-chat-app/README.md b/solutions/attendance-chat-app/README.md deleted file mode 100644 index 8404454da..000000000 --- a/solutions/attendance-chat-app/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Attendance Chat App - -This code sample shows how to build a Google Chat app using Google -Apps Script. The Chat app responds to messages in a space or direct message (DM) and -allows the user to set a vacation responder in Gmail or add an all-day event to -their Calendar from Google Chat. - -## Usage - -You can follow [this codelab](https://developers.google.com/codelabs/chat-apps-script) -to build and test this Chat app. - -To use this Chat app, you must enable the Hangouts Chat API in the -[Google API Console](https://console.developers.google.com/). After enabling -the API, configuring the Chat app, and publishing it, you must add the Chat app to a space -or DM to begin a conversation. - -For more information about how to publish a Chat app, see -[Publishing Google Chat apps](https://developers.google.com/workspace/chat/apps-publish). - -## Disclaimer - -This is not an official product. diff --git a/solutions/attendance-chat-app/final/Code.gs b/solutions/attendance-chat-app/final/Code.gs deleted file mode 100644 index 79f42cdc4..000000000 --- a/solutions/attendance-chat-app/final/Code.gs +++ /dev/null @@ -1,183 +0,0 @@ -/** - * Responds to an ADDED_TO_SPACE event in Google Chat. - * @param {object} event the event object from Google Chat - * @return {object} JSON-formatted response - * @see https://developers.google.com/workspace/chat/receive-respond-interactions - */ -function onAddToSpace(event) { - console.info(event); - let message = "Thank you for adding me to "; - if (event.space.type === "DM") { - message += `a DM, ${event.user.displayName}!`; - } else { - message += event.space.displayName; - } - return { text: message }; -} - -/** - * Responds to a REMOVED_FROM_SPACE event in Google Chat. - * @param {object} event the event object from Google Chat - * @see https://developers.google.com/workspace/chat/receive-respond-interactions - */ -function onRemoveFromSpace(event) { - console.info(event); - console.log("Chat app removed from ", event.space.name); -} - -const DEFAULT_IMAGE_URL = "https://goo.gl/bMqzYS"; -const HEADER = { - header: { - title: "Attendance Chat app", - subtitle: "Log your vacation time", - imageUrl: DEFAULT_IMAGE_URL, - }, -}; - -/** - * Creates a card-formatted response. - * @param {object} widgets the UI components to send - * @return {object} JSON-formatted response - */ -function createCardResponse(widgets) { - return { - cards: [ - HEADER, - { - sections: [ - { - widgets: widgets, - }, - ], - }, - ], - }; -} - -const REASON = { - SICK: "Out sick", - OTHER: "Out of office", -}; -/** - * Responds to a MESSAGE event triggered in Google Chat. - * @param {object} event the event object from Google Chat - * @return {object} JSON-formatted response - */ -function onMessage(event) { - console.info(event); - let reason = REASON.OTHER; - const name = event.user.displayName; - const userMessage = event.message.text; - - // If the user said that they were 'sick', adjust the image in the - // header sent in response. - if (userMessage.indexOf("sick") > -1) { - // Hospital material icon - HEADER.header.imageUrl = "https://goo.gl/mnZ37b"; - reason = REASON.SICK; - } else if (userMessage.indexOf("vacation") > -1) { - // Spa material icon - HEADER.header.imageUrl = "https://goo.gl/EbgHuc"; - } - - const widgets = [ - { - textParagraph: { - text: `Hello, ${name}.
Are you taking time off today?`, - }, - }, - { - buttons: [ - { - textButton: { - text: "Set vacation in Gmail", - onClick: { - action: { - actionMethodName: "turnOnAutoResponder", - parameters: [ - { - key: "reason", - value: reason, - }, - ], - }, - }, - }, - }, - { - textButton: { - text: "Block out day in Calendar", - onClick: { - action: { - actionMethodName: "blockOutCalendar", - parameters: [ - { - key: "reason", - value: reason, - }, - ], - }, - }, - }, - }, - ], - }, - ]; - return createCardResponse(widgets); -} - -/** - * Responds to a CARD_CLICKED event triggered in Google Chat. - * @param {object} event the event object from Google Chat - * @return {object} JSON-formatted response - * @see https://developers.google.com/workspace/chat/receive-respond-interactions - */ -function onCardClick(event) { - console.info(event); - let message = ""; - const reason = event.action.parameters[0].value; - if (event.action.actionMethodName === "turnOnAutoResponder") { - turnOnAutoResponder(reason); - message = "Turned on vacation settings."; - } else if (event.action.actionMethodName === "blockOutCalendar") { - blockOutCalendar(reason); - message = "Blocked out your calendar for the day."; - } else { - message = "I'm sorry; I'm not sure which button you clicked."; - } - return { text: message }; -} - -const ONE_DAY_MILLIS = 24 * 60 * 60 * 1000; -/** - * Turns on the user's vacation response for today in Gmail. - * @param {string} reason the reason for vacation, either REASON.SICK or REASON.OTHER - */ -function turnOnAutoResponder(reason) { - const currentTime = new Date().getTime(); - Gmail.Users.Settings.updateVacation( - { - enableAutoReply: true, - responseSubject: reason, - responseBodyHtml: - "I'm out of the office today; will be back on the next business day.

Created by Attendance Chat app!", - restrictToContacts: true, - restrictToDomain: true, - startTime: currentTime, - endTime: currentTime + ONE_DAY_MILLIS, - }, - "me", - ); -} - -/** - * Places an all-day meeting on the user's Calendar. - * @param {string} reason the reason for vacation, either REASON.SICK or REASON.OTHER - */ -function blockOutCalendar(reason) { - CalendarApp.createAllDayEvent( - reason, - new Date(), - new Date(Date.now() + ONE_DAY_MILLIS), - ); -} diff --git a/solutions/attendance-chat-app/final/appsscript.json b/solutions/attendance-chat-app/final/appsscript.json deleted file mode 100644 index 434f00b3e..000000000 --- a/solutions/attendance-chat-app/final/appsscript.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "timeZone": "America/Los_Angeles", - "dependencies": { - "enabledAdvancedServices": [ - { - "userSymbol": "Gmail", - "serviceId": "gmail", - "version": "v1" - } - ] - }, - "chat": {} -} diff --git a/solutions/attendance-chat-app/step-3/Code.gs b/solutions/attendance-chat-app/step-3/Code.gs deleted file mode 100644 index 6f10f0716..000000000 --- a/solutions/attendance-chat-app/step-3/Code.gs +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Responds to an ADDED_TO_SPACE event - * in Google Chat. - * - * @param event the event object from Google Chat - * @return JSON-formatted response - */ -function onAddToSpace(event) { - console.info(event); - - let message = ""; - - if (event.space.type === "DM") { - message = `Thank you for adding me to a DM, ${event.user.displayName}!`; - } else { - message = `Thank you for adding me to ${event.space.displayName}`; - } - - return { text: message }; -} - -/** - * Responds to a REMOVED_FROM_SPACE event - * in Google Chat. - * - * @param event the event object from Google Chat - */ -function onRemoveFromSpace(event) { - console.info(event); - console.info("Chat app removed from ", event.space.name); -} diff --git a/solutions/attendance-chat-app/step-3/appsscript.json b/solutions/attendance-chat-app/step-3/appsscript.json deleted file mode 100644 index 02005f501..000000000 --- a/solutions/attendance-chat-app/step-3/appsscript.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "timeZone": "America/Los_Angeles", - "dependencies": {}, - "chat": {} -} diff --git a/solutions/attendance-chat-app/step-4/Code.gs b/solutions/attendance-chat-app/step-4/Code.gs deleted file mode 100644 index 6f10f0716..000000000 --- a/solutions/attendance-chat-app/step-4/Code.gs +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Responds to an ADDED_TO_SPACE event - * in Google Chat. - * - * @param event the event object from Google Chat - * @return JSON-formatted response - */ -function onAddToSpace(event) { - console.info(event); - - let message = ""; - - if (event.space.type === "DM") { - message = `Thank you for adding me to a DM, ${event.user.displayName}!`; - } else { - message = `Thank you for adding me to ${event.space.displayName}`; - } - - return { text: message }; -} - -/** - * Responds to a REMOVED_FROM_SPACE event - * in Google Chat. - * - * @param event the event object from Google Chat - */ -function onRemoveFromSpace(event) { - console.info(event); - console.info("Chat app removed from ", event.space.name); -} diff --git a/solutions/attendance-chat-app/step-4/appsscript.json b/solutions/attendance-chat-app/step-4/appsscript.json deleted file mode 100644 index 02005f501..000000000 --- a/solutions/attendance-chat-app/step-4/appsscript.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "timeZone": "America/Los_Angeles", - "dependencies": {}, - "chat": {} -} diff --git a/solutions/attendance-chat-app/step-5/Code.gs b/solutions/attendance-chat-app/step-5/Code.gs deleted file mode 100644 index 83f227e40..000000000 --- a/solutions/attendance-chat-app/step-5/Code.gs +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Responds to an ADDED_TO_SPACE event - * in Google Chat. - * - * @param event the event object from Google Chat - * @return JSON-formatted response - */ -function onAddToSpace(event) { - console.info(event); - - let message = ""; - - if (event.space.type === "DM") { - message = `Thank you for adding me to a DM, ${event.user.displayName}!`; - } else { - message = `Thank you for adding me to ${event.space.displayName}`; - } - - return { text: message }; -} - -/** - * Responds to a REMOVED_FROM_SPACE event - * in Google Chat. - * - * @param event the event object from Google Chat - */ -function onRemoveFromSpace(event) { - console.info(event); - console.info("Chat app removed from ", event.space.name); -} - -/** - * Creates a card-formatted response. - * - * @param widgets the UI components to send - * @return JSON-formatted response - */ -function createCardResponse(widgets) { - return { - cards: [ - header, - { - sections: [ - { - widgets: widgets, - }, - ], - }, - ], - }; -} - -/** - * Responds to a MESSAGE event triggered in Google Chat. - * - * @param event the event object from Google Chat - * @return JSON-formatted response - */ -function onMessage(event) { - const userMessage = event.message.text; - - const widgets = [ - { - textParagraph: { - text: `You said: ${userMessage}`, - }, - }, - ]; - - return createCardResponse(widgets); -} diff --git a/solutions/attendance-chat-app/step-5/appsscript.json b/solutions/attendance-chat-app/step-5/appsscript.json deleted file mode 100644 index 02005f501..000000000 --- a/solutions/attendance-chat-app/step-5/appsscript.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "timeZone": "America/Los_Angeles", - "dependencies": {}, - "chat": {} -} diff --git a/solutions/attendance-chat-app/step-6/Code.gs b/solutions/attendance-chat-app/step-6/Code.gs deleted file mode 100644 index a7803a9af..000000000 --- a/solutions/attendance-chat-app/step-6/Code.gs +++ /dev/null @@ -1,198 +0,0 @@ -/** - * Responds to an ADDED_TO_SPACE event - * in Google Chat. - * - * @param event the event object from Google Chat - * @return JSON-formatted response - */ -function onAddToSpace(event) { - console.info(event); - - let message = ""; - - if (event.space.type === "DM") { - message = `Thank you for adding me to a DM, ${event.user.displayName}!`; - } else { - message = `Thank you for adding me to ${event.space.displayName}`; - } - - return { text: message }; -} - -/** - * Responds to a REMOVED_FROM_SPACE event - * in Google Chat. - * - * @param event the event object from Google Chat - */ -function onRemoveFromSpace(event) { - console.info(event); - console.info("Chat app removed from ", event.space.name); -} - -const DEFAULT_IMAGE_URL = "https://goo.gl/bMqzYS"; -const header = { - header: { - title: "Attendance Chat app", - subtitle: "Log your vacation time", - imageUrl: DEFAULT_IMAGE_URL, - }, -}; - -/** - * Creates a card-formatted response. - * - * @param widgets the UI components to send - * @return JSON-formatted response - */ -function createCardResponse(widgets) { - return { - cards: [ - header, - { - sections: [ - { - widgets: widgets, - }, - ], - }, - ], - }; -} - -const REASON_SICK = "Out sick"; -const REASON_OTHER = "Out of office"; - -/** - * Responds to a MESSAGE event triggered in Google Chat. - * - * @param event the event object from Google Chat - * @return JSON-formatted response - */ -function onMessage(event) { - console.info(event); - - let reason = REASON_OTHER; - const name = event.user.displayName; - const userMessage = event.message.text; - - // If the user said that they were "sick", adjust the image in the - // header sent in response. - if (userMessage.indexOf("sick") > -1) { - // Hospital material icon - header.header.imageUrl = "https://goo.gl/mnZ37b"; - reason = REASON_SICK; - } else if (userMessage.indexOf("vacation") > -1) { - // Spa material icon - header.header.imageUrl = "https://goo.gl/EbgHuc"; - } - - const widgets = [ - { - textParagraph: { - text: `Hello, ${name}.
Are you taking time off today?`, - }, - }, - { - buttons: [ - { - textButton: { - text: "Set vacation in Gmail", - onClick: { - action: { - actionMethodName: "turnOnAutoResponder", - parameters: [ - { - key: "reason", - value: reason, - }, - ], - }, - }, - }, - }, - { - textButton: { - text: "Block out day in Calendar", - onClick: { - action: { - actionMethodName: "blockOutCalendar", - parameters: [ - { - key: "reason", - value: reason, - }, - ], - }, - }, - }, - }, - ], - }, - ]; - - return createCardResponse(widgets); -} - -/** - * Responds to a CARD_CLICKED event triggered in Google Chat. - * - * @param event the event object from Google Chat - * @return JSON-formatted response - */ -function onCardClick(event) { - console.info(event); - - let message = ""; - const reason = event.action.parameters[0].value; - - if (event.action.actionMethodName === "turnOnAutoResponder") { - turnOnAutoResponder(reason); - message = "Turned on vacation settings."; - } else if (event.action.actionMethodName === "blockOutCalendar") { - blockOutCalendar(reason); - message = "Blocked out your calendar for the day."; - } else { - message = "I'm sorry; I'm not sure which button you clicked."; - } - - return { text: message }; -} - -const ONE_DAY_MILLIS = 24 * 60 * 60 * 1000; - -/** - * Turns on the user's vacation response for today in Gmail. - * - * @param reason the reason for vacation, either REASON_SICK or REASON_OTHER - */ -function turnOnAutoResponder(reason) { - const currentTime = new Date().getTime(); - - Gmail.Users.Settings.updateVacation( - { - enableAutoReply: true, - responseSubject: reason, - responseBodyHtml: - "I'm out of the office today; will be back on the next business day.

Created by Attendance Chat app!", - restrictToContacts: true, - restrictToDomain: true, - startTime: currentTime, - endTime: currentTime + ONE_DAY_MILLIS, - }, - "me", - ); -} - -/** - * Places an all-day meeting on the user's Calendar. - * - * @param reason the reason for vacation, either REASON_SICK or REASON_OTHER - */ -function blockOutCalendar(reason) { - CalendarApp.createAllDayEvent( - reason, - new Date(), - new Date(Date.now() + ONE_DAY_MILLIS), - ); -} diff --git a/solutions/attendance-chat-app/step-6/appsscript.json b/solutions/attendance-chat-app/step-6/appsscript.json deleted file mode 100644 index 434f00b3e..000000000 --- a/solutions/attendance-chat-app/step-6/appsscript.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "timeZone": "America/Los_Angeles", - "dependencies": { - "enabledAdvancedServices": [ - { - "userSymbol": "Gmail", - "serviceId": "gmail", - "version": "v1" - } - ] - }, - "chat": {} -}