loading...

Tracking Twitter mentions with Monday.com

alanblee profile image Alan Lee Updated on ・3 min read

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.

Let's built 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,
  });
Enter fullscreen mode Exit fullscreen mode

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",
  });
Enter fullscreen mode Exit fullscreen mode

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

Monday Board

(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);
Enter fullscreen mode Exit fullscreen mode

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)
      }
    }
Enter fullscreen mode Exit fullscreen mode

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
        );
      });
  };
Enter fullscreen mode Exit fullscreen mode

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.

Monday Board

Last but not least, let's initiate the integration by starting the Reshuffle App

app.start();
Enter fullscreen mode Exit fullscreen mode

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.

Discussion

pic
Editor guide