I need to go back to a previous menu

Hi, I had three menus “Main menu”, “Sub-menu” and “menu”

Main men contains opinions A, B, and C
If user select A bot will display the “Sub-menu” opinions X,Y, and Z
Now if user select" X" bot will respond with menu of M,N,L

Her if user type “go back” I need to get “Sub-menu” opinions of X,Y,Z

Is possible implement the common functionality when every user type “go back” or select “back” button redirect to previous menu