Access WhatsApp messages from the day using API
I am building an application using the WhatsApp Business Cloud API. Essentially I want to know if it's possible to build an application that collects all the messages from the day and downloads it. Specifically the media attached to it using the API. As far as I know you can use webhooks to get incoming messages. But in order to do this the application has to be run forever, and my cousin has a problem with this as it could cause problems to run an application forever vs just run it once a day. I'm able to send messages using the API and a python wrapper but that's much more simple than what I'm trying to do. Aditionally, there is an option of using selenium but that's not really an automated solution to what we're trying to do because everytime selenium executes the browser we'd need to log in using the QR code. If anyone has any idea if this is possible (or not possible) I'd be very appreciative!
from heyoo import WhatsApp import logging import requests from dotenv import load_dotenv from flask import Flask, request, make_response app = Flask(__name__) token = 'EAAVk5rqOCsABAAcPPrZC6GnlZAJuykdFIQd4DhkuRVNeGntfFOU5jaK4jG2yCZBS6i7kFQGk3kRvDP0fExBXRsFyqWUqfVVJsSxeQdcA9XHWpRuUsnnuwqLcZAQpwTiuoZCXv4ixCcHYlPEe6NGHupCalHvWw9NQRoZAVnegU5ZCBvX6eO9E8vyum1lQ2SSt7OuUpdpIkmkyBK8tiEL8rpGwM8RrqZA3A10ZD' messenger = WhatsApp(token, phone_number_id='100398242927044') messenger.send_message('Hey its JJ ', '1xxxxxxxx') logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" ) print("hello") @app.route("/", methods=["GET", "POST"]) def hook():
//some code that isn't working yet
I'm new to all of this stuff so I don't really know how to set up a webhook either but my cousin who's business I'm building this app for doesn't ideally want to use a webhook.
You can use ngrok server, which provides:
how to use ngrok to integrate your localhost app with WhatsApp by using Webhooks. WhatsApp webhooks can be used to notify an external application whenever specific events occur in your WhatsApp account
https://ngrok.com/docs/integrations/whatsapp/webhooks
Ngrok didn't works for Whatsapp, see more here: Ngrok webhooks not getting verified in Meta webhook's callbackurl
But you can use alternatives to reverse proxy your localhost (port 8000 as example):
ssh -R 80:localhost:8000 serveo.net