TMA Examples
Check out the examples below to see how to create your own Telegram Mini App.
Basic TMA Example
This is a basic and straightforward Telegram Mini App(TMA) implemented using plain JavaScript, HTML, and CSS. This project aims to provide a minimalistic example of how to create a simple TMA and launch it within Telegram without relying on complex build tools or bleeding-edge libraries.
- App is available via direct link: t.me/simple_telegram_mini_app_bot/app
- Or you can launch app with a bot menu button: t.me/simple_telegram_mini_app_bot
- Deployment URL: https://telegram-mini-apps-dev.github.io/vanilla-js-boilerplate/
Open Demo
GitHub
Features
- Minimalistic user interface.
- No external libraries or frameworks used.
- Easy to understand and modify.
Getting Started
Prerequisites
To run this example, you'll need a modern web browser with JavaScript enabled.
Installation
- Clone this repository to your local machine:
git clone https://github.com/Telegram-Mini-Apps-Dev/vanilla-js-boilerplate.git
- Navigate to the project directory:
cd vanilla-js-boilerplate
Open index.html in your preferred code editor or IDE.
Usage
- Open index.html in your preferred code editor or IDE.
- Make your changes.
- Create your own GitHub repository, commit and push your updates.
- Go to your repository GitHub page and open Settings. Check the Pages tab and Build and deployment section. If GitHub Actions option was selected, assets should be deployed to Pages and there will be an URL like
https://<username>.github.io/vanilla-js-boilerplate/
. You can copy this URL and use it with BotFather bot to create your very own TWA.
Modern TMA Example
Introduction
Vite (which means "fast" in French) is a front-end build tool and development server that aims to provide a faster and leaner development experience for modern web projects. We will utilise Vite to create this Telegram Mini App example.
You can find the example project here https://github.com/Telegram-Mini-Apps-Dev/vite-boilerplate or you can go through following instructions.
Prerequisites
We are going to start with scaffolding your Vite project.
With NPM:
$ npm create vite@latest
With Yarn:
$ yarn create vite
Then follow the prompts!
Or you can simply run this command to create React project with TypeScript Support:
# npm 7+, extra double-dash is needed:
npm create vite my-react-telegram-web-app -- --template react-ts
# or yarn
yarn create vite my-react-telegram-web-app --template react-ts
# this will change the directory to recently created project
cd my-react-telegram-web-app
Development of Mini App
Now we need to start the development mode of the project, run the following commands in terminal:
# npm
npm install
npm run dev --host
# or yarn
yarn
yarn dev --host
--host
option allows you to get URL with IP address, which you can use for test purposes during the development process. Important note: In development mode we are going to use a self-signed SSL certificate, which will give us the option to test our app with hot reload only in the web version of Telegram https://web.telegram.org/ due to the other platforms (iOS, Android, MacOS) policies.
We need to add @vitejs/plugin-basic-ssl
plugin:
- npm
- Yarn
- pnpm
npm install @vitejs/plugin-basic-ssl
yarn add @vitejs/plugin-basic-ssl