diff --git a/src/AmazonAlexaDriver.php b/src/AmazonAlexaDriver.php index 78aa347..344156c 100644 --- a/src/AmazonAlexaDriver.php +++ b/src/AmazonAlexaDriver.php @@ -15,6 +15,7 @@ use BotMan\BotMan\Interfaces\DriverEventInterface; use BotMan\BotMan\Messages\Incoming\IncomingMessage; use BotMan\BotMan\Messages\Outgoing\OutgoingMessage; +use BotMan\Drivers\AmazonAlexa\Extensions\Directives; class AmazonAlexaDriver extends HttpDriver { @@ -125,6 +126,9 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam if ($attachment instanceof Card) { $parameters['card'] = $attachment; } + if ($attachment instanceof Directives) { + $parameters['directives'] = $attachment; + } } else { $text = $message; } @@ -147,6 +151,7 @@ public function sendPayload($payload) $response->respondSsml($payload['text']); } $response->card = $payload['card'] ?? null; + $response->directives = $payload['directives'] ?? null; $response->shouldEndSession = $payload['shouldEndSession'] ?? false; return Response::create(json_encode($response->render()))->send(); diff --git a/src/Extensions/Directives.php b/src/Extensions/Directives.php new file mode 100644 index 0000000..4e28b97 --- /dev/null +++ b/src/Extensions/Directives.php @@ -0,0 +1,94 @@ +audioItem = new Stream; + } + + public function type($type) + { + $this->type = $type; + + return $this; + } + + public function getType() + { + return $this->type; + } + + public function playBehaviour($playBehaviour) + { + $this->playBehaviour = $playBehaviour; + + return $this; + } + + public function getPlayBehaviour() + { + return $this->playBehaviour; + } + + public function url($url) + { + $this->audioItem->url($url); + } + + public function token($token) + { + $this->audioItem->token($token); + } + + public function expectedPreviousToken($expectedPreviousToken) + { + $this->audioItem->expectedPreviousToken($expectedPreviousToken); + } + + public function offsetInMilliseconds($offsetInMilliseconds) + { + $this->audioItem->offsetInMilliseconds($offsetInMilliseconds); + } + + public function toWebDriver() + { + return []; + } + + public function render() + { + return array_filter([ + [ + 'type' => $this->type, + 'playBehavior' => $this->playBehaviour, + 'audioItem' => [ + 'stream' => $this->audioItem->renderStream(), + ], + ], + ]); + } +} \ No newline at end of file diff --git a/src/Extensions/Stream.php b/src/Extensions/Stream.php new file mode 100644 index 0000000..e1a94d2 --- /dev/null +++ b/src/Extensions/Stream.php @@ -0,0 +1,71 @@ +url = $url; + + return $this; + } + + public function getUrl() + { + return $this->url; + } + + public function token($token) + { + $this->token = $token; + + return $this; + } + + public function getToken() + { + return $this->token; + } + + public function expectedPreviousToken($expectedPreviousToken) + { + $this->expectedPreviousToken = $expectedPreviousToken; + + return $this; + } + + public function getExpectedPreviousToken() + { + return $this->expectedPreviousToken; + } + + public function offsetInMilliseconds($offsetInMilliseconds) + { + $this->offsetInMilliseconds = $offsetInMilliseconds; + + return $this; + } + + public function getOffsetInMilliseconds() + { + return $this->offsetInMilliseconds; + } + + public function renderStream() + { + return [ + 'url' => $this->url, + 'token' => $this->token, + 'expectedPreviousToken' => $this->expectedPreviousToken, + 'offsetInMilliseconds' => $this->offsetInMilliseconds, + ]; + } +} \ No newline at end of file