Share process management statuses with Slack

Introduction

This article introduces how to post a message into a Slack channel, when a workflow status of a record in a Kintone App is proceeded to "Completed".

Scenario

Although Slack has many bots in the marketplace, marketplace bots tend to only function for a particular scenario, which may not always fit in with the user's needs.

 

Different database instants within Kintone can cover many scenarios depending on the user's needs, such as CRMs, Project Management, Interview Notes, Task Lists, Expense Reports, PTO request forms and so on. Kintone Apps tend to result in higher productivity if their Process Management settings have been enabled, that defines a streamline workflow for every record within the database.

 

This article shows a quick way to spin up a bot that will send messages to a Slack channel from Kintone. A JavaScript customization applied to a Kintone App will trigger when the workflow of a record is proceeded to a particular status. The script sends a request to Slack's Incoming Webhook feature to post messages into Slack channels. The contents of the scripts are simple, making it possible for the script to be adapted to the user's needs, so that the bot can flexibly function for many types of scenarios.

 

Setting up the connection

In this article, messages from Kintone to Slack will be posted with the below scenario:

  • End 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 the Kintone App that are set to "Completed" are notified to a Slack channel

Follow these steps to set up the connection between Kintone and Slack.

1. Get a Slack channel ready

Create a Slack channel that will receive notifications from Kintone.

US_01.PNG

2. Set up an Incoming Webhook in Slack

In Slack, 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 and take note of the URL displayed in the Webhook URL settings, as it will be used in the next step. Input anything for the Descriptive Label, Customize Name and Icon.

3. Prepare a Kintone App

Log into Kintone, and navigate to a Kintone App where the customization will be applied, or create a new App from the marketplace. Navigate to the App's settings, and to the Process Management settings. Check the Enable process management check box, if this settings has not been enabled yet. Make sure to include a status named Completed in the Status Settings.

processStatus.PNG

Save the settings, and click on Update App to apply the changes to the Kintone App.

4. Upload a JavaScript file to Kintone

Copy the contents of the below code into a local JavaScript file.
Make sure to replace the Kintone subdomain name to a subdomain that matches your instance, and the Incoming Webhook URL to the URL generated in the earlier steps. Also replace <FieldcodeOfTask> with a field code of a field that exists in the Kintone App. The value of that field will be included in the Slack message.

post2slack.js

 

In this code, the app.record.detail.process.proceed event is triggered when a user proceeds a task in a record. If the status is proceeded to Completed, the kintone.proxy API is used to send a POST request to Slack's Incoming Webhook URL.


Save the JavaScript file, navigate to the App's settings, then to JavaScript and CSS Customization, and upload the file to the Upload JavaScript for PC settings. Save the settings, and click on Update App to apply the changes to the App.

Test the connection

If the record list in the Kintone App is empty, add a new record into the App.
Navigate to the details page of the App, and proceed the process management status until it reaches Completed.

 

status_to_slack-compressor.gif

 

This should trigger the event to fire data into the Slack Channel. Check the Slack Channel to see if a message has been posted.

 

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, the app.record.detail.process.proceed event was used to send messages to Slack, to utilize Kintone's strong process management features.
This event can be replaced with other events, such as the app.record.create.submit.success event to post messages when new records are added into the Kintone App and the app.record.edit.submit.success event to post messages when records are edited.

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

Was this article helpful?
1 out of 1 found this helpful
Do you have any questions or issues related to this article?
Please share your views with us in the Community forums!