Open6

Alexaスキル開発入門メモ

どんぎどんぎ

入門サイト

公式のトレーニングページ

https://developer.amazon.com/ja-JP/alexa/alexa-skills-kit/get-deeper/tutorials-code-samples/build-a-skill

はじめてのAlexaスキル開発

https://alexa-skills-kit-python-sdk.readthedocs.io/ja/latest/DEVELOPING_YOUR_FIRST_SKILL.html

pythonでのHow toが載っている。

  • ハンドラークラス
  • デコレータ

それぞれを使った実装方法と、各ハンドラーの意味合いが端的にまとめられていてわかりやすい

どんぎどんぎ

任意文字列のスロットを作りたい

https://note.com/torusnote/n/n77896a394177

公式には提供されていないようなので、カスタムスロットの
「サンプルにそれっぽいものがなかったら、生リテラルをそのまま突っ込む」
仕様を利用する

どんぎどんぎ

応答の返し方

一番シンプルなもの

from ask_sdk_core.dispatch_components import AbstractRequestHandler
from ask_sdk_core.utils import is_intent_name
from ask_sdk_core.handler_input import HandlerInput
from ask_sdk_model import Response
from ask_sdk_model.ui import SimpleCard
 
 
class HelloWorldIntentHandler(AbstractRequestHandler):
    """ハローワールドインテント用ハンドラー"""
    def can_handle(self, handler_input):
        # type: (HandlerInput) -> bool
        return is_intent_name("HelloWorldIntent")(handler_input)
 
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
 
        speech_text = "これはAlexaが読み上げるテキストです。Alexaアプリを開いてカードを見てください。"
        card_title = "これはカードのタイトルです"
        card_text = “これはカードの内容です。このカードにはプレーンテキストのみ含まれます。\r\nコンテンツが読みやすいように改行を使用して調整します。"
 
        return handler_input.response_builder.speak(speech_text).set_card(
            SimpleCard(card_title, card_text)).response
どんぎどんぎ

ユーザーに再質問して会話をつづける

askを使う

speech_text = ("宇宙博士へようこそ。私は、"
                       "ある惑星からほかの惑星まで旅するのにかかる時間から、宇宙についてのジョークまで、"
                       "宇宙に関するいろいろなことを知っています。何を知りたいですか?")
 
reprompt_text = "宇宙について私に何か聞いてください。"

return handler_input.response_builder.speak(speech_text).ask(
            reprompt_text).response
どんぎどんぎ

カードを表示する

set_cardを使う

speech_text = "これはAlexaが読み上げるテキストです。Alexaアプリを開いてカードを見てください。"
card_title = "これはカードのタイトルです"
card_text = “これはカードの内容です。このカードにはプレーンテキストのみ含まれます。\r\nコンテンツが読みやすいように改行を使用して調整します。"
 
return handler_input.response_builder.speak(speech_text).set_card(
            SimpleCard(card_title, card_text)).response