Skip to content

Commit

Permalink
fix: add a default value to subtitle and add validation for subtitle …
Browse files Browse the repository at this point in the history
…type
  • Loading branch information
Gabriel Herzhaft committed Nov 20, 2018
1 parent 1d7103b commit fefdcb2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/botfuel-dialog/src/messages/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Card extends Part {
* @param {Object[]} actions - an array of actions
* @param {Object} [subtitle] - the subtitle (optional)
*/
constructor(title, imageUrl, actions, subtitle) {
constructor(title, imageUrl, actions, subtitle = '') {
super();
this.title = title;
this.imageUrl = imageUrl;
Expand All @@ -40,19 +40,23 @@ class Card extends Part {
/** @inheritDoc */
toJson() {
// TODO : this is very Messenger specific, let's generalize it!
return {
const cardJson = {
title: this.title,
image_url: this.imageUrl,
subtitle: this.subtitle,
buttons: this.actions.map(action => action.toJson())
};
if (this.subtitle !== '') {
cardJson.subtitle = this.subtitle
}
return cardJson
}

/** @inheritDoc */
validate() {
this.validateString('card', this.title);
this.validateUrl('card', this.imageUrl);
this.validateActions('card', this.actions);
this.validateString('card', this.subtitle)
}

/**
Expand Down

0 comments on commit fefdcb2

Please sign in to comment.