Skip to content

Commit 247fb10

Browse files
authored
Add isUnblocked flag to Follow Webhook event (#597)
In the Messaging API, you can now determine whether a user has added your LINE Official Account as a friend or unblocked by a webhook follow event. News: https://developers.line.biz/en/news/2024/02/06/add-friends-and-unblock-friends-can-now-be-determined-by-webhook/ --- The OpenAPI definition has been updated at line/line-openapi#50, but the test fails if only the OpenAPI auto-generated code is used, so the SDK is updated manually. The only substantial change is 6437e48.
1 parent 1aa43ad commit 247fb10

File tree

6 files changed

+85
-3
lines changed

6 files changed

+85
-3
lines changed

line-openapi

linebot/v3/webhooks/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from linebot.v3.webhooks.models.event import Event
5454
from linebot.v3.webhooks.models.event_mode import EventMode
5555
from linebot.v3.webhooks.models.file_message_content import FileMessageContent
56+
from linebot.v3.webhooks.models.follow_detail import FollowDetail
5657
from linebot.v3.webhooks.models.follow_event import FollowEvent
5758
from linebot.v3.webhooks.models.group_source import GroupSource
5859
from linebot.v3.webhooks.models.image_message_content import ImageMessageContent

linebot/v3/webhooks/models/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from linebot.v3.webhooks.models.event import Event
3535
from linebot.v3.webhooks.models.event_mode import EventMode
3636
from linebot.v3.webhooks.models.file_message_content import FileMessageContent
37+
from linebot.v3.webhooks.models.follow_detail import FollowDetail
3738
from linebot.v3.webhooks.models.follow_event import FollowEvent
3839
from linebot.v3.webhooks.models.group_source import GroupSource
3940
from linebot.v3.webhooks.models.image_message_content import ImageMessageContent
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# coding: utf-8
2+
3+
"""
4+
Webhook Type Definition
5+
6+
Webhook event definition of the LINE Messaging API # noqa: E501
7+
8+
The version of the OpenAPI document: 1.0.0
9+
Generated by OpenAPI Generator (https://openapi-generator.tech)
10+
11+
Do not edit the class manually.
12+
"""
13+
14+
15+
from __future__ import annotations
16+
import pprint
17+
import re # noqa: F401
18+
import json
19+
20+
21+
22+
from pydantic.v1 import BaseModel, Field, StrictBool
23+
24+
class FollowDetail(BaseModel):
25+
"""
26+
FollowDetail
27+
"""
28+
is_unblocked: StrictBool = Field(..., alias="isUnblocked", description="Whether a user has added your LINE Official Account as a friend or unblocked.")
29+
30+
__properties = ["isUnblocked"]
31+
32+
class Config:
33+
"""Pydantic configuration"""
34+
allow_population_by_field_name = True
35+
validate_assignment = True
36+
37+
def to_str(self) -> str:
38+
"""Returns the string representation of the model using alias"""
39+
return pprint.pformat(self.dict(by_alias=True))
40+
41+
def to_json(self) -> str:
42+
"""Returns the JSON representation of the model using alias"""
43+
return json.dumps(self.to_dict())
44+
45+
@classmethod
46+
def from_json(cls, json_str: str) -> FollowDetail:
47+
"""Create an instance of FollowDetail from a JSON string"""
48+
return cls.from_dict(json.loads(json_str))
49+
50+
def to_dict(self):
51+
"""Returns the dictionary representation of the model using alias"""
52+
_dict = self.dict(by_alias=True,
53+
exclude={
54+
},
55+
exclude_none=True)
56+
return _dict
57+
58+
@classmethod
59+
def from_dict(cls, obj: dict) -> FollowDetail:
60+
"""Create an instance of FollowDetail from a dict"""
61+
if obj is None:
62+
return None
63+
64+
if not isinstance(obj, dict):
65+
return FollowDetail.parse_obj(obj)
66+
67+
_obj = FollowDetail.parse_obj({
68+
"is_unblocked": obj.get("isUnblocked")
69+
})
70+
return _obj
71+

linebot/v3/webhooks/models/follow_event.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@
2323
from linebot.v3.webhooks.models.delivery_context import DeliveryContext
2424
from linebot.v3.webhooks.models.event import Event
2525
from linebot.v3.webhooks.models.event_mode import EventMode
26+
from linebot.v3.webhooks.models.follow_detail import FollowDetail
2627
from linebot.v3.webhooks.models.source import Source
2728

2829
class FollowEvent(Event):
2930
"""
3031
Event object for when your LINE Official Account is added as a friend (or unblocked). You can reply to follow events.
3132
"""
3233
reply_token: StrictStr = Field(..., alias="replyToken", description="Reply token used to send reply message to this event")
34+
follow: FollowDetail = Field(...)
3335
type: str = "follow"
3436

35-
__properties = ["type", "source", "timestamp", "mode", "webhookEventId", "deliveryContext", "replyToken"]
37+
__properties = ["type", "source", "timestamp", "mode", "webhookEventId", "deliveryContext", "replyToken", "follow"]
3638

3739
class Config:
3840
"""Pydantic configuration"""
@@ -64,6 +66,9 @@ def to_dict(self):
6466
# override the default output from pydantic.v1 by calling `to_dict()` of delivery_context
6567
if self.delivery_context:
6668
_dict['deliveryContext'] = self.delivery_context.to_dict()
69+
# override the default output from pydantic.v1 by calling `to_dict()` of follow
70+
if self.follow:
71+
_dict['follow'] = self.follow.to_dict()
6772
return _dict
6873

6974
@classmethod
@@ -82,7 +87,8 @@ def from_dict(cls, obj: dict) -> FollowEvent:
8287
"mode": obj.get("mode"),
8388
"webhook_event_id": obj.get("webhookEventId"),
8489
"delivery_context": DeliveryContext.from_dict(obj.get("deliveryContext")) if obj.get("deliveryContext") is not None else None,
85-
"reply_token": obj.get("replyToken")
90+
"reply_token": obj.get("replyToken"),
91+
"follow": FollowDetail.from_dict(obj.get("follow")) if obj.get("follow") is not None else None
8692
})
8793
return _obj
8894

tests/v3/text/webhook.json

+3
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@
152152
"webhookEventId": "testwebhookeventid",
153153
"deliveryContext": {
154154
"isRedelivery": false
155+
},
156+
"follow": {
157+
"isUnblocked": true
155158
}
156159
},
157160
{

0 commit comments

Comments
 (0)