Slack's Slash Commands enable communication with external services from within Slack. This article introduces how to create personal Slack Slash Commands to get record data from a Kintone App. In this example, records are obtained from a To Do App in Kintone, and AWS Lambda is used in between Slack and Kintone to facilitate the integration solution.
For more details about Slack Slash Commands, refer to the Slack documentation, Slash Commands - Slack API.
Set Up the Slash Command
Navigate to https://api.slack.com/apps and click Create New App. Enter the required fields, and click Create App as shown below.
On the next page select Slash Commands, and then Create New Command.
Enter the following values:
|Request URL||(Enter a dummy URL for now)|
|Short Description||List your todos|
An API Gateway URL will be entered in the Request URL field later on, but for now a dummy URL can be set. Once the Slash Command has been created, navigate to Settings and then Basic Information and jot down the Signing Secret found in App Credentials.
Set Up the Kintone App
Create the To Do app from the Kintone App Marketplace. To do so, click Create App, then Create from Marketplace from the top page to open the market place.
Look for the To Do App and click Add This App.
Click the gear mark to go to the settings of the To Do App, and set the field codes as follows. For details on how to set field codes, refer to the Help Center document, What Is a Field Code?.
|Field Name||Field Code|
Next, generate an API token by going to the App Settings tab and clicking API Token to open the API Token settings page. Click Generate to generate the API token and make sure it has the View records permission as shown below.
Make note of the API token as it will be used later.
Click Save and then Update App to save the changes made to the App.
Create the Lambda Function
Log into your AWS account, open the AWS Web Console and navigate to Lambda.
Select Author from scratch and set the Function name and Runtime settings as follows. Finally click Create function.
Copy and paste the following code into the space for the Lambda function code, replacing the following variables with the information of the Kintone and Slack environments set up earlier.
Lambda Function Code
|kintoneHost||The Kintone domain name|
|appId||The App ID of the to-do app|
|slackSigningSecret||The Slack Signing Secret retrieved earlier|
|apiToken||The Kintone API token retrieved earlier|
* In order to protect the token and the API token, encrypt these tokens using AWS Key Management System when in a production environment. Refer to the Creating Keys documentation of KMS for more information.
The page should look like the following.
API Gateway Settings
Click Add trigger to add a new Lambda trigger.
On the settings page, set the configurations as follows. Click Add once the settings are complete.
The API endpoint will be displayed under the name of the Lambda function. Copy the URL to add to the Slack settings.
Run the Slash Command
Go back to the Slack API Applications settings page from earlier and set the endpoint URL of the API Gateway that was created. Then, navigate to the Basic Information settings and under Building Apps for Slack, click Install App to Workspace as shown below.
On the next screen, allow the App to access the workspace.
Navigate to the created channel within Slack. Typing in the Slash command /mytodo will execute the Lambda function and the incomplete To Dos in Kintone for the current user will be displayed in the channel.
Note: Records are retrieved by matching the Slack login name with the Kintone login name, so only Kintone records assigned to the current logged in Slack user are displayed.
Kintone and Slack can easily be integrated using Slash Commands and AWS Lambda. While the sample in this article retrieves records from Kintone, a different Slash command can for example, be created to register or update records in Kintone from Slack as well. With the large number of Kintone REST APIs available, there are tons of possibilities for productivity-improving Slash commands. Refer to the Kintone REST API documentation for more information.