elchief84/alexa-php-sdk

Amazon Echo (Alexa) PHP SDK

dev-master 2018-07-16 21:30 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:48:31 UTC


README

Build Status Code Climate

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

使用 SDK

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

Composer

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

{
  "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 的自动补全功能来发现这些函数。