Skip to content

Hassi34/whatsapp-ai-chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

WhatsApp Chatbot

Typing SVG

animated

License Build Last Commit Code Size Repo Size License Issue Tracking Open Issues

Following are the main contents to follow, you can jump to any section:

Introduction

WhatsApp Chatbot with OpenAI Integration is a sophisticated messaging bot that can be deployed to interact with users on WhatsApp. Leveraging the Twilio API for WhatsApp messaging and the ChatGPT by OpenAI for natural language processing, this bot can understand and respond to user queries in a conversational manner. It goes beyond basic chatbots by utilizing custom tools to access the internet, ensuring that it can provide up-to-date information and perform a wide range of tasks.

System Design

image

Key Features

1- Seamless WhatsApp Integration: Users can interact with the chatbot just like they would with any other contact on WhatsApp, making it a user-friendly and familiar experience.

2- Natural Language Processing: The chatbot uses OpenAI's advanced language models to understand and generate human-like responses, making interactions feel more natural and engaging.

3- Custom Tools: Custom-built tools enhance the bot's capabilities, allowing it to access the internet for real-time information retrieval and perform a variety of tasks.

4- Internet Access: The bot can browse the internet to fetch the latest information, news, weather updates, and more, ensuring users receive up-to-date answers.

5- Customizable: Developers can easily customize the bot's responses, actions, and integration with other services to meet specific project requirements.

6- DevOps Practices: This project adheres to industry-standard DevOps practices for deployment, ensuring reliability, scalability, and ease of maintenance.

Tech Stack Used

1. Python 
2. Generative AI 
3. Docker
4. RESTful API(Flask)
5. Chatbot
6. Cloud Computing
7. SMTP Server

Infrastructure

1. DockerHub
2. Twilio
3. ChatGPT
4. GitHub
5. Ngrok
6. CircleCI
7. AWS-EC2 as a Self hosted runner

CICD on Circleci

image

Run Locally

Either you can clone the repo and run the project using source or you can directly run a docker container

Run with source code

  • Ensure you have Python 3.8+ installed.

  • Create a new Python Conda environment:

conda create -n venv python=3.11  
conda activate venv 

OR

  • Create a new Python virtual environment with pip:
virtualenv venv
source venv/Scripts/activate

Install dependencies

  pip install -r requirements.txt

Clone the project

  git clone https://github.com/Hassi34/whatsapp-ai-chatbot.git

Go to the project directory

  cd whatsapp-ai-chatbot

Export the environment variable

OPENAI_API_KEY=""
SERPAPI_API_KEY=""
OPENWEATHER_API_KEY=""

AWS_ACCESS_KEY_ID=""
AWS_SECRET_ACCESS_KEY=""
AWS_DEFAULT_REGION=""

ENV_FILE_PATH_RUNNER=""

#Email Alerts
EMAIL_PASS=""
SERVER_EMAIL=""
SANITY_CHECK_EMAIL_RECIPIENTS=""
PRODUCTION_DEPLOYMENT_SUCCESS_EMAIL_RECIPIENTS=""

Run a docker container

First ensure you have the docker installed on your system and then run following commands: πŸ‘‡πŸ»

Pull Image from Docker Hub

In case you have not already pulled the image from the Docker Hub, you can use the following command:

docker pull hassi34/whatsapp-ai-chatbot

Docker Container

Now once you have the docker image from the Docker Hub, you can now run the following commands to test and deploy the container to the web

  • Run a Docker Container
    Check all the available images:
docker images

Use the following command to run a docker container on your system:

docker run -itd -e OPENAI_API_KEY=$OPENAI_API_KEY -e SERPAPI_API_KEY=$SERPAPI_API_KEY -e OPENWEATHER_API_KEY=$OPENWEATHER_API_KEY -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION --name <CONTAINER NAME> -p 8080:8080 hassi34/whatsapp-ai-chatbot

Check if the container is running:

docker ps -a

If the container is running, then the API services will be available at port 8080
Enter the following url to you Twilio Post request:

http://<YOUR IP ADDRESS>:8080/chatgpt_webhook

Conclusion

This project is production ready for similar use cases and comes with the industry standard engineering practices.

πŸ‘‰πŸ»Thank you for visiting πŸ™ Your feedback would be highly appreciated πŸ’―πŸ˜Š

πŸ‘‰πŸ»If you find this project useful then don't forget to star the repo βœ¨β­πŸ€–

πŸ“ƒ License

MIT Β© Hasanain

Let's connect on LinkedIn