Skip to content

Commit 43aca1a

Browse files
authored
add APL support (#97)
* add APL support * cs fix * add additional tests * optimize code * add additional tests
1 parent a53d55b commit 43aca1a

384 files changed

Lines changed: 19518 additions & 1020 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.php-cs-fixer.cache

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## [2.1.0](https://github.com/maxbeckers/amazon-alexa-php/tree/2.1.0) (TBD)
4+
[Full Changelog](https://github.com/maxbeckers/amazon-alexa-php/compare/2.0.0...2.1.0)
5+
6+
**Added:**
7+
- **APL Support**: Alexa Presentation Language (directives, documents, components, commands, gestures) now supported for building multimodal experiences.
8+
39
## [2.0.0](https://github.com/maxbeckers/amazon-alexa-php/tree/2.0.0) (TBD)
410
[Full Changelog](https://github.com/maxbeckers/amazon-alexa-php/compare/1.13.0...2.0.0)
511

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ A modern PHP library for building Amazon Alexa skills with clean, maintainable c
1313
- **Request Validation**: Automatic verification of Amazon request signatures
1414
- **Flexible Handler System**: Easy-to-extend request handler architecture
1515
- **SSML Support**: Built-in Speech Synthesis Markup Language generator
16+
- **APL Support**: Create and send Alexa Presentation Language documents, components, directives, gestures and commands
1617
- **Device Address API**: Helper for accessing user location data
1718
- **PHP 8.2+ Ready**: Leverages modern PHP features and type safety
1819
- **Symfony Integration**: Available bundle for Symfony applications
@@ -162,6 +163,58 @@ $ssml = $ssmlGenerator->getSsml();
162163
// Result: <speak>Welcome to our cooking skill! <break strength="medium" /> Today we will learn about <emphasis level="strong">amazing</emphasis> pasta recipes. <break time="2s" /> Let's get started!</speak>
163164
```
164165

166+
## 🖼 APL (Alexa Presentation Language)
167+
168+
Build multimodal experiences with the included APL directive, component, command, and gesture classes:
169+
170+
```php
171+
<?php
172+
173+
use MaxBeckers\AmazonAlexa\Response\Directives\APL\RenderDocumentDirective;
174+
use MaxBeckers\AmazonAlexa\Response\Response;
175+
use MaxBeckers\AmazonAlexa\ResponseHelper;
176+
177+
// Inside a request handler:
178+
$document = [
179+
'type' => 'APL',
180+
'version' => '1.8',
181+
'mainTemplate' => [
182+
'items' => [
183+
[
184+
'type' => 'Text',
185+
'text' => '${payload.data.message}',
186+
'style' => 'textStylePrimary1'
187+
]
188+
]
189+
],
190+
];
191+
192+
$dataSources = [
193+
'data' => [
194+
'message' => 'Hello from APL!'
195+
],
196+
];
197+
198+
$aplDirective = new RenderDocumentDirective(
199+
token: 'mainScreen',
200+
document: $document,
201+
datasources: $dataSources
202+
);
203+
204+
// Using the response helper (if available in your handler base)
205+
$response = $this->responseHelper->respond(
206+
outputSpeech: 'Showing a visual response.',
207+
directives: [$aplDirective],
208+
shouldEndSession: false
209+
);
210+
211+
// Or manually:
212+
$alexaResponse = new Response();
213+
$alexaResponse->response->directives[] = $aplDirective;
214+
```
215+
216+
You can also leverage the rich PHP class model (components, commands, gestures, layouts) instead of raw arrays for stronger typing when building complex documents.
217+
165218
## 📍 Device Address Information
166219

167220
Access user location data with proper permissions:

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"skill",
2020
"alexa-custom-skill",
2121
"library",
22-
"ssml"
22+
"ssml",
23+
"apl"
2324
],
2425
"license": "MIT",
2526
"support": {

examples/Handlers/AskForPermissionsConsentCardResponseRequestHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class AskForPermissionsConsentCardResponseRequestHandler extends AbstractRequest
1717
public function __construct(
1818
private readonly ResponseHelper $responseHelper
1919
) {
20+
parent::__construct();
2021
$this->supportedApplicationIds = ['my_amazon_skill_id'];
2122
}
2223

examples/Handlers/CardResponseRequestHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class CardResponseRequestHandler extends AbstractRequestHandler
1818
public function __construct(
1919
private readonly ResponseHelper $responseHelper
2020
) {
21+
parent::__construct();
2122
$this->supportedApplicationIds = ['my_amazon_skill_id'];
2223
}
2324

examples/Handlers/SimpleIntentRequestHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class SimpleIntentRequestHandler extends AbstractRequestHandler
1616
public function __construct(
1717
private readonly ResponseHelper $responseHelper
1818
) {
19+
parent::__construct();
1920
$this->supportedApplicationIds = ['my_amazon_skill_id'];
2021
}
2122

examples/ask-for-permissions-card-response.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,4 @@
4949
} else {
5050
http_response_code(400);
5151
}
52-
5352
exit();

examples/card-response.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,4 @@
4949
} else {
5050
http_response_code(400);
5151
}
52-
5352
exit();

examples/simple-intent-request.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,4 @@
4949
} else {
5050
http_response_code(400);
5151
}
52-
5352
exit();

0 commit comments

Comments
 (0)