-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zhang
committed
Oct 26, 2018
1 parent
4728d42
commit ad2fcec
Showing
13 changed files
with
1,003 additions
and
545 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,163 @@ | ||
==================== | ||
***************** | ||
応答のビルド | ||
==================== | ||
***************** | ||
|
||
標準的な応答 | ||
================= | ||
|
||
Lambdaをスキルのエンドポイントに使用している場合は、Alexaがユーザーリクエストに応答するための応答本文を提供するだけで済みます。応答本文のJSON構造についてのドキュメントは、 `こちら <https://developer.amazon.com/ja/docs/custom-skills/request-and-response-json-reference.html#response-format>`_ を参照してください。 | ||
|
||
応答本文には、次のプロパティが含まれる場合があります: | ||
|
||
* version | ||
* sessionAttributes | ||
* response | ||
|
||
ASK SDK v2 for Node.jsを使用すると、versionとsessionAttributesを入力してくれるので、ボイラープレートコード(毎回書かなければならないお決まりのコード)を書く手間が省けるので、その分応答の作成に集中できます。 | ||
|
||
ResponseBuilder | ||
--------------- | ||
|
||
SDKには応答を作成するためのヘルパー関数が含まれています。\ ``Response``\ には複数の要素が含まれる場合があり、ヘルパー関数によって応答を生成しやすくなり、各応答の要素を初期化したり設定したりする時間を削減できます。 | ||
|
||
**インターフェース** | ||
|
||
.. code:: typescript | ||
interface ResponseBuilder { | ||
speak(speechOutput: string): this; | ||
reprompt(repromptSpeechOutput: string): this; | ||
withSimpleCard(cardTitle: string, cardContent: string): this; | ||
withStandardCard(cardTitle: string, cardContent: string, smallImageUrl?: string, largeImageUrl?: string): this; | ||
withLinkAccountCard(): this; | ||
withAskForPermissionsConsentCard(permissionArray: string[]): this; | ||
addDelegateDirective(updatedIntent?: Intent): this; | ||
addElicitSlotDirective(slotToElicit: string, updatedIntent?: Intent): this; | ||
addConfirmSlotDirective(slotToConfirm: string, updatedIntent?: Intent): this; | ||
addConfirmIntentDirective(updatedIntent?: Intent): this; | ||
addAudioPlayerPlayDirective(playBehavior: interfaces.audioplayer.PlayBehavior, url: string, token: string, offsetInMilliseconds: number, expectedPreviousToken?: string): this; | ||
addAudioPlayerStopDirective(): this; | ||
addAudioPlayerClearQueueDirective(clearBehavior: interfaces.audioplayer.ClearBehavior): this; | ||
addRenderTemplateDirective(template: interfaces.display.Template): this; | ||
addHintDirective(text: string): this; | ||
addVideoAppLaunchDirective(source: string, title?: string, subtitle?: string): this; | ||
withShouldEndSession(val: boolean): this; | ||
addDirective(directive: Directive): this; | ||
getResponse(): Response; | ||
} | ||
以下の例は、ResponseBuilderヘルパー関数を使用して応答を作成する方法を示しています。 | ||
|
||
.. code:: javascript | ||
const handle = function(handlerInput) { | ||
return handlerInput.responseBuilder | ||
.speak('foo') | ||
.reprompt('bar') | ||
.withSimpleCard('title', 'cardText') | ||
.getResponse(); | ||
} | ||
=============== | ||
|
||
``ResponseBuilder`` には応答を作成するためのヘルパーメソッドが含まれています。 ``Response`` には複数の要素が含まれる場合があり、ヘルパーメソッドによって、各応答の要素を初期化したり設定したりする必要がなくなり、応答を生成しやすくなります。 ``ResponseBuilder`` は、 ``HandlerInput`` コンテナオブジェクトからハンドラーで使用できます。 ``ResponseBuilder`` の詳細については、 `TypeDoc <http://ask-sdk-node-typedoc.s3-website-us-east-1.amazonaws.com/classes/responsebuilder.html>`_ を参照してください。 | ||
|
||
利用可能なメソッド | ||
---------------------------------- | ||
|
||
.. code-block:: typescript | ||
speak(speechOutput: string): this; | ||
reprompt(repromptSpeechOutput: string): this; | ||
withSimpleCard(cardTitle: string, cardContent: string): this; | ||
withStandardCard(cardTitle: string, cardContent: string, smallImageUrl?: string, largeImageUrl?: string): this; | ||
withLinkAccountCard(): this; | ||
withAskForPermissionsConsentCard(permissionArray: string[]): this; | ||
addDelegateDirective(updatedIntent?: Intent): this; | ||
addElicitSlotDirective(slotToElicit: string, updatedIntent?: Intent): this; | ||
addConfirmSlotDirective(slotToConfirm: string, updatedIntent?: Intent): this; | ||
addConfirmIntentDirective(updatedIntent?: Intent): this; | ||
addAudioPlayerPlayDirective(playBehavior: interfaces.audioplayer.PlayBehavior, url: string, token: string, offsetInMilliseconds: number, expectedPreviousToken?: string, audioItemMetadata? : AudioItemMetadata): this; | ||
addAudioPlayerStopDirective(): this; | ||
addAudioPlayerClearQueueDirective(clearBehavior: interfaces.audioplayer.ClearBehavior): this; | ||
addRenderTemplateDirective(template: interfaces.display.Template): this; | ||
addHintDirective(text: string): this; | ||
addVideoAppLaunchDirective(source: string, title?: string, subtitle?: string): this; | ||
withShouldEndSession(val: boolean): this; | ||
addDirective(directive: Directive): this; | ||
getResponse(): Response; | ||
次のResponseBuilderメソッドは、 `public beta SDK <https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/tree/2.x_public-beta>`__ でのみ使用できます: | ||
|
||
.. code-block:: typescript | ||
withCanFulfillIntent(canFulfillIntent : CanFulfillIntent) : this; | ||
以下の例は、 ``ResponseBuilder`` ヘルパーメソッドを使用して応答を作成する方法を示しています。 | ||
|
||
.. tabs:: | ||
|
||
.. code-tab:: javascript | ||
|
||
const response = handlerInput.responseBuilder | ||
.speak('foo') | ||
.reprompt('bar') | ||
.withSimpleCard('title', 'cardText') | ||
.getResponse(); | ||
|
||
.. code-tab:: typescript | ||
|
||
const response = handlerInput.responseBuilder | ||
.speak('foo') | ||
.reprompt('bar') | ||
.withSimpleCard('title', 'cardText') | ||
.getResponse(); | ||
|
||
.. note:: | ||
|
||
speakとreprompt値のコンテンツはSSMLタグで囲みます。つまり、値に含まれるXMLの特殊文字はエスケープ処理をする必要があります。たとえば、 ``handlerInput.responseBuilder.speak("I like M&M's")`` では、このままでは失敗します。文字 ``&`` を ``&`` と記述する必要があります。他にも処理が必要な文字は、 ``<`` -> ``<``;、および ``>`` -> ``>`` などがあります。 | ||
|
||
画像とテキストのヘルパー | ||
------------------------------ | ||
============================================ | ||
|
||
ASK SDK v2 for Node.jsは以下のヘルパークラスを提供しています。これらは、Echo Showと互換性のあるスキルで広く使用されるテキストや画像の要素の作成に便利です。 | ||
|
||
ImageHelper | ||
----------- | ||
|
||
.. tabs:: | ||
|
||
.. code-tab:: javascript | ||
|
||
const Alexa = require('ask-sdk-core'); | ||
|
||
const myImage = new Alexa.ImageHelper() | ||
.withDescription('FooDescription') | ||
.addImageInstance('http://BarImageSource') | ||
.getImage(); | ||
|
||
.. code-tab:: typescript | ||
|
||
import { ImageHelper } from 'ask-sdk-core'; | ||
import { interfaces } from 'ask-sdk-model'; | ||
import Image = interfaces.display.Image; | ||
|
||
const myImage : Image = new ImageHelper() | ||
.withDescription('FooDescription') | ||
.addImageInstance('http://BarImageSource') | ||
.getImage(); | ||
|
||
PlainTextContentHelper | ||
---------------------- | ||
|
||
.. tabs:: | ||
|
||
.. code-tab:: javascript | ||
|
||
const Alexa = require('ask-sdk-core'); | ||
|
||
const myTextContent = new Alexa.PlainTextContentHelper() | ||
.withPrimaryText('Foo') | ||
.withSecondaryText('Bar') | ||
.withTertiaryText('Baz') | ||
.getTextContent(); | ||
|
||
ASK SDK v2 for | ||
Node.jsは以下のヘルパークラスを提供しています。これらは、Echo | ||
Showと互換性のあるスキルで広く使用されるテキストや画像の要素の作成に便利です。 | ||
.. code-tab:: typescript | ||
|
||
**``ImageHelper``** | ||
import { PlainTextContentHelper } from 'ask-sdk-core'; | ||
import { interfaces } from 'ask-sdk-model'; | ||
import TextContent = interfaces.display.TextContent; | ||
|
||
.. code:: javascript | ||
const myTextContent : TextContent = new PlainTextContentHelper() | ||
.withPrimaryText('Foo') | ||
.withSecondaryText('Bar') | ||
.withTertiaryText('Baz') | ||
.getTextContent(); | ||
|
||
const Alexa = require('ask-sdk'); | ||
|
||
const myImage = new Alexa.ImageHelper() | ||
.withDescription('FooDescription') | ||
.addImageInstance('http://BarImageSource') | ||
.getImage(); | ||
RichTextContentHelper | ||
--------------------- | ||
|
||
**``PlainTextContentHelper``** | ||
.. tabs:: | ||
|
||
.. code:: javascript | ||
.. code-tab:: javascript | ||
|
||
const Alexa = require('ask-sdk'); | ||
const Alexa = require('ask-sdk-core'); | ||
|
||
const myTextContent = new Alexa.PlainTextContentHelper() | ||
.withPrimaryTexT('Foo') | ||
.withSecondaryText('Bar') | ||
.withTertiaryText('Baz') | ||
.getTextContent(); | ||
const myTextContent = new Alexa.RichTextContentHelper() | ||
.withPrimaryText('Foo') | ||
.withSecondaryText('Bar') | ||
.withTertiaryText('Baz') | ||
.getTextContent(); | ||
|
||
**``RichTextContentHelper``** | ||
.. code-tab:: typescript | ||
|
||
.. code:: javascript | ||
import { RichTextContentHelper } from 'ask-sdk-core'; | ||
import { interfaces } from 'ask-sdk-model'; | ||
import TextContent = interfaces.display.TextContent; | ||
|
||
const Alexa = require('ask-sdk'); | ||
const myTextContent : TextContent = new RichTextContentHelper() | ||
.withPrimaryText('Foo') | ||
.withSecondaryText('Bar') | ||
.withTertiaryText('Baz') | ||
.getTextContent(); | ||
|
||
const myTextContent = new Alexa.RichTextContentHelper() | ||
.withPrimaryTexT('Foo') | ||
.withSecondaryText('Bar') | ||
.withTertiaryText('Baz') | ||
.getTextContent(); |
Oops, something went wrong.