This project demonstrates how to create a Telegram chatbot using ChatGPT, Flask, and EC2. The following technologies and services are used:
- Ngrok and Flask as a server.
- Telegram BOT Token obtained from "BotFather".
- ChatGPT API for generating responses.
- Flask App as an API for the Request/Response model.
- AWS EC2 for deployment (24/7 running).
- Create free accounts on OpenAI, AWS, and Ngrok.
- Create a Flask App.
- Create an EC2 instance on AWS.
- Git clone this repository on the EC2 instance.
- Create a Telegram bot using "BotFather" and obtain the API Token.
- Use the
TELEGRAM_BOT_TOKENandOPENAI_API_KEYin your code (avoid using static values, use global variables). - Run the script on the EC2 instance.
- Open a second terminal and use Ngrok to create a tunnel on port
5000. - Set up a webhook for Telegram verification.
To use this project:
-
Clone the repository.
-
Open a terminal in the working directory.
-
Run the following command to install the required dependencies:
pip install -r requirements.txt -
telegram_bot.pyis the Flask API that handles the request/response of the chatbot. -
Run the script with the following command:
python3 telegram_bot.py -
To set up the webhook, use the following format:
https://api.telegram.org/bot<Your Bot Token>/setWebhook?url=<URL of App>
For a more detailed explanation of this project, refer to the tutorial on the Machine Learning Hub YouTube channel.
If you find this project helpful, consider supporting me:
- Buy me a Coffee☕
- Donate via PayPal (It will inspire me to work on more projects)
Feel free to follow me and star⭐ this repository!