It's a simple Telegram bot that utilizes OpenAI's ChatGPT API to generate human-like responses to user messages. The bot can be used in both private chats and group chats, responding only when mentioned in a group chat. (In order to activate bot in a group chat, you need to make bot an admin of a group)
To run this project, you need:
- Node.js (version 14 or higher) installed on your machine.
- A Telegram bot token, which can be obtained by creating a new bot using the BotFather on Telegram.
- An OpenAI API key, which can be obtained by signing up for an API key on the OpenAI website.
Before running the project, you need to install the following packages globally:
- TypeScript:
npm install -g typescript
- ts-node:
npm install -g ts-node
These packages are required for compiling and running TypeScript code.
-
Clone the repository or copy the provided code into a new directory.
-
Create a
.env
file in the project directory and add the following variables:
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
OPENAI_API_KEY=your_openai_api_key
Replace your_telegram_bot_token
and your_openai_api_key
with your actual Telegram bot token and OpenAI API key, respectively.
- Install the required dependencies by running:
npm install
- Run the bot using the following command:
npm run start:dev
# or for production
npm start
The bot should now be running, and you should see the message "Telegram bot is running..." in your console.
You can now interact with the bot by sending it a message on Telegram. If the bot is added to a group chat, it will respond when mentioned.