Skip to content

Commit

Permalink
Add isUnblocked flag to Follow Webhook event (#597)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mokuzon committed Feb 6, 2024
1 parent 1aa43ad commit 247fb10
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 deletions.
2 changes: 1 addition & 1 deletion line-openapi
Submodule line-openapi updated 1 files
+11 −0 webhook.yml
1 change: 1 addition & 0 deletions linebot/v3/webhooks/__init__.py
Expand Up @@ -53,6 +53,7 @@
from linebot.v3.webhooks.models.event import Event
from linebot.v3.webhooks.models.event_mode import EventMode
from linebot.v3.webhooks.models.file_message_content import FileMessageContent
from linebot.v3.webhooks.models.follow_detail import FollowDetail
from linebot.v3.webhooks.models.follow_event import FollowEvent
from linebot.v3.webhooks.models.group_source import GroupSource
from linebot.v3.webhooks.models.image_message_content import ImageMessageContent
Expand Down
1 change: 1 addition & 0 deletions linebot/v3/webhooks/models/__init__.py
Expand Up @@ -34,6 +34,7 @@
from linebot.v3.webhooks.models.event import Event
from linebot.v3.webhooks.models.event_mode import EventMode
from linebot.v3.webhooks.models.file_message_content import FileMessageContent
from linebot.v3.webhooks.models.follow_detail import FollowDetail
from linebot.v3.webhooks.models.follow_event import FollowEvent
from linebot.v3.webhooks.models.group_source import GroupSource
from linebot.v3.webhooks.models.image_message_content import ImageMessageContent
Expand Down
71 changes: 71 additions & 0 deletions linebot/v3/webhooks/models/follow_detail.py
@@ -0,0 +1,71 @@
# coding: utf-8

"""
Webhook Type Definition
Webhook event definition of the LINE Messaging API # noqa: E501
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
"""


from __future__ import annotations
import pprint
import re # noqa: F401
import json



from pydantic.v1 import BaseModel, Field, StrictBool

class FollowDetail(BaseModel):
"""
FollowDetail
"""
is_unblocked: StrictBool = Field(..., alias="isUnblocked", description="Whether a user has added your LINE Official Account as a friend or unblocked.")

__properties = ["isUnblocked"]

class Config:
"""Pydantic configuration"""
allow_population_by_field_name = True
validate_assignment = True

def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.dict(by_alias=True))

def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
return json.dumps(self.to_dict())

@classmethod
def from_json(cls, json_str: str) -> FollowDetail:
"""Create an instance of FollowDetail from a JSON string"""
return cls.from_dict(json.loads(json_str))

def to_dict(self):
"""Returns the dictionary representation of the model using alias"""
_dict = self.dict(by_alias=True,
exclude={
},
exclude_none=True)
return _dict

@classmethod
def from_dict(cls, obj: dict) -> FollowDetail:
"""Create an instance of FollowDetail from a dict"""
if obj is None:
return None

if not isinstance(obj, dict):
return FollowDetail.parse_obj(obj)

_obj = FollowDetail.parse_obj({
"is_unblocked": obj.get("isUnblocked")
})
return _obj

10 changes: 8 additions & 2 deletions linebot/v3/webhooks/models/follow_event.py
Expand Up @@ -23,16 +23,18 @@
from linebot.v3.webhooks.models.delivery_context import DeliveryContext
from linebot.v3.webhooks.models.event import Event
from linebot.v3.webhooks.models.event_mode import EventMode
from linebot.v3.webhooks.models.follow_detail import FollowDetail
from linebot.v3.webhooks.models.source import Source

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

__properties = ["type", "source", "timestamp", "mode", "webhookEventId", "deliveryContext", "replyToken"]
__properties = ["type", "source", "timestamp", "mode", "webhookEventId", "deliveryContext", "replyToken", "follow"]

class Config:
"""Pydantic configuration"""
Expand Down Expand Up @@ -64,6 +66,9 @@ def to_dict(self):
# override the default output from pydantic.v1 by calling `to_dict()` of delivery_context
if self.delivery_context:
_dict['deliveryContext'] = self.delivery_context.to_dict()
# override the default output from pydantic.v1 by calling `to_dict()` of follow
if self.follow:
_dict['follow'] = self.follow.to_dict()
return _dict

@classmethod
Expand All @@ -82,7 +87,8 @@ def from_dict(cls, obj: dict) -> FollowEvent:
"mode": obj.get("mode"),
"webhook_event_id": obj.get("webhookEventId"),
"delivery_context": DeliveryContext.from_dict(obj.get("deliveryContext")) if obj.get("deliveryContext") is not None else None,
"reply_token": obj.get("replyToken")
"reply_token": obj.get("replyToken"),
"follow": FollowDetail.from_dict(obj.get("follow")) if obj.get("follow") is not None else None
})
return _obj

3 changes: 3 additions & 0 deletions tests/v3/text/webhook.json
Expand Up @@ -152,6 +152,9 @@
"webhookEventId": "testwebhookeventid",
"deliveryContext": {
"isRedelivery": false
},
"follow": {
"isUnblocked": true
}
},
{
Expand Down

0 comments on commit 247fb10

Please sign in to comment.