From 4ef093e5fff762374aa66189d14418a75af09f81 Mon Sep 17 00:00:00 2001 From: ttsukagoshi Date: Sun, 8 Aug 2021 01:40:40 +0900 Subject: [PATCH 1/4] #20: Add menu for setting up reminder notification Pending message localization --- src/i18n.js | 11 ++-- src/websiteMonitoring.js | 112 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 111 insertions(+), 12 deletions(-) diff --git a/src/i18n.js b/src/i18n.js index 39b25e6..1e7cf95 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -22,6 +22,7 @@ const MESSAGES = { menuTriggers: 'Triggers', menuSetStatusCheckTrigger: 'Set Status Check Trigger', menuSetLogExtractionTrigger: 'Set Log Extraction Trigger', + menuSetReminderTrigger: 'Set Reminder Trigger', menuDeleteTriggers: 'Delete Triggers', menuCheckStatus: 'Check Status', menuExtractStatusLogs: 'Extract Status Logs', @@ -55,7 +56,7 @@ const MESSAGES = { '\nChanges to website status have been emailed to {{myEmail}}', alertTitleCompleteStatusCheck: '[Website Status] Complete: Status Check', mailSubErrorStatusCheck: '[Website Status] Error: Status Check', - mailBodyErrorStatusCheck: + mailBodyError: '{{errorStack}}\n\n-----\nThis notice is managed by the following spreadsheet:\n{{spreadsheetUrl}}', alertTitleError: 'ERROR', errorHeaderNameTargetUrlNotFound: @@ -112,7 +113,7 @@ const MESSAGES = { alertTitleCompleteStatusCheck: '[サイト公開ステータス] 完了:ステータス確認', mailSubErrorStatusCheck: '[サイト公開ステータス] エラー:ステータス確認', - mailBodyErrorStatusCheck: + mailBodyError: '{{errorStack}}\n\n-----\nこの通知は次のGoogleスプレッドシートによって管理されています:\n{{spreadsheetUrl}}', alertTitleError: 'エラー', errorHeaderNameTargetUrlNotFound: @@ -324,13 +325,13 @@ class LocalizedMessage { return text; } /** - * Replace placeholder string in this.messageList.mailBodyErrorStatusCheck + * Replace placeholder string in this.messageList.mailBodyError * @param {String} errorStack * @param {String} spreadsheetUrl * @returns {String} The replaced text. */ - replaceMailBodyErrorStatusCheck(errorStack, spreadsheetUrl) { - let text = this.messageList.mailBodyErrorStatusCheck; + replaceMailBodyError(errorStack, spreadsheetUrl) { + let text = this.messageList.mailBodyError; let placeholderValues = [ { regexp: '{{errorStack}}', diff --git a/src/websiteMonitoring.js b/src/websiteMonitoring.js index bb32082..ca17c53 100644 --- a/src/websiteMonitoring.js +++ b/src/websiteMonitoring.js @@ -19,7 +19,9 @@ deleteTimeBasedTriggers, extractStatusLogsTriggered, onOpen, +sendReminder, setupLogExtractionTrigger, +setupReminderTrigger, setupStatusCheckTrigger, websiteMonitoringTriggered */ @@ -62,6 +64,10 @@ function onOpen() { localMessage.messageList.menuSetLogExtractionTrigger, 'setupLogExtractionTrigger' ) + .addItem( + localMessage.messageList.menuSetReminderTrigger, + 'setupReminderTrigger' + ) .addSeparator() .addItem( localMessage.messageList.menuDeleteTriggers, @@ -84,7 +90,7 @@ function setupStatusCheckTrigger() { const handlerFunction = 'websiteMonitoringTriggered'; const frequencyKey = 'TRIGGER_MINUTE_FREQUENCY_STATUS_CHECK'; const frequencyUnit = 'minute'; - setupTrigger(handlerFunction, frequencyKey, frequencyUnit); + setupTrigger_(handlerFunction, frequencyKey, frequencyUnit); } /** @@ -95,7 +101,7 @@ function setupLogExtractionTrigger() { const handlerFunction = 'extractStatusLogsTriggered'; const frequencyKey = 'TRIGGER_DAYS_FREQUENCY_LOG_EXTRACTION'; const frequencyUnit = 'day'; - setupTrigger(handlerFunction, frequencyKey, frequencyUnit); + setupTrigger_(handlerFunction, frequencyKey, frequencyUnit); } /** @@ -105,7 +111,7 @@ function setupLogExtractionTrigger() { * @param {String} frequencyKey Key in the options sheet that refers to the trigger frequency for this handler function. * @param {String} frequencyUnit Unit of the value of frequencyKey, i.e., minute, hour, day, or week. */ -function setupTrigger(handlerFunction, frequencyKey, frequencyUnit) { +function setupTrigger_(handlerFunction, frequencyKey, frequencyUnit) { const ui = SpreadsheetApp.getUi(); const myEmail = Session.getActiveUser().getEmail(); const ss = SpreadsheetApp.getActiveSpreadsheet(); @@ -200,6 +206,24 @@ function setupTrigger(handlerFunction, frequencyKey, frequencyUnit) { } } +/** + * Set time-based trigger for sending monthly reminders + * of active time-based triggers set by this user in this script. + * Trigger will be set for the first day of each month. + */ +function setupReminderTrigger() { + // UI alert message /////// + const handlerFunction = 'sendReminder'; + // Delete existing trigger for the same handler function. + ScriptApp.getProjectTriggers().forEach((trigger) => { + if (trigger.getHandlerFunction() === handlerFunction) { + ScriptApp.deleteTrigger(trigger); + } + }); + // Set new trigger + ScriptApp.newTrigger(handlerFunction).timeBased().onMonthDay(1).create(); +} + /** * Delete existing trigger(s). */ @@ -540,10 +564,7 @@ function websiteMonitoring(triggered = false) { 'NA', ]); let messageSub = localMessage.messageList.mailSubErrorStatusCheck; - let messageBody = localMessage.replaceMailBodyErrorStatusCheck( - e.stack, - ss.getUrl() - ); + let messageBody = localMessage.replaceMailBodyError(e.stack, ss.getUrl()); if (options.ENABLE_CHAT_NOTIFICATION) { // Post on Google Chat postToChat_( @@ -740,6 +761,83 @@ function extractStatusLogs(triggered = false) { } } +function sendReminder() { + const triggers = ScriptApp.getProjectTriggers(); + if (triggers.length > 0) { + const ss = SpreadsheetApp.getActiveSpreadsheet(); + const localMessage = new LocalizedMessage(ss.getSpreadsheetLocale()); + const myEmail = Session.getActiveUser().getEmail(); + // Parse options data from spreadsheet + const optionsArr = ss + .getSheetByName(SHEET_NAME_OPTIONS) + .getDataRange() + .getValues(); + optionsArr.shift(); + const options = optionsArr.reduce((obj, row) => { + let [key, value] = [row[1], row[2]]; // Assuming that the keys and their options are set in columns B and C, respectively. + if (key) { + obj[key] = value; + } + return obj; + }, {}); + var messageSub = '[Website Status] '; + var messageBody = ''; + try { + messageSub += 'Reminder: Active Triggers'; + let triggerInfo = triggers + .reduce((info, trigger) => { + if (trigger.getHandlerFunction() === 'websiteMonitoringTriggered') { + // Get the list of target websites to monitor + const targetWebsitesSheet = ss.getSheetByName(SHEET_NAME_DASHBOARD); + const targetWebsitesArr = targetWebsitesSheet + .getRange( + TARGET_WEBSITES_RANGE_POSITION.row, + TARGET_WEBSITES_RANGE_POSITION.col, + targetWebsitesSheet.getLastRow() - + TARGET_WEBSITES_RANGE_POSITION.row + + 1, + TARGET_WEBSITES_COL_NUM + ) + .getValues(); + targetWebsitesArr.shift(); + info.push( + `Website Monitoring:\n${targetWebsitesArr + .map((website) => `- ${website.join(' ')}`) + .join('\n')}` + ); + } else if ( + trigger.getHandlerFunction() === 'extractStatusLogsTriggered' + ) { + info.push('Trigger for periodical status log extraction is set.'); + } + return info; + }, []) + .join('\n'); + messageBody = `This is a monthly reminder of the time-based triggers set for this website monitoring script:\n\n${triggerInfo}\n\n-----\nThis notice is managed by the following spreadsheet:\n${ss.getUrl()}`; ////// + } catch (e) { + console.error(e.stack); + messageSub = '[Website Status] Error: Send Reminder'; // localMessage.messageList.mailSubErrorSendReminder; + messageBody = localMessage.replaceMailBodyError(e.stack, ss.getUrl()); + } finally { + if (options.ENABLE_CHAT_NOTIFICATION) { + // Post on Google Chat + postToChat_( + options.CHAT_WEBHOOK_URL, + `*${messageSub}*\n\n${messageBody}` + ); + } + if ( + !options.ENABLE_CHAT_NOTIFICATION || + !options.DISABLE_MAIL_NOTIFICATION + ) { + // If chat notification is disabled OR mail notification is NOT disabled + // send email notification + MailApp.sendEmail(myEmail, messageSub, messageBody); + } + } + } +} + /** * Parse a given array of HTTP reponse codes (in strings) into actual codes. * For example, ["201", "30x"] will be converted into the following array of codes: From 33649c56e1ab04e55499408fcab9f569f8b97883 Mon Sep 17 00:00:00 2001 From: ttsukagoshi Date: Sun, 8 Aug 2021 01:40:40 +0900 Subject: [PATCH 2/4] #20: Add menu for setting up reminder notification Pending message localization --- src/i18n.js | 11 ++-- src/websiteMonitoring.js | 112 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 111 insertions(+), 12 deletions(-) diff --git a/src/i18n.js b/src/i18n.js index 39b25e6..1e7cf95 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -22,6 +22,7 @@ const MESSAGES = { menuTriggers: 'Triggers', menuSetStatusCheckTrigger: 'Set Status Check Trigger', menuSetLogExtractionTrigger: 'Set Log Extraction Trigger', + menuSetReminderTrigger: 'Set Reminder Trigger', menuDeleteTriggers: 'Delete Triggers', menuCheckStatus: 'Check Status', menuExtractStatusLogs: 'Extract Status Logs', @@ -55,7 +56,7 @@ const MESSAGES = { '\nChanges to website status have been emailed to {{myEmail}}', alertTitleCompleteStatusCheck: '[Website Status] Complete: Status Check', mailSubErrorStatusCheck: '[Website Status] Error: Status Check', - mailBodyErrorStatusCheck: + mailBodyError: '{{errorStack}}\n\n-----\nThis notice is managed by the following spreadsheet:\n{{spreadsheetUrl}}', alertTitleError: 'ERROR', errorHeaderNameTargetUrlNotFound: @@ -112,7 +113,7 @@ const MESSAGES = { alertTitleCompleteStatusCheck: '[サイト公開ステータス] 完了:ステータス確認', mailSubErrorStatusCheck: '[サイト公開ステータス] エラー:ステータス確認', - mailBodyErrorStatusCheck: + mailBodyError: '{{errorStack}}\n\n-----\nこの通知は次のGoogleスプレッドシートによって管理されています:\n{{spreadsheetUrl}}', alertTitleError: 'エラー', errorHeaderNameTargetUrlNotFound: @@ -324,13 +325,13 @@ class LocalizedMessage { return text; } /** - * Replace placeholder string in this.messageList.mailBodyErrorStatusCheck + * Replace placeholder string in this.messageList.mailBodyError * @param {String} errorStack * @param {String} spreadsheetUrl * @returns {String} The replaced text. */ - replaceMailBodyErrorStatusCheck(errorStack, spreadsheetUrl) { - let text = this.messageList.mailBodyErrorStatusCheck; + replaceMailBodyError(errorStack, spreadsheetUrl) { + let text = this.messageList.mailBodyError; let placeholderValues = [ { regexp: '{{errorStack}}', diff --git a/src/websiteMonitoring.js b/src/websiteMonitoring.js index bb32082..ca17c53 100644 --- a/src/websiteMonitoring.js +++ b/src/websiteMonitoring.js @@ -19,7 +19,9 @@ deleteTimeBasedTriggers, extractStatusLogsTriggered, onOpen, +sendReminder, setupLogExtractionTrigger, +setupReminderTrigger, setupStatusCheckTrigger, websiteMonitoringTriggered */ @@ -62,6 +64,10 @@ function onOpen() { localMessage.messageList.menuSetLogExtractionTrigger, 'setupLogExtractionTrigger' ) + .addItem( + localMessage.messageList.menuSetReminderTrigger, + 'setupReminderTrigger' + ) .addSeparator() .addItem( localMessage.messageList.menuDeleteTriggers, @@ -84,7 +90,7 @@ function setupStatusCheckTrigger() { const handlerFunction = 'websiteMonitoringTriggered'; const frequencyKey = 'TRIGGER_MINUTE_FREQUENCY_STATUS_CHECK'; const frequencyUnit = 'minute'; - setupTrigger(handlerFunction, frequencyKey, frequencyUnit); + setupTrigger_(handlerFunction, frequencyKey, frequencyUnit); } /** @@ -95,7 +101,7 @@ function setupLogExtractionTrigger() { const handlerFunction = 'extractStatusLogsTriggered'; const frequencyKey = 'TRIGGER_DAYS_FREQUENCY_LOG_EXTRACTION'; const frequencyUnit = 'day'; - setupTrigger(handlerFunction, frequencyKey, frequencyUnit); + setupTrigger_(handlerFunction, frequencyKey, frequencyUnit); } /** @@ -105,7 +111,7 @@ function setupLogExtractionTrigger() { * @param {String} frequencyKey Key in the options sheet that refers to the trigger frequency for this handler function. * @param {String} frequencyUnit Unit of the value of frequencyKey, i.e., minute, hour, day, or week. */ -function setupTrigger(handlerFunction, frequencyKey, frequencyUnit) { +function setupTrigger_(handlerFunction, frequencyKey, frequencyUnit) { const ui = SpreadsheetApp.getUi(); const myEmail = Session.getActiveUser().getEmail(); const ss = SpreadsheetApp.getActiveSpreadsheet(); @@ -200,6 +206,24 @@ function setupTrigger(handlerFunction, frequencyKey, frequencyUnit) { } } +/** + * Set time-based trigger for sending monthly reminders + * of active time-based triggers set by this user in this script. + * Trigger will be set for the first day of each month. + */ +function setupReminderTrigger() { + // UI alert message /////// + const handlerFunction = 'sendReminder'; + // Delete existing trigger for the same handler function. + ScriptApp.getProjectTriggers().forEach((trigger) => { + if (trigger.getHandlerFunction() === handlerFunction) { + ScriptApp.deleteTrigger(trigger); + } + }); + // Set new trigger + ScriptApp.newTrigger(handlerFunction).timeBased().onMonthDay(1).create(); +} + /** * Delete existing trigger(s). */ @@ -540,10 +564,7 @@ function websiteMonitoring(triggered = false) { 'NA', ]); let messageSub = localMessage.messageList.mailSubErrorStatusCheck; - let messageBody = localMessage.replaceMailBodyErrorStatusCheck( - e.stack, - ss.getUrl() - ); + let messageBody = localMessage.replaceMailBodyError(e.stack, ss.getUrl()); if (options.ENABLE_CHAT_NOTIFICATION) { // Post on Google Chat postToChat_( @@ -740,6 +761,83 @@ function extractStatusLogs(triggered = false) { } } +function sendReminder() { + const triggers = ScriptApp.getProjectTriggers(); + if (triggers.length > 0) { + const ss = SpreadsheetApp.getActiveSpreadsheet(); + const localMessage = new LocalizedMessage(ss.getSpreadsheetLocale()); + const myEmail = Session.getActiveUser().getEmail(); + // Parse options data from spreadsheet + const optionsArr = ss + .getSheetByName(SHEET_NAME_OPTIONS) + .getDataRange() + .getValues(); + optionsArr.shift(); + const options = optionsArr.reduce((obj, row) => { + let [key, value] = [row[1], row[2]]; // Assuming that the keys and their options are set in columns B and C, respectively. + if (key) { + obj[key] = value; + } + return obj; + }, {}); + var messageSub = '[Website Status] '; + var messageBody = ''; + try { + messageSub += 'Reminder: Active Triggers'; + let triggerInfo = triggers + .reduce((info, trigger) => { + if (trigger.getHandlerFunction() === 'websiteMonitoringTriggered') { + // Get the list of target websites to monitor + const targetWebsitesSheet = ss.getSheetByName(SHEET_NAME_DASHBOARD); + const targetWebsitesArr = targetWebsitesSheet + .getRange( + TARGET_WEBSITES_RANGE_POSITION.row, + TARGET_WEBSITES_RANGE_POSITION.col, + targetWebsitesSheet.getLastRow() - + TARGET_WEBSITES_RANGE_POSITION.row + + 1, + TARGET_WEBSITES_COL_NUM + ) + .getValues(); + targetWebsitesArr.shift(); + info.push( + `Website Monitoring:\n${targetWebsitesArr + .map((website) => `- ${website.join(' ')}`) + .join('\n')}` + ); + } else if ( + trigger.getHandlerFunction() === 'extractStatusLogsTriggered' + ) { + info.push('Trigger for periodical status log extraction is set.'); + } + return info; + }, []) + .join('\n'); + messageBody = `This is a monthly reminder of the time-based triggers set for this website monitoring script:\n\n${triggerInfo}\n\n-----\nThis notice is managed by the following spreadsheet:\n${ss.getUrl()}`; ////// + } catch (e) { + console.error(e.stack); + messageSub = '[Website Status] Error: Send Reminder'; // localMessage.messageList.mailSubErrorSendReminder; + messageBody = localMessage.replaceMailBodyError(e.stack, ss.getUrl()); + } finally { + if (options.ENABLE_CHAT_NOTIFICATION) { + // Post on Google Chat + postToChat_( + options.CHAT_WEBHOOK_URL, + `*${messageSub}*\n\n${messageBody}` + ); + } + if ( + !options.ENABLE_CHAT_NOTIFICATION || + !options.DISABLE_MAIL_NOTIFICATION + ) { + // If chat notification is disabled OR mail notification is NOT disabled + // send email notification + MailApp.sendEmail(myEmail, messageSub, messageBody); + } + } + } +} + /** * Parse a given array of HTTP reponse codes (in strings) into actual codes. * For example, ["201", "30x"] will be converted into the following array of codes: From 36bcff7aa4b23dbbd5139eaa73c09101525e6e82 Mon Sep 17 00:00:00 2001 From: ttsukagoshi Date: Tue, 10 Aug 2021 01:01:43 +0900 Subject: [PATCH 3/4] Close #20: Reminder message localization --- src/i18n.js | 58 ++++++++++++++++++++++++++++++++++++++++ src/websiteMonitoring.js | 34 ++++++++++++++++++----- 2 files changed, 85 insertions(+), 7 deletions(-) diff --git a/src/i18n.js b/src/i18n.js index 1e7cf95..6ece903 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -39,6 +39,8 @@ const MESSAGES = { alertTitleCompleteTriggerSetup: 'Complete ({{handlerFunction}})', alertMessageCompleteTriggerSetup: 'Trigger set at {{frequency}}-{{frequencyUnit}} interval.', + alertMessageCompleteReminderTriggerSetup: + 'Monthly reminder to notify {{myEmail}} of the website status settings is now set up. You will be notified of the monitoring status on the first day of each month.', alertTitleContinueTriggerDelete: 'Deleting All Triggers', alertMessageContinueTriggerDelete: 'Deleting all existing trigger(s) on this spreadsheet/script set by {{myEmail}}. Are you sure you want to continue?', @@ -71,12 +73,21 @@ const MESSAGES = { '[Website Status] Error in Status Log Extraction:\n{{errorStack}}', errorInvalidResponseCode: 'Invalid response code "{{code}}" at ALLOWED_RESPONSE_CODES or ERROR_RESPONSE_CODES.', + mailSubSendReminderPrefix: '[Website Status] ', + mailSubSendReminder: 'Reminder: Active Triggers', + mailBodySendReminder: + 'This is a monthly reminder, sent automatically, of the time-based triggers set for this website monitoring script:\n\n{{triggerInfo}}\n\n-----\nThis notice is managed by the following spreadsheet:\n{{spreadsheetUrl}}', + mailSubErrorSendReminder: 'Error: Send Reminder', + messageMonitoredSitesPrefix: 'Monitored Websites', + messageTriggerLogExtractionIsSet: + 'Trigger for periodical status log extraction is set.', }, ja_JP: { menuTitle: 'サイト公開ステータス', menuTriggers: 'トリガー', menuSetStatusCheckTrigger: 'トリガー設定(ステータス確認)', menuSetLogExtractionTrigger: 'トリガー設定(ログ抽出)', + menuSetReminderTrigger: 'トリガー設定(リマインダー)', menuDeleteTriggers: 'トリガー削除', menuCheckStatus: 'ステータス確認', menuExtractStatusLogs: '確認ログを抽出', @@ -94,6 +105,8 @@ const MESSAGES = { alertTitleCompleteTriggerSetup: '完了({{handlerFunction}})', alertMessageCompleteTriggerSetup: 'トリガー設定完了:{{frequency}}-{{frequencyUnit}}間隔.', + alertMessageCompleteReminderTriggerSetup: + '{{myEmail}}宛にサイト公開ステータス監視の設定状況をリマインドするトリガーの設定が完了しました。毎月1日に、公開監視状況の設定が通知されます。', alertTitleContinueTriggerDelete: '全てのトリガーを削除します', alertMessageContinueTriggerDelete: 'このスプレッドシート/スクリプトで {{myEmail}} によって設定された全てのトリガーを削除します。このまま続けますか?', @@ -128,6 +141,14 @@ const MESSAGES = { '[サイト公開ステータス] ログ抽出エラー:\n{{errorStack}}', errorInvalidResponseCode: '無効なレスポンスコード「{{code}}」が ALLOWED_RESPONSE_CODES または ERROR_RESPONSE_CODES にて指定されています。', + mailSubSendReminderPrefix: '[サイト公開ステータス] ', + mailSubSendReminder: 'リマインダー:設定されているトリガー', + mailBodySendReminder: + 'これは、サイト公開ステータス監視のトリガー設定状況をお知らせするため、毎月1日に自動的に送信されるリマインダーです。\n\n{{triggerInfo}}\n\n-----\nこの通知は次のGoogleスプレッドシートによって管理されています:\n{{spreadsheetUrl}}', + mailSubErrorSendReminder: 'エラー:リマインダー送信', + messageMonitoredSitesPrefix: '公開ステータスの監視対象サイト', + messageTriggerLogExtractionIsSet: + '公開ステータスログを定期的に抽出するトリガーが設定されています。', }, }; @@ -425,4 +446,41 @@ class LocalizedMessage { text = this.replacePlaceholders_(text, placeholderValues); return text; } + /** + * Replace placeholder string in this.messageList.alertMessageCompleteReminderTriggerSetup + * @param {String} myEmail + * @returns {String} The replaced text. + */ + replaceAlertMessageCompleteReminderTriggerSetup(myEmail) { + let text = this.messageList.alertMessageCompleteReminderTriggerSetup; + let placeholderValues = [ + { + regexp: '{{myEmail}}', + value: myEmail, + }, + ]; + text = this.replacePlaceholders_(text, placeholderValues); + return text; + } + /** + * Replace placeholder string in this.messageList.mailBodySendReminder + * @param {String} triggerInfo + * @param {String} spreadsheetUrl + * @returns {String} The replaced text. + */ + replaceMailBodySendReminder(triggerInfo, spreadsheetUrl) { + let text = this.messageList.mailBodySendReminder; + let placeholderValues = [ + { + regexp: '{{triggerInfo}}', + value: triggerInfo, + }, + { + regexp: '{{spreadsheetUrl}}', + value: spreadsheetUrl, + }, + ]; + text = this.replacePlaceholders_(text, placeholderValues); + return text; + } } diff --git a/src/websiteMonitoring.js b/src/websiteMonitoring.js index ca17c53..7c98d22 100644 --- a/src/websiteMonitoring.js +++ b/src/websiteMonitoring.js @@ -212,7 +212,10 @@ function setupTrigger_(handlerFunction, frequencyKey, frequencyUnit) { * Trigger will be set for the first day of each month. */ function setupReminderTrigger() { - // UI alert message /////// + const ui = SpreadsheetApp.getUi(); + const localMessage = new LocalizedMessage( + SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetLocale() + ); const handlerFunction = 'sendReminder'; // Delete existing trigger for the same handler function. ScriptApp.getProjectTriggers().forEach((trigger) => { @@ -222,6 +225,13 @@ function setupReminderTrigger() { }); // Set new trigger ScriptApp.newTrigger(handlerFunction).timeBased().onMonthDay(1).create(); + ui.alert( + localMessage.replaceAlertTitleCompleteTriggerSetup(handlerFunction), + localMessage.replaceAlertMessageCompleteReminderTriggerSetup( + Session.getActiveUser().getEmail() + ), + ui.ButtonSet.OK + ); } /** @@ -761,6 +771,9 @@ function extractStatusLogs(triggered = false) { } } +/** + * Send a reminder to the user on the website status monitoring settings. + */ function sendReminder() { const triggers = ScriptApp.getProjectTriggers(); if (triggers.length > 0) { @@ -780,10 +793,9 @@ function sendReminder() { } return obj; }, {}); - var messageSub = '[Website Status] '; + var messageSub = localMessage.messageList.mailSubSendReminderPrefix; var messageBody = ''; try { - messageSub += 'Reminder: Active Triggers'; let triggerInfo = triggers .reduce((info, trigger) => { if (trigger.getHandlerFunction() === 'websiteMonitoringTriggered') { @@ -801,22 +813,30 @@ function sendReminder() { .getValues(); targetWebsitesArr.shift(); info.push( - `Website Monitoring:\n${targetWebsitesArr + `${ + localMessage.messageList.messageMonitoredSitesPrefix + }:\n${targetWebsitesArr .map((website) => `- ${website.join(' ')}`) .join('\n')}` ); } else if ( trigger.getHandlerFunction() === 'extractStatusLogsTriggered' ) { - info.push('Trigger for periodical status log extraction is set.'); + info.push( + localMessage.messageList.messageTriggerLogExtractionIsSet + ); } return info; }, []) .join('\n'); - messageBody = `This is a monthly reminder of the time-based triggers set for this website monitoring script:\n\n${triggerInfo}\n\n-----\nThis notice is managed by the following spreadsheet:\n${ss.getUrl()}`; ////// + messageSub += localMessage.messageList.mailSubSendReminder; + messageBody = localMessage.replaceMailBodySendReminder( + triggerInfo, + ss.getUrl() + ); } catch (e) { console.error(e.stack); - messageSub = '[Website Status] Error: Send Reminder'; // localMessage.messageList.mailSubErrorSendReminder; + messageSub += localMessage.messageList.mailSubErrorSendReminder; messageBody = localMessage.replaceMailBodyError(e.stack, ss.getUrl()); } finally { if (options.ENABLE_CHAT_NOTIFICATION) { From 11d98acec641c77f69d85b4cbce84103342f40fe Mon Sep 17 00:00:00 2001 From: ttsukagoshi Date: Tue, 10 Aug 2021 01:06:51 +0900 Subject: [PATCH 4/4] Add message to refer to the managing spreadsheet for the latest and detailed info on website status --- src/i18n.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/i18n.js b/src/i18n.js index 6ece903..2e5342c 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -76,7 +76,7 @@ const MESSAGES = { mailSubSendReminderPrefix: '[Website Status] ', mailSubSendReminder: 'Reminder: Active Triggers', mailBodySendReminder: - 'This is a monthly reminder, sent automatically, of the time-based triggers set for this website monitoring script:\n\n{{triggerInfo}}\n\n-----\nThis notice is managed by the following spreadsheet:\n{{spreadsheetUrl}}', + 'This is a monthly reminder, sent automatically, of the time-based triggers set for this website monitoring script:\n\n{{triggerInfo}}\nSee the managing spreadsheet for details on the latest website status.\n\n-----\nThis notice is managed by the following spreadsheet:\n{{spreadsheetUrl}}', mailSubErrorSendReminder: 'Error: Send Reminder', messageMonitoredSitesPrefix: 'Monitored Websites', messageTriggerLogExtractionIsSet: @@ -144,7 +144,7 @@ const MESSAGES = { mailSubSendReminderPrefix: '[サイト公開ステータス] ', mailSubSendReminder: 'リマインダー:設定されているトリガー', mailBodySendReminder: - 'これは、サイト公開ステータス監視のトリガー設定状況をお知らせするため、毎月1日に自動的に送信されるリマインダーです。\n\n{{triggerInfo}}\n\n-----\nこの通知は次のGoogleスプレッドシートによって管理されています:\n{{spreadsheetUrl}}', + 'これは、サイト公開ステータス監視のトリガー設定状況をお知らせするため、毎月1日に自動的に送信されるリマインダーです。\n\n{{triggerInfo}}\n最新のサイト公開ステータスについては、管理スプレッドシートをご確認ください。\n\n-----\nこの通知は次のGoogleスプレッドシートによって管理されています:\n{{spreadsheetUrl}}', mailSubErrorSendReminder: 'エラー:リマインダー送信', messageMonitoredSitesPrefix: '公開ステータスの監視対象サイト', messageTriggerLogExtractionIsSet: