Skip to content

Commit

Permalink
Merge pull request #892 from jovotech/ca-transactions
Browse files Browse the repository at this point in the history
✨ Transactions for Google Assistant Conversational Actions
  • Loading branch information
aswetlow committed Feb 3, 2021
2 parents ceaea11 + 217648e commit a8db4f8
Show file tree
Hide file tree
Showing 75 changed files with 5,940 additions and 92 deletions.
Expand Up @@ -31,7 +31,7 @@ app.setHandler({

MyNameIsIntent() {
console.log(this.$request.getInputs());

this.tell('Hey ' + this.$inputs.name.value + ', nice to meet you!');
},
});
Expand Down
@@ -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"
}
}
}
}
}
}
@@ -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"
}
@@ -0,0 +1,10 @@
// ------------------------------------------------------------------
// JOVO PROJECT CONFIGURATION
// ------------------------------------------------------------------

module.exports = {
googleAction: {
projectId: '<PROJECT ID>',
},
endpoint: '${JOVO_WEBHOOK_URL}',
};
@@ -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 };
@@ -0,0 +1,17 @@
// ------------------------------------------------------------------
// APP CONFIGURATION
// ------------------------------------------------------------------

module.exports = {
logging: true,

intentMap: {
'AMAZON.StopIntent': 'END',
},

db: {
FileDb: {
pathToFile: '../db/db.json',
},
},
};
@@ -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 examples/javascript/02_googleassistantconv/scenes/src/index.js
@@ -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));
};
@@ -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"
}
}
}
}
}
}

0 comments on commit a8db4f8

Please sign in to comment.