Post Tweets on Twitter when Records are Approved
This article introduces how to post tweets on 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 tweet as well as the datetime to post the tweet in a Kintone record.
- A reviewer checks the tweet contents and approves or rejects it.
- If approved, the tweet is posted at the set datetime.
AWS Lambda is used to host the function that checks for ready tweets and posts them to Twitter at their defined times. It also updates the Kintone record by changing the status to Complete and inserting a link to the posted tweet in the record.
The general flow of the customization is as follows:
- When the set datetime passes, the Lambda function is triggered and retrieves the tweet data from Kintone.
- The data is tweeted on Twitter.
- The process management status of the Kintone record is updated. The record is also updated with the URL of the tweet.
The following diagram shows the general flow of the customization.
- This customization uses a Node.js v12.18.0 environment.
- To use the Twitter API, a Twitter developer account is needed. For details, refer to the Apply for Access page of the Twitter developer website.
Prepare the Kintone App
Create the form
Create an App with the following field and settings. Save the form when finished.
|Field Type||Field Name||Field Code||Notes|
|Date and time||Tweet date and time||tweetDate|
|Text area||Tweet content||tweetBody|
|Link (URL)||Tweet URL||tweetUrl||The URL of the tweet is automatically set in this field after the tweet is posted.|
Generate an API token
Create an API token with view and edit permissions. Refer to the Generating API Tokens article on the Kintone Help site for more information.
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.
Set Process Management settings with the following. Do not set a default assignee for the Tweet scheduled status. If set, the status cannot be updated with the API token.
Status Not started, In review, Tweet scheduled, Completed
Status Assignee Action Next Status Not started Set to anybody Start In review In review -
- Tweet shceduled
- Not started
Tweet scheduled - Complete Completed
Prepare the Twitter Settings
Prepare the Twitter account
Log in to Twitter if the necessary Twitter account already exists. If not, create a new Twitter account from Twitter.com .
Apply for a developer account
A Twitter developer account is required to use the Twitter API. For those using the Twitter API for the first time, refer to the Apply for access page of the Twitter developer website.
Register a new application
Access the Apps page of the Twitter developer website.
Click Create an App to create a new application. Enter in an appropriate name for the app under App name, and a description of the application in Application description. The website URL can be a dummy URL such as
In the Tell us how this app will be used field, fill in a brief description of the application and how it will be used.
Click Create to save the app.
Next, navigate to the Keys and tokens tab and make a note of the API key and API secret key under Consumer API keys.
Click Generate above the Access token & access token secret box.
Make note of the displayed Access token and Access token secret. They will not be displayed again and if forgotten will need to be regenerated.
Prepare the Lambda Function Executable
This step must be done in an environment where Node.js is installed.
Save the following sample code as a file named index.js.
Run the following commands to install the module and create the ZIP file (the Lambda function executable).
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
Refer to the AWS Lambda execution role documentation to create a role to execute Lambda.
In this sample, the role is created with the name AWSLambdaExecute as an example.
Create a new Lambda function
In AWS Lambda, click Create 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 12.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 that usage of EventBridge is charged based on the number of events published. Refer to the Amazon EventBridge Pricing page for details.
Click the kintone-to-twitter box to return to the Lambda function settings and click Actions to open up the Actions menu. Click to Upload a .zip file and upload the Lambda function execution file created earlier, named kintone-to-twitter.zip.
Navigate to Environment variables and click Manage 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.
The environment variable settings should look like the following:
Navigate down to the Basic settings and click Edit.
Enter the settings as follows, checking that the Handler, 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 tweet content and the desired date of the tweet. Proceed the process management states to "Tweet Scheduled".
Check that the tweet 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 tweet should be entered in the Link field.
Note that images may be added to the tweet with the following conditions:
- Accepted file types: JPG, PNG, GIF, WEBP
- Maximum file size: 5MB
- Maximum static images in one tweet (JPG, PNG, WEBP): Up to 4
- Maximum GIFs in one tweet: 1
- GIF files must be uploaded alone and cannot be mixed with other image types.