Alexa:在技能反应中加入一张牌

时间:2018-04-17 14:14:23

标签: node.js aws-lambda alexa alexa-skills-kit

如果用户正在使用回音点,我想显示旅行信息。例如41美元是在越南旅行的平均每日价格。我在TravelCosts功能中使用tellWithCard命令。目前"我得到模板不可用或目前不支持"

const skillData = [
    {
        country: "FRANCE",
        costs: "$175 is the average daily price for travelling in France. The average price of food for one day is $36. The average price of a hotel for a couple is $206"
    },
    {
        country: "SPAIN",
        costs: "$135 is the average daily price for travelling in Spain. The average price of food for one day is $32. The average price of a hotel for a couple is $118"
    },

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];
    }
  }

1 个答案:

答案 0 :(得分:2)

this.emit(':tellWithCard', speechOutput, cardTitle, cardContent, imageObj); 的语法不正确。

基于alexa-sdk docs,正确的语法是:

imageObj

其中this.emit(':tellWithCard', getSuggestion(skillData, 'country', countrySlot.toUpperCase()).costs, 'You card title', 'your card content'); 是可选的。

DAYS = 7     ; constant representing the number of days in a week
HOURS = 24   ; constant representing the number of hours in a day
MINUTES = 60  ; constant representing the number of minutes in an hour
SECONDS = 60  ; constant representing the number of seconds in a minute

.data

date_time DWORD ? ; byte 0000 stores the DAY, byte 0001 stores the HOUR, 
byte 0002 stores the MINUTE, and byte 0003 stores the SECOND
num_of_iters DWORD 0  ; counts the total number of iterations
day BYTE DAYS   ; used to restore cl to the current day value
hour BYTE HOURS  ; used to restore cl to the current hour value
minute BYTE MINUTES  ; used to restore cl to the current minute value