src/WebhookClient.php
protected function renderV2()
    {
        $out = [];

        $messages = [];

        foreach ($this->messages as $message) {
            if ($message instanceof Payload) {
                $out['payload'] = $message->render();
            } else {
                $messages[] = $message->render();
            }
        }

        if (count($messages)) {
            $out['fulfillmentMessages'] = $messages;
        }

        if ($this->text) {
            $out['fulfillmentText'] = $this->text;
        }

        $outgoingContexts = [];
        foreach ($this->outgoingContexts as $outgoingContext) {
            $outContexts = [
                'name' => $this->session.'/contexts/'.$outgoingContext->getName(),
            ];

            if ($outgoingContext->getLifespan()) {
                $outContexts['lifespanCount'] = $outgoingContext->getLifespan();
            }

            if ($outgoingContext->getParameters()) {
                $outContexts['parameters'] = $outgoingContext->getParameters();
            }

            $outgoingContexts[] = $outContexts;
        }
        $out['outputContexts'] = $outgoingContexts;

        return $out;
    }
protected function renderV2()
    {
        $out = [];

        $messages = [];

        foreach ($this->messages as $message) {
            if ($message instanceof Payload) {
                $out['payload'] = $message->render();
            } else {
                $messages[] = $message->render();
            }
        }

        if (count($messages)) {
            $out['fulfillmentMessages'] = $messages;
        }

        if ($this->text) {
            $out['fulfillmentText'] = $this->text;
        }

        $outgoingContexts = [];
        foreach ($this->outgoingContexts as $outgoingContext) {
            $outContexts = [
                'name' => $this->session.'/contexts/'.$outgoingContext->getName(),
            ];

            if ($outgoingContext->getLifespan()) {
                $outContexts['lifespanCount'] = $outgoingContext->getLifespan();
            }

            if ($outgoingContext->getParameters()) {
                $outContexts['parameters'] = $outgoingContext->getParameters();
            }

            $outgoingContexts[] = $outContexts;
        }
        $out['outputContexts'] = $outgoingContexts;

        return $out;
    }
Render response as array for API V2.

@param string $session session

@return array