Skip to content

Commit 3ea1d87

Browse files
committed
Use unified client in README
1 parent 4fac244 commit 3ea1d87

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

README.rst

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
)
@@ -60,7 +58,7 @@ Usage:
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()
@@ -180,7 +176,7 @@ Add a **handler** method by using this decorator.
180176
181177
@handler.add(MessageEvent, message=TextMessage)
182178
def handle_message(event):
183-
line_bot_api.reply_message(
179+
line_bot_client.reply_message(
184180
ReplyMessageRequest(
185181
reply_token=event.reply_token,
186182
messages=[TextMessage(text=event.message.text)]
@@ -286,7 +282,7 @@ Thus, you can send a JSON designed with `Flex Message Simulator <https://develop
286282
287283
bubble_string = """{ type:"bubble", ... }"""
288284
message = FlexMessage(alt_text="hello", contents=FlexContainer.from_json(bubble_string))
289-
line_bot_api.reply_message(
285+
line_bot_client.reply_message(
290286
ReplyMessageRequest(
291287
reply_token=event.reply_token,
292288
messages=[message]
@@ -302,7 +298,7 @@ The ``x-line-accepted-request-id`` or ``content-type`` header can also be obtain
302298
303299
.. code:: python
304300
305-
response = line_bot_api.reply_message_with_http_info(
301+
response = line_bot_client.reply_message_with_http_info(
306302
ReplyMessageRequest(
307303
reply_token=event.reply_token,
308304
messages=[TextMessage(text='see application log')]
@@ -312,13 +308,13 @@ The ``x-line-accepted-request-id`` or ``content-type`` header can also be obtain
312308
app.logger.info("Got x-line-request-id: " + response.headers['x-line-request-id'])
313309
app.logger.info("Got response with http body: " + str(response.data))
314310
315-
You can get error messages from ``ApiException`` when you use ``MessagingApi``. Each client defines its own exception class.
311+
You can get error messages from ``ApiException`` when you use ``LineBotClient``. Each underlying client defines its own exception class.
316312
317313
.. code:: python
318314
319315
from linebot.v3.messaging import ApiException, ErrorResponse
320316
try:
321-
line_bot_api.reply_message_with_http_info(
317+
line_bot_client.reply_message_with_http_info(
322318
ReplyMessageRequest(
323319
reply_token='invalid-reply-token',
324320
messages=[TextMessage(text='see application log')]
@@ -365,7 +361,7 @@ If you keep using old line-bot-sdk library (``version < 3.x``) but use ``3.x``,
365361
366362
::
367363
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.
364+
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.
369365
370366
371367
If it's noisy, you can suppress this warning as follows.

0 commit comments

Comments
 (0)