Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🍽️ Forkable Lunch Ordering Automation with Stagehand

This project automates weekly lunch ordering on Forkable using Stagehand, an SDK for browser automation built on top of Playwright.

Features

  • Automatic Login: Multi-step authentication with environment variables
  • Smart Meal Selection: Analyzes and scores meals based on healthiness
  • Health Scoring System: Rates each meal from 1-10 based on nutritional value
  • Automated Ordering: Processes each weekday systematically
  • Order Summary: Provides a detailed summary with health indicators
  • Live Browser Session: Watch the automation in real-time via Browserbase

Meal Selection Logic

The script uses a health scoring system (1-10 scale):

  • 10: Salads with lots of vegetables
  • 8-9: Grilled proteins with vegetables, kabobs
  • 6-7: Bowls with balanced ingredients
  • 4-5: Sandwiches, wraps
  • 1-3: Fried foods, heavy pastas, burgers

For each day, the script:

  1. Clicks "Choose Another Meal" for that day
  2. Extracts all available meal options
  3. Assigns health scores to each meal
  4. Selects the highest-scoring (healthiest) option
  5. Adds it to the cart

Setting the Stage

Install Dependencies

npm install

Configure Environment Variables

Copy .env.example to .env and add your API keys:

cp .env.example .env && nano .env

Required environment variables:

  • BROWSERBASE_PROJECT_ID: Your Browserbase project ID
  • BROWSERBASE_API_KEY: Your Browserbase API key
  • OPENAI_API_KEY: Your OpenAI API key (for AI-powered element detection)
  • FORKABLE_EMAIL: Your Forkable login email
  • FORKABLE_PASSWORD: Your Forkable password

Curtain Call

Run the lunch ordering automation:

npm start

The script will:

  1. Open a browser session (watch live via the Browserbase URL)
  2. Navigate to https://forkable.com/mc/
  3. Log in with your credentials
  4. Navigate to the current week's lunch order
  5. Select healthy meals for each weekday
  6. Save the week's orders
  7. Display a summary of selected meals

Development

Build TypeScript

npm run build

Run on Local Browser

To run on a local browser instead of Browserbase, change env: "BROWSERBASE" to env: "LOCAL" in the index.ts file.

About Stagehand

Stagehand is an SDK for automating browsers with AI capabilities. It's built on top of Playwright and provides a higher-level API for better debugging and AI fail-safes.

Key features used in this project:

  • page.act(): Perform natural language actions on web pages
  • page.observe(): Discover and plan actions on web pages
  • page.extract(): Extract structured data from web pages

What's Next?

  • Schedule Daily Runs: Set up a cron job to run this script weekly
  • Meal Preferences: Add configuration for personal meal preferences
  • Diet Restrictions: Support for dietary restrictions (vegetarian, vegan, gluten-free)
  • Slack Notifications: Send meal selection summaries to Slack

Requirements

  • Node.js 16+
  • Browserbase account
  • OpenAI API key
  • Forkable account with access to lunch ordering

Troubleshooting

If you encounter issues:

  1. Ensure all environment variables are set correctly
  2. Check that your Forkable credentials are valid
  3. Verify your Browserbase and OpenAI API keys are active
  4. Watch the live browser session for debugging

About

Automatically order healthy lunches using Stagehand

Resources

Stars

9 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages