src/Response/AlexaResponse.php
private function prepareResponseData()
    {
        $responseData = [];
        $responseData['version'] = self::ALEXA_RESPONSE_VERSION;
        $response = [];

        //Check to see if a speech, card, or reprompt object are set and if so
        //add them to the data object
        if (!is_null($this->speech) && $this->speech instanceof OutputSpeech) {
            $response = $this->speech->toArray();
        }

        if (!is_null($this->card) && $this->card instanceof Card) {
            $response['card'] = $this->card->toArray();
        }

        if (!is_null($this->reprompt) && $this->reprompt instanceof Reprompt && trim($this->reprompt->getValue()) != "") {
            $response['reprompt'] = $this->reprompt->toArray();
        }

        if (!is_null($this->directives)) {
            foreach ($this->directives as $directive) {
                $response['directives'][] = $directive->toArray();
            }
        }

        $response['shouldEndSession'] = $this->shouldSessionEnd;

        $sessionAttributes = $this->getSessionData();

        if ($sessionAttributes && count($sessionAttributes) > 0) {
            $responseData['sessionAttributes'] = $sessionAttributes;
        }

        $responseData['response'] = $response;

        return $responseData;
    }
private function prepareResponseData()
    {
        $responseData = [];
        $responseData['version'] = self::ALEXA_RESPONSE_VERSION;
        $response = [];

        //Check to see if a speech, card, or reprompt object are set and if so
        //add them to the data object
        if (!is_null($this->speech) && $this->speech instanceof OutputSpeech) {
            $response = $this->speech->toArray();
        }

        if (!is_null($this->card) && $this->card instanceof Card) {
            $response['card'] = $this->card->toArray();
        }

        if (!is_null($this->reprompt) && $this->reprompt instanceof Reprompt && trim($this->reprompt->getValue()) != "") {
            $response['reprompt'] = $this->reprompt->toArray();
        }

        if (!is_null($this->directives)) {
            foreach ($this->directives as $directive) {
                $response['directives'][] = $directive->toArray();
            }
        }

        $response['shouldEndSession'] = $this->shouldSessionEnd;

        $sessionAttributes = $this->getSessionData();

        if ($sessionAttributes && count($sessionAttributes) > 0) {
            $responseData['sessionAttributes'] = $sessionAttributes;
        }

        $responseData['response'] = $response;

        return $responseData;
    }
Build the valid Alexa response object

@return array