UNPKG

3.19 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 | {
70 contentType: "PlainText" | "SSML" | "CustomPayload";
71 content: string;
72 }
73 | undefined;
74 responseCard?:
75 | {
76 version: number;
77 contentType: "application/vnd.amazonaws.card.generic";
78 genericAttachments: LexGenericAttachment[];
79 }
80 | undefined;
81}
82
83export interface LexDialogActionClose extends LexDialogActionBase {
84 type: "Close";
85 fulfillmentState: "Fulfilled" | "Failed";
86}
87
88export interface LexDialogActionElicitIntent extends LexDialogActionBase {
89 type: "ElicitIntent";
90}
91
92export interface LexDialogActionElicitSlot extends LexDialogActionBase {
93 type: "ElicitSlot";
94 intentName: string;
95 slots: { [name: string]: string | null };
96 slotToElicit: string;
97}
98
99export interface LexDialogActionConfirmIntent extends LexDialogActionBase {
100 type: "ConfirmIntent";
101 intentName: string;
102 slots: { [name: string]: string | null };
103}
104
105export interface LexDialogActionDelegate {
106 type: "Delegate";
107 slots: { [name: string]: string | null };
108}
109
110export type LexDialogAction =
111 | LexDialogActionClose
112 | LexDialogActionElicitIntent
113 | LexDialogActionElicitSlot
114 | LexDialogActionConfirmIntent
115 | LexDialogActionDelegate;
116
117export interface LexResult {
118 sessionAttributes?: { [key: string]: string } | undefined;
119 dialogAction: LexDialogAction;
120}