Skip to content

Commit d6d5215

Browse files
nnsnodnbbe-hase
authored andcommitted
Add AccountLinkEvent (#105)
* Add AccountLinkEvent * Fix E501
1 parent b0239a2 commit d6d5215

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

linebot/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@
4141
JoinEvent,
4242
LeaveEvent,
4343
PostbackEvent,
44+
AccountLinkEvent,
4445
BeaconEvent,
4546
Postback,
4647
Beacon,
48+
Link,
4749
)
4850
from .imagemap import ( # noqa
4951
ImagemapSendMessage,

linebot/models/events.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,40 @@ def __init__(self, timestamp=None, source=None, reply_token=None,
261261
)
262262

263263

264+
class AccountLinkEvent(Event):
265+
"""Webhook AccountLinkEvent.
266+
267+
https://developers.line.me/en/docs/messaging-api/reference/#account-link-event
268+
269+
Event object for when a user has linked his/her LINE account with a provider's service account.
270+
You can reply to account link events.
271+
If the link token has expired or has already been used,
272+
no webhook event will be sent and the user will be shown an error.
273+
"""
274+
275+
def __init__(self, timestamp=None, source=None, reply_token=None, link=None, **kwargs):
276+
"""__init__ method.
277+
278+
:param long timestamp: Time of the event in milliseconds
279+
:param source: Source object
280+
:type source: T <= :py:class:`linebot.models.sources.Source`
281+
:param str reply_token: Reply token
282+
:param link: Link object
283+
:type link: :py:class:`linebot.models.events.Link`
284+
:param kwargs:
285+
"""
286+
super(AccountLinkEvent, self).__init__(
287+
timestamp=timestamp, source=source, reply_token=reply_token, link=link
288+
)
289+
290+
self.type = 'accountLink'
291+
self.source = source
292+
self.reply_token = reply_token
293+
self.link = self.get_or_new_from_json_dict(
294+
link, Link
295+
)
296+
297+
264298
class Postback(Base):
265299
"""Postback.
266300
@@ -310,3 +344,21 @@ def device_message(self):
310344
:return:
311345
"""
312346
return bytearray.fromhex(self.dm) if self.dm is not None else None
347+
348+
349+
class Link(Base):
350+
"""Link.
351+
352+
https://developers.line.me/en/docs/messaging-api/reference/#link-object
353+
"""
354+
355+
def __init__(self, result=None, nonce=None, **kwargs):
356+
"""__init__ method.
357+
358+
:param str result: Indicate whether the link was successful or not.
359+
:param str nonce: Specified nonce when verifying the user ID.
360+
"""
361+
super(Link, self).__init__(**kwargs)
362+
363+
self.result = result
364+
self.nonce = nonce

linebot/webhook.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
JoinEvent,
3131
LeaveEvent,
3232
PostbackEvent,
33-
BeaconEvent
33+
BeaconEvent,
34+
AccountLinkEvent,
3435
)
3536
from .utils import LOGGER, PY3, safe_compare_digest
3637

@@ -141,6 +142,8 @@ def parse(self, body, signature):
141142
events.append(PostbackEvent.new_from_json_dict(event))
142143
elif event_type == 'beacon':
143144
events.append(BeaconEvent.new_from_json_dict(event))
145+
elif event_type == 'accountLink':
146+
events.append(AccountLinkEvent.new_from_json_dict(event))
144147
else:
145148
LOGGER.warn('Unknown event type. type=' + event_type)
146149

0 commit comments

Comments
 (0)