Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Install :

pip install -U zdgram

How to use?

  • Config your bot :

from zdgram import Bot, types

API_TOKEN = "API_TOKEN_HERE"

bot = Bot(API_TOKEN, allowed_updates=["message"])
  • Add handlers to recive updates from telegram:

  • Any update from telegram:
@bot.onUpdate
async def on_updates(bot: Bot, update: types.Update):
    print(update)
  • message and edited_message:
@bot.onMessage()
async def on_message(bot: Bot, message: types.Message):
    print(message)

@bot.onEditedMessage()
async def on_edited_message(bot: Bot, message: types.Message):
    print(message)

# Custom filter
def filter_admin(message: types.Message):
    admins = [123456789, 987654321]
    return bool(message.from_user.id in admins)

@bot.onMessage(func=filter_admin)
@bot.onEditedMessage(func=filter_admin)
async def on_custom_filter(bot: Bot, message: types.Message):
    print(message)

# Echo Bot
@bot.onMessage(func=lambda m: m.text)
async def echo(bot: Bot, message: types.Message):
    return await bot.sendMessage(
        message.chat.id,
        message.text,
        entities=message.entities
    )
  • Callback Queries .
@bot.onCallbackQuery()
async def on_callback_query(bot: Bot, callback_query: types.CallbackQuery):
    return await bot.sendMessage(
        callback_query.message.chat.id,
        callback_query.data
    )
  • Inline Queries .
@bot.onInlineQuery()
async def on_inline_query(bot: Bot, inline_query: types.InlineQuery):
    print(inline_query)
  • Start the bot:

import logging

logging.basicConfig(level=logging.INFO)

bot.run()
  • Start multiple bots:

import logging

from zdgram import run_multiple_bots, Bot, types, enums

logging.basicConfig(level=logging.INFO)

bot_1 = Bot("API_TOKEN_1")
bot_2 = Bot("API_TOKEN_2")

@bot_1.onMessage()
@bot_2.onMessage()
async  def on_message(bot: Bot, message: types.Message):
    return await bot.sendMessage(
        message.chat.id,
        (await bot.getMe()).mention.markdown,
        parse_mode=enums.ParseMode.MARKDOWN
    )

bot_1.run(run_multiple_bots([bot_1, bot_2]))
  • Create Listener ( Conversation ):

from zdgram import types, enums, Bot

bot = Bot(bot_token="")

def filter_text_and_private(m: types.Message):
    return bool(m.text and m.chat.type == enums.ChatType.PRIVATE)

@bot.onMessage(func=filter_text_and_private)
async def on_message(bot: Bot, message: types.Message):
    await bot.sendMessage(
        message.chat.id,
        "Send your name",
        reply_to_message_id=message.id
    )
    msg = await bot.listen(filter_text_and_private)
    return await bot.sendMessage(
        message.chat.id,
        "Your name is : " + msg.text
    )

LICENSE :

Metadata

Release files for zdgram 0.1.dev7

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

Source distribution (sdist)

Source distribution for zdgram 0.1.dev7
File Size Uploaded
zdgram-0.1.dev7.tar.gz 35.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for zdgram 0.1.dev7
File Interpreter ABI Platform
zdgram-0.1.dev7-py3-none-any.whl Python 3 none any Details

Total release size: 109.2 kB

Release files / zdgram-0.1.dev7.tar.gz

Download URL zdgram-0.1.dev7.tar.gz
Size 35.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c3daecb90023db119ac25e4bf0e6fd833ec9642a1c91b6ccd66a915f7b29bc9a
BLAKE2b-256 checksum
How to use checksums
89842e2bd66827fe736dffdd1b1d1d2c986763f6fe036c316f89f40f9bc50eb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / zdgram-0.1.dev7-py3-none-any.whl

Download URL zdgram-0.1.dev7-py3-none-any.whl
Size 73.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0d0e5da988feb93bb49c2e2cddb1f54c42f109678fa89b2c273a4def599bd1d
BLAKE2b-256 checksum
How to use checksums
14d3b6feee0ab690fe7e9d4b4c255930c1981de9f79c687e35508dab15d1dded
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5
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