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

Duplicate Responses from WhatsApp Chatbot #2

Open
yousseftarhri opened this issue Sep 7, 2024 · 0 comments
Open

Duplicate Responses from WhatsApp Chatbot #2

yousseftarhri opened this issue Sep 7, 2024 · 0 comments

Comments

@yousseftarhri
Copy link
Owner

Problem:

When someone sends a message to the WhatsApp chatbot, the bot sends duplicate responses in the chat. This seems to happen because of the current POST request structure or possibly some configuration in the WhatsApp API.

Steps to Reproduce:

  1. Send a message to the WhatsApp chatbot.
  2. Observe the duplicate responses in the chat.

Expected Behavior:

The bot should only send a single response for each user message.

Code Snippet:

@app.route('/', methods=["POST"])
def send_message():
    if request.method == 'POST':
        body = request.get_json()
        print(body)

        if body["entry"][0]["changes"][0]['value']["messages"][0]["from"] == PHONE_NUMBER:
            user_question = body["entry"][0]["changes"][0]['value']["messages"][0]["text"]["body"]

            response = ai_response(user_question)
            url = "https://graph.facebook.com/v18.0/115446774859882/messages"
            headers = {
                "Authorization": f"Bearer {WHAT_TOKEN}",
                "Content-Type": "application/json"
            }
            data = {
                "messaging_product": "whatsapp",
                "to": PHONE_NUMBER,
                "type": "text",
                "text": {"body": response}
            }

            response = requests.post(url, json=data, headers=headers)
            print(response.text)
            return Response(body, 200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant