You can develop Alexa skills in PHP using the Amazon Alexa SDK for PHP library. Using the following code as starting point for your own skill. First you have to create a Request object from the POST request’s data. Then create a new skill with Alexa::skill($applicationId), passing your application id. Finally define your request handers and call handle($request) which handles the request and creates a response.

use MaxBeckers\AmazonAlexa\Request\Request;

$request = Request::fromAmazonRequest(file_get_contents('php://input'), $_SERVER['HTTP_SIGNATURECERTCHAINURL'], $_SERVER['HTTP_SIGNATURE']);

$alexa = Alexa::skill('amzn1.ask.skill.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX');

// define middlewares and request handlers...

$response = $alexa->handle($request);

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

Notice that this package is not an official Amazon Alexa SDK. Released under an MIT license. More information at https://github.com/skollro/alexa-php-sdk

LEAVE A REPLY

Please enter your comment!
Please enter your name here