示例HTML文件,其中包含与Telegram Web应用程序API的普通JS交互。现场演示:附加机器人。
Web应用程序必须托管在某个地方。将其托管在GitHub存储库上是一种快速,免费的方法:
https://{github-username}.github.io/{repository-name}/{location-inside-repository}
。在这种情况下: https://revenkroz.github.io/telegram-web-app-bot-example/index.html
://revenkroz.github.io/telegram-web-app-bot-example/index.html 向用户显示一个特殊的菜单按钮(靠近消息输入字段):
Bot Settings
- Menu Button
- Specify..
/ Edit menu button URL
https://revenkroz.github.io/telegram-web-app-bot-example/index.html
)第二种方法是将包含files web_app
的数据发送到Web应用程序:
{
"text" : " Test web_app " ,
"web_app" : {
"url" : " https://revenkroz.github.io/telegram-web-app-bot-example/index.html "
}
}
要将Web应用程序连接到Telegram Client,请使用此代码(更多信息)将脚本telegram-web-app.js
放在<head>
标签中<head>标签。
< script src =" https://telegram.org/js/telegram-web-app.js " > </ script >
连接脚本后, window.Telegram.WebApp
对象将可用。