Skip to content

Commit 1b63fb0

Browse files
authored
Support : "webhook redelivery" (#385)
News https://developers.line.biz/ja/news/2022/04/19/webhook-redelivery/ Added to two common properties - create `DeliveryContext` class - add two properties in `Event` - add test case in `TestWebhookParser`
1 parent 3f28675 commit 1b63fb0

File tree

4 files changed

+284
-1
lines changed

4 files changed

+284
-1
lines changed

linebot/models/delivery_context.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# https://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
"""linebot.models.delivery_context module."""
14+
15+
16+
from abc import ABCMeta
17+
18+
from future.utils import with_metaclass
19+
20+
from .base import Base
21+
22+
23+
class DeliveryContext(with_metaclass(ABCMeta, Base)):
24+
"""Abstract Base Class of DeliveryContext."""
25+
26+
def __init__(self, is_redelivery=None, **kwargs):
27+
"""__init__ method.
28+
29+
:param bool is_redelivery: Whether the webhook event is a redelivered one or not
30+
:param kwargs:
31+
"""
32+
super(DeliveryContext, self).__init__(**kwargs)
33+
34+
self.is_redelivery = is_redelivery

linebot/models/events.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from future.utils import with_metaclass
2121

2222
from linebot.models.base import Base
23+
from linebot.models.delivery_context import DeliveryContext
2324
from linebot.models.messages import (
2425
TextMessage,
2526
ImageMessage,
@@ -46,7 +47,15 @@ class Event(with_metaclass(ABCMeta, Base)):
4647
https://developers.line.biz/en/reference/messaging-api/#webhook-event-objects
4748
"""
4849

49-
def __init__(self, mode=None, timestamp=None, source=None, **kwargs):
50+
def __init__(
51+
self,
52+
mode=None,
53+
timestamp=None,
54+
source=None,
55+
webhook_event_id=None,
56+
delivery_context=None,
57+
**kwargs
58+
):
5059
"""__init__ method.
5160
5261
:param str mode: Channel state
@@ -67,6 +76,10 @@ def __init__(self, mode=None, timestamp=None, source=None, **kwargs):
6776
'room': SourceRoom,
6877
}
6978
)
79+
self.webhook_event_id = webhook_event_id
80+
self.delivery_context = self.get_or_new_from_json_dict(
81+
delivery_context, DeliveryContext
82+
)
7083

7184

7285
class MessageEvent(Event):

0 commit comments

Comments
 (0)