UNPKG

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