Skip to main content

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

YOUR_BOT_TOKEN = "0:0"
CHAT_ID = 0


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. ๐Ÿ˜•\n"
                            f"But 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_BOT_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

YOUR_BOT_TOKEN = "0:0"

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! ๐ŸŒ

FastAPI Integration

from fastapi import FastAPI, Request
from minigram import FastAPIMiniGram
from fastapi.responses import JSONResponse

class MyFastAPIBot(FastAPIMiniGram):
    async def incoming(self, msg):
        if msg.text == "/hello":
            return await msg.reply("Hello from FastAPI! ๐Ÿ‘‹")

bot = MyFastAPIBot("YOUR_BOT_TOKEN")
bot.set_webhook("https://yourwebsite.com/webhook")

app = FastAPI()

@app.post("/webhook")
async def webhook(request: Request):
    return await bot.fastapi_handler(request)

MiniGram supports both asynchronous and synchronous methods for FastAPI, giving you the flexibility to choose the best approach for your application. Whether you prefer async or sync, MiniGram has got you covered! ๐ŸŒ

Asynchronous Mode

import asyncio
from minigram import AsyncMiniGram

YOUR_BOT_TOKEN = "0:0"
CHAT_ID = 0

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. ๐Ÿ˜•\n"
                            f"But 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(YOUR_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

minigram_py-0.4.1.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

minigram_py-0.4.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file minigram_py-0.4.1.tar.gz.

File metadata

  • Download URL: minigram_py-0.4.1.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for minigram_py-0.4.1.tar.gz
Algorithm Hash digest
SHA256 deabed2be8b8321d425d7c6406398db2480bee1506570e0a8a5c6ca9b3d11cde
MD5 b30b8e059047f1c8d8de848c29776d23
BLAKE2b-256 e08a174bcc28665111b83c339b6b46869bf7205a046ef9ba04c2164680f84712

See more details on using hashes here.

File details

Details for the file minigram_py-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: minigram_py-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for minigram_py-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 659f943bde6bfa76df719a944d30b8ffa4003e3938b4e488f57aafadf591723d
MD5 06109846914a9fa129dcb75ce7cd8034
BLAKE2b-256 fe2c07ed1c8b3387c2dda2ecec50b92759b753f75f23fb4a186d1ee050a25d57

See more details on using hashes here.

Supported by

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