Telegram WebアプリAPIとのプレーンJS相互作用を含むHTMLファイルの例。ライブデモ:ボットを添付します。
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
) 2番目の方法は、WebアプリにURLを含むフィールドweb_app
を含むデータを使用してボタンを送信することです。
{
"text" : " Test web_app " ,
"web_app" : {
"url" : " https://revenkroz.github.io/telegram-web-app-bot-example/index.html "
}
}
WebアプリをTelegramクライアントに接続するには、このコードを使用して、他のスクリプトの前にスクリプトtelegram-web-app.js
<head>
タグに配置します(詳細):
< script src =" https://telegram.org/js/telegram-web-app.js " > </ script >
スクリプトが接続されると、 window.Telegram.WebApp
オブジェクトが利用可能になります。