Announcing PHP Package Development - a new video course launching early 2019!

Amazon Alexa

The Amazon Alexa driver allows you to listen for pre-configured intents through the Alexa skill builder. You can also reply with custom Amazon Alexa Cards.

Installation & Setup

First you need to pull in the Amazon Alexa Driver.

composer require botman/driver-amazon-alexa

Then load the driver before creating the BotMan instance (only when you don't use BotMan Studio):

DriverManager::loadDriver(\BotMan\Drivers\AmazonAlexa\AmazonAlexaDriver::class);

// Create BotMan instance
BotManFactory::create($config);

Or if you use BotMan Studio:

php artisan botman:install-driver amazon-alexa

This driver requires a valid and secure URL in order to set up webhooks and receive events and information from the chat users. This means your application should be accessible through an HTTPS URL.

{callout-info} ngrok is a great tool to create such a public HTTPS URL for your local application. If you use Laravel Valet, you can create it with "valet share" as well.

To connect BotMan with your Amazon Alexa skill, you first need to follow the official guide to create your custom Amazon Alexa skill.

Amazon Alexa does not require any kind of configuration.

Supported Features

This is a list of features that the driver supports. If a driver does not support a specific action, it is in most cases a limitation from the messaging service - not BotMan.

Feature Supported?
Conversations
Question-Buttons
Image Attachment ✅ - through Cards
Video Attachment
Audio Attachment
Location Attachment

Accessing Alexa Slots

Amazon Alexa allows your intents to contain custom arguments - called "slots". Whenever you hear for a Alexa message that contains these slots, they will get stored as a slot extra on the IncomingMessage object. To access it, just retrieve it from the message extras:

$botman->hears('My-Intent-Name', function($bot) {
    $slots = $bot->getMessage()->getExtras('slots');
});

Sending Alexa Cards

Amazon Alexa allows your custom skill to reply not only by using voice, but also by adding custom Skill Cards to your replies. These are graphical cards that describe or enhance the voice interaction.

To create and send such a Card with BotMan, just create a Card object and add it as an OutgoingMessage attachment like this:

$botman->hears('My-Intent-Name', function($bot) {
    $card = Card::create('Your card title', 'Your card subtitle')
        ->type(Card::STANDARD_CARD_TYPE)
        ->image('https://botman.io/images/foo.png')
        ->text('This is a longer text for your card.');

    $message = OutgoingMessage::create('This is the spoken response')->withAttachment($card)
    $bot->reply($message);
});