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".
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.
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.
2. Set up an Incoming Webhook in Slack
In Slack, open the Incoming Webhook Integration page.
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.
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.
Save the settings, and click on "Update App" to apply the changes to the Kintone App.
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.
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.
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".
This should trigger the event to fire data into the Slack Channel. Check the Slack Channel to see if a message has been posted.
If nothing is being posted into your Slack channel, try reading through the Debugging Tips for Kintone JS article to check for bugs.
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: