3.4 KiB
StarTransactionsBot
A long-polling bot for Telegram Stars invoices, transaction history, paid media, refund updates, and TON wallet information.
Commands
/startreplies with a sample invoice charging1Star, payloadsample payload, and a Pay button. Matching pre-checkout queries are approved automatically./transactionsworks only in the chat whose numeric ID was supplied as the second program argument. It replies with the bot's first transaction page./wallet_cardin your private chat with the bot reads the public TON wallet card on your profile withgetChat. It shows the wallet address, balance in the smallest units, and NFT sticker count, or reports that the card is absent.
The commands are not registered in Telegram's command menu.
Transaction pages
Pages use an offset and a default limit of 10. Each returned transaction includes
its ID, date, amount, direction (incoming, outgoing, or unknown), and partner
type. The inline keyboard contains:
<when a previous nonnegative offset exists;>on every page, usingoffset + limit, even when no later records exist.
Selecting either button fetches that page and edits the existing text message. The
initial /transactions command is admin-chat filtered; pagination callbacks are not
independently filtered, so keep the resulting message in the private admin chat.
Pagination state is encoded in callback data and is not persisted by the bot.
Other triggers
- A photo or video is sent back as paid media costing
1Star. - A visual gallery is downloaded to temporary files and re-uploaded as one-Star paid media, retaining its caption above the media; only photos and videos are used.
- Paid-media-info messages are printed to standard output.
- Refunded-payment events receive a reply containing the payment information.
onTonWalletTransferreplies to a transfer service message with the signed amount, peer wallet address, and transaction ID. The amount stays in Telegram's decimal-string representation. Outgoing amounts are negative, and an empty transaction ID appears as pending.onPaidMessagesWaivedacknowledges the service message Telegram sends when someone uses a link that grants free messages to the recipient.- Every received update is printed to standard output.
Setup, permissions, and payment safety
Create a bot, keep its token private, and choose the numeric ID of the user who may open transaction history. Use that user's private chat, and allow the bot to send messages, invoices, photos, and videos. The Telegram environment and client must support Stars and paid media; purchasers need Stars to complete payments.
This is a charging example: /start and delivered photo/video content can create
one-Star purchase flows. Use test accounts or Telegram's test environment when
appropriate. The code approves its sample pre-checkout query but performs no
fulfilment after payment. No chat-administrator methods or webhook are configured.
Run
From the repository root, pass the token and decimal admin ID first:
./gradlew :StarTransactionsBot:run --args="BOT_TOKEN ADMIN_USER_ID"
Both arguments are required; an absent or nonnumeric admin ID stops startup. The
optional, case-sensitive flags debug and testServer may follow them in either
order to enable formatted logging or Telegram's test API.
./gradlew :StarTransactionsBot:run --args="BOT_TOKEN ADMIN_USER_ID debug testServer"