Posts under category Facebook WhatsApp Business API

I am using the WhatsApp Business API for a chatbot. I am writing an app review for whatsapp_business_messaging but it keeps getting rejected. Following is the note from the reviewer

Hi,While reviewing the submission we found that the Send and receive messages,Managing customer accounts are not shown in the screencasts, please recheck and submit.

The screencast that was submitted showcased sending and receiving of messages (conversation with the bot). However, I am not able to understand the meaning of "Managing customer accounts". Can anyone please help me out here?

For reference:

Review feedback for whatsapp_business_messaging permission -

App rejected - Unable to determine use case details Developer Policy 1.9 - Build a quality product We were unable to approve your request for this permission because the explanation of your app's use case was unclear. To resolve this issue, please provide a valid use case with a revised screencast or notes that explain the following items:

  1. Which app function requires the requested permission.
  2. How the requested permission will enhance your app's functionality and integration.
  3. How the requested permission will enhance the end user's experience. You should also make sure that the screencast submitted is the correct video for the app before you re-submit for review. For more information, you can also view our App Review introduction video and App Review Rejection Guide. Notes from your reviewer: Hi,While reviewing the submission we found that the Send and receive messages,Managing customer accounts are not shown in the screencasts, please recheck and submit.

Following is the description of the permission usage that I have written:

The whatsapp_business_messaging permission will be used for sending out the responses to the user. These responses will be created by our Large Language Model (LLM) backend and get sent back to the user using the whatsapp_business_messaging permission. The “/messages” endpoint will act like a mailman to deliver messages to the user. The requested permission will help in developing a two-way communication with the end user allowing them to have an interactive experience with the chatbot. We will leverage the whatsapp_business_messaging permission to promptly respond to user queries in real-time, facilitating a smoother and more user-friendly interaction via WhatsApp.

I'm having issues trying to download media files from the WhatsApp Business API. Following along with their documentation (https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#download-media) they provide a cURL command that is successful in downloading a media file when used - however, the same request (I think) when done using NodeJS' fetch returns text/html responses with vague error wording and a 200 status code.

# Successful cURL: curl "https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=281274211304477&ext=1705672414&hash=ATtH6AOGFu0RqEpENicHUg8HCUkVfwGzfrHVCdiE7J8AUA" --header "Authorization: Bearer ..." 
// Successful cURL from child_process.exec: exec(   `curl --location "${mediaURL}" --header "Authorization: Bearer ..."` ); 
// Unsuccessful fetch: fetch(   "https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=281274211304477&ext=1705672414&hash=ATtH6AOGFu0RqEpENicHUg8HCUkVfwGzfrHVCdiE7J8AUA",   { headers: { Authorization: "Bearer ..." } } ); 

Suggestion from WhatsApp Cloud API Receiving Images from Users Error is also unsuccessful, unfortunately:

// Also unsuccessful fetch: fetch("https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=281274211304477&ext=1705672414&hash=ATtH6AOGFu0RqEpENicHUg8HCUkVfwGzfrHVCdiE7J8AUA", {   headers: {     Authorization: "Bearer ...",     "User-Agent": "curl/7.64.1",   }, }) 

Note: The lookaside.fbsbx.com URLs are all retrieved successfully from the WhatsApp Business APIs.

Per the documentation, a 404 error should occur if the link has expired, however, this isn't the case - and the access token hasn't expired either. Looking through the Community Forums, specifically https://developers.facebook.com/community/threads/1367000994138329/?join_id=f25971b6b4f9cc4, many conversations suggest that the User-Agent header should be spoofed - yet this doesn't seem to work either, although tweaking the User-Agent header within Postman yields varying results.

Successful in Postman:

Unsuccessful when User-Agent is adjusted in Postman:

Unsuccessful when User-Agent is removed in Postman:

Any suggestions would be greatly appreciated. I was unable to use the Meta for Developers' "Report a bug" forms as support appears to be unavailable for WhatsApp Business APIs.

Also seen posts: 1, 2 on StackOverflow; 1, 2, 3, 4, 5, 6 on Meta Support Forums.

I am working on a project using FastAPI to handle incoming WhatsApp messages and respond to them. I've set up the webhook, and I can successfully receive messages. However, I'm encountering issues when trying to send a response back to the user using the WhatsApp Business API.

Here is the relevant part of my code:

from fastapi import FastAPI, Request, HTTPException, Query from fastapi.responses import JSONResponse from pydantic import BaseModel import requests app = FastAPI() VERIFY_TOKEN = "tourism"   class WhatsAppEvent(BaseModel):     message: dict WHATSAPP_API_ENDPOINT = "https://graph.facebook.com/v18.0/***(Entered my phone number ID)/messages" WHATSAPP_API_TOKEN = "***(Entered my API access token)" @app.post("/") async def handle_post_request(request: Request):     # Process the incoming POST request here     data = await request.json()     print("Received POST request data:", data)     # Send a response     return {"status": "success", "message": "POST request received"} @app.get("/") def verify(request: Request):     mode = request.query_params.get('hub.mode')     challenge = request.query_params.get('hub.challenge')     token = request.query_params.get('hub.verify_token')     if mode and token:         if mode == 'subscribe' and token == VERIFY_TOKEN:             print("WEBHOOK_VERIFIED")             return JSONResponse(content=int(challenge), status_code=200)         else:             raise HTTPException(status_code=403, detail="Verification failed")     return {"code": 200, 'message': 'test'} @app.post("/incoming-message") def receive_message(event: WhatsAppEvent):     try:         user_message = event.message['text']         sender_id = event.message['sender']['id']         bot_response = f'You said: {user_message}' #sending an echo message                  # Prepare response for WhatsApp         response_data = {             'recipient': {'id': sender_id},             'message': {'text': bot_response}         }         send_whatsapp_message(sender_id, bot_response)         return JSONResponse(content=response_data, status_code=200)     except Exception as e:         raise HTTPException(status_code=500, detail=f"Error processing message: {str(e)}")      def send_whatsapp_message(recipient_id, message_body):     headers = {         'Authorization': f'Bearer {WHATSAPP_API_TOKEN}',         'Content-Type': 'application/json'     }     data = {         'phone': recipient_id,         'message': {             'text': message_body         }     }     try:         response = requests.post(WHATSAPP_API_ENDPOINT, headers=headers, json=data)         response.raise_for_status()  # Raises HTTPError for bad responses         print("WhatsApp API response:", response.text)  # Add this line for debugging         return response.json()  # If you want to return the API response data     except requests.exceptions.HTTPError as errh:         print("HTTP Error:", errh)         raise HTTPException(status_code=response.status_code, detail=f"HTTP Error: {errh}")     except requests.exceptions.RequestException as err:         print("Request Error:", err)         raise HTTPException(status_code=response.status_code, detail=f"Request Error: {err}") if __name__ == "__main__":     import uvicorn     uvicorn.run(app, reload=False, host="0.0.0.0", port=8000) 

I have verified that the webhook is working (WEBHOOK_VERIFIED is printed in the console), and I can see the incoming messages in the logs. However, the send_whatsapp_message function does not seem to be sending messages successfully.

The response from the WhatsApp API is as follows:

WEBHOOK_VERIFIED INFO:     2a03:2880:23ff:5::face:b00c:0 - "GET /?hub.mode=subscribe&hub.challenge=1310749767&hub.verify_token=tourism HTTP/1.1" 200 OK Received POST request data: {'object': 'whatsapp_business_account', 'entry': [{'id': '**(My ID)', 'changes': [{'value': {'messaging_product': 'whatsapp', 'metadata': {'display_phone_number': '**(My number)', 'phone_number_id': '**(My Phone number ID)'}, 'contacts': [{'profile': {'name': 'Rishikesh Dasari'}, 'wa_id': '**(recipient Number)'}], 'messages': [{'from': '**(recipient Number)', 'id': 'wamid.HBgMOTE5MzkwMzYwMjYyFQIAEhgWM0VCMEMyRUU3MzQ4Q0VCNjFGQUIzRgA=', 'timestamp': '1705643757', 'text': {'body': 'hello'}, 'type': 'text'}]}, 'field': 'messages'}]}]} INFO:     2a03:2880:20ff:b::face:b00c:0 - "POST / HTTP/1.1" 200 OK 

I have double-checked the WhatsApp API endpoint, token, and the structure of the request, but I'm still unable to send messages. I suspect there might be an issue with my send_whatsapp_message function.

Can someone please review the code and provide insights on what might be causing the problem? Additionally, if there's a better way to handle sending WhatsApp messages in FastAPI, I'm open to suggestions.