Skip to content

Commit

Permalink
trunkate with ellipsis by default
Browse files Browse the repository at this point in the history
  • Loading branch information
hyzhak committed Jan 26, 2017
1 parent e11bfc5 commit d049a85
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions botstory/integrations/fb/messenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ async def send_text_message(self, recipient, text,

if options and options.get('overflow', None) == 'cut':
text = text[:i.limit]
else:
text = text[:i.limit - 2] + '\u2026'
except validate.Invalid as i:
logger.warn(str(i))

Expand Down
37 changes: 37 additions & 0 deletions botstory/integrations/fb/messenger_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async def test_send_text_message():
}
)


@pytest.mark.asyncio
async def test_truncate_long_message():
user = utils.build_fake_user()
Expand Down Expand Up @@ -86,6 +87,42 @@ async def test_truncate_long_message():
}
)


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

global story
story = Story()

interface = story.use(messenger.FBInterface(page_access_token='qwerty1'))
mock_http = story.use(mockhttp.MockHttpInterface())

await story.start()

very_long_message = 'very_long_message' * 100
await interface.send_text_message(
recipient=user,
text=very_long_message,
quick_replies=None,
)

mock_http.post.assert_called_with(
'https://graph.facebook.com/v2.6/me/messages/',
params={
'access_token': 'qwerty1',
},
json={
'message': {
'text': very_long_message[:638] + '\u2026',
},
'recipient': {
'id': user['facebook_user_id'],
},
}
)


@pytest.mark.asyncio
async def test_integration():
user = utils.build_fake_user()
Expand Down

0 comments on commit d049a85

Please sign in to comment.