Add webhook support to notification property in config (#143)
* Add basic webhook option to workerConfig.notification as alternative to apprise * Add uptime.config.ts example for webhook option * Removed trailing commas from newly added types for consistency * Add ability to customize webhook body * use template --------- Co-authored-by: lyc8503 <[email protected]>
This commit is contained in:
1 parent
d11f8deeb2
commit
4b24ad38a2
5 files changed
+120
-80
No files matched your search
+37
-16
@@ -84,13 +84,34 @@ const workerConfig: WorkerConfig = {
|
||||
timeout: 5000,
|
||||
},
|
||||
],
|
||||
// [Optional] Notification settings
|
||||
notification: {
|
||||
// [Optional] apprise API server URL
|
||||
// if not specified, no notification will be sent
|
||||
appriseApiServer: 'https://apprise.example.com/notify',
|
||||
// [Optional] recipient URL for apprise, refer to https://github.com/caronc/apprise
|
||||
// if not specified, no notification will be sent
|
||||
recipientUrl: 'tgram://bottoken/ChatID',
|
||||
// [Optional] Notification webhook settings, if not specified, no notification will be sent
|
||||
// Wiki: TODO
|
||||
webhook: {
|
||||
// [Required] webhook URL (example: Telegram Bot API)
|
||||
url: 'https://api.telegram.org/bot123456:ABCDEF/sendMessage',
|
||||
// [Optional] HTTP method, default to 'GET' for payloadType=param, 'POST' otherwise
|
||||
method: 'POST',
|
||||
// [Optional] headers to be sent
|
||||
headers: {
|
||||
foo: 'bar',
|
||||
},
|
||||
// [Required] Specify how to encode the payload
|
||||
// Should be one of 'param', 'json' or 'x-www-form-urlencoded'
|
||||
// 'param': append url-encoded payload to URL search parameters
|
||||
// 'json': POST json payload as body, set content-type header to 'application/json'
|
||||
// 'x-www-form-urlencoded': POST url-encoded payload as body, set content-type header to 'x-www-form-urlencoded'
|
||||
payloadType: 'x-www-form-urlencoded',
|
||||
// [Required] payload to be sent
|
||||
// $MSG will be replaced with the human-readable notification message
|
||||
payload: {
|
||||
chat_id: 12345678,
|
||||
text: '$MSG',
|
||||
},
|
||||
// [Optional] timeout calling this webhook, in millisecond, default to 5000
|
||||
timeout: 10000,
|
||||
},
|
||||
// [Optional] timezone used in notification messages, default to "Etc/GMT"
|
||||
timeZone: 'Asia/Shanghai',
|
||||
// [Optional] grace period in minutes before sending a notification
|
||||
@@ -153,15 +174,15 @@ const maintenances: MaintenanceConfig[] = [
|
||||
// This COULD BE DANGEROUS, as generating too many maintenance entries can lead to performance problems
|
||||
// Undeterministic outputs may also lead to bugs or unexpected behavior
|
||||
// If you don't know how to DEBUG, use this approach WITH CAUTION
|
||||
...(function (){
|
||||
const schedules = [];
|
||||
const today = new Date();
|
||||
...(function () {
|
||||
const schedules = []
|
||||
const today = new Date()
|
||||
|
||||
for (let i = -1; i <= 1; i++) {
|
||||
// JavaScript's Date object will automatically handle year rollovers
|
||||
const date = new Date(today.getFullYear(), today.getMonth() + i, 15);
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const date = new Date(today.getFullYear(), today.getMonth() + i, 15)
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
|
||||
schedules.push({
|
||||
title: `${year}/${parseInt(month)} - Test scheduled maintenance`,
|
||||
@@ -169,11 +190,11 @@ const maintenances: MaintenanceConfig[] = [
|
||||
body: 'Monthly scheduled maintenance',
|
||||
start: `${year}-${month}-15T02:00:00.000+08:00`,
|
||||
end: `${year}-${month}-15T04:00:00.000+08:00`,
|
||||
});
|
||||
})
|
||||
}
|
||||
return schedules;
|
||||
})()
|
||||
return schedules
|
||||
})(),
|
||||
]
|
||||
|
||||
// Don't forget this, otherwise compilation fails.
|
||||
export { pageConfig, workerConfig, maintenances }
|
||||
export { maintenances, pageConfig, workerConfig }
|
||||
Reference in new issue
Block a user