0

I have successfully created a facebook messenger bot using Graph API by following these two tutorials: https://www.pragnakalp.com/create-facebook-chatbot-using-python-tutorial-with-examples/

https://www.pragnakalp.com/build-an-automated-ai-powered-facebook-messenger-chatbot-with-chatgpt-using-flask/

The bot works great when I open the page messenger and have a talk with it. But it does not cater anyone other than me. I have also made the application live. I am new to this that's why I cannot really figure out the problem here. What steps am I missing? Why can't it reply to anyone else? This is my code

PAGE_ACCESS_TOKEN='EAAO------'
API = "https://graph.facebook.com/v17.0/me/messages?access_token="+PAGE_ACCESS_TOKEN

@app.route("/", methods=['GET'])
def fbverify():
    if request.args.get("hub.mode") == "subscribe" and request.args.get("hub.challenge"):
        if not request.args.get("hub.verify_token")==PAGE_ACCESS_TOKEN:
            return "Verification token missmatch", 403
        return request.args['hub.challenge'], 200
    return "Hello", 200


@app.route("/", methods=['POST'])
def fbwebhook():
    data = request.get_json()
    print(data)
    
        # Read messages from facebook messenger.
    message = data['entry'][0]['messaging'][0]['message']
    print(message)
    sender_id = data['entry'][0]['messaging'][0]['sender']['id']
    print(sender_id)
    if message['text']:
        # Response from chatbot_handler
        response_text = chatbot_handler(message['text'], chat_history)  
        
        request_body = {
            "recipient": {
                "id": sender_id
            },
            "message": {
                "text": response_text  # Use the response from chatbot_handler
            }
        }
        
        response = requests.post(API, json=request_body).json()
        return response

Any kind of help will be highly appreciated. Thanks!

AqashaT
  • 45
  • 1
  • 7

0 Answers0