2017 © Pedro Peláez
 

library amazon-alexa-php

Amazon Alexa interface for PHP

image

vasily-kartashov/amazon-alexa-php

Amazon Alexa interface for PHP

  • Tuesday, July 3, 2018
  • by vasily-kartashov
  • Repository
  • 2 Watchers
  • 2 Stars
  • 1,743 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 64 Forks
  • 0 Open issues
  • 19 Versions
  • 23 % Grown

The README.md

Amazon Alexa PHP Library

Build Status, (*1)

This library provides provides some interface for developing Amazon Alexa Skills for your PHP app., (*2)

Consider this library work in progress and subject to rather significant API changes in the nearest future. Current implementation is garbage, but there's almost no alternative out there., (*3)

Usage

Install via composer: vasily-kartashov/amazon-alexa-php., (*4)

Roadmap

  • Remove public access
  • Add more unit tests
  • Deprecate the old confusing API
  • Add dependency on standard HTTP request object
  • Add integration with Oauth-Server from php-league
  • ~~Stop throwing exceptions around~~
  • Add LoggerAwareInterface
  • Extract Certificate validation authority and add cacheing to it
  • Add validator and dependency on https://github.com/alexa/alexa-smarthome/tree/master/validation_schemas

Requests

Create request by using a factory method Request::fromHttpRequest that accepts objects of type RequestInterface as defined by PSR-7. For example when using Guzzle one can initialize an Alexa request object by running:, (*5)

$request = Request::fromHttpRequest(ServerRequest::fromGlobals(), $applicationId);

Certificate validation

By default the system validates the request signature by fetching Amazon's signing certificate and decrypting the signature. You need CURL to be able to get the certificate. No caching is done but you can override the Certificate class easily if you want to implement certificate caching yourself based on what your app provides:, (*6)

Here is a basic example:, (*7)

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;
  }
}

And then in your app, use the setCertificateDependency function:, (*8)

$certificate = new MyAppCertificate($_SERVER['HTTP_SIGNATURECERTCHAINURL'], $_SERVER['HTTP_SIGNATURE']);

$alexa = new \Alexa\Request\Request($rawRequest);
$alexa->setCertificateDependency($certificate);

$alexaRequest = $alexa->fromData();

Application Id validation

The library will automatically validate your Application Id matches the one of the incoming request - you don't need to do anything for that. If and only if you wish to change how the validation happens, you might use a similar scenario to the certificate validation - provide your own Application class extending the \Alexa\Request\Application and providing a validateApplicationId() function as part of that. Pass your application to the Request library in a same way as the certificate:, (*9)


$application = new MyAppApplication($myappId); $alexa = new \Alexa\Request\Request($rawRequest, $myappId); $alexa->setApplicationDependency($application); $alexaRequest = $alexa->fromData();

Response

You can build an Alexa response with the Response class. You can optionally set a card or a reprompt too., (*10)

Here's a few examples., (*11)

$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');

To output the response, simply use the ->render() function, e.g. in Laravel you would create the response like so:, (*12)

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

In vanilla PHP:, (*13)

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

The Versions

03/07 2018

dev-master

9999999-dev

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mathias Hansen
by Emanuele Corradini
by Jakub Suchy
by Vasily Kartashov

02/07 2018

0.2.6

0.2.6.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Mathias Hansen
by Emanuele Corradini
by Jakub Suchy

02/07 2018

0.2.5

0.2.5.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Mathias Hansen
by Emanuele Corradini
by Jakub Suchy

29/06 2018

0.2.4

0.2.4.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Mathias Hansen
by Emanuele Corradini
by Jakub Suchy

27/04 2018

0.2.3

0.2.3.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Mathias Hansen
by Emanuele Corradini
by Jakub Suchy

25/09 2017

0.2.2

0.2.2.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Mathias Hansen
by Emanuele Corradini
by Jakub Suchy

22/09 2017

0.2.1

0.2.1.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Mathias Hansen
by Emanuele Corradini
by Jakub Suchy

22/09 2017

0.2.0

0.2.0.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Mathias Hansen
by Emanuele Corradini
by Jakub Suchy

20/06 2016

0.1.6

0.1.6.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Mathias Hansen
by Emanuele Corradini
by Jakub Suchy

13/04 2016

dev-drupal

dev-drupal

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Mathias Hansen
by Emanuele Corradini

24/03 2016

dev-certificate

dev-certificate

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Mathias Hansen
by Emanuele Corradini

29/11 2015

0.1.5

0.1.5.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Mathias Hansen

29/11 2015

0.1.4

0.1.4.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Mathias Hansen

27/10 2015

0.1.3

0.1.3.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Mathias Hansen

02/10 2015

0.1.2

0.1.2.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Mathias Hansen

29/09 2015

0.1.1

0.1.1.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Mathias Hansen

20/09 2015

0.1.0

0.1.0.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Mathias Hansen

27/08 2015

0.0.2

0.0.2.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Mathias Hansen

26/08 2015

0.0.1

0.0.1.0

Amazon Alexa interface for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Mathias Hansen