29 const Aws::LexRuntimeService::Model::PostContentRequest & request)
31 os <<
"Request: " << std::endl;
32 os <<
"Bot Alias: " << request.GetBotAlias() << std::endl;
33 os <<
"Bot Name : " << request.GetBotName() << std::endl;
35 ss << request.GetBody()->rdbuf();
36 os <<
"Input data: " << ss.str() << std::endl;
37 os <<
"User Id: " << request.GetUserId() << std::endl;
38 os <<
"Accept Type: " << request.GetAccept() << std::endl;
39 os <<
"Content Type: " << request.GetContentType() << std::endl;
45 const Aws::LexRuntimeService::Model::PostContentResult & result)
47 os <<
"PostContentResult: " << std::endl;
48 os <<
"Message: " << result.GetMessage() << std::endl;
49 os <<
"Slot to elicit: " << result.GetSlotToElicit() << std::endl;
50 using Aws::LexRuntimeService::Model::MessageFormatTypeMapper::GetNameForMessageFormatType;
51 using Aws::LexRuntimeService::Model::DialogStateMapper::GetNameForDialogState;
52 os <<
"Dialog State: " << GetNameForDialogState(result.GetDialogState()) << std::endl;
53 os <<
"Message format type: " << GetNameForMessageFormatType(result.GetMessageFormat()) <<
55 os <<
"Slots: " << result.GetSlots() << std::endl;
56 os <<
"Session Attributes: " << result.GetSessionAttributes() << std::endl;
57 os <<
"Content Type: " << result.GetContentType() << std::endl;
58 os <<
"Intent Name: " << result.GetIntentName() << std::endl;
63 Aws::LexRuntimeService::Model::PostContentResult & result,
66 using Aws::LexRuntimeService::Model::MessageFormatTypeMapper::GetNameForMessageFormatType;
67 response.
message_format_type = GetNameForMessageFormatType(result.GetMessageFormat()).c_str();
71 std::streampos audio_size = result.GetAudioStream().seekg(0, std::ios_base::end).tellg();
73 result.GetAudioStream().seekg(0, std::ios_base::beg);
74 result.GetAudioStream().read(reinterpret_cast<char *>(&response.
audio_response[0]), audio_size);
76 response.
intent_name = result.GetIntentName().c_str();
77 using Aws::LexRuntimeService::Model::DialogStateMapper::GetNameForDialogState;
78 response.
dialog_state = GetNameForDialogState(result.GetDialogState()).c_str();
79 std::string session_attributes = result.GetSessionAttributes().c_str();
82 auto slot_byte_buffer = Aws::Utils::HashingUtils::Base64Decode(result.GetSlots().c_str());
83 Aws::String slot_string(reinterpret_cast<char *>(slot_byte_buffer.GetUnderlyingData()),
84 slot_byte_buffer.GetLength());
88 if (!slot_string.empty()) {
89 auto slot_json = Aws::Utils::Json::JsonValue(slot_string);
90 if (slot_json.WasParseSuccessful()) {
91 AWS_LOGSTREAM_DEBUG(__func__,
"slot_json: " << slot_string);
93 auto view = slot_json.View();
94 for (
auto & element : view.GetAllObjects()) {
95 response.
slots[element.first.c_str()] = element.second.AsString().c_str();
98 AWS_LOGSTREAM_WARN(__func__,
"Unable to parse slot string " << slot_string);
106 std::shared_ptr<LexConfiguration> lex_configuration,
107 std::shared_ptr<Aws::LexRuntimeService::LexRuntimeServiceClient> lex_runtime_client)
109 if (!(lex_configuration && lex_runtime_client)) {
121 Aws::LexRuntimeService::Model::PostContentRequest post_content_request;
127 post_content_request.SetContentType(request.
content_type.c_str());
128 auto io_stream = Aws::MakeShared<Aws::StringStream>(
kAllocationTag);
132 request.
audio_request.end(), std::ostream_iterator<unsigned char>(*io_stream));
136 post_content_request.SetBody(io_stream);
137 AWS_LOGSTREAM_DEBUG(__func__,
"PostContentRequest " << post_content_request);
140 if (post_content_result.IsSuccess()) {
141 auto & result = post_content_result.GetResult();
142 AWS_LOGSTREAM_DEBUG(__func__,
"PostContentResult succeeded: " << result.GetMessage());
146 bool is_retryable = post_content_result.GetError().ShouldRetry();
148 AWS_LOGSTREAM_ERROR(__func__,
149 "Aws Lex Error Has Occurred during LexRuntimeService->PostContent" << std::endl <<
150 "PostContentResult failed: " << std::endl <<
151 post_content_result.GetError() << std::endl <<
152 "Request which caused error: " << std::endl <<
std::string session_attributes
static const char * kAllocationTag
std::vector< uint8_t > audio_request
std::shared_ptr< Aws::LexRuntimeService::LexRuntimeServiceClient > lex_runtime_client_
ErrorCode CopyResult(Aws::LexRuntimeService::Model::PostContentResult &result, LexResponse &response)
Copy the PostContentRestult to a LexResponse.
std::ostream & operator<<(std::ostream &os, const Aws::LexRuntimeService::Model::PostContentRequest &request)
std::string message_format_type
std::unordered_map< std::string, std::string > slots
ErrorCode ConfigureAwsLex(std::shared_ptr< LexConfiguration > lex_configuration, std::shared_ptr< Aws::LexRuntimeService::LexRuntimeServiceClient > lex_runtime_client)
Configure the Lex Interactor.
std::string text_response
std::shared_ptr< LexConfiguration > lex_configuration_
std::vector< uint8_t > audio_response
ErrorCode PostContent(const LexRequest &request, LexResponse &response) override