You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Telethon Bot创建WebView按钮触发ButtonTypeInvalidError问题求助

解决Telethon发送WebApp按钮时的ButtonTypeInvalidError错误

你遇到的ButtonTypeInvalidError是因为直接使用types.KeyboardButtonWebView不符合Telethon发送消息时的按钮格式规范,Telethon要求用其自定义的按钮构造器来创建WebView按钮。

改用Telethon内置的Button.webview()方法即可解决问题,示例代码如下:

from telethon.tl.custom.button import Button

await client.send_message(
    event.chat_id,
    "Test",
    buttons=[
        Button.webview("press me", "https://google.com")
    ]
)

额外注意事项:

  • 确保你的Telethon版本为最新版,旧版本可能存在WebView按钮的兼容性问题
  • WebApp按钮仅在私聊场景下能正常展示,部分群组环境会受Telegram限制无法显示
  • 传入的WebApp链接必须是合法的HTTPS地址,Telegram不支持HTTP链接的WebApp

内容的提问来源于stack exchange,提问作者Dariosky

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 16:45:43