Registry / communication / line

line

JSON →
library3.21.0pypypi✓ verified 53d ago

LINE Messaging API enables bot development for LINE, the dominant messaging platform in Japan, Thailand, and Taiwan with 196M+ monthly users. Official SDKs exist for Python and Node.js. Primary documentation is in Japanese — English docs are complete but may lag Japanese versions.

communication
pip install line-bot-sdk
Install & Compatibility
Where this runs
tested against v? · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 1.854s · 117.3MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 7.7s · import 1.670s · 189MB
156MB installed
● package 156MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WebhookHandler (Python v3)
from linebot.v3 import WebhookHandler
from linebot import WebhookHandler
linebot v2 imports (no .v3) still work but are legacy. All new code should use linebot.v3 namespace.
MessagingApi (Python v3)
from linebot.v3.messaging import Configuration, ApiClient, MessagingApi
from linebot import LineBotApi
LineBotApi is the v2 class. Replaced by MessagingApi in v3. Both still work but v3 is current.

Minimal LINE bot webhook handler using linebot.v3 SDK with Flask.

from flask import Flask, request, abort from linebot.v3 import WebhookHandler from linebot.v3.exceptions import InvalidSignatureError from linebot.v3.messaging import ( Configuration, ApiClient, MessagingApi, ReplyMessageRequest, TextMessage ) from linebot.v3.webhooks import MessageEvent, TextMessageContent app = Flask(__name__) configuration = Configuration(access_token='YOUR_CHANNEL_ACCESS_TOKEN') handler = WebhookHandler('YOUR_CHANNEL_SECRET') @app.route('/callback', methods=['POST']) def callback(): signature = request.headers['X-Line-Signature'] body = request.get_data(as_text=True) try: handler.handle(body, signature) except InvalidSignatureError: abort(400) return 'OK' @handler.add(MessageEvent, message=TextMessageContent) def handle_message(event): with ApiClient(configuration) as api_client: line_bot_api = MessagingApi(api_client) line_bot_api.reply_message( ReplyMessageRequest( reply_token=event.reply_token, messages=[TextMessage(text=event.message.text)] ) ) if __name__ == '__main__': app.run()
Debug
Known issues
breakingSignature verification is mandatory. Never process webhook events without verifying X-Line-Signature header using HMAC-SHA256 with your channel secret.
fix
Always call handler.handle(body, signature) and catch InvalidSignatureError. Abort 400 on failure.
affects: all
breakingDo not use body parsers (bodyParser.json, express.json) before LINE webhook middleware in Node.js. Pre-parsing the body breaks signature verification.
fix
Register LINE middleware before any body parser middleware on the webhook route
affects: all
breakingReply tokens are single-use and expire in 30 seconds. Storing and reusing a reply token will fail silently.
fix
Use push messages (push_message API) for delayed or async responses instead of reply tokens
affects: all
gotchaWebhook endpoint must return HTTP 200 within 30 seconds. LINE Platform retries failed webhooks if webhook redelivery is enabled.
fix
Process webhook events asynchronously. Return 200 immediately, handle events in background.
affects: all
gotchaChannel access token and channel secret are different credentials. Confusing them is the most common setup error.
fix
Channel secret → WebhookHandler constructor. Channel access token → Configuration/MessagingApi.
affects: all
gotchaNo error is returned when pushing messages to users who have blocked the bot. Delivery silently fails.
fix
Track opt-out webhook events to maintain your own block list and avoid unnecessary push API calls.
affects: all
gotchaContent from user messages (images, video, audio) must be fetched separately via GET /v2/bot/message/{messageId}/content using api-data.line.me domain, not api.line.me.
fix
Use https://api-data.line.me/v2/bot/message/{messageId}/content for binary content retrieval
affects: all
breakingMissing required Python packages (e.g., Flask, Django, etc.) will cause a `ModuleNotFoundError` when the application attempts to import them. This prevents the application from starting or functioning correctly.
fix
Ensure all necessary Python packages are installed in the environment where the script is executed. This can be done using `pip install <package_name>` for individual packages or `pip install -r requirements.txt` if a `requirements.txt` file is used to list dependencies.
affects: all
Errors
Common errors & fixes
InvalidSignatureError: <InvalidSignatureError [Invalid signature. signature=...]>
The webhook signature sent by the LINE Platform does not match the signature calculated by your bot server, often due to an incorrect Channel Secret or modifications to the request body before verification.
fix
Ensure the 'Channel Secret' in your bot application exactly matches the one in the LINE Developers Console, and use the raw request body without any modification (e.g., pretty-printing JSON) for signature validation with UTF-8 encoding.
LineBotApiError [Authentication failed due to the following reason: invalid token. Confirm that the access token in the authorization...]
The Channel Access Token used for API requests is invalid, expired, revoked, or incorrectly configured.
fix
Verify that the 'Channel Access Token' in your code is correct and currently valid in the LINE Developers Console. If it's a short-lived token, ensure it hasn't expired, and if it's been reissued or revoked, obtain a new valid token.
Request failed with status code 400
This error, often accompanied by an 'invalid replyToken', indicates an issue with the request payload sent to the LINE Messaging API, such as using an expired, already used, or incorrectly formatted reply token or message object.
fix
Ensure the 'reply_token' is used immediately after receiving the event and has not been used before, as reply tokens are single-use and time-sensitive. Also, verify that the message objects in your request adhere to the LINE Messaging API specifications.
ModuleNotFoundError: No module named 'linebot'
The 'line-bot-sdk' Python package has not been installed or is not accessible in the current Python environment.
fix
Install the library using pip: `pip install line-bot-sdk`. Confirm that your script is being executed within the Python environment where the package was installed.
LineBotSdkDeprecatedIn30: Call to deprecated method ... (Use 'from linebot.v3.messaging import MessagingApi' and 'MessagingApi(...)....' instead. See https://github.com/line/line-bot-sdk-python/blob/master/README.rst for more details.) -- Deprecated since version 3.0.0.
Your code is using older modules or methods from the `linebot` (version 2.x) namespace, but a newer version of the SDK (3.x) is installed, which has introduced a `v3` namespace with breaking changes.
fix
Update your imports and code to use the `linebot.v3` modules and classes as specified in the deprecation warning, adapting your code to the new API structure.
Upgrade
Version history
0.8.2latest on PyPI
Audit
Dependencies
flaskoptionalRequired for webhook server in Python examples. Any WSGI framework works.
Agent activity
59 hits · last 30 days
node
4
seranking-bot
4
bytedance
3
ahrefsbot
2
Resources