0
Emergency Push Notification
One script reply has been approved by the moderators Verified

A publicly-accessible URL that Pushover will send a request to when the user has acknowledged the notification

Created by maximehacecadahut 912 days ago Viewed 3202 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 211 days ago
1
type Pushover = {
2
	apiToken: string
3
	userKey: string
4
}
5

6
export async function main(
7
	resource: Pushover,
8
	data: {
9
		message: string
10
		retry: number
11
		expire: number
12
		device?: string
13
		title?: string
14
	}
15
) {
16
	const form = new URLSearchParams()
17
	form.append('token', resource.apiToken)
18
	form.append('user', resource.userKey)
19
	form.append('message', data.message)
20
	form.append('retry', data.retry.toString())
21
	form.append('expire', data.expire.toString())
22
	form.append('priority', '2')
23
	data.device && form.append('device', data.device)
24
	data.title && form.append('title', data.title)
25

26
	return (
27
		await fetch('https://api.pushover.net/1/messages.json', {
28
			method: 'POST',
29
			body: form,
30
			headers: {
31
				'Content-Type': 'application/x-www-form-urlencoded'
32
			}
33
		})
34
	).json()
35
}
36