3232)
3333from .models .responses import (
3434 Group , UserIds , RichMenuAliasResponse , RichMenuAliasListResponse , ChannelAccessTokens ,
35- IssueChannelTokenResponseV2 , VerifyChannelTokenResponseV2 , ValidAccessTokenKeyIDsResponse
35+ IssueChannelTokenResponseV2 , VerifyChannelTokenResponseV2 , ValidAccessTokenKeyIDsResponse ,
36+ InsightMessageEventOfCustomAggregationUnitResponse , AggregationInfoResponse ,
37+ AggregationNameListResponse
3638)
3739
3840
@@ -114,7 +116,8 @@ def reply_message(self, reply_token, messages, notification_disabled=False, time
114116
115117 def push_message (
116118 self , to , messages ,
117- retry_key = None , notification_disabled = False , timeout = None ):
119+ retry_key = None , notification_disabled = False ,
120+ custom_aggregation_units = None , timeout = None ):
118121 """Call push message API.
119122
120123 https://developers.line.biz/en/reference/messaging-api/#send-push-message
@@ -129,6 +132,11 @@ def push_message(
129132 :param retry_key: (optional) Arbitrarily generated UUID in hexadecimal notation.
130133 :param bool notification_disabled: (optional) True to disable push notification
131134 when the message is sent. The default value is False.
135+ :param custom_aggregation_units: (optional) Name of aggregation unit. Case-sensitive.
136+ Max unit: 1
137+ Max aggregation unit name length: 30 characters
138+ Supported character types: Half-width alphanumeric characters and underscore
139+ :type custom_aggregation_units: str | list[str]
132140 :param timeout: (optional) How long to wait for the server
133141 to send data before giving up, as a float,
134142 or a (connect timeout, read timeout) float tuple.
@@ -147,11 +155,17 @@ def push_message(
147155 'notificationDisabled' : notification_disabled ,
148156 }
149157
158+ if custom_aggregation_units is not None :
159+ if not isinstance (custom_aggregation_units , (list , tuple )):
160+ custom_aggregation_units = [custom_aggregation_units ]
161+ data ['customAggregationUnits' ] = custom_aggregation_units
162+
150163 self ._post (
151164 '/v2/bot/message/push' , data = json .dumps (data ), timeout = timeout
152165 )
153166
154- def multicast (self , to , messages , retry_key = None , notification_disabled = False , timeout = None ):
167+ def multicast (self , to , messages , retry_key = None , notification_disabled = False ,
168+ custom_aggregation_units = None , timeout = None ):
155169 """Call multicast API.
156170
157171 https://developers.line.biz/en/reference/messaging-api/#send-multicast-message
@@ -169,6 +183,11 @@ def multicast(self, to, messages, retry_key=None, notification_disabled=False, t
169183 :param retry_key: (optional) Arbitrarily generated UUID in hexadecimal notation.
170184 :param bool notification_disabled: (optional) True to disable push notification
171185 when the message is sent. The default value is False.
186+ :param custom_aggregation_units: (optional) Name of aggregation unit. Case-sensitive.
187+ Max unit: 1
188+ Max aggregation unit name length: 30 characters
189+ Supported character types: Half-width alphanumeric characters and underscore
190+ :type custom_aggregation_units: str | list[str]
172191 :param timeout: (optional) How long to wait for the server
173192 to send data before giving up, as a float,
174193 or a (connect timeout, read timeout) float tuple.
@@ -187,6 +206,11 @@ def multicast(self, to, messages, retry_key=None, notification_disabled=False, t
187206 'notificationDisabled' : notification_disabled ,
188207 }
189208
209+ if custom_aggregation_units is not None :
210+ if not isinstance (custom_aggregation_units , (list , tuple )):
211+ custom_aggregation_units = [custom_aggregation_units ]
212+ data ['customAggregationUnits' ] = custom_aggregation_units
213+
190214 self ._post (
191215 '/v2/bot/message/multicast' , data = json .dumps (data ), timeout = timeout
192216 )
@@ -1718,6 +1742,75 @@ def get_channel_token_key_ids_v2_1(
17181742 timeout = timeout )
17191743 return ValidAccessTokenKeyIDsResponse .new_from_json_dict (response .json )
17201744
1745+ def get_statistics_per_unit (self , custom_aggregation_unit , from_date , to_date , timeout = None ):
1746+ """Return statistics about how users interact with push and multicast messages.
1747+
1748+ https://developers.line.biz/en/reference/partner-docs/#get-statistics-per-unit
1749+
1750+ :param str custom_aggregation_unit: Name of aggregation unit specified when sending
1751+ the message like `push_message(...)` and `multicast(...)`.
1752+ :param str from_date: Start date of aggregation period.
1753+ The format is `yyyyMMdd` (Timezone is UTC+9).
1754+ :param str to_date: End date of aggregation period.
1755+ The end date can be specified for up to 30 days later.
1756+ The format is `yyyyMMdd` (Timezone is UTC+9).
1757+ :param timeout: (optional) How long to wait for the server
1758+ to send data before giving up, as a float,
1759+ or a (connect timeout, read timeout) float tuple.
1760+ Default is self.http_client.timeout
1761+ :type timeout: float | tuple(float, float)
1762+ :rtype: :py:class:
1763+ `linebot.models.responses.InsightMessageEventOfCustomAggregationUnitResponse`
1764+ """
1765+ response = self ._get (
1766+ '/v2/bot/insight/message/event/aggregation?'
1767+ 'customAggregationUnit={custom_aggregation_unit}&from={from_date}&to={to_date}' .format (
1768+ custom_aggregation_unit = custom_aggregation_unit ,
1769+ from_date = from_date , to_date = to_date ),
1770+ timeout = timeout
1771+ )
1772+
1773+ return InsightMessageEventOfCustomAggregationUnitResponse .new_from_json_dict (response .json )
1774+
1775+ def get_number_of_units_used_this_month (self , timeout = None ):
1776+ """Return the number of aggregation units used this month.
1777+
1778+ https://developers.line.biz/en/reference/partner-docs/#get-number-of-units-used-this-month
1779+
1780+ :param timeout: (optional) How long to wait for the server
1781+ to send data before giving up, as a float,
1782+ or a (connect timeout, read timeout) float tuple.
1783+ Default is self.http_client.timeout
1784+ :type timeout: float | tuple(float, float)
1785+ :rtype: :py:class: `linebot.models.responses.AggregationInfoResponse`
1786+ """
1787+ response = self ._get ('/v2/bot/message/aggregation/info' , timeout = timeout )
1788+ return AggregationInfoResponse .new_from_json_dict (response .json )
1789+
1790+ def get_name_list_of_units_used_this_month (self , limit = 100 , start = None , timeout = None ):
1791+ """Return the name list of units used this month for statistics aggregation.
1792+
1793+ :param int limit: Maximum number of aggregation units you can get per request.
1794+ If you don't specify a value, or if you specify a value greater than or equal to 100,
1795+ the maximum is 100.
1796+ :param str start: Get the next array of name list of units
1797+ :param timeout: (optional) How long to wait for the server
1798+ to send data before giving up, as a float,
1799+ or a (connect timeout, read timeout) float tuple.
1800+ Default is self.http_client.timeout
1801+ :type timeout: float | tuple(float, float)
1802+ :rtype: :py:class: `linebot.models.responses.AggregationNameListResponse`
1803+ """
1804+ params = {'limit' : limit } if start is None else {'limit' : limit , 'start' : start }
1805+
1806+ response = self ._get (
1807+ '/v2/bot/message/aggregation/list' ,
1808+ params = params ,
1809+ timeout = timeout
1810+ )
1811+
1812+ return AggregationNameListResponse .new_from_json_dict (response .json )
1813+
17211814 def _get (self , path , endpoint = None , params = None , headers = None , stream = False , timeout = None ):
17221815 url = (endpoint or self .endpoint ) + path
17231816
0 commit comments