@@ -41,15 +41,13 @@ Usage:
4141 from flask import Flask, request, abort
4242
4343 from linebot.v3 import (
44+ LineBotClient,
4445 WebhookHandler
4546 )
4647 from linebot.v3.exceptions import (
4748 InvalidSignatureError
4849 )
4950 from linebot.v3.messaging import (
50- Configuration,
51- ApiClient,
52- MessagingApi,
5351 ReplyMessageRequest,
5452 TextMessage
5553 )
6058
6159 app = Flask(__name__ )
6260
63- configuration = Configuration( access_token = ' YOUR_CHANNEL_ACCESS_TOKEN' )
61+ line_bot_client = LineBotClient( channel_access_token = ' YOUR_CHANNEL_ACCESS_TOKEN' )
6462 handler = WebhookHandler(' YOUR_CHANNEL_SECRET' )
6563
6664
@@ -85,14 +83,12 @@ Usage:
8583
8684 @handler.add (MessageEvent, message = TextMessageContent)
8785 def handle_message (event ):
88- with ApiClient(configuration) as api_client:
89- line_bot_api = MessagingApi(api_client)
90- line_bot_api.reply_message_with_http_info(
91- ReplyMessageRequest(
92- reply_token = event.reply_token,
93- messages = [TextMessage(text = event.message.text)]
94- )
86+ line_bot_client.reply_message(
87+ ReplyMessageRequest(
88+ reply_token = event.reply_token,
89+ messages = [TextMessage(text = event.message.text)]
9590 )
91+ )
9692
9793 if __name__ == " __main__" :
9894 app.run()
@@ -122,6 +118,7 @@ WebhookParser
122118 parser = linebot.v3.WebhookParser(
123119 ' YOUR_CHANNEL_SECRET' ,
124120 skip_signature_verification = lambda : False
121+ )
125122
126123 parse(self, body, signature, as_payload=False)
127124^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -141,7 +138,7 @@ If the signature does NOT match, ``InvalidSignatureError`` is raised.
141138 payload = parser.parse(body, signature, as_payload = True )
142139
143140 for event in payload.events:
144- do_something(payload. event, payload.destination)
141+ do_something(event, payload.destination)
145142
146143 WebhookHandler
147144~~~~~~~~~~~~~~
@@ -159,6 +156,7 @@ WebhookHandler
159156 handler = linebot.v3.WebhookHandler(
160157 ' YOUR_CHANNEL_SECRET' ,
161158 skip_signature_verification = lambda : False
159+ )
162160
163161 handle(self, body, signature)
164162^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -178,16 +176,16 @@ Add a **handler** method by using this decorator.
178176
179177.. code :: python
180178
181- @ handler.add(MessageEvent, message = TextMessage )
179+ @handler.add (MessageEvent, message = TextMessageContent )
182180 def handle_message (event ):
183- line_bot_api .reply_message(
181+ line_bot_client .reply_message(
184182 ReplyMessageRequest(
185183 reply_token = event.reply_token,
186184 messages = [TextMessage(text = event.message.text)]
187185 )
188186 )
189187
190- When the event is an instance of MessageEvent and event.message is an instance of TextMessage ,
188+ When the event is an instance of MessageEvent and event.message is an instance of TextMessageContent ,
191189this handler method is called.
192190
193191.. code :: python
@@ -286,7 +284,7 @@ Thus, you can send a JSON designed with `Flex Message Simulator <https://develop
286284
287285 bubble_string = """ { type:"bubble", ... }"""
288286 message = FlexMessage(alt_text = " hello" , contents = FlexContainer.from_json(bubble_string))
289- line_bot_api .reply_message(
287+ line_bot_client .reply_message(
290288 ReplyMessageRequest(
291289 reply_token = event.reply_token,
292290 messages = [message]
@@ -302,7 +300,7 @@ The ``x-line-accepted-request-id`` or ``content-type`` header can also be obtain
302300
303301.. code :: python
304302
305- response = line_bot_api .reply_message_with_http_info(
303+ response = line_bot_client .reply_message_with_http_info(
306304 ReplyMessageRequest(
307305 reply_token = event.reply_token,
308306 messages = [TextMessage(text = ' see application log' )]
@@ -312,13 +310,13 @@ The ``x-line-accepted-request-id`` or ``content-type`` header can also be obtain
312310 app.logger.info(" Got x-line-request-id: " + response.headers[' x-line-request-id' ])
313311 app.logger.info(" Got response with http body: " + str (response.data))
314312
315- You can get error messages from `` ApiException`` when you use `` MessagingApi `` . Each client defines its own exception class .
313+ You can get error messages from ``ApiException `` when you use ``LineBotClient ``. Each underlying client defines its own exception class.
316314
317315.. code :: python
318316
319317 from linebot.v3.messaging import ApiException, ErrorResponse
320318 try :
321- line_bot_api .reply_message_with_http_info(
319+ line_bot_client .reply_message_with_http_info(
322320 ReplyMessageRequest(
323321 reply_token = ' invalid-reply-token' ,
324322 messages = [TextMessage(text = ' see application log' )]
@@ -365,7 +363,7 @@ If you keep using old line-bot-sdk library (``version < 3.x``) but use ``3.x``,
365363
366364::
367365
368- LineBotSdkDeprecatedIn30: Call to deprecated method get_bot_info. (Use ' from linebot.v3.messaging import MessagingApi ' and ' MessagingApi (...).get_bot_info(...)' instead. See https:// github.com/ line/ line- bot- sdk- python/ blob/ master/ README .rst for more details.) -- Deprecated since version 3.0 .0.
366+ LineBotSdkDeprecatedIn30: Call to deprecated method get_bot_info. (Use 'from linebot.v3 import LineBotClient ' and 'LineBotClient (...).get_bot_info(...)' instead. See https://github.com/line/line-bot-sdk-python/blob/master/README.rst for more details.) -- Deprecated since version 3.0.0.
369367
370368
371369If it's noisy, you can suppress this warning as follows.
0 commit comments