Skip to content

Commit

Permalink
allow content type location for quick replies
Browse files Browse the repository at this point in the history
  • Loading branch information
hyzhak committed Jun 7, 2017
1 parent 6eb3b49 commit aa2dcdc
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
2 changes: 1 addition & 1 deletion botstory/integrations/fb/messenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async def send_text_message(self, recipient, text,
'text': text,
}

quick_replies = [{**reply, 'content_type': 'text'} for reply in quick_replies]
quick_replies = [{'content_type': 'text', **reply} for reply in quick_replies]
if len(quick_replies) > 0:
message['quick_replies'] = quick_replies

Expand Down
61 changes: 61 additions & 0 deletions botstory/integrations/fb/messenger_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,67 @@ async def test_quick_replies():
)


@pytest.mark.asyncio
async def test_quick_replies_with_location():
user = utils.build_fake_user()

global story
story = Story()

story.use(messenger.FBInterface(page_access_token='qwerty3'))
story.use(mockdb.MockDB())
mock_http = story.use(mockhttp.MockHttpInterface())

await story.ask(
'Where do you live?',
quick_replies=[{
'content_type': 'location',
}, {
'title': 'Europe',
'payload': 'SET_LOCATION_EU',
}, {
'title': 'US :',
'payload': 'SET_LOCATION_US',
}, {
'title': 'Ukraine',
'payload': 'SET_LOCATION_UA',
}, ],
user=user,
)

mock_http.post.assert_called_with(
'https://graph.facebook.com/v2.6/me/messages/',
params={
'access_token': 'qwerty3',
},
json={
'message': {
'text': 'Where do you live?',
'quick_replies': [
{
'content_type': 'location',
}, {
'content_type': 'text',
'title': 'Europe',
'payload': 'SET_LOCATION_EU',
}, {
'content_type': 'text',
'title': 'US :',
'payload': 'SET_LOCATION_US',
}, {
'content_type': 'text',
'title': 'Ukraine',
'payload': 'SET_LOCATION_UA',
},
],
},
'recipient': {
'id': user['facebook_user_id'],
},
}
)


@pytest.mark.asyncio
async def test_setup_webhook():
global story
Expand Down
9 changes: 5 additions & 4 deletions botstory/integrations/fb/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ def send_text_message(text, quick_replies):
raise Invalid('send message quick replies should not exceed 10 limit')

for item in quick_replies:
if len(item['title']) > 20:
raise Invalid('send message quick replies title should not exceed 20 character limit')
if 'content_type' not in item:
raise Invalid('send message quick replies should have content_type')
if item['content_type'] == 'text' and len(item['payload']) > 1000:
raise Invalid('send message quick replies payload should not exceed 1000 character limit')
if item['content_type'] == 'text':
if len(item['title']) > 20:
raise Invalid('send message quick replies title should not exceed 20 character limit')
if len(item['payload']) > 1000:
raise Invalid('send message quick replies payload should not exceed 1000 character limit')

0 comments on commit aa2dcdc

Please sign in to comment.