From 7b95da7c92e82c968aae4b36f3a39569606b123f Mon Sep 17 00:00:00 2001 From: James Daniels Date: Thu, 2 Mar 2017 14:24:59 -0800 Subject: [PATCH] Adding an initial actions sdk example Ported https://github.com/actions-on-google/actionssdk-say-number-nodejs with some minor enhancements. Change-Id: I4b74d6a2011e77dd4707758aa3d329965cc9f0db --- actionssdk-say-number/action.json | 18 ++++++ actionssdk-say-number/firebase.json | 1 + actionssdk-say-number/functions/index.js | 64 ++++++++++++++++++++ actionssdk-say-number/functions/package.json | 9 +++ 4 files changed, 92 insertions(+) create mode 100644 actionssdk-say-number/action.json create mode 100644 actionssdk-say-number/firebase.json create mode 100644 actionssdk-say-number/functions/index.js create mode 100644 actionssdk-say-number/functions/package.json diff --git a/actionssdk-say-number/action.json b/actionssdk-say-number/action.json new file mode 100644 index 0000000..13b9b88 --- /dev/null +++ b/actionssdk-say-number/action.json @@ -0,0 +1,18 @@ +{ + "versionLabel": "1.0.0", + "agentInfo": { + "languageCode": "en-US", + "projectId": "hello", + "voiceName": "male_1" + }, + "actions": [ + { + "initialTrigger": { + "intent": "assistant.intent.action.MAIN" + }, + "httpExecution": { + "url": "YOUR_ENDPOINT_URL" + } + } + ] +} diff --git a/actionssdk-say-number/firebase.json b/actionssdk-say-number/firebase.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/actionssdk-say-number/firebase.json @@ -0,0 +1 @@ +{} diff --git a/actionssdk-say-number/functions/index.js b/actionssdk-say-number/functions/index.js new file mode 100644 index 0000000..514d87e --- /dev/null +++ b/actionssdk-say-number/functions/index.js @@ -0,0 +1,64 @@ +// Copyright 2016, Google, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// [START app] +'use strict'; + +const functions = require('firebase-functions'); + +exports.helloWorld = functions.https.onRequest((request, response) => { + + const ActionsSdkAssistant = require('actions-on-google').ActionsSdkAssistant; + const assistant = new ActionsSdkAssistant({request, response}); + + const reprompts = [ + "I didn't hear a number", + "If you're still there, what's the number?", + 'What is the number?' + ]; + + let actionMap = new Map(); + + actionMap.set(assistant.StandardIntents.MAIN, assistant => { + const inputPrompt = assistant.buildInputPrompt(true, ` + Hi! + I can read out an ordinal like 123. + Say a number. + `, reprompts + ); + assistant.ask(inputPrompt); + }); + + actionMap.set(assistant.StandardIntents.TEXT, assistant => { + const rawInput = assistant.getRawInput(); + if (rawInput === 'bye') { + assistant.tell('Goodbye!'); + } else if (isNaN(parseInt(rawInput))) { + const inputPrompt = assistant.buildInputPrompt(false, `I didn't quite get that, what was the + number?`, reprompts); + assistant.ask(inputPrompt); + } else { + const inputPrompt = assistant.buildInputPrompt(true, ` + The ordinal of ${rawInput} is + ${rawInput} + `, reprompts + ); + assistant.ask(inputPrompt); + } + }); + + assistant.handleRequest(actionMap); + +}) +// [END app] diff --git a/actionssdk-say-number/functions/package.json b/actionssdk-say-number/functions/package.json new file mode 100644 index 0000000..3e5f61b --- /dev/null +++ b/actionssdk-say-number/functions/package.json @@ -0,0 +1,9 @@ +{ + "name": "functions", + "description": "Firebase Functions", + "dependencies": { + "actions-on-google": "^1.0.7", + "firebase-admin": "^4.0.5", + "firebase-functions": "https://storage.googleapis.com/firebase-preview-drop/node/firebase-functions/firebase-functions-preview.latest.tar.gz" + } +}