telemenu
Easily build complex telegram menu logic with almost no code.
Because I'm writing a lot of code making that possible, lol.
Currently still a work in progress.
The details of what this library aims for, how it behaves and also some of the needed inner gearing is currently documented in telemenu/menus_old.py.
menus = TeleMenuMachine(database_driver=SimpleDictDriver(), teleflask_or_tblueprint=bot)
@menus.register
class MainMenu(GotoMenu):
title = "test"
description = "Lorem ipsum \n\n We even have access to the data:\n{data!r}"
def menus(self):
return [TestMenu, AnotherTestMenu]
# end def
# end class
Have a look at that example, if you like to see a full working example.
Available variables
All menus
(e.g. GotoMenu
, RadioMenu
, CheckboxMenu
)
-
title
(typestr
):
The bold headline of the menu. -
title_escape
(typebool
):
Set toFalse
to turn off the automatic HTML escaping. -
description
(typestr
):
The message part with user instructions. -
description_escape
(typebool
):
Set toFalse
to turn off the automatic HTML escaping. -
cancel
(typestr
,CancelButton
,BackButton
,GotoButton
,Menu
):
Goes to a different menu, deleting the data. Provide astr
which will be automatically be converted automatically to aCancelButton
.
If you provide aBackButton
or aGotoButton
you have to setdoes_cancel
toTrue
. -
back
(typestr
,BackButton
,GotoButton
,Menu
):
Goes to a different menu, without deleting or saving the data.
Provide astr
which will be automatically be converted automatically to aBackButton
. If you provide aBackButton
or aGotoButton
you have to setdoes_cancel
toFalse
. -
done
(typestr
,GotoButton
,Menu
):
Goes to a different menu, saving the data. Provide astr
which will be automatically be converted automatically to aBackButton
.
If you provide aGotoButton
you have to setdoes_cancel
toFalse
.
Internal variables you usually don't have to replace as they already have a sane default:
_id
(typestr
):
This allows you to overwrite the automaticly genereated name of the underlying state.
You should probably not change this.text
(typestr
): Returns a HTML string for the final rendered message. This is basically<b>{title}</b>\n{description}\n<i>{value}</i>
.value
(typestr
): basically does a user representation of what the current menu is storing. So for exampleCheckboxMenu
puts the labels of the selected strings (instead of the stored keys) as a comma separated list.value_escape
(typebool
):
Set toFalse
to turn off the automatic HTML escaping.
GotoMenu
menus
(list containing anyChangeMenuButton
button subclass (includingGotoButton
andBackButton
) or simply some otherMenu
s. You can mix those.):
This is a list of menus you can jump to.
RadioMenu
radiobuttons
(list ofRadioButton
elements):
A list of values to choose a single entry from.
CheckboxMenu
checkboxes
: (list ofCheckboxMenu
elements):
A list of values to choose a single entry from.
TextStrMenu
Make sure that all commands you want handled regardless of this menu are registered before this menu.
Note, the ALL
state is always processed only after all other states, including the menus. Therefore you must use a regular register.
Instead you should use @bot.on_command
and be sure to abort the processing of any other listeners.
This can be done by either using the @abort_processing
decorator (from teleflask import abort_processing
) or by raising raise AbortProcessingPlease()
(from teleflask.exceptions import AbortProcessingPlease
) directly.
parsing_success
(typestr
):
A text to send when the parsing succeed. Useful to hint users of/done
, etc.parsing_failure
(typestr
):
A text to send when the parsing failed. Useful to hint users of/done
, etc.