Monetize a Telegram bot or Mini App with one API
MGRAM is the ad network you plug into a Telegram bot or Mini App with a few HTTPS calls. POST /tasks returns paid sponsor tasks (subscribe to a channel, start a bot) to show before your content — you earn for every completion Telegram confirms. POST /reply-ads/show sends a short ad from your bot after a useful action — you earn per impression. Owners get 70% of every placement, from the first user, payouts in USDT. Plain JSON over HTTPS with a Bearer key — or the open-source Python SDK and bot templates at github.com/mgram-web; an OpenAPI description is at mgram.biz/openapi.json.
· prices update automatically
- 70% to the bot owner
- Works from the first user
- OpenAPI: mgram.biz/openapi.json
What to integrate
| Goal | Call | You earn |
|---|---|---|
| Force subscribe: sponsor tasks before your content | POST /tasks → buttons; POST /tasks/check on “Check” | from $0.0126 per confirmed subscription, from $0.0101 per bot start |
| An ad after a useful action | POST /reply-ads/show with user_id and message_id | $2.10 per 1,000 impressions |
| No polling | POST /tasks/webhook — task.completed / task.refunded to your server, signed with HMAC-SHA256 | — |
| Many bots (bot builders, hosting) | Partner API: POST /register/bot, bulk settings | 70% to each bot's owner |
Start in 3 steps
Connect the bot
Open @mgram, send the bot's token (the message is deleted at once; you can revoke the token in @BotFather any time).
Get the Bot API key
In @mgram: bot stats → Settings → API access. Keep it on your server only.
Paste the code
Pick your framework below. If MGRAM is unreachable or there are no tasks, skip: true lets the user through — your bot never breaks.
aiogram 3 (Python)
# aiogram 3 — force subscribe (paid tasks) + Reply Ads. pip install aiogram aiohttp
import os, aiohttp
from aiogram import Router, F
from aiogram.types import Message, CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton
MGRAM = "https://api.mgram.biz"
HEADERS = {"Authorization": f"Bearer {os.environ['MGRAM_API_KEY']}"} # the key stays on your server
router = Router()
async def mgram(path: str, payload: dict) -> dict:
async with aiohttp.ClientSession(headers=HEADERS, timeout=aiohttp.ClientTimeout(total=5)) as s:
async with s.post(MGRAM + path, json=payload) as r:
return (await r.json()).get("data") or {}
def user_fields(u) -> dict:
return {"user_id": u.id, "language_code": u.language_code, "is_premium": bool(u.is_premium),
"first_name": u.first_name, "username": u.username}
async def gate_keyboard(user) -> InlineKeyboardMarkup | None:
"""None: let the user in. Otherwise: the sponsor tasks to complete first (you earn per completion)."""
try:
data = await mgram("/tasks", user_fields(user))
except Exception:
return None # never block your users if MGRAM is unreachable
if data.get("skip"):
return None
rows = [[InlineKeyboardButton(text=t["button_text"], url=t["link"])] for t in data.get("tasks", [])]
rows.append([InlineKeyboardButton(text="✅ Check", callback_data="mgram_check")])
return InlineKeyboardMarkup(inline_keyboard=rows)
@router.message(F.text)
async def any_message(message: Message):
kb = await gate_keyboard(message.from_user)
if kb:
await message.answer("Subscribe to continue:", reply_markup=kb)
return
await message.answer("Here is your result ...") # your bot's normal answer
await mgram("/reply-ads/show", {**user_fields(message.from_user), "message_id": message.message_id})
@router.callback_query(F.data == "mgram_check")
async def check(cq: CallbackQuery):
data = await mgram("/tasks/check", {"user_id": cq.from_user.id})
await cq.answer("Thanks, you are in!" if data.get("skip") else "Not all tasks are done yet", show_alert=not data.get("skip"))python-telegram-bot
# python-telegram-bot 21 — the same gate. pip install python-telegram-bot httpx
import os, httpx
from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton
from telegram.ext import ContextTypes
MGRAM = httpx.AsyncClient(base_url="https://api.mgram.biz", timeout=5,
headers={"Authorization": f"Bearer {os.environ['MGRAM_API_KEY']}"})
async def mgram(path: str, payload: dict) -> dict:
return (await MGRAM.post(path, json=payload)).json().get("data") or {}
async def on_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
u = update.effective_user
data = await mgram("/tasks", {"user_id": u.id, "language_code": u.language_code, "is_premium": bool(u.is_premium)})
if not data.get("skip"):
rows = [[InlineKeyboardButton(t["button_text"], url=t["link"])] for t in data.get("tasks", [])]
rows.append([InlineKeyboardButton("✅ Check", callback_data="mgram_check")])
await update.message.reply_text("Subscribe to continue:", reply_markup=InlineKeyboardMarkup(rows))
return
await update.message.reply_text("Here is your result ...")
await mgram("/reply-ads/show", {"user_id": u.id, "message_id": update.message.message_id})grammY (TypeScript / Node)
// grammY (Node 18+) — force subscribe + Reply Ads. npm i grammy
import { Bot, InlineKeyboard } from "grammy";
const bot = new Bot(process.env.BOT_TOKEN!);
const mgram = async (path: string, body: object) => {
const r = await fetch("https://api.mgram.biz" + path, {
method: "POST",
headers: { Authorization: `Bearer ${process.env.MGRAM_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify(body),
});
return ((await r.json()).data ?? {}) as any;
};
bot.on("message:text", async (ctx) => {
const u = ctx.from;
const gate = await mgram("/tasks", { user_id: u.id, language_code: u.language_code, is_premium: !!u.is_premium });
if (!gate.skip) {
const kb = new InlineKeyboard();
for (const t of gate.tasks ?? []) kb.url(t.button_text, t.link).row();
await ctx.reply("Subscribe to continue:", { reply_markup: kb.text("✅ Check", "mgram_check") });
return;
}
await ctx.reply("Here is your result ...");
await mgram("/reply-ads/show", { user_id: u.id, message_id: ctx.message.message_id });
});
bot.callbackQuery("mgram_check", async (ctx) => {
const r = await mgram("/tasks/check", { user_id: ctx.from.id });
await ctx.answerCallbackQuery({ text: r.skip ? "Thanks, you are in!" : "Not all tasks are done yet", show_alert: !r.skip });
});
bot.start();Telegraf (Node)
// Telegraf — the gate in a middleware. npm i telegraf
import { Telegraf, Markup } from "telegraf";
const bot = new Telegraf(process.env.BOT_TOKEN!);
const mgram = (path: string, body: object) =>
fetch("https://api.mgram.biz" + path, {
method: "POST",
headers: { Authorization: `Bearer ${process.env.MGRAM_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify(body),
}).then((r) => r.json()).then((j: any) => j.data ?? {});
bot.use(async (ctx, next) => {
if (!ctx.from || !ctx.message) return next();
const gate = await mgram("/tasks", { user_id: ctx.from.id, language_code: ctx.from.language_code });
if (gate.skip) return next();
const buttons = (gate.tasks ?? []).map((t: any) => [Markup.button.url(t.button_text, t.link)]);
buttons.push([Markup.button.callback("✅ Check", "mgram_check")]);
return ctx.reply("Subscribe to continue:", Markup.inlineKeyboard(buttons));
});Telegram Mini App
// Telegram Mini App: the page sends initData to YOUR backend; the backend calls MGRAM (never put the key in the page).
// Frontend
const res = await fetch("/api/mgram-tasks", { method: "POST", body: Telegram.WebApp.initData });
const { tasks, skip } = await res.json(); // render tasks[i].button_text → Telegram.WebApp.openTelegramLink(tasks[i].link)
// Backend (Node/Express): Telegram signs initData; MGRAM verifies it
app.post("/api/mgram-tasks", express.text(), async (req, res) => {
const user = JSON.parse(new URLSearchParams(req.body).get("user") || "{}");
const r = await fetch("https://api.mgram.biz/tasks", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.MGRAM_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ user_id: user.id, init_data: req.body }),
});
res.json((await r.json()).data ?? {});
});Any language: plain HTTPS
curl -X POST https://api.mgram.biz/tasks \
-H "Authorization: Bearer $MGRAM_API_KEY" -H "Content-Type: application/json" \
-d '{"user_id": 123456789, "language_code": "en"}'
# → {"ok": true, "data": {"status": "tasks", "skip": false, "tasks": [{"id": 1, "button_text": "Subscribe", "link": "https://t.me/...", ...}]}}Open source on GitHub
Ready-made, tested code under the MIT license — clone a template in your language and run it: github.com/mgram-web.
| Repository | Stack | Language | Inside |
|---|---|---|---|
| mgram-sdk | Python | Russian · English | SDK on PyPI (pip install mgram-sdk): API client, aiogram 3 and python-telegram-bot integrations, webhook signature check |
| mgram-js | JavaScript · TypeScript | English | SDK on npm (npm i mgram-sdk): grammY and Telegraf middleware, zero dependencies |
| mgram-go | Go | English | SDK for Go (go get github.com/mgram-web/mgram-go), standard library only |
| mgram-mcp | MCP | English | MCP server for advertisers: Claude Code plugin, Gemini CLI extension, Cursor and VS Code setup |
| telegram-bot-monetization | Python · Node.js | English | aiogram 3 bot template + grammY, Telegraf and Mini App examples |
| monetizaciya-telegram-bota | Python | Russian | aiogram 3 bot template: force subscribe + Reply Ads, tests |
| monetizar-bot-telegram | Python | Spanish | aiogram 3 bot template, texts in Spanish |
| ganhar-dinheiro-bot-telegram | Python | Portuguese | aiogram 3 bot template, texts in Portuguese |
| monetisasi-bot-telegram | Python | Indonesian | aiogram 3 bot template, texts in Indonesian |
| telegram-bot-para-kazanma | Python | Turkish | aiogram 3 bot template, texts in Turkish |
Rules that keep the money honest
- Paid only for actions Telegram confirms; a user who was already subscribed, a farm account or a repeated task is not paid.
- A subscriber who leaves within 72 hours is refunded to the advertiser (webhook task.refunded).
- Reply Ads: one call per user per second; the ad is sent by your bot only if the user wrote to it in the last minutes.
- You control the content: block topics, casino and 18+, approve orders by hand.
- Most campaigns today come from Russian-speaking advertisers; GEO and language filters route ads to matching audiences.
Frequently asked questions
How do I monetize a Telegram bot with an API?
Connect the bot to MGRAM, then call POST /tasks to show paid sponsor tasks before your content and POST /reply-ads/show to show an ad after a useful action. You get 70% of every placement.
Is there an SDK?
Yes, an open-source Python SDK on PyPI — pip install mgram-sdk (pypi.org/project/mgram-sdk, source: github.com/mgram-web/mgram-sdk) for aiogram 3, python-telegram-bot and webhooks; for JavaScript and TypeScript — npm i mgram-sdk (npmjs.com/package/mgram-sdk), one middleware for grammY and Telegraf; for Go — go get github.com/mgram-web/mgram-go (pkg.go.dev); and tested bot templates in six languages at github.com/mgram-web. The API itself is plain JSON over HTTPS with a Bearer key; the OpenAPI description is at https://mgram.biz/openapi.json.
Does it work for Mini Apps?
Yes: send Telegram.WebApp.initData from the page to your backend and pass it as init_data to POST /tasks; MGRAM verifies the Telegram signature.
Will my bot break if MGRAM is down?
No: treat any error like skip: true and let the user through, as the snippets do.
How many users do I need?
Force subscribe and the Tasks API work from the first user; broadcasts and Reply Ads open at 50 users.
Ready to start?
Everything happens in Telegram: open @mgram, choose English, and the bot walks you through each step.