Skip to main content

Step-by-step guide

Telegram Mini Apps (TMA) are web applications that run inside the Telegram messenger. They are built using web technologies, including HTML, CSS, and JavaScript. TMAs can be used to create apps, games, and other types of applications.

Create your Mini App

  1. 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 turned off, configure these headers in your server responses:

Cache-Control: no-store, must-revalidate
Pragma: no-cache
Expires: 0
  1. Once the script is connected, the window.Telegram.WebApp object becomes available. Learn more about creating a Mini App using telegram-web-app.js here.

  2. You can also connect the SDK using the npm package for Telegram Mini Apps SDK:

npm i @twa-dev/sdk

See the Modern TMA example for @twa-dev/sdk in this guide.

  1. 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 as sample_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 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.
  • Click the button next to the attachment picker to launch your Telegram Mini App in messenger.
  • You’re awesome!
Was this article useful?