LoginSignup
0
0

node.jsでalexaスキル その6

Posted at

概要

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

練習問題

Alexa-hostedで、じゃんけん、インテントを追加せよ。

方針

  • 「じゃんけんグー」で、「私もグー、あいこだね」

じゃんけん、インテントを追加

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

  • 対話モデル>インテント>インテントを追加>サンプル発話
    " じゃんけんグー "

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

コードを追加

const GuuIntentHandler = {
	canHandle(handlerInput) {
		return handlerInput.requestEnvelope.request.type === 'IntentRequest' && handlerInput.requestEnvelope.request.intent.name === 'GuuIntent';
	},
	handle(handlerInput) {
		const array = ["私もグー、あいこだね", "私はチョキ、くそ、負けた", "私はパー、あんたの負け"]
		const min = Math.ceil(0);
		const max = Math.floor(array.length - 1);
		let randomInt = Math.floor(Math.random() * (max - min) + min);
		const speechText = array[randomInt];
		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