-4

I'm programming a telegram bot in php, and everything is working, except that now I want to add sub menus inside my cases of the switch. For example, the user puts '/insertcolour', then the bots sends a message "Insert your favourite colour" and then how could I read that colour without exiting the primary switch?

I tried with this code inside my case:

  do{ 
      $update2 = file_get_contents('php://input'); 
      $update2 = json_decode($update2, TRUE);
    }while($update2['message']['message_id']==$messageId);

But it just gets stuck and stops reading other commands... Someone knows how to solve this?

Adrian
  • 7
  • 2

1 Answers1

0

You can't do like that, but you have an option if your using Switch case

$collors = array("green", "red", "Blue");

switch($text)
{
    case"/start":
        startmsg($msgID,$welcome);
        break;
    case"/insertcolour":
        insertcolour($msgID);
        break;
    default:
            if (in_array($text, $collors))
              {
              //you can add next function here
              }
            break;
  • Thanks for your response. But in this case I would have to do a big array with all the colours, right? Cause for example, if it weren't colours but employees ID's? Something that I couldn't create an array? Isn't there a way to reread the data sent afterwards the first message by the user inside one of the cases? – Adrian May 14 '21 at 01:12