A webhook in Python Django framework for WhatsApp automation. This project is developed using WhatsApp Cloud API.
- Python3
- Django
- JSON
- Create new project in firebase
- Setup realtime database
- Navigate to Project Settings > Service Accounts > Firebase Admin SDK
- Select Python Language then generate new private key, This will download json file.
- Now copy the content of this JSON file and paste it in
webhook/firebase.py
(Line 10-21). - Then copy the database URL from Realtime Database Firebase Console and paste it in
webhook/firebase.py
(Line 8).
- Clone this repository to your workspace
git clone https://github.com/parth-p-7span/wabot-django.git
- Navigate to wabot-django directory in your terminal
cd wabot-django
- Install required packages using below command
pip install -r requirements.txt
- Add your database in
wabot/settings.py
file - Migrate database with following commands
python manage.py makemigrations
python manage.py migrate
- Run the project using below command
python manage.py runserver
- Deploy the project in any platform and obtain endpoint URL.
- Configure webhook in Meta developer portal. ( Please read this before proceeding ahead)
- Verify Token is given in the
wabot/settings.py
file with nameWA_VERIFY_TOKEN
webhook/actions.json
: A JSON file that holds all the actions needed to perform by the bot.webhook/firebase.py
: A Python file for connecting app to firebase and performing actions.webhook/func.py
: A Python file for performing whatsapp actions like send message, mark as read message, and send input validation error message.webhook/input_validator.py
: This file contains all the functions for validating input messages.
- The primary key of object contains the order of message that has to be sent via BOT.
next
key has the data of next message after performing one action.type
key has the data type of Bot's messageuser_input
key has boolean value. If it is true, the bot will wait for the user to send a message before sending the subsequent message; otherwise, the bot will keep sending subsequent messages.expected
key has the expected type of user's message. A validation error is sent if the user submits a message with the incorrect message type.child
key has the data of the message body as per Whatsapp Cloud API.