-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Pushover notification adapter (#91)
* Add Pushover notification adapter
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { markdown2Html } from '../../services/markdown.js'; | ||
import { getJob } from '../../services/storage/jobStorage.js'; | ||
import fetch from 'node-fetch'; | ||
|
||
export const send = ({ serviceName, newListings, notificationConfig, jobKey }) => { | ||
const { token, user, device } = notificationConfig.find((adapter) => adapter.id === config.id).fields; | ||
const job = getJob(jobKey); | ||
const jobName = job == null ? jobKey : job.name; | ||
const promises = newListings.map((newListing) => { | ||
const title = `${serviceName}: ${newListing.title}`; | ||
const message = `Address: ${newListing.address}\nSize: ${newListing.size}\nPrice: ${newListing.price}\nLink: ${newListing.link}`; | ||
return fetch('https://api.pushover.net/1/messages.json', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
token: token, | ||
user: user, | ||
message: message, | ||
device: device, | ||
title: newListing.title, | ||
}), | ||
}); | ||
}); | ||
|
||
return Promise.all(promises); | ||
}; | ||
|
||
export const config = { | ||
id: 'pushover', | ||
name: 'Pushover', | ||
readme: markdown2Html('lib/notification/adapter/pushover.md'), | ||
description: 'Fredy will send new listings to your mobile using Pushover.', | ||
fields: { | ||
token: { | ||
type: 'text', | ||
label: 'API token', | ||
description: 'Your application\'s API token.', | ||
}, | ||
user: { | ||
type: 'text', | ||
label: 'User key', | ||
description: 'Your user/group key.', | ||
}, | ||
device: { | ||
type: 'text', | ||
label: 'Device name', | ||
description: 'The device name to send your notification to. Messages may be addressed to multiple specific devices by joining them with a comma.', | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### Pushover Adapter | ||
|
||
Refer to the [instructions](https://support.pushover.net/i7-what-is-pushover-and-how-do-i-use-it) to set up your Pushover application. | ||
|
||
After setting up the application, please enter both your newly created User key and API token. |