This project consists of a Chrome extension and a Google Cloud Function designed to streamline the process of parsing orders from WhatsApp chats and organizing them into a Google Sheet.
The Chrome extension runs on WhatsApp Web, allowing users to select a message containing an item catalog. It then scrapes subsequent messages in the chat, assuming they contain orders based on the catalog. The scraped data is sent to a Google Cloud Function for processing.
The Google Cloud Function receives the scraped data, uses a Large Language Model (LLM, specifically Gemini in the current implementation) to parse the messages and extract structured order information based on the provided catalog. It then calculates summaries (Order Summary and Item Totals) and updates a specified Google Sheet using the Google Sheets API.
WAOrderParser/
├── .gitignore # Specifies intentionally untracked files
├── LICENSE # Project license (MIT)
├── README.md # This file
│
├── chrome-extension/ # Source code for the Chrome Extension
│ ├── manifest.json # Extension manifest file
│ ├── popup.html # HTML for the extension popup
│ ├── popup.js # JavaScript for the extension popup logic
│ ├── scraper.js # Content script for scraping WhatsApp Web
│ └── icons/ # Extension icons
│ └── icon128.png
│
└── gcp-function/ # Source code for the Google Cloud Function
├── main.py # Main Python code for the Cloud Function
├── prompts.yaml # YAML file containing prompts for the LLM
├── requirements.txt # Python dependencies
├── sheet_format.py # Helper for Google Sheet formatting
└── (Optional: deployment scripts/configs)
This project requires setting up both the Chrome Extension and the Google Cloud Function.
- Set up Google Cloud Project: If you don't have one, create a Google Cloud project. Enable the Google Sheets API and Google Drive API for your project.
- Create Service Account: Create a service account with the necessary permissions to access Google Sheets and Google Drive. Download the service account key as a JSON file.
- Share Google Sheet: Create a new Google Sheet (or use an existing one) where the parsed orders will be stored. Share this Google Sheet with the email address of the service account you created.
- Deploy the Cloud Function:
- Install the Google Cloud SDK (
gcloud). - Navigate to the
gcp-function/directory in your terminal. - Deploy the function using the
gcloud functions deploycommand. You will need to specify:- A function name (e.g.,
wa-order-parser). - The runtime (e.g.,
python39orpython310). - The trigger (e.g.,
--trigger-http). - Environment variables:
GEMINI_KEY: Your Gemini API key.GOOGLE_SHEET_NAME: The exact name of the Google Sheet you shared with the service account.
- The entry point (
message_parser). - Provide the service account key JSON file path during deployment or configure it afterwards.
- A function name (e.g.,
- Example deployment command (adjust region and other parameters as needed):
gcloud functions deploy wa-order-parser \ --runtime python39 \ --trigger-http \ --allow-unauthenticated \ --entry-point message_parser \ --set-env-vars GEMINI_KEY=YOUR_GEMINI_KEY,GOOGLE_SHEET_NAME="Your Google Sheet Name" \ --region=YOUR_REGION \ --service-account=YOUR_SERVICE_ACCOUNT_EMAIL - Note the Trigger URL provided after successful deployment. You will need this for the Chrome extension.
- Install the Google Cloud SDK (
- Load the Extension:
- Open Google Chrome.
- Go to
chrome://extensions/. - Enable "Developer mode" using the toggle switch in the top right corner.
- Click the "Load unpacked" button in the top left corner.
- Select the
chrome-extension/directory from this repository.
- Update Cloud Function URL:
- Open the
chrome-extension/scraper.jsfile in a text editor. - Find the line
const apiUrl = "YOUR_CLOUD_FUNCTION_URL"; - Replace
"YOUR_CLOUD_FUNCTION_URL"with the Trigger URL of your deployed Google Cloud Function. - Save the file.
- Go back to
chrome://extensions/, find the "WhatsApp Order Parser" extension, and click the refresh button (circular arrow icon) to reload the extension with the updated URL.
- Open the
- Open WhatsApp Web (
web.whatsapp.com) in your Chrome browser. - Navigate to the chat containing the orders you want to parse.
- Click on the "WhatsApp Order Parser" extension icon in your browser toolbar.
- In the extension popup, click the "Parse Orders" button.
- An alert will prompt you to click on the message that contains the item list or catalog. Click on that message in the WhatsApp chat.
- Confirm that you selected the correct message when prompted.
- Another alert will confirm that the data has been sent for processing.
- Check your configured Google Sheet. A new worksheet named with the current date (YYYY-MM-DD) should be created or updated with the parsed order summaries and item totals.
- Google Sheet Name: Configured via the
GOOGLE_SHEET_NAMEenvironment variable when deploying the Google Cloud Function. - Gemini API Key: Configured via the
GEMINI_KEYenvironment variable when deploying the Google Cloud Function. - Cloud Function URL: Hardcoded in
chrome-extension/scraper.js. You must manually update this file and reload the extension if your Cloud Function URL changes.
(Optional: Add details on how others can contribute to your project)
This project is licensed under the MIT License - see the LICENSE file for details.