TMA launch tutorial
Telegram Mini Apps (TMA) are web applications that run inside the Telegram messenger. They are built using web technologies—HTML, CSS, and JavaScript. Telegram Mini Apps can be used to create dApps, games, and other types of apps that can be run inside Telegram.
Create your Mini App
- To connect your Mini App to Telegram, add the SDK script
telegram-web-app.js
using this code:
<script src="https://telegram.org/js/telegram-web-app.js"></script>
It's best to disable caching in the HTML. To ensure your caching is turned off, specify these headers in your request:
Cache-Control: no-store, must-revalidate
Pragma: no-cache
Expires: 0
-
Once the script is connected, the window.Telegram.WebApp object becomes available. Learn more about creating Mini App using
telegram-web-app.js
here. -
You can also connect the SDK using the NPM package for Telegram Mini Apps SDK:
- npm
- Yarn
- pnpm
npm i @twa-dev/sdk
yarn add @twa-dev/sdk
pnpm add @twa-dev/sdk
Find a guide for @twa-dev/sdk
here.
- Once your Mini App is ready and deployed to a web server, move on to the next step.
Setting up a bot for the Mini App
To connect your Mini App to Telegram, you need to create a bot and set up a Mini App for it. Follow these steps:
1. Start a chat with BotFather
- Open the Telegram app or web version.
- Search for
@BotFather
in the search bar or click this link https://t.me/BotFather. - Start a chat with BotFather by clicking
START
.
2. Create a new bot
- Send the
/newbot
command to BotFather. - Choose a display name for your bot. It can include spaces.
- Choose a unique username for your bot that ends with
bot
, such assample_bot
.
3. Set up the bot Mini App
- Send the
/mybots
command to @BotFather. - Select your bot from the list and choose Bot settings.
- Select Menu button.
- Choose Edit menu button URL and send URL to your Telegram Mini App (e.g., a link from GitHub Pages deployment).
4. Access the bot
- Search for your bot using its username in Telegram's search bar.
- Click the button next to attach picker to launch your Telegram Mini App in messenger.
- You’re awesome!