Skip to content

Commit

Permalink
renamed ratio back to image_aspect_ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
chentsulin committed Aug 28, 2017
1 parent 814aead commit 701e717
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 30 deletions.
52 changes: 28 additions & 24 deletions packages/messaging-api-messenger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,40 +353,45 @@ Page-scoped user ID of the recipient or [recipient](https://developers.facebook.

Type: `Array<Object>`

###### ratio
###### options

###### options.image_aspect_ratio

Type: `String`
Value: `horizontal | square`

###### options
Default: `horizontal`

###### options.tag

Type: `String`
Value: `SHIPPING_UPDATE | RESERVATION_UPDATE | ISSUE_RESOLUTION APPOINTMENT_UPDATE | GAME_EVENT | TRANSPORTATION_UPDATE | FEATURE_FUNCTIONALITY_UPDATE | TICKET_UPDATE`

```js
client.sendGenericTemplate(USER_ID, [
{
title: "Welcome to Peter's Hats",
image_url: 'https://petersfancybrownhats.com/company_image.png',
subtitle: "We've got the right hat for everyone.",
default_action: {
type: 'web_url',
url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
messenger_extensions: true,
webview_height_ratio: 'tall',
fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
},
buttons: [
{
type: 'postback',
title: 'Start Chatting',
payload: 'DEVELOPER_DEFINED_PAYLOAD',
client.sendGenericTemplate(
USER_ID,
[
{
title: "Welcome to Peter's Hats",
image_url: 'https://petersfancybrownhats.com/company_image.png',
subtitle: "We've got the right hat for everyone.",
default_action: {
type: 'web_url',
url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
messenger_extensions: true,
webview_height_ratio: 'tall',
fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
},
],
},
]);
buttons: [
{
type: 'postback',
title: 'Start Chatting',
payload: 'DEVELOPER_DEFINED_PAYLOAD',
},
],
},
],
{ image_aspect_ratio: 'square' }
);
```

Adding a [tag](https://developers.facebook.com/docs/messenger-platform/message-tags) to a message allows you to send it outside the 24+1 window, for a limited number of use cases, per [Messenger Platform policy](https://developers.facebook.com/docs/messenger-platform/policy-overview).
Expand All @@ -399,7 +404,6 @@ client.sendGenericTemplate(
// ...
},
],
'square',
{ tag: 'ISSUE_RESOLUTION' }
);
```
Expand Down
3 changes: 2 additions & 1 deletion packages/messaging-api-messenger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"axios": "^0.16.1",
"form-data": "^2.2.0",
"invariant": "^2.2.2"
"invariant": "^2.2.2",
"lodash.omit": "^4.5.0"
}
}
11 changes: 7 additions & 4 deletions packages/messaging-api-messenger/src/MessengerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import querystring from 'querystring';
import axios from 'axios';
import FormData from 'form-data';
import invariant from 'invariant';
import omit from 'lodash.omit';

import type {
UserID,
Expand Down Expand Up @@ -516,17 +517,19 @@ export default class MessengerClient {
sendGenericTemplate = (
recipient: UserID | Recipient,
elements: Array<TemplateElement>,
ratio: string = 'horizontal',
options?: SendOption
options?: {
...SendOption,
image_aspect_ratio?: 'horizontal' | 'square',
} = {}
): Promise<SendMessageSucessResponse> =>
this.sendTemplate(
recipient,
{
template_type: 'generic',
elements,
image_aspect_ratio: ratio, // FIXME rename to image_aspect_ratio?
image_aspect_ratio: options.image_aspect_ratio || 'horizontal',
},
options
omit(options, ['image_aspect_ratio'])
);

// https://developers.facebook.com/docs/messenger-platform/send-api-reference/list-template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,41 @@ describe('send api', () => {
expect(res).toEqual(reply);
});

it('can use square generic template', async () => {
const { client, mock } = createMock();

const reply = {
recipient_id: RECIPIENT_ID,
message_id: 'mid.1489394984387:3dd22de509',
};

mock
.onPost(`/me/messages?access_token=${ACCESS_TOKEN}`, {
recipient: {
id: RECIPIENT_ID,
},
message: {
attachment: {
type: 'template',
payload: {
template_type: 'generic',
elements: templateElements,
image_aspect_ratio: 'square',
},
},
},
})
.reply(200, reply);

const res = await client.sendGenericTemplate(
RECIPIENT_ID,
templateElements,
{ image_aspect_ratio: 'square' }
);

expect(res).toEqual(reply);
});

it('can use generic template with tag', async () => {
const { client, mock } = createMock();

Expand All @@ -1964,7 +1999,6 @@ describe('send api', () => {
const res = await client.sendGenericTemplate(
RECIPIENT_ID,
templateElements,
'horizontal',
{ tag: 'SHIPPING_UPDATE' }
);

Expand Down
4 changes: 4 additions & 0 deletions packages/messaging-api-messenger/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ js-tokens@^3.0.0:
version "3.0.2"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"

lodash.omit@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.omit/-/lodash.omit-4.5.0.tgz#6eb19ae5a1ee1dd9df0b969e66ce0b7fa30b5e60"

loose-envify@^1.0.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848"
Expand Down

0 comments on commit 701e717

Please sign in to comment.