From acc8743fa0f4dd0769576ccee916e7b43259bbf9 Mon Sep 17 00:00:00 2001 From: Anton Nayshtut Date: Sun, 24 Sep 2017 14:45:23 +0300 Subject: [PATCH] Generic Template: image_aspect_ratio supported For more info see [1]. [1] https://developers.facebook.com/docs/messenger-platform/send-messages/template/generic --- fbmq/template.py | 5 +++-- tests/test_template.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/fbmq/template.py b/fbmq/template.py index 391f0fb..dcc7f7b 100644 --- a/fbmq/template.py +++ b/fbmq/template.py @@ -72,11 +72,12 @@ def __init__(self): class Generic(object): - def __init__(self, elements): + def __init__(self, elements, square_image=False): self.type = 'template' self.payload = { 'template_type': 'generic', - 'elements': elements + 'elements': elements, + 'image_aspect_ratio': 'square' if square_image else 'horizontal' } diff --git a/tests/test_template.py b/tests/test_template.py index a416574..2806a92 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -67,11 +67,22 @@ def test_generic(self): image_url='https://test.com/img', buttons=[ {'type': 'web_url', 'title': 'title', 'value': 'https://test.com'}])]) + self.assertEquals( + '{"payload": {"elements": [{"buttons": [{"title": "title", "type": "web_url", "url": "https://test.com"}],' + ' "image_url": "https://test.com/img", "item_url": "https://test.com", "subtitle": "subtitle",' + ' "title": "generic"}], "image_aspect_ratio": "horizontal", "template_type": "generic"}, "type": "template"}', utils.to_json(generic)) + def test_generic_square_image(self): + generic = Template.Generic( + elements=[Template.GenericElement(title='generic', subtitle='subtitle', item_url='https://test.com', + image_url='https://test.com/img', + buttons=[ + {'type': 'web_url', 'title': 'title', 'value': 'https://test.com'}])], + square_image=True) self.assertEquals( '{"payload": {"elements": [{"buttons": [{"title": "title", "type": "web_url", "url": "https://test.com"}],' ' "image_url": "https://test.com/img", "item_url": "https://test.com", "subtitle": "subtitle",' - ' "title": "generic"}], "template_type": "generic"}, "type": "template"}', utils.to_json(generic)) + ' "title": "generic"}], "image_aspect_ratio": "square", "template_type": "generic"}, "type": "template"}', utils.to_json(generic)) def test_list(self): listt = Template.List(