Giter Site home page Giter Site logo

minigram-py's Introduction

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! ๐ŸŽˆ๐Ÿค–

minigram-py's People

Contributors

bobuk avatar dimentium avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.