maxbeckers /
amazon-alexa-php
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | use MaxBeckers\AmazonAlexa\Helper\ResponseHelper; |
||
| 6 | use MaxBeckers\AmazonAlexa\Request\Request; |
||
| 7 | use MaxBeckers\AmazonAlexa\Request\Request\Standard\IntentRequest; |
||
| 8 | use MaxBeckers\AmazonAlexa\RequestHandler\AbstractRequestHandler; |
||
| 9 | use MaxBeckers\AmazonAlexa\Response\Card; |
||
| 10 | use MaxBeckers\AmazonAlexa\Response\Response; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Just a simple example request handler for a card response. |
||
| 14 | * To create a response with an image @see https://developer.amazon.com/de/docs/custom-skills/include-a-card-in-your-skills-response.html#creating-a-home-card-to-display-text-and-an-image |
||
| 15 | */ |
||
| 16 | class CardResponseRequestHandler extends AbstractRequestHandler |
||
| 17 | { |
||
| 18 | public function __construct( |
||
| 19 | private readonly ResponseHelper $responseHelper |
||
| 20 | ) { |
||
| 21 | parent::__construct(); |
||
| 22 | $this->supportedApplicationIds = ['my_amazon_skill_id']; |
||
| 23 | } |
||
| 24 | |||
| 25 | public function supportsRequest(Request $request): bool |
||
| 26 | { |
||
| 27 | // support all intent requests, should not be done. |
||
| 28 | return $request->request instanceof IntentRequest; |
||
| 29 | } |
||
| 30 | |||
| 31 | public function handleRequest(Request $request): Response |
||
| 32 | { |
||
| 33 | $card = Card::createSimple( |
||
| 34 | 'Example of the Card Title', |
||
| 35 | "Example of card content. This card has just plain text content.\nThe content is formatted with line breaks to improve readability." |
||
| 36 | ); |
||
| 37 | $this->responseHelper->card($card); |
||
| 38 | |||
| 39 | return $this->responseHelper->respond('Text to speak back to the user.'); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 40 | } |
||
| 41 | } |
||
| 42 |