Skip to main content

Asynchronous SDK for integrating with the tgpromo.org API

Project description

tgpromo

An asynchronous Python SDK for integrating your Telegram bot or service with the tgpromo.org advertising platform.

  • 🚀 Supports Python 3.8 and above
  • 🔐 Safe by design — robust error handling and health checks
  • ⚡️ Minimal integration — just one method call to show ads

🔗 Useful Links


📦 Installation

pip install tgpromo

⚙️ Quick Start

To integrate your bot with tgpromo, simply call the ad impression method each time you receive a message from a user and want to show an ad.

This is the only required step — the method returns a flag indicating whether the impression was successfully sent.

If your bot responds quickly, you can show the ad after sending your reply.

import asyncio
from tgpromo import PartnerClient, TGPromoException

async def main():
    client = PartnerClient(token='YOUR_PARTNER_API_TOKEN')

    try:
        result = await client.ads.impressions.send(
            user_id=123,
            message_id=456
        )
        print('Impression sent: ', result.impression_sent)
    except TGPromoException as e:
        print('Impression send error: ', e)
        
    # Clean up client when done
    await client.aclose()

if __name__ == '__main__':
    asyncio.run(main())

🤖 Example with aiogram

This example uses aiogram v3. It sends an ad impression when the /start command is received.

You can also show ads after any user interaction — for example, after completing a task or sending a message.

import asyncio
from os import getenv

from aiogram import Bot, Dispatcher, html
from aiogram.client.default import DefaultBotProperties
from aiogram.enums import ParseMode
from aiogram.filters import CommandStart
from aiogram.types import Message
from tgpromo import PartnerClient, TGPromoException


# Bot token can be obtained via https://t.me/BotFather
BOT_TOKEN = getenv('BOT_TOKEN')

# Partner API token is available in the bot management panel (https://tgpromo.org or https://t.me/tgpromo_bot)
TGPROMO_PARTNER_API_TOKEN = getenv('TGPROMO_PARTNER_API_TOKEN')

dp = Dispatcher()
partner_client = PartnerClient(TGPROMO_PARTNER_API_TOKEN)


@dp.message(CommandStart())
async def command_start_handler(message: Message) -> None:
    """
    Handle the /start command and attempt to send an ad impression.
    """
    try:
        result = await partner_client.ads.impressions.send(
            user_id=message.from_user.id,
            message_id=message.message_id
        )

        if not result.impression_sent:
            print('Impression not sent - try another network or your own ad ;)')
    except TGPromoException as e:
        print('Impression send error: ', e)

    await message.answer(f'Hello, {html.bold(message.from_user.full_name)}!')


async def main() -> None:
    bot = Bot(token=BOT_TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML))
    await dp.start_polling(bot)


if __name__ == '__main__':
    asyncio.run(main())

🔒 Safety & Resilience Features

  • Your service remains stable even if the tgpromo API becomes temporarily unreachable
  • API requests are automatically paused during network outages or server errors
  • Availability is automatically restored once API connectivity returns
  • Raises TGPromoException for general errors, and PartnerAPIException for partner-specific issues

📝 License

This project is licensed under the MIT License – see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tgpromo-0.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tgpromo-0.1.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file tgpromo-0.1.0.tar.gz.

File metadata

  • Download URL: tgpromo-0.1.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.8.10 Windows/10

File hashes

Hashes for tgpromo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9bcba5d38e7f0632f4741b21a1e26d60bc7aa0b769d6b92b0c185ffb6a60861a
MD5 172237af75cc805dc206e45ee645736d
BLAKE2b-256 bebf5ba8442bccbfe46567557f7d5ab3743d8e4b04d159b37be555bf9c65260e

See more details on using hashes here.

File details

Details for the file tgpromo-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tgpromo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.8.10 Windows/10

File hashes

Hashes for tgpromo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0810e86db7426fc8c3fc01ba5540dc7366d4e064cea3fb97cc72d37e16f2164e
MD5 61f04d64744b0bcccb46abeaee811221
BLAKE2b-256 6f9f247f930587a0f257e243dcfb23cb027cd5934a9649436d983797b1f2055f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page