Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line bot doesn't reply any message #730

Open
snowuyl opened this issue Dec 31, 2024 · 0 comments
Open

Line bot doesn't reply any message #730

snowuyl opened this issue Dec 31, 2024 · 0 comments
Labels

Comments

@snowuyl
Copy link

snowuyl commented Dec 31, 2024

#!/usr/bin/env python

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='Access token from Line developer console')
handler = WebhookHandler('Channel secret from Line developer console')

@app.route("/callback", methods=['POST'])
def callback():
# get X-Line-Signature header value
signature = request.headers['X-Line-Signature']

# get request body as text
body = request.get_data(as_text=True)
app.logger.info("Request body: " + body)

# handle webhook body
try:
    handler.handle(body, signature)
except InvalidSignatureError:
    app.logger.info("Invalid signature. Please check your channel access token/channel secret.")
    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_with_http_info(
ReplyMessageRequest(
reply_token=event.reply_token,
messages=[TextMessage(text=event.message.text)]
)
)

if name == "main":
app.run()

System Informations

  • Python version: 3.9.21
  • SDK version: 3.14.2
  • OS: Rokcy Linux 9

Expected Behavior

Line Bot should reply any message.

Current Behavior

Line Bot doesn't reply any message.

Steps to Reproduce

  1. Running sample code from line-bot-sdk-python Github as shown above.
  2. Sending "Hi" from iPhone Line APP to Line Bot
  3. Line Bot doesn't reply any message.

Logs

./line_bot_test.py

  • Serving Flask app 'line_bot_test'
  • Debug mode: off
    WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
  • Running on http://127.0.0.1:5000
    Press CTRL+C to quit
@snowuyl snowuyl added the bug label Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant