ตัวอย่าง html-file ที่มีการโต้ตอบแบบธรรมดากับ Telegram Web Apps API การสาธิตสด: แนบบอท
เว็บแอปจะต้องโฮสต์ที่ไหนสักแห่ง การโฮสต์บนพื้นที่เก็บข้อมูล GitHub เป็นวิธีที่รวดเร็วและฟรีในการทำ:
https://{github-username}.github.io/{repository-name}/{location-inside-repository}
ในกรณีนี้: https://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
) วิธีที่สองคือการส่งปุ่มพร้อมข้อมูลที่มี field web_app
พร้อม URL ไปยังเว็บแอป:
{
"text" : " Test web_app " ,
"web_app" : {
"url" : " https://revenkroz.github.io/telegram-web-app-bot-example/index.html "
}
}
ในการเชื่อมต่อเว็บแอปเข้ากับไคลเอนต์โทรเลขวางสคริปต์ telegram-web-app.js
ในแท็ก <head>
ก่อนที่สคริปต์อื่น ๆ โดยใช้รหัสนี้ (ข้อมูลเพิ่มเติม):
< script src =" https://telegram.org/js/telegram-web-app.js " > </ script >
เมื่อเชื่อมต่อสคริปต์วัตถุ window.Telegram.WebApp
จะพร้อมใช้งาน