【问题标题】:Alexa: including a card in the skills responseAlexa:在技能响应中包含一张卡片
【发布时间】:2018-04-20 11:55:43
【问题描述】:

如果用户正在使用回声点,我想显示旅行信息。例如,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];
    }
  }

【问题讨论】:

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


    【解决方案1】:

    :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');
    

    【讨论】:

      猜你喜欢
      • 2020-11-15
      • 2019-01-23
      • 1970-01-01
      • 1970-01-01
      • 2018-05-12
      • 1970-01-01
      • 1970-01-01
      • 2020-07-23
      • 1970-01-01
      相关资源
      最近更新 更多