-1

I would like a help to make submenus, from the menu number "1". I tried using the code below but it did not work.

Here is my code:

@signals.message_received.connect
def handle(message):
    # Main menu
    if message.command == "Olá":
        menuPrincipal(message)
    # 1 - Budgeting
    elif message.command == "1":
        orcamentos(message)
    # 2 - Track an order already in progress
    elif message.command == "2":
        pedidoAndamento(message)
    # 3 - Change the date, time or location of the event
    elif message.command == "3":
        alterarPedido(message)
    # 4 - Special Offers
    elif message.command == "4":
        promocoes(message)
    # 5 - Speak to a representative
    elif message.command == "5":
        chamarRepresentante(message)

Below is the orcamentos() function that I would like to put as a submenu:

def orcamentos(message):
    mac.send_message(txtOrcamentos, message.conversation)
        # 1 Party kit
    if message.command == "1":
        partyKit(message)
        # 2 Confectionery cake
    elif message.command == "2":
        confCake(message)
        # 3 Salty pie
    elif message.command == "3":
        saltPie(message)
        # 4 Cupcakes
    elif message.command == "4":
        cupcakes(message)
        # 5 Sweets
    elif message.command == "5":
        sweets(message)
        # 6 Salty
    elif message.command == "6":
        salty(message)
Maicon Costa
  • 23
  • 1
  • 5
  • What user interface library are you using? – martineau Oct 30 '17 at 21:18
  • A library that connects via whatstapp, the user types the data via whatsapp. With the menus working, but I'm not able to do submenus. – Maicon Costa Oct 30 '17 at 21:39
  • "A library that connects via whatstapp" isn't specific enough. How do you expect anyone to be able to help if they don't even know what library you're trying to use? – martineau Oct 30 '17 at 21:42
  • Sorry, I thought the question was more about python. The library name is macbot. – Maicon Costa Oct 30 '17 at 21:48
  • Every human interface library has a different way of handling menus and submenus, so answering "how to do them?" questions requires know that bit of information (unless you're getting a `SyntaxError` or some other generic problem). – martineau Oct 30 '17 at 21:51
  • Okay. Do you have any suggestions on how to do them? – Maicon Costa Oct 30 '17 at 21:53
  • No, never heard of it (and couldn't find it). Is there documentation? Where is it located? – martineau Oct 31 '17 at 00:18

1 Answers1

0

you can use regex or 'in' keyword, ex : if "1" in message.command: but i will prefer using regex so it will be more specified that what user types is a command or not.

also if you like to compress your files(because i am having like 30+menu in my bot) you will probably like to keep them in seperate file, so you can use this interface file 'yowsup.layers.interface' which contains 'YowInterfaceLayer, ProtocolEntityCallback'.

"^fun$" this regex will detect the word fun and "^wiki (?P[^$]+)$" will detect the word after the keyword wiki so it have far more control over commands.