Skip to main content

An Elegant Modern Bot Framework for Python

Project description

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)", "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 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")

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

Telegant-0.2.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

Telegant-0.2.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file Telegant-0.2.1.tar.gz.

File metadata

  • Download URL: Telegant-0.2.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for Telegant-0.2.1.tar.gz
Algorithm Hash digest
SHA256 35d0574102847fe663e4f018e557602880c8615815eaf70c39f02ce2997748fa
MD5 5ebea5df19041a804dc41a364a319503
BLAKE2b-256 713e96c827326bf2384101d47b5d14664a2640339e40622c7a6b634ccb7692bb

See more details on using hashes here.

File details

Details for the file Telegant-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: Telegant-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for Telegant-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 61733cb00c131965cc363a81bd1580ed52618467f228bbe0d84fb381175ca914
MD5 33debf18415096d5f6d7994c09796ee3
BLAKE2b-256 03c701f16b4bfae71d0932e3fd7428a877c151ef8fb9c009b8b1f7ffaaa36c0e

See more details on using hashes here.

Supported by

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