PHP code example of nomisoft / php-alexa-helper

1. Go to this page and download the library: Download nomisoft/php-alexa-helper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nomisoft / php-alexa-helper example snippets


use \Alexa\Request\AlexaRequest;
$alexaRequest = AlexaRequest::fromRequest();

$alexaRequest = new AlexaRequest($json);

$alexaRequest->version;
$alexaRequest->session->application->applicationId;
$alexaRequest->request->intent->slots->ZodiacSign->value;

use \Alexa\Request\AlexaRequest;
use \Alexa\Request\RequestValidator;
$alexaRequest = AlexaRequest::fromRequest();
$validator = new RequestValidator($request);
if (!$validator->validate('YOUR_APP_ID')) {
    print_r($validator->getErrors());
}

use \Alexa\Request\AlexaRequest;
use \Alexa\Request\OutputSpeech;
$response = new AlexaResponse();
$speech = new OutputSpeech();
$speech->setText('Hello World');
$response->setOutputSpeech($speech);

$speech = new OutputSpeech();
$speech->setType('SSML');
$speech->setText('<speak>Hello <say-as interpret-as="spell-out">world</say-as>.</speak>');

use \Alexa\Request\Card;
$card = new Card();
$card->setContent('Hello World');
$response->setCard($card);
$response->render();

$card = new Card();
$card->setType('Standard');
$card->setTitle('Hello World Title');
$card->setText('Hello World Content');
$card->setSmallImage('http://example.com/small.jpg');
$card->setLargeImage('http://example.com/large.jpg');
$response->setCard($card);

$jsonResponse = new \Symfony\Component\HttpFoundation\JsonResponse($response);
return $jsonResponse;

composer