Alexa:在技能响应中包含一张卡片
Alexa: including a card in the skills response
我想在用户使用回声点时显示旅行信息。例如,41 美元是在 Vietnam.I 上午使用 TravelCosts 函数中的 tellWithCard 命令旅行的平均每日价格。目前"i get The template is not available or currently not supported"
const skillData = [
{
country: "FRANCE",
costs: "5 is the average daily price for travelling in France. The average price of food for one day is . The average price of a hotel for a couple is 6"
},
{
country: "SPAIN",
costs: "5 is the average daily price for travelling in Spain. The average price of food for one day is . The average price of a hotel for a couple is 8"
},
var handlers = {
'LaunchRequest': function () {
this.emit(':askWithCard', 'Welcome to Travel Helper. Tell me what country you're going to. I will tell you how much you need on average to spend on food and accommodation. ', 'Tell me what country you are going to and I will tell you much you need on average to spend on food and accommodation', 'Travel Helper Guide', 'What country are you going to? I will tell you much you need on average to spend on food and accommodation');
},
'TravelCosts': function() {
var countrySlot = this.event.request.intent.slots.country.value;
-->this.emit(':tellWithCard', getSuggestion(skillData, 'country', countrySlot.toUpperCase()).costs);
},
'Unhandled': function () {
this.emit(':tell', 'Sorry, I don\'t know what to do');
},
'AMAZON.HelpIntent': function () {
this.emit(':askWithCard', 'Welcome to Travel Helper. Tell me what country your are going to. I will tell you how much you need on average to spend on food and accommodation. ', 'Tell me what country your are going to and I will Tell me the name and I will tell you much you need on average to spend on food and accomodation', 'Travel Helper Guide', 'What country are you going to? I will tell you much you need on average to spend on food and accomodation');
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', "Okay!");
},
'AMAZON.StopIntent': function () {
this.emit(':tell', "Goodbye! and thanks for using Travel Helper");
},
};
exports.handler = function(event, context){
var alexa = Alexa.handler(event, context);
alexa.registerHandlers(handlers);
alexa.execute();
};
function getSuggestion(data, propName, propValue) {
for (var i=0; i < data.length; i++) {
if (data[i][propName] == propValue) {
return data[i];
}
}
您 :tellWithCard
的语法不正确。
基于alexa-sdk docs,正确的语法是:
this.emit(':tellWithCard', speechOutput, cardTitle, cardContent, imageObj);
其中 imageObj
是可选的。
this.emit(':tellWithCard', getSuggestion(skillData, 'country', countrySlot.toUpperCase()).costs, 'You card title', 'your card content');
我想在用户使用回声点时显示旅行信息。例如,41 美元是在 Vietnam.I 上午使用 TravelCosts 函数中的 tellWithCard 命令旅行的平均每日价格。目前"i get The template is not available or currently not supported"
const skillData = [
{
country: "FRANCE",
costs: "5 is the average daily price for travelling in France. The average price of food for one day is . The average price of a hotel for a couple is 6"
},
{
country: "SPAIN",
costs: "5 is the average daily price for travelling in Spain. The average price of food for one day is . The average price of a hotel for a couple is 8"
},
var handlers = {
'LaunchRequest': function () {
this.emit(':askWithCard', 'Welcome to Travel Helper. Tell me what country you're going to. I will tell you how much you need on average to spend on food and accommodation. ', 'Tell me what country you are going to and I will tell you much you need on average to spend on food and accommodation', 'Travel Helper Guide', 'What country are you going to? I will tell you much you need on average to spend on food and accommodation');
},
'TravelCosts': function() {
var countrySlot = this.event.request.intent.slots.country.value;
-->this.emit(':tellWithCard', getSuggestion(skillData, 'country', countrySlot.toUpperCase()).costs);
},
'Unhandled': function () {
this.emit(':tell', 'Sorry, I don\'t know what to do');
},
'AMAZON.HelpIntent': function () {
this.emit(':askWithCard', 'Welcome to Travel Helper. Tell me what country your are going to. I will tell you how much you need on average to spend on food and accommodation. ', 'Tell me what country your are going to and I will Tell me the name and I will tell you much you need on average to spend on food and accomodation', 'Travel Helper Guide', 'What country are you going to? I will tell you much you need on average to spend on food and accomodation');
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', "Okay!");
},
'AMAZON.StopIntent': function () {
this.emit(':tell', "Goodbye! and thanks for using Travel Helper");
},
};
exports.handler = function(event, context){
var alexa = Alexa.handler(event, context);
alexa.registerHandlers(handlers);
alexa.execute();
};
function getSuggestion(data, propName, propValue) {
for (var i=0; i < data.length; i++) {
if (data[i][propName] == propValue) {
return data[i];
}
}
您 :tellWithCard
的语法不正确。
基于alexa-sdk docs,正确的语法是:
this.emit(':tellWithCard', speechOutput, cardTitle, cardContent, imageObj);
其中 imageObj
是可选的。
this.emit(':tellWithCard', getSuggestion(skillData, 'country', countrySlot.toUpperCase()).costs, 'You card title', 'your card content');