minimalistic telegram bot framework that can be used in AWS Lambda or anywhere
Project description
MiniGram ๐ค๐ฌ
MiniGram is an ultraminimalistic Python library for building Telegram bots that's perfect for use in restricted environments like AWS Lambdas. Say goodbye to bloated libraries and hello to MiniGram's sleek and efficient design! ๐โจ
Features ๐
- Lightweight and minimalistic ๐
- Works in both synchronous and asynchronous modes โก๏ธ
- Seamless integration with popular web libraries like Starlette/FastAPI and aiohttp ๐
- Easy to use and understand API ๐
- Perfect for deploying bots in restricted environments like AWS Lambdas ๐
Installation ๐ฆ
To start building your super cool Telegram bot with MiniGram, simply install it using pip:
pip install minigram-py
Usage ๐
Using MiniGram is as easy as 1-2-3! Here are a few examples to get you started:
Basic Example
from minigram import MiniGram
class MyAwesomeBot(MiniGram):
def handle_update(self, update):
match update.update_type:
case "message":
match update.text:
case "/sync" | "/async":
self.reply(update, "I'm a bot, for sure! โ๏ธ")
case _:
self.send_text(
update.from_id,
f"I don't understand that command. ๐\nBut your id = {update.from_id}",
)
case "message_reaction":
self.reply(update, "I see you like this message!")
case "edited_message":
self.set_message_reaction(update, "๐")
bot = MyAwesomeBot(YOUR_BBOT_TOKEN)
bot.send_text(CHAT_ID, "Hello from an bot! ๐")
bot.start_polling()
In just a few lines of code, you've created a bot that responds to the "/start" command. How cool is that? ๐
Starlette Integration
from starlette.applications import Starlette
from starlette.routing import Route
from minigram import StarletteMiniGram
class MyStarletteBot(StarletteMiniGram):
async def incoming(self, msg):
if msg.text == "/hello":
return msg.reply("Hello from Starlette! ๐")
bot = MyStarletteBot("YOUR_BOT_TOKEN")
bot.set_webhook("https://yourwebsite.com/webhook")
app = Starlette(debug=True, routes=[
Route("/webhook", bot.starlette_handler, methods=["POST"]),
])
This example shows how seamlessly MiniGram integrates with Starlette, allowing you to create a webhook endpoint for your bot in no time! ๐
Asynchronous Mode
import asyncio
from minigram import AsyncMiniGram
class MyAsyncBot(AsyncMiniGram):
async def handle_update(self, update):
match update.update_type:
case "message":
match update.text:
case "/sync" | "/async":
await self.reply(update, "I'm a asynchronous bot, for sure! โ๏ธ")
case _:
await self.send_text(
update.from_id,
f"I don't understand that command. ๐\nBut your id = {update.from_id}",
)
case "message_reaction":
await self.reply(update, "I see you like this message!")
case "edited_message":
await self.set_message_reaction(update, "๐")
async def main():
bot = MyAsyncBot(BOT_TOKEN)
await bot.send_text(CHAT_ID, "Hello from an asynchronous bot! ๐")
await bot.start_polling()
if __name__ == "__main__":
asyncio.run(main())
MiniGram works just as well in asynchronous mode, making it easy to integrate with your existing async application. ๐๏ธ
Contributing ๐ค
We love contributions! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request on our GitHub repository. Let's make MiniGram even better together! ๐ช
License ๐
MiniGram is released under the MIT License, so feel free to use it in your projects, whether they're open-source or commercial. ๐
Now go forth and build some amazing bots with MiniGram! ๐๐ค
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
Built Distribution
File details
Details for the file minigram_py-0.3.0.tar.gz
.
File metadata
- Download URL: minigram_py-0.3.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f751156c7b4a16badc274c7e09b2e3184b295c402c0137a652b361e82decef57 |
|
MD5 | a1d8f2a402ee6178f4d7516b3c77adb5 |
|
BLAKE2b-256 | 0f7fa32805f7f0e74a3fdff71fdd197ca5aac987c0fbafa335b6170404f6fdc9 |
File details
Details for the file minigram_py-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: minigram_py-0.3.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 874d9036f67f3bdb573ef1f4ff044244ad83b87f8f0af78653de0716ab93f5aa |
|
MD5 | 8be70598ba5d9ddf0ac70fe325796f52 |
|
BLAKE2b-256 | a23715fa1abe0e3dec56d64265adea28c591626a9032d3460e38c20ed312bd1a |