Skip to main content

botomorph

This framework is designed for writing bots that can use various frameworks to interact with the messenger API.

Install

pip install botomorph

GitHub: https://github.com/rezschikovivan/botomorph

Why use

The framework allows you to run bots written in it on different platforms, using different frameworks to interact with their APIs. The class-based approach to writing handlers allows you to use inheritance to extract common logic or define a family of similar bots.

Features

  • Multiplatform bots
  • Inheritance of handlers
  • A class-based approach to writing bots
  • Has type hints
  • Asynchronous

Example

from botomorph import Filter, Handler, BaseMsg, Sender, Keyboard, start_bots
from botomorph.vkbottle_component import VKBottleComponent
from botomorph.aiogram_component import AiogramComponent

# If necessary, you can create your own handler class that will perform certain actions when methods are registered, such as checking for the presence of specific attributes or automatically registering methods in a registry. To do this, you need to create a class that inherits from ClsHandler and implement the before and after methods. The before method will be called before the handler class is created, and the after method will be called after the handler class is created. These methods allow you to perform any necessary actions with the handler class or its attributes. However, it is important to return the result of the parent call to avoid breaking the core's logic. 
class F(ClsHandler):

    def before(cls, mcs, name, bases, attrs):
        print(f"A handler class is being created {name}...")
        return super().before(mcs, name, bases, attrs)
    
    def after(cls, new_cls, mcs, name, bases, attrs):
        print(f"The {name} handler class has been successfully created!")
        return super().after(new_cls, mcs, name, bases, attrs)

set_handlers_registrator(F())

class Echo:

    @Handler(Filter().in_text("hi"))
    async def cab8(cls, message:BaseMsg):
        await message.answer("Вы воспользовались кнопкой!")

    @Handler(Filter().in_text("Привет"))
    async def cab2(cls, message:BaseMsg):
        await message.send_reply_kboard(keyboard=Keyboard([ [["name1", "data1"], ["name","data2"]] ]),text="реплай клавиатура")

class VKEcho(Echo, VKBottleComponent):    
    TOKEN = vk_token

    @Handler(Filter().text("кабинет"))
    async def cab3(cls, message:BaseMsg):
        await message.answer("Кфбинет №11")

    # An example of a handler method that displays information about the message and its sender in the console. In this method, we retrieve the sender object of the message and check for different types of attachments (photos, documents, audio, etc.), displaying this information in the console.
    # @Handler()
    # async def cab2(cls, message:BaseMsg):
    #     user:Sender = await message.sender
    #     print(user.first_name)
    #     print("ФОТО:  ", message.photo)
    #     print("ДОКУМЕНТ:  ", message.document)
    #     print("АУДИО:  ", message.audio)
    #     print("ГОЛОСОВОЕ:  ", message.voice)
    #     print("ВИДЕО:  ", message.video)
    #     print("ТЕКСТ:  ", message.text)
    #     print("data:  ", message.date)


class TGEcho(Echo, AiogramComponent):
    TOKEN = tgram_token

    @Handler(Filter().text("кабинет"))
    async def cab3(cls, message:BaseMsg):
        await message.answer("Кфбинет №22")

import asyncio
print("works")
asyncio.run(start_bots())

summary

Basic functionality is now available using aiogram and vkbottle. It currently lacks features such as inline_buttons and FSM, but it is ideal for writing bots that do not require complex user interaction but still support multi-platform

Metadata

Release files for botomorph 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for botomorph 1.0.0
File Size Uploaded
botomorph-1.0.0.tar.gz 15.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for botomorph 1.0.0
File Interpreter ABI Platform
botomorph-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.4 kB

Release files / botomorph-1.0.0.tar.gz

Download URL botomorph-1.0.0.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e27e9bb8dd3a9a2b8922e4a6a5eece45599c6b9d5c1e5070e8a95deaae239959
BLAKE2b-256 checksum
How to use checksums
c2bc9777d5944bd319c3932a681357214d86a408285d5c029232401b629992a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / botomorph-1.0.0-py3-none-any.whl

Download URL botomorph-1.0.0-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83bd30165b31a27300d0e508f4b4044a035187eb967e122d201bd1fcaccb6392
BLAKE2b-256 checksum
How to use checksums
50e91299d398b0c6af8807e4c91ebd466157a2d6d842dbffff024bb8ffbfa2a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page