This repository can be used to create a WhatsApp chat bot that replies with the ChatGPT API. Therefore, you have to create a Whatsapp Business account and sign up at openai. Please follow the next steps:
- Create a WhatsApp Business Account for your app, as explained here. This will provide you with a phone number id and a Whatsapp access token. Export them as system variables as PHONE_NUMBER_ID and WHATSAPP_ACCESS_TOKEN
- Get an api key from openai.com. Store it as OPENAI_API_KEY.
- Start the Flask app with
python3 app.py
. - Create an ngrok account to make your app public. Run:
ngrok http 5002 --region us
. It is important to choose the us location. Otherwise Meta will block your ngrok forwarding. - Add the ngrok url as a webhook to your WhatsApp Business App as explained here.
- Add the phone number you want to chat with to the recipients list of your WhatsApp Business App. This is step 2 in link.
- Run:
python3 chatbot.py --new-number 49174xxxxxx"
, where you add the phone number you want to chat with here. This will send a hello world template message to your phone number. Now you can use this chat to chat with the bot. - If you want to restart the chat, just send "new chat" in the chat.