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.1.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.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tgpromo-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 caac941407a47503816cf5fcc3f85b481a478a5dae2591f31ff4ace4dc02680d
MD5 510b5d18094d5fafc5482d1f6cacd7d8
BLAKE2b-256 6c9d6b2df9a78fc00c5600c2a7b6ec7c1e7d04467868d72c23e290ff83615624

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tgpromo-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8ab1239fcdb8a2e6f327ffde66c591a7a736139c9726c7a20c509df4d0a89ef3
MD5 c81a8a8ed4837742cee012e4115c1aea
BLAKE2b-256 ce0b93c4afae4ae5c5936e6d11551cc5e55bcf4e9d0c5a67efe44d512a820d5b

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