1 /** 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * SPDX-License-Identifier: Apache-2.0. 4 */ 5 6 #include <aws/lex/model/PostTextResult.h> 7 #include <aws/core/utils/json/JsonSerializer.h> 8 #include <aws/core/AmazonWebServiceResult.h> 9 #include <aws/core/utils/StringUtils.h> 10 #include <aws/core/utils/UnreferencedParam.h> 11 12 #include <utility> 13 14 using namespace Aws::LexRuntimeService::Model; 15 using namespace Aws::Utils::Json; 16 using namespace Aws::Utils; 17 using namespace Aws; 18 PostTextResult()19PostTextResult::PostTextResult() : 20 m_messageFormat(MessageFormatType::NOT_SET), 21 m_dialogState(DialogState::NOT_SET) 22 { 23 } 24 PostTextResult(const Aws::AmazonWebServiceResult<JsonValue> & result)25PostTextResult::PostTextResult(const Aws::AmazonWebServiceResult<JsonValue>& result) : 26 m_messageFormat(MessageFormatType::NOT_SET), 27 m_dialogState(DialogState::NOT_SET) 28 { 29 *this = result; 30 } 31 operator =(const Aws::AmazonWebServiceResult<JsonValue> & result)32PostTextResult& PostTextResult::operator =(const Aws::AmazonWebServiceResult<JsonValue>& result) 33 { 34 JsonView jsonValue = result.GetPayload().View(); 35 if(jsonValue.ValueExists("intentName")) 36 { 37 m_intentName = jsonValue.GetString("intentName"); 38 39 } 40 41 if(jsonValue.ValueExists("nluIntentConfidence")) 42 { 43 m_nluIntentConfidence = jsonValue.GetObject("nluIntentConfidence"); 44 45 } 46 47 if(jsonValue.ValueExists("alternativeIntents")) 48 { 49 Array<JsonView> alternativeIntentsJsonList = jsonValue.GetArray("alternativeIntents"); 50 for(unsigned alternativeIntentsIndex = 0; alternativeIntentsIndex < alternativeIntentsJsonList.GetLength(); ++alternativeIntentsIndex) 51 { 52 m_alternativeIntents.push_back(alternativeIntentsJsonList[alternativeIntentsIndex].AsObject()); 53 } 54 } 55 56 if(jsonValue.ValueExists("slots")) 57 { 58 Aws::Map<Aws::String, JsonView> slotsJsonMap = jsonValue.GetObject("slots").GetAllObjects(); 59 for(auto& slotsItem : slotsJsonMap) 60 { 61 m_slots[slotsItem.first] = slotsItem.second.AsString(); 62 } 63 } 64 65 if(jsonValue.ValueExists("sessionAttributes")) 66 { 67 Aws::Map<Aws::String, JsonView> sessionAttributesJsonMap = jsonValue.GetObject("sessionAttributes").GetAllObjects(); 68 for(auto& sessionAttributesItem : sessionAttributesJsonMap) 69 { 70 m_sessionAttributes[sessionAttributesItem.first] = sessionAttributesItem.second.AsString(); 71 } 72 } 73 74 if(jsonValue.ValueExists("message")) 75 { 76 m_message = jsonValue.GetString("message"); 77 78 } 79 80 if(jsonValue.ValueExists("sentimentResponse")) 81 { 82 m_sentimentResponse = jsonValue.GetObject("sentimentResponse"); 83 84 } 85 86 if(jsonValue.ValueExists("messageFormat")) 87 { 88 m_messageFormat = MessageFormatTypeMapper::GetMessageFormatTypeForName(jsonValue.GetString("messageFormat")); 89 90 } 91 92 if(jsonValue.ValueExists("dialogState")) 93 { 94 m_dialogState = DialogStateMapper::GetDialogStateForName(jsonValue.GetString("dialogState")); 95 96 } 97 98 if(jsonValue.ValueExists("slotToElicit")) 99 { 100 m_slotToElicit = jsonValue.GetString("slotToElicit"); 101 102 } 103 104 if(jsonValue.ValueExists("responseCard")) 105 { 106 m_responseCard = jsonValue.GetObject("responseCard"); 107 108 } 109 110 if(jsonValue.ValueExists("sessionId")) 111 { 112 m_sessionId = jsonValue.GetString("sessionId"); 113 114 } 115 116 if(jsonValue.ValueExists("botVersion")) 117 { 118 m_botVersion = jsonValue.GetString("botVersion"); 119 120 } 121 122 if(jsonValue.ValueExists("activeContexts")) 123 { 124 Array<JsonView> activeContextsJsonList = jsonValue.GetArray("activeContexts"); 125 for(unsigned activeContextsIndex = 0; activeContextsIndex < activeContextsJsonList.GetLength(); ++activeContextsIndex) 126 { 127 m_activeContexts.push_back(activeContextsJsonList[activeContextsIndex].AsObject()); 128 } 129 } 130 131 132 133 return *this; 134 } 135