Integrate and send slack notifications with the Slack Notifier gem

Tram Ho

1. Introduction

  • I have a friend in another project who said that he made a package to track when there was an error, he would send a message about chatwork for individuals or a general box => save the effort to access the server and see log => help more time consuming and more secure than the server. Oh, good friend. Of course I think I should only use it in the development and staging environment, but the product must be considered =))
  • But what about the project using slack? So in the previous post I will guide the basic how to integrate and use gem slack-notifier to shoot slack notifications offline.

2. Setup

2.1 Create webhook

2.2 Select channel

  • Immediately after selecting the hook, the form select channel will be displayed.
  • Here you want to notify send where to send, select that channel
  • Select and then submit thoai (for example I choose #general)

2.3 Webhook URL

  • After submitting the form successfully, the system will return you a URL. That is the webhook URL we use to connect to the slack.
  • The URL looks like this

  • Note: x, y, z are random characters.

2.4 Setup Rails

  • If you don’t have a Rails app project yet, create it, then install the gem as follows

  • You can try out the gem using the following code.

  • You should see the words “Hello World from AppName” on your chat slack box right after

You can configure sending messages by another name as follows

Send to a certain channel:

Add link to the message

2.5 Format message

  • To make the message easier to see, we need to format it beautifully such as capitalization, underline, listing by list, …
  • I give some examples:

3. Send notification when there is a slack exception

  • Install a gem

  • Here I will configure the channel #exceptions to send
  • The basic configuration will be as follows:

  • Oke is good, now you can try to make an error and check the message at the slack.
  • Also you can refer to more about API integration here:
  • Slack API – https://api.slack.com
  • Slack – Incoming WebHooks
Share the news now

Source : Viblo