├── .gitignore ├── README.md └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vscode 3 | frp 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Telegram Web Apps for Bots / Mini App Example 2 | 3 | Example HTML-file that contains a plain-JS interaction with Telegram Web Apps API. 4 | See live demo (with jQuery): [Attach Bot](https://t.me/asmico_attach_bot). 5 | 6 | ## Links 7 | * Official docs: https://core.telegram.org/bots/webapps 8 | * Live Demo Bot: [Attach Bot](https://t.me/asmico_attach_bot) 9 | * Telegram Promo Bot: [Durger King](https://t.me/durgerkingbot) 10 | 11 | ## Quick setup 12 | 13 | #### 0. Optional: Host the Web App in GitHub Pages 14 | 15 | The Web App must be hosted somewhere. Hosting it on a GitHub repository is a quick, free way to do it: 16 | 17 | 1. Create a repository (or fork this one) 18 | 2. On the repository: Settings –> Pages: 19 | - Source: Deploy from a branch 20 | - Branch: master, / (root), Save 21 | 3. Wait a few minutes for the web to be deployed. It will be available at: `https://{github-username}.github.io/{repository-name}/{location-inside-repository}`. In this case: `https://revenkroz.github.io/telegram-web-app-bot-example/index.html` 22 | 23 | #### 1. Show the user a button to open a Web App. There are two ways: 24 | 25 | 1. Show the user a special menu button (near the message input field): 26 | 1. Go to [Bot Father](https://t.me/BotFather) 27 | 2. Select your bot 28 | 3. To set button in Bio: `Bot Settings` — `Configure Mini App` 29 | 4. Send a URL to your Web App (in this case, `https://revenkroz.github.io/telegram-web-app-bot-example/index.html`) 30 | 5. To set corner button in Bot: `Bot Settings` — `Menu Button` — `Specify..`/`Edit menu button URL` 31 | 6. Send a URL to your Web App (in this case, `https://revenkroz.github.io/telegram-web-app-bot-example/index.html`) 32 | 33 | 2. The second way is to send a button with the data that contains field `web_app` with a URL to a Web App: 34 | ```json 35 | { 36 | "text": "Test web_app", 37 | "web_app": { 38 | "url": "https://revenkroz.github.io/telegram-web-app-bot-example/index.html" 39 | } 40 | } 41 | ``` 42 | 43 | #### 2. Add script to your Web App 44 | 45 | To connect a Web App to the Telegram client, place the script `telegram-web-app.js` in the `
` tag before any other scripts, using this code ([more info](https://core.telegram.org/bots/webapps#initializing-web-apps)): 46 | ```html 47 | 48 | ``` 49 | 50 | Once the script is connected, a `window.Telegram.WebApp` object will become available. 51 | 52 | #### 3. Do the thing! 53 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 21 |Test links:
420 |Test permissions:
464 |Sensors:
480 |Test alerts:
490 |Haptics:
508 |Cloud storage:
515 | 537 | 538 |Biometrics:
539 |Location:
553 |
565 |
571 |