Skip to main content

An Elegant Modern Bot Framework for Python

Project description

Telegant

Telegant

Telegant is an elegant modern bot framework for Python, designed to provide developers with simple and elegant access to the Telegram bot API. The project is currently at the alpha testing stage and provides only the required basic features to prove the concept of simplicity.

Installation

To install the project, simply run:

pip install telegant

Example

from telegant import Telegant
import asyncio

bot = Telegant("YOUR_BOT_TOKEN_HERE")

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

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

asyncio.run(bot.start_polling())

Usage

On text

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

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

Sending bot with buttons

Inline buttons example

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

    await bot.sendMessage(chat_id=update["message"]["chat"]["id"],text="What's up?", reply_markup=bot.create_reply_markup(buttons))

Reply buttons example

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

    await bot.sendMessage(chat_id=pdate["message"]["chat"]["id"],text="What's up?", reply_markup=bot.create_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.sendMessage(chat_id=update["message"]["chat"]["id"], text="Sup I'm start")

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

@bot.commands(['help', 'ask'])
async def say_hello(bot, update):  
    await bot.sendMessage(chat_id=update["message"]["chat"]["id"], 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.sendMessage(chat_id=update["message"]["chat"]["id"], 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.sendMessage(chat_id=update["message"]["chat"]["id"], text="Callbacks are perfect!")

Single callback example

@bot.callback('option1')
async def say_hello(bot, update):  
    await bot.sendMessage(chat_id=update["message"]["chat"]["id"], 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.1.4.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

Telegant-0.1.4-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for Telegant-0.1.4.tar.gz
Algorithm Hash digest
SHA256 69eb7e2c0c8d5666d48f6341da9bcce0c73199d8709ab638ae828d144f072fd8
MD5 5f253117b0eeb35c6aa19a923ea203dc
BLAKE2b-256 c8aa6297919f84c595dd887aa8af0f71d8e6b7fc4d1b0259de75a2357a381837

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Telegant-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 6.3 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.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 071359b133471ddecb1d0e54ca2633b2f8aee08d539497c7c0145ba4bc8d5ea1
MD5 01745043ec821e7bfee20692c8b30153
BLAKE2b-256 dd565aac9baae8454c96dae24efdb929fefda90991649751db7e6c2960b4ca30

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