-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #892 from jovotech/ca-transactions
✨ Transactions for Google Assistant Conversational Actions
- Loading branch information
Showing
75 changed files
with
5,940 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
examples/javascript/02_googleassistantconv/push-notifications/models/en.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"invocation": "my test app", | ||
"intents": [ | ||
{ | ||
"name": "PushNotificationsIntent", | ||
"phrases": ["notify me"] | ||
}, | ||
{ | ||
"name": "PushNotificationsClickedIntent", | ||
"phrases": [] | ||
} | ||
], | ||
"googleAssistant": { | ||
"custom": { | ||
"scenes": { | ||
"PushNotificationsScene": { | ||
"intentEvents": [ | ||
{ | ||
"intent": "PushNotificationsIntent", | ||
"transitionToScene": "PushNotificationScene_Notifications" | ||
} | ||
] | ||
}, | ||
"PushNotificationsScene_Notifications": { | ||
"conditionalEvents": [ | ||
{ | ||
"condition": "scene.slots.status == \"FINAL\" && (session.params.NotificationsSlot_PushNotificationsClickedIntent.permissionStatus == \"PERMISSION_GRANTED\" || session.params.NotificationsSlot_PushNotificationsClickedIntent.permissionStatus == \"ALREADY_GRANTED\")", | ||
"handler": { | ||
"webhookHandler": "Jovo" | ||
} | ||
}, | ||
{ | ||
"condition": "scene.slots.status == \"FINAL\" && session.params.NotificationsSlot_PushNotificationsClickedIntent.permissionStatus != \"PERMISSION_GRANTED\" && session.params.NotificationsSlot_PushNotificationsClickedIntent.permissionStatus != \"ALREADY_GRANTED\"", | ||
"handler": { | ||
"webhookHandler": "Jovo" | ||
} | ||
} | ||
], | ||
"slots": [ | ||
{ | ||
"commitBehavior": { | ||
"writeSessionParam": "NotificationsSlot_PushNotificationsClickedIntent" | ||
}, | ||
"config": { | ||
"intent": { | ||
"intentName": "PushNotificationsClickedIntent" | ||
} | ||
}, | ||
"defaultValue": { | ||
"sessionParam": "NotificationsSlot_PushNotificationsClickedIntent" | ||
}, | ||
"name": "NotificationsSlot_PushNotificationsClickedIntent", | ||
"required": true, | ||
"type": { | ||
"name": "actions.type.Notifications" | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"global": { | ||
"actions.intent.MAIN": { | ||
"handler": { | ||
"webhookHandler": "Jovo" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
examples/javascript/02_googleassistantconv/push-notifications/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "jovo-examples-googleassistantconv-push-notifications", | ||
"version": "3.0.0", | ||
"description": "A sample voice app that works with the Jovo Framework", | ||
"main": "src/index.js", | ||
"dependencies": { | ||
"jovo-db-filedb": "^3.1.3", | ||
"jovo-framework": "^3.3.0", | ||
"jovo-platform-googleassistantconv": "^3.1.3", | ||
"jovo-plugin-debugger": "^3.1.3" | ||
}, | ||
"devDependencies": { | ||
"gulp": "^4.0.2", | ||
"gulp-install": "^1.1.0", | ||
"gulp-run-command": "0.0.10", | ||
"gulp-zip": "^5.0.1", | ||
"jest": "^26.0.1" | ||
}, | ||
"scripts": { | ||
"tsc": "node -v", | ||
"test": "jest", | ||
"bundle": "gulp --gulpfile node_modules/jovo-framework/gulpfile.js --cwd ./", | ||
"start": "cd src && node index.js --webhook", | ||
"launch": "npm start -- --launch" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/jovotech/jovo-sample-voice-app-nodejs.git" | ||
}, | ||
"author": "Jovo", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/jovotech/jovo-sample-voice-app-nodejs/issues" | ||
}, | ||
"homepage": "https://github.com/jovotech/jovo-sample-voice-app-nodejs#readme" | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/javascript/02_googleassistantconv/push-notifications/project.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// ------------------------------------------------------------------ | ||
// JOVO PROJECT CONFIGURATION | ||
// ------------------------------------------------------------------ | ||
|
||
module.exports = { | ||
googleAction: { | ||
projectId: '<PROJECT ID>', | ||
}, | ||
endpoint: '${JOVO_WEBHOOK_URL}', | ||
}; |
57 changes: 57 additions & 0 deletions
57
examples/javascript/02_googleassistantconv/push-notifications/src/app.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
const { App } = require('jovo-framework'); | ||
const { | ||
GoogleAssistant, | ||
PushNotificationsApi, | ||
} = require('jovo-platform-googleassistantconv'); | ||
const { JovoDebugger } = require('jovo-plugin-debugger'); | ||
const { FileDb } = require('jovo-db-filedb'); | ||
|
||
// ------------------------------------------------------------------ | ||
// APP INITIALIZATION | ||
// ------------------------------------------------------------------ | ||
|
||
const app = new App(); | ||
|
||
app.use(new GoogleAssistant(), new JovoDebugger(), new FileDb()); | ||
|
||
// ------------------------------------------------------------------ | ||
// APP LOGIC | ||
// ------------------------------------------------------------------ | ||
|
||
app.setHandler({ | ||
LAUNCH() { | ||
this.$googleAction.setNextScene('PushNotificationsScene'); | ||
this.ask('If you want me to send you notifications, just say "notify me".'); | ||
}, | ||
|
||
PushNotificationsClickedIntent() { | ||
this.tell('Hello World!'); | ||
}, | ||
|
||
async ON_PERMISSION() { | ||
if ( | ||
this.$googleAction.isPermissionGranted() || | ||
this.$googleAction.isPermissionAlreadyGranted() | ||
) { | ||
const credentials = require('../credentials.json'); | ||
const reminderUserId = this.$googleAction.getNotificationsUserId(); | ||
|
||
const api = new PushNotificationsApi(credentials); | ||
|
||
await api.sendPushNotification({ | ||
userId: reminderUserId, | ||
intent: 'PushNotificationsClickedIntent', | ||
title: 'Click me!', | ||
locale: 'en', | ||
}); | ||
|
||
this.ask('Great!'); | ||
} else { | ||
this.ask('Ok.'); | ||
} | ||
}, | ||
}); | ||
|
||
module.exports = { app }; |
17 changes: 17 additions & 0 deletions
17
examples/javascript/02_googleassistantconv/push-notifications/src/config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// ------------------------------------------------------------------ | ||
// APP CONFIGURATION | ||
// ------------------------------------------------------------------ | ||
|
||
module.exports = { | ||
logging: true, | ||
|
||
intentMap: { | ||
'AMAZON.StopIntent': 'END', | ||
}, | ||
|
||
db: { | ||
FileDb: { | ||
pathToFile: '../db/db.json', | ||
}, | ||
}, | ||
}; |
27 changes: 27 additions & 0 deletions
27
examples/javascript/02_googleassistantconv/push-notifications/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
const { ExpressJS, Lambda, Webhook } = require('jovo-framework'); | ||
const { app } = require('./app.js'); | ||
|
||
// ------------------------------------------------------------------ | ||
// HOST CONFIGURATION | ||
// ------------------------------------------------------------------ | ||
|
||
// ExpressJS (Jovo Webhook) | ||
if (process.argv.indexOf('--webhook') > -1) { | ||
const port = process.env.JOVO_PORT || 3000; | ||
Webhook.jovoApp = app; | ||
|
||
Webhook.listen(port, () => { | ||
console.info(`Local server listening on port ${port}.`); | ||
}); | ||
|
||
Webhook.post('/webhook', async (req, res) => { | ||
await app.handle(new ExpressJS(req, res)); | ||
}); | ||
} | ||
|
||
// AWS Lambda | ||
exports.handler = async (event, context, callback) => { | ||
await app.handle(new Lambda(event, context, callback)); | ||
}; |
26 changes: 11 additions & 15 deletions
26
examples/javascript/02_googleassistantconv/scenes/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,21 @@ | ||
'use strict'; | ||
const { | ||
Webhook, | ||
ExpressJS, | ||
Lambda | ||
} = require('jovo-framework'); | ||
const { Webhook, ExpressJS, Lambda } = require('jovo-framework'); | ||
|
||
const {app} = require('./app.js'); | ||
const { app } = require('./app.js'); | ||
|
||
if (process.argv.indexOf('--webhook') > -1) { | ||
const port = process.env.JOVO_PORT || 3000; | ||
Webhook.jovoApp = app; | ||
Webhook.listen(port, () => { | ||
console.info(`Local server listening on port ${port}!`); | ||
}); | ||
const port = process.env.JOVO_PORT || 3000; | ||
Webhook.jovoApp = app; | ||
Webhook.listen(port, () => { | ||
console.info(`Local server listening on port ${port}!`); | ||
}); | ||
|
||
Webhook.post('/webhook', async (req, res) => { | ||
await app.handle(new ExpressJS(req, res)); | ||
}); | ||
Webhook.post('/webhook', async (req, res) => { | ||
await app.handle(new ExpressJS(req, res)); | ||
}); | ||
} | ||
|
||
// AWS Lambda | ||
exports.handler = async (event, context, callback) => { | ||
await app.handle(new Lambda(event, context, callback)); | ||
await app.handle(new Lambda(event, context, callback)); | ||
}; |
100 changes: 100 additions & 0 deletions
100
examples/javascript/02_googleassistantconv/transactions-digitalgoods/models/en.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
"invocation": "transactions demo", | ||
"intents": [ | ||
{ | ||
"name": "YesIntent", | ||
"phrases": [ | ||
"Yo", | ||
"Yeah", | ||
"Yes" | ||
] | ||
} | ||
], | ||
"inputTypes": [ | ||
{ | ||
"name": "NameInputType", | ||
"values": [] | ||
} | ||
], | ||
"googleAssistant": { | ||
"custom": { | ||
"scenes": { | ||
"TransactionCompletePurchaseScene": { | ||
"conditionalEvents": [ | ||
{ | ||
"condition": "scene.slots.status == \"FINAL\"", | ||
"handler": { | ||
"webhookHandler": "Jovo" | ||
} | ||
} | ||
], | ||
"slots": [ | ||
{ | ||
"commitBehavior": { | ||
"writeSessionParam": "CompletePurchase" | ||
}, | ||
"config": "$session.params.purchase", | ||
"name": "CompletePurchase", | ||
"required": true, | ||
"type": { | ||
"name": "actions.type.CompletePurchaseValue" | ||
} | ||
} | ||
] | ||
}, | ||
"TransactionDigitalPurchaseCheckScene": { | ||
"conditionalEvents": [ | ||
{ | ||
"condition": "scene.slots.status == \"FINAL\"", | ||
"handler": { | ||
"webhookHandler": "Jovo" | ||
} | ||
} | ||
], | ||
"slots": [ | ||
{ | ||
"commitBehavior": { | ||
"writeSessionParam": "DigitalPurchaseCheck" | ||
}, | ||
"config": { | ||
"@type": "type.googleapis.com/google.actions.transactions.v3.DigitalPurchaseCheckSpec" | ||
}, | ||
"name": "DigitalPurchaseCheck", | ||
"required": true, | ||
"type": { | ||
"name": "actions.type.DigitalPurchaseCheckResult" | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"global": { | ||
"actions.intent.CANCEL": { | ||
"handler": { | ||
"webhookHandler": "Jovo" | ||
} | ||
}, | ||
"actions.intent.MAIN": { | ||
"handler": { | ||
"webhookHandler": "Jovo" | ||
} | ||
}, | ||
"actions.intent.NO_INPUT_1": { | ||
"handler": { | ||
"webhookHandler": "Jovo" | ||
} | ||
}, | ||
"actions.intent.NO_INPUT_2": { | ||
"handler": { | ||
"webhookHandler": "Jovo" | ||
} | ||
}, | ||
"actions.intent.NO_INPUT_FINAL": { | ||
"handler": { | ||
"webhookHandler": "Jovo" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.