Make your text-bot with only one handler.
Project description
textode
Textode is a simple tool to create text bots with only one handler. You can use it for Telegram, VK or any other social network.
What is it for
Textode helps you build static text bots.
Static text bots is bots that has concrete structure, like instruction on the pill bottle or a movie script. So, perfect examples of what you can do with this library is instruction bots, text quests, and so on.
What is it not for
It is not designed to build bots that use data provided by user (e.g. store user age).
What is the idea
In textode the main part of the bot is Node. It used to build bot structure.
For example, this is the basic bot in textode:
KeyboardNode(
title="/start",
text="Hello! Here is your keyboard.",
buttons=[
TextNode(title="About bot", text="*about*"),
ImageNode(title="Bot logo", path="logo.png"),
],
)
With this structure bot handles "/start" message, responses with "Hello! Here is your keyboard." text and keyboard of two buttons - "About bot" that sends text about bot and "Bot logo" that sends image of bot logo.
The main advantage of this approach is that your bot is now defined by concrete schema. Instead of making handlers you are designing Node structure.
Another advantage is that instead of many handlers you now have one. It works because of Node identity, they all have the same basic fields:
- title - message text that triggers node.
- text - text that sends back.
Because of that, you need to make only one handler that picking right node (depends on user input), handles if there is no node with this text, or handles node type (sends keyboard for KeyboardNode, image for ImageNode etc.).
Installation
via pip:
pip install textode
or poetry:
poetry add textode
Examples
Look here for usage examples (aiogram and vkbottle are presented) with schemas (built by Graphviz with JetBrains Mono font).
About usage
Note NodeDict
imports
If my_node.py
contains your node, you must import NodeDict
in this file,
and then import NodeDict
from my_node.py
to file with bot.
If your node and your bot are placed in one file, you only need to use
from textode import NodeDict
.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.