Skip to content
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
2 changes: 2 additions & 0 deletions linebot/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@
JoinEvent,
LeaveEvent,
PostbackEvent,
AccountLinkEvent,
BeaconEvent,
Postback,
Beacon,
Link,
)
from .imagemap import ( # noqa
ImagemapSendMessage,
Expand Down
52 changes: 52 additions & 0 deletions linebot/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,40 @@ def __init__(self, timestamp=None, source=None, reply_token=None,
)


class AccountLinkEvent(Event):
"""Webhook AccountLinkEvent.

https://developers.line.me/en/docs/messaging-api/reference/#account-link-event

Event object for when a user has linked his/her LINE account with a provider's service account.
You can reply to account link events.
If the link token has expired or has already been used,
no webhook event will be sent and the user will be shown an error.
"""

def __init__(self, timestamp=None, source=None, reply_token=None, link=None, **kwargs):
"""__init__ method.

:param long timestamp: Time of the event in milliseconds
:param source: Source object
:type source: T <= :py:class:`linebot.models.sources.Source`
:param str reply_token: Reply token
:param link: Link object
:type link: :py:class:`linebot.models.events.Link`
:param kwargs:
"""
super(AccountLinkEvent, self).__init__(
timestamp=timestamp, source=source, reply_token=reply_token, link=link
)

self.type = 'accountLink'
self.source = source
self.reply_token = reply_token
self.link = self.get_or_new_from_json_dict(
link, Link
)


class Postback(Base):
"""Postback.

Expand Down Expand Up @@ -310,3 +344,21 @@ def device_message(self):
:return:
"""
return bytearray.fromhex(self.dm) if self.dm is not None else None


class Link(Base):
"""Link.

https://developers.line.me/en/docs/messaging-api/reference/#link-object
"""

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

:param str result: Indicate whether the link was successful or not.
:param str nonce: Specified nonce when verifying the user ID.
"""
super(Link, self).__init__(**kwargs)

self.result = result
self.nonce = nonce
5 changes: 4 additions & 1 deletion linebot/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
JoinEvent,
LeaveEvent,
PostbackEvent,
BeaconEvent
BeaconEvent,
AccountLinkEvent,
)
from .utils import LOGGER, PY3, safe_compare_digest

Expand Down Expand Up @@ -141,6 +142,8 @@ def parse(self, body, signature):
events.append(PostbackEvent.new_from_json_dict(event))
elif event_type == 'beacon':
events.append(BeaconEvent.new_from_json_dict(event))
elif event_type == 'accountLink':
events.append(AccountLinkEvent.new_from_json_dict(event))
else:
LOGGER.warn('Unknown event type. type=' + event_type)

Expand Down