I assume that you get a message from the gateway such as:
(Session#, UserInput)
and you need to compute the next information to send to the user ?
I propose:
table CURRENTSTATE:
Session#
State
table STATES:
State
Title
table CHOICES:
State
Choice
Name
DoCode
NewState
Then when you get the message (Session#, UserInput):
- query CURRENTSTATE using the Session# to determine what state the user is in.
- query CHOICES using the State and Choice=UserInput to determine the new state (and DoCode) based on user input.
- Based on DoCode, you can do some processing.
- update CURRENTSTATE to reflect the new state.
- query STATES to get the Title (e.g. "Please choose a color").
- query CHOICES to get the possible choices from the new state (e.g. (1, "Blue"), (2, "Red"), etc.)
- build the message (concat Title + choices)
- return message to user.
Is that a reasonable way to solve the problem ?