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

Sends a Push Notification to devices with Pushover. More information at Pushing Messages

Created by paulparod 899 days ago Viewed 11808 times
1
Submitted by bryan958 Typescript (fetch-only)
Verified 420 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
		device?: string
11
		title?: string
12
		priority?: number
13
	}
14
) {
15
	const form = new URLSearchParams()
16
	form.append('token', resource.apiToken)
17
	form.append('user', resource.userKey)
18
	form.append('message', data.message)
19
	data.device && form.append('device', data.device)
20
	data.title && form.append('title', data.title)
21
	data.priority && form.append('priority', data.priority.toString())
22

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