Skip to content

Commit

Permalink
add tag to generic template and text message
Browse files Browse the repository at this point in the history
  • Loading branch information
radTuti committed Jun 6, 2017
1 parent 303cc32 commit adc7f3a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/client/client.js
Expand Up @@ -79,6 +79,10 @@ export default class Client {
notification_type: notificationType,
};

if (message.tag) {
facebookEnvelope.tag = message.tag;
}

return this.proxyFetchFacebook(`${this.baseURL}/me/messages?access_token=${this.pageAccessToken}`, { body: JSON.stringify(facebookEnvelope) })
.catch((error) => {
log.error(error);
Expand Down
6 changes: 6 additions & 0 deletions src/message/contentTypes/textMessage.js
Expand Up @@ -13,4 +13,10 @@ export default class TextMessage extends Message {
this.state.text = text;
return this;
}

withTag(tag) {
validate.oneOf(tag, ['ISSUE_RESOLUTION'], 'tag', 'TextMessage.withTag');
this.tag = tag;
return this;
}
}
6 changes: 6 additions & 0 deletions src/message/templates/genericTemplate.js
Expand Up @@ -43,4 +43,10 @@ export default class GenericTemplate extends Template {
this.state.attachment.payload.elements.push(element);
return this;
}

withTag(tag) {
validate.oneOf(tag, ['SHIPPING_UPDATE', 'RESERVATION_UPDATE', 'ISSUE_RESOLUTION'], 'tag', 'GenericTemplate.withTag');
this.tag = tag;
return this;
}
}
Expand Up @@ -10,3 +10,14 @@ test('TextMessage.constructor', (expect) => {
}, 'should have the correct structure');
expect.end();
});

test('TextMessage.withTag', (expect) => {
const testTextMsg = new TextMessage('hello, world!').withTag('ISSUE_RESOLUTION');
expect.same(testTextMsg, {
state: {
text: 'hello, world!',
},
tag: 'ISSUE_RESOLUTION',
}, 'should have the correct structure');
expect.end();
});
3 changes: 2 additions & 1 deletion test/message/templates/genericTemplate.test.js
Expand Up @@ -13,7 +13,7 @@ test('GenericTemplate', (expect) => {
.setImageUrl('https//bot.peters-hats.com/img/hats/fez.jpg')
.setDefaultAction(new DefaultAction('http://m.me/petershats?ref=invited_by_24601'))
.addButton(new UrlButton('Take Quiz', 'http://m.me/petershats?ref=invited_by_24601')),
]).addElement(new GenericElement('Additional'));
]).addElement(new GenericElement('Additional')).withTag('SHIPPING_UPDATE');
expect.same(testTemplate, {
state: {
attachment: {
Expand Down Expand Up @@ -46,6 +46,7 @@ test('GenericTemplate', (expect) => {
},
},
},
tag: 'SHIPPING_UPDATE',
}, 'should have the correct structure');
expect.end();
});

0 comments on commit adc7f3a

Please sign in to comment.