Skip to main content

adsun — Telegram bot ads for Python

Official Adsun Python SDK. Monetize your Telegram bot with sponsored messages and earn USDT, and verify Telegram Mini App reward callbacks on your server. Zero required dependencies; helpers for aiogram 3 and python-telegram-bot 20+.

pip install adsun              # core (standard library only)
pip install "adsun[aiogram]"   # + aiogram helper
pip install "adsun[ptb]"       # + python-telegram-bot helper
  1. Sign up at https://adsun.io/publishers, add your bot as a Bot platform and create a block.
  2. Copy your account token (Profile → Token) and the numeric block id (e.g. 50001).

aiogram 3

from aiogram.filters import Command
from adsun import AsyncAdsunBot
from adsun.integrations.aiogram import send_ad

ads = AsyncAdsunBot(token="YOUR_ACCOUNT_TOKEN", block_id="50001")

@dp.message(Command("bonus"))
async def bonus(message):
    ad = await send_ad(message.bot, message.chat.id, ads, message.from_user.id, message.from_user.language_code or "en")
    if ad is None:
        await message.answer("No offer right now")

python-telegram-bot

from adsun import AsyncAdsunBot
from adsun.integrations.ptb import send_ad

ads = AsyncAdsunBot(token="YOUR_ACCOUNT_TOKEN", block_id="50001")

async def bonus(update, context):
    u = update.effective_user
    await send_ad(context.bot, update.effective_chat.id, ads, u.id, u.language_code or "en")

Any framework (sync, no dependencies)

from adsun import AdsunBot

ads = AdsunBot(token="YOUR_ACCOUNT_TOKEN", block_id="50001")
ad = ads.get_ad(user_id=123456789, language="en")   # None = no ad right now
if ad:
    print(ad.text_html, ad.image_url, ad.buttons())  # [[(text, url)], [(reward_text, reward_url)]]

Send it yourself with parse_mode="HTML" and protect_content=True (ad messages must not be forwardable).

Errors: InvalidToken (401), BlockNotActive (404), BadRequest (400), AdsunError (others / network).

Reward URL callback (Mini Apps and bots)

Set the block's Reward URL in the panel: https://your-app.com/adsun/reward?userid=[userId]&block=[blockId]&secret=LONG_RANDOM_SECRET

from adsun import parse_reward_callback

@app.get("/adsun/reward")            # Flask / FastAPI / Django — any dict-like query works
def reward():
    cb = parse_reward_callback(request.args, secret=REWARD_SECRET)
    if cb is None:
        return "forbidden", 403
    add_coins(cb.user_id)            # make this idempotent: Adsun retries on 5xx / network errors
    return "ok"

HTTP API (what the SDK calls)

GET https://api.adsun.io/advbot?tgid=<user id>&blockid=<number>&language=<code>&token=<account token> → 200 {text_html, click_url, button_name, image_url, button_reward_name, reward_url} or 204 (no ad).

Links: https://adsun.io/docs · https://adsun.io/telegram-bot-monetization · support@adsun.io · @ADSunSupport

MIT License. Adsun is not affiliated with Telegram.

Metadata

Release files for adsun 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for adsun 1.0.0
File Size Uploaded Provenance Actions
adsun-1.0.0.tar.gz 7.7 kB Without provenance Details for adsun-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for adsun 1.0.0
File Interpreter ABI Platform Actions
adsun-1.0.0-py3-none-any.whl Python 3 none any Details for adsun-1.0.0-py3-none-any.whl

Total release size: 17.5 kB

Release files / adsun-1.0.0.tar.gz

Download URL adsun-1.0.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
749e00c97ada58fbe13e108f5e723ca93ce66db728b03696278df2fe966958b9
BLAKE2b-256 checksum
How to use checksums
30b4ada5635385a656ec9fbe3d004c15d90f3b4d3e79cf26d507a151bf718f5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Release files / adsun-1.0.0-py3-none-any.whl

Download URL adsun-1.0.0-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9e90d2c6b1e2e2c7db7a214337abb7f630e518cc719f2ef5279784613d13714
BLAKE2b-256 checksum
How to use checksums
72993e2d58fb5e4afe016b20d948eba11334be3dceccacac7e8d63385641b91b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Security for adsun 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page