UNPKG

4.18 kBTypeScriptView Raw
1import { Callback, Handler } from "../handler";
2
3export type LexV2Handler = Handler<LexV2Event, LexV2Result>;
4export type LexV2Callback = Callback<LexV2Result>;
5
6// Lex V2
7// https://docs.aws.amazon.com/lexv2/latest/dg/lambda.html
8export interface LexV2Event {
9 messageVersion: string;
10 invocationSource: "DialogCodeHook" | "FulfillmentCodeHook";
11 inputMode: "DTMF" | "Speech" | "Text";
12 responseContentType: string;
13 sessionId: string;
14 inputTranscript: string;
15 bot: LexV2Bot;
16 interpretations: LexV2Interpretation[];
17 proposedNextState: {
18 dialogAction: LexV2DialogAction;
19 intent: LexV2Intent;
20 };
21 requestAttributes?: Record<string, string>;
22 sessionState: LexV2SessionState;
23 transcriptions: LexV2Transcription[];
24}
25
26export interface LexV2Bot {
27 id: string;
28 name: string;
29 aliasId: string;
30 aliasName: string;
31 localeId: string;
32 version: string; // 'DRAFT' | `${number}`
33}
34
35export interface LexV2Interpretation {
36 intent: LexV2Intent;
37 nluConfidence?: number;
38 sentimentResponse?: LexV2SentimentResponse;
39}
40
41export interface LexV2Intent {
42 confirmationState: "Confirmed" | "Denied" | "None";
43 name: string;
44 slots: LexV2Slots;
45 state: LexV2IntentState;
46 kendraResponse?: any;
47}
48
49export type LexV2IntentState =
50 | "Failed"
51 | "Fulfilled"
52 | "FulfillmentInProgress"
53 | "InProgress"
54 | "ReadyForFulfillment"
55 | "Waiting";
56
57export interface LexV2SentimentResponse {
58 sentiment: string;
59 sentimentScore: LexV2SentimentScore;
60}
61
62export interface LexV2SentimentScore {
63 mixed: number;
64 negative: number;
65 neutral: number;
66 positive: number;
67}
68
69export interface LexV2SessionState {
70 activeContexts?: LexV2ActiveContext[];
71 sessionAttributes?: Record<string, string>;
72 dialogAction?: LexV2DialogAction;
73 intent: LexV2Intent;
74 originatingRequestId: string;
75}
76
77export interface LexV2ActiveContext {
78 name: string;
79 contextAttributes: Record<string, string>;
80 timeToLive: {
81 timeToLiveInSeconds: number;
82 turnsToLive: number;
83 };
84}
85
86export type LevV2DialogActionWithoutSlot =
87 | { type: "Close" }
88 | { type: "ConfirmIntent" }
89 | { type: "Delegate" }
90 | { type: "ElicitIntent" };
91
92export type LexV2DialogAction =
93 | (LevV2DialogActionWithoutSlot & { slotToElicit?: never })
94 | { type: "ElicitSlot"; slotToElicit: string };
95
96export type LexV2ResultDialogAction =
97 | (LevV2DialogActionWithoutSlot & { slotToElicit?: never })
98 | { type: "ElicitSlot"; slotToElicit: string; slotElicitationStyle: "Default" | "SpellByLetter" | "SpellByWord" };
99
100export interface LexV2Result {
101 sessionState: {
102 sessionAttributes?: Record<string, string>;
103 dialogAction: LexV2ResultDialogAction;
104 intent?: {
105 name?: string;
106 state: LexV2IntentState;
107 slots?: LexV2Slots;
108 };
109 };
110 messages?: LexV2Message[];
111}
112
113export type LexV2Message = LexV2ContentMessage | LexV2ImageResponseCardMessage;
114
115export interface LexV2ContentMessage {
116 contentType: "CustomPayload" | "PlainText" | "SSML";
117 content: string;
118}
119
120export interface LexV2ImageResponseCardMessage {
121 contentType: "ImageResponseCard";
122 imageResponseCard: LexV2ImageResponseCard;
123}
124
125export interface LexV2ImageResponseCard {
126 title: string;
127 subtitle?: string;
128 imageUrl?: string;
129 buttons?: LexV2ImageResponseCardButton[];
130}
131
132export interface LexV2ImageResponseCardButton {
133 text: string;
134 value: string;
135}
136
137export type LexV2Slot = LexV2ScalarSlotValue | LexV2ListSlotValue;
138export type LexV2Slots = Record<string, LexV2Slot | null>;
139
140export interface LexV2ScalarSlotValue {
141 shape: "Scalar";
142 value: LexV2SlotValue;
143}
144
145export interface LexV2ListSlotValue {
146 shape: "List";
147 value: LexV2SlotValue;
148 values: LexV2ScalarSlotValue[];
149}
150
151export interface LexV2SlotValue {
152 interpretedValue?: string;
153 originalValue: string;
154 resolvedValues: string[];
155}
156
157export interface LexV2Transcription {
158 transcription: string;
159 transcriptionConfidence: number;
160 resolvedContext: {
161 intent: string;
162 };
163 resolvedSlots: LexV2Slots;
164}