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 utils = require(__dirname + '/lib/utils'); // Get common adapter utils
|
||||||
const Pushover = require('pushover-notifications');
|
const Pushover = require('pushover-notifications');
|
||||||
|
|
||||||
|
const Request = require('request');
|
||||||
|
|
||||||
const adapter = new utils.Adapter('pushover');
|
const adapter = new utils.Adapter('pushover');
|
||||||
|
|
||||||
adapter.on('message', obj => {
|
adapter.on('message', obj => {
|
||||||
@ -105,6 +107,7 @@ function sendNotification(message, callback) {
|
|||||||
} else {
|
} else {
|
||||||
pushover.token = adapter.config.token
|
pushover.token = adapter.config.token
|
||||||
}
|
}
|
||||||
|
|
||||||
message.title = message.title || adapter.config.title;
|
message.title = message.title || adapter.config.title;
|
||||||
message.sound = message.sound || (adapter.config.sound ? adapter.config.sound : undefined);
|
message.sound = message.sound || (adapter.config.sound ? adapter.config.sound : undefined);
|
||||||
message.priority = message.priority || adapter.config.priority;
|
message.priority = message.priority || adapter.config.priority;
|
||||||
@ -125,6 +128,24 @@ function sendNotification(message, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
adapter.log.info('Send pushover notification: ' + JSON.stringify(message));
|
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) => {
|
pushover.send(message, (err, result) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user