Code Monkey home page Code Monkey logo

Comments (10)

okdtsk avatar okdtsk commented on June 26, 2024

HI, sorry for late response.
Could you tell us your way how to verify and error log if it was produced.
Thanks.

from line-bot-sdk-python.

laymonage avatar laymonage commented on June 26, 2024

It seems that you can't use the "Verify" button in console if you call the Reply API.

Using the same code as written in README.rst:

from flask import Flask, request, abort

from linebot import (
    LineBotApi, WebhookHandler
)
from linebot.exceptions import (
    InvalidSignatureError
)
from linebot.models import (
    MessageEvent, TextMessage, TextSendMessage,
)

app = Flask(__name__)

line_bot_api = LineBotApi('YOUR_CHANNEL_ACCESS_TOKEN')
handler = WebhookHandler('YOUR_CHANNEL_SECRET')


@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:
        abort(400)

    return 'OK'


@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
    line_bot_api.reply_message(
        event.reply_token,
        TextSendMessage(text=event.message.text))


if __name__ == "__main__":
    app.run()

or the flask-echo example app, verifying the Webhook in Console always returns the error saying that the server returns an invalid response.
However, deleting

    line_bot_api.reply_message(
        event.reply_token,
        TextSendMessage(text=event.message.text))

will make the verification successful, but of course the bot won't do anything when it receives a message.

In your example, the callback function will return 'ok get' (or 'ok post', I don't know why you wrote this) and exit right away, therefore handler.handle(body, signature) won't be processed and Reply API won't be called, and Webhook verification will succeed.

Question is:
Is it possible to do Webhook verification AND calling the Reply API at the same time?
(I think this is related to #37).

from line-bot-sdk-python.

mgilangjanuar avatar mgilangjanuar commented on June 26, 2024

Hmm I'll try to propose an idea to fix this issue. Currently, my PR #80 failed in CI.

from line-bot-sdk-python.

trumad avatar trumad commented on June 26, 2024

I am also facing this issue. The bot will not join any group chat without webhook working properly, as well as the verify button not working properly in the development console. Would be great if this could be fixed!

from line-bot-sdk-python.

be-hase avatar be-hase commented on June 26, 2024

Because the replyToken and userId contained in the verify button are dummy data, if you use API to call it, it becomes error.
This button is used for confirming the connection. (Including SSL setting)

from line-bot-sdk-python.

trumad avatar trumad commented on June 26, 2024

To clarify, you think that only the Verify button is broken and webhook does actually work? Is there another reason the bot won't join group chats? And why does the verify button work for the java version of the bot's sdk, but not the python sdk? @mgilangjanuar - do you think this issue should be closed, or does further work need to be done?

from line-bot-sdk-python.

be-hase avatar be-hase commented on June 26, 2024

Is there another reason the bot won't join group chats?

Could you check this setting ?
(Default is Disabled)

2018-01-10 15 32 31

And why does the verify button work for the java version of the bot's sdk, but not the python sdk?

Java SDK(with spring-boot) handles exception and always return 200.
If you want to do the same action in python, please handle the exception as follows.

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

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

    try:
        events = parser.parse(body, signature)
        for event in events:
            if not isinstance(event, MessageEvent):
                continue
            if not isinstance(event.message, TextMessage):
                continue

            line_bot_api.reply_message(
                event.reply_token,
                TextSendMessage(text=event.message.text)
            )
    except:
        # handle all exception
        print("Unexpected error:", sys.exc_info()[0])

    return 'OK'

from line-bot-sdk-python.

mgilangjanuar avatar mgilangjanuar commented on June 26, 2024

@trumad alternatively, you can install with pip install -e git+https://github.com/mgilangjanuar/line-bot-sdk-python.git@master#egg=line_bot_sdk 😆✌️

from line-bot-sdk-python.

trumad avatar trumad commented on June 26, 2024

Thanks guys for your quick replies. The bot is enabled for joining group chats, yes. I'll hopefully get a chance to work on this project again tomorrow night given this new information. Thanks!

from line-bot-sdk-python.

jayhot1 avatar jayhot1 commented on June 26, 2024

@be-hase i need your help i've emailed you my problem, can you please contact me ??

from line-bot-sdk-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.