2017 © Pedro Peláez
 

library alexa-request-validator

Validates requests from Amazon Alexa

image

craigh/alexa-request-validator

Validates requests from Amazon Alexa

  • Thursday, February 15, 2018
  • by craigh411
  • Repository
  • 2 Watchers
  • 2 Stars
  • 63 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 4 Versions
  • 15 % Grown

The README.md

alexa-request-validator

A PHP implementation of the Alexa request validation required when using a web service with your Alexa skill, as set out in the Alexa docs, (*1)

Installation

Install via composer by doing:, (*2)

composer require craigh/alexa-request-validator, (*3)

How to use

Once installed you can instantiate the AlexaRequestValidator in your classes as follows:, (*4)

$validator = new \Humps\AlexaRequest\AlexaRequestValidator('YOUR_ALEXA_SKILL_ID', file_get_contents('php://input'), $_SERVER['HTTP_SIGNATURECERTCHAINURL'], $_SERVER['HTTP_SIGNATURE']);

Then simply do (Ideally you would add this in Middleware):, (*5)

try {
  if($validator->validateRequest()){
    // Accept request to your service
  }

  // Reject request with a 500 error, hopefully this shouldn't happen!
}catch(\Humps\AlexaRequest\Exceptions\AlexaValidationException $e) { 
  // Reject the request with a 400 error or the given error code (via $e->getCode()) with the returned message ($e->getMessage())
}

Timeout Tolerance

By default the timeout tolerance is 120 seconds (well within the 150 seconds required by Amazon). If you want to adjust this you can pass a fifth paramater to the constructor:, (*6)

$validator = new AlexaRequestValidator('YOUR_ALEXA_SKILL_ID', file_get_contents('php://input'), $_SERVER['HTTP_SIGNATURECERTCHAINURL'], $_SERVER['HTTP_SIGNATURE'], 150);

Tip: If you are testing through the Amazon Alexa Skill "test" section you may want to increase this tolerance during development so you can replay the request through your server. Just don't forget to reset it before certification!, (*7)

The Versions

15/02 2018

dev-master

9999999-dev

Validates requests from Amazon Alexa

  Sources   Download

MIT

The Requires

 

The Development Requires

by Craig Humphreys

15/02 2018

1.0.3

1.0.3.0

Validates requests from Amazon Alexa

  Sources   Download

MIT

The Requires

 

The Development Requires

by Craig Humphreys

25/09 2017

1.0.2

1.0.2.0

Validates requests from Amazon Alexa

  Sources   Download

MIT

The Requires

 

The Development Requires

by Craig Humphreys

25/09 2017

1.0.1

1.0.1.0

Validates requests from Amazon Alexa

  Sources   Download

MIT

The Requires

 

The Development Requires

by Craig Humphreys