Skip to content

Commit

Permalink
Merge branch 'f2m2rd-patch-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed Oct 25, 2017
2 parents ed1abc4 + 471198d commit 93944b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/AmazonAlexaDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class AmazonAlexaDriver extends HttpDriver
{
const DRIVER_NAME = 'AmazonAlexa';
const LAUNCH_REQUEST = 'LaunchRequest';
const SESSION_ENDED_REQUEST = 'SessionEndedRequest';

protected $messages = [];

Expand Down Expand Up @@ -73,8 +74,9 @@ public function getMessages()
$session = $this->payload->get('session');

$message = new IncomingMessage($intent['name'], $session['user']['userId'], $session['sessionId']);
$message->addExtras('slots', Collection::make($intent['slots']));

if (! is_null($intent) && array_key_exists('slots', $intent)) {
$message->addExtras('slots', Collection::make($intent['slots']));
}
$this->messages = [$message];
}

Expand All @@ -87,7 +89,7 @@ public function getMessages()
public function hasMatchingEvent()
{
$type = $this->event->get('type');
if ($type === self::LAUNCH_REQUEST) {
if ($type === self::LAUNCH_REQUEST || $type === self::SESSION_ENDED_REQUEST) {
$event = new GenericEvent($this->event);
$event->setName($type);

Expand Down Expand Up @@ -141,6 +143,7 @@ public function sendPayload($payload)
$response = new AlexaResponse();
$response->respond($payload['text']);
$response->card = $payload['card'] ?? null;
$response->shouldEndSession = $payload['shouldEndSession'] ?? false;

return Response::create(json_encode($response->render()))->send();
}
Expand Down
11 changes: 11 additions & 0 deletions tests/AmazonAlexaDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ public function it_fires_launch_event()
$this->assertSame(AmazonAlexaDriver::LAUNCH_REQUEST, $event->getName());
}

/** @test */
public function it_fires_session_ended_event()
{
$driver = $this->getValidDriver(null, AmazonAlexaDriver::SESSION_ENDED_REQUEST);

$event = $driver->hasMatchingEvent();

$this->assertInstanceOf(GenericEvent::class, $event);
$this->assertSame(AmazonAlexaDriver::SESSION_ENDED_REQUEST, $event->getName());
}

/** @test */
public function it_no_events_for_regular_messages()
{
Expand Down

0 comments on commit 93944b3

Please sign in to comment.