【问题标题】:updates in telegram bot switch()电报机器人开关()中的更新
【发布时间】:2017-06-07 00:33:57
【问题描述】:

我在我的 .php 文件中编写了这段代码,并在其中设置了运行良好的 webHook。

$token = "my token";
$website = "https://api.telegram.org/bot" . $token . "/";
$updates = file_get_contents("php://input");
$updates = json_decode($updates, true);
$text = $updates["message"]["text"];
$chatID = $updates["message"]["chat"]["id"];

switch($text){
  case "/prova_gratuita":
        if(check($chatID)){
          sendMessage($chatID, "Are you sure? Demo is available only one time. Write confirm to continue");
          switch($text){
            case "confirm":
                 ...
                 break;
          } 
        }

第二个switch() 不起作用。为什么?我能做些什么? 我知道我应该更新$text 的值,但我不知道该怎么做

【问题讨论】:

  • 为什么它应该起作用?
  • 对不起,我没有完成这个问题。 @u_mulder

标签: php webhooks telegram-bot php-telegram-bot telegram-webhook


【解决方案1】:

我认为错误是您设置问题的方式。 每个机器人输入都是对该 WebHook 的调用。那么 $ text 就不能这样 aggornato 了。

您还应该在第一个开关中包含第二个“case”。

$token = "my token";
$website = "https://api.telegram.org/bot" . $token . "/";
$updates = file_get_contents("php://input");
$updates = json_decode($updates, true);
$text = $updates["message"]["text"];
$chatID = $updates["message"]["chat"]["id"];

switch($text){
    case "/prova_gratuita":
        if(check($chatID))    sendMessage($chatID, "Are you sure? Demo is available only one time. Write confirm to continue");
    case "confirm":
    ...

 }

每次您向机器人发送消息时,他都会调用 WebHook。所以要改变 $updates 的状态,所以即使是 $text 脚本也应该重启

【讨论】:

  • 我明白了。谢谢
  • 每次您向机器人发送消息时,他都会调用 WebHook。所以要改变 $updates 的状态,所以即使是 $text 脚本也应该重启
  • Sisi adesso ci sono arrivato。 Grazie di nuovo
  • 拜托,这也是答案的一部分:)
猜你喜欢
  • 2017-08-18
  • 1970-01-01
  • 2017-01-23
  • 1970-01-01
  • 2015-09-22
  • 1970-01-01
  • 2022-11-09
  • 2018-02-27
  • 2018-07-22
相关资源
最近更新 更多