A library to create multilevel menus for chatbots
Project description
navmenu
A library to create multilevel menus for chatbots.
Installation
navmenu can be installed with pip:
pip3 install navmenu
Introduction
First, import everything you will need:
from navmenu import MenuManager
from navmenu.actions import MessageAction, SubmenuAction, GoBackAction
from navmenu.contents import Content
from navmenu.io import ConsoleIO
from navmenu.item_contents import TextItemContent
from navmenu.items import Item
from navmenu.menus import Menu
from navmenu.state import MemoryStateHandler
Then, create a menu with one item:
menu = Menu(Content('Welcome!'), [
Item('print', TextItemContent('print text'), MessageAction('Text message'))
])
'print' is the internal menu item name. It can be any string but must be unique within menu.
Also, you can add items to menus later:
new_item = Item('hello', TextItemContent('say hello'), MessageAction('Hello!'))
menu.add_item(new_item)
Every menu should be wrapped in a MenuManager:
menu_manager = MenuManager({
'main_menu': menu
}, MemoryStateHandler('main_menu'))
MemoryStateHandler('main_menu') means that the user state will be saved in memory. It will not persist between app restarts. 'main_menu' is the name of the first menu to show.
Finally, show the menu to a user:
io = ConsoleIO(menu_manager)
io.start_loop()
Links
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters