Skip to content

Add support for altUri.desktop property #168

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

Merged
merged 1 commit into from
May 31, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions linebot/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
MessageAction as MessageTemplateAction, # backward compatibility
URIAction as URITemplateAction, # backward compatibility
DatetimePickerAction as DatetimePickerTemplateAction, # backward compatibility
AltUri,
)
from .base import ( # noqa
Base,
Expand Down
27 changes: 26 additions & 1 deletion linebot/models/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,44 @@ class URIAction(Action):
the URI specified in the uri property is opened.
"""

def __init__(self, label=None, uri=None, **kwargs):
def __init__(self, label=None, uri=None, alt_uri=None, **kwargs):
"""__init__ method.

:param str label: Label for the action
Max: 20 characters
:param str uri: URI opened when the action is performed.
:param alt_uri: URI opened when the desktop app.
:type alt_uri: T <= :py:class:`linebot.models.actions.AltUri`
:param kwargs:
"""
super(URIAction, self).__init__(**kwargs)

self.type = 'uri'
self.label = label
self.uri = uri
self.alt_uri = self.get_or_new_from_json_dict(alt_uri, AltUri)


class AltUri(with_metaclass(ABCMeta, Base)):
"""AltUri.

https://github.com/line/line-bot-sdk-python/issues/155

URI opened when the desktop app.
"""

def __init__(self, desktop=None, **kwargs):
"""__init__ method.

:param str desktop: URI opened on LINE for macOS and Windows
when the action is performed.
If the altUri.desktop property is set,
the uri property is ignored on LINE for macOS and Windows.
:param kwargs:
"""
super(AltUri, self).__init__(**kwargs)

self.desktop = desktop


class DatetimePickerAction(Action):
Expand Down
10 changes: 7 additions & 3 deletions tests/api/test_send_template_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from linebot.models import (
TemplateSendMessage, ButtonsTemplate,
PostbackAction, MessageAction,
URIAction, DatetimePickerAction,
URIAction, AltUri, DatetimePickerAction,
ConfirmTemplate, CarouselTemplate, CarouselColumn,
ImageCarouselTemplate, ImageCarouselColumn
)
Expand All @@ -51,7 +51,8 @@ def setUp(self):
label='message', text='message text'
),
URIAction(
label='uri', uri='http://example.com/'
label='uri', uri='http://example.com/',
alt_uri=AltUri(desktop="http://example.com/desktop")
)
]
)
Expand Down Expand Up @@ -81,7 +82,10 @@ def setUp(self):
{
"type": "uri",
"label": "uri",
"uri": "http://example.com/"
"uri": "http://example.com/",
"altUri": {
"desktop": "http://example.com/desktop"
}
}
]
}
Expand Down