whatsappwhatsapp-cloud-api

Getting message sent directly from Whatsapp instead of Whatsapp Bussines API


I'm facing some problems developing an internal chat for a client. I've already looked at some posts here saying that there is no way to make this work. So instead of asking a generic question I'm going to open up my problem so that if anyone has difficulty with this in the future, they can check possible solutions.

Basically my client has 3 phones in 3 buildings and wants to have access to the WhatsApp conversation on each of the phones. I'm working with the official WhatsApp API and I can send and receive messages with this API. The problem is:

When one of the employees sends a message directly from WhatsApp, the response that my endpoint receives does not contain the message sent itself. I will show the return JSON below.

The only thing I can think of is to try a get method using wamid, which is a unique WhatsApp message ID. But unfortunately the Whats API does not allow this. Can anyone think of a solution so that I can save the message sent and import it into my database, so that it goes to the internal chat?

Maybe build a mobile app with this integration, but developing some WhatsApp replica should not be the optimal solution lmao

{
  "_id": {
    "$oid": "65d6098e02eea5099ba46d00"
  },
  "object": "whatsapp_business_account",
  "entry": [
    {
      "id": "178770005328586",
      "changes": [
        {
          "value": {
            "messaging_product": "whatsapp",
            "metadata": {
              "display_phone_number": "15551337772",
              "phone_number_id": "209170728947400"
            },
            "statuses": [
              {
                "id": "wamid.HBgNNTUxOTk5OTQ1OTE2NRUCABEYEjBDOUFEQjZERDIyRTY5MUU3QQA=",
                "status": "read",
                "timestamp": "1708525966",
                "recipient_id": "5519999459165"
              }
            ]
          },
          "field": "messages"
        }
      ]
    }
  ]
}

Solution

  • Answering my own question for any future developer who may work with the whatsapp api.

    The whatsapp official api until this post date, does not provide a return message for the messages you send throw your own phone. So unfortunately your client will need to use only your personal chat, or, you will need to build a mobile app so his/her employee's use instead of the whatsapp.

    Besides this, there is another problem you will face: to offer a complete whatsapp experience, you WILL need the unique message_id of every message.

    So come with me: your customer writes a message in your app, and then send it.

    You need to save it in your database

    After the save, you send a post request to your whatsapp api.

    After the successfully post, you will receive a return with the json format that contains your unique id.

    To find the respective message, timestamp is not a good option, instead look for the oldest data without a upload status and then upload it adding the id and other data that you need.