1 | /**
|
2 | * Copyright 2018 Google Inc. All Rights Reserved.
|
3 | *
|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | * you may not use this file except in compliance with the License.
|
6 | * You may obtain a copy of the License at
|
7 | *
|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
9 | *
|
10 | * Unless required by applicable law or agreed to in writing, software
|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | * See the License for the specific language governing permissions and
|
14 | * limitations under the License.
|
15 | */
|
16 | import * as Api from './api/v2';
|
17 | import * as ApiV1 from './api/v1';
|
18 | import * as ActionsApi from '../actionssdk/api/v2';
|
19 | import { Conversation, ConversationBaseOptions, ConversationOptionsInit } from '../actionssdk';
|
20 | import { ProtoAny, JsonObject } from '../../common';
|
21 | import { Contexts, ContextValues, Parameters } from './context';
|
22 | import { Incoming } from './incoming';
|
23 | /** @hidden */
|
24 | export interface SystemIntent {
|
25 | intent: string;
|
26 | data: ProtoAny<string, JsonObject>;
|
27 | }
|
28 | /** @hidden */
|
29 | export interface GoogleAssistantResponse {
|
30 | expectUserResponse?: boolean;
|
31 | noInputPrompts?: ActionsApi.GoogleActionsV2SimpleResponse[];
|
32 | isSsml?: boolean;
|
33 | richResponse?: ActionsApi.GoogleActionsV2RichResponse;
|
34 | systemIntent?: SystemIntent;
|
35 | userStorage?: string;
|
36 | speechBiasingHints?: string[];
|
37 | }
|
38 | /** @hidden */
|
39 | export interface PayloadGoogle {
|
40 | google: GoogleAssistantResponse;
|
41 | }
|
42 | /** @public */
|
43 | export interface DialogflowConversationOptions<TConvData, TUserStorage> extends ConversationBaseOptions<TConvData, TUserStorage> {
|
44 | /** @public */
|
45 | body?: Api.GoogleCloudDialogflowV2WebhookRequest | ApiV1.DialogflowV1WebhookRequest;
|
46 | }
|
47 | /** @public */
|
48 | export declare class DialogflowConversation<TConvData = JsonObject, TUserStorage = JsonObject, TContexts extends Contexts = Contexts> extends Conversation<TUserStorage> {
|
49 | /** @public */
|
50 | body: Api.GoogleCloudDialogflowV2WebhookRequest | ApiV1.DialogflowV1WebhookRequest;
|
51 | /**
|
52 | * Get the current Dialogflow action name.
|
53 | *
|
54 | * @example
|
55 | * ```javascript
|
56 | *
|
57 | * app.intent('Default Welcome Intent', conv => {
|
58 | * const action = conv.action
|
59 | * })
|
60 | * ```
|
61 | *
|
62 | * @public
|
63 | */
|
64 | action: string;
|
65 | /**
|
66 | * Get the current Dialogflow intent name.
|
67 | *
|
68 | * @example
|
69 | * ```javascript
|
70 | *
|
71 | * app.intent('Default Welcome Intent', conv => {
|
72 | * const intent = conv.intent // will be 'Default Welcome Intent'
|
73 | * })
|
74 | * ```
|
75 | *
|
76 | * @public
|
77 | */
|
78 | intent: string;
|
79 | /**
|
80 | * The Dialogflow parameters from the current intent.
|
81 | * Values will only be a string, an Object, or undefined if not included.
|
82 | *
|
83 | * Will also be sent via intent handler 3rd argument which is the encouraged method to retrieve.
|
84 | *
|
85 | * @example
|
86 | * ```javascript
|
87 | *
|
88 | * // Encouraged method through intent handler
|
89 | * app.intent('Tell Greeting', (conv, params) => {
|
90 | * const color = params.color
|
91 | * const num = params.num
|
92 | * })
|
93 | *
|
94 | * // Encouraged method through destructuring in intent handler
|
95 | * app.intent('Tell Greeting', (conv, { color, num }) => {
|
96 | * // now use color and num as variables
|
97 | * }))
|
98 | *
|
99 | * // Using conv.parameters
|
100 | * app.intent('Tell Greeting', conv => {
|
101 | * const parameters = conv.parameters
|
102 | * // or destructed
|
103 | * const { color, num } = conv.parameters
|
104 | * })
|
105 | * ```
|
106 | *
|
107 | * @public
|
108 | */
|
109 | parameters: Parameters;
|
110 | /** @public */
|
111 | contexts: ContextValues<TContexts>;
|
112 | /** @public */
|
113 | incoming: Incoming;
|
114 | /**
|
115 | * The user's raw input query.
|
116 | *
|
117 | * @example
|
118 | * ```javascript
|
119 | *
|
120 | * app.intent('User Input', conv => {
|
121 | * conv.close(`You said ${conv.query}`)
|
122 | * })
|
123 | * ```
|
124 | *
|
125 | * @public
|
126 | */
|
127 | query: string;
|
128 | /**
|
129 | * The session data in JSON format.
|
130 | * Stored using contexts.
|
131 | *
|
132 | * @example
|
133 | * ```javascript
|
134 | *
|
135 | * app.intent('Default Welcome Intent', conv => {
|
136 | * conv.data.someProperty = 'someValue'
|
137 | * })
|
138 | * ```
|
139 | *
|
140 | * @public
|
141 | */
|
142 | data: TConvData;
|
143 | /** @public */
|
144 | version: number;
|
145 | /** @hidden */
|
146 | _followup?: Api.GoogleCloudDialogflowV2EventInput | ApiV1.DialogflowV1FollowupEvent;
|
147 | /** @hidden */
|
148 | _init: ConversationOptionsInit<TConvData, TUserStorage>;
|
149 | /** @public */
|
150 | constructor(options?: DialogflowConversationOptions<TConvData, TUserStorage>);
|
151 | /**
|
152 | * Triggers an intent of your choosing by sending a followup event from the webhook.
|
153 | * Final response can theoretically include responses but these will not be handled
|
154 | * by Dialogflow. Dialogflow will not pass anything back to Google Assistant, therefore
|
155 | * Google Assistant specific information, most notably conv.user.storage, is ignored.
|
156 | *
|
157 | * @example
|
158 | * ```javascript
|
159 | *
|
160 | * const app = dialogflow()
|
161 | *
|
162 | * // Create a Dialogflow intent with event 'apply-for-license-event'
|
163 | *
|
164 | * app.intent('Default Welcome Intent', conv => {
|
165 | * conv.followup('apply-for-license-event', {
|
166 | * date: new Date().toISOString(),
|
167 | * })
|
168 | * // The dialogflow intent with the 'apply-for-license-event' event
|
169 | * // will be triggered with the given parameters `date`
|
170 | * })
|
171 | * ```
|
172 | *
|
173 | * @param event Name of the event
|
174 | * @param parameters Parameters to send with the event
|
175 | * @param lang The language of this query.
|
176 | * See {//dialogflow.com/docs/languages|Language Support}
https: |
177 | * for a list of the currently supported language codes.
|
178 | * Note that queries in the same session do not necessarily need to specify the same language.
|
179 | * By default, it is the languageCode sent with Dialogflow's queryResult.languageCode
|
180 | *
|
181 | */
|
182 | followup(event: string, parameters?: Parameters, lang?: string): this;
|
183 | /** @public */
|
184 | serialize(): Api.GoogleCloudDialogflowV2WebhookResponse | ApiV1.DialogflowV1WebhookResponse;
|
185 | }
|