How to accept crypto payments in a Telegram bot
A bot that sells a hoodie, a ticket or a service and takes USDT, USDC, Bitcoin and other coins for it: what Telegram allows, the payment button, the webhook that tells the bot a payment is final, and the code in Node.js and Python.
First: what a bot may sell for crypto
Telegram draws the line by what is sold. Digital goods and services used inside Telegram — access to a channel, a bot’s premium features, in-app items — must be paid in Telegram Stars, and Telegram says plainly that crypto is not allowed for them (its Stars page). Physical goods and services outside Telegram may use any payment provider the bot chooses (Bot Developer Terms, section 6): a hoodie, a printed book, a ticket to an event, a repair, a consultation booked by the bot.
Use a plain bot with a URL button, as below — not a Mini App. Telegram’s blockchain guidelines hold Mini Apps to TON and leave bots without a Mini App out of those rules. Which goods count as digital follows Apple’s and Google’s rules; read them for anything in between.
How the payment works
- 1The buyer sends
/buy, or taps a product in the bot. - 2Your server creates an Orboni checkout session and the bot answers with a Pay with crypto button that opens the session’s
url. - 3The buyer pays on Orboni’s page in the coin they hold, from a wallet or an exchange. The money goes to your wallet, never through Orboni.
- 4Once the payment is final, Orboni sends your server a signed
checkout.session.completed. The bot tells the buyer, and you ship.
The bot never shows an address or works out a rate: the payment page does that, in the buyer’s language, and checks the payment on the chain.
What you need
- A bot and its token, from @BotFather.
- An Orboni account with your wallets set, and a test secret key (Developers → API keys).
- A server reachable over HTTPS: Telegram sends webhooks to ports 443, 80, 88 and 8443.
- An Orboni webhook endpoint at your server’s /orboni address (Developers → Webhooks), and its signing secret, whsec_….
No server? A payment link made in the dashboard can go into the bot’s message as it is. You then see each payment in the dashboard rather than in the bot.
Point Telegram at your server
Telegram sends the bot’s updates to one address. Give it a secret of your own, letters, digits, _ and -: Telegram sends it back in X-Telegram-Bot-Api-Secret-Token, and the code below refuses an update without it.
curl "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/setWebhook" \
-d url=https://example.com/telegram \
-d secret_token=$TELEGRAM_WEBHOOK_SECRETThe bot
Two routes: /telegram takes the bot’s updates and answers /buy with a button; /orboni takes Orboni’s webhook and tells the buyer once the payment is final. The buyer’s chat rides along in the session’s metadata. Install with npm install express orboni or pip install flask requests orboni.
import express from 'express';
import Orboni from 'orboni';
const orboni = new Orboni(process.env.ORBONI_SECRET_KEY);
const TELEGRAM = `https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}`;
const BOT_NAME = 'your_shop_bot'; // the bot's username, for the way back
async function telegram(method, body) {
const res = await fetch(`${TELEGRAM}/${method}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
return res.json();
}
const app = express();
// 1. Telegram's updates: /buy answers with a payment button.
app.post('/telegram', express.json(), async (req, res) => {
if (req.get('X-Telegram-Bot-Api-Secret-Token') !== process.env.TELEGRAM_WEBHOOK_SECRET) {
return res.sendStatus(401);
}
res.sendStatus(200); // answer first, work after
const message = req.body.message;
if (message?.text !== '/buy') return;
const session = await orboni.checkout.sessions.create({
amount: 2490, // $24.90, in cents
currency: 'usd',
description: 'Hoodie, size M',
metadata: { chat_id: String(message.chat.id) },
success_url: `https://t.me/${BOT_NAME}?start=paid`,
});
await telegram('sendMessage', {
chat_id: message.chat.id,
text: 'Hoodie, size M: $24.90. Pay with the coin you hold:',
reply_markup: {
inline_keyboard: [[{ text: 'Pay with crypto', url: session.url }]],
},
});
});
// 2. Orboni's webhook: the payment is final, the bot says so.
app.post('/orboni', express.raw({ type: 'application/json' }), async (req, res) => {
let event;
try {
event = await orboni.webhooks.constructEvent(
req.body,
req.get('Webhook-Signature'),
process.env.ORBONI_WEBHOOK_SECRET,
);
} catch {
return res.sendStatus(400);
}
res.sendStatus(200);
if (event.type !== 'checkout.session.completed') return;
const session = event.data.object;
await telegram('sendMessage', {
chat_id: Number(session.metadata.chat_id),
text: `Paid, thank you. Your order ${session.id} is on its way.`,
});
});
app.listen(3000);success_url brings the buyer back to the bot once paid (?start=paid arrives as /start paid). It is only the way back: ship on the webhook, which comes whether or not the buyer returns.
Test it without real money
- 1Run the bot with the
sk_test_…key and a test webhook endpoint. On your own computer, a tunnel (ngrok, Cloudflare Tunnel) gives both webhooks an HTTPS address. - 2Send the bot
/buyand open the button’s link in a browser where you are signed in to Orboni. - 3Press Simulate payment: the test payment is marked paid, Orboni sends the webhook as for a real one, and the bot writes back. A buyer given a test link sees no such button.
More on test keys, test networks and part payments: Testing.
Before the first real payment
- Switch to the sk_live_… key and a live webhook endpoint, with its own signing secret.
- Ship only on checkout.session.completed; checkout.session.payment_detected means seen on the chain, not final.
- Keep the event ids you have handled: a webhook may come twice, or out of order.
- Keep the bot token, the Orboni key and both secrets out of your code, in the server’s environment.
- Answer /terms and /support in the bot, as Telegram asks of bots that take payments.
What it costs
Orboni takes 0.5% of each completed live payment, invoiced once a month; nothing is taken out of the payment, and there is no monthly fee. The buyer pays their network’s fee. See pricing and the coins a buyer can pay with.