UNPKG

2.94 kBJavaScriptView Raw
1"use strict";
2/**
3 * Copyright 2018 Google Inc. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.Place = void 0;
19const helper_1 = require("./helper");
20/**
21 * Asks user to provide a geo-located place, possibly using contextual information,
22 * like a store near the user's location or a contact's address.
23 *
24 * Developer provides custom text prompts to tailor the request handled by Google.
25 *
26 * @example
27 * ```javascript
28 *
29 * // Actions SDK
30 * const app = actionssdk()
31 *
32 * app.intent('actions.intent.MAIN', conv => {
33 * conv.ask(new Place({
34 * prompt: 'Where do you want to get picked up?',
35 * context: 'To find a place to pick you up',
36 * }))
37 * })
38 *
39 * app.intent('actions.intent.PLACE', (conv, input, place, status) => {
40 * if (place) {
41 * conv.close(`Ah, I see. You want to get picked up at ${place.formattedAddress}`)
42 * } else {
43 * // Possibly do something with status
44 * conv.close(`Sorry, I couldn't find where you want to get picked up`)
45 * }
46 * })
47 *
48 * // Dialogflow
49 * const app = dialogflow()
50 *
51 * app.intent('Default Welcome Intent', conv => {
52 * conv.ask(new Place({
53 * prompt: 'Where do you want to get picked up?',
54 * context: 'To find a place to pick you up',
55 * }))
56 * })
57 *
58 * // Create a Dialogflow intent with the `actions_intent_PLACE` event
59 * app.intent('Get Place', (conv, params, place, status) => {
60 * if (place) {
61 * conv.close(`Ah, I see. You want to get picked up at ${place.formattedAddress}`)
62 * } else {
63 * // Possibly do something with status
64 * conv.close(`Sorry, I couldn't find where you want to get picked up`)
65 * }
66 * })
67 * ```
68 *
69 * @public
70 */
71class Place extends helper_1.SoloHelper {
72 /**
73 * @param options Place options
74 * @public
75 */
76 constructor(options) {
77 const extension = {
78 '@type': 'type.googleapis.com/google.actions.v2.PlaceValueSpec.PlaceDialogSpec',
79 permissionContext: options.context,
80 requestPrompt: options.prompt,
81 };
82 super({
83 intent: 'actions.intent.PLACE',
84 type: 'type.googleapis.com/google.actions.v2.PlaceValueSpec',
85 data: {
86 dialogSpec: {
87 extension,
88 },
89 },
90 });
91 }
92}
93exports.Place = Place;
94//# sourceMappingURL=place.js.map
\No newline at end of file