facebookcallbackfacebook-messenger-botchalice

Can't verify facebook callback url or verify token using python chalice


@app.route('/webhook', methods=['GET'])
def webhook_verify():
    print('testing')
    # Get all query parameters from the GET request
    query_params = app.current_request.query_params

    # Log all parameter names and values
    logger.info('Query parameters received:')
    for param_name, param_value in query_params.items():
        print(f'{param_name}: {param_value}')

    hub_verify_token = query_params.get('hub.verify_token')
    hub_challenge = query_params.get('hub.challenge')

    if hub_verify_token == VERIFY_TOKEN:
        # Log a successful verification
        print('Webhook verification successful')
        return str(query_params.get("hub.challenge")), 200  # 200 OK
    
    # Log an unsuccessful verification
    print('Webhook verification failed: Wrong verify token')
    return {'error': 'Wrong verify token'}, 403  # 403 Forbidden

Here's the code that handles the webhook

And then I verify the callback url in the facebook developers page. It then says

The callback URL or verify token couldn't be validated. Please verify the provided information or try again later.

But, when looking at the cloudwatch logs, it shows this: Logs showing that verification token is correct

It shows that verification token is correct, and returns a 200 response. So, I'm confused why it shows there's an error on the facebook developer page

What I've tried: Looking at other return response formats of other python facebook messenger repositories and following that format, but no luck.


Solution

  • From

            return str(query_params.get("hub.challenge")), 200  # 200 OK
    

    To

            return str(query_params.get("hub.challenge"))
    

    Turns out, using chalice for facebook webhooks for 200 requests doesn't need to be stated. Works now after changing that