All Projects → maxbeckers → Amazon Alexa Php

maxbeckers / Amazon Alexa Php

Licence: mit
Php library for amazon echo (alexa) skill development.

Projects that are alternatives of or similar to Amazon Alexa Php

Chatskills
Run and debug Alexa skills on the command-line. Create bots. Run them in Slack. Run them anywhere!
Stars: ✭ 171 (+83.87%)
Mutual labels:  alexa, echo, alexa-skill, amazon-echo, amazon
alexa-ruby
Ruby toolkit for Amazon Alexa service
Stars: ✭ 17 (-81.72%)
Mutual labels:  alexa, amazon, amazon-echo, alexa-skill
Alexa Skill Kit
Library for effortless Alexa Skill development with AWS Lambda
Stars: ✭ 278 (+198.92%)
Mutual labels:  alexa, alexa-skill, amazon-echo, amazon
Home-Assistant
Home-Assistant-Config
Stars: ✭ 186 (+100%)
Mutual labels:  alexa, amazon, amazon-echo
Go Alexa
A collection of Amazon Echo / Alexa tools for Go development.
Stars: ✭ 245 (+163.44%)
Mutual labels:  alexa, amazon-echo, amazon
alexa template
A template and tutorial for building an Alexa Skill written in Python focused on readability.
Stars: ✭ 44 (-52.69%)
Mutual labels:  alexa, echo, alexa-skill
go-avs
A simple package for communicating with Amazon’s HTTP/2 API for AVS.
Stars: ✭ 25 (-73.12%)
Mutual labels:  alexa, amazon, amazon-echo
Awesome Amazon Alexa
🗣Curated list of awesome resources for the Amazon Alexa platform.
Stars: ✭ 458 (+392.47%)
Mutual labels:  alexa, alexa-skill, amazon-echo
Echo Sonos
Amazon Echo integration with Sonos
Stars: ✭ 722 (+676.34%)
Mutual labels:  echo, alexa-skill, amazon-echo
HuntTheYetiAlexa
Play the game Hunt the Yeti on the Amazon Echo
Stars: ✭ 17 (-81.72%)
Mutual labels:  alexa, amazon, amazon-echo
alexa-verifier-middleware
An express middleware that verifies HTTP requests sent to an Alexa skill are sent from Amazon.
Stars: ✭ 31 (-66.67%)
Mutual labels:  alexa, amazon, alexa-skill
cookiecutter-flask-ask
Cookiecutter template for Alexa skills based on the fantastic Flask-Ask framework 🍾🗣❓
Stars: ✭ 51 (-45.16%)
Mutual labels:  alexa, amazon-echo, alexa-skill
Bst
🔧 Bespoken Tools - Tools for making voice apps faster and better
Stars: ✭ 193 (+107.53%)
Mutual labels:  alexa, echo, amazon-echo
Home Assistant
Home-Assistant-Config
Stars: ✭ 182 (+95.7%)
Mutual labels:  alexa, amazon-echo, amazon
mapbox-assistant-example
Examples of Amazon Echo, Google Home, and other bots interacting with Mapbox services.
Stars: ✭ 15 (-83.87%)
Mutual labels:  alexa, amazon, echo
Voicewp
Create Alexa Skills through WordPress
Stars: ✭ 132 (+41.94%)
Mutual labels:  alexa, alexa-skill, amazon
alexa-spotify-connect
Control Spotify Connect devices with Alexa
Stars: ✭ 92 (-1.08%)
Mutual labels:  alexa, amazon, echo
alexa-skill-boilerplate
An easy to use Amazon Alexa Skill Boilerplate for fast skill creation
Stars: ✭ 54 (-41.94%)
Mutual labels:  alexa, amazon-echo, alexa-skill
Alexa Skills Kit Sdk For Java
The Alexa Skills Kit SDK for Java helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Stars: ✭ 758 (+715.05%)
Mutual labels:  alexa, amazon-echo, amazon
SinricPro Generic
Simple way to control your IOT development boards like ESP8226, ESP32, Arduino SAMD21, Adafruit SAMD21, SAMD51, nRF52, STM32, Teensy, SAM DUE with Amazon Alexa or Google Home
Stars: ✭ 18 (-80.65%)
Mutual labels:  alexa, alexa-skill

Build Status Coverage Status MIT Licence contributions welcome Scrutinizer Code Quality

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.

Install via composer

Require the package with composer:

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

Map request data to request object

Map needed request headers and request body to Request.

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.

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

Register request handlers

For different requests it's helpful to create different RequestHandlers.

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.

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

Then implement the abstract supportsRequest-method.

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.

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.

$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.

$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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].