Neil
Neil

Reputation: 569

Alexa: including a card in the skills response

I want to display travel information if the user is using an echo spot. E.g $41 is the average daily price for traveling in Vietnam.I am using the tellWithCard command in the TravelCosts function. At the moment "i get The template is not available or currently not supported"

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

Upvotes: 0

Views: 820

Answers (1)

bgsuello
bgsuello

Reputation: 692

Your syntax for :tellWithCard is incorrect.

Base on the alexa-sdk docs, the correct syntax is:

this.emit(':tellWithCard', speechOutput, cardTitle, cardContent, imageObj);

where imageObj is optional.

this.emit(':tellWithCard', getSuggestion(skillData, 'country', countrySlot.toUpperCase()).costs, 'You card title', 'your card content');

Upvotes: 2

Related Questions