1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import * as Api from './api/v2';
|
17 | import { AppHandler } from '../../assistant';
|
18 | import { ExceptionHandler, Argument, Intent, ConversationAppOptions, ConversationApp } from './conversation';
|
19 | import { ActionsSdkConversation } from './conv';
|
20 | import { BuiltinFrameworkMetadata } from '../../framework';
|
21 |
|
22 | export interface ActionsSdkIntentHandler<TConvData, TUserStorage, TConversation extends ActionsSdkConversation<TConvData, TUserStorage>, TArgument extends Argument> {
|
23 |
|
24 | (conv: TConversation,
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 | input: string,
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 | argument: TArgument,
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 | status: Api.GoogleRpcStatus | undefined): Promise<any> | any;
|
43 | }
|
44 |
|
45 | export interface ActionSdkIntentHandlers {
|
46 | [intent: string]: ActionsSdkIntentHandler<{}, {}, ActionsSdkConversation<{}, {}>, Argument> | string | undefined;
|
47 | }
|
48 |
|
49 | export interface ActionsSdkHandlers<TConvData, TUserStorage, TConversation extends ActionsSdkConversation<TConvData, TUserStorage>> {
|
50 | intents: ActionSdkIntentHandlers;
|
51 | catcher: ExceptionHandler<TUserStorage, TConversation>;
|
52 | fallback?: ActionsSdkIntentHandler<{}, {}, ActionsSdkConversation<{}, {}>, Argument> | string;
|
53 | }
|
54 |
|
55 | export interface ActionsSdkMiddleware<TConversationPlugin extends ActionsSdkConversation<{}, {}>> {
|
56 |
|
57 | (
|
58 |
|
59 | conv: ActionsSdkConversation<{}, {}>,
|
60 |
|
61 | framework: BuiltinFrameworkMetadata): (ActionsSdkConversation<{}, {}> & TConversationPlugin) | void | Promise<ActionsSdkConversation<{}, {}> & TConversationPlugin> | Promise<void>;
|
62 | }
|
63 |
|
64 | export interface ActionsSdkApp<TConvData, TUserStorage, TConversation extends ActionsSdkConversation<TConvData, TUserStorage>> extends ConversationApp<TConvData, TUserStorage> {
|
65 |
|
66 | _handlers: ActionsSdkHandlers<TConvData, TUserStorage, TConversation>;
|
67 | |
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | intent<TArgument extends Argument>(intent: Intent | Intent[], handler: ActionsSdkIntentHandler<TConvData, TUserStorage, TConversation, TArgument> | Intent): this;
|
79 | |
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | intent<TArgument extends Argument>(intent: string | string[], handler: ActionsSdkIntentHandler<TConvData, TUserStorage, TConversation, TArgument> | string): this;
|
91 |
|
92 | catch(catcher: ExceptionHandler<TUserStorage, TConversation>): this;
|
93 |
|
94 | fallback(handler: ActionsSdkIntentHandler<TConvData, TUserStorage, TConversation, Argument> | string): this;
|
95 |
|
96 | _middlewares: ActionsSdkMiddleware<ActionsSdkConversation<{}, {}>>[];
|
97 |
|
98 | middleware<TConversationPlugin extends ActionsSdkConversation<{}, {}>>(middleware: ActionsSdkMiddleware<TConversationPlugin>): this;
|
99 |
|
100 | verification?: ActionsSdkVerification | string;
|
101 | }
|
102 |
|
103 | export interface ActionsSdk {
|
104 |
|
105 | <TConvData, TUserStorage, Conversation extends ActionsSdkConversation<TConvData, TUserStorage> = ActionsSdkConversation<TConvData, TUserStorage>>(options?: ActionsSdkOptions<TConvData, TUserStorage>): AppHandler & ActionsSdkApp<TConvData, TUserStorage, Conversation>;
|
106 |
|
107 | <Conversation extends ActionsSdkConversation<{}, {}> = ActionsSdkConversation<{}, {}>>(options?: ActionsSdkOptions<{}, {}>): AppHandler & ActionsSdkApp<{}, {}, Conversation>;
|
108 | }
|
109 |
|
110 | export interface ActionsSdkVerification {
|
111 | |
112 |
|
113 |
|
114 |
|
115 | project: string;
|
116 | |
117 |
|
118 |
|
119 |
|
120 | status?: number;
|
121 | |
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | error?: string | ((error: string) => string);
|
129 | }
|
130 | /** @public */
|
131 | export interface ActionsSdkOptions<TConvData, TUserStorage> extends ConversationAppOptions<TConvData, TUserStorage> {
|
132 | /**
|
133 | * Validates whether request is from Google through signature verification.
|
134 | * Uses Google-Auth-Library to verify authorization token against given Google Cloud Project ID.
|
135 | * Auth token is given in request header with key, "authorization".
|
136 | *
|
137 | * HTTP Code 403 will be thrown by default on verification error.
|
138 | *
|
139 | * @example
|
140 | * ```javascript
|
141 | *
|
142 | * const app = actionssdk({ verification: 'nodejs-cloud-test-project-1234' })
|
143 | * ```
|
144 | *
|
145 | * @public
|
146 | */
|
147 | verification?: ActionsSdkVerification | string;
|
148 | }
|
149 | /**
|
150 | * This is the function that creates the app instance which on new requests,
|
151 | * creates a way to interact with the conversation API directly from Assistant,
|
152 | * providing implementation for all the methods available in the API.
|
153 | *
|
154 | * Only supports Actions SDK v2.
|
155 | *
|
156 | * @example
|
157 | * ```javascript
|
158 | *
|
159 | * const app = actionssdk()
|
160 | *
|
161 | * app.intent('actions.intent.MAIN', conv => {
|
162 | * conv.ask('How are you?')
|
163 | * })
|
164 | * ```
|
165 | *
|
166 | * @public
|
167 | */
|
168 | export declare const actionssdk: ActionsSdk;
|
169 |
|
\ | No newline at end of file |