A basic slot machine game for Telegram, built with Node.js, Express, and Vite.
packages/frontend/Dockerfile
and packages/backend/Dockerfile
)package.json
)/newbot
to create a new bot./setinline
to BotFather./newgame
to BotFather./empty
.Clone the repository:
git clone https://github.com/your-username/slot-machine-monorepo.git
cd slot-machine-monorepo
Install dependencies:
pnpm install
Set up environment variables:
Create a .env
file in the packages/backend
directory with the following content:
BOT_TOKEN=your_telegram_bot_token
FRONTEND_URL=http://localhost:5173 # For local development
API_SECRET=your_chosen_api_secret
Remember to replace your_telegram_bot_token
with the actual token you received from BotFather.
Configure the frontend URL:
Update the backendUrl
in packages/frontend/src/game.ts
to match your backend deployment URL.
Clone the repository:
git clone https://github.com/your-username/slot-machine-monorepo.git
cd slot-machine-monorepo
Install dependencies:
pnpm install
Set up environment variables:
Create a .env
file in the packages/backend
directory with the following content:
BOT_TOKEN=your_telegram_bot_token
FRONTEND_URL=http://localhost:5173 # For local development
API_SECRET=your_chosen_api_secret
Remember to replace your_telegram_bot_token
with the actual token you received from BotFather.
Configure the frontend:
Update the backendUrl
in packages/frontend/src/game.ts
:
const backendUrl = "http://localhost:8080"; // For local development
Set up frontend environment variables:
Create a .env
file in the packages/frontend
directory with the following content:
VITE_BACKEND_URL=http://localhost:8080 # For local development
API_SECRET=your_chosen_api_secret
Remember to update this URL when deploying to production.
Start the frontend development server:
pnpm run dev:frontend
This will start the Vite development server, typically on http://localhost:5173.
In a new terminal, start the backend server:
pnpm run start:backend
This will start the Express server, typically on http://localhost:3000.
Open your browser and navigate to http://localhost:5173 to see the frontend.
To test the Telegram integration locally, you may need to use a tool like ngrok to expose your local server to the internet. Update the FRONTEND_URL
in your .env
file and the backendUrl
in the frontend code with the ngrok(or similar service) URL when testing.
Remember to update these URLs and environment variables when deploying to production.
packages/frontend/src/
.packages/backend/
.pnpm run start:backend
again).pnpm run format
to format your code before committing.This project is configured for deployment on Fly.io. Make sure you have the Fly CLI installed and are logged in.
Update environment variables:
In packages/backend/.env
:
BOT_TOKEN=your_telegram_bot_token
FRONTEND_URL=https://your-production-frontend-url.fly.dev
API_SECRET=your_chosen_api_secret
In packages/frontend/.env
:
VITE_BACKEND_URL=https://your-production-backend-url.fly.dev
API_SECRET=your_chosen_api_secret
Deploy the frontend:
pnpm run deploy:frontend
Deploy the backend:
pnpm run deploy:backend
Alternatively, you can deploy both at once:
pnpm run deploy:all
Note: Make sure your Fly.io account has the necessary resources allocated for both the frontend and backend applications. You may need to adjust the fly.toml
files in each package if you encounter any issues with resource allocation or scaling. If you have issues with env varibales not being set properly in the container for the front-end check in the Dockerfile line #15.
For more detailed information on Fly.io deployment, refer to their documentation.
Deployment scripts are taking care of environement variables for you, which means that you don't need anymore to add secrets manually on fly.io. In order to add environment variables for any of the apps (front or back) follow these instructions:
#Define env arguments here
section.Contributions are welcome! Please follow these steps:
git checkout -b feature/your-feature-name
git commit -m 'Add some feature'
git push origin feature/your-feature-name
When submitting a pull request, please use the provided PR template. For bug reports, please use the bug report template.
This project is licensed under the MIT License - see the LICENSE file for details.