Skip to main content

A framework to develop UI & logic for telegram bots with class based views

Project description

Televiewshka

Note: as for now, this is neither stable nor working code. Being Created in ... purposes it is a subject for further updates and improvements

viewshka - Russian noun: informal of eng. "view", obtained by adding a diminutive suffix "shka"

Televiewshka allows you develop UI & logic for telegram bots with class based views. In views you can define its content and how user actions and replies must be handled on it. When all stuff related particular step in user flow is held in one class, you can clearly see relationship between components

Televiewshka supposed to be developed in such a manner to be compatible with a bunch of libs and frameworks for telegram bot api widely used by community

I guess I should write few adaptors for this purpose someday

(Supposed) Example

from telebot import TeleBot
from televiewshka import KeyboardView, \
    KeyboardLayout, Button, adaptors, handler, render

# create adaptor for your lib/framework
bot = TeleBot("super-secret")
bot = adaptors.create_adaptor(bot)


# specify views
class FirstView(KeyboardView):
    @bot.action_handler(action="next")
    def go_next(self, query: Query):
        return render("NextView", inplace=True, param=42)

    @staticmethod
    def render():
        return KeyboardLayout(
            keyboard = (
                Button("Go next", on_click="next"),
            ))


class NextView(KeyboardView):
    @bot.action_handler()
    def back(self, query: Query):
        return render(FirstView, inplace=True)

    @staticmethod
    def render(param: int):
        return KeyboardLayout(
            text=f"Passed param: {param}",
            keyboard = (
                Button("Go back", on_click="back"),
            ))

# run the bot
bot.start()

Some details explained

Views

something that can be rendered to user and than handle user actions on itselves actions are dispatched to appropriate view' and method in accordance with user state (e.g. current_scene flag) which is set when the view is rendered

Dispatch

messages are being dispatched according to user' state state = current view callback data or message = view method

User state

pass

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

televiewshka-0.0.1.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

televiewshka-0.0.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file televiewshka-0.0.1.tar.gz.

File metadata

  • Download URL: televiewshka-0.0.1.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for televiewshka-0.0.1.tar.gz
Algorithm Hash digest
SHA256 eb5a5754215036b178db50be63346db3ecc60ba28ccad33efc082cb4736e3e70
MD5 15f46c18ce739e508567ef9458cff7d7
BLAKE2b-256 e3c245a75c3a81e0dbe2e31e1cd74797caa92728931dda3d00a53eabc1fa2894

See more details on using hashes here.

File details

Details for the file televiewshka-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: televiewshka-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for televiewshka-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0bf0885c168ba52cbe64540bc447faf885853b9a3a1879e1cae223ced00baf6b
MD5 cbf9cce55af71babee7b7bbd51aedd4a
BLAKE2b-256 7d26695c4c3b99041067ee54488f83ac1238894ef821a5f51c7d13353bb000e1

See more details on using hashes here.

Supported by

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