This Repository houses a fully functional Telegram Mini APP example with development and deployment instructions.
With Mini Apps developers can use JavaScript to create infinitely flexible interfaces that can be launched right inside Telegram — and can completely replace any website. read more >>
In this repository we are going to implement a simple but functional Telegram Mini App to play Yatzy.
Keep reading to get familiar with repository directory structure, and development and deployments instructions.
.devcontainer: configs for dev container environmentpublic: contains web app interfacecss: contains web app stylesheetsjs: contains js logic of web appimages: images folderindex.html: web app interface HTML file.
src: web app and bot server-sidebot: telegram bot logicdb: contains logic for redis connectionexpress: contains express-related logiccontrollers: web app controllers logicmiddlewares: web app APIs middlewaresroutes: web app routeshelpers.js: controllers-related helpersindex.js: express server
game: game logic (Yatzy)models: contains db queries
tests: project unit tests.env: environment variable file (you should create this).env.example: environment variable example file.eslintrc: eslint rulesconfig: config file (its values are set via environment variable)docker-compose.ymlDockerfileindex.js: project entrypointngrok.js: logic for starting an ngrok tunnelpackage.jsonpackage-lock.json
- Nodejs runtime.
npmpackage manager.- Redis as database.
- Telegram bot token: Use @BotFather to obtain your bot token. >> tutorial
- Ngrok authentication token: We will use it to creating a secure https tunnel to communicate with telegram bot and web app in dev environment. Just signup and get your token.
- jQuery and bootstrap for developing web app interface.
- express: Fast, unopinionated, minimalist web framework for Node.js.
- telegraf: Modern Telegram Bot API framework for Node.js
- ioredis: A robust, performance-focused and full-featured Redis client for Node.js.
- ngrok: Node.js wrapper for the ngrok client.
If you have Docker installed and VS code, install Dev Containers VS code extension. By this you will be able to run and open devcontainer of this repository.
Install dependencies by running
npm installthen copy .env.example and rename it to .env;
cp .env.example .envset your proper environment variables then if you want to use ngrok tunnel run it first;
npm run ngrokset the tunnel address as BOT_WEBHOOK_DOMAIN and WEB_APP_URL, and then start the project;
npm startIf you want to use an HTTP proxy for communicating to telegram, set the GLOBAL_AGENT_HTTP_PROXY environment variable and the start project as bellow;
npm run proxifiedIn dev environment you can run tests by;
npm testRun it By (installing dependencies)[#install-dependencies] or just Clone the repo, set the environment variables, move to project root and run
docker compose up -dStop it by
docker compose down