◆ The Problem
A local tea shop owner had a simple but painful problem.
Customers loved his tea. But after visiting once, many never came back.
He had no app, no loyalty card, no customer database — and no way to encourage repeat visits. Large companies like Starbucks, Duolingo, and Myntra solve this exact problem with loyalty systems and streak mechanics. But those systems cost lakhs to build and maintain.
Small businesses are left out.
So I decided to fix that.
◆ The Inspiration
Before building, I looked at how big platforms keep users coming back:
- 🟢Duolingo — users return daily to maintain their learning streak
- ☕Starbucks Rewards — customers earn stars for every purchase and redeem them for free drinks
- 💼LinkedIn Games — daily puzzles like Queens and Pinpoint bring users back every day
- 🛍️Myntra (past campaign) — streak-style campaigns previously rewarded users for visiting the app daily to earn credits and discounts. The feature no longer exists but the concept proved effective.
All of these use the same core psychology: reward consistency.
My goal was to bring this exact logic to a local tea shop — using only tools that are free or nearly free.
◆ What I Built
An AI-powered customer loyalty system using:
| Tool | Role |
|---|---|
| Telegram Bot | Customer-facing interface |
| n8n | Workflow automation |
| AI Agent (Groq LLM) | Natural language extraction |
| Google Sheets | Customer database |
The concept is simple:
- Every 10 visits → customer earns a free tea
- A unique 6-digit code is generated every morning to verify real visits
- One visit counted per customer per day — no cheating
Important difference from Duolingo:
- Duolingo tracks consecutive daily streaks — miss one day and your streak resets to zero.
- This system tracks total visits — not calendar days.
- Customer visits today → Visit Count = 1
- Customer returns after 33 days → Visit Count = 2
- Customer returns after 2 days → Visit Count = 3
No daily pressure. No streak loss. Just consistent rewards for coming back — whenever the customer is ready.
This makes the system more practical and forgiving for real-world customers.
◆ How the System Works
» The Morning Routine (Workflow 1)
Every morning, n8n's Schedule Trigger runs automatically.
Here's what happens:
- A random 6-digit verification code is generated using the Edit Fields node
- The code is saved into Google Sheet (Sheet 1)
- The code is sent to the shopkeeper via Telegram
The shopkeeper writes this code on a board inside the shop — on the counter, menu card, or notebook. Only customers physically present in the shop can see it.
This is the fraud prevention layer. Simple but effective.
» The Customer Check-In Flow (Workflow 2)

When a customer opens the Telegram bot, the system checks whether they are a new or existing customer using their Telegram Chat ID.
● New Customer Flow
If the Chat ID is not found in the sheet:
- Bot asks the customer to share their name and mobile number
- Customer types naturally — for example: > "My name is Rahul Patil and my number is 9876543210"
- The AI Agent extracts name and mobile from the free text :
{
"name": "Rahul Patil",
"mobile": "9876543210"
}
4. Data is saved to Google Sheets automatically
No forms. No dropdowns. Just natural conversation.
● Existing Customer Flow
If the Chat ID already exists:
- Bot asks: "Please enter today's 6-digit code"
- Customer types the code they saw in the shop
- AI Agent extracts the code from the message:
{
"code": "582741"
}
4. System compares the entered code with today's generated code in the sheet
● Validation and Count Logic
Once the customer submits the code, the system runs two checks before recording the visit:
Check 1 — Is the code correct?
- If wrong → Bot replies: "Invalid code. Please enter the correct code."
- Visit count is NOT increased
Check 2 — Has the customer already visited today?
- System compares
Last Visit Datewith today's date - If already visited → Bot replies: "Today's count already completed. Come back tomorrow."
- This prevents abuse
If both checks pass:
- Visit count is incremented by 1
- Last Visit Date is updated in the sheet
- System checks:
Total Visits % 10 == 0 - If TRUE → Bot sends: "Congratulations! Today's tea is FREE 🎉"
- Otherwise → Normal success message with updated count
◆ Google Sheet Structure
The system uses two sheets:
Sheet 1 — Daily Code
| Column | Description |
|---|---|
| Date | Today's date |
| Code | 6-digit verification code |
Sheet 2 — Customer Data
| Column | Description |
|---|---|
| Chat ID | Telegram unique identifier |
| Name | Customer name |
| Mobile | Mobile number |
| Total Visits | Running visit count |
| Last Visit Date | Date of last valid visit |
⚠️ Important: Column names are case-sensitive in n8n's Google Sheets node. Make sure they match exactly.
◆ How to Set Up Your Telegram Bot
- Open Telegram and search for @botfather
- Send
/newbotand follow the instructions - BotFather will give you a bot token — save this for n8n
- To get your personal Chat ID (for sending the daily code to yourself), use the
@userinfobotor any Chat ID bot on Telegram - Add the bot token in n8n's Telegram credential settings
◆ Why AI Agents Instead of Traditional Chatbot Logic?
This is the most important design decision in the project.
Traditional chatbot flows in n8n require:
- Multiple wait/pause nodes
- Session state management
- Complex branching for each input
For example, a traditional flow would look like this:
Bot asks: "What is your name?" → wait for reply
Bot asks: "What is your mobile number?" → wait for reply
Bot asks: "Enter the 6-digit code" → wait for reply
Each wait requires a separate node and session tracking in n8n. If the user takes too long or sends an unexpected message, the flow breaks completely.
Telegram + n8n does not handle long conversational waits well. The workflow gets complicated fast.
Instead, I used an AI Agent with a single prompt that extracts structured data from any natural input in one call.
For registration:
Input: "I am Saurabh, my mobile is 9876543210"
Output:{ "name": "Saurabh", "mobile": "9876543210" }
For code validation:
Input: "582741" or "the code is 582741"
Output:{ "code": "582741" }
This makes the workflow simpler, the user experience better, and the system more flexible — customers can type in any format and it still works.
◆ The Full Workflow Summary
MORNING:
Schedule Trigger → Generate Code → Save to Sheet → Send to Shopkeeper
CUSTOMER:
Telegram Message
→ Check Chat ID in Sheet
→ New User? → Ask Details → AI Extracts → Save to Sheet
→ Existing User? → Ask for Code → AI Extracts → Validate Code
→ Wrong Code? → Error Message
→ Already Visited Today? → Error Message
→ All Checks Pass → Increment Visit Count → Update Sheet
→ Visits % 10 == 0? → Free Tea Message
→ Otherwise → Success Message
◆ Business Impact
This system gives a local tea shop:
✅ Repeat customer visits through reward incentives
✅ A complete digital customer database
✅ Fraud-proof daily verification
✅ Zero custom mobile app needed
✅ Owner dashboard via Google Sheets — accessible from any phone
✅ Almost zero running cost
◆ What I Learned
- AI agents are not just for chat — they're incredible for replacing complex input parsing logic in automation workflows
- Simple fraud prevention works — a physical code in the shop is low-tech but highly effective
- Google Sheets is underrated as a database — for small-scale systems like this, it's perfect
- n8n + Telegram is a powerful combo — you can build surprisingly capable customer-facing systems without a single line of backend code
◆ What's Next (v2 Ideas)
- WhatsApp support using WhatsApp Business API
- Weekly visit summary sent to shopkeeper automatically
- Birthday reward detection
- Multi-shop support with separate code systems
- Export customer list to CSV for marketing
◆ Final Thought
Enterprise-grade customer retention is no longer only for companies with big budgets.
With the right tools — Telegram, n8n, an LLM, and Google Sheets — you can bring the same loyalty mechanics used by Duolingo and Starbucks to a tea stall on any street corner.
If you're learning automation or AI agents, building real-world projects like this is the fastest way to grow. It's not a tutorial project — it's something that actually solves a problem.
Built by Saurabh Patil — automation builder and AI agent enthusiast.
If a tea shop can run a Duolingo-style loyalty system using only Telegram and automation tools, what other small businesses could benefit from similar AI-powered workflows?
I'd love to hear your thoughts and ideas in the comments.
Tags: n8n ai-agents automation telegram google-sheets no-code build-in-public groq llm side-project


Top comments (0)