This Node.js application integrates a Telegram chatbot with ElasticSearch for search functionalities and utilizes ChatGPT for generating conversational responses. It fetches search results from ElasticSearch based on user queries received via Telegram, then prompts ChatGPT with contextual information to generate relevant responses.
-
Install Dependencies
- Ensure you have Node.js installed on your system.
- Run
npm install
to install the required dependencies specified inpackage.json
.
-
Environment Variables
- Create a
.env
file in the root directory. - Add the following environment variables to the
.env
file:BOTTOKEN=YOUR_TELEGRAM_BOT_TOKEN ELKAPIKEY=YOUR_ELASTICSEARCH_API_KEY VTIGPTKEY=YOUR_CHATGPT_API_KEY ELKURL=YOUR_ELASTICSEARCH_URL ELKUSER=YOUR_ELASTICSEARCH_USERNAME ELKPASS=YOUR_ELASTICSEARCH_PASSWORD
- Replace
YOUR_TELEGRAM_BOT_TOKEN
,YOUR_ELASTICSEARCH_API_KEY
,YOUR_CHATGPT_API_KEY
,YOUR_ELASTICSEARCH_URL
,YOUR_ELASTICSEARCH_USERNAME
, andYOUR_ELASTICSEARCH_PASSWORD
with your respective API keys and Elasticsearch credentials.
- Create a
-
Telegram Bot Initialization
- Create a new Telegram bot using BotFather.
- Obtain the bot token and replace
YOUR_TELEGRAM_BOT_TOKEN
with it in the.env
file.
-
ElasticSearch Setup
- Set up an instance of ElasticSearch and obtain the necessary credentials.
- Replace
YOUR_ELASTICSEARCH_API_KEY
,YOUR_ELASTICSEARCH_URL
,YOUR_ELASTICSEARCH_USERNAME
, andYOUR_ELASTICSEARCH_PASSWORD
with your ElasticSearch configuration.
-
ChatGPT Setup
- Obtain an API key for ChatGPT from the OpenAI platform.
- Replace
YOUR_CHATGPT_API_KEY
with your ChatGPT API key in the.env
file.
-
Running the Application
- Execute
node index.js
to start the application. - Your Telegram bot is now active and ready to respond to messages.
- Execute
- Send messages to your Telegram bot to trigger responses.
- The bot will search for relevant content in ElasticSearch based on the received message and generate responses using ChatGPT.
- Ensure your ElasticSearch instance is configured correctly and contains the necessary data for search functionality.
- Monitor API usage and manage rate limits for both ElasticSearch and ChatGPT to avoid exceeding quotas.
This project is licensed under the MIT License.