示例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
對象將可用。