How to create a Slack app with JSON feed

As part of our standard client service here at Moove, we ensure that all of our client sites are updated as soon as a new WordPress release becomes available, particularly important security patch releases. To assist us with this, we have created an application that pulls information about new WordPress releases in to Slack so that every member of our team is notified instantly of new versions. This feed is served by WordPress REST API in JSON format.

For this particular functionality, we implemented the following steps:

  1. Create the Slack application
  2. Set up a server side application to handle JSON from WP REST API
  3. Create incoming hooks to connect the server app with the Slack app

Important notes

  • We chose a Slack module called ‘Incoming Webhooks’ which is a really easy way to post a Slack message from an external source (server side application).
  • Every time you want to get access to the new channel you need to create new webhook. Once this is created, you will get a unique URL where you can send a standard HTTP POST with JSON payload.
  • This payload is built up with many options, for more information see Slack API messages.

Slack Integration Webhooks

  • Immediately after receiving the webhook URL, you can build the server application.
  • Build a short script (e.g. PHP) which will handle the JSON response and send a message to the Slack channel in a desired format.
  • In global, there are many techniques to make HTTP POST/GET but to speed things up, we used Unirest which is set of lightweight HTTP libraries publicly maintained by Mashape.
  • Once the server side application/script is completed, transfer it to the server or run it locally. In our setup we moved it to our own server.
  • After this, setup a cron job otherwise you will need to run it manually which won’t have the desired effect to automatically check for WordPress releases.

Once it is created you can easily customise it with colours and a logo:

Slack API WordPress

And that’s it! We hope this helps you to stay up to date with important WordPress releases. If you’ve created any useful Slack apps that have improved your workflow then let us know!

 

Let's connect