Skip to main content

Telegant

Code style: black

Telegant

Telegant is an elegant modern bot framework for Python, designed to provide developers with simple and elegant access to the Telegram bot API. This project is now in Beta phase. All Telegram bot api methods are now supported automatically.

Features and highlights

  • Automated coverage of all Telegram bot api methods
  • Support of snake_case, camelCase and PascalCase for methods
  • Asynchronous bot
  • Lightweight
  • Fast
  • Simple
  • Bot Helpers
  • Regex Expressions for text messages

Installation

To install the project, simply run:

pip install telegant

Contribution

For contribution to this project you have to open discussion under Contribution section. It will be decided if your request is going to be accepted or not.

Example

from telegant import Bot

bot = Bot("YOUR_BOT_TOKEN_HERE")

@bot.hear("hello")
async def say_hello(bot, update): 
    await bot.send_message(text="What's up?")

#Your code here (Recommended to write your functions in order)

bot.start_polling()

Usage

On text

If you need your bot to respond to specified text just use @bot.hear()

@bot.hear("hello")
async def say_hello(bot, update): 
    await bot.send_message(text="What's up?")

Or many texts

@bot.hears(["hello"])
async def say_hello(bot, update): 
    await bot.send_message(text="What's up?")

Case styles

Ability to use different case styles

snake_case

@bot.hear("hello")
async def say_hello(bot, update): 
    await bot.send_message(text="What's up?")

camelCase

@bot.hear("hello")
async def say_hello(bot, update): 
    await bot.sendMessage(text="What's up?")

PascalCase

@bot.hear("hello")
async def say_hello(bot, update): 
    await bot.SendMessage(text="What's up?")

Sending bot with buttons

Inline buttons example

@bot.hear("hello")
async def say_hello(bot, update): 
    buttons = [
        [
            {"text": "Option 1 (inline)", "callback_data": "option1"},  
        ]
    ]

    #snake_case example
    await bot.send_message(text="What's up?", reply_markup=buttons)

Reply buttons example

@bot.hear("hello")
async def say_hello(bot, update): 
    buttons = [
        [
            {"text": "Option 1 (reply)"},  
        ]
    ]

    await bot.send_message(text="What's up?", reply_markup=buttons)

Bot always detects your buttons type automatically by callback_data key. If you want to use inline buttons you have to write text and data values for each button. As it is detects your inline button when you have "data" key in your button. Otherwise, it will detect as reply keyboard.

Commands

You can assign to one function one command or many commands as needed. For single command use @bot.command() decorator.

@bot.command("start")
async def say_hello(bot, update):  
    await bot.send_message(text="Sup I'm start")

For several commands use @bot.commands() decorator.

@bot.commands(['help', 'ask'])
async def say_hello(bot, update):  
    await bot.send_message(text="You've reached for help")

Export data after command by your keys

@bot.commands(['usernameandage'])
@bot.with_args(['username', 'age'])
async def handler(bot, update, data): 
    await bot.send_message(text=f"Hello {data['username']}, you are {data['age']} years old.")

Callbacks

Telegant also offers to you simply detect your callbacks where you able to assign many or one callback to your function

Many callbacks example

@bot.callbacks(['option1', 'option2'])
async def say_hello(bot, update):  
    await bot.send_message(text="Callbacks are perfect!")

Single callback example

@bot.callback('option1')
async def say_hello(bot, update):  
    await bot.send_message(text="Callback is perfect")

Metadata

Release files for Telegant 0.2.6

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

Source distribution (sdist)

Source distribution for Telegant 0.2.6
File Size Uploaded
Telegant-0.2.6.tar.gz 6.7 kB Details

Built distribution (wheel)

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

Total release size: 15.2 kB

Release files / Telegant-0.2.6.tar.gz

Download URL Telegant-0.2.6.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
bafbd0e167a04b222ad5a37818d7e740602f2c09a489623bc095bc67ce17854e
BLAKE2b-256 checksum
How to use checksums
632122380f6d6e608ba6fe19546f350fdcfef87c50489b0be1411ac0dbdc99d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / Telegant-0.2.6-py3-none-any.whl

Download URL Telegant-0.2.6-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79e1fa7d026d7fcdc252e1209d754245177c6cfe8c9dd39849e4ec7292830098
BLAKE2b-256 checksum
How to use checksums
70566a3316c8f9e55e4a871e6384ee2d1f1a2a4e926b3bfa59289e354d27c152
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

0.2.6 This release

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

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