-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_helper.js
More file actions
35 lines (31 loc) · 1.03 KB
/
node_helper.js
File metadata and controls
35 lines (31 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const NodeHelper = require("node_helper");
const fetch = require("node-fetch");
module.exports = NodeHelper.create({
start: function() {
console.log("Starting node_helper for module [" + this.name + "]");
},
getQuote: function() {
var self = this;
var maxLength = self.config.maxLength;
var tags = self.config.tags;
var url = "https://api.quotable.io/random?maxLength=" + maxLength + "&tags=" + tags;
fetch(url)
.then(response => response.json())
.then(data => {
var quoteText = data.content;
var quoteAuthor = data.author;
self.sendSocketNotification("QUOTE", {
quote: quoteText,
author: quoteAuthor
});
})
.catch(error => {
console.error(self.name + ": Could not load quote.", error);
});
},
socketNotificationReceived: function(notification, payload) {
if (notification === "GET_QUOTE") {
this.getQuote();
}
}
});