This repository contains a Telegram bot built with Node.js and TypeScript. The bot integrates with OpenAI's API to process and respond to messages.
- Node.js (v18.x or higher recommended)
- npm (Node Package Manager)
- An OpenAI API key
- A Telegram bot token
To use this bot, you'll need an API key from OpenAI. Follow these steps to get your key:
- Visit OpenAI's API platform.
- Sign up for an account or log in if you already have one.
- Navigate to the API keys section and generate a new key.
To interact with Telegram's Bot API, you need a bot token. Here's how to create one:
- Open Telegram and search for the "BotFather" user.
- Start a chat and use the
/newbot
command to create a new bot. - Follow the instructions to set a name and username for your bot.
- BotFather will provide a token; keep this token secure as it allows control over your bot.
To set up and run the bot, follow these steps:
-
Clone or download the repository to your local machine.
-
Navigate to the bot's directory
-
Install the project dependencies by running the following command:
npm install
-
Copy the .env.example file to a new file named
.env
.cp .env.sample .env
-
Open the
.env
file and replace the placeholders with your OpenAI API key and Telegram bot token:OPENAI_API_KEY='your_openai_api_key_here' TELEGRAM_BOT_TOKEN='your_telegram_bot_token_here'
-
Start the bot by running the following command:
npm run dev