Skip to content

Commit c950e25

Browse files
authored
Add validating message objects APIs (#409)
1 parent 048e05e commit c950e25

File tree

6 files changed

+642
-7
lines changed

6 files changed

+642
-7
lines changed

README.rst

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,61 @@ https://developers.line.biz/en/reference/messaging-api/#get-narrowcast-progress-
180180
print(narrowcast.target_count)
181181
182182
183+
validate\_reply\_message\_objects(self, messages, timeout=None)
184+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
185+
186+
Validate that an array of message objects used for reply message is valid.
187+
188+
https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-reply-message
189+
190+
.. code:: python
191+
192+
line_bot_api.validate_reply_message_objects(TextSendMessage(text='Hello World!'))
193+
194+
validate\_push\_message\_objects(self, messages, timeout=None)
195+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
196+
197+
Validate that an array of message objects used for push message is valid.
198+
199+
https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-push-message
200+
201+
.. code:: python
202+
203+
line_bot_api.validate_push_message_objects(TextSendMessage(text='Hello World!'))
204+
205+
validate\_multicast\_message\_objects(self, messages, timeout=None)
206+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
207+
208+
Validate that an array of message objects used for multicast message is valid.
209+
210+
https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-multicast-message
211+
212+
.. code:: python
213+
214+
line_bot_api.validate_multicast_message_objects(TextSendMessage(text='Hello World!'))
215+
216+
validate\_broadcast\_message\_objects(self, messages, timeout=None)
217+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
218+
219+
Validate that an array of message objects used for broadcast message is valid.
220+
221+
https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-broadcast-message
222+
223+
.. code:: python
224+
225+
line_bot_api.validate_broadcast_message_objects(TextSendMessage(text='Hello World!'))
226+
227+
validate\_narrowcast\_message\_objects(self, messages, timeout=None)
228+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
229+
230+
Validate that an array of message objects used for narrowcast message is valid.
231+
232+
https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-narrowcast-message
233+
234+
.. code:: python
235+
236+
line_bot_api.validate_narrowcast_message_objects(TextSendMessage(text='Hello World!'))
237+
183238
get\_profile(self, user\_id, timeout=None)
184239
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
185240

@@ -764,7 +819,7 @@ TextSendMessage-Emoji
764819
"index": 0,
765820
"productId": "5ac1bfd5040ab15980c9b435",
766821
"emojiId": "001"
767-
},
822+
},
768823
{
769824
"index": 13,
770825
"productId": "5ac1bfd5040ab15980c9b435",

linebot/api.py

Lines changed: 175 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
Group, UserIds, RichMenuAliasResponse, RichMenuAliasListResponse, ChannelAccessTokens,
3535
IssueChannelTokenResponseV2, VerifyChannelTokenResponseV2, ValidAccessTokenKeyIDsResponse,
3636
InsightMessageEventOfCustomAggregationUnitResponse, AggregationInfoResponse,
37-
AggregationNameListResponse
37+
AggregationNameListResponse,
38+
ValidateBroadcastMessageObjectsResponse,
39+
ValidateMulticastMessageObjectsResponse, ValidateNarrowcastMessageObjectsResponse,
40+
ValidatePushMessageObjectsResponse, ValidateReplyMessageObjectsResponse,
3841
)
3942

4043

@@ -174,7 +177,7 @@ def multicast(self, to, messages, retry_key=None, notification_disabled=False,
174177
Messages cannot be sent to groups or rooms.
175178
176179
:param to: IDs of the receivers
177-
Max: 150 users
180+
Max: 500 users
178181
:type to: list[str]
179182
:param messages: Messages.
180183
Max: 5
@@ -327,6 +330,176 @@ def get_progress_status_narrowcast(self, request_id, timeout=None):
327330

328331
return MessageProgressNarrowcastResponse.new_from_json_dict(response.json)
329332

333+
def validate_reply_message_objects(self, messages, timeout=None):
334+
"""Call validate reply message objects API.
335+
336+
https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-reply-message
337+
338+
You can validate that an array of message objects is valid as a value
339+
for the messages property of the request body for the send reply message endpoint.
340+
341+
:param messages: Messages.
342+
Max: 5
343+
:type messages: T <= :py:class:`linebot.models.send_messages.SendMessage` |
344+
list[T <= :py:class:`linebot.models.send_messages.SendMessage`]
345+
:param timeout: (optional) How long to wait for the server
346+
to send data before giving up, as a float,
347+
or a (connect timeout, read timeout) float tuple.
348+
Default is self.http_client.timeout
349+
:type timeout: float | tuple(float, float)
350+
:rtype: :py:class:`linebot.models.responses.ValidateReplyMessageObjectsResponse`
351+
"""
352+
if not isinstance(messages, (list, tuple)):
353+
messages = [messages]
354+
355+
data = {
356+
'messages': [message.as_json_dict() for message in messages],
357+
}
358+
359+
response = self._post(
360+
'/v2/bot/message/validate/reply', data=json.dumps(data),
361+
timeout=timeout
362+
)
363+
364+
return ValidateReplyMessageObjectsResponse(
365+
request_id=response.headers.get('X-Line-Request-Id'))
366+
367+
def validate_push_message_objects(self, messages, timeout=None):
368+
"""Call validate push message objects API.
369+
370+
https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-push-message
371+
372+
You can validate that an array of message objects is valid as a value
373+
for the messages property of the request body for the send push message endpoint.
374+
375+
:param messages: Messages.
376+
Max: 5
377+
:type messages: T <= :py:class:`linebot.models.send_messages.SendMessage` |
378+
list[T <= :py:class:`linebot.models.send_messages.SendMessage`]
379+
:param timeout: (optional) How long to wait for the server
380+
to send data before giving up, as a float,
381+
or a (connect timeout, read timeout) float tuple.
382+
Default is self.http_client.timeout
383+
:type timeout: float | tuple(float, float)
384+
:rtype: :py:class:`linebot.models.responses.ValidatePushMessageObjectsResponse`
385+
"""
386+
if not isinstance(messages, (list, tuple)):
387+
messages = [messages]
388+
389+
data = {
390+
'messages': [message.as_json_dict() for message in messages],
391+
}
392+
393+
response = self._post(
394+
'/v2/bot/message/validate/push', data=json.dumps(data),
395+
timeout=timeout
396+
)
397+
398+
return ValidatePushMessageObjectsResponse(
399+
request_id=response.headers.get('X-Line-Request-Id'))
400+
401+
def validate_multicast_message_objects(self, messages, timeout=None):
402+
"""Call validate multicast message objects API.
403+
404+
https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-multicast-message
405+
406+
You can validate that an array of message objects is valid as a value
407+
for the messages property of the request body for the send multicast message endpoint.
408+
409+
:param messages: Messages.
410+
Max: 5
411+
:type messages: T <= :py:class:`linebot.models.send_messages.SendMessage` |
412+
list[T <= :py:class:`linebot.models.send_messages.SendMessage`]
413+
:param timeout: (optional) How long to wait for the server
414+
to send data before giving up, as a float,
415+
or a (connect timeout, read timeout) float tuple.
416+
Default is self.http_client.timeout
417+
:type timeout: float | tuple(float, float)
418+
:rtype: :py:class:`linebot.models.responses.ValidateMulticastMessageObjectsResponse`
419+
"""
420+
if not isinstance(messages, (list, tuple)):
421+
messages = [messages]
422+
423+
data = {
424+
'messages': [message.as_json_dict() for message in messages],
425+
}
426+
427+
response = self._post(
428+
'/v2/bot/message/validate/multicast', data=json.dumps(data),
429+
timeout=timeout
430+
)
431+
432+
return ValidateMulticastMessageObjectsResponse(
433+
request_id=response.headers.get('X-Line-Request-Id'))
434+
435+
def validate_broadcast_message_objects(self, messages, timeout=None):
436+
"""Call validate broadcast message objects API.
437+
438+
https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-broadcast-message
439+
440+
You can validate that an array of message objects is valid as a value
441+
for the messages property of the request body for the send broadcast message endpoint.
442+
443+
:param messages: Messages.
444+
Max: 5
445+
:type messages: T <= :py:class:`linebot.models.send_messages.SendMessage` |
446+
list[T <= :py:class:`linebot.models.send_messages.SendMessage`]
447+
:param timeout: (optional) How long to wait for the server
448+
to send data before giving up, as a float,
449+
or a (connect timeout, read timeout) float tuple.
450+
Default is self.http_client.timeout
451+
:type timeout: float | tuple(float, float)
452+
:rtype: :py:class:`linebot.models.responses.ValidateBroadcastMessageObjectsResponse`
453+
"""
454+
if not isinstance(messages, (list, tuple)):
455+
messages = [messages]
456+
457+
data = {
458+
'messages': [message.as_json_dict() for message in messages],
459+
}
460+
461+
response = self._post(
462+
'/v2/bot/message/validate/broadcast', data=json.dumps(data),
463+
timeout=timeout
464+
)
465+
466+
return ValidateBroadcastMessageObjectsResponse(
467+
request_id=response.headers.get('X-Line-Request-Id'))
468+
469+
def validate_narrowcast_message_objects(self, messages, timeout=None):
470+
"""Call validate narrowcast message objects API.
471+
472+
https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-narrowcast-message
473+
474+
You can validate that an array of message objects is valid as a value
475+
for the messages property of the request body for the send narrowcast message endpoint.
476+
477+
:param messages: Messages.
478+
Max: 5
479+
:type messages: T <= :py:class:`linebot.models.send_messages.SendMessage` |
480+
list[T <= :py:class:`linebot.models.send_messages.SendMessage`]
481+
:param timeout: (optional) How long to wait for the server
482+
to send data before giving up, as a float,
483+
or a (connect timeout, read timeout) float tuple.
484+
Default is self.http_client.timeout
485+
:type timeout: float | tuple(float, float)
486+
:rtype: :py:class:`linebot.models.responses.ValidateNarrowcastMessageObjectsResponse`
487+
"""
488+
if not isinstance(messages, (list, tuple)):
489+
messages = [messages]
490+
491+
data = {
492+
'messages': [message.as_json_dict() for message in messages],
493+
}
494+
495+
response = self._post(
496+
'/v2/bot/message/validate/narrowcast', data=json.dumps(data),
497+
timeout=timeout
498+
)
499+
500+
return ValidateNarrowcastMessageObjectsResponse(
501+
request_id=response.headers.get('X-Line-Request-Id'))
502+
330503
def get_message_delivery_broadcast(self, date, timeout=None):
331504
"""Get number of sent broadcast messages.
332505

0 commit comments

Comments
 (0)