An auto-responder for WhatsApp Web that runs entirely on your own machine. Selenium drives a Chrome window logged into WhatsApp Web, picks up the chats with unread messages, and replies with text from a local LLM running in Ollama. Nothing is sent to a cloud AI service.
It opens WhatsApp Web in Chrome, and every 10 seconds it checks the sidebar for chats with unread messages. For each one it opens the chat, reads the last message, sends it to the Ollama model, and types back the reply.
The main pieces:
| Function | What it does |
|---|---|
start_whatsapp() |
Starts Chrome (ChromeDriver comes from webdriver-manager) and opens WhatsApp Web |
get_chats_with_unread_messages() |
Finds the chats in the sidebar with unread messages |
open_chat() / get_today_messages() |
Opens a chat and reads its last message |
respond_with_ollama() |
Sends the message to the model and gets the reply |
send_message() |
Types the reply into the chat |
whatsapp_bot() |
The loop that ties it together |
You need Python 3.9+, Google Chrome and Ollama.
pip install -r requirements.txt
ollama pull llama3.2
python whats.pyChrome opens on WhatsApp Web. Scan the QR code with your phone (Linked devices in WhatsApp) within 15 seconds and the bot starts answering unread chats.
Want a different model? Set OLLAMA_MODEL (the default is llama3.2):
OLLAMA_MODEL=mistral python whats.pyA few rough edges, since this was a personal experiment:
- It expects WhatsApp Web in Italian. The message box is found by its Italian label
(
Scrivi un messaggio), so for another language you need to change thearia-labelinsend_message(). - The selectors are fragile. Unread chats and messages are located by WhatsApp Web's generated CSS class
names, and those change without warning. If it stops finding chats, open the page, inspect it and
update the class names in
get_chats_with_unread_messages()andget_today_messages(). - There's no memory. Only the last message of each chat goes to the model.
- If 15 seconds isn't enough to scan the QR code, bump up the
time.sleep()instart_whatsapp().
Automating WhatsApp Web isn't endorsed by WhatsApp and may go against its Terms of Service. This was a personal experiment, so use it only on your own account.