A proof-of-concept integration between Twilio Whatsapp and OpenAI ChatGPT.
Most conversational commerce companies are interested in how new AI developments may improve end user experience. This is a proof of concept project for using WhatsApp as an interface to OpenAI, allowing a customizable prompt and a short-term memory. The project can be modified to include some more elaborate features, such as using embeddings for a custom knowledge base, or integrating with other OpenAI features such as speech to text and image generation.
- Python 3.10 - Check out Libraries And Frameworks
- Docker - Package the app for deployment
- SQL Database - Linked offering has a generous free tier
- Twilio Account - First users get free credits
- OpenAI API Key - First users get free credits
- Ngrok (or other network tunneling tool) for local development
- Fly.io CLI - Free tier up to 3 apps, easily package and run Docker based applications
- Clone this Repository
git clone https://github.com/deistermatheus/whatsLLM.git
- Create an environment file, setting appropriate variables for Database, Twilio and OpenAI:
cp .env.example .env
- Create the Database Structure
alembic upgrade head
- Start the API
uvicorn project.api.main:app --host 0.0.0.0 --reload
- Alternatively, to run a local docker image of the project:
docker build -t whatsllm .
docker run -it -p 8000:8000 --env-file=./.env whatsllm bash server.sh
- Check the OpenAPI docs page or make a direct request to see the project is up and running:
curl -X 'GET' \
'http://localhost:8000/health' \
-H 'accept: application/json'
- Setup your Twilio Webhook Endpoint
For local development, ngrok is recommended to get a public url for Twilio:
ngrok http 8000
After obtaining a public URL, set up the Whatsapp Webhook in the Twilio Console. The docs for Twilio Webhooks can be found here.
To start the deployment process, a Fly.io account is required:
fly launch
The app requires a database connection and API keys for integrations, to set required environment variables:
fly secrets import < .env
After making changes:
fly deploy
The app should now be available in a public url such as:
https://<your-chosen-app-name>.fly.dev/health
https://<your-chosen-app-name>.fly.dev/docs
Create a new secret in the repository with:
fly tokens create deploy -x 99999h
Setup the GitHub Action by defining a new repository secret with the token
- Get the integration working
- Add SQL Database for short term context
- Save customizable prompt in chatbot configs
- Deploy to the cloud
- Add Telegram as alternative channel
- Allow more customization choices over GPT (model, temperature...)
- Voice support
- Image generation
- Embeddings for larger context
- Add Automated Testing with CI Check
- Improve OpenAPI documentation
- Improve Type Hinting
This project is licensed under the MIT License - see the LICENSE.md file for details