-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
executable file
·37 lines (33 loc) · 989 Bytes
/
node_helper.js
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
36
37
'use strict';
const NodeHelper = require('node_helper');
const AWS = require('aws-sdk');
AWS.config.loadFromPath(__dirname + '/config.json');
var ddb = new AWS.DynamoDB()
module.exports = NodeHelper.create({
// Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
if (notification === 'START_MODULE') {
this.start_module(payload);
}
},
start_module: function(payload) {
let self = this
var fetchDB = function() {
ddb.query({
TableName: 'Notes',
KeyConditionExpression: 'userId = :uid',
ExpressionAttributeValues: {
':uid': {
"S": payload.alexaUserId
}
}
}, function(err, results) {
// send notes to mirror
self.sendSocketNotification("RESULT", results.Items[0].mapAttr.M.notes.L);
// do this every 5 minute to update the list
setTimeout(fetchDB, 300000);
})
}
fetchDB();
}
});