10.0: Manage Twitter mentions with automations and custom records #8
jstanden
started this conversation in
Guides and Tutorials
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Create a new Twitter app
Sign in to Twitter using your corporate/team account.
Navigate to https://developer.twitter.com/en/portal/dashboard
Creating a project
If you don't have a project yet, you'll have to petition for one. If you already have a project you can skip this section.
Most likely you want: Professional >> Building customized solutions in-house.
Click the Get Started button.
Fill in the application.
Create a standalone app
Once you have an approved project you can create applications.
From Projects & Apps >> Overview click the Create App button in the Standalone Apps section at the bottom.
App Name: Twitter for Cerb
Make a note of your API key, secret key, and token.
Click the App settings button at the bottom.
Enable write permission
In the App permissions section, click the blue Edit button.
Select Read and Write and click the Save button.
Enable 3-legged OAuth
In the Authentication Settings section at the bottom, click the blue Edit button.
Enable 3-legged OAuth.
https://your-cerb-url/oauth/callback/cerb.service.provider.oauth1
Click the blue Save button in the bottom right.
Import the package in Cerb
Navigate to Setup >> Packages >> Import.
Paste the following package:
Click the Import button.
Enter your Twitter API key and secret.
Click the Import button again.
Configure the Twitter connected account in Cerb
Click on the Twitter (@username) connected account in the package output.
Rename the connected account using your own Twitter username.
Click the Link to Twitter button and log into the account you want to automate.
Review the consent screen and click the Authorize app button.
Click the Save Changes button.
Synchronize tweets
Navigate to Setup >> Configure >> Scheduler.
In the Automations scheduler job, click run now.
It will take several seconds. When it is complete, you can close the extra tab in your browser.
Reading tweets
Navigate to Search >> Tweets.
You should your most recent @mentions, as well as the most recent posts and replies from your account.
You can open the card for a tweet to view its thread.
Replying to tweets
On tweet card popups there is a Reply interaction in the Actions section.
How it works
Custom record
Tweets
The package creates a new custom record type for Tweets. You'll find it in Search >> Custom Records.
The tweet record type includes several custom fields: message, status ID, parent status ID, account, user name, user screen name, user profile image, and account.
Automations
The package imports three automations. You'll find them in Search >> Automations.
wgm.example.twitter.syncMentions
wgm.example.twitter.syncMentions
is a timer-based automation that runs every 5 mins.It takes a Twitter-based connected account as input and fetches its @mentions timeline since the last update. This is tracked in a
since_id
key in automation storage.This automation can be used to sync any number of Twitter accounts.
After receiving a response from the Twitter API, results are converted to objects from JSON and iterated using a repeat: command.
For each tweet, the record.upsert: command is used to create or update its record based on Twitter's internal status ID for the message.
We also store the connected account with each message to simplify follow-up API actions like replying.
We keep track of the highest status ID as
since_id
for the next interval and store that at the end.Finally, we exit in the await: state. This creates a continuation so the timer resumes with the same state at the next interval (in 5 mins).
The automation policy needs the http.request: command with access to the specific API endpoint.
It needs the storage.get: and storage.set: commands to load and save data between executions.
It also needs the record.create:, record.update:, and record.upsert: commands to create or update the
tweet
custom record type.wgm.example.twitter.syncUserTimeline
wgm.example.twitter.syncUserTimeline
is another timer-based automation that runs every 5 mins.It is functionally almost identical to the mentions automation above, except it syncs the tweets and replies of a specific account. In this case it's your own account. This is used to thread @mentions and your replies.
You can reuse this automation to sync the tweets of any number of accounts.
The automation policy is identical to the mentions automation, except for a different Twitter API endpoint.
wgm.example.twitter.reply
wgm.example.twitter.reply
is a worker-based interaction automation.It takes a tweet record as input and prompts the current worker for a reply message to post to Twitter, and automatically @mentions the author of the tweet being replied to.
After the worker provides a message, the automation posts the tweet using the Twitter API.
The automation policy simply needs the http.request: command with access to the specific API endpoint.
Automation Timers
The package creates two automation timers. You can find them in Search >> Automation Timers.
Sync @username Tweets
This runs the
wgm.example.twitter.syncUserTimeline
timer automation using a specific connected account and target Twitter user. This syncs that user's recent tweets and replies intotweet
records.You can create additional timers to sync other user timelines. You'd only need to change the
screen_name:
.Sync Mentions
This runs the
wgm.example.twitter.syncMentions
timer automation using a specific connected account. This syncs the account's@mention
timeline intotweet
records.You can create additional timers to sync other account mentions. You'd only need to change the
connected_account:
. You can create new connected accounts with your same Twitter service from Search >> Connected Accounts >> (+).Card widgets
The package creates two card widgets. You can find them in Search >> Card Widgets.
Conversation
This card widget displays the tweet in the familiar format; optionally including the tweet being replied to.
It uses a sheet widget and a
worklist.records
data query.The sheet schema has a single column with an HTML layout to display the user name, user screen name, user profile image, and message.
Action
This card widget provides a Reply interaction on tweet cards.
You can add additional interactions for other actions.
Beta Was this translation helpful? Give feedback.
All reactions