如何通过频道中的按钮打开电报网络应用程序(不是私人聊天)?

问题描述 投票:0回答:2

有没有办法通过单击按钮从频道打开 Telegram 中的 Web 应用程序?也就是算法是什么?

向频道添加机器人 机器人通过按钮发送消息 用户单击按钮,应用程序将在 Telegram 中打开

问题:右键消息没有发送。错误:

 [error_code] => 400
 [description] => Bad Request: BUTTON_TYPE_INVALID

我的代码:

   $telegram = new Telegram($bot_api_key, $bot_username);

      $keyboard = [
          "inline_keyboard" => [
              [
                   [
                     'text' => 'Open App',
                     'web_app' => ['url' => 'https://test.com/bot.php'],
                   ]
              ]
          ]
      ];
      $result = Request::sendMessage([
        'chat_id' => $chat_id,
        'parse_mode' => 'markdown',
        'text'    => 'Test message',
        'reply_markup' => $keyboard
      ]);
php api bots telegram
2个回答
1
投票

不可能!

您想要的功能仅适用于 BoT 在私人聊天中发送的消息,不适用于频道或群组。

由于 web 或 webview 可能存在漏洞/脚本,并且不是托管在 telegram 服务器上,而是托管在用户上,因此这样做是为了避免此类情况。

但是,您可以简单地发送一个链接按钮,该按钮将打开并提示在 telegran 官方客户端中打开链接。


0
投票
  1. 通过 botFather 创建 /newapp
  2. 创建一个带有普通链接的内联按钮,如下所示
  3. https://t.me/your_bot/your_app?startapp
示例:

$msg['text'] = "Message"; $msg["reply_markup"] = json_encode(["inline_keyboard" => [ [["text"=>"button","url"=>"https://t.me/your_bot/your_app?startApp"]]] ]); tlgrm("sendMessage", $msg, $user);
    
© www.soinside.com 2019 - 2024. All rights reserved.