Every 5 minutes
Hear about every new Firestore document
A few minutes after a document lands in the collection you pick, you get its key fields in Slack or email.
- Runs
- Every 5 minutes
- Apps
- Firebase
- AI
- Not needed
- Access
- datastore read (Cloud Datastore Viewer)
Send this to your assistant
Create a ClickRuntime automation: every 5 minutes, check my Firestore 'orders' collection for documents newer than the last one by createdAt and post each new order's customer, total and status to #orders in Slack.
First time? Adding ClickRuntime to your assistant takes about two minutes.
Why use it
Why teams use this automation
In many apps, a new document in a Firestore collection means that something a human needs to see has happened: a support request, a refund request, a new lead from a contact form, a flagged post. The app saves it and moves on, and nobody is told. Staff discover the record when they next open an admin page, which may be hours later, while the customer who wrote in is still waiting.
Every five minutes, ClickRuntime runs a structured query on the collection, ordered by createdAt and starting after the last value it stored, and sends you the new documents. It then saves the latest timestamp as a cursor, so each document is reported once.
It is a good fit for apps without a built-in notification system, where the database is the only record of events.
What you get out of it
React to customer requests quickly
A support request or refund request that triggers a message within five minutes gets answered faster. Quick replies reduce churn and chargebacks from customers who feel ignored. Customers who feel heard stay longer.
Add alerts without changing app code
Developers do not have to write and deploy a notification feature. The alert reads the collection from outside, so releases stay small and the app's own code stays focused. Fewer deploys also means fewer chances to break something.
Catch problems from flagged content
If your app lets users report posts, a new report document alerts a moderator right away. Harmful content stays visible for minutes, not for the rest of the day. Moderators can then act in time.
Avoid missed and duplicate messages
The cursor means you are told once per document. If a run is delayed or the service restarts, the next run picks up from the saved point and nothing is skipped.
Make background activity visible
Teams often forget what the app records behind the scenes. Seeing new documents arrive helps non-technical staff understand what customers are doing and when. Understanding the product's real activity helps everyone.
How it works
What happens, step by step
Every five minutes ClickRuntime checks the Firestore collection you picked for documents created since its last check.
It posts the key fields of each new document to Slack or email.
It remembers where it stopped, so nothing is sent twice.
Before it runs live
- Connect Firebase
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 Firebase steps into one automation
Under the hood
The code that runs this automation
from clickruntime import on_trigger, credentials, http, notify, state, report_fetched
PROJECT = "acme-prod"
FS = f"https://firestore.googleapis.com/v1/projects/{PROJECT}/databases/(default)/documents"
def fs_headers():
return {"Authorization": f"Bearer {credentials.connection('google', 'work')}"}
def val(field):
return next(iter(field.values())) if field else None
@on_trigger
def run(event):
since = state.get("since") or "1970-01-01T00:00:00Z"
query = {"structuredQuery": {"from": [{"collectionId": "orders"}],
"where": {"fieldFilter": {"field": {"fieldPath": "createdAt"}, "op": "GREATER_THAN", "value": {"timestampValue": since}}},
"orderBy": [{"field": {"fieldPath": "createdAt"}}], "limit": 100}}
docs = [r["document"] for r in http.post(f"{FS}:runQuery", json=query, headers=fs_headers()).json() if "document" in r]
report_fetched(len(docs))
if not docs:
return {"new": 0}
for d in docs:
f = d["fields"]
notify.slack(f"New order: {val(f.get('customer'))}, {val(f.get('total'))}, {val(f.get('status'))}", channel="#orders")
state.set("since", docs[-1]["fields"]["createdAt"]["timestampValue"])
return {"new": len(docs)}FAQ
Common questions
Do documents need a creation timestamp?
What does the notification include?
Can I watch a subcollection?
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 new Realtime Database entries by email
New children under a database path reach your inbox shortly after they are written.
See how it worksGet a morning count of new users and orders
Each morning you see how many documents yesterday added to each collection, next to the day before.
See how it worksExport Firestore to Cloud Storage nightly
Your Firestore data is exported to a dated folder each night, and you are told if an export fails.
See how it worksKeep exploring
Set up “Hear about every new Firestore document” from your assistant
Copy the prompt above, or connect your assistant first. Free plan, no credit card.