PHP code example of dmitrijs / amazon-alexa-php

1. Go to this page and download the library: Download dmitrijs/amazon-alexa-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dmitrijs / amazon-alexa-php example snippets


$jsonDataAsArray = $request->json()->all(); // This is how you would retrieve this with Laravel
$alexaRequest = \Alexa\Request\Request::fromData($jsonDataAsArray);

if ($alexaRequest instanceof IntentRequest) {
	// Handle intent here
}

$response = new \Alexa\Response\Response;
$response->respond('Cooool. I\'ll lower the temperature a bit for you!')
	->withCard('Temperature decreased by 2 degrees');

$response = new \Alexa\Response\Response;
$response->respond('What is your favorite color?')
	->reprompt('Please tell me your favorite color');

$response = new \Alexa\Response\Response;
$response->dialogDelegate();

return response()->json($response->render());

header('Content-Type: application/json');
echo json_encode($response->render());
exit;