Open source ChatGPT Telegram Bot via Telegraf is an advanced Telegram bot designed to provide seamless text, voice, and photo interactions using OpenAI's ChatGPT. Built with the Telegraf framework, this bot allows users to ask ChatGPT questions via text messages, voice messages, and even photos, receiving text responses. Ideal for enhancing user engagement, customer support, and more, this bot leverages PostgreSQL for data storage and can integrate with Pinecone vector database to improve the quality of answers by utilizing long-term memory.
Telegram Bot from this repository is available at:
https://t.me/chat_gpt_ai_open_source_bot
Feel free to interact with the bot and test its capabilities!
- Text Message Processing: Handles text messages, converting them to responses.
- Voice Message Processing: Handles voice messages, converting them to text for processing.
- Photo Message Processing: Handles photo messages, converting them to text for processing.
- OpenAI's ChatGPT Integration: Utilizes the powerful ChatGPT model to generate responses.
- Perplexity AI Integration: Enhanced search capabilities for more accurate responses.
- PostgreSQL Database: Stores user data and interactions in a PostgreSQL database.
- Docker and Docker Compose Support: Easily deploy the bot using Docker and Docker Compose.
- Pinecone Integration: Optional long-term memory support using Pinecone.
-
Clone the repository:
git clone https://github.com/kirill-markin/chatgpt-telegram-bot-telegraf.git cd chatgpt-telegram-bot-telegraf
-
Copy the
.env.example
file to.env
and fill in the required values:cp .env.example .env
-
Open the
.env
file and configure the following variables:TELEGRAM_BOT_TOKEN=replace_with_your_telegram_bot_token OPENAI_API_KEY=replace_with_your_openai_api_key DATABASE_URL=replace_with_your_database_url # You can change the settings path if needed # Path can be URL to static file or local file SETTINGS_PATH=./settings/private_en.yaml # Optional: Perplexity API key for enhanced search capabilities PERPLEXITY_API_KEY=replace_with_your_perplexity_api_key # Optional: Set the maximum tokens for trial users, default is 0 (no trial) MAX_TRIAL_TOKENS=100000 # Optional: Only if you want to use Pinecone for Long-Term Memory PINECONE_API_KEY=replace_with_your_pinecone_api_key PINECONE_INDEX_NAME=replace_with_your_pinecone_index_name
-
If you use remote settings, you can set the URL in the
.env
file inSETTINGS_PATH
. The URL should point to a YAML file with the the same structure as thesettings/private_en.yaml
file. For example:SETTINGS_PATH=https://kirill-markin.com/data/chatgpt-telegram-bot-telegraf_settings.yaml
-
Make sure you have the latest version of Docker.
-
Start the services:
docker compose up -d
-
To stop the services, run:
docker compose down
-
Build and run the Docker container:
docker build -t chatgpt-telegram-bot-telegraf . docker run --rm -it chatgpt-telegram-bot-telegraf
Ensure you have met the following requirements:
- Node.js and npm installed, long-term support (lts) version recomended to avoid warnings
- PostgreSQL database
- OpenAI API key
- Perplexity API key (optional, for enhanced search capabilities)
- Docker and Docker Compose (optional)
- Pinecone API key (optional)
-
Clone the repository:
git clone https://github.com/kirill-markin/chatgpt-telegram-bot-telegraf.git cd chatgpt-telegram-bot-telegraf
-
Copy the
.env.example
file to.env
and fill in the required values:cp .env.example .env
-
Open the
.env
file and configure the following variables -
Install the dependencies:
npm install
-
Run prestart script to fetch the config file:
npm run prestart
-
Start the bot:
npm start
-
To run the tests, use the following command:
npm test
Ensure all dependencies are installed:
npm install
To display help information about available commands, use the following command:
npm run help
To print list of all PREMIUM users, use the following command:
npm run list-premium
The output will include the user ID, username, and the creation date formatted as Created at: YYYY-MM-DD HH:MM:SS UTC
, sorted by the most recent creation date first.
You can set a user as PREMIUM via the command line.
Use the following command to set a user as PREMIUM:
npm run set-premium <userId>
Replace <userId>
with the ID of the user you want to set as PREMIUM.
Example:
npm run set-premium 123456789
Please google how to get the user ID in Telegram, as it is not the same as the username.
To remove the PREMIUM status from a user, use the following command:
npm run remove-premium <userId>
Example:
npm run remove-premium 123456789
- The
users
table stores information about the bot users. - The
messages
table stores the messages exchanged between users and the bot. - The
events
table logs various events related to user interactions and bot operations.
Contributions are welcome! Please fork the repository and create a pull request with your changes.
This project is licensed under the MIT License. See the LICENSE file for details.