Tracking Twitter mentions with Monday.com
Connect systems with Reshuffle.
Monitoring social media mentions is an essential part of any business. It gives brands an opportunity to track, analyze and respond to conversations about them on social media. In this quick tutorial, I will show you an example how you can a setup a simple Twitter mentions tracker with Monday.com.
In this article we will be using Reshuffle's open source integration framework to easily integrate Twitter and Monday services to meet your brands needs for social monitoring.
How to Build It
Normal setup and configuration could take a while in order to get these services to work together. Reshuffle is an open source, lightweight, and event-driven framework that helps you build integrations that completes complex tasks.
These integrations and workflows are created inside a Reshuffle App. The objects that let you interact with these services are called connectors.
The first thing we need to do is to declare a Reshuffle App and a Twitter connector that will search for any @mentions or #hashtag passed in.
const app = new Reshuffle()
const twitter = new TwitterConnector(app, {
customerKey: process.env.TWITTER_CUSTOMER_KEY,
customerSecret: process.env.TWITTER_CUSTOMER_SECRET,
})
To keep track of mentions, we will be pushing them onto a Monday board using the Monday connector.
const monday = new MondayConnector(app, {
token: process.env.MONDAY_TOKEN,
baseURL: 'https://localhost:8000',
})
Now that we have the connectors declared, we can start using them.
First thing is to make a new board from your Monday dashboard. Get the board ID from the url (eg. new-board-name.monday.com/board/2193445), this will be used to get the board data like column IDs, item names etc. Make a new board with columns that look similar to this.
Column | Type |
---|---|
tweet | Long-text |
user | Text |
created-at | Date |
;(async () => {
const boardItems = await monday.getBoardItems(BOARD_ID)
for (let id in boardItems.items) {
if (!tweetsCache[boardItems.items[id].name]) {
tweetsCache[boardItems.items[id].name] = { fetched: true }
}
}
})().catch(console.error)
As you can see above, we use the BOARD_ID
to fetch any items that is currently on the board using the getBoardItems
method. For each of the row names, we will be using the Twitter IDs, as you will see later on. This function will run before any Twitter connector actions to prevent duplicate tweets from being saved onto the board.
With this duplicate check in place, we can move on with the Twitter connector.
We need to define the event to listen to using the Twitter connector's on()
method. In this case, we will listen for search events.
twitter.on({ search: "@reshuffleHQ" }, async (event, app) => {
for (const tweet of event.tweets) {
if (!tweetsCache[tweet.id]) {
tweetsCache[tweet.id] = {
user: tweet.user.screen_name,
date: tweet.created_at,
tweet: tweet.text,
};
addNewItem(tweet)
}
}
We will get an array of tweets from the event object. You can see in the if
block, we run a check on the object from earlier, to prevent duplicate tweets from being added onto the Monday board. If the tweet does not exist in the object, we can continue to adding a new row with the addNewItem
function we will create.
const createItems = async (tweetInfo) => {
monday
.getColumn(BOARD_ID)
.then((res) => {
return res.boards[0].columns.map(({ title }) => title)
})
.then(async (title) => {
const testObj = {
[title[1]]: () => tweetInfo.text,
[title[2]]: () => tweetInfo.user.screen_name,
[title[3]]: () =>
new Date(Date.parse(tweetInfo.created_at))
.toISOString()
.split('T')[0],
}
const testQuery = await monday.createItem(
BOARD_ID,
JSON.stringify(tweetInfo.id),
testObj
)
})
}
In this function, we will be using multiple methods from the Monday connector. First we use the getColumn
, to get the titles of each column, then we create an object using the column titles as the key. Finally, we can pass it through to the createItem
method to generate a row that will look something like this.
Last but not least, let's initiate the integration by starting the Reshuffle App
app.start()
With minimal code, Twitter mentions are easily tracked with the Monday board. Now its your turn to get creative! Find new solutions to monitoring social mentions, maybe extend this functionality by tracking the frequency of daily mentions.
Now, Make it Happen
As your developers and project management teams experience the ease of working with integrated applications, we encourage you to consider where else integrating workflows would benefit your teams. With so many different tools, the more you can consolidate them into one common interface, the easier people can get work done.
Reshuffle is continually listening to what our customers need and desire. Don't see a Connector to a service you'd like to integrate? Send a tweet to @ReshuffleHQ to let us know which Connector you'd like us to develop next.