This article introduces how to post on X, formerly known as Twitter, automatically after Kintone Records are approved. AWS Lambda is used to facilitate the integration.
The general flow of the operation is as follows:
An employee registers a post as well as the datetime to post in a Kintone record.
A reviewer checks the post contents and approves or rejects it.
If approved, the post is posted at the set datetime. If the datetime is in the past, it is posted immediately.
AWS Lambda is used to receive the webhook data, and either post, or schedule a post to X as the user. When the request is successful it also updates the Kintone record by changing the status to Complete and inserting a link to the post in the record.
Sample Image
The general flow of the customization is as follows:
When the set datetime passes, the Lambda function is triggered and retrieves the X post data from Kintone.
The data is posted on X.
The process management status of the Kintone record is updated. The record is also updated with the URL of the X post.
The following diagram shows the general flow of the customization.
Note
This customization uses a Node.js v22.x environment.
To use the X API, a X developer account is needed. For details, refer to the following page of the X developer website:
X Subscription Plan
Prepare the Kintone App
Create the Form
Create an App with the following field and settings. Save the form when finished. For more information, refer to the following page:
Create an App
Field Type
Field Name
Field Code
Notes
Date and time
Post date and time
postDate
Required field
Text area
Post content
postBody
Required field
Attachment
Image file
imageFile
Link (URL)
Post URL
postUrl
The URL of the X post is automatically set in this field after the X post is posted.
Generate an API Token
Create an API token with view and edit permissions. For more information, refer to the following page:
Generating API Tokens
Set Up the Process Management Settings
Open the App Settings tab and navigate to Process Management under General Settings.
Check the Enable process management check box to enable the process management feature.
Do not set a default assignee for the Post scheduled status. If set, the status cannot be updated with the API token.
For more information, refer to the following page:
Set Process Management settings
Status
Not started, In review, Post scheduled, Completed
Process list
Status
Assignee
Action
Next Status
Not started
Set to anybody
Start
In review
In review
-
OK
Not OK
Post scheduled
Not started
Post scheduled
-
Complete
Completed
Prepare the X Settings
Prepare the X Account
Log in to X if the necessary X account already exists. If not, create a new X account from the following site:
x.com
Apply for a Developer Account
An X developer account is required to use the X API. For those using the X API for the first time, refer to the following page of the X developer website:
Subscription Plan
Register a New App
Access the following page of the X developer website:
Project & Apps
The default Project App will be used. Create a new app if needed.
Next, navigate to the Keys and tokens tab and make a note of the API key and API secret key under Consumer keys.
If an error occurs with the ZIP command, check that the file index.js and the directory node_modules exist in the hierarchy.
Prepare the AWS Settings
Create an Execution Role
Create a role to execute Lambda. For more information, refer to the following page:
AWS Lambda execution role
In this sample, the role is created with the name AWSLambdaExecute as an example.
Create a New Lambda Function
In AWS Lambda, click Create a function.
Choose Author from scratch and enter in the rest of the settings as shown in the image below. The Function name can be anything and the Runtime should be set to Node.js 22.x. The Execution role should is set as the role that was created in the previous step.
After creating the function, click Add trigger.
USe the drop down to select EventBridge (CloudWatch Events) as the trigger.
Enter in any value for Rule and Rule name, and under Schedule expression, set the rate to 1 minute.
Note
Note that usage of EventBridge is charged based on the number of events published. For more information, refer to the following page:
Amazon EventBridge Pricing
Return to the Lambda Function overview and click Code to open up the Code source. Click to .zip file from Upload fromand upload the Lambda function execution file created earlier, named kintone-to-x.zip.
Navigate to Environment variables and click Edit environment variables.
Click Add environment variable to create a new row of variable settings.
Referring to the following section of the index.js code, create a row of variable settings for each variable, matching up the capitalized portion of the variables with the values obtained earlier.
1
2
3
4
5
6
7
8
9
10
11
12
// Kintone subdomain and App information
const DOMAIN = process.env.KINTONE_DOMAIN;
const APP_ID = process.env.KINTONE_APP_ID;
const API_TOKEN = process.env.KINTONE_API_TOKEN;
// X app information
const client = new TwitterApi({
consumer_key: process.env.TWITTER_API_KEY,
consumer_secret: process.env.TWITTER_API_SECRET,
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
});
The environment variable settings should look like the following:
Navigate down to the General configuration and click Edit.
Enter the settings as follows, checking that the Timeout and Execution role values are correct. Click save when done.
Test the Integration
Add a new record into the Kintone App, filling in the X post content and the desired date of the X post. Proceed the process management states to "X post scheduled".
Check that the X post is posted when the set datetime has passed. If the configuration is successful, the record status should change to Complete and the link to the posted X post should be entered in the Link field.
Limitations
Note that images may be added to the X post with the following conditions:
Accepted file types: JPG, PNG, GIF, WEBP
Maximum file size: 5MB
Maximum static images in one X post (JPG, PNG, WEBP): Up to 4
Maximum GIFs in one X post: 1
GIF files must be uploaded alone and cannot be mixed with other image types.