Every 5 minutes
Reply to WhatsApp customers by replying to an email
When you reply in Gmail to a "WhatsApp from … (+number)" email, your reply text is sent to that customer on WhatsApp from your business number within 5 minutes.
- Runs
- Every 5 minutes
- Apps
- Gmail, WhatsApp Business
- AI
- Not needed
- Access
- Gmail read + modify; WhatsApp messaging
Send this to your assistant
Create a ClickRuntime automation: every 5 minutes, find emails I've sent in Gmail that reply to 'WhatsApp from … (+number)' threads, and send my reply text to that number on WhatsApp from my business number, then label the email Sent to WhatsApp.
First time? Adding ClickRuntime to your assistant takes about two minutes.
Why use it
Why teams use this automation
Getting WhatsApp messages into email solves half the problem. The other half is answering, and switching to a phone or a separate WhatsApp login for each reply slows the team down.
This watches your Gmail sent mail for replies to WhatsApp threads and sends the reply text to the customer on WhatsApp from your business number. The quoted part of the email is removed so the customer only sees your answer.
It suits support teams who already forward WhatsApp messages into a shared Gmail inbox and want to answer from there.
What you get out of it
Answer from the inbox you already use
Agents reply in Gmail as they would to any email. The customer gets the answer on WhatsApp.
No shared phone
Nobody needs to pass around a phone or a WhatsApp Business login to answer customers.
A copy of every answer
Each reply stays in Gmail's sent mail, in the same thread as the customer's message, so the full conversation is in one place.
Told when WhatsApp says no
Replies outside WhatsApp's 24-hour window are refused by WhatsApp. You get an email with the reason, so the customer is not left waiting without anyone knowing.
Sent once only
Each handled email is labelled, so a reply is never sent to the customer twice.
How it works
What happens, step by step
Every 5 minutes ClickRuntime looks in your Gmail sent mail for replies to WhatsApp message threads.
It reads the customer's number from the subject line.
Your reply is trimmed of the quoted text and sent to the customer on WhatsApp from your business number.
The email is labelled so it is never sent twice, and you are told by email if WhatsApp refuses the message.
Before it runs live
- Connect Google through your own Google app (a one-time, 10-minute setup), so it works with your own Gmail
- Connect WhatsApp Business
What you get
Build your own
Need it to work differently?
Your own rules
Conditions, thresholds, filters and exceptions, written the way you'd explain them to a colleague.
Any number of apps
One automation can read from one app and update several others. Over 248 apps are ready, and anything with an API works too.
AI where it helps
Summaries, classification, extraction and drafts use ClickRuntime's built-in AI, with no extra key.
On a schedule or on each event
Runs as often as every 5 minutes, or the moment an app sends an event, and keeps track of what it already handled.
Changes you can ask for
- Act only on the items that match your own rules, and skip the rest
- Add an AI step, for example to summarize, sort or draft a reply
- Add another app, for example also send it to Slack
- Combine it with other Gmail and WhatsApp Business steps into one automation
Under the hood
The code that runs this automation
import re, base64
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from clickruntime import on_trigger, credentials, http, notify, report_fetched
WA = "https://graph.facebook.com/v20.0/your-phone-number-id/messages"
gmail = lambda: build("gmail", "v1", credentials=Credentials(credentials.connection("google", "work")), cache_discovery=False).users()
LABEL = "Label_sent_to_whatsapp" # Gmail label ID for "Sent to WhatsApp"
QUERY = 'in:sent subject:"WhatsApp from" -label:sent-to-whatsapp newer_than:2d'
def plain_body(payload):
parts = payload.get("parts") or [payload]
for p in parts:
if p.get("mimeType") == "text/plain" and p["body"].get("data"):
return base64.urlsafe_b64decode(p["body"]["data"]).decode(errors="ignore")
if p.get("parts"):
found = plain_body(p)
if found:
return found
return ""
def strip_quote(text):
lines = []
for line in text.splitlines():
if line.startswith(">") or re.match(r"^On .+wrote:$", line.strip()):
break
lines.append(line)
return "\n".join(lines).strip()
@on_trigger
def run(event):
ids = [m["id"] for m in gmail().messages().list(userId="me", q=QUERY, maxResults=20).execute().get("messages", [])]
report_fetched(len(ids))
sent = 0
for i in ids:
m = gmail().messages().get(userId="me", id=i, format="full").execute()
subject = next(h["value"] for h in m["payload"]["headers"] if h["name"] == "Subject")
number = re.search(r"\(\+(\d{7,15})\)", subject)
text = strip_quote(plain_body(m["payload"]))
if number and text:
r = http.post(WA, headers={"Authorization": f"Bearer {credentials.secret('WHATSAPP_TOKEN')}"},
json={"messaging_product": "whatsapp", "to": number.group(1), "type": "text", "text": {"body": text[:4000]}})
if r.status_code >= 400:
notify.email_me(f"WhatsApp reply not sent to +{number.group(1)}",
f"WhatsApp said: {r.json().get('error', {}).get('message')}\n\nYour reply:\n{text}")
else:
sent += 1
gmail().messages().modify(userId="me", id=i, body={"addLabelIds": [LABEL]}).execute()
return {"sent": sent}FAQ
Common questions
Why might a reply not be delivered?
Do I need the forwarding automation as well?
Does my email signature get sent?
What permissions does it need?
Does it need AI?
How many runs does it use?
Can I change how it works?
Related
You might also like
Get urgent emails on WhatsApp
When an important email arrives, you get a WhatsApp message with a one-line summary, and the email is labelled in Gmail.
See how it worksGet critical alerts by email and WhatsApp
When one of your systems reports a failure, you get an email and a WhatsApp message, without repeats for the same problem.
See how it worksGet each new Stripe sale by email and WhatsApp
Every completed Stripe checkout sends you an email with the details and a WhatsApp message with the amount.
See how it worksKeep exploring
Set up “Reply to WhatsApp customers by replying to an email” from your assistant
Copy the prompt above, or connect your assistant first. Free plan, no credit card.