Purpose of the project
zapier is a awesome tool that allows you to create a form of collaboration between the services that you are using on the web.
It gives you an easy way to build workflows where actions on a given website will trigger events on another of your preferred websites. One of the recipes (zap) that you can find on zapier catalog creates a notification in a Slack discussion channel when a comment is posted on your WordPress website.
The idea of this project is to use a bunch of Python tools (the Flask framework and the
requests library mostly) to build the same functionality in a small web server running on a Raspberry Pi.
Pourquoi faire simple quand on peut faire compliqué.
— Les Shadoks
Description of the workflow
When a new comment is posted on an article, WordPress sends a POST requests containing all the characteristics of the comment to a predefined URI.
Running on the Raspberry Pi, a Flask webserver receives the POST request that is sent by WordPress and automatically translates it in the format that is expected by the Slack incoming webhook API.
The webserver will use the
requests Python library to send a POST request to the Slack incoming web hook API containing the message to be published in the discussion channel.
Final state of the tool
As you can see in the screencast below when a comment is added to the blog, a message containing all the characteristics of the comment is added in the target Slack channel. A notification is fired by Slack (Upper right side of the screen) and the message appears on the left part of the screen in the Slack conversation.
And of course, the message can be viewed in all the different Slack clients.
What did I learn?
This project was my first project with my Raspberry Pi. I learned a lot on how to set up a web server on this small machine and how to forward ports from the router to the Pi.
It was also my first project with Flask. I learned some basic knowledge of how a REST API can be built using this framework.
I also learned that you can be really happy with a functioning application that is made of only 20 lines of code!
To teach myself how to use the
requests python library, I used their official website.