Skip to content

Commit b6d71b1

Browse files
authored
Feature: Add msg-use demo (#3103)
<!-- This is an auto-generated description by cubic. --> ## Summary by cubic Add a new WhatsApp message scheduler demo (msg-use) that lets users write natural-language instructions to schedule and send messages via WhatsApp Web. Includes scripts, docs, and examples to log in, test, and run the scheduler. - **New Features** - New example app: msg-use with login.py and scheduler.py - Parses natural language into contact, message, and time; supports immediate and scheduled sends - Test and debug modes, plus programmatic usage examples - Docs: new msg-use page (linked in docs.json) and README; ad-use docs updated with clone steps and a clearer warning <!-- End of auto-generated description by cubic. -->
2 parents 4966c9e + 893e3e2 commit b6d71b1

File tree

7 files changed

+546
-2
lines changed

7 files changed

+546
-2
lines changed

docs/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@
199199
"pages": [
200200
"examples/apps/ad-use",
201201
"examples/apps/vibetest-use",
202-
"examples/apps/news-use"
202+
"examples/apps/news-use",
203+
"examples/apps/msg-use"
203204
]
204205
}
205206
]

docs/examples/apps/ad-use.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ Export your Gemini API key, get it from: [Google AI Studio](https://makersuite.g
3434
export GOOGLE_API_KEY='your-google-api-key-here'
3535
```
3636

37+
Clone the repo and cd into the app folder
38+
```bash
39+
git clone https://github.com/browser-use/browser-use.git
40+
cd browser-use/examples/apps/ad-use
41+
```
42+
3743
## Normal Usage
3844

3945
```bash

docs/examples/apps/msg-use.mdx

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
title: "Msg-Use (WhatsApp Sender)"
3+
description: "AI-powered WhatsApp message scheduler using browser agents and Gemini. Schedule personalized messages in natural language."
4+
icon: "message"
5+
mode: "wide"
6+
---
7+
8+
<Note>
9+
This demo requires browser-use v0.7.7+.
10+
</Note>
11+
12+
<video
13+
controls
14+
className="w-full aspect-video rounded-xl"
15+
src="https://browser-use.github.io/media/demos/msg_use.mp4">
16+
</video>
17+
18+
## Features
19+
20+
1. Agent logs into WhatsApp Web automatically
21+
2. Parses natural language scheduling instructions
22+
3. Composes personalized messages using AI
23+
4. Schedules messages for future delivery or sends immediately
24+
5. Persistent session (no repeated QR scanning)
25+
26+
## Setup
27+
28+
Make sure the newest version of browser-use is installed:
29+
```bash
30+
pip install -U browser-use
31+
```
32+
33+
Export your Gemini API key, get it from: [Google AI Studio](https://makersuite.google.com/app/apikey)
34+
```bash
35+
export GOOGLE_API_KEY='your-gemini-api-key-here'
36+
```
37+
38+
Clone the repo and cd into the app folder
39+
```bash
40+
git clone https://github.com/browser-use/browser-use.git
41+
cd browser-use/examples/apps/msg-use
42+
```
43+
44+
## Initial Login
45+
46+
First-time setup requires QR code scanning:
47+
```bash
48+
python login.py
49+
```
50+
- Scan QR code when browser opens
51+
- Session will be saved for future use
52+
53+
## Normal Usage
54+
55+
1. **Edit your schedule** in `messages.txt`:
56+
```
57+
- Send "Hi" to Magnus on the 13.06 at 18:15
58+
- Tell hinge date (Camila) at 20:00 that I miss her
59+
- Send happy birthday message to sister on the 15.06
60+
- Remind mom to pick up the car next tuesday
61+
```
62+
63+
2. **Test mode** - See what will be sent:
64+
```bash
65+
python scheduler.py --test
66+
```
67+
68+
3. **Run scheduler**:
69+
```bash
70+
python scheduler.py
71+
72+
# Debug Mode - See the browser in action
73+
python scheduler.py --debug
74+
```
75+
76+
## Programmatic Usage
77+
78+
```python
79+
import asyncio
80+
from scheduler import schedule_messages
81+
82+
async def main():
83+
messages = [
84+
"Send hello to John at 15:30",
85+
"Remind Sarah about meeting tomorrow at 9am"
86+
]
87+
await schedule_messages(messages, debug=False)
88+
89+
asyncio.run(main())
90+
```
91+
92+
## Example Output
93+
94+
The scheduler processes natural language and outputs structured results:
95+
96+
```json
97+
[
98+
{
99+
"contact": "Magnus",
100+
"original_message": "Hi",
101+
"composed_message": "Hi",
102+
"scheduled_time": "2025-06-13 18:15"
103+
},
104+
{
105+
"contact": "Camila",
106+
"original_message": "I miss her",
107+
"composed_message": "I miss you ❤️",
108+
"scheduled_time": "2025-06-14 20:00"
109+
},
110+
{
111+
"contact": "sister",
112+
"original_message": "happy birthday message",
113+
"composed_message": "Happy birthday! 🎉 Wishing you an amazing day, sis! Hope you have the best birthday ever! ❤️🎂🎈",
114+
"scheduled_time": "2025-06-15 09:00"
115+
}
116+
]
117+
```
118+
119+
## Source Code
120+
121+
Full implementation: [https://github.com/browser-use/browser-use/tree/main/examples/apps/msg-use](https://github.com/browser-use/browser-use/tree/main/examples/apps/msg-use)

examples/apps/ad-use/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Automatically generate Instagram ads from any landing page using browser agents and Google's Nano Banana 🍌 image generation model.
44

55
> [!WARNING]
6-
> This demo requires browser-use v0.7.4+.
6+
> This demo requires browser-use v0.7.7+.
77
88
https://github.com/user-attachments/assets/7fab54a9-b36b-4fba-ab98-a438f2b86b7e
99

@@ -26,6 +26,12 @@ Export your Gemini API key, get it from: [Google AI Studio](https://makersuite.g
2626
export GOOGLE_API_KEY='your-google-api-key-here'
2727
```
2828

29+
Clone the repo and cd into the app folder
30+
```bash
31+
git clone https://github.com/browser-use/browser-use.git
32+
cd browser-use/examples/apps/ad-use
33+
```
34+
2935
## Normal Usage
3036

3137
```bash

examples/apps/msg-use/README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Msg-Use
2+
3+
AI-powered message scheduler using browser agents and Gemini. Schedule personalized messages in natural language and let AI compose them intelligently.
4+
5+
[!WARNING]
6+
This demo requires browser-use v0.7.7+.
7+
8+
https://browser-use.github.io/media/demos/msg_use.mp4
9+
10+
## Features
11+
12+
1. Agent logs into WhatsApp Web automatically
13+
2. Parses natural language scheduling instructions
14+
3. Composes personalized messages using AI
15+
4. Schedules messages for future delivery or sends immediately
16+
5. Persistent session (no repeated QR scanning)
17+
18+
## Setup
19+
20+
Make sure the newest version of browser-use is installed:
21+
```bash
22+
pip install -U browser-use
23+
```
24+
25+
Export your Gemini API key, get it from: [Google AI Studio](https://makersuite.google.com/app/apikey)
26+
```
27+
export GOOGLE_API_KEY='your-gemini-api-key-here'
28+
```
29+
30+
Clone the repo and cd into the app folder
31+
```bash
32+
git clone https://github.com/browser-use/browser-use.git
33+
cd browser-use/examples/apps/msg-use
34+
```
35+
36+
## Initial Login
37+
38+
First-time setup requires QR code scanning:
39+
```bash
40+
python login.py
41+
```
42+
- Scan QR code when browser opens
43+
- Session will be saved for future use
44+
45+
## Normal Usage
46+
47+
1. **Edit your schedule** in `messages.txt`:
48+
```
49+
- Send "Hi" to Magnus on the 09.09 at 18:15
50+
- Tell hinge date (Camila) at 20:00 that I miss her
51+
- Remind mom to pick up the car next tuesday
52+
```
53+
54+
2. **Test mode** - See what will be sent:
55+
```bash
56+
python scheduler.py --test
57+
```
58+
59+
3. **Run scheduler**:
60+
```bash
61+
python scheduler.py
62+
```
63+
64+
## Programmatic Usage
65+
66+
```python
67+
import asyncio
68+
from scheduler import schedule_messages
69+
70+
async def main():
71+
messages = [
72+
"Send hello to John at 15:30",
73+
"Remind Sarah about meeting tomorrow at 9am"
74+
]
75+
await schedule_messages(messages, debug=False)
76+
77+
asyncio.run(main())
78+
```
79+
80+
## Output
81+
82+
Example scheduling output:
83+
```json
84+
[
85+
{
86+
"contact": "Magnus",
87+
"original_message": "Hi",
88+
"composed_message": "Hi",
89+
"scheduled_time": "2025-06-13 18:15"
90+
},
91+
{
92+
"contact": "Camila",
93+
"original_message": "I miss her",
94+
"composed_message": "I miss you ❤️",
95+
"scheduled_time": "2025-06-14 20:00"
96+
}
97+
]
98+
```
99+
100+
## Files
101+
102+
- `scheduler.py` - Main scheduler script
103+
- `login.py` - One-time login setup
104+
- `messages.txt` - Your message schedule in natural language
105+
106+
## License
107+
108+
MIT

examples/apps/msg-use/login.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import asyncio
2+
import os
3+
from pathlib import Path
4+
5+
from browser_use import Agent, BrowserSession
6+
from browser_use.llm.google import ChatGoogle
7+
8+
GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
9+
10+
# Browser profile directory for persistence (same as main script)
11+
USER_DATA_DIR = Path.home() / '.config' / 'whatsapp_scheduler' / 'browser_profile'
12+
USER_DATA_DIR.mkdir(parents=True, exist_ok=True)
13+
14+
# Storage state file for cookies
15+
STORAGE_STATE_FILE = USER_DATA_DIR / 'storage_state.json'
16+
17+
18+
async def login_to_whatsapp():
19+
"""Open WhatsApp Web and wait for user to scan QR code"""
20+
if not GOOGLE_API_KEY:
21+
print('❌ Error: GOOGLE_API_KEY environment variable is required')
22+
print("Please set it with: export GOOGLE_API_KEY='your-api-key-here'")
23+
return
24+
25+
print('WhatsApp Login Setup')
26+
print('=' * 50)
27+
print(f'Browser profile directory: {USER_DATA_DIR}')
28+
print(f'Storage state file: {STORAGE_STATE_FILE}')
29+
print('=' * 50)
30+
31+
try:
32+
llm = ChatGoogle(model='gemini-2.0-flash-exp', temperature=0.3, api_key=GOOGLE_API_KEY)
33+
34+
task = """
35+
You are helping a user log into WhatsApp Web. Follow these steps:
36+
37+
1. Navigate to https://web.whatsapp.com
38+
2. Wait for the page to load completely
39+
3. If you see a QR code, tell the user to scan it with their phone
40+
4. Wait patiently for the login to complete
41+
5. Once you see the WhatsApp chat interface, confirm successful login
42+
43+
Take your time and be patient with page loads.
44+
"""
45+
46+
print('\nOpening WhatsApp Web...')
47+
print('Please scan the QR code when it appears.\n')
48+
49+
browser_session = BrowserSession(
50+
headless=False, # Show browser
51+
user_data_dir=str(USER_DATA_DIR), # Use persistent profile directory
52+
storage_state=str(STORAGE_STATE_FILE) if STORAGE_STATE_FILE.exists() else None, # Use saved cookies/session
53+
)
54+
55+
agent = Agent(task=task, llm=llm, browser_session=browser_session)
56+
57+
result = await agent.run()
58+
59+
print('\n✅ Login completed!')
60+
print("Note: For now, you'll need to scan the QR code each time.")
61+
print("We'll improve session persistence in a future update.")
62+
print('\nPress Enter to close the browser...')
63+
input()
64+
65+
except Exception as e:
66+
print(f'\n❌ Error during login: {str(e)}')
67+
print('Please try again.')
68+
69+
70+
if __name__ == '__main__':
71+
asyncio.run(login_to_whatsapp())

0 commit comments

Comments
 (0)