2017 © Pedro Peláez
 

library amazon-alexa-php

Php library for amazon echo (alexa) skill development.

image

maxbeckers/amazon-alexa-php

Php library for amazon echo (alexa) skill development.

  • Sunday, July 29, 2018
  • by maxbeckers
  • Repository
  • 5 Watchers
  • 24 Stars
  • 856 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 8 Forks
  • 2 Open issues
  • 33 Versions
  • 65 % Grown

The README.md

Build Status Scrutinizer Code Quality Coverage Status MIT Licence contributions welcome, (*1)

Amazon alexa php library

This library is a helper for amazon echo (alexa) skills with php. With this library it's very simple to handle alexa requests in your php application. You only create some handlers for the requests of your alexa skill and add them to a registry., (*2)

Install via composer

Require the package with composer:, (*3)

composer require maxbeckers/amazon-alexa-php

Usage

Handle the request: - map request data to request object - validate request - handle request data - create response - send response, (*4)

Map request data to request object

Map needed request headers and request body to Request., (*5)

use MaxBeckers\AmazonAlexa\Request\Request;
...
$requestBody  = file_get_contents('php://input');
$alexaRequest = Request::fromAmazonRequest($requestBody, $_SERVER['HTTP_SIGNATURECERTCHAINURL'], $_SERVER['HTTP_SIGNATURE']);

Validate request

The RequestValidator will handle the amazon request validation., (*6)

use MaxBeckers\AmazonAlexa\Validation\RequestValidator;
...
$validator = new RequestValidator();
$validator->validate($alexaRequest);

Register request handlers

For different requests it's helpful to create different RequestHandlers., (*7)

use MaxBeckers\AmazonAlexa\RequestHandler\RequestHandlerRegistry;
...
$requestHandlerRegistry = new RequestHandlerRegistry();
$requestHandlerRegistry->addHandler($myRequestHandler);

Use registry to handle request

use MaxBeckers\AmazonAlexa\RequestHandler\RequestHandlerRegistry;
...
$requestHandler = $requestHandlerRegistry->getSupportingHandler($alexaRequest);
$response       = $requestHandler->handleRequest($alexaRequest);

Render response

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

Create a new request handler

The new request handler must extend AbstractRequestHandler. In constructor set the supportedApplicationIds to your skill Ids., (*8)

public function __construct()
{
    $this->supportedApplicationIds = ['my_amazon_skill_id'];
}

Then implement the abstract supportsRequest-method., (*9)

public function supportsRequest(Request $request): bool
{
    return $request->request instanceOf MaxBeckers\AmazonAlexa\Request\Request\Standard\IntentRequest &&
        'MyTestIntent' === $request->request->intent->name;
}

Then implement the handleRequest-method. For simple responses there is a ResponseHelper., (*10)

use MaxBeckers\AmazonAlexa\Helper\ResponseHelper;
...
public function handleRequest(Request $request): Response
{
    return $this->responseHelper->respond('Success :)');
}

Check device address information

To get either "Full Address" or "Country & Postal Code" from the customer you need the permissions for user api call. More informations for the call see device-address-api., (*11)

$helper = new DeviceAddressInformationHelper();
$fullAddress = $helper->getAddress($request);
$countryAndPostalCode = $helper->getCountryAndPostalCode($request);

Generate SSML

For SSML output you can use the SsmlGenerator. With the helper will generate valid SSML for alexa. All types of alexa known SSML tags have a function in the SsmlGeneator. You can add all SSML you need to the generator and call getSsml to get the full string., (*12)

$ssmlGenerator = new SsmlGenerator();
$ssmlGenerator->say('one');
$ssmlGenerator->pauseStrength(SsmlGenerator::BREAK_STRENGTH_MEDIUM);
$ssmlGenerator->say('two');
$ssml = $ssmlGenerator->getSsml();
// $ssml === '<speak>one <break strength="medium" /> two</speak>'

Symfony Integration

There is also a symfony bundle on maxbeckers/amazon-alexa-bundle., (*13)

The Versions

29/07 2018

dev-master

9999999-dev

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill ssml

29/07 2018

1.2.1

1.2.1.0

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill ssml

29/07 2018

dev-develop

dev-develop

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill ssml

27/07 2018

1.2.0

1.2.0.0

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill ssml

30/06 2018

dev-feature/28

dev-feature/28

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill ssml

17/05 2018

1.1.3

1.1.3.0

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill ssml

17/05 2018

1.1.x-dev

1.1.9999999.9999999-dev

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill ssml

21/03 2018

1.1.2

1.1.2.0

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill ssml

15/03 2018

1.1.1

1.1.1.0

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill ssml

15/02 2018

1.1.0

1.1.0.0

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill ssml

06/02 2018

1.0.16

1.0.16.0

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill ssml

22/01 2018

1.0.15

1.0.15.0

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill ssml

09/01 2018

1.0.14

1.0.14.0

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill ssml

03/01 2018

1.0.13

1.0.13.0

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill

21/12 2017

1.0.12

1.0.12.0

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill

14/12 2017

1.0.11

1.0.11.0

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill

13/12 2017

1.0.10

1.0.10.0

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill

11/12 2017

1.0.9

1.0.9.0

Php library for amazon echo (alexa) skill development.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php library echo php7 alexa skill php71 amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php alexa-sdk php72 alexa-custom-skill

06/12 2017

1.0.8

1.0.8.0

This library is a helper for amazon alexa skills with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php alexa skill amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php

04/12 2017

1.0.7

1.0.7.0

This library is a helper for amazon alexa skills with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php alexa skill amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php

04/12 2017

1.0.6

1.0.6.0

This library is a helper for amazon alexa skills with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php alexa skill amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php

01/12 2017

1.0.5

1.0.5.0

This library is a helper for amazon alexa skills with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php alexa skill amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php

30/11 2017

1.0.4

1.0.4.0

This library is a helper for amazon alexa skills with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php alexa skill amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php

30/11 2017

1.0.3

1.0.3.0

This library is a helper for amazon alexa skills with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php alexa skill amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php

29/11 2017

1.0.2

1.0.2.0

This library is a helper for amazon alexa skills with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php alexa skill amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php

29/11 2017

1.0.1

1.0.1.0

This library is a helper for amazon alexa skills with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php alexa skill amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php

02/10 2017

1.0.0

1.0.0.0

This library is a helper for amazon alexa skills with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php alexa skill amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php

31/07 2017

0.1.6

0.1.6.0

This library is a helper for amazon alexa skills with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php alexa skill amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php

26/07 2017

0.1.5

0.1.5.0

This library is a helper for amazon alexa skills with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php alexa skill amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php

25/07 2017

0.1.4

0.1.4.0

This library is a helper for amazon alexa skills with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php alexa skill amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php

21/07 2017

0.1.3

0.1.3.0

This library is a helper for amazon alexa skills with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php alexa skill amazon-alexa amazon-alexa-php amazon-echo amazon-echo-php alexa-skill alexa-skill-php

12/07 2017

0.1.2

0.1.2.0

This library is a helper for amazon alexa skills with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php alexa amazon alexa alexa skill

10/07 2017

0.1.1

0.1.1.0

This library is a helper for amazon alexa skills with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Maximilian Beckers

php alexa amazon alexa alexa skill