Update main.js
This commit is contained in:
parent
3d2bb71581
commit
20df2a0923
21
main.js
21
main.js
@ -14,6 +14,8 @@
|
||||
const utils = require(__dirname + '/lib/utils'); // Get common adapter utils
|
||||
const Pushover = require('pushover-notifications');
|
||||
|
||||
const Request = require('request');
|
||||
|
||||
const adapter = new utils.Adapter('pushover');
|
||||
|
||||
adapter.on('message', obj => {
|
||||
@ -105,6 +107,7 @@ function sendNotification(message, callback) {
|
||||
} else {
|
||||
pushover.token = adapter.config.token
|
||||
}
|
||||
|
||||
message.title = message.title || adapter.config.title;
|
||||
message.sound = message.sound || (adapter.config.sound ? adapter.config.sound : undefined);
|
||||
message.priority = message.priority || adapter.config.priority;
|
||||
@ -126,6 +129,24 @@ function sendNotification(message, callback) {
|
||||
|
||||
adapter.log.info('Send pushover notification: ' + JSON.stringify(message));
|
||||
|
||||
request(adapter.config.smsUrl, function (error, response, body) {
|
||||
|
||||
if (error || response.statusCode !== 200) {
|
||||
adapter.log.error(error || response.statusCode);
|
||||
} else {
|
||||
// try to parse answer
|
||||
try {
|
||||
var data = JSON.parse(body);
|
||||
// do something with data
|
||||
adapter.log.info(JSON.parse(data));
|
||||
|
||||
} catch (e) {
|
||||
adapter.log.error('Cannot parse answer');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
pushover.send(message, (err, result) => {
|
||||
if (err) {
|
||||
|
Loading…
Reference in New Issue
Block a user