This project was developed to provide a personal Telegram Chatbot that allows communication with OpenAI's ChatGPT API. It aims to be deployed with AWS Lambda functions, in order to make it scalable.
Access it live on Telegram (only available for the admin, in order to avoid API costs to the owner. You can create your own, using this code as base)
- Ask ChatGPT specific questions;
- Have context based conversations with ChatGPT;
- Generate images from prompts with DALL-E 3;
- Provide images for chat contexts;
During the development of this project, the following techologies were used:
$ python -m venv env
$ .\env\Scripts\activate # On Windows machines
$ source ./env/bin/activate # On MacOS/Unix machines
(env) $ pip install -r requirements.txt
Create an .env file on the root directory, with all needed variables, credentials and API keys, according to the sample provided (example.env).
To run the project in a development environment, execute the following command on the root directory, with the virtual environment activated.
(env) $ python bot.py
In order to leave the virtual environment, you can simply execute the command below:
(env) $ deactivate
If you want to deploy the bot with AWS Lambda functions, the code file will be the lambda function file.
For that, there are some extra steps to be done, such as:
- Creating the AWS Lambda function;
- Setting the function trigger as an Amazon API Gateway;
- Setting the webhook for the Telegram communication with the API Gateway route;
- Creating the DynamoDB file with the messages list;
- Adjusting the AWS Lambda function role to allow accessing the DynamoDB tables;
- Setting up environment variables on the configurations for the Lambda function;
- Adding the external Python libraries to Lambda function using layers;
- Telegram Bot API
- Building a Scalable Telegram Chatbot with Python and Serverless Function.
- telegram.ext package
- Add External Python Libraries to AWS Lambda using Lambda Layers
This project is under the MIT license. For more information, access LICENSE.