git clone git@github.com:MarioLisbona/v2-node-telegram-app.git
- cd into the directory
cd v2-node-telegram-app
- Change the filename
.env.sample
to.env
- Open Telegram: Open the Telegram app on your device or use the web version.
- Search for BotFather: In the search bar, type "BotFather" and select the BotFather account from the search results. BotFather is the official bot provided by Telegram for creating and managing bots.
- Start BotFather: Start a chat with BotFather by clicking on the "Start" button.
- Create a New Bot: Once you're in the chat with BotFather, type the following command to create a new bot:
/newbot
- Choose a Name: BotFather will ask you to choose a name for your bot. This name will be displayed in Telegram chats and contact lists.
- Choose a Username: Next, BotFather will ask you to choose a username for your bot. This username must be unique and end with "bot" (e.g., MyNewBot_bot).
- Bot Creation: After providing a name and username, BotFather will confirm the details you've entered and provide you with a token for your new bot. This token is necessary for authenticating requests to the Telegram Bot API.
- Save the Token: Copy the token and use its value for the
.env
key-pairBOT_TOKEN
- Run the following command to install the dependencies
npm install
- Run the following command to start the server
npm start
The front end will load at http://localhost:3000
- Create a new telegram chat and add the bot username
- Open the chat and click the 3 dots in the top right corner and select
info
- Find the bot in the members list and click it
- Click
Add to Group or Channel
and select the chat you want to use - Add the bot as Administrator
- If this is the first time you have created the chat, then you can send messages from either the client or the telegram app. This is because the
chatId
is set in thegroup_chat_created
handler. - If the the server restarts and connect to the bot in an existing chat, then the first message will need to be sent from the telegram app. This is because the
chatId
needs to be set in themessage
handler because it wasnt stored when the gourp was created.