WhatsApp Bot Developed using Twilio and Python Flask
- A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated python virtual environments for them.
-
Run following command to create a new virtual environment inside your project folder:
python -m venv myvenv
-
After running above command, a folder named myvenv will get created in your project folder.
-
Activate the virtual environment by running following command: For ubuntu and mac users:
source myvenv/bin/activate
For windows users:
myvenv\Scripts\activate
flask :
pip install flask
twilio :
pip install twilio
-
Create Flask App and Run
python app.py
(or)
Manual Flask Run :
For CMD :
$ export FLASK_APP=hello.py
$ export FLASK_DEBUG=1
$ flask run
For PowerShell :
$env:FLASK_APP = "hello.py"
$env:FLASK_DEBUG = 1
flask run
Upload code to git then config heroku
-
Install the Heroku CLI Download and install the Heroku CLI.
-
If you haven't already, log in to your Heroku account and follow the prompts to create a new SSH public key.
$ heroku login
- Use Git to clone wbhelper's source code to your local machine.
$ heroku git:clone -a reponame
$ cd reponame
- Deploy your changes Make some changes to the code you just cloned and deploy them to Heroku using Git.
$ git add .
$ git commit -am "make it better"
$ git push heroku master
Note :
-
A Procfile is a mechanism for declaring what commands are run by your application's dynos on the Heroku platform.
web gunicorn app:app
-
Also, install gunicorn in your virtual environment:
pip install gunicorn
-
To specify a particular version of Python via your app's runtime.txt
python-3.7.2
- Contains all 3rd party libraries required by your app.
Simply do:
pip freeze > requirements.txt
to generate a requirements.txt file.
Create : python -m venv myvenv
Activate : myvenv\Scripts\activate
To check path :
$env:PATH
(PS)
-
.gitignore file specifies patterns which are used to exclude certain files in your working directory from your Git history.
-
Open file and type file name to ignore :
myvenv/
*.pyc
-
Login into dialogflow console
-
Create a new agent or import a pre-built agent
-
From settings page of agent, open the service account of your project in Google Cloud Console
-
Create a new service account for your project. Download private key for the service account in a JSON file
-
Install Python Client for Dialogflow dialogflow-python-client
pip install dialogflow