1 | ;
|
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 | */
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.Carousel = void 0;
|
19 | const helper_1 = require("../helper");
|
20 | const option_1 = require("./option");
|
21 | /**
|
22 | * Asks to collect user's input with a carousel.
|
23 | *
|
24 | * @example
|
25 | * ```javascript
|
26 | *
|
27 | * // Actions SDK
|
28 | * const app = actionssdk()
|
29 | *
|
30 | * app.intent('actions.intent.MAIN', conv => {
|
31 | * conv.ask('Which of these looks good?')
|
32 | * conv.ask(new Carousel({
|
33 | * items: {
|
34 | * [SELECTION_KEY_ONE]: {
|
35 | * title: 'Number one',
|
36 | * description: 'Description of number one',
|
37 | * synonyms: ['synonym of KEY_ONE 1', 'synonym of KEY_ONE 2'],
|
38 | * },
|
39 | * [SELECTION_KEY_TWO]: {
|
40 | * title: 'Number two',
|
41 | * description: 'Description of number one',
|
42 | * synonyms: ['synonym of KEY_TWO 1', 'synonym of KEY_TWO 2'],
|
43 | * }
|
44 | * }
|
45 | * }))
|
46 | * })
|
47 | *
|
48 | * app.intent('actions.intent.OPTION', (conv, input, option) => {
|
49 | * if (option === SELECTION_KEY_ONE) {
|
50 | * conv.close('Number one is a great choice!')
|
51 | * } else {
|
52 | * conv.close('Number two is also a great choice!')
|
53 | * }
|
54 | * })
|
55 | *
|
56 | * // Dialogflow
|
57 | * const app = dialogflow()
|
58 | *
|
59 | * app.intent('Default Welcome Intent', conv => {
|
60 | * conv.ask('Which of these looks good?')
|
61 | * conv.ask(new Carousel({
|
62 | * items: {
|
63 | * [SELECTION_KEY_ONE]: {
|
64 | * title: 'Number one',
|
65 | * description: 'Description of number one',
|
66 | * synonyms: ['synonym of KEY_ONE 1', 'synonym of KEY_ONE 2'],
|
67 | * },
|
68 | * [SELECTION_KEY_TWO]: {
|
69 | * title: 'Number two',
|
70 | * description: 'Description of number one',
|
71 | * synonyms: ['synonym of KEY_TWO 1', 'synonym of KEY_TWO 2'],
|
72 | * }
|
73 | * }
|
74 | * }))
|
75 | * })
|
76 | *
|
77 | * // Create a Dialogflow intent with the `actions_intent_OPTION` event
|
78 | * app.intent('Get Option', (conv, input, option) => {
|
79 | * if (option === SELECTION_KEY_ONE) {
|
80 | * conv.close('Number one is a great choice!')
|
81 | * } else {
|
82 | * conv.close('Number two is also a great choice!')
|
83 | * }
|
84 | * })
|
85 | * ```
|
86 | *
|
87 | * @public
|
88 | */
|
89 | class Carousel extends helper_1.Helper {
|
90 | /**
|
91 | * @param options Carousel option
|
92 | * @public
|
93 | */
|
94 | constructor(options) {
|
95 | super({
|
96 | intent: 'actions.intent.OPTION',
|
97 | type: 'type.googleapis.com/google.actions.v2.OptionValueSpec',
|
98 | data: {
|
99 | carouselSelect: {
|
100 | items: Array.isArray(options.items)
|
101 | ? options.items
|
102 | : option_1.convert(options.items),
|
103 | imageDisplayOptions: options.display,
|
104 | },
|
105 | },
|
106 | });
|
107 | }
|
108 | }
|
109 | exports.Carousel = Carousel;
|
110 | //# sourceMappingURL=carousel.js.map |
\ | No newline at end of file |