├── README.md ├── composer.json ├── composer.lock └── src ├── Request ├── IntentRequest.php ├── LaunchRequest.php ├── Request.php ├── SessionEndedRequest.php └── User.php └── Response ├── Card ├── AbstractCard.php ├── LinkAccountCard.php ├── SimpleCard.php └── StandardCard.php ├── OutputSpeech.php ├── Reprompt.php └── Response.php /README.md: -------------------------------------------------------------------------------- 1 | # Amazon Alexa PHP Library 2 | 3 | This library provides provides a convient interface for developing Amazon Alexa Skills for your PHP app. 4 | 5 | ## Usage 6 | 7 | Install via composer: `composer require minicodemonkey/amazon-alexa-php`. 8 | 9 | ### Requests 10 | When Amazon Alexa triggers your skill, a HTTP request will be sent to the URL you specified for your app. 11 | 12 | You can parse the `JSON` body of the request like so: 13 | ```php 14 | $jsonDataAsArray = $request->json()->all(); // This is how you would retrieve this with Laravel 15 | $alexaRequest = \Alexa\Request\Request::fromData($jsonDataAsArray); 16 | ``` 17 | 18 | You can determine the type of the request with `instanceof`, e.g.: 19 | ```php 20 | if ($alexaRequest instanceof IntentRequest) { 21 | // Handle intent here 22 | } 23 | ``` 24 | 25 | ### Responses 26 | You can build several Alexa responses with the `Response` class. You can optionally set cards or a reprompt, too. 27 | 28 | Here's a few examples. 29 | 30 | #### Simple text response 31 | ```php 32 | $response = new \Alexa\Response\Response; 33 | $response->respond('I\'m your response message'); 34 | ``` 35 | 36 | #### With reprompt 37 | ```php 38 | $response = new \Alexa\Response\Response; 39 | $response->reprompt('What is your favourite color?'); 40 | ``` 41 | 42 | #### Cards 43 | 44 | For detailled informations on cards check out the following link: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/providing-home-cards-for-the-amazon-alexa-app#creating-a-home-card-to-display-text-and-an-image 45 | 46 | ##### SingleCard 47 | ```php 48 | $response = new \Alexa\Response\Response; 49 | $response->respond('Cooool. I\'ll lower the temperature a bit for you!') 50 | ->withCard('Temperature decreased by 2 degrees'); 51 | ``` 52 | 53 | ##### StandardCard with images 54 | You can also show images within your card 55 | 56 | Please note some notes on image sizing and hosting: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/providing-home-cards-for-the-amazon-alexa-app#image_size 57 | 58 | ```php 59 | $response = new \Alexa\Response\Response; 60 | $response->respond('Cooool. I\'ll lower the temperature a bit and show you an image!') 61 | ->withImageCardCard('My title', 'My caption text for the image...', 'https://url.to/small-image.jpg', 'https://url.to/large-image.jpg'); 62 | ``` 63 | 64 | ##### LinkAccountCard 65 | The LinkAccountCard is used for skills with enabled account linking and will show a link to your configured account linking url. As title, text etc. are set automatically there is no possibility to set random text. 66 | 67 | ```php 68 | $response = new \Alexa\Response\Response; 69 | $response->respond('To link the skill with your account, click the linkAccount shown in your alexa app.') 70 | ->withLinkAccountCard(); 71 | ``` 72 | 73 | #### Output the response 74 | To output the response, simply use the `->render()` function, e.g. in Laravel you would create the response like so: 75 | ```php 76 | return response()->json($response->render()); 77 | ``` 78 | 79 | In vanilla PHP: 80 | ```php 81 | header('Content-Type: application/json'); 82 | echo json_encode($response->render()); 83 | exit; 84 | ``` 85 | 86 | ## TODO 87 | * Verify request timestamp integrity automatically -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minicodemonkey/amazon-alexa-php", 3 | "description": "Amazon Alexa interface for PHP", 4 | "license": "MIT", 5 | "type": "library", 6 | "authors": [ 7 | { 8 | "name": "Mathias Hansen", 9 | "email": "me@codemonkey.io" 10 | } 11 | ], 12 | "require": { 13 | "php": ">=5.4.0" 14 | }, 15 | "require-dev": { 16 | "phpunit/phpunit": "~4.6" 17 | }, 18 | "autoload": { 19 | "psr-4": { 20 | "Alexa\\" : "src/" 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "af9c255a6dfaa5bf42c87ba353945448", 8 | "packages": [], 9 | "packages-dev": [ 10 | { 11 | "name": "doctrine/instantiator", 12 | "version": "1.0.5", 13 | "source": { 14 | "type": "git", 15 | "url": "https://github.com/doctrine/instantiator.git", 16 | "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" 17 | }, 18 | "dist": { 19 | "type": "zip", 20 | "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", 21 | "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", 22 | "shasum": "" 23 | }, 24 | "require": { 25 | "php": ">=5.3,<8.0-DEV" 26 | }, 27 | "require-dev": { 28 | "athletic/athletic": "~0.1.8", 29 | "ext-pdo": "*", 30 | "ext-phar": "*", 31 | "phpunit/phpunit": "~4.0", 32 | "squizlabs/php_codesniffer": "~2.0" 33 | }, 34 | "type": "library", 35 | "extra": { 36 | "branch-alias": { 37 | "dev-master": "1.0.x-dev" 38 | } 39 | }, 40 | "autoload": { 41 | "psr-4": { 42 | "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" 43 | } 44 | }, 45 | "notification-url": "https://packagist.org/downloads/", 46 | "license": [ 47 | "MIT" 48 | ], 49 | "authors": [ 50 | { 51 | "name": "Marco Pivetta", 52 | "email": "ocramius@gmail.com", 53 | "homepage": "http://ocramius.github.com/" 54 | } 55 | ], 56 | "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", 57 | "homepage": "https://github.com/doctrine/instantiator", 58 | "keywords": [ 59 | "constructor", 60 | "instantiate" 61 | ], 62 | "time": "2015-06-14 21:17:01" 63 | }, 64 | { 65 | "name": "phpdocumentor/reflection-docblock", 66 | "version": "2.0.4", 67 | "source": { 68 | "type": "git", 69 | "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", 70 | "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" 71 | }, 72 | "dist": { 73 | "type": "zip", 74 | "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", 75 | "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", 76 | "shasum": "" 77 | }, 78 | "require": { 79 | "php": ">=5.3.3" 80 | }, 81 | "require-dev": { 82 | "phpunit/phpunit": "~4.0" 83 | }, 84 | "suggest": { 85 | "dflydev/markdown": "~1.0", 86 | "erusev/parsedown": "~1.0" 87 | }, 88 | "type": "library", 89 | "extra": { 90 | "branch-alias": { 91 | "dev-master": "2.0.x-dev" 92 | } 93 | }, 94 | "autoload": { 95 | "psr-0": { 96 | "phpDocumentor": [ 97 | "src/" 98 | ] 99 | } 100 | }, 101 | "notification-url": "https://packagist.org/downloads/", 102 | "license": [ 103 | "MIT" 104 | ], 105 | "authors": [ 106 | { 107 | "name": "Mike van Riel", 108 | "email": "mike.vanriel@naenius.com" 109 | } 110 | ], 111 | "time": "2015-02-03 12:10:50" 112 | }, 113 | { 114 | "name": "phpspec/prophecy", 115 | "version": "v1.5.0", 116 | "source": { 117 | "type": "git", 118 | "url": "https://github.com/phpspec/prophecy.git", 119 | "reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7" 120 | }, 121 | "dist": { 122 | "type": "zip", 123 | "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4745ded9307786b730d7a60df5cb5a6c43cf95f7", 124 | "reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7", 125 | "shasum": "" 126 | }, 127 | "require": { 128 | "doctrine/instantiator": "^1.0.2", 129 | "phpdocumentor/reflection-docblock": "~2.0", 130 | "sebastian/comparator": "~1.1" 131 | }, 132 | "require-dev": { 133 | "phpspec/phpspec": "~2.0" 134 | }, 135 | "type": "library", 136 | "extra": { 137 | "branch-alias": { 138 | "dev-master": "1.4.x-dev" 139 | } 140 | }, 141 | "autoload": { 142 | "psr-0": { 143 | "Prophecy\\": "src/" 144 | } 145 | }, 146 | "notification-url": "https://packagist.org/downloads/", 147 | "license": [ 148 | "MIT" 149 | ], 150 | "authors": [ 151 | { 152 | "name": "Konstantin Kudryashov", 153 | "email": "ever.zet@gmail.com", 154 | "homepage": "http://everzet.com" 155 | }, 156 | { 157 | "name": "Marcello Duarte", 158 | "email": "marcello.duarte@gmail.com" 159 | } 160 | ], 161 | "description": "Highly opinionated mocking framework for PHP 5.3+", 162 | "homepage": "https://github.com/phpspec/prophecy", 163 | "keywords": [ 164 | "Double", 165 | "Dummy", 166 | "fake", 167 | "mock", 168 | "spy", 169 | "stub" 170 | ], 171 | "time": "2015-08-13 10:07:40" 172 | }, 173 | { 174 | "name": "phpunit/php-code-coverage", 175 | "version": "2.2.2", 176 | "source": { 177 | "type": "git", 178 | "url": "https://github.com/sebastianbergmann/php-code-coverage.git", 179 | "reference": "2d7c03c0e4e080901b8f33b2897b0577be18a13c" 180 | }, 181 | "dist": { 182 | "type": "zip", 183 | "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2d7c03c0e4e080901b8f33b2897b0577be18a13c", 184 | "reference": "2d7c03c0e4e080901b8f33b2897b0577be18a13c", 185 | "shasum": "" 186 | }, 187 | "require": { 188 | "php": ">=5.3.3", 189 | "phpunit/php-file-iterator": "~1.3", 190 | "phpunit/php-text-template": "~1.2", 191 | "phpunit/php-token-stream": "~1.3", 192 | "sebastian/environment": "^1.3.2", 193 | "sebastian/version": "~1.0" 194 | }, 195 | "require-dev": { 196 | "ext-xdebug": ">=2.1.4", 197 | "phpunit/phpunit": "~4" 198 | }, 199 | "suggest": { 200 | "ext-dom": "*", 201 | "ext-xdebug": ">=2.2.1", 202 | "ext-xmlwriter": "*" 203 | }, 204 | "type": "library", 205 | "extra": { 206 | "branch-alias": { 207 | "dev-master": "2.2.x-dev" 208 | } 209 | }, 210 | "autoload": { 211 | "classmap": [ 212 | "src/" 213 | ] 214 | }, 215 | "notification-url": "https://packagist.org/downloads/", 216 | "license": [ 217 | "BSD-3-Clause" 218 | ], 219 | "authors": [ 220 | { 221 | "name": "Sebastian Bergmann", 222 | "email": "sb@sebastian-bergmann.de", 223 | "role": "lead" 224 | } 225 | ], 226 | "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", 227 | "homepage": "https://github.com/sebastianbergmann/php-code-coverage", 228 | "keywords": [ 229 | "coverage", 230 | "testing", 231 | "xunit" 232 | ], 233 | "time": "2015-08-04 03:42:39" 234 | }, 235 | { 236 | "name": "phpunit/php-file-iterator", 237 | "version": "1.4.1", 238 | "source": { 239 | "type": "git", 240 | "url": "https://github.com/sebastianbergmann/php-file-iterator.git", 241 | "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" 242 | }, 243 | "dist": { 244 | "type": "zip", 245 | "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", 246 | "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", 247 | "shasum": "" 248 | }, 249 | "require": { 250 | "php": ">=5.3.3" 251 | }, 252 | "type": "library", 253 | "extra": { 254 | "branch-alias": { 255 | "dev-master": "1.4.x-dev" 256 | } 257 | }, 258 | "autoload": { 259 | "classmap": [ 260 | "src/" 261 | ] 262 | }, 263 | "notification-url": "https://packagist.org/downloads/", 264 | "license": [ 265 | "BSD-3-Clause" 266 | ], 267 | "authors": [ 268 | { 269 | "name": "Sebastian Bergmann", 270 | "email": "sb@sebastian-bergmann.de", 271 | "role": "lead" 272 | } 273 | ], 274 | "description": "FilterIterator implementation that filters files based on a list of suffixes.", 275 | "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", 276 | "keywords": [ 277 | "filesystem", 278 | "iterator" 279 | ], 280 | "time": "2015-06-21 13:08:43" 281 | }, 282 | { 283 | "name": "phpunit/php-text-template", 284 | "version": "1.2.1", 285 | "source": { 286 | "type": "git", 287 | "url": "https://github.com/sebastianbergmann/php-text-template.git", 288 | "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" 289 | }, 290 | "dist": { 291 | "type": "zip", 292 | "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", 293 | "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", 294 | "shasum": "" 295 | }, 296 | "require": { 297 | "php": ">=5.3.3" 298 | }, 299 | "type": "library", 300 | "autoload": { 301 | "classmap": [ 302 | "src/" 303 | ] 304 | }, 305 | "notification-url": "https://packagist.org/downloads/", 306 | "license": [ 307 | "BSD-3-Clause" 308 | ], 309 | "authors": [ 310 | { 311 | "name": "Sebastian Bergmann", 312 | "email": "sebastian@phpunit.de", 313 | "role": "lead" 314 | } 315 | ], 316 | "description": "Simple template engine.", 317 | "homepage": "https://github.com/sebastianbergmann/php-text-template/", 318 | "keywords": [ 319 | "template" 320 | ], 321 | "time": "2015-06-21 13:50:34" 322 | }, 323 | { 324 | "name": "phpunit/php-timer", 325 | "version": "1.0.7", 326 | "source": { 327 | "type": "git", 328 | "url": "https://github.com/sebastianbergmann/php-timer.git", 329 | "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" 330 | }, 331 | "dist": { 332 | "type": "zip", 333 | "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", 334 | "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", 335 | "shasum": "" 336 | }, 337 | "require": { 338 | "php": ">=5.3.3" 339 | }, 340 | "type": "library", 341 | "autoload": { 342 | "classmap": [ 343 | "src/" 344 | ] 345 | }, 346 | "notification-url": "https://packagist.org/downloads/", 347 | "license": [ 348 | "BSD-3-Clause" 349 | ], 350 | "authors": [ 351 | { 352 | "name": "Sebastian Bergmann", 353 | "email": "sb@sebastian-bergmann.de", 354 | "role": "lead" 355 | } 356 | ], 357 | "description": "Utility class for timing", 358 | "homepage": "https://github.com/sebastianbergmann/php-timer/", 359 | "keywords": [ 360 | "timer" 361 | ], 362 | "time": "2015-06-21 08:01:12" 363 | }, 364 | { 365 | "name": "phpunit/php-token-stream", 366 | "version": "1.4.6", 367 | "source": { 368 | "type": "git", 369 | "url": "https://github.com/sebastianbergmann/php-token-stream.git", 370 | "reference": "3ab72c62e550370a6cd5dc873e1a04ab57562f5b" 371 | }, 372 | "dist": { 373 | "type": "zip", 374 | "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3ab72c62e550370a6cd5dc873e1a04ab57562f5b", 375 | "reference": "3ab72c62e550370a6cd5dc873e1a04ab57562f5b", 376 | "shasum": "" 377 | }, 378 | "require": { 379 | "ext-tokenizer": "*", 380 | "php": ">=5.3.3" 381 | }, 382 | "require-dev": { 383 | "phpunit/phpunit": "~4.2" 384 | }, 385 | "type": "library", 386 | "extra": { 387 | "branch-alias": { 388 | "dev-master": "1.4-dev" 389 | } 390 | }, 391 | "autoload": { 392 | "classmap": [ 393 | "src/" 394 | ] 395 | }, 396 | "notification-url": "https://packagist.org/downloads/", 397 | "license": [ 398 | "BSD-3-Clause" 399 | ], 400 | "authors": [ 401 | { 402 | "name": "Sebastian Bergmann", 403 | "email": "sebastian@phpunit.de" 404 | } 405 | ], 406 | "description": "Wrapper around PHP's tokenizer extension.", 407 | "homepage": "https://github.com/sebastianbergmann/php-token-stream/", 408 | "keywords": [ 409 | "tokenizer" 410 | ], 411 | "time": "2015-08-16 08:51:00" 412 | }, 413 | { 414 | "name": "phpunit/phpunit", 415 | "version": "4.8.6", 416 | "source": { 417 | "type": "git", 418 | "url": "https://github.com/sebastianbergmann/phpunit.git", 419 | "reference": "2246830f4a1a551c67933e4171bf2126dc29d357" 420 | }, 421 | "dist": { 422 | "type": "zip", 423 | "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2246830f4a1a551c67933e4171bf2126dc29d357", 424 | "reference": "2246830f4a1a551c67933e4171bf2126dc29d357", 425 | "shasum": "" 426 | }, 427 | "require": { 428 | "ext-dom": "*", 429 | "ext-json": "*", 430 | "ext-pcre": "*", 431 | "ext-reflection": "*", 432 | "ext-spl": "*", 433 | "php": ">=5.3.3", 434 | "phpspec/prophecy": "^1.3.1", 435 | "phpunit/php-code-coverage": "~2.1", 436 | "phpunit/php-file-iterator": "~1.4", 437 | "phpunit/php-text-template": "~1.2", 438 | "phpunit/php-timer": ">=1.0.6", 439 | "phpunit/phpunit-mock-objects": "~2.3", 440 | "sebastian/comparator": "~1.1", 441 | "sebastian/diff": "~1.2", 442 | "sebastian/environment": "~1.3", 443 | "sebastian/exporter": "~1.2", 444 | "sebastian/global-state": "~1.0", 445 | "sebastian/version": "~1.0", 446 | "symfony/yaml": "~2.1|~3.0" 447 | }, 448 | "suggest": { 449 | "phpunit/php-invoker": "~1.1" 450 | }, 451 | "bin": [ 452 | "phpunit" 453 | ], 454 | "type": "library", 455 | "extra": { 456 | "branch-alias": { 457 | "dev-master": "4.8.x-dev" 458 | } 459 | }, 460 | "autoload": { 461 | "classmap": [ 462 | "src/" 463 | ] 464 | }, 465 | "notification-url": "https://packagist.org/downloads/", 466 | "license": [ 467 | "BSD-3-Clause" 468 | ], 469 | "authors": [ 470 | { 471 | "name": "Sebastian Bergmann", 472 | "email": "sebastian@phpunit.de", 473 | "role": "lead" 474 | } 475 | ], 476 | "description": "The PHP Unit Testing framework.", 477 | "homepage": "https://phpunit.de/", 478 | "keywords": [ 479 | "phpunit", 480 | "testing", 481 | "xunit" 482 | ], 483 | "time": "2015-08-24 04:09:38" 484 | }, 485 | { 486 | "name": "phpunit/phpunit-mock-objects", 487 | "version": "2.3.7", 488 | "source": { 489 | "type": "git", 490 | "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", 491 | "reference": "5e2645ad49d196e020b85598d7c97e482725786a" 492 | }, 493 | "dist": { 494 | "type": "zip", 495 | "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/5e2645ad49d196e020b85598d7c97e482725786a", 496 | "reference": "5e2645ad49d196e020b85598d7c97e482725786a", 497 | "shasum": "" 498 | }, 499 | "require": { 500 | "doctrine/instantiator": "^1.0.2", 501 | "php": ">=5.3.3", 502 | "phpunit/php-text-template": "~1.2", 503 | "sebastian/exporter": "~1.2" 504 | }, 505 | "require-dev": { 506 | "phpunit/phpunit": "~4.4" 507 | }, 508 | "suggest": { 509 | "ext-soap": "*" 510 | }, 511 | "type": "library", 512 | "extra": { 513 | "branch-alias": { 514 | "dev-master": "2.3.x-dev" 515 | } 516 | }, 517 | "autoload": { 518 | "classmap": [ 519 | "src/" 520 | ] 521 | }, 522 | "notification-url": "https://packagist.org/downloads/", 523 | "license": [ 524 | "BSD-3-Clause" 525 | ], 526 | "authors": [ 527 | { 528 | "name": "Sebastian Bergmann", 529 | "email": "sb@sebastian-bergmann.de", 530 | "role": "lead" 531 | } 532 | ], 533 | "description": "Mock Object library for PHPUnit", 534 | "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", 535 | "keywords": [ 536 | "mock", 537 | "xunit" 538 | ], 539 | "time": "2015-08-19 09:14:08" 540 | }, 541 | { 542 | "name": "sebastian/comparator", 543 | "version": "1.2.0", 544 | "source": { 545 | "type": "git", 546 | "url": "https://github.com/sebastianbergmann/comparator.git", 547 | "reference": "937efb279bd37a375bcadf584dec0726f84dbf22" 548 | }, 549 | "dist": { 550 | "type": "zip", 551 | "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22", 552 | "reference": "937efb279bd37a375bcadf584dec0726f84dbf22", 553 | "shasum": "" 554 | }, 555 | "require": { 556 | "php": ">=5.3.3", 557 | "sebastian/diff": "~1.2", 558 | "sebastian/exporter": "~1.2" 559 | }, 560 | "require-dev": { 561 | "phpunit/phpunit": "~4.4" 562 | }, 563 | "type": "library", 564 | "extra": { 565 | "branch-alias": { 566 | "dev-master": "1.2.x-dev" 567 | } 568 | }, 569 | "autoload": { 570 | "classmap": [ 571 | "src/" 572 | ] 573 | }, 574 | "notification-url": "https://packagist.org/downloads/", 575 | "license": [ 576 | "BSD-3-Clause" 577 | ], 578 | "authors": [ 579 | { 580 | "name": "Jeff Welch", 581 | "email": "whatthejeff@gmail.com" 582 | }, 583 | { 584 | "name": "Volker Dusch", 585 | "email": "github@wallbash.com" 586 | }, 587 | { 588 | "name": "Bernhard Schussek", 589 | "email": "bschussek@2bepublished.at" 590 | }, 591 | { 592 | "name": "Sebastian Bergmann", 593 | "email": "sebastian@phpunit.de" 594 | } 595 | ], 596 | "description": "Provides the functionality to compare PHP values for equality", 597 | "homepage": "http://www.github.com/sebastianbergmann/comparator", 598 | "keywords": [ 599 | "comparator", 600 | "compare", 601 | "equality" 602 | ], 603 | "time": "2015-07-26 15:48:44" 604 | }, 605 | { 606 | "name": "sebastian/diff", 607 | "version": "1.3.0", 608 | "source": { 609 | "type": "git", 610 | "url": "https://github.com/sebastianbergmann/diff.git", 611 | "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" 612 | }, 613 | "dist": { 614 | "type": "zip", 615 | "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", 616 | "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", 617 | "shasum": "" 618 | }, 619 | "require": { 620 | "php": ">=5.3.3" 621 | }, 622 | "require-dev": { 623 | "phpunit/phpunit": "~4.2" 624 | }, 625 | "type": "library", 626 | "extra": { 627 | "branch-alias": { 628 | "dev-master": "1.3-dev" 629 | } 630 | }, 631 | "autoload": { 632 | "classmap": [ 633 | "src/" 634 | ] 635 | }, 636 | "notification-url": "https://packagist.org/downloads/", 637 | "license": [ 638 | "BSD-3-Clause" 639 | ], 640 | "authors": [ 641 | { 642 | "name": "Kore Nordmann", 643 | "email": "mail@kore-nordmann.de" 644 | }, 645 | { 646 | "name": "Sebastian Bergmann", 647 | "email": "sebastian@phpunit.de" 648 | } 649 | ], 650 | "description": "Diff implementation", 651 | "homepage": "http://www.github.com/sebastianbergmann/diff", 652 | "keywords": [ 653 | "diff" 654 | ], 655 | "time": "2015-02-22 15:13:53" 656 | }, 657 | { 658 | "name": "sebastian/environment", 659 | "version": "1.3.2", 660 | "source": { 661 | "type": "git", 662 | "url": "https://github.com/sebastianbergmann/environment.git", 663 | "reference": "6324c907ce7a52478eeeaede764f48733ef5ae44" 664 | }, 665 | "dist": { 666 | "type": "zip", 667 | "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6324c907ce7a52478eeeaede764f48733ef5ae44", 668 | "reference": "6324c907ce7a52478eeeaede764f48733ef5ae44", 669 | "shasum": "" 670 | }, 671 | "require": { 672 | "php": ">=5.3.3" 673 | }, 674 | "require-dev": { 675 | "phpunit/phpunit": "~4.4" 676 | }, 677 | "type": "library", 678 | "extra": { 679 | "branch-alias": { 680 | "dev-master": "1.3.x-dev" 681 | } 682 | }, 683 | "autoload": { 684 | "classmap": [ 685 | "src/" 686 | ] 687 | }, 688 | "notification-url": "https://packagist.org/downloads/", 689 | "license": [ 690 | "BSD-3-Clause" 691 | ], 692 | "authors": [ 693 | { 694 | "name": "Sebastian Bergmann", 695 | "email": "sebastian@phpunit.de" 696 | } 697 | ], 698 | "description": "Provides functionality to handle HHVM/PHP environments", 699 | "homepage": "http://www.github.com/sebastianbergmann/environment", 700 | "keywords": [ 701 | "Xdebug", 702 | "environment", 703 | "hhvm" 704 | ], 705 | "time": "2015-08-03 06:14:51" 706 | }, 707 | { 708 | "name": "sebastian/exporter", 709 | "version": "1.2.1", 710 | "source": { 711 | "type": "git", 712 | "url": "https://github.com/sebastianbergmann/exporter.git", 713 | "reference": "7ae5513327cb536431847bcc0c10edba2701064e" 714 | }, 715 | "dist": { 716 | "type": "zip", 717 | "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e", 718 | "reference": "7ae5513327cb536431847bcc0c10edba2701064e", 719 | "shasum": "" 720 | }, 721 | "require": { 722 | "php": ">=5.3.3", 723 | "sebastian/recursion-context": "~1.0" 724 | }, 725 | "require-dev": { 726 | "phpunit/phpunit": "~4.4" 727 | }, 728 | "type": "library", 729 | "extra": { 730 | "branch-alias": { 731 | "dev-master": "1.2.x-dev" 732 | } 733 | }, 734 | "autoload": { 735 | "classmap": [ 736 | "src/" 737 | ] 738 | }, 739 | "notification-url": "https://packagist.org/downloads/", 740 | "license": [ 741 | "BSD-3-Clause" 742 | ], 743 | "authors": [ 744 | { 745 | "name": "Jeff Welch", 746 | "email": "whatthejeff@gmail.com" 747 | }, 748 | { 749 | "name": "Volker Dusch", 750 | "email": "github@wallbash.com" 751 | }, 752 | { 753 | "name": "Bernhard Schussek", 754 | "email": "bschussek@2bepublished.at" 755 | }, 756 | { 757 | "name": "Sebastian Bergmann", 758 | "email": "sebastian@phpunit.de" 759 | }, 760 | { 761 | "name": "Adam Harvey", 762 | "email": "aharvey@php.net" 763 | } 764 | ], 765 | "description": "Provides the functionality to export PHP variables for visualization", 766 | "homepage": "http://www.github.com/sebastianbergmann/exporter", 767 | "keywords": [ 768 | "export", 769 | "exporter" 770 | ], 771 | "time": "2015-06-21 07:55:53" 772 | }, 773 | { 774 | "name": "sebastian/global-state", 775 | "version": "1.0.0", 776 | "source": { 777 | "type": "git", 778 | "url": "https://github.com/sebastianbergmann/global-state.git", 779 | "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" 780 | }, 781 | "dist": { 782 | "type": "zip", 783 | "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", 784 | "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", 785 | "shasum": "" 786 | }, 787 | "require": { 788 | "php": ">=5.3.3" 789 | }, 790 | "require-dev": { 791 | "phpunit/phpunit": "~4.2" 792 | }, 793 | "suggest": { 794 | "ext-uopz": "*" 795 | }, 796 | "type": "library", 797 | "extra": { 798 | "branch-alias": { 799 | "dev-master": "1.0-dev" 800 | } 801 | }, 802 | "autoload": { 803 | "classmap": [ 804 | "src/" 805 | ] 806 | }, 807 | "notification-url": "https://packagist.org/downloads/", 808 | "license": [ 809 | "BSD-3-Clause" 810 | ], 811 | "authors": [ 812 | { 813 | "name": "Sebastian Bergmann", 814 | "email": "sebastian@phpunit.de" 815 | } 816 | ], 817 | "description": "Snapshotting of global state", 818 | "homepage": "http://www.github.com/sebastianbergmann/global-state", 819 | "keywords": [ 820 | "global state" 821 | ], 822 | "time": "2014-10-06 09:23:50" 823 | }, 824 | { 825 | "name": "sebastian/recursion-context", 826 | "version": "1.0.1", 827 | "source": { 828 | "type": "git", 829 | "url": "https://github.com/sebastianbergmann/recursion-context.git", 830 | "reference": "994d4a811bafe801fb06dccbee797863ba2792ba" 831 | }, 832 | "dist": { 833 | "type": "zip", 834 | "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/994d4a811bafe801fb06dccbee797863ba2792ba", 835 | "reference": "994d4a811bafe801fb06dccbee797863ba2792ba", 836 | "shasum": "" 837 | }, 838 | "require": { 839 | "php": ">=5.3.3" 840 | }, 841 | "require-dev": { 842 | "phpunit/phpunit": "~4.4" 843 | }, 844 | "type": "library", 845 | "extra": { 846 | "branch-alias": { 847 | "dev-master": "1.0.x-dev" 848 | } 849 | }, 850 | "autoload": { 851 | "classmap": [ 852 | "src/" 853 | ] 854 | }, 855 | "notification-url": "https://packagist.org/downloads/", 856 | "license": [ 857 | "BSD-3-Clause" 858 | ], 859 | "authors": [ 860 | { 861 | "name": "Jeff Welch", 862 | "email": "whatthejeff@gmail.com" 863 | }, 864 | { 865 | "name": "Sebastian Bergmann", 866 | "email": "sebastian@phpunit.de" 867 | }, 868 | { 869 | "name": "Adam Harvey", 870 | "email": "aharvey@php.net" 871 | } 872 | ], 873 | "description": "Provides functionality to recursively process PHP variables", 874 | "homepage": "http://www.github.com/sebastianbergmann/recursion-context", 875 | "time": "2015-06-21 08:04:50" 876 | }, 877 | { 878 | "name": "sebastian/version", 879 | "version": "1.0.6", 880 | "source": { 881 | "type": "git", 882 | "url": "https://github.com/sebastianbergmann/version.git", 883 | "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" 884 | }, 885 | "dist": { 886 | "type": "zip", 887 | "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", 888 | "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", 889 | "shasum": "" 890 | }, 891 | "type": "library", 892 | "autoload": { 893 | "classmap": [ 894 | "src/" 895 | ] 896 | }, 897 | "notification-url": "https://packagist.org/downloads/", 898 | "license": [ 899 | "BSD-3-Clause" 900 | ], 901 | "authors": [ 902 | { 903 | "name": "Sebastian Bergmann", 904 | "email": "sebastian@phpunit.de", 905 | "role": "lead" 906 | } 907 | ], 908 | "description": "Library that helps with managing the version number of Git-hosted PHP projects", 909 | "homepage": "https://github.com/sebastianbergmann/version", 910 | "time": "2015-06-21 13:59:46" 911 | }, 912 | { 913 | "name": "symfony/yaml", 914 | "version": "v2.7.3", 915 | "source": { 916 | "type": "git", 917 | "url": "https://github.com/symfony/Yaml.git", 918 | "reference": "71340e996171474a53f3d29111d046be4ad8a0ff" 919 | }, 920 | "dist": { 921 | "type": "zip", 922 | "url": "https://api.github.com/repos/symfony/Yaml/zipball/71340e996171474a53f3d29111d046be4ad8a0ff", 923 | "reference": "71340e996171474a53f3d29111d046be4ad8a0ff", 924 | "shasum": "" 925 | }, 926 | "require": { 927 | "php": ">=5.3.9" 928 | }, 929 | "require-dev": { 930 | "symfony/phpunit-bridge": "~2.7" 931 | }, 932 | "type": "library", 933 | "extra": { 934 | "branch-alias": { 935 | "dev-master": "2.7-dev" 936 | } 937 | }, 938 | "autoload": { 939 | "psr-4": { 940 | "Symfony\\Component\\Yaml\\": "" 941 | } 942 | }, 943 | "notification-url": "https://packagist.org/downloads/", 944 | "license": [ 945 | "MIT" 946 | ], 947 | "authors": [ 948 | { 949 | "name": "Fabien Potencier", 950 | "email": "fabien@symfony.com" 951 | }, 952 | { 953 | "name": "Symfony Community", 954 | "homepage": "https://symfony.com/contributors" 955 | } 956 | ], 957 | "description": "Symfony Yaml Component", 958 | "homepage": "https://symfony.com", 959 | "time": "2015-07-28 14:07:07" 960 | } 961 | ], 962 | "aliases": [], 963 | "minimum-stability": "stable", 964 | "stability-flags": [], 965 | "prefer-stable": false, 966 | "prefer-lowest": false, 967 | "platform": { 968 | "php": ">=5.4.0" 969 | }, 970 | "platform-dev": [] 971 | } 972 | -------------------------------------------------------------------------------- /src/Request/IntentRequest.php: -------------------------------------------------------------------------------- 1 | intentName = $data['request']['intent']['name']; 13 | 14 | if (isset($data['request']['intent']['slots'])) { 15 | foreach ($data['request']['intent']['slots'] as $slot) { 16 | if (isset($slot['value'])) { 17 | $this->slots[$slot['name']] = $slot['value']; 18 | } 19 | } 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/Request/LaunchRequest.php: -------------------------------------------------------------------------------- 1 | applicationId = $data['session']['application']['applicationId']; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Request/Request.php: -------------------------------------------------------------------------------- 1 | requestId = $data['request']['requestId']; 19 | $this->timestamp = new DateTime($data['request']['timestamp']); 20 | $this->user = new User($data['session']['user']); 21 | $this->locale = $data['request']['locale']; 22 | } 23 | 24 | public static function fromData($data) { 25 | $requestType = $data['request']['type']; 26 | 27 | if (!class_exists('\\Alexa\\Request\\' . $requestType)) { 28 | throw new RuntimeException('Unknown request type: ' . $requestType); 29 | } 30 | 31 | $className = '\\Alexa\\Request\\' . $requestType; 32 | 33 | $request = new $className($data); 34 | return $request; 35 | } 36 | 37 | public function validate() { 38 | $this->validateTimestamp(); 39 | } 40 | 41 | private function validateTimestamp() { 42 | $now = new DateTime; 43 | $differenceInSeconds = $now->getTimestamp() - $this->timestamp->getTimestamp(); 44 | 45 | if ($differenceInSeconds > self::TIMESTAMP_VALID_TOLERANCE_SECONDS) { 46 | throw new InvalidArgumentException('Request timestamp was too old. Possible replay attack.'); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Request/SessionEndedRequest.php: -------------------------------------------------------------------------------- 1 | reason = $data['request']['reason']; 12 | } 13 | } -------------------------------------------------------------------------------- /src/Request/User.php: -------------------------------------------------------------------------------- 1 | userId = isset($data['userId']) ? $data['userId'] : null; 11 | $this->accessToken = isset($data['accessToken']) ? $data['accessToken'] : null; 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /src/Response/Card/AbstractCard.php: -------------------------------------------------------------------------------- 1 | type; 17 | } 18 | 19 | /** 20 | * @param string $type 21 | */ 22 | public function setType($type) 23 | { 24 | $this->type = $type; 25 | } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getTitle() 31 | { 32 | return $this->title; 33 | } 34 | 35 | /** 36 | * @param string $title 37 | */ 38 | public function setTitle($title) 39 | { 40 | $this->title = $title; 41 | } 42 | 43 | /** 44 | * @return string 45 | */ 46 | public function getContent() 47 | { 48 | return $this->content; 49 | } 50 | 51 | /** 52 | * @param string $content 53 | */ 54 | public function setContent($content) 55 | { 56 | $this->content = $content; 57 | } 58 | 59 | public function render() { 60 | return [ 61 | 'type' => $this->type, 62 | 'title' => $this->title, 63 | 'content' => $this->content, 64 | ]; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/Response/Card/LinkAccountCard.php: -------------------------------------------------------------------------------- 1 | type = 'LinkAccount'; 9 | } 10 | 11 | public function render() { 12 | return [ 13 | 'type' => $this->getType(), 14 | ]; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/Response/Card/SimpleCard.php: -------------------------------------------------------------------------------- 1 | type = 'Standard'; 14 | } 15 | 16 | /** 17 | * @return string 18 | */ 19 | public function getSmallImageUrl() 20 | { 21 | return $this->smallImageUrl; 22 | } 23 | 24 | /** 25 | * @param string $smallImageUrl 26 | */ 27 | public function setSmallImageUrl($smallImageUrl) 28 | { 29 | $this->smallImageUrl = $smallImageUrl; 30 | } 31 | 32 | /** 33 | * @return string 34 | */ 35 | public function getLargeImageUrl() 36 | { 37 | return $this->largeImageUrl; 38 | } 39 | 40 | /** 41 | * @param string $largeImageUrl 42 | */ 43 | public function setLargeImageUrl($largeImageUrl) 44 | { 45 | $this->largeImageUrl = $largeImageUrl; 46 | } 47 | 48 | /** 49 | * @return string 50 | */ 51 | public function getText() 52 | { 53 | return $this->text; 54 | } 55 | 56 | /** 57 | * @param string $text 58 | */ 59 | public function setText($text) 60 | { 61 | $this->text = $text; 62 | } 63 | 64 | public function render() { 65 | return [ 66 | 'type' => $this->getType(), 67 | 'title' => $this->getTitle(), 68 | 'text' => $this->getText(), 69 | 'image' => [ 70 | 'smallImageUrl' => $this->getSmallImageUrl(), 71 | 'largeImageUrl' => $this->getLargeImageUrl() 72 | ] 73 | ]; 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /src/Response/OutputSpeech.php: -------------------------------------------------------------------------------- 1 | $this->type, 12 | 'text' => $this->text 13 | ]; 14 | } 15 | } -------------------------------------------------------------------------------- /src/Response/Reprompt.php: -------------------------------------------------------------------------------- 1 | outputSpeech = new OutputSpeech; 10 | } 11 | 12 | public function render() { 13 | return [ 14 | 'outputSpeech' => $this->outputSpeech->render() 15 | ]; 16 | } 17 | } -------------------------------------------------------------------------------- /src/Response/Response.php: -------------------------------------------------------------------------------- 1 | outputSpeech = new OutputSpeech; 20 | } 21 | 22 | public function respond($text) { 23 | $this->outputSpeech = new OutputSpeech; 24 | $this->outputSpeech->text = $text; 25 | 26 | return $this; 27 | } 28 | 29 | public function reprompt($text) { 30 | $this->reprompt = new Reprompt; 31 | $this->reprompt->outputSpeech->text = $text; 32 | 33 | return $this; 34 | } 35 | 36 | public function withCard($title, $content = '') { 37 | $this->card = new SimpleCard; 38 | $this->card->title = $title; 39 | $this->card->content = $content; 40 | 41 | return $this; 42 | } 43 | 44 | /** 45 | * @see https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/providing-home-cards-for-the-amazon-alexa-app#creating-a-home-card-to-display-text-and-an-image 46 | */ 47 | public function withImageCard($title, $text = '', $smallImageUrl, $largeImageUrl) { 48 | $this->card = new StandardCard(); 49 | $this->card->setTitle($title); 50 | $this->card->setText($text); 51 | $this->card->setSmallImageUrl($smallImageUrl); 52 | $this->card->setLargeImageUrl($largeImageUrl); 53 | 54 | return $this; 55 | } 56 | 57 | public function withLinkAccountCard() { 58 | $this->card = new LinkAccountCard(); 59 | 60 | return $this; 61 | } 62 | 63 | public function endSession($shouldEndSession = true) { 64 | $this->shouldEndSession = $shouldEndSession; 65 | 66 | return $this; 67 | } 68 | 69 | public function render() { 70 | return [ 71 | 'version' => $this->version, 72 | 'sessionAttributes' => $this->sessionAttributes, 73 | 'response' => [ 74 | 'outputSpeech' => $this->outputSpeech ? $this->outputSpeech->render() : null, 75 | 'card' => $this->card ? $this->card->render() : null, 76 | 'reprompt' => $this->reprompt ? $this->reprompt->render() : null, 77 | 'shouldEndSession' => $this->shouldEndSession ? true : false 78 | ] 79 | ]; 80 | } 81 | } --------------------------------------------------------------------------------