{"id":21461528,"url":"https://github.com/andreisoroka/telegram-bot-web-app","last_synced_at":"2025-03-17T04:49:35.800Z","repository":{"id":244874285,"uuid":"815708375","full_name":"AndreiSoroka/telegram-bot-web-app","owner":"AndreiSoroka","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-27T23:44:08.000Z","size":185,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-23T14:28:02.274Z","etag":null,"topics":["telegram-bot","telegram-bot-example"],"latest_commit_sha":null,"homepage":"https://t.me/TestAssignmentBot","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AndreiSoroka.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-15T22:50:00.000Z","updated_at":"2024-11-10T16:27:25.000Z","dependencies_parsed_at":"2024-06-28T01:04:26.790Z","dependency_job_id":null,"html_url":"https://github.com/AndreiSoroka/telegram-bot-web-app","commit_stats":null,"previous_names":["andreisoroka/telegram-bot-web-app"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreiSoroka%2Ftelegram-bot-web-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreiSoroka%2Ftelegram-bot-web-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreiSoroka%2Ftelegram-bot-web-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreiSoroka%2Ftelegram-bot-web-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AndreiSoroka","download_url":"https://codeload.github.com/AndreiSoroka/telegram-bot-web-app/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243976502,"owners_count":20377692,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["telegram-bot","telegram-bot-example"],"created_at":"2024-11-23T07:09:31.400Z","updated_at":"2025-03-17T04:49:35.780Z","avatar_url":"https://github.com/AndreiSoroka.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"🌐 Demo: https://t.me/TestAssignmentBot\n\n# Technologies list:\n- **Telegram Bot:**\n  - Node.js\n  - TypeScript\n  - Grammy\n  - TypeORM/SQLite/MySQL\n  - Zod\n  - tsx \u0026 pkgroll\n- **Web App:**\n  - Rollup\n  - TypeScript\n  - Snabbdom\n\n\u003cdetails\u003e\n  \u003csummary\u003eFew words about the project (click)\u003c/summary\u003e\n  The last time I created a bot was back in 2018.\n  The bot used to read chats, and if someone typed “!Friday”,\n  it would send a random video.\n  As an Easter egg, I’ve added a similar command in memory of that first bot.\n  \n  Overall, I was very excited to work on this test assignment.\n  It was a stroke of luck because I had been planning\n  to integrate a bot for one of my projects and needed to delve deeper into it.\n  Naturally, I ended up spending more time on it than initially planned.\n  \n  I can say that Telegram has changed significantly over these six years.\n  Additionally, I finally got a chance to try Rollup directly and Snabbdom.\n  I had wanted to for a long time, but never had a reason until now.\n\u003c/details\u003e\n\n---\n\n# Test Assignment\n\n\u003e Create a Simple Telegram Web App Bot in Node.js\n\u003e\n\u003e ### Requirements:\n\u003e\n\u003e 1. `/start` Command:\n\u003e   - The bot should have a `/start` command that sends a message with a web app button.\n\u003e   - The button should open a website displaying the user’s Telegram first name (e.g., “Hello, !”).\n\u003e 2. Database Integration:\n\u003e   - The bot should save the users of the bot in a database (SQLite or PostgreSQL).\n\u003e 3. Admin Command:\n\u003e   - The bot should have an `/adminhello \u003ctelegram_id\u003e \u003ctext\u003e` command that only certain Telegram users can use.\n\u003e   - Example usage: `/adminhello 274139721 Hello from admin!`\n\u003e   - This command should send a message from the bot, “Hello from admin!” to the user with a Telegram ID of 274139721.\n\u003e   - Admin users can get user IDs directly from the database. Admins can be hardcoded.\n\n---\n\n# Project Overview. How to start app?\n\nThis repository consists of two main projects:\n\n1. **Telegram Bot** - node.js application that interacts with the Telegram API.\n2. **Web App** – generate static files for the Web App.\n\n---\n\n## Dependencies\n\nRepository uses npm [workspaces](https://docs.npmjs.com/cli/v10/using-npm/workspaces) to manage dependencies.\n\nTo install all dependencies, run the following command in the root directory:\n\n```bash\nnpm install\n```\n\n## Telegram Bot\n\n### 🔥 Fast Start\n\nYou can register a new bot using BotFather: https://t.me/botfather\n\nTo start the bot, you need to provide the following environment variables:\n\n```bash\nTELEGRAM_BOT_TOKEN=\"\u003ctelegram-token\u003e\" ADMINS=\"\u003ctelegram-id\u003e\" npm start -w telegram-bot\n```\n\nOr, to configure the Telegram bot before starting it,\ncreate a `./telegram-bot/.env.local` file with the following contents:\n\n```dotenv\n### File: ./telegram-bot/.env.local\n\nTELEGRAM_BOT_TOKEN=\u003ctelegram-token\u003e\nADMINS=\u003ctelegram-id\u003e\n```\n\nThen, run the bot using the following command:\n\n```bash\nnpm start -w telegram-bot\n```\n\n🚀 Now your bot is running and ready to accept commands.\n\n### 🧩 Full Configuration for local development\n\nFor local development, you need to install\n[serve](https://www.npmjs.com/package/serve)\nand [ngrok](https://ngrok.com/).\n\n```dotenv\n### File: ./web-app/.env.local\n\nTELEGRAM_BOT_NAME=\u003ctelegram-bot-name\u003e\n```\n\nTo start the `web-app`, run the following commands:\n\n```bash\nnpm run build -w web-app\nserve ./web-app/dist\nngrok http http://localhost:3000/\n```\n\nFrom ngrok, copy the URL and paste it into the `WEB_APP_URL` environment variable in the `./telegram-bot/.env.local` file.\nThe link should look like `https://\u003cyour-ngrok-id\u003e.ngrok.io`.\n\nTo start the bot, you need to provide the following environment variables:\n\n```dotenv\n### File: ./telegram-bot/.env.local\n\nTELEGRAM_BOT_TOKEN=\u003ctelegram-token\u003e\nADMINS=\u003ctelegram-id\u003e[,\u003ctelegram-id\u003e,...]\nSQLITE_PATH=.temp/database/path/\nWEB_APP_URL=https://\u003cyour-ngrok-id\u003e.ngrok.io\n```\n\n```bash\nnpm start -w telegram-bot\n```\n\n### 📝 Deployment to production (cPanel example)\n\n\u003e **Note:** Why do I deploy to **cPanel**? I just have cheap hosting for many years.\n\n1. Configure environment variables for the Telegram bot in the `./telegram-bot/.env.production.local` file or in the **cPanel** environment variables.\n\n   ```dotenv\n    ### File: ./telegram-bot/.env.production.local\n\n    TELEGRAM_BOT_TOKEN=\u003ctelegram-token\u003e\n    ADMINS=\u003ctelegram-id\u003e[,\u003ctelegram-id\u003e,...]\n    ### Database settings:\n    DATABASE_TYPE=mysql\n    MYSQL_HOST=localhost\n    MYSQL_PORT=3306\n    MYSQL_USER=\u003cmysql-user\u003e\n    MYSQL_PASSWORD=\u003cmysql-password\u003e# 🥲\n    MYSQL_DATABASE=\u003cmysql-database\u003e\n    ### Webhook settings:\n    WEBHOOK_BASE_URL=https://\u003cyour-server\u003e/\n    WEBHOOK_PATH=/webhook\n    ### Web App settings:\n    WEB_APP_URL=https://\u003cyour-server\u003e/\n   ```\n\n2. Configure environment variables for the `web-app` in the `./web-app/.env.production.local` file.\n\n   ```dotenv\n    ### File: ./web-app/.env.production.local\n\n    TELEGRAM_BOT_NAME=\u003ctelegram-bot-name\u003e\n   ```\n\n3. Build the `telegram-bot` and `web-app`\n   ```bash\n   npm run build --workspaces\n   # or\n   # npm run build -w telegram-bot\n   # npm run build -w web-app\n   ```\n4. Create cPanel ESM starter script (_cPanel specific_)\n\n   ```javascript\n   // File: ./telegram-bot/dist/index.cjs\n\n   import(\"index.mjs\");\n   ```\n\n5. Upload the `./telegram-bot/dist` and `./web-app/dist` directories to the server.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreisoroka%2Ftelegram-bot-web-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreisoroka%2Ftelegram-bot-web-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreisoroka%2Ftelegram-bot-web-app/lists"}