Skip to content

Parses item orders on whatsapp and organizes them in Google sheet

License

Notifications You must be signed in to change notification settings

bsmnyk/WAOrderParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WhatsApp Order Parser

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.

Project Structure

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)

Setup

This project requires setting up both the Chrome Extension and the Google Cloud Function.

1. Google Cloud Function Setup

  1. 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.
  2. 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.
  3. 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.
  4. 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 deploy command. You will need to specify:
      • A function name (e.g., wa-order-parser).
      • The runtime (e.g., python39 or python310).
      • 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.
    • 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.

2. Chrome Extension Setup

  1. 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.
  2. Update Cloud Function URL:
    • Open the chrome-extension/scraper.js file 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.

Usage

  1. Open WhatsApp Web (web.whatsapp.com) in your Chrome browser.
  2. Navigate to the chat containing the orders you want to parse.
  3. Click on the "WhatsApp Order Parser" extension icon in your browser toolbar.
  4. In the extension popup, click the "Parse Orders" button.
  5. 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.
  6. Confirm that you selected the correct message when prompted.
  7. Another alert will confirm that the data has been sent for processing.
  8. 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.

Configuration

  • Google Sheet Name: Configured via the GOOGLE_SHEET_NAME environment variable when deploying the Google Cloud Function.
  • Gemini API Key: Configured via the GEMINI_KEY environment 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.

Contributing

(Optional: Add details on how others can contribute to your project)

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Parses item orders on whatsapp and organizes them in Google sheet

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published