UNPKG

5.32 kBTypeScriptView Raw
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 */
16import * as Api from './api/v2';
17import * as ApiV1 from './api/v1';
18/** @public */
19export interface Parameters {
20 /** @public */
21 [parameter: string]: string | Object | undefined;
22}
23/** @public */
24export interface Contexts {
25 /** @public */
26 [context: string]: Context<Parameters> | undefined;
27}
28/** @public */
29export interface OutputContexts {
30 /** @public */
31 [context: string]: OutputContext<Parameters> | undefined;
32}
33/** @public */
34export interface Context<TParameters extends Parameters> extends OutputContext<TParameters> {
35 /**
36 * Full name of the context.
37 * @public
38 */
39 name: string;
40 /**
41 * Remaining number of intents
42 * @public
43 */
44 lifespan: number;
45 /**
46 * The context parameters from the current intent.
47 * Context parameters include parameters collected in previous intents
48 * during the lifespan of the given context.
49 *
50 * See {@link https://dialogflow.com/docs/concept-actions#section-extracting-values-from-contexts|
51 * here}.
52 *
53 * @example
54 * ```javascript
55 *
56 * app.intent('Tell Greeting', conv => {
57 * const context1 = conv.contexts.get('context1')
58 * const parameters = context1.parameters
59 * const color = parameters.color
60 * const num = parameters.num
61 * })
62 *
63 * // Using destructuring
64 * app.intent('Tell Greeting', conv => {
65 * const context1 = conv.contexts.get('context1')
66 * const { color, num } = context1.parameters
67 * })
68 * ```
69 *
70 * @public
71 */
72 parameters: TParameters;
73}
74/** @public */
75export interface OutputContext<TParameters extends Parameters> {
76 /** @public */
77 lifespan: number;
78 /** @public */
79 parameters?: TParameters;
80}
81export declare class ContextValues<TContexts extends Contexts> {
82 private _session?;
83 /** @public */
84 input: TContexts;
85 /** @public */
86 output: OutputContexts;
87 /** @hidden */
88 constructor(outputContexts?: Api.GoogleCloudDialogflowV2Context[] | ApiV1.DialogflowV1Context[], _session?: string);
89 /** @hidden */
90 _serialize(): Api.GoogleCloudDialogflowV2Context[];
91 /** @hidden */
92 _serializeV1(): ApiV1.DialogflowV1Context[];
93 /**
94 * Returns the incoming context by name for this intent.
95 *
96 * @example
97 * ```javascript
98 *
99 * const AppContexts = {
100 * NUMBER: 'number',
101 * }
102 *
103 * const app = dialogflow()
104 *
105 * app.intent('Default Welcome Intent', conv => {
106 * conv.contexts.set(AppContexts.NUMBER, 1)
107 * conv.ask('Welcome to action snippets! Say a number.')
108 * })
109 *
110 * // Create intent with 'number' context as requirement
111 * app.intent('Number Input', conv => {
112 * const context = conv.contexts.get(AppContexts.NUMBER)
113 * })
114 * ```
115 *
116 * @param name The name of the Context to retrieve.
117 * @return Context value matching name or undefined if no matching context.
118 * @public
119 */
120 get(name: keyof TContexts): TContexts[keyof TContexts];
121 /**
122 * Set a new context for the current intent.
123 *
124 * @example
125 * ```javascript
126 *
127 * const AppContexts = {
128 * NUMBER: 'number',
129 * }
130 *
131 * const app = dialogflow()
132 *
133 * app.intent('Default Welcome Intent', conv => {
134 * conv.contexts.set(AppContexts.NUMBER, 1)
135 * conv.ask('Welcome to action snippets! Say a number.')
136 * })
137 *
138 * // Create intent with 'number' context as requirement
139 * app.intent('Number Input', conv => {
140 * const context = conv.contexts.get(AppContexts.NUMBER)
141 * })
142 * ```
143 *
144 * @param name Name of the context. Dialogflow converts to lowercase.
145 * @param lifespan Context lifespan.
146 * @param parameters Context parameters.
147 * @public
148 */
149 set(name: string, lifespan: number, parameters?: Parameters): void;
150 /** @public */
151 delete(name: string): void;
152 /**
153 * Returns the incoming contexts for this intent as an iterator.
154 *
155 * @example
156 * ```javascript
157 *
158 * const AppContexts = {
159 * NUMBER: 'number',
160 * }
161 *
162 * const app = dialogflow()
163 *
164 * app.intent('Default Welcome Intent', conv => {
165 * conv.contexts.set(AppContexts.NUMBER, 1)
166 * conv.ask('Welcome to action snippets! Say a number.')
167 * })
168 *
169 * // Create intent with 'number' context as requirement
170 * app.intent('Number Input', conv => {
171 * for (const context of conv.contexts) {
172 * // do something with the contexts
173 * }
174 * })
175 * ```
176 *
177 * @public
178 */
179 [Symbol.iterator](): IterableIterator<Context<Parameters>>;
180}
181
\No newline at end of file