Order a pizza from pizza tuesday and manage the orders using Telegram.
The project is built using Node.js, JavaScript, Telegraf and Firebase. It is set up for hosting on Heroku using CI/CD.
To run the project locally / in your own environt, you need to set up a few things first.
- Follow the instructions on creating a new bot using the BotFather.
- Store the api key safely
- Rename
.example.env
to.env
- Enter the previously saved token into the
TELEGRAM_TOKEN
variable
You could also create a second bot using the BotFather as a development bot. In this case, the production bot would run online (e.g. on Heroku) using the initial token. While you can develop and test new features using the development token.
- Set up a Firebase project
- Create a Firestore database
- Go to Settings > Service Accounts
- Generate a new private key
- Copy the value of
project_id
in this file toFIREBASE_PROJECT_ID
in.env
- Copy the value of
client_email
in this file toFIREBASE_CLIENT_EMAIL
in.env
- Copy the value of
private_key
in this file toFIREBASE_PRIVATE_KEY
in.env
- Set
FIRESTORE_USER_COLLECTION
to the name of the collection in Firebase Firestore that will store all user entries. (e.g.users
). To separate your development database from your production database, you could simply use a different collection name in your local environment variables, such asdev-users
. - Do the same to all other environment variables following this schema:
FIRESTORE_<ENTITY>_COLLECTION
.
The environment is set up to allow running in dev mode and in production mode. Before running the bot, make sure that you have followed all steps in the Set up section of this readme!
- Make sure that you have installed Node.js at version 17.0.0 or higher
- Install all dependencies by running
npm i
at the root directory - Run
npm run dev
This way you can do changes to your code and the bot will automatically restart on save. If you want to run it like in production, run npm start
instead of the command in step 3.
There are many different ways to host a Telegram bot like this, but I have chosen to host it as a worker on Heroku. This has the benefit of being completely free while also allowing easy CI/CD integration. I have followed this guide in order to set everything up if you are interested in the total process.
In case you are only interested in setting up the Heroku app using CI/CD, read more in this specific part of the article