Adding Telegram Stars Payments to Your Bot
Telegram Stars (XTR) let users pay for digital goods without a bank card.
Setup
from aiogram import Bot, Dispatcher
from aiogram.types import LabeledPrice
bot = Bot(token=TOKEN)
PRICE_STARS = 100 # ~$1.99
Send Invoice
@dp.message(Command('buy'))
async def send_invoice(message: Message):
await bot.send_invoice(
chat_id=message.chat.id,
title='Premium Access',
description='30 days of premium features',
payload='premium_30d',
provider_token='',
currency='XTR',
prices=[LabeledPrice(label='Premium', amount=PRICE_STARS)]
)
Handle Payment
@dp.pre_checkout_query()
async def process_pre_checkout(query: PreCheckoutQuery):
await query.answer(ok=True)
@dp.message(lambda m: m.successful_payment is not None)
async def payment_received(message: Message):
payment = message.successful_payment
if payment.invoice_payload == 'premium_30d':
db.set_premium(message.from_user.id, days=30)
await message.answer('Premium activated for 30 days!')
What Can You Sell With Stars?
- Digital content (ebooks, courses)
- Bot subscriptions
- AI generations
- In-game items
Need a monetized Telegram bot? Contact me on Upwork.
From $79 | 3-5 days delivery
Top comments (0)