UNPKG

4.43 kBTypeScriptView Raw
1/**
2 * Copyright 2018 Google Inc. All Rights Reserved.d
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 */
16import * as Api from './api/v2';
17import * as ApiV1 from './api/v1';
18import { Image, Suggestions, BasicCard, SimpleResponse, LinkOutSuggestion, List, Carousel } from '../actionssdk';
19import { JsonObject } from '../../common';
20export declare type IncomingMessage = string | Image | Suggestions | BasicCard | SimpleResponse | LinkOutSuggestion | List | Carousel | JsonObject;
21export declare class Incoming {
22 /** @public */
23 parsed: IncomingMessage[];
24 /** @hidden */
25 constructor(fulfillment: Api.GoogleCloudDialogflowV2IntentMessage[] | ApiV1.DialogflowV1Fulfillment | undefined);
26 /**
27 * Gets the first Dialogflow incoming message with the given type.
28 * Messages are converted into client library class instances or a string.
29 *
30 * Only messages with the platform field unlabeled (for generic use)
31 * or labeled `ACTIONS_ON_GOOGLE` (`google` in v1) will be converted and read.
32 *
33 * The conversation is detailed below for a specific message oneof:
34 * * Generic Platform Response
35 * * `text` -> `typeof string`
36 * * `image` -> `Image`
37 * * `quickReplies` -> `Suggestions`
38 * * `card` -> `BasicCard`
39 * * Actions on Google Response
40 * * `simpleResponses` -> `SimpleResponse[]`
41 * * `basicCard` -> `BasicCard`
42 * * `suggestions` -> `Suggestions`
43 * * `linkOutSuggestion` -> `LinkOutSuggestion`
44 * * `listSelect` -> `List`
45 * * `carouselSelect` -> `Carousel`
46 * * `payload` -> `typeof object`
47 *
48 * Dialogflow v1:
49 * * Generic Platform Response
50 * * `0` (text) -> `typeof string`
51 * * `3` (image) -> `Image`
52 * * `1` (card) -> `BasicCard`
53 * * `2` (quick replies) -> `Suggestions`
54 * * `4` (custom payload) -> `typeof object`
55 * * Actions on Google Response
56 * * `simple_response` -> `SimpleResponse`
57 * * `basic_card` -> `BasicCard`
58 * * `list_card` -> `List`
59 * * `suggestion_chips` -> `Suggestions`
60 * * `carousel_card` -> `Carousel`
61 * * `link_out_chip` -> `LinkOutSuggestion`
62 * * `custom_payload` -> `typeof object`
63 *
64 * @example
65 * ```javascript
66 *
67 * // Dialogflow
68 * const { dialogflow, BasicCard } = require('actions-on-google')
69 *
70 * const app = dialogflow()
71 *
72 * // Create an Actions on Google Basic Card in the Dialogflow Console Intent Responses section
73 * app.intent('Default Welcome Intent', conv => {
74 * const str = conv.incoming.get('string') // get the first text response
75 * const card = conv.incoming.get(BasicCard) // gets the instance of BasicCard
76 * // Do something with the Basic Card
77 * })
78 * ```
79 *
80 * @param type A string checking for the typeof message or a class checking for instanceof message
81 * @public
82 */
83 get<TMessage extends IncomingMessage>(type: new (...args: any[]) => TMessage): TMessage;
84 /** @public */
85 get(type: 'string'): string;
86 /**
87 * Gets the Dialogflow incoming messages as an iterator.
88 * Messages are converted into client library class instances or a string.
89 * See {@link Incoming#get|conv.incoming.get} for details on how the conversion works.
90 *
91 * @example
92 * ```javascript
93 *
94 * // Dialogflow
95 * const app = dialogflow()
96 *
97 * // Create messages in the Dialogflow Console Intent Responses section
98 * app.intent('Default Welcome Intent', conv => {
99 * const messages = [...conv.incoming]
100 * // do something with the messages
101 * // or just spread them out back to the user
102 * conv.ask(`Here's what was set in the Dialogflow console`)
103 * conv.ask(...conv.incoming)
104 * }
105 * ```
106 *
107 * @public
108 */
109 [Symbol.iterator](): IterableIterator<IncomingMessage>;
110}
111
\No newline at end of file