Capture WhatsApp Messages from a group
We have agents that are receiving requests to buy products over whatsapp groups. A group includes many agents from many companies, all competing for the same business. We would like to capture the messages that are posted to these groups and send them to our CRM via an API so we can process them quickly. How can this be achieved?
This is only possible through unofficial API gateways that provide group handling. Cloud API does not have the ability to interact with groups in any way, unfortunately. Before you can send a message to CRM, you will need to receive it somehow. Depending on the WhatsApp API you use, the mechanism may be different, I'll give you an example of what I use myself (my project is different, but I think you'll get the gist)
# Get a list of all groups, if you work with several groups, for example def get_groups(token): url = f"https://gate.whapi.cloud/groups?token={token}" headers = {"accept": "application/json"} response = requests.get(url, headers=headers) if response.status_code == 200: return json.loads(response.text).get('groups', []) else: print(f"Failed to get groups. Status code: {response.status_code}") return [] # Receive messages from a certain group def get_group_messages(group_id, token): url = f"https://gate.whapi.cloud/messages/list/{group_id}?token={token}" headers = {"accept": "application/json"} response = requests.get(url, headers=headers) if response.status_code == 200: return json.loads(response.text).get('messages', []) else: print(f"Failed to get messages from group {group_id}. Status code: {response.status_code}") return [] # Sending messages to CRMthanks @Hafiz. where do I get the token from? Also, can this be done in realtime or it must run on a schedule?
The work happens in real time. You only need to configure the webhook to accept the message and you will receive the information instantly. They have an article in their knowledge base about how to get real-time messages. The gateway itself is paid, but I thought I found the cheapest one on the market. You can take a closer look at this service, but there are analogs.