This is an application that uses the Twilio API for WhatsApp, Beautiful Soup, and Python 3 to parse the Goodreads quotes webpage.
You will need a few things to run this application.
- Python 3 installed
- Ngrok to make your Flask app visible from the internet so Twilio can send requests to it
- A Twilio account (sign up for a free Twilio account here)
- Your WhatsApp sandbox set up in your Twilio account
At the moment, only approved business accounts can use Twilio's WhatsApp API so we need to go on over to the Twilio WhatsApp Sandbox in our Twilio console. To activate it we must choose a Sandbox number, agree to the terms of WhatsApp, and select Activate Sandbox.
To join a Sandbox, send “join ” to your Sandbox number in WhatsApp and you should get a response confirming you’ve joined. You can follow these instructions to install the WhatsApp Sandbox Channel in your account and connect your WhatsApp account with the Sandbox.
Next, clone this application, cd
into the directory and install the necessary libraries and modules with pip3.
git clone https://github.com/elizabethsiegle/parse-html-for-top-goodreads-quotes-with-sms
cd parse-html-for-top-goodreads-quotes-with-sms
pip3 install requests twilio flask string bs4 random
If this throws permission errors run pip3 install --user [package]
.
On the command line in that directory run
python goodreads.py
and then open up a new terminal tab, get to the directory with your code, and run
ngrok http 5000
Make sure you configure your Twilio phone number configured with that public-facing URL as shown in this handy tutorial and pass it to your WhatsApp number as shown below.
Tada! You're now all set to build the rest of the app and should be able to send messages that look like this.