maxbeckers / amazon-alexa-bundle
Symfony Bundle for amazon alexa skills.
Installs: 1 945
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 2
Forks: 2
Open Issues: 0
Type:symfony-bundle
pkg:composer/maxbeckers/amazon-alexa-bundle
Requires
- php: >=8.2
- maxbeckers/amazon-alexa-php: >=2.0
- symfony/config: ^6.4|^7.0
- symfony/dependency-injection: ^6.4|^7.0
- symfony/framework-bundle: ^6.4|^7.0
- symfony/http-foundation: ^6.4|^7.0
- symfony/http-kernel: ^6.4|^7.0
README
This bundle is a simple helper to create an Amazon Echo (Alexa) endpoint to your symfony project. You only need to add the Bundle to your project and create some handlers for the alexa requests, configured in amazon alexa backend.
Requirements
- PHP 8.2+
- Symfony 6.4+
Install via composer
Require the bundle via composer:
composer require maxbeckers/amazon-alexa-bundle
Enable the Bundle
Add the bundle to your config/bundles.php
:
return [ // ...existing bundles... MaxBeckers\AmazonAlexaBundle\MaxBeckersAmazonAlexaBundle::class => ['all' => true], ];
Enable Routing
Then add the Bundle endpoint for alexa to config/routes.yaml
.
# config/routes.yaml maxbeckers_amazon_alexa: path: /alexa/ controller: MaxBeckers\AmazonAlexaBundle\Controller\AmazonAlexaController::amazonRequestAction
Create handlers
To add Handlers for alexa, create them as a service and tag them with maxbeckers_amazon_alexa.request_handler
.
How to create a handler see maxbeckers/amazon-alexa-php.
# config/services.yaml services: Example\MyIntentHandler: arguments: - '@MaxBeckers\AmazonAlexa\Helper\ResponseHelper' tags: - 'maxbeckers_amazon_alexa.request_handler'
Generate ssml
For ssml use the MaxBeckers\AmazonAlexa\Helper\SsmlGenerator
service to create valid ssml.
use MaxBeckers\AmazonAlexa\Helper\SsmlGenerator; class MyService { public function __construct( private readonly SsmlGenerator $ssmlGenerator ) { } public function generateSsml(): string { // add a message $this->ssmlGenerator->say('Hello World'); $ssml = $this->ssmlGenerator->getSsml(); // $ssml === '<speak>Hello World</speak>' return $ssml; } }
For backward compatibility, you can still use the service ID:
$ssmlGenerator = $this->container->get('maxbeckers_amazon_alexa.ssml_generator');