1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import * as Api from '../api/v2';
|
17 | import { Headers } from '../../../framework';
|
18 | import { Surface, Available } from './surface';
|
19 | import { User } from './user';
|
20 | import { Image, RichResponse, Suggestions, RichResponseItem, MediaObject, SimpleResponse } from './response';
|
21 | import { Helper } from './helper';
|
22 | import { Arguments } from './argument';
|
23 | import { Device } from './device';
|
24 | import { Input } from './input';
|
25 | import { JsonObject } from '../../../common';
|
26 | import { ServiceBaseApp, AppOptions } from '../../../assistant';
|
27 | import { OAuth2Client } from 'google-auth-library';
|
28 | import { Canvas } from './canvas';
|
29 |
|
30 | export declare type Intent = 'actions.intent.MAIN' | 'actions.intent.TEXT' | 'actions.intent.PERMISSION' | 'actions.intent.OPTION' | 'actions.intent.TRANSACTION_REQUIREMENTS_CHECK' | 'actions.intent.DELIVERY_ADDRESS' | 'actions.intent.TRANSACTION_DECISION' | 'actions.intent.CONFIRMATION' | 'actions.intent.DATETIME' | 'actions.intent.SIGN_IN' | 'actions.intent.NO_INPUT' | 'actions.intent.CANCEL' | 'actions.intent.NEW_SURFACE' | 'actions.intent.REGISTER_UPDATE' | 'actions.intent.CONFIGURE_UPDATES' | 'actions.intent.PLACE' | 'actions.intent.LINK' | 'actions.intent.MEDIA_STATUS' | 'actions.intent.COMPLETE_PURCHASE' | 'actions.intent.DIGITAL_PURCHASE_CHECK';
|
31 |
|
32 | export declare type InputValueSpec = 'type.googleapis.com/google.actions.v2.PermissionValueSpec' | 'type.googleapis.com/google.actions.v2.OptionValueSpec' | 'type.googleapis.com/google.actions.v2.TransactionRequirementsCheckSpec' | 'type.googleapis.com/google.actions.v2.DeliveryAddressValueSpec' | 'type.googleapis.com/google.actions.v2.TransactionDecisionValueSpec' | 'type.googleapis.com/google.actions.v2.ConfirmationValueSpec' | 'type.googleapis.com/google.actions.v2.DateTimeValueSpec' | 'type.googleapis.com/google.actions.v2.NewSurfaceValueSpec' | 'type.googleapis.com/google.actions.v2.RegisterUpdateValueSpec' | 'type.googleapis.com/google.actions.v2.SignInValueSpec' | 'type.googleapis.com/google.actions.v2.PlaceValueSpec' | 'type.googleapis.com/google.actions.v2.LinkValueSpec' | 'type.googleapis.com/google.actions.transactions.v3.CompletePurchaseValueSpec' | 'type.googleapis.com/google.actions.transactions.v3.TransactionDecisionValueSpec' | 'type.googleapis.com/google.actions.transactions.v3.TransactionRequirementsCheckSpec' | 'type.googleapis.com/google.actions.transactions.v3.DigitalPurchaseCheckSpec';
|
33 |
|
34 | export declare type DialogSpec = 'type.googleapis.com/google.actions.v2.PlaceValueSpec.PlaceDialogSpec' | 'type.googleapis.com/google.actions.v2.LinkValueSpec.LinkDialogSpec';
|
35 |
|
36 | export declare type Response = RichResponse | RichResponseItem | Image | Suggestions | MediaObject | Helper<Intent, JsonObject>;
|
37 |
|
38 | export interface ConversationResponse {
|
39 | richResponse: Api.GoogleActionsV2RichResponse;
|
40 | expectUserResponse: boolean;
|
41 | userStorage: string;
|
42 | expectedIntent?: Api.GoogleActionsV2ExpectedIntent;
|
43 | noInputPrompts?: Api.GoogleActionsV2SimpleResponse[];
|
44 | speechBiasingHints?: string[];
|
45 | }
|
46 | export interface ConversationOptionsInit<TConvData, TUserStorage> {
|
47 |
|
48 | data?: TConvData;
|
49 |
|
50 | storage?: TUserStorage;
|
51 | }
|
52 |
|
53 | export interface ConversationBaseOptions<TConvData, TUserStorage> {
|
54 |
|
55 | headers?: Headers;
|
56 |
|
57 | init?: ConversationOptionsInit<TConvData, TUserStorage>;
|
58 |
|
59 | debug?: boolean;
|
60 |
|
61 | ordersv3?: boolean;
|
62 | }
|
63 |
|
64 | export interface ConversationOptions<TUserStorage> {
|
65 |
|
66 | request?: Api.GoogleActionsV2AppRequest;
|
67 |
|
68 | headers?: Headers;
|
69 |
|
70 | init?: ConversationOptionsInit<{}, TUserStorage>;
|
71 |
|
72 | ordersv3?: boolean;
|
73 | }
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | export declare class UnauthorizedError extends Error {
|
102 | }
|
103 |
|
104 | export declare class Conversation<TUserStorage> {
|
105 |
|
106 | request: Api.GoogleActionsV2AppRequest;
|
107 |
|
108 | headers: Headers;
|
109 |
|
110 | responses: Response[];
|
111 |
|
112 | expectUserResponse: boolean;
|
113 |
|
114 | surface: Surface;
|
115 |
|
116 | available: Available;
|
117 |
|
118 | digested: boolean;
|
119 | |
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | sandbox: boolean;
|
126 |
|
127 | input: Input;
|
128 | |
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 | user: User<TUserStorage>;
|
136 |
|
137 | arguments: Arguments;
|
138 |
|
139 | device: Device;
|
140 |
|
141 | canvas: Canvas;
|
142 | |
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 | id: string;
|
157 |
|
158 | type: Api.GoogleActionsV2ConversationType;
|
159 | |
160 |
|
161 |
|
162 |
|
163 |
|
164 | screen: boolean;
|
165 | |
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 | noInputs: (string | SimpleResponse)[];
|
191 | |
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 | speechBiasing: string[];
|
206 |
|
207 | _raw?: JsonObject;
|
208 |
|
209 | _responded: boolean;
|
210 |
|
211 | _init: ConversationOptionsInit<{}, TUserStorage>;
|
212 |
|
213 | _ordersv3: boolean;
|
214 |
|
215 | constructor(options?: ConversationOptions<TUserStorage>);
|
216 | /** @public */
|
217 | json<T = JsonObject>(json: T): this;
|
218 | /** @public */
|
219 | add(...responses: Response[]): this;
|
220 | /**
|
221 | * Asks to collect user's input. All user's queries need to be sent to the app.
|
222 | * {@link https:
|
223 | * The guidelines when prompting the user for a response must be followed at all times}.
|
224 | *
|
225 | * @example
|
226 | * ```javascript
|
227 | *
|
228 | * // Actions SDK
|
229 | * const app = actionssdk()
|
230 | *
|
231 | * app.intent('actions.intent.MAIN', conv => {
|
232 | * const ssml = '<speak>Hi! <break time="1"/> ' +
|
233 | * 'I can read out an ordinal like <say-as interpret-as="ordinal">123</say-as>. ' +
|
234 | * 'Say a number.</speak>'
|
235 | * conv.ask(ssml)
|
236 | * })
|
237 | *
|
238 | * app.intent('actions.intent.TEXT', (conv, input) => {
|
239 | * if (input === 'bye') {
|
240 | * return conv.close('Goodbye!')
|
241 | * }
|
242 | * const ssml = `<speak>You said, <say-as interpret-as="ordinal">${input}</say-as></speak>`
|
243 | * conv.ask(ssml)
|
244 | * })
|
245 | *
|
246 | * // Dialogflow
|
247 | * const app = dialogflow()
|
248 | *
|
249 | * app.intent('Default Welcome Intent', conv => {
|
250 | * conv.ask('Welcome to action snippets! Say a number.')
|
251 | * })
|
252 | *
|
253 | * app.intent('Number Input', (conv, {num}) => {
|
254 | * conv.close(`You said ${num}`)
|
255 | * })
|
256 | * ```
|
257 | *
|
258 | * @param responses A response fragment for the library to construct a single complete response
|
259 | * @public
|
260 | */
|
261 | ask(...responses: Response[]): this;
|
262 | |
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 | close(...responses: Response[]): this;
|
302 |
|
303 | response(): ConversationResponse;
|
304 | }
|
305 | export interface ExceptionHandler<TUserStorage, TConversation extends Conversation<TUserStorage>> {
|
306 |
|
307 | (conv: TConversation, error: Error): Promise<any> | any;
|
308 | }
|
309 |
|
310 | export interface Traversed {
|
311 | [key: string]: boolean;
|
312 | }
|
313 |
|
314 | export interface ConversationAppOptions<TConvData, TUserStorage> extends AppOptions {
|
315 |
|
316 | init?: () => ConversationOptionsInit<TConvData, TUserStorage>;
|
317 | |
318 |
|
319 |
|
320 |
|
321 |
|
322 | clientId?: string;
|
323 |
|
324 | ordersv3?: boolean;
|
325 | }
|
326 | export interface OAuth2ConfigClient {
|
327 |
|
328 | id: string;
|
329 | }
|
330 | export interface OAuth2Config {
|
331 |
|
332 | client: OAuth2ConfigClient;
|
333 | }
|
334 | export interface ConversationApp<TConvData, TUserStorage> extends ServiceBaseApp {
|
335 |
|
336 | init?: () => ConversationOptionsInit<TConvData, TUserStorage>;
|
337 |
|
338 | auth?: OAuth2Config;
|
339 |
|
340 | ordersv3: boolean;
|
341 |
|
342 | _client?: OAuth2Client;
|
343 | }
|