Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support new options for template message images #247

Merged
merged 1 commit into from Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/messaging-api-line/src/Line.js
Expand Up @@ -96,11 +96,17 @@ function createButtonTemplate(
altText: string,
{
thumbnailImageUrl,
imageAspectRatio,
imageSize,
imageBackgroundColor,
title,
text,
actions,
}: {
thumbnailImageUrl?: string,
imageAspectRatio?: 'rectangle' | 'square',
imageSize?: 'cover' | 'contain',
imageBackgroundColor?: string,
title?: string,
text: string,
actions: Array<TemplateAction>,
Expand All @@ -109,6 +115,9 @@ function createButtonTemplate(
return createTemplate(altText, {
type: 'buttons',
thumbnailImageUrl,
imageAspectRatio,
imageSize,
imageBackgroundColor,
title,
text,
actions,
Expand All @@ -132,10 +141,22 @@ function createConfirmTemplate(
});
}

function createCarouselTemplate(altText: string, columns: Array<ColumnObject>) {
function createCarouselTemplate(
altText: string,
columns: Array<ColumnObject>,
{
imageAspectRatio,
imageSize,
}: {
imageAspectRatio?: 'rectangle' | 'square',
imageSize?: 'cover' | 'contain',
}
) {
return createTemplate(altText, {
type: 'carousel',
columns,
imageAspectRatio,
imageSize,
});
}

Expand Down
25 changes: 23 additions & 2 deletions packages/messaging-api-line/src/LineClient.js
Expand Up @@ -183,11 +183,17 @@ export default class LineClient {
altText: string,
{
thumbnailImageUrl,
imageAspectRatio,
imageSize,
imageBackgroundColor,
title,
text,
actions,
}: {
thumbnailImageUrl?: string,
imageAspectRatio?: 'rectangle' | 'square',
imageSize?: 'cover' | 'contain',
imageBackgroundColor?: string,
title?: string,
text: string,
actions: Array<TemplateAction>,
Expand All @@ -196,6 +202,9 @@ export default class LineClient {
this._send(type, target, [
Line.createButtonTemplate(altText, {
thumbnailImageUrl,
imageAspectRatio,
imageSize,
imageBackgroundColor,
title,
text,
actions,
Expand Down Expand Up @@ -225,9 +234,21 @@ export default class LineClient {
type: SendType,
target: SendTarget,
altText: string,
columns: Array<ColumnObject>
columns: Array<ColumnObject>,
{
imageAspectRatio,
imageSize,
}: {
imageAspectRatio?: 'rectangle' | 'square',
imageSize?: 'cover' | 'contain',
}
): Promise<MutationSuccessResponse> =>
this._send(type, target, [Line.createCarouselTemplate(altText, columns)]);
this._send(type, target, [
Line.createCarouselTemplate(altText, columns, {
imageAspectRatio,
imageSize,
}),
]);

_sendImageCarouselTemplate = (
type: SendType,
Expand Down
42 changes: 39 additions & 3 deletions packages/messaging-api-line/src/__tests__/LineClient.spec.js
Expand Up @@ -528,6 +528,9 @@ describe('Reply Message', () => {
template: {
type: 'buttons',
thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',
imageAspectRatio: 'rectangle',
imageSize: 'cover',
imageBackgroundColor: '#FFFFFF',
title: 'Menu',
text: 'Please select',
actions: [
Expand Down Expand Up @@ -558,6 +561,9 @@ describe('Reply Message', () => {
'this is a template',
{
thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',
imageAspectRatio: 'rectangle',
imageSize: 'cover',
imageBackgroundColor: '#FFFFFF',
title: 'Menu',
text: 'Please select',
actions: [
Expand Down Expand Up @@ -657,6 +663,8 @@ describe('Reply Message', () => {
altText: 'this is a carousel template',
template: {
type: 'carousel',
imageAspectRatio: 'rectangle',
imageSize: 'cover',
columns: [
{
thumbnailImageUrl:
Expand Down Expand Up @@ -759,7 +767,11 @@ describe('Reply Message', () => {
},
],
},
]
],
{
imageAspectRatio: 'rectangle',
imageSize: 'cover',
}
);

expect(res).toEqual(reply);
Expand Down Expand Up @@ -1260,6 +1272,9 @@ describe('Push Message', () => {
template: {
type: 'buttons',
thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',
imageAspectRatio: 'rectangle',
imageSize: 'cover',
imageBackgroundColor: '#FFFFFF',
title: 'Menu',
text: 'Please select',
actions: [
Expand Down Expand Up @@ -1290,6 +1305,9 @@ describe('Push Message', () => {
'this is a template',
{
thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',
imageAspectRatio: 'rectangle',
imageSize: 'cover',
imageBackgroundColor: '#FFFFFF',
title: 'Menu',
text: 'Please select',
actions: [
Expand Down Expand Up @@ -1389,6 +1407,8 @@ describe('Push Message', () => {
altText: 'this is a carousel template',
template: {
type: 'carousel',
imageAspectRatio: 'rectangle',
imageSize: 'cover',
columns: [
{
thumbnailImageUrl:
Expand Down Expand Up @@ -1491,7 +1511,11 @@ describe('Push Message', () => {
},
],
},
]
],
{
imageAspectRatio: 'rectangle',
imageSize: 'cover',
}
);

expect(res).toEqual(reply);
Expand Down Expand Up @@ -1995,6 +2019,9 @@ describe('Multicast', () => {
template: {
type: 'buttons',
thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',
imageAspectRatio: 'rectangle',
imageSize: 'cover',
imageBackgroundColor: '#FFFFFF',
title: 'Menu',
text: 'Please select',
actions: [
Expand Down Expand Up @@ -2025,6 +2052,9 @@ describe('Multicast', () => {
'this is a template',
{
thumbnailImageUrl: 'https://example.com/bot/images/image.jpg',
imageAspectRatio: 'rectangle',
imageSize: 'cover',
imageBackgroundColor: '#FFFFFF',
title: 'Menu',
text: 'Please select',
actions: [
Expand Down Expand Up @@ -2124,6 +2154,8 @@ describe('Multicast', () => {
altText: 'this is a carousel template',
template: {
type: 'carousel',
imageAspectRatio: 'rectangle',
imageSize: 'cover',
columns: [
{
thumbnailImageUrl:
Expand Down Expand Up @@ -2226,7 +2258,11 @@ describe('Multicast', () => {
},
],
},
]
],
{
imageAspectRatio: 'rectangle',
imageSize: 'cover',
}
);

expect(res).toEqual(reply);
Expand Down
3 changes: 2 additions & 1 deletion packages/messaging-api-line/src/__tests__/index.spec.js
@@ -1,5 +1,6 @@
import { LineClient } from '../';
import { Line, LineClient } from '../';

it('should export api correctly', () => {
expect(Line).toBeDefined();
expect(LineClient).toBeDefined();
});