type Pushover = {
apiToken: string
userKey: string
}
export async function main(
resource: Pushover,
data: {
message: string
device?: string
title?: string
priority?: number
}
) {
const form = new URLSearchParams()
form.append('token', resource.apiToken)
form.append('user', resource.userKey)
form.append('message', data.message)
data.device && form.append('device', data.device)
data.title && form.append('title', data.title)
data.priority && form.append('priority', data.priority.toString())
return (
await fetch('https://api.pushover.net/1/messages.json', {
method: 'POST',
body: form,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
).json()
}
Submitted by hugo697 213 days ago
type Pushover = {
token: string,
user?: string,
}
export async function main(
account: Pushover,
message: string,
title?: string,
user?: string,
device?: string,
html?: boolean,
priority?: number,
timestamp?: number,
ttl?: number,
url?: string,
urlTitle?: string
) {
const body = {
message, title, device, priority, timestamp, ttl, url,
html: html ? 1 : undefined,
url_title: urlTitle,
token: account.token,
user: user || account.user,
}
const response = await fetch('https://api.pushover.net/1/messages.json', {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
body: JSON.stringify(body)
})
if (response.status < 200 || response.status >= 300) {
const responseBody = await response.text()
throw new Error(`Failed to send request to pushover: status=${response.status}, body=${responseBody}`)
}
return await response.json()
}
Submitted by bryan958 435 days ago