{"id":13828462,"url":"https://github.com/maxbeckers/amazon-alexa-php","last_synced_at":"2025-05-16T03:05:49.093Z","repository":{"id":45936639,"uuid":"96616549","full_name":"maxbeckers/amazon-alexa-php","owner":"maxbeckers","description":"Php library for amazon echo (alexa) skill development.","archived":false,"fork":false,"pushed_at":"2025-01-06T06:26:18.000Z","size":398,"stargazers_count":113,"open_issues_count":3,"forks_count":30,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-05-13T07:15:09.841Z","etag":null,"topics":["alexa","alexa-custom-skill","alexa-sdk","alexa-skill","alexa-skill-kit","amazon","amazon-alexa-php","amazon-alexa-skill","amazon-echo","echo","library","php","php7","php71","php72","skill","ssml"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxbeckers.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-08T12:06:25.000Z","updated_at":"2025-01-06T06:26:23.000Z","dependencies_parsed_at":"2024-05-10T10:46:44.352Z","dependency_job_id":"fefb73e7-2418-4720-b9d6-e8b43c579ad9","html_url":"https://github.com/maxbeckers/amazon-alexa-php","commit_stats":{"total_commits":189,"total_committers":11,"mean_commits":"17.181818181818183","dds":0.7037037037037037,"last_synced_commit":"44c05d67f6810820594bfb40c4391d406179f553"},"previous_names":[],"tags_count":49,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbeckers%2Famazon-alexa-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbeckers%2Famazon-alexa-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbeckers%2Famazon-alexa-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbeckers%2Famazon-alexa-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxbeckers","download_url":"https://codeload.github.com/maxbeckers/amazon-alexa-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254459088,"owners_count":22074605,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alexa","alexa-custom-skill","alexa-sdk","alexa-skill","alexa-skill-kit","amazon","amazon-alexa-php","amazon-alexa-skill","amazon-echo","echo","library","php","php7","php71","php72","skill","ssml"],"created_at":"2024-08-04T09:02:48.008Z","updated_at":"2025-05-16T03:05:44.078Z","avatar_url":"https://github.com/maxbeckers.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"[![Build Status](https://scrutinizer-ci.com/g/maxbeckers/amazon-alexa-php/badges/build.png?b=master)](https://scrutinizer-ci.com/g/maxbeckers/amazon-alexa-php/?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/maxbeckers/amazon-alexa-php/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/maxbeckers/amazon-alexa-php/?branch=master)\n[![Coverage Status](https://scrutinizer-ci.com/g/maxbeckers/amazon-alexa-php/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/maxbeckers/amazon-alexa-php/?branch=master)\n[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)\n[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/maxbeckers/amazon-alexa-php/issues)\n\n# Amazon alexa php library\nThis 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.\n\n## Install via composer\nRequire the package with composer:\n```\ncomposer require maxbeckers/amazon-alexa-php\n```\n\n## Usage\nHandle the request: \n- map request data to request object\n- validate request\n- handle request data\n- create response\n- send response\n\n### Map request data to request object\nMap needed request headers and request body to `Request`.\n```php\nuse MaxBeckers\\AmazonAlexa\\Request\\Request;\n...\n$requestBody  = file_get_contents('php://input');\n$alexaRequest = Request::fromAmazonRequest($requestBody, $_SERVER['HTTP_SIGNATURECERTCHAINURL'], $_SERVER['HTTP_SIGNATURE']);\n```\n### Validate request\nThe `RequestValidator` will handle the amazon request validation.\n```php\nuse MaxBeckers\\AmazonAlexa\\Validation\\RequestValidator;\n...\n$validator = new RequestValidator();\n$validator-\u003evalidate($alexaRequest);\n```\n### Register request handlers\nFor different requests it's helpful to create different RequestHandlers.\n```php\nuse MaxBeckers\\AmazonAlexa\\RequestHandler\\RequestHandlerRegistry;\n...\n$requestHandlerRegistry = new RequestHandlerRegistry();\n$requestHandlerRegistry-\u003eaddHandler($myRequestHandler);\n```\n### Use registry to handle request\n```php\nuse MaxBeckers\\AmazonAlexa\\RequestHandler\\RequestHandlerRegistry;\n...\n$requestHandler = $requestHandlerRegistry-\u003egetSupportingHandler($alexaRequest);\n$response       = $requestHandler-\u003ehandleRequest($alexaRequest);\n```\n### Render response\n```php\nheader('Content-Type: application/json');\necho json_encode($response);\nexit();\n```\n### Create a new request handler\nThe new request handler must extend `AbstractRequestHandler`.\nIn constructor set the `supportedApplicationIds` to your skill Ids.\n```php\npublic function __construct()\n{\n    $this-\u003esupportedApplicationIds = ['my_amazon_skill_id'];\n}\n```\nThen implement the abstract `supportsRequest`-method.\n```php\npublic function supportsRequest(Request $request): bool\n{\n    return $request-\u003erequest instanceOf MaxBeckers\\AmazonAlexa\\Request\\Request\\Standard\\IntentRequest \u0026\u0026\n        'MyTestIntent' === $request-\u003erequest-\u003eintent-\u003ename;\n}\n```\nThen implement the `handleRequest`-method. For simple responses there is a `ResponseHelper`.\n```php\nuse MaxBeckers\\AmazonAlexa\\Helper\\ResponseHelper;\n...\npublic function handleRequest(Request $request): Response\n{\n    return $this-\u003eresponseHelper-\u003erespond('Success :)');\n}\n```\n## Check device address information\nTo get either \"Full Address\" or \"Country \u0026 Postal Code\" from the customer you need the permissions for user api call. More informations for the call see [device-address-api](https://developer.amazon.com/de/docs/custom-skills/device-address-api.html).\n```php\n$helper = new DeviceAddressInformationHelper();\n$fullAddress = $helper-\u003egetAddress($request);\n$countryAndPostalCode = $helper-\u003egetCountryAndPostalCode($request);\n```\n## Generate SSML\nFor 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`. \nYou can add all SSML you need to the generator and call `getSsml` to get the full string.\n```php\n$ssmlGenerator = new SsmlGenerator();\n$ssmlGenerator-\u003esay('one');\n$ssmlGenerator-\u003epauseStrength(SsmlGenerator::BREAK_STRENGTH_MEDIUM);\n$ssmlGenerator-\u003esay('two');\n$ssml = $ssmlGenerator-\u003egetSsml();\n// $ssml === '\u003cspeak\u003eone \u003cbreak strength=\"medium\" /\u003e two\u003c/speak\u003e'\n```\n\n## Symfony Integration\nThere is also a symfony bundle on [maxbeckers/amazon-alexa-bundle](https://github.com/maxbeckers/amazon-alexa-bundle).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxbeckers%2Famazon-alexa-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxbeckers%2Famazon-alexa-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxbeckers%2Famazon-alexa-php/lists"}