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.NewSurface = void 0;
|
19 | const helper_1 = require("./helper");
|
20 | const common_1 = require("../../../../common");
|
21 | /**
|
22 | * Requests the user to switch to another surface during the conversation.
|
23 | * Works only for en-* locales.
|
24 | *
|
25 | * @example
|
26 | * ```javascript
|
27 | *
|
28 | * // Actions SDK
|
29 | * const app = actionssdk()
|
30 | *
|
31 | * const imageResponses = [
|
32 | * `Here's an image of Google`,
|
33 | * new Image({
|
34 | * url: 'https://storage.googleapis.com/gweb-uniblog-publish-prod/images/' +
|
35 | * 'Search_GSA.2e16d0ba.fill-300x300.png',
|
36 | * alt: 'Google Logo',
|
37 | * })
|
38 | * ]
|
39 | *
|
40 | * app.intent('actions.intent.MAIN', conv => {
|
41 | * const capability = 'actions.capability.SCREEN_OUTPUT'
|
42 | * if (conv.surface.capabilities.has(capability)) {
|
43 | * conv.close(...imageResponses)
|
44 | * } else {
|
45 | * conv.ask(new NewSurface({
|
46 | * capabilities: capability,
|
47 | * context: 'To show you an image',
|
48 | * notification: 'Check out this image',
|
49 | * }))
|
50 | * }
|
51 | * })
|
52 | *
|
53 | * app.intent('actions.intent.NEW_SURFACE', (conv, input, newSurface) => {
|
54 | * if (newSurface.status === 'OK') {
|
55 | * conv.close(...imageResponses)
|
56 | * } else {
|
57 | * conv.close(`Ok, I understand. You don't want to see pictures. Bye`)
|
58 | * }
|
59 | * })
|
60 | *
|
61 | * // Dialogflow
|
62 | * const app = dialogflow()
|
63 | *
|
64 | * const imageResponses = [
|
65 | * `Here's an image of Google`,
|
66 | * new Image({
|
67 | * url: 'https://storage.googleapis.com/gweb-uniblog-publish-prod/images/' +
|
68 | * 'Search_GSA.2e16d0ba.fill-300x300.png',
|
69 | * alt: 'Google Logo',
|
70 | * })
|
71 | * ]
|
72 | *
|
73 | * app.intent('Default Welcome Intent', conv => {
|
74 | * const capability = 'actions.capability.SCREEN_OUTPUT'
|
75 | * if (conv.surface.capabilities.has(capability)) {
|
76 | * conv.close(...imageResponses)
|
77 | * } else {
|
78 | * conv.ask(new NewSurface({
|
79 | * capabilities: capability,
|
80 | * context: 'To show you an image',
|
81 | * notification: 'Check out this image',
|
82 | * }))
|
83 | * }
|
84 | * })
|
85 | *
|
86 | * // Create a Dialogflow intent with the `actions_intent_NEW_SURFACE` event
|
87 | * app.intent('Get New Surface', (conv, input, newSurface) => {
|
88 | * if (newSurface.status === 'OK') {
|
89 | * conv.close(...imageResponses)
|
90 | * } else {
|
91 | * conv.close(`Ok, I understand. You don't want to see pictures. Bye`)
|
92 | * }
|
93 | * })
|
94 | * ```
|
95 | *
|
96 | * @public
|
97 | */
|
98 | class NewSurface extends helper_1.SoloHelper {
|
99 | /**
|
100 | * @param options NewSurface options
|
101 | * @public
|
102 | */
|
103 | constructor(options) {
|
104 | super({
|
105 | intent: 'actions.intent.NEW_SURFACE',
|
106 | type: 'type.googleapis.com/google.actions.v2.NewSurfaceValueSpec',
|
107 | data: {
|
108 | capabilities: common_1.toArray(options.capabilities),
|
109 | context: options.context,
|
110 | notificationTitle: options.notification,
|
111 | },
|
112 | });
|
113 | }
|
114 | }
|
115 | exports.NewSurface = NewSurface;
|
116 | //# sourceMappingURL=newsurface.js.map |
\ | No newline at end of file |