Skip to content

Commit

Permalink
Allows manual override of FB button type to allow buttons such as Cal…
Browse files Browse the repository at this point in the history
…l button (#43)

* Allows override of FB button type to allow buttons such as Call button

* Corrects logic of checking type existing

* Adds tests for addButton type override
  • Loading branch information
sagech authored and stojanovic committed Nov 2, 2016
1 parent 8c5da38 commit 23a47f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/facebook/format-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class Generic extends FacebookTemplate {
return this;
}

addButton(title, value) {
addButton(title, value, type) {
const bubble = this.getLastBubble();

bubble.buttons = bubble.buttons || [];
Expand All @@ -244,6 +244,10 @@ class Generic extends FacebookTemplate {
button.payload = value;
}

if (type) {
button.type = type;
}

bubble.buttons.push(button);

return this;
Expand Down
8 changes: 8 additions & 0 deletions spec/facebook/facebook-format-message-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ describe('Facebook format message', () => {
expect(generic.bubbles[0].buttons[2].payload).toBe('v3');
});

it('should override type when a type parameter is passed', () => {
generic
.addBubble('Test')
.addButton('b1', '+123456789', 'phone_number');

expect(generic.bubbles[0].buttons[0].type).toBe('phone_number');
});

it('should throw an error if you add more than 3 buttons', () => {
generic
.addBubble('Test');
Expand Down

0 comments on commit 23a47f9

Please sign in to comment.