all files / lib/ QuickReplies.js

100% Statements 0/0
100% Branches 0/0
100% Functions 0/0
100% Lines 0/0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44                                                                                       
class QuickReply {
  constructor(title, payload) {
    if (title.length > 20) {
      throw new Error('Title cannot be longer 20 characters.');
    }
 
    if (payload.length > 1000) {
      throw new Error('Payload cannot be longer 1000 characters.');
    }
 
    this.title = title;
    this.payload = payload;
 
    return {
      content_type: 'text',
      title: this.title,
      payload: this.payload,
    };
  }
}
 
class QuickReplies {
  constructor(quickReplies = []) {
    if (!Array.isArray(quickReplies)) {
      throw new Error('You must pass an array of QuickReply objects.');
    }
 
    if (quickReplies.length > 10) {
      throw new Error('You cannot have more than 10 quick replies.');
    }
 
    this.quickReplies = quickReplies;
 
    return {
      quick_replies: this.quickReplies,
    };
  }
}
 
export {
  QuickReply,
  QuickReplies,
};