UNPKG

2.95 kBTypeScriptView Raw
1import { Callback, Handler } from "../handler";
2
3export type LexHandler = Handler<LexEvent, LexResult>;
4export type LexCallback = Callback<LexResult>;
5
6// Lex
7// https://docs.aws.amazon.com/lambda/latest/dg/invoking-lambda-function.html#supported-event-source-lex
8export interface LexEvent {
9 currentIntent: {
10 name: string;
11 slots: { [name: string]: string | null };
12 slotDetails: LexSlotDetails;
13 confirmationStatus: 'None' | 'Confirmed' | 'Denied';
14 };
15 bot: {
16 name: string;
17 alias: string;
18 version: string;
19 };
20 userId: string;
21 inputTranscript: string;
22 invocationSource: 'DialogCodeHook' | 'FulfillmentCodeHook';
23 outputDialogMode: 'Text' | 'Voice';
24 messageVersion: '1.0';
25 sessionAttributes: { [key: string]: string };
26 requestAttributes: { [key: string]: string } | null;
27}
28
29export interface LexSlotResolution {
30 value: string;
31}
32
33export interface LexSlotDetails {
34 [name: string]: {
35 // The following line only works in TypeScript Version: 3.0, The array should have at least 1 and no more than 5 items
36 // resolutions: [LexSlotResolution, LexSlotResolution?, LexSlotResolution?, LexSlotResolution?, LexSlotResolution?];
37 resolutions: LexSlotResolution[];
38 originalValue: string;
39 };
40}
41
42export interface LexGenericAttachment {
43 title: string;
44 subTitle: string;
45 imageUrl: string;
46 attachmentLinkUrl: string;
47 buttons: Array<{
48 text: string;
49 value: string;
50 }>;
51}
52
53export interface LexDialogActionBase {
54 type: 'Close' | 'ElicitIntent' | 'ElicitSlot' | 'ConfirmIntent';
55 message?: {
56 contentType: 'PlainText' | 'SSML' | 'CustomPayload';
57 content: string;
58 };
59 responseCard?: {
60 version: number;
61 contentType: 'application/vnd.amazonaws.card.generic';
62 genericAttachments: LexGenericAttachment[];
63 };
64}
65
66export interface LexDialogActionClose extends LexDialogActionBase {
67 type: 'Close';
68 fulfillmentState: 'Fulfilled' | 'Failed';
69}
70
71export interface LexDialogActionElicitIntent extends LexDialogActionBase {
72 type: 'ElicitIntent';
73}
74
75export interface LexDialogActionElicitSlot extends LexDialogActionBase {
76 type: 'ElicitSlot';
77 intentName: string;
78 slots: { [name: string]: string | null };
79 slotToElicit: string;
80}
81
82export interface LexDialogActionConfirmIntent extends LexDialogActionBase {
83 type: 'ConfirmIntent';
84 intentName: string;
85 slots: { [name: string]: string | null };
86}
87
88export interface LexDialogActionDelegate {
89 type: 'Delegate';
90 slots: { [name: string]: string | null };
91}
92
93export type LexDialogAction =
94 | LexDialogActionClose
95 | LexDialogActionElicitIntent
96 | LexDialogActionElicitSlot
97 | LexDialogActionConfirmIntent
98 | LexDialogActionDelegate;
99
100export interface LexResult {
101 sessionAttributes?: { [key: string]: string };
102 dialogAction: LexDialogAction;
103}