【问题标题】:Telegram Bot sub menus in PHPPHP 中的 Telegram Bot 子菜单
【发布时间】:2021-08-03 22:01:57
【问题描述】:

我正在用 php 编写一个电报机器人,一切正常,除了现在我想在我的开关盒中添加子菜单。例如,用户输入“/insertcolour”,然后机器人发送消息“插入您最喜欢的颜色”,然后我如何在不退出主开关的情况下读取该颜色?

我尝试在我的案例中使用此代码:

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

但它只是卡住并停止读取其他命令... 有人知道如何解决这个问题吗?

【问题讨论】:

    标签: php telegram telegram-bot php-telegram-bot


    【解决方案1】:

    你不能那样做,但是如果你使用 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;
    

    【讨论】:

    • 感谢您的回复。但在这种情况下,我必须用所有颜色做一个大数组,对吧?例如,如果不是颜色而是员工 ID?我无法创建数组的东西?有没有办法在其中一个案例中重新读取用户在第一条消息之后发送的数据?
    猜你喜欢
    • 2022-01-26
    • 2021-07-12
    • 2021-11-26
    • 2018-12-10
    • 1970-01-01
    • 2018-09-22
    • 2017-05-13
    • 2016-07-15
    • 1970-01-01
    相关资源
    最近更新 更多