awsmug/alexa-php-sdk

Amazon Echo (Alexa) PHP SDK

dev-master 2019-01-16 08:59 UTC

This package is not auto-updated.

Last update: 2024-09-18 06:44:40 UTC


README

Build Status Code Climate

这是一个免费的PHP软件开发工具包,用于Amazon Echo。

使用SDK

要使用SDK,只需将alexa-sdk.php文件包含到您的Alexa项目中,并使用您自己的Skill扩展Skill类。

Composer

使用composer添加Alexa PHP SDK。只需将以下内容添加到您的项目中:

{
  "require": {
    "awsmug/alexa-php-sdk": "dev-master"
  }
}

添加composer.json后,使用composer install安装所有包。要在PHP代码中使用SDK,只需像这样包含SDK:

require_once dirname( __FILE__ ) . '/vendor/awsmug/alexa-php-sdk/src/alexa-sdk.php';

简单的技能

这是非常简单的技能的代码。

use Alexa\Skill_Template;
use Alexa\Exception;

class Simple_Skill extends Skill_Template {

	public function intent_request() {
		/**
		 * Put in your answer stuff here!
		 */
		$this->output()->response()->output_speech()->set_text( 'You started the skill!' );
		$this->output()->response()->end_session();
	}
}

$simple_skill = new Simple_Skill( 'YOUR-SKILL-ID' );

try{
	$simple_skill->run();
} catch( Exception $exception) {
	$simple_skill->log( $exception->getMessage() );
	echo $exception->getMessage();
}

使用自动完成

SDK已编程为自动完成功能。如果您使用像PHP Storm这样的IDE,功能将自动完成,您可以通过IDE的自动完成功能发现这些功能。