LoginSignup
0
0

node.jsでalexaスキル その7

Last updated at Posted at 2024-04-18

概要

node.jsでalexaスキル、やってみた。
練習問題やってみた。

練習問題

Alexa-hostedで、ズンドコ、インテントを追加せよ。

方針

「ズンドコ」で、「ズン ドコ キヨシ」

ズンドコ、インテントを追加

  • 対話モデル>インテント>インテントを追加>カスタムインテントを作成
    ZundokoIntent

  • 対話モデル>インテント>インテントを追加>サンプル発話
    " ズンドコ "

  • 対話モデル>インテント>インテントを追加>保存>スキルをビルド

コードを追加

const ZundokoIntentHandler = {
	canHandle(handlerInput) {
		return handlerInput.requestEnvelope.request.type === 'IntentRequest' && handlerInput.requestEnvelope.request.intent.name === 'ZundokoIntent';
	},
	handle(handlerInput) {
		let speechText = '';
		let j = 0;
		while (j < 4)
		{
			if (Math.floor(Math.random() * 2) < 1)
			{
				j++;
				speechText += "ズン ";
			}
			else
			{
				j = 0;
				speechText += "ドコ ";
			}
		}
		speechText += "ドコ キヨシ";
		return handlerInput.responseBuilder.speak(speechText).withSimpleCard('Alexaズンドコ', speechText).getResponse();
	}
};

テスト

image.png

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0