Select HTTPs, enter the address and select “My development endpoint has a certificate from a trusted certificate authority”. Then back to the interaction model and click on “Build Click”.<\/strong><\/p>\nThe PHP-Part<\/h2>\n
Now we can finally get to the PHP topic. Actually, not much changes here in comparison to my old tutorial, but I will explain it again briefly. As a logger I use monologue to check why some questions were not answered. You can also see which intents or utterances are asked, but not supported by your skill. For example, when I say “hiderido” – this uterance is missing.<\/p>\n
Composer File for Monolog:<\/p>\n
{\r\n \"name\": \"db-dzine\/alexaphp\",\r\n \"description\": \"PHP Class for Alexa\",\r\n \"type\": \"library\",\r\n \"authors\": ,\r\n \"minimum-stability\": \"dev\",\r\n \"require\": {\r\n \"monolog\/monolog\": \"1.x-dev\",\r\n }\r\n}<\/pre>\nAfter that run\u00a0composer install<\/code> in your folder. Then you can create an index.php and load autload & monolog:<\/p>\n<?php \/\/ Load Monolog Vendor require_once __DIR__ . '\/vendor\/autoload.php'; \/\/ Autoload files using Composer autoload use Monolog\\Logger; use Monolog\\Handler\\StreamHandler; \/\/ Save Requests on debug log define('DEBUG', true); define('DEBUG_FILE', __DIR__ . '\/logs\/log.log'); $logger = new Logger('Alexa'); $logger->pushHandler( new StreamHandler( DEBUG_FILE, Logger::INFO ) );<\/pre>\nUm requests von eurem Skill zu catchen:<\/p>\n
\/\/ Get Alexa Request\r\n$jsonRequest = file_get_contents('php:\/\/input');\r\n\r\n\/\/ Decode the Request\r\n$data = json_decode($jsonRequest, true);\r\n\r\n\/\/ Abort when Empty\r\nif( empty($data) || (!isset($data) ) ) {\r\n\tdie('Bad Request');\r\n}<\/pre>\nThe following variables can be read from the data array. There’s more in here, of course, but these are the most important:<\/p>\n
$intent = !empty($data) ? $data : 'default';\r\n$intentData = !empty($data) ? $data : 'default';\r\n$sessionId = !empty($data) ? $data : 'default'; \r\n\r\n$logger->info( var_export($data, true));\r\n$logger->info( $intentData );\r\n$logger->info( $sessionId);<\/pre>\nNow we can use the $intent variable to find out which intent was addressed. I return a nice hello via a switch statement in case of the “hello”-intent. And if a name was passed with it, I will also return it. Return the whole as JSON encoded string to Alexa.<\/p>\n
switch ($intent) {\r\n\r\n\t\/\/ Hallo Intent f\u00fcr Utterances hi, hallo, moin\r\n\tcase 'hallo':\r\n\t\t\/\/ Hallo Intentdata abfragen\r\n\t\t$name = !empty($intentData) ? $intentData : '';\r\n\r\n\t\t\/\/ save $name in data file - here also mysql can be used\r\n\t\t\/\/ later you can use session id to get data like name\r\n\t\tif(!empty($name)) {\r\n\t\t\t$dataToSave = array($sessionId => array(\r\n\t\t\t\t'name' => $name\r\n\t\t\t));\r\n\t\t\t$fp = fopen('data.json', 'w');\r\n\t\t\tfwrite($fp, json_encode($dataToSave));\r\n\t\t\tfclose($fp);\r\n\t\t}\r\n\r\n\t\t$responseArray = ,\r\n\t\t 'shouldEndSession' => false\r\n\t\t ]\r\n\t\t];\r\n\t\tbreak;\r\n\r\n\t\/\/ Default\r\n\tdefault:\r\n\t\t$responseArray = ,\r\n\t\t 'shouldEndSession' => true\r\n\t\t ]\r\n\t\t];\r\n\t\tbreak;\r\n}\r\n\r\nheader ( 'Content-Type: application\/json' );\r\necho json_encode ( $responseArray );\r\ndie();<\/pre>\nSkill testing<\/h2>\n
We can test our skill with a “Question daniel hello klaus”. Sounds stupid, but ask daniel to start the skill (invocation name) and hello (intent) is executed.<\/p>\n
You can also use your Alexa app on your smartphone to test the skill.<\/p>\n","protected":false},"excerpt":{"rendered":"
Since my last tutorial some things have changed at Amazon’s Alexa Developer Platform. The interface has been reworked and instead of the old system, where intents had to be created manually, there is now a skill builder. Therefore I would like to give you here a small update of my old Alexa PHP Tutorials.The Skill…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[18,1,5],"tags":[],"class_list":["post-551","post","type-post","status-publish","format-standard","hentry","category-alexa","category-general","category-php"],"_links":{"self":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/posts\/551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/comments?post=551"}],"version-history":[{"count":7,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/posts\/551\/revisions"}],"predecessor-version":[{"id":4339,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/posts\/551\/revisions\/4339"}],"wp:attachment":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/media?parent=551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/categories?post=551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/tags?post=551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}