Download the PHP package skollro/alexa-php-sdk without Composer
On this page you can find all versions of the php package skollro/alexa-php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download skollro/alexa-php-sdk
More information about skollro/alexa-php-sdk
Files in skollro/alexa-php-sdk
Package alexa-php-sdk
Short Description Expressive SDK for developing Amazon Alexa skills in PHP.
License MIT
Informations about the package alexa-php-sdk
Amazon Alexa SDK for PHP
This package provides a framework-agnostic expressive SDK for developing Alexa skills in PHP based on https://github.com/maxbeckers/amazon-alexa-php.
Disclaimer
This package is no official Amazon Alexa SDK.
Until now this package does not support every operation which might be needed for writing Alexa skills but is a solid foundation. So feel free to PR missing features.
Install
You can install this package via composer:
Usage
Create a skill and handle requests
Use 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.
Middlewares
All requests are piped through several middlewares before the request handler is invoked.
Remember to return $next($request, $response)
to invoke the next middleware in the chain.
If you return a $response
from a middleware no other handlers are invoked and $response
is returned immediately.
Automatically attached middlewares
When creating a skill with Alexa::skill($applicationId)
we automatically attach the following two middlewares.
- Skollro\Alexa\VerifyRequest: Verifies if the request is coming from the Amazon Echo API and checks signatures.
- Skollro\Alexa\VerifyApplicationId: Verifies if the request is intended for your application.
Before middleware
Checking for an access token is a typical use case for a middleware which runs before the request handler.
After middleware
To run a middleware after the request handler, store the result of $next($request, $response)
in a temporary variable and return the response later.
Request handlers
Amazon Echo API sends different types of requests to your application. Use those callbacks to implement your skill's logic. You can use invokable classes for better encapsulation.
Responses
You can make use of a fluent and natural syntax for creating responses.
Exceptions
If you throw an exception in a request handler we invoke this callback so you can handle exceptions there.
License
The MIT License (MIT). Please see License File for more information.