Skip to content

The moment it happens

Sell with Telegram Stars and log every payment in a sheet

Customers buy from your bot with Telegram Stars, and every payment and refund lands in your Google Sheet.

Runs
The moment it happens
Apps
Google Sheets, Telegram
AI
Not needed
Access
Telegram bot token; Sheets read+write

Send this to your assistant

Create a ClickRuntime automation: when a user sends /buy to my bot, send a Telegram Stars invoice; when they pay, log it in my Payments sheet and confirm. Handle /refund too.

Paste it into your assistant. It tells you what it will send or change before it runs live.

First time? Adding ClickRuntime to your assistant takes about two minutes.

Why use it

Why teams use this automation

A developer runs a Telegram bot that offers premium features, guides or digital downloads. Telegram requires digital goods to be sold in Stars, and the payment flow involves several messages that have to be answered quickly and correctly. Without a record outside Telegram, it is hard to know who paid, for what, and what has been refunded.

This automation handles the full flow: it sends the invoice, approves the checkout, confirms the purchase and records it. Refund requests are processed the same way, so the sheet is an accurate ledger you can reconcile and report from.

What you get out of it

  • A ledger you can actually read

    Every payment and refund is a row with the user, amount and payment reference. Monthly revenue, top buyers and refund rates are a simple sheet formula away.

  • Checkout is answered in time

    Telegram expects a quick answer before it charges the user. Handling it automatically means buyers are not left with a failed payment because nobody responded.

  • Refunds without digging

    The payment reference needed for a refund is already in the sheet. A /refund request uses it, and a refund row is added so your totals stay correct.

  • Buyers get an instant confirmation

    A confirmation message right after paying reassures the buyer. It also cuts down on "did my payment go through?" messages.

How it works

What happens, step by step

  1. When someone sends /buy to your bot, it sends them an invoice priced in Telegram Stars.

  2. When they tap Pay, ClickRuntime approves the checkout straight away.

  3. Once the payment succeeds, a row with the buyer, amount and payment reference is added to the Payments tab, and the buyer gets a confirmation.

  4. If a refund is requested with /refund, the payment is refunded and the refund is logged in the sheet.

Before it runs live

  • Connect your Google Sheets account and pick the spreadsheets it may use
  • Connect Telegram
  • Paste your automation's link into the other app's webhook settings

What you get

RunsThe moment it happens
Sell with Telegram Stars and log every payment in a sheetjust nowSucceeded
Google Sheets · Payments2026-10-19 14:02 · user 51832 · 100 Stars · Pro access · paid

Build your own

Need it to work differently?

This template is a starting point. Copy the prompt and change it, or describe a different automation from scratch, with your own conditions, more apps or an AI step. Your assistant writes it, tests it and runs it on ClickRuntime.
  • 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 Google Sheets and Telegram steps into one automation

Under the hood

The code that runs this automation

This is the Python script that runs each time the automation starts. Your AI assistant writes it for you when you send the prompt, and you allow each step in your assistant. To change how the automation works, describe the change to your assistant and it updates the script for you. For every function it can use, see the script reference.
telegram_stars_payments_ledger.pyexample
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from clickruntime import on_event, credentials, http

SHEET_ID = "your-spreadsheet-id"

@on_event
def handle(event):
    u = event.json or {}
    tg = f"https://api.telegram.org/bot{credentials.secret('TELEGRAM_BOT_TOKEN')}"
    if "pre_checkout_query" in u:
        http.post(f"{tg}/answerPreCheckoutQuery", json={"pre_checkout_query_id": u["pre_checkout_query"]["id"], "ok": True})
        return {"precheckout": "ok"}
    msg = u.get("message") or {}
    chat, uid, text = msg.get("chat", {}).get("id"), msg.get("from", {}).get("id"), msg.get("text", "")
    sheets = build("sheets", "v4", credentials=Credentials(credentials.connection("google", "work")), cache_discovery=False)
    log_row = lambda row: sheets.spreadsheets().values().append(spreadsheetId=SHEET_ID, range="Payments!A:E",
        valueInputOption="USER_ENTERED", body={"values": [row]}).execute()
    if text == "/buy":
        http.post(f"{tg}/sendInvoice", json={"chat_id": chat, "title": "Pro access", "description": "30 days of Pro",
            "payload": "pro-30", "currency": "XTR", "prices": [{"label": "Pro", "amount": 100}]})
    elif "successful_payment" in msg:
        p = msg["successful_payment"]
        log_row([event.received_at, uid, p["total_amount"], p["telegram_payment_charge_id"], "paid"])
        http.post(f"{tg}/sendMessage", json={"chat_id": chat, "text": "Payment received, Pro is active."})
    elif text.startswith("/refund "):
        charge = text.split(" ", 1)[1]
        http.post(f"{tg}/refundStarPayment", json={"user_id": uid, "telegram_payment_charge_id": charge})
        log_row([event.received_at, uid, 0, charge, "refunded"])
    return {"handled": True}

FAQ

Common questions

What are Telegram Stars?
Stars are Telegram's in-app currency for digital goods and services. Users buy them inside Telegram, and your bot receives them when someone pays an invoice.
Can I sell more than one product?
Yes. Keep a list of products with names and prices, and the bot can send a different invoice for each command or button, recording which product was bought.
Who can trigger a refund?
You choose. Refunds can be limited to your own Telegram account, or offered to buyers within a set number of days of their purchase, checked against the date in the sheet.
What permissions does it need?
Telegram bot token; Sheets read+write. Nothing else in your accounts is used.
Does it need AI?
No. It runs without AI, so it doesn't use your plan's AI allowance.
How many runs does it use?
One run for each event the app sends.
Can I change how it works?
Yes. Describe the change to your AI assistant, for example a different schedule, channel or filter. It updates the automation, tests it and tells you what changed.

Set up “Sell with Telegram Stars and log every payment in a sheet” from your assistant

Copy the prompt above, or connect your assistant first. Free plan, no credit card.