This README provides setup instructions for creating a Telegram Bot using Typescript, OpenAI API and Replit. Using these technologies, you can create a bot that can respond to user commands and execute functions programmed into the code.
Before starting this project, make sure you have the following ready:
- Telegram Desktop (https://desktop.telegram.org/)
- OpenAI API account (https://openai.com/)
- Replit account (https://repl.it/)
- Create a new project in Replit, making sure to select Typescript as your language when prompted. After the project is created, click on “Open in IDE” to open the project in an online editor or click on “Open in Terminal” to open it in a command line interface (CLI).
- In your CLI, run
npm install --save @types/node @types/telegraf
. This will install telegraf library package which supports Typescript.
- Create an OpenAI account and log in at https://openai.com/signup/.
- Click on your profile icon in the upper right corner of the page and select “API Keys” from the dropdown menu.
- On the API Keys page, click “Generate New Key” to generate a new API key for your account.
- The new API key will be displayed on the page – make sure to copy it down or save it somewhere safe as you won’t be able to see it again once you leave this page!
- Store the Open API Key as a
secret
in the Replit project.
- Register a Telegram Bot: First, you will need to register your bot with the Telegram Bot Father. This can be done by sending a message to @BotFather (the official bot from Telegram). Once you do that, type in the command “/newbot” and follow the instructions provided by Bot Father. After completing the registration process, you will be provided with an access token which you will need later on.
- Save the access token as a
secret
in the Replit project. - Setting up the bot commands by chatting
/setcommands
to @BotFather and set following commandwhoami
,tldr
,ama
,code
,explaincode
,brainstorm
.
Just click Run
on Replit the project and the bot ready to help you answering your questions!
Tips: to make it always available, you can use Always On
feature on Replit.
Almost 90% of this README content is generated by the help of this bot itself :)