Retrieve Kintone data with Slack Slash Commands and AWS Lambda

Introduction

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. 

 

001.png

 

On the next page select Slash Commands, and then Create New Command.

Enter the following values:

Field Value
Command /mytodo
Request URL (Enter a dummy URL for now)
Short Description List your todos

 

002.png

 

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.

 

app_store.png

 

 

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
To Do name
Status status
Due date due_date
Assigned to assignees

 

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. 

 

004.png

 

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.

 

005.png

 

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

Variable Name Value
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.

 

006.png

 

API Gateway Settings

Click Add trigger to add a new Lambda trigger.

007.png

 

On the settings page, set the configurations as follows. Click Add once the settings are complete.

 

Screen_Shot_2020-05-14_at_10.27.36.png

 

The API endpoint will be displayed under the name of the Lambda function. Copy the URL to add to the Slack settings.

 

009.png

 

 

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. 

 

Screen_Shot_2020-05-20_at_11.20.20.png

 

On the next screen, allow the App to access the workspace.

 

Screen_Shot_2020-05-20_at_11.21.37.png

 

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.

 

Screen_Shot_2020-05-14_at_10.41.06.png

 

Finally

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.

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