/
app.js
75 lines (61 loc) 路 2.15 KB
/
app.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'use strict';
// ------------------------------------------------------------------
// APP INITIALIZATION
// ------------------------------------------------------------------
const { App } = require('jovo-framework');
const { GoogleAssistant, NotificationPlugin } = require('jovo-platform-googleassistant');
const app = new App();
const googleAssistant = new GoogleAssistant();
googleAssistant.use(new NotificationPlugin());
app.use(
googleAssistant
);
// ------------------------------------------------------------------
// APP LOGIC
// ------------------------------------------------------------------
app.setHandler({
async LAUNCH() {
this.toIntent('AskForNotifications');
// this.toIntent('SendNotificationIntent');
},
AskForNotifications() {
// You have to show them suggestion chips inviting them to opt-in,
// before you can send the actual permission request
this.$googleAction.showSuggestionChips(['yes', 'no']);
this.ask('Notifications?');
},
YesIntent() {
this.$googleAction.askForNotification('HelloWorldIntent');
},
async SendNotificationIntent() {
const accessToken = await this.$googleAction.$notification.getAccessToken(
'<client-email>',
'<private-key>'
);
const notification = {
customPushMessage: {
userNotification: {
title: 'Notification Test Title',
},
target: {
userId: this.$user.getId(),
intent: 'HelloWorldIntent',
locale: this.$request.getLocale()
},
}
};
const result = await this.$googleAction.$notification.sendNotification(notification, accessToken);
this.tell('Notification sent!');
},
HelloWorldIntent() {
// this.tell('Hello World!');
},
ON_PERMISSION() {
if (this.$googleAction.isPermissionGranted()) {
this.tell('Alright! You will receive notifications');
} else {
this.tell('You won\'t receive notifications');
}
}
});
module.exports.app = app;