Post messages to Slack

Introduction

In this article, we implement a JavaScript customization on a kintone App that sends requests to Slack's Incoming Webhook feature to post messages into Slack channels.

Setting up the connection

It's true that kintone does have it's own notification feature, but there are several advantages for utilizing the notification features on Slack:

  • Team members not using kintone can receive the same notifications
  • Users can choose to turn on/off the notification for each channel
  • Desktop/Mobile apps are available for receiving push notifications

These features are useful when you wish to send notifications to a wide group of recipients but leave each recipient to decide the importance of the notification, such as in case of a system failures.

In this article, we will post messages from kintone to Slack with the below scenario:

  • Users use a shared to-do App inside kintone, where they use the process management feature to keep track of the status of each task
  • Tasks in kintone that are set to "Completed" are notified to a Slack channel

Get Slack ready

Create a channel that will receive notifications from kintone.

US_01.PNG

Set up an Incoming Webhook

Open the Incoming Webhook Integration page.

https://www.slack.com/services/new/incoming-webhook

US_02.PNG


Choose the channel to which you want to send messages to and click the [Add Incoming WebHooks Integration] button. An Incoming Webhook will be set up.

US_03.PNG

Copy the URL of the Incoming Webhook, as we will use this later on. Customize the bot name and icon to fit your needs. Save your settings, and Slack will now be ready.

Upload a JavaScript file to kintone

Next, we will set up the settings for kintone.
Create a JavaScript file which will send data to the Incoming Webhook URL, and upload it to a kintone App.

post2slack.js

Here, we use the app.record.detail.process.proceed event so that the event is triggered when a user proceeds a process management status. In this example, the kintone.proxy API will send a POST request to the Incoming Webhook URL of Slack when the status is changed to "Completed".
Upload the JavaScript file to your App.

Make sure that your App also has the Process Management feature turned on that includes a "Completed" status.
processStatus.PNG


Once you are ready, save your settings, and update your App.

Test the connection

To test to see if the connection is working, add a new record to your App. Proceed the process management status until it reaches "Completed". Check your Slack Channel to see if your message has reached your Slack channel.

US_04.PNG


If nothing is being posted into your Slack channel, try reading through the Debugging Tips for kintone JS article to check for bugs.

Finally

In this example, we used the app.record.detail.process.proceed event to send messages to Slack, to utilize kintone's strong process management features. You can replace this event with other events, such as the app.record.create.submit.success event to post messages when new records are added and the app.record.edit.submit.success event to post messages when records are edited, etc.

For more details on Slack's Incoming Webhook feature, refer to the following document:
https://api.slack.com/incoming-webhooks

Was this article helpful?
0 out of 0 found this helpful
Comments
Please sign in to leave a comment.