0
votes

I am new to google Dialogflow and trying to add cards in Dialogflow messenger. Below is my code to display the cards on Dialogflow messenger. Please help me out. Cards are not showing up in the messenger. I have created an intent to call the cards as well.

  function welcome(agent) {
    agent.add(`Welcome to my agent!`);
  }
 
  function fallback(agent) {
    agent.add(`I didn't understand`);
    agent.add(`I'm sorry, can you try again?`);
  }

  // // Uncomment and edit to make your own intent handler
  // // uncomment `intentMap.set('your intent name here', yourFunctionHandler);`
  // // below to get this function to be run when a Dialogflow intent is matched
   function cards(agent) {
     agent.add(`This message is from Dialogflow's Cloud Functions for Firebase editor!`);
     agent.add(new Card({
      title: 'Title: this is a card title',
      imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png',
      text: 'This is the body text of a card. You can even use line\n breaks and emoji! ????',
      buttonText: 'This is a button',
      buttonUrl: 'https://assistant.google.com/'
      })
      );}

  // Run the proper function handler based on the matched Dialogflow intent name
  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', cards);
  //intentMap.set('Dialogflow Cards', cards);
  // intentMap.set('your intent name here', googleAssistantHandler);
  agent.handleRequest(intentMap);
});
1

1 Answers

0
votes

Cards are a Google Assistant element and will only show on devices or platforms that support Google Assistant. The web simulator of Dialogflow only supports text based responses.

If you want to see the card response, you should integrate your project with Google Assistant via the integrations tab and test your bot in the Google Assistant simulator or on a real Google Assistant device.