Telegram Bot Game not working

筅森魡賤 提交于 2019-12-10 11:55:13

问题


I am realizing my bot telegram with a game. I wrote this:

$content = file_get_contents("php://input");
$update = json_decode($content, true);
if(!$update)
{
    exit;
}
$chatId = isset($message['chat']['id']) ? $message['chat']['id'] : "";

header("Content-Type: application/json");
$parameters = array('chat_id' => $chatId);
$parameters["method"] = "sendGame";
$parameters["game_short_name"] = "prova";
$parameters["text"] = parse_url("<my_html_5_url>");
$message = json_encode($parameters);
echo json_encode($parameters);

My sample html5 code is:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Title of the document</title>
    </head>

    <body>
        Content of the document......
    </body>

</html>

When I call the game, I only see the image inserted by Botfather, but I have no chance to see my html5. Where am I wrong?


回答1:


I edit in this way:

$content = file_get_contents("php://input");
$update = json_decode($content, true);

if(!$update)
{
  exit;
}

$message = isset($update['message']) ? $update['message'] : "";
$messageId = isset($message['message_id']) ? $message['message_id'] : "";
$chatId = isset($message['chat']['id']) ? $message['chat']['id'] : "";
header("Content-Type: application/json");

if(isset($update["callback_query"])) {
  $parameters["method"] = "answerCallbackQuery";
  $parameters["callback_query_id"] = $update["callback_query"]["id"];
  $parameters["url"] = "<my_html_5_url>";
  echo json_encode($parameters);

  die;
}
$parameters = array('chat_id' => $chatId);
$parameters["method"] = "sendGame";
$parameters["game_short_name"] = "prova";

echo json_encode($parameters);


来源:https://stackoverflow.com/questions/42188779/telegram-bot-game-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!