Develop Alexa Skills for Amazon Echo with PHP

58
Develop Alexa Skills Develop Alexa Skills for Amazon Echo with PHP for Amazon Echo with PHP AWS Tech Community Days, Cologne, 27/09/2017 AWS Tech Community Days, Cologne, 27/09/2017

Transcript of Develop Alexa Skills for Amazon Echo with PHP

Page 1: Develop Alexa Skills for Amazon Echo with PHP

Develop Alexa Skills Develop Alexa Skills for Amazon Echo with PHPfor Amazon Echo with PHP

AWS Tech Community Days, Cologne, 27/09/2017AWS Tech Community Days, Cologne, 27/09/2017

Page 2: Develop Alexa Skills for Amazon Echo with PHP

Ralf EggertRalf EggertCEO Travello GmbH, Trainer, Author, Coach,CEO Travello GmbH, Trainer, Author, Coach,

PHP Developer & Alexa Skill DeveloperPHP Developer & Alexa Skill Developer

Page 3: Develop Alexa Skills for Amazon Echo with PHP

Three questions!Three questions!

Page 4: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 44 from from 5858

AgendaAgenda

Amazon Alexa Basics

Prepare skill

Why PHP?

Implement skill code

Learnings

Page 5: Develop Alexa Skills for Amazon Echo with PHP

Amazon Alexa BasicsAmazon Alexa Basics

Page 6: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 66 from from 5858

How does an Alexa request work?How does an Alexa request work?

AWSLambdaFunction

Alexa Voice Service

Page 7: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 77 from from 5858

How does an Alexa request work?How does an Alexa request work?

AWSLambdaFunction

Alexa Voice Service

Voice Command

Page 8: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 88 from from 5858

How does an Alexa request work?How does an Alexa request work?

AWSLambdaFunction

Alexa Voice Service

Voice Command

Voice Request

Page 9: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 99 from from 5858

How does an Alexa request work?How does an Alexa request work?

AWSLambdaFunction

Alexa Voice Service

Voice Command

Voice Request

JSON Request

Page 10: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 1010 from from 5858

How does an Alexa request work?How does an Alexa request work?

AWSLambdaFunction

Alexa Voice Service

Voice Command

Voice Request

JSON Request

JSON Response

Page 11: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 1111 from from 5858

How does an Alexa request work?How does an Alexa request work?

AWSLambdaFunction

Alexa Voice Service

Text Response

Voice Command

Voice Request

JSON Request

JSON Response

Page 12: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 1212 from from 5858

How does an Alexa request work?How does an Alexa request work?

AWSLambdaFunction

Alexa Voice Service

Text Response

Voice Response

Card Response

Voice Command

Voice Request

JSON Request

JSON Response

Page 13: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 1313 from from 5858

Alternative requestAlternative request

HTTPSEndpoint

Server

Alexa Voice Service

Text Response

Voice Response

Card Response

Voice Command

Voice Request

JSON Request

JSON Response

Page 14: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 1414 from from 5858

Alexa Voice Service (AVS)Alexa Voice Service (AVS)

Alexa Voice Service

AutomaticSpeech

Recognition(ASR)

NaturalLanguage

Understanding(NLU)

TextTo

Speech(TTS)

VoiceCommandMapping

Page 15: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 1515 from from 5858

Alexa Skills Kit (ASK)Alexa Skills Kit (ASK)

Alexa Skills Kit

Interaction-Model /Skill Builder

Configuration

Publishing /Privacy

TestService Simulator

Beta Test

Page 16: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 1616 from from 5858

ASK OverviewASK Overview

Page 17: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 1717 from from 5858

Alexa Skill BuilderAlexa Skill Builder

Page 18: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 1818 from from 5858

AWS Lambda FunctionsAWS Lambda Functions

Page 19: Develop Alexa Skills for Amazon Echo with PHP

Why PHP?Why PHP?

Page 20: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 2020 from from 5858

Possible solutionsPossible solutions

Compile PHP for AWS

Use supported runtime engine for AWS

Use own HTTPS endpoint server

Page 21: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 2121 from from 5858

Use supported runtime engine?Use supported runtime engine?

Page 22: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 2222 from from 5858

Compile PHP for AWS Lambda?Compile PHP for AWS Lambda?

https://goo.gl/N9VVvb

Page 23: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 2323 from from 5858

Use own HTTPS endpoint server?Use own HTTPS endpoint server?

Page 24: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 2424 from from 5858

Solution foundSolution found

Compile PHP for AWS

Use supported runtime engine for AWS

Use own HTTPS endpoint server

Page 25: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 2525 from from 5858

Disadvantages own HTTPS endpointDisadvantages own HTTPS endpoint

Some dev-tools only work with Lambda (API, CLI)

Need to build own library for Alexa

Server administration

Page 26: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 2626 from from 5858

Advantages own HTTPS endpointAdvantages own HTTPS endpoint

Use any software you want

Full control over server environment

Privacy concerns (soft concern)

Page 27: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 2727 from from 5858

Open-source PHP libraryOpen-source PHP library

https://github.com/travello-gmbh/

Page 28: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 2828 from from 5858

My current tech stackMy current tech stack

Page 29: Develop Alexa Skills for Amazon Echo with PHP

Prepare skillPrepare skill

Page 30: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 3030 from from 5858

Create sample dialogsCreate sample dialogs

Page 31: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 3131 from from 5858

Sample dialog ISample dialog I

Alexa, start my zoo!

Welcome to your zoo.

Please name an animal in my zoo!

An elephant lives in your zoo.

Thanks, Alexa.

You are welcome.

Page 32: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 3232 from from 5858

Sample dialog IISample dialog II

Alexa, start my zoo!

Welcome to your zoo.

How many animals live in my zoo?

42 animals live in your zoo.

Thanks, Alexa.

You are welcome.

Page 33: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 3333 from from 5858

Create flow diagramsCreate flow diagrams

Page 34: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 3434 from from 5858

Flow diagrammFlow diagramm

Welcome to your zoo

Start my zoo

An elephantlives in your zoo

42 animalslive in your zoo

»name« »number«

»name« »number«

You're welcome

»thanks« »thanks«

»thanks«

Page 35: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 3535 from from 5858

Configure Alexa Skills KitConfigure Alexa Skills Kit

Page 36: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 3636 from from 5858

Create custom slot typesCreate custom slot types

Page 37: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 3737 from from 5858

Create custom intentsCreate custom intents

Page 38: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 3838 from from 5858

Configure HTTPS endpointConfigure HTTPS endpoint

Page 39: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 3939 from from 5858

Configure SSL certificateConfigure SSL certificate

Page 40: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 4040 from from 5858

Test HTTPS endpointTest HTTPS endpoint

Page 41: Develop Alexa Skills for Amazon Echo with PHP

Implement skill codeImplement skill code

Page 42: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 4242 from from 5858

Install sample applicationInstall sample application

$ git clone https://github.com/travello-gmbh/example-zoo-skill

$ cd example-zoo-skill

$ composer install

$ sudo chmod -R 777 data/cache/

// setup a virtual host for http://example-zoo-skill

// with the example-zoo-skill/html/ path as doc root

Page 43: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 4343 from from 5858

Test sample applicationTest sample application

/data/postman/collection.json

Page 44: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 4444 from from 5858

Update text fileUpdate text file

return [ 'alexaLaunchTitle' => 'Welcome', 'alexaLaunchMessage' => 'Welcome to my zoo', 'alexaRepromptMessage' => 'Another animal or cancel?', 'alexaHelpTitle' => 'Help', 'alexaHelpMessage' => 'You can ask me which animal ' . 'lives in your zoo or how many animals live there.', 'alexaCancelTitle' => 'Thanks', 'alexaCancelMessage' => 'Thanks and see you soon!', 'alexaStopTitle' => 'Thanks', 'alexaStopMessage' => 'Thanks and see you soon!', 'alexaAnimalTitle' => 'An animal', 'alexaAnimalMessage' => '%1$s lives in your zoo!', 'alexaCountTitle' => 'Animal census', 'alexaCountMessage' => '%1$s animals live in your zoo!',];

/data/texts/zoo.common.texts.de-DE.php

Page 45: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 4545 from from 5858

Create text helper classCreate text helper class

<?phpnamespace Zoo\Application\Helper;

use TravelloAlexaLibrary\Application\Helper\AbstractTextHelper;

class ZooTextHelper extends AbstractTextHelper implements ZooTextHelperInterface{ public function getAnimalTitle(): string { return $this->commonTexts[$this->locale]['alexaAnimalTitle']; } public function getAnimalMessage(string $animal): string { return sprintf($this->commonTexts[$this->locale]['alexaAnimalMessage'], $animal); } public function getCountTitle(): string { return $this->commonTexts[$this->locale]['alexaCountTitle']; } public function getCountMessage(int $count): string { return sprintf($this->commonTexts[$this->locale]['alexaCountMessage'], $count); }} /module/Zoo/src/Application/Helper/ZooTextHelper.php

Page 46: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 4646 from from 5858

Create zoo application ICreate zoo application I

<?phpnamespace Zoo\Application;

use TravelloAlexaLibrary\Application\AbstractAlexaApplication;use TravelloAlexaLibrary\Request\RequestType\IntentRequestType;use Zoo\Application\Helper\ZooTextHelperInterface;

class ZooApplication extends AbstractAlexaApplication{ protected function handleIntentRequest(): bool { $intentRequest = $this->alexaRequest->getRequest();

switch ($intentRequest->getIntent()->getName()) { case 'AnimalIntent': return $this->animalIntent();

case 'AMAZON.StopIntent': return $this->stopIntent();

/* ... */ } }}

/module/Zoo/src/Application/ZooApplication.php

Page 47: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 4747 from from 5858

Create zoo application IICreate zoo application II

<?phpnamespace Zoo\Application;

use TravelloAlexaLibrary\Response\Card\Standard;use TravelloAlexaLibrary\Response\OutputSpeech\SSML;

class ZooApplication extends AbstractAlexaApplication{ private function animalIntent(): bool { $zooMessage = $this->textHelper->getAnimalMessage('An elephant');

$this->alexaResponse->setOutputSpeech(new SSML($zooMessage));

$this->alexaResponse->setCard(new Standard( $this->textHelper->getAnimalTitle(), $zooMessage, $this->smallImageUrl, $this->largeImageUrl ));

return true; }}

/module/Zoo/src/Application/ZooApplication.php

Page 48: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 4848 from from 5858

Test zoo applicationTest zoo application

/data/postman/collection.json

Page 49: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 4949 from from 5858

More featuresMore features

Session attributes step2→

Second intent step4→

https://github.com/travello-gmbh/example-zoo-skill

Species slot type step3→

Page 50: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 5050 from from 5858

Coming soon in Library 2.0Coming soon in Library 2.0

https://github.com/travello-gmbh/amazon-alexa-skill-library

Introducing Intent classes

Automatic intent handling

Page 51: Develop Alexa Skills for Amazon Echo with PHP

LearningsLearnings

Page 52: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 5252 from from 5858

Early successEarly success

6 months top 10 activated skills

75.000 customers so far

64 customer reviews so far

2.500.000 utterances so far

Most accessed DE skill in 05/2017

Page 53: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 5353 from from 5858

Biggest challengesBiggest challenges

First name slot type

Signature validation

Category slot type intents→

Chance to break first skill2nd server for tests

More complex VUI / CUI

Page 54: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 5454 from from 5858

Certification processCertification process

7 days for feedback (02/2017)

Signature validation issue

16 hours to go live (07/2017)Single-word invocation issue

0 issues»abbrechen« intent issue

Page 55: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 5555 from from 5858

Development numbersDevelopment numbers

10 working days total

80% for infrastructure code

15 working days total

90% for skill code

20% for skill code

10% for infrastructure code

Page 56: Develop Alexa Skills for Amazon Echo with PHP

AWS Tech Community DaysAWS Tech Community DaysRalf EggertRalf Eggert 5656 from from 5858

LearningsLearnings

Start with simple skill

Test thoroughly

Write a solid code base

Build more than one skill

Design a sophisticated VUI

Do not trust slot-types blindly

Have fun!

Page 57: Develop Alexa Skills for Amazon Echo with PHP

Questions?Questions?

Page 58: Develop Alexa Skills for Amazon Echo with PHP

Thanks!Thanks!Mail: [email protected]: [email protected]: www.travello.audioWeb: www.travello.audio