43 lines
966 B
JavaScript
43 lines
966 B
JavaScript
const axios = require('axios');
|
|
|
|
|
|
class PushoverTransport
|
|
{
|
|
async send(logger, contact, notification)
|
|
{
|
|
try
|
|
{
|
|
const data = {
|
|
token: contact.token,
|
|
user: contact.user,
|
|
message: notification.message,
|
|
priority: notification.priority,
|
|
timestamp: notification.timestamp,
|
|
url: notification.url,
|
|
url_title: contact.urlTitle || 'Manage notifications'
|
|
};
|
|
|
|
if (notification.sound)
|
|
data.sound = notification.sound;
|
|
|
|
if (notification.priority === 2)
|
|
{
|
|
data.retry = 300;
|
|
data.expire = 3600;
|
|
}
|
|
|
|
const response = await axios.post("https://api.pushover.net/1/messages.json", data);
|
|
logger.verbose(`Pushover API returned status code ${response.status}`);
|
|
|
|
return response.status === 200;
|
|
}
|
|
catch (err)
|
|
{
|
|
logger.verbose(`Pushover API error: ${err}`);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = PushoverTransport; |