Step-by-step guide
Telegram Mini Apps (TMA) are web applications that run inside the Telegram app. They are built using web technologies, including HTML, CSS, and JavaScript. TMAs can be used to create apps and games.
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>
tip
It's best to disable caching using HTTP response headers. To ensure caching is disabled, configure these headers in your server responses:
Cache-Control: no-store, must-revalidate
Pragma: no-cache
Expires: 0
-
Once the script is loaded, the
window.Telegram.WebApp
object becomes available. Learn more about creating a Mini App usingtelegram-web-app.js
. -
You can also use the
@twa-dev/sdk
npm package:
- npm
- Yarn
- pnpm
- Bun
npm install @twa-dev/sdk
yarn add @twa-dev/sdk
pnpm add @twa-dev/sdk
bun add @twa-dev/sdk
See the Modern TMA example for @twa-dev/sdk
in this guide.
- Once your Mini App is deployed, continue with Setting up a bot for the Mini App.
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 @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 Mini App for the bot
- 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 enter the URL when prompted by BotFather (e.g., a link from GitHub pages deployment).
4. Access the bot
- Search for your bot using its username in Telegram's search bar.
- Tap the Menu button (next to the attachment icon) to launch your Telegram Mini App.
Was this article useful?