28
28
MessageDeliveryPushResponse , MessageDeliveryReplyResponse ,
29
29
InsightMessageDeliveryResponse , InsightFollowersResponse , InsightDemographicResponse ,
30
30
InsightMessageEventResponse , BroadcastResponse , NarrowcastResponse ,
31
- MessageProgressNarrowcastResponse , BotInfo ,
31
+ MessageProgressNarrowcastResponse , BotInfo , GetWebhookResponse , TestWebhookResponse ,
32
32
)
33
33
from .models .responses import Group
34
34
@@ -1133,6 +1133,7 @@ def get_bot_info(self, timeout=None):
1133
1133
"""Get a bot's basic information.
1134
1134
1135
1135
https://developers.line.biz/en/reference/messaging-api/#get-bot-info
1136
+
1136
1137
:param timeout: (optional) How long to wait for the server
1137
1138
to send data before giving up, as a float,
1138
1139
or a (connect timeout, read timeout) float tuple.
@@ -1147,6 +1148,76 @@ def get_bot_info(self, timeout=None):
1147
1148
1148
1149
return BotInfo .new_from_json_dict (response .json )
1149
1150
1151
+ def set_webhook_endpoint (self , webhook_endpoint , timeout = None ):
1152
+ """Set the webhook endpoint URL.
1153
+
1154
+ https://developers.line.biz/en/reference/messaging-api/#set-webhook-endpoint-url
1155
+
1156
+ :param str webhook_endpoint: A valid webhook URL to be set.
1157
+ :param timeout: (optional) How long to wait for the server
1158
+ to send data before giving up, as a float,
1159
+ or a (connect timeout, read timeout) float tuple.
1160
+ Default is self.http_client.timeout
1161
+ :type timeout: float | tuple(float, float)
1162
+ :rtype: dict
1163
+ :return: Empty dict.
1164
+ """
1165
+ data = {
1166
+ 'endpoint' : webhook_endpoint
1167
+ }
1168
+
1169
+ response = self ._put (
1170
+ '/v2/bot/channel/webhook/endpoint' ,
1171
+ data = json .dumps (data ),
1172
+ timeout = timeout ,
1173
+ )
1174
+
1175
+ return response .json
1176
+
1177
+ def get_webhook_endpoint (self , timeout = None ):
1178
+ """Get information on a webhook endpoint.
1179
+
1180
+ https://developers.line.biz/en/reference/messaging-api/#get-webhook-endpoint-information
1181
+
1182
+ :rtype: :py:class:`linebot.models.responses.GetWebhookResponse`
1183
+ :return: Webhook information, including `endpoint` for webhook
1184
+ URL and `active` for webhook usage status.
1185
+ """
1186
+ response = self ._get (
1187
+ '/v2/bot/channel/webhook/endpoint' ,
1188
+ timeout = timeout ,
1189
+ )
1190
+
1191
+ return GetWebhookResponse .new_from_json_dict (response .json )
1192
+
1193
+ def test_webhook_endpoint (self , webhook_endpoint = None , timeout = None ):
1194
+ """Checks if the configured webhook endpoint can receive a test webhook event.
1195
+
1196
+ https://developers.line.biz/en/reference/messaging-api/#test-webhook-endpoint
1197
+
1198
+ :param webhook_endpoint: (optional) Set this parameter to
1199
+ specific the webhook endpoint of the webhook. Default is the webhook
1200
+ endpoint that is already set to the channel.
1201
+ :param timeout: (optional) How long to wait for the server
1202
+ to send data before giving up, as a float,
1203
+ or a (connect timeout, read timeout) float tuple.
1204
+ Default is self.http_client.timeout
1205
+ :type timeout: float | tuple(float, float)
1206
+ :rtype: :py:class:`linebot.models.responses.TestWebhookResponse`
1207
+ """
1208
+ data = {}
1209
+
1210
+ if webhook_endpoint is not None :
1211
+ data ['endpoint' ] = webhook_endpoint
1212
+
1213
+ response = self ._post (
1214
+ '/v2/bot/channel/webhook/test' ,
1215
+ data = json .dumps (data ),
1216
+ timeout = timeout ,
1217
+ )
1218
+
1219
+ return TestWebhookResponse .new_from_json_dict (response .json )
1220
+
1150
1221
def _get (self , path , endpoint = None , params = None , headers = None , stream = False , timeout = None ):
1151
1222
url = (endpoint or self .endpoint ) + path
1152
1223
@@ -1189,6 +1260,20 @@ def _delete(self, path, endpoint=None, data=None, headers=None, timeout=None):
1189
1260
self .__check_error (response )
1190
1261
return response
1191
1262
1263
+ def _put (self , path , endpoint = None , data = None , headers = None , timeout = None ):
1264
+ url = (endpoint or self .endpoint ) + path
1265
+
1266
+ if headers is None :
1267
+ headers = {'Content-Type' : 'application/json' }
1268
+ headers .update (self .headers )
1269
+
1270
+ response = self .http_client .put (
1271
+ url , headers = headers , data = data , timeout = timeout
1272
+ )
1273
+
1274
+ self .__check_error (response )
1275
+ return response
1276
+
1192
1277
@staticmethod
1193
1278
def __check_error (response ):
1194
1279
if 200 <= response .status_code < 300 :
0 commit comments