DEV Community

idk
idk

Posted on

Surfgram - new era of Telegram Bots

Surfgram Logo
Hello World, I'm Alan, I'm 14 y.o python dev and I created my own framework for Telegram Bot API - Surfgram.

Surfgram is fully async, rust-powered (client for API communications written in Rust), OPP-based framework with CLI.

  1. First, you need to install surfgram:
pip install -U surfgram 
Enter fullscreen mode Exit fullscreen mode
  1. Create your first bot:
surfgram new mybot
Enter fullscreen mode Exit fullscreen mode
  1. Run your bot:
cd mybot
surfgram run --debug 
Enter fullscreen mode Exit fullscreen mode

Whoa! Your bot is running. Now you can read docs or check more examples

For example, you can create new bot command handler with:

from surfgram import APIObject, Bot
from surfgram.types import BotCommand
from typing import Callable, List

class StartCommand(BotCommand):
    @property
    def __names__(self) -> List[str]:
        return ["start"] # target: /start 

    @property
    def __callback__(self) -> Callable:
        return self.handle

    async def handle(
        self,
        update: APIObject,
        bot: Bot
    ) -> None:
        await bot.send_message(
            chat_id=update.message.chat.id,
            text="Hello, world!"
        )
Enter fullscreen mode Exit fullscreen mode

Thanks you for reading!

Top comments (0)