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