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.DateTime = void 0;
19const helper_1 = require("./helper");
20/**
21 * Asks user for a timezone-agnostic date and time.
22 *
23 * @example
24 * ```javascript
25 *
26 * // Actions SDK
27 * const app = actionssdk()
28 *
29 * app.intent('actions.intent.MAIN', conv => {
30 * conv.ask(new DateTime({
31 * prompts: {
32 * initial: 'When do you want to come in?',
33 * date: 'Which date works best for you?',
34 * time: 'What time of day works best for you?',
35 * }
36 * }))
37 * })
38 *
39 * app.intent('actions.intent.DATETIME', (conv, input, datetime) => {
40 * const { month, day } = datetime.date
41 * const { hours, minutes } = datetime.time
42 * conv.close(new SimpleResponse({
43 * speech: 'Great see you at your appointment!',
44 * text: `Great, we will see you on ${month}/${day} at ${hours} ${minutes || ''}`
45 * }))
46 * })
47 *
48 * // Dialogflow
49 * const app = dialogflow()
50 *
51 * app.intent('Default Welcome Intent', conv => {
52 * conv.ask(new DateTime({
53 * prompts: {
54 * initial: 'When do you want to come in?',
55 * date: 'Which date works best for you?',
56 * time: 'What time of day works best for you?',
57 * }
58 * }))
59 * })
60 *
61 * // Create a Dialogflow intent with the `actions_intent_DATETIME` event
62 * app.intent('Get Datetime', (conv, params, datetime) => {
63 * const { month, day } = datetime.date
64 * const { hours, minutes } = datetime.time
65 * conv.close(new SimpleResponse({
66 * speech: 'Great see you at your appointment!',
67 * text: `Great, we will see you on ${month}/${day} at ${hours} ${minutes || ''}`
68 * }))
69 * })
70 * ```
71 *
72 * @public
73 */
74class DateTime extends helper_1.SoloHelper {
75 /**
76 * @param options DateTime options
77 * @public
78 */
79 constructor(options) {
80 const { prompts = {} } = options;
81 super({
82 intent: 'actions.intent.DATETIME',
83 type: 'type.googleapis.com/google.actions.v2.DateTimeValueSpec',
84 data: {
85 dialogSpec: {
86 requestDatetimeText: prompts.initial,
87 requestDateText: prompts.date,
88 requestTimeText: prompts.time,
89 },
90 },
91 });
92 }
93}
94exports.DateTime = DateTime;
95//# sourceMappingURL=datetime.js.map
\No newline at end of file