Skip to content

Commit a0abc70

Browse files
authored
Support message sticker type and update followers ids API (#369)
* Update get followers ids API params * Add sticker message text property and add condition for stickerResourceType * add test case * update readme
1 parent d97d488 commit a0abc70

File tree

6 files changed

+50
-6
lines changed

6 files changed

+50
-6
lines changed

README.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,19 @@ https://developers.line.biz/en/reference/messaging-api/#test-webhook-endpoint
650650
print(test_result.reason)
651651
print(test_result.detail)
652652
653+
get\_followers\_ids(self, limit=300, start=None, timeout=None)
654+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
655+
656+
Get a list of users who added your LINE Official Account as a friend.
657+
658+
https://developers.line.biz/en/reference/messaging-api/#get-follower-ids
659+
660+
.. code:: python
661+
662+
test_result = line_bot_api.get_followers_ids()
663+
print(test_result.user_ids)
664+
print(test_result.next)
665+
653666
※ Error handling
654667
^^^^^^^^^^^^^^^^^
655668

@@ -1229,6 +1242,8 @@ Message
12291242
- package\_id
12301243
- sticker\_id
12311244
- sticker\_resource\_type
1245+
- keywords
1246+
- text
12321247
- FileMessage
12331248
- type
12341249
- id

linebot/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,11 +1569,13 @@ def test_webhook_endpoint(self, webhook_endpoint=None, timeout=None):
15691569

15701570
return TestWebhookResponse.new_from_json_dict(response.json)
15711571

1572-
def get_followers_ids(self, start=None, timeout=None):
1572+
def get_followers_ids(self, limit=300, start=None, timeout=None):
15731573
"""Get a list of users who added your LINE Official Account as a friend.
15741574
15751575
https://developers.line.biz/en/reference/messaging-api/#get-follower-ids
15761576
1577+
:param int limit: The maximum number of user IDs to retrieve in a single request.
1578+
The default value is 300.
15771579
:param str start: Get the next array of user IDs.
15781580
:param timeout: (optional) How long to wait for the server
15791581
to send data before giving up, as a float,
@@ -1582,7 +1584,7 @@ def get_followers_ids(self, start=None, timeout=None):
15821584
:type timeout: float | tuple(float, float)
15831585
:rtype: :py:class:`linebot.models.responses.UserIds`
15841586
"""
1585-
params = None if start is None else {'start': start}
1587+
params = {'limit': limit} if start is None else {'limit': limit, 'start': start}
15861588

15871589
response = self._get(
15881590
'/v2/bot/followers/ids',

linebot/models/messages.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,15 @@ class StickerMessage(Message):
213213
"""
214214

215215
def __init__(self, id=None, package_id=None, sticker_id=None,
216-
sticker_resource_type=None, keywords=None, **kwargs):
216+
sticker_resource_type=None, keywords=None, text=None, **kwargs):
217217
"""__init__ method.
218218
219219
:param str id: Message ID
220220
:param str package_id: Package ID
221221
:param str sticker_id: Sticker ID
222222
:param str sticker_resource_type: Sticker resource type
223223
:param list[str] keywords: List of up to 15 keywords describing the sticker
224+
:param str text: Any text entered by the user
224225
:param kwargs:
225226
"""
226227
super(StickerMessage, self).__init__(id=id, **kwargs)
@@ -230,6 +231,7 @@ def __init__(self, id=None, package_id=None, sticker_id=None,
230231
self.sticker_id = sticker_id
231232
self.sticker_resource_type = sticker_resource_type
232233
self.keywords = keywords
234+
self.text = text
233235

234236

235237
class FileMessage(Message):

tests/api/test_get_member_ids.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_get_follower_user_ids(self):
134134
self.assertEqual(request.method, 'GET')
135135
self.assertEqual(
136136
request.url,
137-
LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/followers/ids')
137+
LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/followers/ids?limit=300')
138138
self.assertEqual(member_ids_response.user_ids, ['U1', 'U2'])
139139
self.assertEqual(member_ids_response.next, None)
140140

@@ -157,7 +157,30 @@ def test_get_follower_user_ids_with_start(self):
157157
self.assertEqual(
158158
request.url,
159159
LineBotApi.DEFAULT_API_ENDPOINT +
160-
'/v2/bot/followers/ids?start=continuationToken1')
160+
'/v2/bot/followers/ids?limit=300&start=continuationToken1')
161+
self.assertEqual(member_ids_response.user_ids, ['U1', 'U2'])
162+
self.assertEqual(member_ids_response.next, 'continuationToken2')
163+
164+
@responses.activate
165+
def test_get_follower_user_ids_with_start_and_limit(self):
166+
responses.add(
167+
responses.GET,
168+
LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/followers/ids',
169+
json={
170+
'userIds': ['U1', 'U2'],
171+
'next': 'continuationToken2'
172+
},
173+
status=200
174+
)
175+
176+
member_ids_response = self.tested.get_followers_ids(limit=2, start='continuationToken1')
177+
178+
request = responses.calls[0].request
179+
self.assertEqual(request.method, 'GET')
180+
self.assertEqual(
181+
request.url,
182+
LineBotApi.DEFAULT_API_ENDPOINT +
183+
'/v2/bot/followers/ids?limit=2&start=continuationToken1')
161184
self.assertEqual(member_ids_response.user_ids, ['U1', 'U2'])
162185
self.assertEqual(member_ids_response.next, 'continuationToken2')
163186

tests/test_webhook.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def test_parse(self):
170170
self.assertEqual(events[5].message.sticker_resource_type, 'STATIC')
171171
self.assertEqual(events[5].message.keywords[0], 'Love You')
172172
self.assertEqual(events[5].message.keywords[1], 'Love')
173+
self.assertEqual(events[5].message.text, 'Just sticker')
173174

174175
# FollowEvent, SourceUser
175176
self.assertIsInstance(events[6], FollowEvent)

tests/text/webhook.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@
107107
"packageId": "1",
108108
"stickerId": "1",
109109
"stickerResourceType": "STATIC",
110-
"keywords": ["Love You", "Love"]
110+
"keywords": ["Love You", "Love"],
111+
"text": "Just sticker"
111112
}
112113
},
113114
{

0 commit comments

Comments
 (0)