mercredi 3 août 2022

What is an efficient way to generate and process numbered text menus?

I have a program accessed over USSD where the user dials *123# and is presented with a numbered text menu. Like so

1 item 1
2 item 2
3 item 3
4 item 4

The user enters a number and is either presented with a submenu:

1 sub 1
2 sub 2

or is asked to enter an integer:

Enter amount between 25 - 1000

I have a few requirements to make the menus:

  1. dynamic so I can easily swap the submenus (e.g., enter amount should be third step) or step 1 should go to the end of the main menu.
  2. efficiently read user input if he enters an entire sequence like *123*2*(amount)*(destination)
  3. associate a step (to enter integer) with a token, so I can gather all the inputs to a map and then feed it to a function. For example, parsing the example in 2 would give me {amount: 200, destination: 38228382}
  4. input parsing should be efficient, so the app can perform under high load

I have searched a lot, but it looks like people either hard code things or their app is proprietary. For now, I have saved regex patterns for each step to a database so if the user enters *123# they are shown the main menu, for *123*2# a message is shown to enter amount and for *123*2*200# another message is shown to enter destination. If the user goes through the menu step by step, I concatenate all the steps and try to match them with a pattern. This is not efficient because for each input I am evaluating a lot of regex patterns. I also get the entered input with hard coded indexes, i.e., [2] is amount, which is bad too.

I was wondering if anybody could tell me if there are patterns/algorithms designed for generating/parsing numbered text menus?

Aucun commentaire:

Enregistrer un commentaire