Sending Slack Messages from EFT

#40 TOP TIP

I’m often asked about how to link EFT into an alerting system; EFT does of course come with email capability, but you don’t necessarily want to be using this as your best method of getting a heads-up when something goes wrong.

There are a number of different products available and in use around the world, so it’s not unreasonable to expect that Globalscape would leave it to customers to make the connection from EFT into an enterprise alerting system.  While this article is not going to address the various options available to you, I will at least demonstrate how you can interact with one system – Slack.

 

What is Slack?

Slack is a communications platform offering chat and file sharing functionality. Many organisations use it to communicate both internally and externally; it’s especially useful for collaborating on projects with external teams. Better still, there is a free version offered which allows you to have up to 10,000 active messages (if you want to keep messages older than this, you’ll need to pay for it). Slack organises the various chats into channels for either direct communications with other people or group discussions. For our purposes though the most interesting feature is that it has an API that we can use to post messages directly from EFT. Before we look at sending something into Slack, let’s create a private channel to send messages into. We can invite people into the channel later.

 

Slack Webhook

The API that Slack provides is in the form of a webhook. As you can see at https://api.slack.com/messaging/webhooks, a webhook in Slack terms is a URL that you can call to pass a message into a Slack channel. To get started on this process, the first thing that we’ll need to do is create a Slack App. This will give us the ability to make the connection from EFT. We do this by visiting https://api.slack.com/apps/new and completing the short form there.

When you press the ‘Create App’ button, you will receive your credentials to use to make the connection; you don’t need to save this information.

You’ll need to expand the ‘Add features and functionality’ section, select ‘incoming webhooks’, and select ‘activate’.  This will provide sample curl request showing how to pass a message into Slack:

curl -X POST -H ‘Content-type: application/json’ –data ‘{“text”:”Hello, World!”}’ YOUR_WEBHOOK_URL_HERE

It also tells you that no webhooks have been added yet – click the ‘Add new webhook’ button to change that.  You’ll see a drop-down list of all of the available channels – select the channel we created at the start of the process.  The curl request will now be updated to show the final webhook that we will use to send messages:

https://hooks.slack.com/services/????????/????????/????????????????

Every webhook in unique.  If you lose this webhook, you can always return to this page to retrieve it or even create a new webhook.

We can now turn our attention to EFT

 

Calling a Webhook from an event rule

Calling the webhook is very straightforward; we will use this single Powershell command to do it:

Invoke-RestMethod -uri <URI> -Method Post -body <BODY> -ContentType <CONTENTTYPE>

Of course, we’ll set this up using some parameters and call the Powershell as an embedded script in an event action.

We can call an external script if needed (remember to pass some parameters!)

  • Lines 1-3 are the parameters that we will pass to the script (change this if using command line app). In our case we are simply passing the task name, error code and error description.
  • Line 4 tells Powershell to force TLSv1.2 (the server I am using also has TLSv1.1 enabled – Slack won’t accept that)
  • Line 5 is the URL we just generated
  • Line 6 describes how we will structure the message body (JSON format)
  • Lines 7-11 is the message that we pass
  • Line 12 is the actual call

All that remains now is to see how it looks in an event rule – my rule looks like this with a different Slack message depending upon success or failure (sends to different channels accordingly):

The resulting error notification then pops up on my screen!

Once you are happy the process works OK, change the channel notification settings in Slack in order to get alerts directly to your mobile phone when there’s an issue

 

Support

We’re here for you!

Expert EFT consultancy and support in your time zone.
Let us help you make the most out of your EFT software.

See how we can help you