32
32
)
33
33
from .models .responses import (
34
34
Group , UserIds , RichMenuAliasResponse , RichMenuAliasListResponse , ChannelAccessTokens ,
35
- IssueChannelTokenResponseV2 , VerifyChannelTokenResponseV2 , ValidAccessTokenKeyIDsResponse
35
+ IssueChannelTokenResponseV2 , VerifyChannelTokenResponseV2 , ValidAccessTokenKeyIDsResponse ,
36
+ InsightMessageEventOfCustomAggregationUnitResponse , AggregationInfoResponse ,
37
+ AggregationNameListResponse
36
38
)
37
39
38
40
@@ -114,7 +116,8 @@ def reply_message(self, reply_token, messages, notification_disabled=False, time
114
116
115
117
def push_message (
116
118
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 ):
118
121
"""Call push message API.
119
122
120
123
https://developers.line.biz/en/reference/messaging-api/#send-push-message
@@ -129,6 +132,11 @@ def push_message(
129
132
:param retry_key: (optional) Arbitrarily generated UUID in hexadecimal notation.
130
133
:param bool notification_disabled: (optional) True to disable push notification
131
134
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]
132
140
:param timeout: (optional) How long to wait for the server
133
141
to send data before giving up, as a float,
134
142
or a (connect timeout, read timeout) float tuple.
@@ -147,11 +155,17 @@ def push_message(
147
155
'notificationDisabled' : notification_disabled ,
148
156
}
149
157
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
+
150
163
self ._post (
151
164
'/v2/bot/message/push' , data = json .dumps (data ), timeout = timeout
152
165
)
153
166
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 ):
155
169
"""Call multicast API.
156
170
157
171
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
169
183
:param retry_key: (optional) Arbitrarily generated UUID in hexadecimal notation.
170
184
:param bool notification_disabled: (optional) True to disable push notification
171
185
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]
172
191
:param timeout: (optional) How long to wait for the server
173
192
to send data before giving up, as a float,
174
193
or a (connect timeout, read timeout) float tuple.
@@ -187,6 +206,11 @@ def multicast(self, to, messages, retry_key=None, notification_disabled=False, t
187
206
'notificationDisabled' : notification_disabled ,
188
207
}
189
208
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
+
190
214
self ._post (
191
215
'/v2/bot/message/multicast' , data = json .dumps (data ), timeout = timeout
192
216
)
@@ -1718,6 +1742,75 @@ def get_channel_token_key_ids_v2_1(
1718
1742
timeout = timeout )
1719
1743
return ValidAccessTokenKeyIDsResponse .new_from_json_dict (response .json )
1720
1744
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
+
1721
1814
def _get (self , path , endpoint = None , params = None , headers = None , stream = False , timeout = None ):
1722
1815
url = (endpoint or self .endpoint ) + path
1723
1816
0 commit comments