PHP code example of vasily-kartashov / amazon-alexa-php
1. Go to this page and download the library: Download vasily-kartashov/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/ */
vasily-kartashov / amazon-alexa-php example snippets
class MyAppCertificate extends \Alexa\Request\Certificate {
public function getCertificate() {
$cached_certificate = retrieve_cert_from_myapp_cache();
if (empty($cached_certificate)) {
// Certificate is not cached, download it
$cached_ertificate = $this->fetchCertificate();
// Cache it now
}
return $cached_certificate;
}
}
$certificate = new MyAppCertificate($_SERVER['HTTP_SIGNATURECERTCHAINURL'], $_SERVER['HTTP_SIGNATURE']);
$alexa = new \Alexa\Request\Request($rawRequest);
$alexa->setCertificateDependency($certificate);
$alexaRequest = $alexa->fromData();
$application = new MyAppApplication($myappId);
$alexa = new \Alexa\Request\Request($rawRequest, $myappId);
$alexa->setApplicationDependency($application);
$alexaRequest = $alexa->fromData();
$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');