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.reply(update["message"]["chat"]["id"], "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 defined text just use @bot.hears()
@bot.hears("hello")
async def say_hello(bot, update):
await bot.reply(update["message"]["chat"]["id"], "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.reply(update["message"]["chat"]["id"], "What's up?", buttons)
Reply buttons example
@bot.hears("hello")
async def say_hello(bot, update):
buttons = [
{"text": "Option 1 (reply)"},
]
await bot.reply(update["message"]["chat"]["id"], "What's up?", 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.reply(update["message"]["chat"]["id"], "Welcome, your bot works perfectly.", buttons)
For several commands use @bot.commands() decorator.
@bot.commands(['help', 'ask'])
async def say_hello(bot, update):
await bot.reply(update["message"]["chat"]["id"], "Basic help information.", buttons)
Export data after command by your keys
@bot.commands(['usernameandage'])
@bot.with_args(['username', 'age'])
async def handler(bot, update, data):
await bot.reply(update["message"]["chat"]["id"], 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.reply(update["message"]["chat"]["id"], "Callback is detected", buttons)
Single callback example
@bot.callback('option1')
async def say_hello(bot, update):
await bot.reply(update["message"]["chat"]["id"], "Callback is detected", buttons)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Telegant-0.1.2.tar.gz
.
File metadata
- Download URL: Telegant-0.1.2.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c954d987f004d74da5351a83cd45d60f7f44b868ddc2ab4ee73c9c1501d51bfa |
|
MD5 | d37fdba83d7c28dab800c31f753db5a9 |
|
BLAKE2b-256 | ae14f4d0148c547e694abd865d1ed1d37e139477592d2ec5c129044bac499e3b |
File details
Details for the file Telegant-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: Telegant-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 365eb968f704e4e0c640c50095187b76d147a3fb9dc4171ed37f96d356fbe6df |
|
MD5 | 9b90f67c1610e474bb61382e551016cc |
|
BLAKE2b-256 | 2d0fcd4c07170c7c8358758dec1efc4f7a0a875bc2e0128f5572367c555550ad |