# Retrieve the Bot’s Response

The `BotResponse` object provides methods to retrieve the HTTP status code, response HTTP header parameters and response envelope from the bot’s message.

```java
// Retrieve the HTTP status code.
int httpStatusCode = response.getHttpStatusCode();

// Retrieve the response HTTP header parameters.
BotHttpHeaders httpHeaders = response.getHttpHeaders();
// Retrieve all header parameters.
Map<String, Collection<String>> allHeaders = httpHeaders.getAll()
// Retrieve a specific header parameter.
Optional<String> requestId = httpHeaders.getRequestIdHeader();

// Retrieve the response envelope.
ResponseEnvelope responseEnvelope = endSessionResponse
    .getResponseEnvelope();
```

Here is an example of a response body from the bot in JSON format. You can find the API response body schema in our Reference for API v5. This example `messages` array has messages with the `text` type and `choices` type. These types correspond to the TextResponseMessage and ChoicesResponseMessage schemas in the API reference.

```json
{
  "sessionId": "32f468af-bbea-48ed-947d-95e34c05023b",
  "botVersion": "0X9SB00000007cb0AA",
  "processedSequenceIds": [1650390206434],
  "messages": [
    {
      "type": "text",
      "id": "fde67029-c480-454d-9326-8e3024076b92",
      "text": "What is Refund policy?",
      "schedule": {
        "responseDelayMilliseconds": 1200
      }
    },
    {
      "type": "text",
      "id": "48ddb49d-cd4e-4f6a-b897-3e6730265f8b",
      "text": "Product are refundable with 30 days of purchase.",
      "schedule": {
        "responseDelayMilliseconds": 1200
      }
    },
    {
      "type": "text",
      "id": "2ef4993b-4e48-4686-806d-2b0bcf053f2b",
      "text": "Choose one of the options below",
      "schedule": {
        "responseDelayMilliseconds": 1200
      }
    },
    {
      "type": "choices",
      "id": "0267b1d2-d48b-4457-b364-e65e7b52a84e",
      "choices": [
        {
          "label": "Order Status",
          "alias": "1",
          "id": "8acdd120-0bf7-4f4f-bece-6946dd8ece04"
        },
        {
          "label": "Frequently Asked Questions",
          "alias": "2",
          "id": "95356019-f46c-4fc6-bd81-df67679b91ea"
        },
        {
          "label": "Transfer To Agent",
          "alias": "3",
          "id": "3e7debac-cb3d-4154-a923-802f45b1f0b7"
        },
        {
          "label": "End Chat",
          "alias": "4",
          "id": "96ad8494-b407-439e-968d-62762d902157"
        }
      ],
      "widget": "menu",
      "schedule": {
        "responseDelayMilliseconds": 1200
      }
    }
  ],
  "variables": null,
  "_links": null
}
```

The SDK automatically deserializes the JSON body into Java classes. This sample code demonstrates how to extract the bot’s message to the customer from the response body. Not all possible response body schemas and fields are included here.

```java
private String getResponseMessageAsText(List<AnyResponseMessage> messages) {
    StringBuilder sb = new StringBuilder();
    for(AnyResponseMessage message : messages){
      if (message instanceof TextResponseMessage){
        sb.append(((TextResponseMessage) message).getText())
            .append("\n");
      }else if (message instanceof ChoicesResponseMessage){
        List<ChoicesResponseMessageChoices> choices =
            ((ChoicesResponseMessage) message)
            .getChoices();
        for (ChoicesResponseMessageChoices choice : choices){
          sb.append(choice.getAlias())
              .append(".")
              .append(choice.getLabel())
              .append("\n");
        }
      }else if (message instanceof EscalateResponseMessage){
        List<EscalateResponseMessageTargets> targets =
            ((EscalateResponseMessage) message)
            .getTargets();
        // Add code here to transfer the bot to another target.
        sb.append("Transferring you to Agent in Target : " + targets);

      }else if (message instanceof SessionEndedResponseMessage){
        ReasonEnum reason = ((SessionEndedResponseMessage) message)
            .getReason();
        // Add code here to clean up the channel.
        sb.append("The Chat session ended with Reason : " + reason);str
      }
    }
    return sb.toString();
}

System.out.println(getResponseMessageAsText(response.getResponseEnvelope()
    .getMessages()));

```

Here’s the extracted bot’s message to the customer in text format.

```bash
Hi,
I’m a demo bot for the user guide.
Choose one of the options below
1.Order Status
2.Frequently Asked Questions
3.Transfer To Agent
4.End Chat
```
