-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (30 loc) · 1.08 KB
/
index.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
38
var xal = require('../../xal-javascript');
var _ = require('underscore');
var toleranceMinutes = 0.1;
var lastSeen = 0;
var lastPresenceValue = false;
xal.on('xi.event.inform.user.presence', function(state,next){
var value = _.reduce(state.get('xi.event.inform.user.presence'), function(memo, dest) {
return memo || dest.value ;
},false);
if(!lastPresenceValue && value){
xal.log.info('this is true');
var currentTime = new Date();
// TODO: Figure out if this is necessary
if(true || Math.abs(currentTime - lastSeen) > toleranceMinutes * 1000 * 60){
xal.createEvent('xi.event.output.text', function(state, done){
state.put('xi.event.output.text', 'Hello, human.');
done(state);
});
}
lastSeen = currentTime;
}
lastPresenceValue = value;
});
xal.start({name: 'Greet'}, function(){
xal.createEvent('xi.event.ask.user.presence', function(state, done){
state.put('xi.event.ask.user.presence', '?');
done(state);
});
//initialize lastSeen
});