こういう人向け
Amazon Alexaスキル開発で初めてNobe.jp 8.10をさわり、
文法やお約束などイマイチ理解できていない方。
左にプログラミング言語、右に日本語翻訳がほしいような方。
//TODO:Replace this data with your own.You can find translations of this data
const data = [
{
"id": 100001,
"name": "IgA",
"price1": 34,
"price2": "333",
"detail": "指定難病に数えられるIgA腎症。"
}
{
"id": 100001,
"name": "IgA",
"price1": 34,
"price2": "333",
"detail": "指定難病に数えられるIgA腎症。"
}
];
//Editing anything below this line might break your skill.
const handlers = {
'LaunchRequest': function () {//起動したとき
const speechOutput="いらっしゃいませ、ようこそ";
this.emit(":ask",speechOutput,HELP_REPROMPT);
},
//ここから重要
'item_cost': function () {
var price1 = 0;
var price2 = 0
var price_result="該当する商品がありませんでした。";
const intent =this.event.request.intent;
const item_name = intent.slots.item_name.value;
for(var d in data ){
if(data[d].name === item_name){
price1 = data[d].price1;
if(data[d].price2 != ""){
price2 = data[d].price2;
price_result = item_name + "の価格は"+price1+"円です。ホールですと"+price2+"円です";
}else{
price_result = item_name + "の価格は"+price1+"円です。";
}
break;
}
}
this.emit(":ask",price_result,HELP_REPROMPT);
},
var price1 = 0;
var price2 = 0
var price_result="該当する商品がありませんでした。";
const intent =this.event.request.intent;
const item_name = intent.slots.item_name.value;
for(var d in data ){
if(data[d].name === item_name){
price1 = data[d].price1;
if(data[d].price2 != ""){
price2 = data[d].price2;
price_result = item_name + "の価格は"+price1+"円です。ホールですと"+price2+"円です";
}else{
price_result = item_name + "の価格は"+price1+"円です。";
}
break;
}
}
this.emit(":ask",price_result,HELP_REPROMPT);
},
//ここまで重要
'AMAZON.HelpIntent': function () {
const speechOutput = HELP_MESSAGE;
const reprompt = HELP_REPROMPT;
this.response.speak(speechOutput).listen(reprompt);
this.emit(':responseReady');
},
'AMAZON.CancelIntent': function () {
this.response.speak(STOP_MESSAGE);
this.emit(':responseReady');
},
'AMAZON.StopIntent': function () {
this.response.speak(STOP_MESSAGE);
this.emit(':responseReady');
},
'Unhandled': function () {
const speechOutput="すみません、まだわからないことが多くて。勉強しておきます。";
this.emit(":ask",speechOutput,HELP_REPROMPT);
},
};
'AMAZON.HelpIntent': function () {
const speechOutput = HELP_MESSAGE;
const reprompt = HELP_REPROMPT;
this.response.speak(speechOutput).listen(reprompt);
this.emit(':responseReady');
},
'AMAZON.CancelIntent': function () {
this.response.speak(STOP_MESSAGE);
this.emit(':responseReady');
},
'AMAZON.StopIntent': function () {
this.response.speak(STOP_MESSAGE);
this.emit(':responseReady');
},
'Unhandled': function () {
const speechOutput="すみません、まだわからないことが多くて。勉強しておきます。";
this.emit(":ask",speechOutput,HELP_REPROMPT);
},
};
まとめ
(1)item_cost :ここの変数名はインテント名になります。
(2)item_name :ここの変数名はインテントスロットの名前になります。
※Alexa Developer Console上でインテントとスロットタイプをしっかり紐づけましょう。
※(2)ですが、スロットタイプ名ではなくインテントスロットの名前です。
ここ間違えやすいので注意。
ここ間違えやすいので注意。
0 件のコメント:
コメントを投稿