1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import * as ActionsApi from '../actionssdk/api/v2';
|
17 | import { AppHandler } from '../../assistant';
|
18 | import { ExceptionHandler, Argument, ConversationApp, ConversationAppOptions } from '../actionssdk';
|
19 | import { Contexts, Parameters } from './context';
|
20 | import { DialogflowConversation } from './conv';
|
21 | import { BuiltinFrameworkMetadata } from '../../framework';
|
22 |
|
23 | export interface DialogflowIntentHandler<TConvData, TUserStorage, TContexts extends Contexts, TConversation extends DialogflowConversation<TConvData, TUserStorage, TContexts>, TParameters extends Parameters, TArgument extends Argument> {
|
24 |
|
25 | (conv: TConversation, params: TParameters,
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 | argument: TArgument,
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 | status: ActionsApi.GoogleRpcStatus | undefined): Promise<any> | any;
|
38 | }
|
39 |
|
40 | export interface DialogflowIntentHandlers {
|
41 | [event: string]: Function | string | undefined;
|
42 | }
|
43 |
|
44 | export interface DialogflowHandlers<TConvData, TUserStorage, TContexts extends Contexts, TConversation extends DialogflowConversation<TConvData, TUserStorage, TContexts>> {
|
45 | intents: DialogflowIntentHandlers;
|
46 | catcher: ExceptionHandler<TUserStorage, TConversation>;
|
47 | fallback?: Function | string;
|
48 | }
|
49 |
|
50 | export interface DialogflowMiddleware<TConversationPlugin extends DialogflowConversation> {
|
51 | (
|
52 |
|
53 | conv: DialogflowConversation,
|
54 |
|
55 | framework: BuiltinFrameworkMetadata): (DialogflowConversation & TConversationPlugin) | void | Promise<DialogflowConversation & TConversationPlugin> | Promise<void>;
|
56 | }
|
57 |
|
58 | export declare type DefaultDialogflowIntent = 'Default Welcome Intent' | 'Default Fallback Intent';
|
59 |
|
60 | export interface DialogflowApp<TConvData, TUserStorage, TContexts extends Contexts, TConversation extends DialogflowConversation<TConvData, TUserStorage, TContexts>> extends ConversationApp<TConvData, TUserStorage> {
|
61 |
|
62 | _handlers: DialogflowHandlers<TConvData, TUserStorage, TContexts, TConversation>;
|
63 | |
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | intent<TParameters extends Parameters>(intent: DefaultDialogflowIntent | DefaultDialogflowIntent[], handler: DialogflowIntentHandler<TConvData, TUserStorage, TContexts, TConversation, TParameters, Argument> | string): this;
|
75 | |
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | intent<TArgument extends Argument>(intent: DefaultDialogflowIntent | DefaultDialogflowIntent[], handler: DialogflowIntentHandler<TConvData, TUserStorage, TContexts, TConversation, Parameters, TArgument> | string): this;
|
87 | |
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | intent<TParameters extends Parameters, TArgument extends Argument>(intent: DefaultDialogflowIntent | DefaultDialogflowIntent[], handler: DialogflowIntentHandler<TConvData, TUserStorage, TContexts, TConversation, TParameters, TArgument> | string): this;
|
99 | |
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | intent<TParameters extends Parameters>(intent: string | string[], handler: DialogflowIntentHandler<TConvData, TUserStorage, TContexts, TConversation, TParameters, Argument> | string): this;
|
111 | |
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | intent<TArgument extends Argument>(intent: string | string[], handler: DialogflowIntentHandler<TConvData, TUserStorage, TContexts, TConversation, Parameters, TArgument> | string): this;
|
123 | |
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | intent<TParameters extends Parameters, TArgument extends Argument>(intent: string | string[], handler: DialogflowIntentHandler<TConvData, TUserStorage, TContexts, TConversation, TParameters, TArgument> | string): this;
|
135 |
|
136 | catch(catcher: ExceptionHandler<TUserStorage, TConversation>): this;
|
137 |
|
138 | fallback(handler: DialogflowIntentHandler<TConvData, TUserStorage, TContexts, TConversation, Parameters, Argument> | string): this;
|
139 |
|
140 | _middlewares: DialogflowMiddleware<DialogflowConversation<{}, {}, Contexts>>[];
|
141 |
|
142 | middleware<TConversationPlugin extends DialogflowConversation<{}, {}, Contexts>>(middleware: DialogflowMiddleware<TConversationPlugin>): this;
|
143 |
|
144 | verification?: DialogflowVerification | DialogflowVerificationHeaders;
|
145 | }
|
146 |
|
147 | export interface DialogflowVerificationHeaders {
|
148 | |
149 |
|
150 |
|
151 |
|
152 | [key: string]: string;
|
153 | }
|
154 |
|
155 | export interface DialogflowVerification {
|
156 | |
157 |
|
158 |
|
159 |
|
160 | headers: DialogflowVerificationHeaders;
|
161 | |
162 |
|
163 |
|
164 |
|
165 | status?: number;
|
166 | |
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 | error?: string | ((error: string) => string);
|
174 | }
|
175 | /** @public */
|
176 | export interface DialogflowOptions<TConvData, TUserStorage> extends ConversationAppOptions<TConvData, TUserStorage> {
|
177 | /**
|
178 | * Verifies whether the request comes from Dialogflow.
|
179 | * Uses header keys and values to check against ones specified by the developer
|
180 | * in the Dialogflow Fulfillment settings of the app.
|
181 | *
|
182 | * HTTP Code 403 will be thrown by default on verification error.
|
183 | *
|
184 | * @public
|
185 | */
|
186 | verification?: DialogflowVerification | DialogflowVerificationHeaders;
|
187 | }
|
188 | /** @public */
|
189 | export interface Dialogflow {
|
190 | /** @public */
|
191 | <TConvData, TUserStorage, TContexts extends Contexts = Contexts, Conversation extends DialogflowConversation<TConvData, TUserStorage, TContexts> = DialogflowConversation<TConvData, TUserStorage, TContexts>>(options?: DialogflowOptions<TConvData, TUserStorage>): AppHandler & DialogflowApp<TConvData, TUserStorage, TContexts, Conversation>;
|
192 | /** @public */
|
193 | <TContexts extends Contexts, Conversation extends DialogflowConversation<{}, {}, TContexts> = DialogflowConversation<{}, {}, TContexts>>(options?: DialogflowOptions<{}, {}>): AppHandler & DialogflowApp<{}, {}, TContexts, Conversation>;
|
194 | /** @public */
|
195 | <TConversation extends DialogflowConversation<{}, {}> = DialogflowConversation<{}, {}>>(options?: DialogflowOptions<{}, {}>): AppHandler & DialogflowApp<{}, {}, Contexts, TConversation>;
|
196 | }
|
197 | /**
|
198 | * This is the function that creates the app instance which on new requests,
|
199 | * creates a way to handle the communication with Dialogflow's fulfillment API.
|
200 | *
|
201 | * Supports Dialogflow v1 and v2.
|
202 | *
|
203 | * @example
|
204 | * ```javascript
|
205 | *
|
206 | * const app = dialogflow()
|
207 | *
|
208 | * app.intent('Default Welcome Intent', conv => {
|
209 | * conv.ask('How are you?')
|
210 | * })
|
211 | * ```
|
212 | *
|
213 | * @public
|
214 | */
|
215 | export declare const dialogflow: Dialogflow;
|
216 |
|
\ | No newline at end of file |