@aws-sdk/client-lex-runtime-service
Version:
AWS SDK for JavaScript Lex Runtime Service Client for Node.js, Browser and React Native
1,154 lines (1,153 loc) • 61.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deserializeAws_restJson1PutSessionCommand = exports.deserializeAws_restJson1PostTextCommand = exports.deserializeAws_restJson1PostContentCommand = exports.deserializeAws_restJson1GetSessionCommand = exports.deserializeAws_restJson1DeleteSessionCommand = exports.serializeAws_restJson1PutSessionCommand = exports.serializeAws_restJson1PostTextCommand = exports.serializeAws_restJson1PostContentCommand = exports.serializeAws_restJson1GetSessionCommand = exports.serializeAws_restJson1DeleteSessionCommand = void 0;
const protocol_http_1 = require("@aws-sdk/protocol-http");
const smithy_client_1 = require("@aws-sdk/smithy-client");
const serializeAws_restJson1DeleteSessionCommand = async (input, context) => {
const headers = {};
let resolvedPath = "/bot/{botName}/alias/{botAlias}/user/{userId}/session";
if (input.botName !== undefined) {
const labelValue = input.botName;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: botName.");
}
resolvedPath = resolvedPath.replace("{botName}", smithy_client_1.extendedEncodeURIComponent(labelValue));
}
else {
throw new Error("No value provided for input HTTP label: botName.");
}
if (input.botAlias !== undefined) {
const labelValue = input.botAlias;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: botAlias.");
}
resolvedPath = resolvedPath.replace("{botAlias}", smithy_client_1.extendedEncodeURIComponent(labelValue));
}
else {
throw new Error("No value provided for input HTTP label: botAlias.");
}
if (input.userId !== undefined) {
const labelValue = input.userId;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: userId.");
}
resolvedPath = resolvedPath.replace("{userId}", smithy_client_1.extendedEncodeURIComponent(labelValue));
}
else {
throw new Error("No value provided for input HTTP label: userId.");
}
let body;
const { hostname, protocol = "https", port } = await context.endpoint();
return new protocol_http_1.HttpRequest({
protocol,
hostname,
port,
method: "DELETE",
headers,
path: resolvedPath,
body,
});
};
exports.serializeAws_restJson1DeleteSessionCommand = serializeAws_restJson1DeleteSessionCommand;
const serializeAws_restJson1GetSessionCommand = async (input, context) => {
const headers = {};
let resolvedPath = "/bot/{botName}/alias/{botAlias}/user/{userId}/session";
if (input.botName !== undefined) {
const labelValue = input.botName;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: botName.");
}
resolvedPath = resolvedPath.replace("{botName}", smithy_client_1.extendedEncodeURIComponent(labelValue));
}
else {
throw new Error("No value provided for input HTTP label: botName.");
}
if (input.botAlias !== undefined) {
const labelValue = input.botAlias;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: botAlias.");
}
resolvedPath = resolvedPath.replace("{botAlias}", smithy_client_1.extendedEncodeURIComponent(labelValue));
}
else {
throw new Error("No value provided for input HTTP label: botAlias.");
}
if (input.userId !== undefined) {
const labelValue = input.userId;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: userId.");
}
resolvedPath = resolvedPath.replace("{userId}", smithy_client_1.extendedEncodeURIComponent(labelValue));
}
else {
throw new Error("No value provided for input HTTP label: userId.");
}
const query = {
...(input.checkpointLabelFilter !== undefined && { checkpointLabelFilter: input.checkpointLabelFilter }),
};
let body;
const { hostname, protocol = "https", port } = await context.endpoint();
return new protocol_http_1.HttpRequest({
protocol,
hostname,
port,
method: "GET",
headers,
path: resolvedPath,
query,
body,
});
};
exports.serializeAws_restJson1GetSessionCommand = serializeAws_restJson1GetSessionCommand;
const serializeAws_restJson1PostContentCommand = async (input, context) => {
const headers = {
"content-type": "application/octet-stream",
"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
...(isSerializableHeaderValue(input.sessionAttributes) && {
"x-amz-lex-session-attributes": Buffer.from(smithy_client_1.LazyJsonString.fromObject(input.sessionAttributes)).toString("base64"),
}),
...(isSerializableHeaderValue(input.requestAttributes) && {
"x-amz-lex-request-attributes": Buffer.from(smithy_client_1.LazyJsonString.fromObject(input.requestAttributes)).toString("base64"),
}),
...(isSerializableHeaderValue(input.contentType) && { "content-type": input.contentType }),
...(isSerializableHeaderValue(input.accept) && { accept: input.accept }),
...(isSerializableHeaderValue(input.activeContexts) && {
"x-amz-lex-active-contexts": Buffer.from(smithy_client_1.LazyJsonString.fromObject(input.activeContexts)).toString("base64"),
}),
};
let resolvedPath = "/bot/{botName}/alias/{botAlias}/user/{userId}/content";
if (input.botName !== undefined) {
const labelValue = input.botName;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: botName.");
}
resolvedPath = resolvedPath.replace("{botName}", smithy_client_1.extendedEncodeURIComponent(labelValue));
}
else {
throw new Error("No value provided for input HTTP label: botName.");
}
if (input.botAlias !== undefined) {
const labelValue = input.botAlias;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: botAlias.");
}
resolvedPath = resolvedPath.replace("{botAlias}", smithy_client_1.extendedEncodeURIComponent(labelValue));
}
else {
throw new Error("No value provided for input HTTP label: botAlias.");
}
if (input.userId !== undefined) {
const labelValue = input.userId;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: userId.");
}
resolvedPath = resolvedPath.replace("{userId}", smithy_client_1.extendedEncodeURIComponent(labelValue));
}
else {
throw new Error("No value provided for input HTTP label: userId.");
}
let body;
if (input.inputStream !== undefined) {
body = input.inputStream;
}
const { hostname, protocol = "https", port } = await context.endpoint();
return new protocol_http_1.HttpRequest({
protocol,
hostname,
port,
method: "POST",
headers,
path: resolvedPath,
body,
});
};
exports.serializeAws_restJson1PostContentCommand = serializeAws_restJson1PostContentCommand;
const serializeAws_restJson1PostTextCommand = async (input, context) => {
const headers = {
"content-type": "application/json",
};
let resolvedPath = "/bot/{botName}/alias/{botAlias}/user/{userId}/text";
if (input.botName !== undefined) {
const labelValue = input.botName;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: botName.");
}
resolvedPath = resolvedPath.replace("{botName}", smithy_client_1.extendedEncodeURIComponent(labelValue));
}
else {
throw new Error("No value provided for input HTTP label: botName.");
}
if (input.botAlias !== undefined) {
const labelValue = input.botAlias;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: botAlias.");
}
resolvedPath = resolvedPath.replace("{botAlias}", smithy_client_1.extendedEncodeURIComponent(labelValue));
}
else {
throw new Error("No value provided for input HTTP label: botAlias.");
}
if (input.userId !== undefined) {
const labelValue = input.userId;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: userId.");
}
resolvedPath = resolvedPath.replace("{userId}", smithy_client_1.extendedEncodeURIComponent(labelValue));
}
else {
throw new Error("No value provided for input HTTP label: userId.");
}
let body;
body = JSON.stringify({
...(input.activeContexts !== undefined &&
input.activeContexts !== null && {
activeContexts: serializeAws_restJson1ActiveContextsList(input.activeContexts, context),
}),
...(input.inputText !== undefined && input.inputText !== null && { inputText: input.inputText }),
...(input.requestAttributes !== undefined &&
input.requestAttributes !== null && {
requestAttributes: serializeAws_restJson1StringMap(input.requestAttributes, context),
}),
...(input.sessionAttributes !== undefined &&
input.sessionAttributes !== null && {
sessionAttributes: serializeAws_restJson1StringMap(input.sessionAttributes, context),
}),
});
const { hostname, protocol = "https", port } = await context.endpoint();
return new protocol_http_1.HttpRequest({
protocol,
hostname,
port,
method: "POST",
headers,
path: resolvedPath,
body,
});
};
exports.serializeAws_restJson1PostTextCommand = serializeAws_restJson1PostTextCommand;
const serializeAws_restJson1PutSessionCommand = async (input, context) => {
const headers = {
"content-type": "application/json",
...(isSerializableHeaderValue(input.accept) && { accept: input.accept }),
};
let resolvedPath = "/bot/{botName}/alias/{botAlias}/user/{userId}/session";
if (input.botName !== undefined) {
const labelValue = input.botName;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: botName.");
}
resolvedPath = resolvedPath.replace("{botName}", smithy_client_1.extendedEncodeURIComponent(labelValue));
}
else {
throw new Error("No value provided for input HTTP label: botName.");
}
if (input.botAlias !== undefined) {
const labelValue = input.botAlias;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: botAlias.");
}
resolvedPath = resolvedPath.replace("{botAlias}", smithy_client_1.extendedEncodeURIComponent(labelValue));
}
else {
throw new Error("No value provided for input HTTP label: botAlias.");
}
if (input.userId !== undefined) {
const labelValue = input.userId;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: userId.");
}
resolvedPath = resolvedPath.replace("{userId}", smithy_client_1.extendedEncodeURIComponent(labelValue));
}
else {
throw new Error("No value provided for input HTTP label: userId.");
}
let body;
body = JSON.stringify({
...(input.activeContexts !== undefined &&
input.activeContexts !== null && {
activeContexts: serializeAws_restJson1ActiveContextsList(input.activeContexts, context),
}),
...(input.dialogAction !== undefined &&
input.dialogAction !== null && { dialogAction: serializeAws_restJson1DialogAction(input.dialogAction, context) }),
...(input.recentIntentSummaryView !== undefined &&
input.recentIntentSummaryView !== null && {
recentIntentSummaryView: serializeAws_restJson1IntentSummaryList(input.recentIntentSummaryView, context),
}),
...(input.sessionAttributes !== undefined &&
input.sessionAttributes !== null && {
sessionAttributes: serializeAws_restJson1StringMap(input.sessionAttributes, context),
}),
});
const { hostname, protocol = "https", port } = await context.endpoint();
return new protocol_http_1.HttpRequest({
protocol,
hostname,
port,
method: "POST",
headers,
path: resolvedPath,
body,
});
};
exports.serializeAws_restJson1PutSessionCommand = serializeAws_restJson1PutSessionCommand;
const deserializeAws_restJson1DeleteSessionCommand = async (output, context) => {
if (output.statusCode !== 200 && output.statusCode >= 300) {
return deserializeAws_restJson1DeleteSessionCommandError(output, context);
}
const contents = {
$metadata: deserializeMetadata(output),
botAlias: undefined,
botName: undefined,
sessionId: undefined,
userId: undefined,
};
const data = await parseBody(output.body, context);
if (data.botAlias !== undefined && data.botAlias !== null) {
contents.botAlias = data.botAlias;
}
if (data.botName !== undefined && data.botName !== null) {
contents.botName = data.botName;
}
if (data.sessionId !== undefined && data.sessionId !== null) {
contents.sessionId = data.sessionId;
}
if (data.userId !== undefined && data.userId !== null) {
contents.userId = data.userId;
}
return Promise.resolve(contents);
};
exports.deserializeAws_restJson1DeleteSessionCommand = deserializeAws_restJson1DeleteSessionCommand;
const deserializeAws_restJson1DeleteSessionCommandError = async (output, context) => {
const parsedOutput = {
...output,
body: await parseBody(output.body, context),
};
let response;
let errorCode = "UnknownError";
errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
case "BadRequestException":
case "com.amazonaws.lexruntimeservice#BadRequestException":
response = {
...(await deserializeAws_restJson1BadRequestExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "ConflictException":
case "com.amazonaws.lexruntimeservice#ConflictException":
response = {
...(await deserializeAws_restJson1ConflictExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "InternalFailureException":
case "com.amazonaws.lexruntimeservice#InternalFailureException":
response = {
...(await deserializeAws_restJson1InternalFailureExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "LimitExceededException":
case "com.amazonaws.lexruntimeservice#LimitExceededException":
response = {
...(await deserializeAws_restJson1LimitExceededExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "NotFoundException":
case "com.amazonaws.lexruntimeservice#NotFoundException":
response = {
...(await deserializeAws_restJson1NotFoundExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
default:
const parsedBody = parsedOutput.body;
errorCode = parsedBody.code || parsedBody.Code || errorCode;
response = {
...parsedBody,
name: `${errorCode}`,
message: parsedBody.message || parsedBody.Message || errorCode,
$fault: "client",
$metadata: deserializeMetadata(output),
};
}
const message = response.message || response.Message || errorCode;
response.message = message;
delete response.Message;
return Promise.reject(Object.assign(new Error(message), response));
};
const deserializeAws_restJson1GetSessionCommand = async (output, context) => {
if (output.statusCode !== 200 && output.statusCode >= 300) {
return deserializeAws_restJson1GetSessionCommandError(output, context);
}
const contents = {
$metadata: deserializeMetadata(output),
activeContexts: undefined,
dialogAction: undefined,
recentIntentSummaryView: undefined,
sessionAttributes: undefined,
sessionId: undefined,
};
const data = await parseBody(output.body, context);
if (data.activeContexts !== undefined && data.activeContexts !== null) {
contents.activeContexts = deserializeAws_restJson1ActiveContextsList(data.activeContexts, context);
}
if (data.dialogAction !== undefined && data.dialogAction !== null) {
contents.dialogAction = deserializeAws_restJson1DialogAction(data.dialogAction, context);
}
if (data.recentIntentSummaryView !== undefined && data.recentIntentSummaryView !== null) {
contents.recentIntentSummaryView = deserializeAws_restJson1IntentSummaryList(data.recentIntentSummaryView, context);
}
if (data.sessionAttributes !== undefined && data.sessionAttributes !== null) {
contents.sessionAttributes = deserializeAws_restJson1StringMap(data.sessionAttributes, context);
}
if (data.sessionId !== undefined && data.sessionId !== null) {
contents.sessionId = data.sessionId;
}
return Promise.resolve(contents);
};
exports.deserializeAws_restJson1GetSessionCommand = deserializeAws_restJson1GetSessionCommand;
const deserializeAws_restJson1GetSessionCommandError = async (output, context) => {
const parsedOutput = {
...output,
body: await parseBody(output.body, context),
};
let response;
let errorCode = "UnknownError";
errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
case "BadRequestException":
case "com.amazonaws.lexruntimeservice#BadRequestException":
response = {
...(await deserializeAws_restJson1BadRequestExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "InternalFailureException":
case "com.amazonaws.lexruntimeservice#InternalFailureException":
response = {
...(await deserializeAws_restJson1InternalFailureExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "LimitExceededException":
case "com.amazonaws.lexruntimeservice#LimitExceededException":
response = {
...(await deserializeAws_restJson1LimitExceededExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "NotFoundException":
case "com.amazonaws.lexruntimeservice#NotFoundException":
response = {
...(await deserializeAws_restJson1NotFoundExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
default:
const parsedBody = parsedOutput.body;
errorCode = parsedBody.code || parsedBody.Code || errorCode;
response = {
...parsedBody,
name: `${errorCode}`,
message: parsedBody.message || parsedBody.Message || errorCode,
$fault: "client",
$metadata: deserializeMetadata(output),
};
}
const message = response.message || response.Message || errorCode;
response.message = message;
delete response.Message;
return Promise.reject(Object.assign(new Error(message), response));
};
const deserializeAws_restJson1PostContentCommand = async (output, context) => {
if (output.statusCode !== 200 && output.statusCode >= 300) {
return deserializeAws_restJson1PostContentCommandError(output, context);
}
const contents = {
$metadata: deserializeMetadata(output),
activeContexts: undefined,
alternativeIntents: undefined,
audioStream: undefined,
botVersion: undefined,
contentType: undefined,
dialogState: undefined,
inputTranscript: undefined,
intentName: undefined,
message: undefined,
messageFormat: undefined,
nluIntentConfidence: undefined,
sentimentResponse: undefined,
sessionAttributes: undefined,
sessionId: undefined,
slotToElicit: undefined,
slots: undefined,
};
if (output.headers["content-type"] !== undefined) {
contents.contentType = output.headers["content-type"];
}
if (output.headers["x-amz-lex-intent-name"] !== undefined) {
contents.intentName = output.headers["x-amz-lex-intent-name"];
}
if (output.headers["x-amz-lex-nlu-intent-confidence"] !== undefined) {
contents.nluIntentConfidence = new smithy_client_1.LazyJsonString(Buffer.from(output.headers["x-amz-lex-nlu-intent-confidence"], "base64").toString("ascii"));
}
if (output.headers["x-amz-lex-alternative-intents"] !== undefined) {
contents.alternativeIntents = new smithy_client_1.LazyJsonString(Buffer.from(output.headers["x-amz-lex-alternative-intents"], "base64").toString("ascii"));
}
if (output.headers["x-amz-lex-slots"] !== undefined) {
contents.slots = new smithy_client_1.LazyJsonString(Buffer.from(output.headers["x-amz-lex-slots"], "base64").toString("ascii"));
}
if (output.headers["x-amz-lex-session-attributes"] !== undefined) {
contents.sessionAttributes = new smithy_client_1.LazyJsonString(Buffer.from(output.headers["x-amz-lex-session-attributes"], "base64").toString("ascii"));
}
if (output.headers["x-amz-lex-sentiment"] !== undefined) {
contents.sentimentResponse = output.headers["x-amz-lex-sentiment"];
}
if (output.headers["x-amz-lex-message"] !== undefined) {
contents.message = output.headers["x-amz-lex-message"];
}
if (output.headers["x-amz-lex-message-format"] !== undefined) {
contents.messageFormat = output.headers["x-amz-lex-message-format"];
}
if (output.headers["x-amz-lex-dialog-state"] !== undefined) {
contents.dialogState = output.headers["x-amz-lex-dialog-state"];
}
if (output.headers["x-amz-lex-slot-to-elicit"] !== undefined) {
contents.slotToElicit = output.headers["x-amz-lex-slot-to-elicit"];
}
if (output.headers["x-amz-lex-input-transcript"] !== undefined) {
contents.inputTranscript = output.headers["x-amz-lex-input-transcript"];
}
if (output.headers["x-amz-lex-bot-version"] !== undefined) {
contents.botVersion = output.headers["x-amz-lex-bot-version"];
}
if (output.headers["x-amz-lex-session-id"] !== undefined) {
contents.sessionId = output.headers["x-amz-lex-session-id"];
}
if (output.headers["x-amz-lex-active-contexts"] !== undefined) {
contents.activeContexts = new smithy_client_1.LazyJsonString(Buffer.from(output.headers["x-amz-lex-active-contexts"], "base64").toString("ascii"));
}
const data = output.body;
contents.audioStream = data;
return Promise.resolve(contents);
};
exports.deserializeAws_restJson1PostContentCommand = deserializeAws_restJson1PostContentCommand;
const deserializeAws_restJson1PostContentCommandError = async (output, context) => {
const parsedOutput = {
...output,
body: await parseBody(output.body, context),
};
let response;
let errorCode = "UnknownError";
errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
case "BadGatewayException":
case "com.amazonaws.lexruntimeservice#BadGatewayException":
response = {
...(await deserializeAws_restJson1BadGatewayExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "BadRequestException":
case "com.amazonaws.lexruntimeservice#BadRequestException":
response = {
...(await deserializeAws_restJson1BadRequestExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "ConflictException":
case "com.amazonaws.lexruntimeservice#ConflictException":
response = {
...(await deserializeAws_restJson1ConflictExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "DependencyFailedException":
case "com.amazonaws.lexruntimeservice#DependencyFailedException":
response = {
...(await deserializeAws_restJson1DependencyFailedExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "InternalFailureException":
case "com.amazonaws.lexruntimeservice#InternalFailureException":
response = {
...(await deserializeAws_restJson1InternalFailureExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "LimitExceededException":
case "com.amazonaws.lexruntimeservice#LimitExceededException":
response = {
...(await deserializeAws_restJson1LimitExceededExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "LoopDetectedException":
case "com.amazonaws.lexruntimeservice#LoopDetectedException":
response = {
...(await deserializeAws_restJson1LoopDetectedExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "NotAcceptableException":
case "com.amazonaws.lexruntimeservice#NotAcceptableException":
response = {
...(await deserializeAws_restJson1NotAcceptableExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "NotFoundException":
case "com.amazonaws.lexruntimeservice#NotFoundException":
response = {
...(await deserializeAws_restJson1NotFoundExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "RequestTimeoutException":
case "com.amazonaws.lexruntimeservice#RequestTimeoutException":
response = {
...(await deserializeAws_restJson1RequestTimeoutExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "UnsupportedMediaTypeException":
case "com.amazonaws.lexruntimeservice#UnsupportedMediaTypeException":
response = {
...(await deserializeAws_restJson1UnsupportedMediaTypeExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
default:
const parsedBody = parsedOutput.body;
errorCode = parsedBody.code || parsedBody.Code || errorCode;
response = {
...parsedBody,
name: `${errorCode}`,
message: parsedBody.message || parsedBody.Message || errorCode,
$fault: "client",
$metadata: deserializeMetadata(output),
};
}
const message = response.message || response.Message || errorCode;
response.message = message;
delete response.Message;
return Promise.reject(Object.assign(new Error(message), response));
};
const deserializeAws_restJson1PostTextCommand = async (output, context) => {
if (output.statusCode !== 200 && output.statusCode >= 300) {
return deserializeAws_restJson1PostTextCommandError(output, context);
}
const contents = {
$metadata: deserializeMetadata(output),
activeContexts: undefined,
alternativeIntents: undefined,
botVersion: undefined,
dialogState: undefined,
intentName: undefined,
message: undefined,
messageFormat: undefined,
nluIntentConfidence: undefined,
responseCard: undefined,
sentimentResponse: undefined,
sessionAttributes: undefined,
sessionId: undefined,
slotToElicit: undefined,
slots: undefined,
};
const data = await parseBody(output.body, context);
if (data.activeContexts !== undefined && data.activeContexts !== null) {
contents.activeContexts = deserializeAws_restJson1ActiveContextsList(data.activeContexts, context);
}
if (data.alternativeIntents !== undefined && data.alternativeIntents !== null) {
contents.alternativeIntents = deserializeAws_restJson1IntentList(data.alternativeIntents, context);
}
if (data.botVersion !== undefined && data.botVersion !== null) {
contents.botVersion = data.botVersion;
}
if (data.dialogState !== undefined && data.dialogState !== null) {
contents.dialogState = data.dialogState;
}
if (data.intentName !== undefined && data.intentName !== null) {
contents.intentName = data.intentName;
}
if (data.message !== undefined && data.message !== null) {
contents.message = data.message;
}
if (data.messageFormat !== undefined && data.messageFormat !== null) {
contents.messageFormat = data.messageFormat;
}
if (data.nluIntentConfidence !== undefined && data.nluIntentConfidence !== null) {
contents.nluIntentConfidence = deserializeAws_restJson1IntentConfidence(data.nluIntentConfidence, context);
}
if (data.responseCard !== undefined && data.responseCard !== null) {
contents.responseCard = deserializeAws_restJson1ResponseCard(data.responseCard, context);
}
if (data.sentimentResponse !== undefined && data.sentimentResponse !== null) {
contents.sentimentResponse = deserializeAws_restJson1SentimentResponse(data.sentimentResponse, context);
}
if (data.sessionAttributes !== undefined && data.sessionAttributes !== null) {
contents.sessionAttributes = deserializeAws_restJson1StringMap(data.sessionAttributes, context);
}
if (data.sessionId !== undefined && data.sessionId !== null) {
contents.sessionId = data.sessionId;
}
if (data.slotToElicit !== undefined && data.slotToElicit !== null) {
contents.slotToElicit = data.slotToElicit;
}
if (data.slots !== undefined && data.slots !== null) {
contents.slots = deserializeAws_restJson1StringMap(data.slots, context);
}
return Promise.resolve(contents);
};
exports.deserializeAws_restJson1PostTextCommand = deserializeAws_restJson1PostTextCommand;
const deserializeAws_restJson1PostTextCommandError = async (output, context) => {
const parsedOutput = {
...output,
body: await parseBody(output.body, context),
};
let response;
let errorCode = "UnknownError";
errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
case "BadGatewayException":
case "com.amazonaws.lexruntimeservice#BadGatewayException":
response = {
...(await deserializeAws_restJson1BadGatewayExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "BadRequestException":
case "com.amazonaws.lexruntimeservice#BadRequestException":
response = {
...(await deserializeAws_restJson1BadRequestExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "ConflictException":
case "com.amazonaws.lexruntimeservice#ConflictException":
response = {
...(await deserializeAws_restJson1ConflictExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "DependencyFailedException":
case "com.amazonaws.lexruntimeservice#DependencyFailedException":
response = {
...(await deserializeAws_restJson1DependencyFailedExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "InternalFailureException":
case "com.amazonaws.lexruntimeservice#InternalFailureException":
response = {
...(await deserializeAws_restJson1InternalFailureExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "LimitExceededException":
case "com.amazonaws.lexruntimeservice#LimitExceededException":
response = {
...(await deserializeAws_restJson1LimitExceededExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "LoopDetectedException":
case "com.amazonaws.lexruntimeservice#LoopDetectedException":
response = {
...(await deserializeAws_restJson1LoopDetectedExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "NotFoundException":
case "com.amazonaws.lexruntimeservice#NotFoundException":
response = {
...(await deserializeAws_restJson1NotFoundExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
default:
const parsedBody = parsedOutput.body;
errorCode = parsedBody.code || parsedBody.Code || errorCode;
response = {
...parsedBody,
name: `${errorCode}`,
message: parsedBody.message || parsedBody.Message || errorCode,
$fault: "client",
$metadata: deserializeMetadata(output),
};
}
const message = response.message || response.Message || errorCode;
response.message = message;
delete response.Message;
return Promise.reject(Object.assign(new Error(message), response));
};
const deserializeAws_restJson1PutSessionCommand = async (output, context) => {
if (output.statusCode !== 200 && output.statusCode >= 300) {
return deserializeAws_restJson1PutSessionCommandError(output, context);
}
const contents = {
$metadata: deserializeMetadata(output),
activeContexts: undefined,
audioStream: undefined,
contentType: undefined,
dialogState: undefined,
intentName: undefined,
message: undefined,
messageFormat: undefined,
sessionAttributes: undefined,
sessionId: undefined,
slotToElicit: undefined,
slots: undefined,
};
if (output.headers["content-type"] !== undefined) {
contents.contentType = output.headers["content-type"];
}
if (output.headers["x-amz-lex-intent-name"] !== undefined) {
contents.intentName = output.headers["x-amz-lex-intent-name"];
}
if (output.headers["x-amz-lex-slots"] !== undefined) {
contents.slots = new smithy_client_1.LazyJsonString(Buffer.from(output.headers["x-amz-lex-slots"], "base64").toString("ascii"));
}
if (output.headers["x-amz-lex-session-attributes"] !== undefined) {
contents.sessionAttributes = new smithy_client_1.LazyJsonString(Buffer.from(output.headers["x-amz-lex-session-attributes"], "base64").toString("ascii"));
}
if (output.headers["x-amz-lex-message"] !== undefined) {
contents.message = output.headers["x-amz-lex-message"];
}
if (output.headers["x-amz-lex-message-format"] !== undefined) {
contents.messageFormat = output.headers["x-amz-lex-message-format"];
}
if (output.headers["x-amz-lex-dialog-state"] !== undefined) {
contents.dialogState = output.headers["x-amz-lex-dialog-state"];
}
if (output.headers["x-amz-lex-slot-to-elicit"] !== undefined) {
contents.slotToElicit = output.headers["x-amz-lex-slot-to-elicit"];
}
if (output.headers["x-amz-lex-session-id"] !== undefined) {
contents.sessionId = output.headers["x-amz-lex-session-id"];
}
if (output.headers["x-amz-lex-active-contexts"] !== undefined) {
contents.activeContexts = new smithy_client_1.LazyJsonString(Buffer.from(output.headers["x-amz-lex-active-contexts"], "base64").toString("ascii"));
}
const data = output.body;
contents.audioStream = data;
return Promise.resolve(contents);
};
exports.deserializeAws_restJson1PutSessionCommand = deserializeAws_restJson1PutSessionCommand;
const deserializeAws_restJson1PutSessionCommandError = async (output, context) => {
const parsedOutput = {
...output,
body: await parseBody(output.body, context),
};
let response;
let errorCode = "UnknownError";
errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
case "BadGatewayException":
case "com.amazonaws.lexruntimeservice#BadGatewayException":
response = {
...(await deserializeAws_restJson1BadGatewayExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "BadRequestException":
case "com.amazonaws.lexruntimeservice#BadRequestException":
response = {
...(await deserializeAws_restJson1BadRequestExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "ConflictException":
case "com.amazonaws.lexruntimeservice#ConflictException":
response = {
...(await deserializeAws_restJson1ConflictExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "DependencyFailedException":
case "com.amazonaws.lexruntimeservice#DependencyFailedException":
response = {
...(await deserializeAws_restJson1DependencyFailedExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "InternalFailureException":
case "com.amazonaws.lexruntimeservice#InternalFailureException":
response = {
...(await deserializeAws_restJson1InternalFailureExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "LimitExceededException":
case "com.amazonaws.lexruntimeservice#LimitExceededException":
response = {
...(await deserializeAws_restJson1LimitExceededExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "NotAcceptableException":
case "com.amazonaws.lexruntimeservice#NotAcceptableException":
response = {
...(await deserializeAws_restJson1NotAcceptableExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
case "NotFoundException":
case "com.amazonaws.lexruntimeservice#NotFoundException":
response = {
...(await deserializeAws_restJson1NotFoundExceptionResponse(parsedOutput, context)),
name: errorCode,
$metadata: deserializeMetadata(output),
};
break;
default:
const parsedBody = parsedOutput.body;
errorCode = parsedBody.code || parsedBody.Code || errorCode;
response = {
...parsedBody,
name: `${errorCode}`,
message: parsedBody.message || parsedBody.Message || errorCode,
$fault: "client",
$metadata: deserializeMetadata(output),
};
}
const message = response.message || response.Message || errorCode;
response.message = message;
delete response.Message;
return Promise.reject(Object.assign(new Error(message), response));
};
const deserializeAws_restJson1BadGatewayExceptionResponse = async (parsedOutput, context) => {
const contents = {
name: "BadGatewayException",
$fault: "server",
$metadata: deserializeMetadata(parsedOutput),
Message: undefined,
};
const data = parsedOutput.body;
if (data.Message !== undefined && data.Message !== null) {
contents.Message = data.Message;
}
return contents;
};
const deserializeAws_restJson1BadRequestExceptionResponse = async (parsedOutput, context) => {
const contents = {
name: "BadRequestException",
$fault: "client",
$metadata: deserializeMetadata(parsedOutput),
message: undefined,
};
const data = parsedOutput.body;
if (data.message !== undefined && data.message !== null) {
contents.message = data.message;
}
return contents;
};
const deserializeAws_restJson1ConflictExceptionResponse = async (parsedOutput, context) => {
const contents = {
name: "ConflictException",
$fault: "client",
$metadata: deserializeMetadata(parsedOutput),
message: undefined,
};
const data = parsedOutput.body;
if (data.message !== undefined && data.message !== null) {
contents.message = data.message;
}
return contents;
};
const deserializeAws_restJson1DependencyFailedExceptionResponse = async (parsedOutput, context) => {
const contents = {
name: "DependencyFailedException",
$fault: "client",
$metadata: deserializeMetadata(parsedOutput),
Message: undefined,
};
const data = parsedOutput.body;
if (data.Message !== undefined && data.Message !== null) {
contents.Message = data.Message;
}
return contents;
};
const deserializeAws_restJson1InternalFailureExceptionResponse = async (parsedOutput, context) => {
const contents = {
name: "InternalFailureException",
$fault: "server",
$metadata: deserializeMetadata(parsedOutput),
message: undefined,
};
const data = parsedOutput.body;
if (data.message !== undefined && data.message !== null) {
contents.message = data.message;
}
return contents;
};
const deserializeAws_restJson1LimitExceededExceptionResponse = async (parsedOutput, context) => {
const contents = {
name: "LimitExceededException",
$fault: "client",
$metadata: deserializeMetadata(parsedOutput),
message: undefined,
retryAfterSeconds: undefined,
};
if (parsedOutput.headers["retry-after"] !== undefined) {
contents.retryAfterSeconds = parsedOutput.headers["retry-after"];
}
const data = parsedOutput.body;
if (data.message !== undefined && data.message !== null) {
contents.message = data.message;
}
return contents;
};
const deserializeAws_restJson1LoopDetectedExceptionResponse = async (parsedOutput, context) => {
const contents = {
name: "LoopDetectedException",
$fault: "server",
$metadata: deserializeMetadata(parsedOutput),
Message: undefined,
};
const data = parsedOutput.body;
if (data.Message !== undefined && data.Message !== null) {
contents.Message = data.Message;
}
return contents;
};
const deserializeAws_restJson1NotAcceptableExceptionResponse = async (parsedOutput, context) => {
const contents = {
name: "NotAcceptableException",
$fault: "client",
$metadata: deserializeMetadata(parsedOutput),
message: undefined,
};
const data = parsedOutput.body;
if (data.message !== undefined && data.message !== null) {
contents.message = data.message;
}
return contents;
};
const deserializeAws_restJson1NotFoundExceptionResponse = async (parsedOutput, context) => {
const contents = {
name: "NotFoundException",
$fault: "client",
$metadata: deserializeMetadata(parsedOutput),
message: undefined,
};
const data = parsedOutput.body;
if (data.message !== undefined && data.message !== null) {
contents.message = data.message;
}
return contents;
};
const deserializeAws_restJson1RequestTimeoutExceptionResponse = async (parsedOutput, context) => {
const contents = {
name: "RequestTimeoutException",
$fault: "client",
$metadata: deserializeMetadata(parsedOutput),
message: undefined,
};
const data = parsedOutput.body;
if (data.message !== undefined && data.message !== null) {
contents.message = data.message;
}
return contents;
};
const deserializeAws_restJson1UnsupportedMediaTypeExceptionResponse = async (parsedOutput, context) => {
const contents = {
name: "UnsupportedMediaTypeException",
$fault: "client",
$metadata: deserializeMetadata(parsedOutput),
message: undefined,
};
const data = parsedOutput.body;
if (data.message !== undefined && data.message !== null) {
contents.message = data.message;
}
return contents;
};
const serializeAws_restJson1ActiveContext = (input, context) => {
return {
...(input.name !== undefined && input.name !== null && { name: input.name }),
...(input.parameters !== undefined &&
input.parameters !== null && {
parameters: serializeAws_restJson1ActiveContextParametersMap(input.parameters, context),
}),
...(input.timeToLive !== undefined &&
input.timeToLive !== null && {
timeToLive: serializeAws_restJson1ActiveContextTimeToLive(input.timeToLive, context),
}),
};
};
const serializeAws_restJson1ActiveContextParametersMap = (input, context) => {
return Object.entries(input).reduce((acc, [key, value]) => {
if (value === null) {
return acc;
}
return {
...acc,
[key]: value,
};
}, {});
};
const serializeAws_restJson1ActiveContextsList = (input, context) => {
return input
.filter((e) => e != null)
.map((entry) => {
if (entry === null) {
return null;
}
return serializeAws_restJson1ActiveContext(entry, context);
});
};
const serializeAws_restJson1ActiveContextTimeToLive = (input, context) => {
return {
...(input.timeToLiveInSeconds !== undefined &&
input.timeToLiveInSeconds !== null && { timeToLiveInSeconds: input.timeToLiveInSeconds }),
...(input.turnsToLive !== undefined && input.turnsToLive !== null && { turnsToLive: input.turnsToLive }),
};
};
const serializeAws_restJson1DialogAction = (input, context) => {
return {
...(input.fulfillmentState !== undefined &&
input.fulfillmentState !== null && { fulfillmentState: input.fulfillmentState }),
...(input.intentName !== undefined && input.intentName !== null && { intentName: input.intentName }),
...(input.message !== undefined && input.message !== null && { message: input.message }),
...(input.messageFormat !== undefined && input.messageFormat !== null && { messageFormat: input.messageFormat }),
...(input.slotToElicit !== undefined && input.slotToElicit !== null && { slotToElicit: input.slotToElicit }),
...(input.slots !== undefined &&