Skip to content

Commit 8e3ebcb

Browse files
Nicolas GarnierGerrit Code Review
Nicolas Garnier
authored and
Gerrit Code Review
committed
Merge "Adding an initial actions sdk example"
2 parents ae7c556 + 7b95da7 commit 8e3ebcb

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

actionssdk-say-number/action.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"versionLabel": "1.0.0",
3+
"agentInfo": {
4+
"languageCode": "en-US",
5+
"projectId": "hello",
6+
"voiceName": "male_1"
7+
},
8+
"actions": [
9+
{
10+
"initialTrigger": {
11+
"intent": "assistant.intent.action.MAIN"
12+
},
13+
"httpExecution": {
14+
"url": "YOUR_ENDPOINT_URL"
15+
}
16+
}
17+
]
18+
}

actionssdk-say-number/firebase.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2016, Google, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// [START app]
16+
'use strict';
17+
18+
const functions = require('firebase-functions');
19+
20+
exports.helloWorld = functions.https.onRequest((request, response) => {
21+
22+
const ActionsSdkAssistant = require('actions-on-google').ActionsSdkAssistant;
23+
const assistant = new ActionsSdkAssistant({request, response});
24+
25+
const reprompts = [
26+
"I didn't hear a number",
27+
"If you're still there, what's the number?",
28+
'What is the number?'
29+
];
30+
31+
let actionMap = new Map();
32+
33+
actionMap.set(assistant.StandardIntents.MAIN, assistant => {
34+
const inputPrompt = assistant.buildInputPrompt(true, `<speak>
35+
Hi! <break time="1"/>
36+
I can read out an ordinal like <say-as interpret-as="ordinal">123</say-as>.
37+
Say a number.
38+
</speak>`, reprompts
39+
);
40+
assistant.ask(inputPrompt);
41+
});
42+
43+
actionMap.set(assistant.StandardIntents.TEXT, assistant => {
44+
const rawInput = assistant.getRawInput();
45+
if (rawInput === 'bye') {
46+
assistant.tell('Goodbye!');
47+
} else if (isNaN(parseInt(rawInput))) {
48+
const inputPrompt = assistant.buildInputPrompt(false, `I didn't quite get that, what was the
49+
number?`, reprompts);
50+
assistant.ask(inputPrompt);
51+
} else {
52+
const inputPrompt = assistant.buildInputPrompt(true, `<speak>
53+
The ordinal of <say-as interpret-as="cardinal">${rawInput}</say-as> is
54+
<say-as interpret-as="ordinal">${rawInput}</say-as>
55+
</speak>`, reprompts
56+
);
57+
assistant.ask(inputPrompt);
58+
}
59+
});
60+
61+
assistant.handleRequest(actionMap);
62+
63+
})
64+
// [END app]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "functions",
3+
"description": "Firebase Functions",
4+
"dependencies": {
5+
"actions-on-google": "^1.0.7",
6+
"firebase-admin": "^4.0.5",
7+
"firebase-functions": "https://storage.googleapis.com/firebase-preview-drop/node/firebase-functions/firebase-functions-preview.latest.tar.gz"
8+
}
9+
}

0 commit comments

Comments
 (0)