Home

Automated Tweets after Successful Netlify Build

This is the (custom) workflow I use to automatically tweet after publishing new content to my blog.

When I publish new content to this blog, a tweet like this gets published.

I built the workflow to support this from scratch. Let's look at how it works.

Why Automate Tweets?

For me, this isn't some elaborate and secret plan to get a million followers or massively boost my pageviews. I have a simple rule: When I publish something new, I share it at least once.

I built this workflow to solve a simple issue with timing and context switching.

Before this process was in place, I would draft an article, review/edit it, publish it, then share it. The time between each of those steps varied from post to post, but could be as long as days or weeks.

By the time the article is ready to be shared, I'm often done thinking deeply about it. I've already spent much time in the zone, and have moved onto something else. To author a meaningfully contextual message is to refocus my brain on the article, come up with something clever, grab the URL, and publish a tweet. Of course, I also have to wait for the production build to finish and then make sure I remember to actually send the tweet (which I've forgotten a number of times).

After putting this process in place, I can author the tweet while I'm writing the article. As you'll see, I don't even have to know what the URL is going to be. I just leave a short message for the tweet, and once the publishing process completes itself, the tweet is automatically published to Twitter.

No context switching. No reminder setting. I'm onto the next thing while my Twitter account stays active.

The Post-Build Tweet Publishing Workflow

There are three components that make up the engine that drives this process:

This is how it works:

  1. tweet frontmatter: My blog content is stored in markdown files, which use YAML frontmatter to store meta properties about the post. When I publish a new post, I add a property tweet where the value is the body of the tweet to publish. Here's an example that you can see matches the tweet at the beginning of this article.
  2. Netlify Build Plugin: When I merge a commit with a new post to the main branch, a new Netlify build gets kicked off. When a build on the main branch is successful, my netlify-plugin-github-dispatch plugin uses the GitHub API to release a dispatch, which triggers the GitHub workflow.
  3. GitHub Workflow: The GitHub workflow basically just sets up dependencies and then runs npm run publish-tweets from my website's working directory (www in the monorepo).
  4. Node.js Script: The script looks for any posts with a tweet property in the frontmatter, verifies that it hasn't been sent yet, then publishes the tweet, appending the URL for the post to the bottom of the tweet text. It then cleans up by removing the tweet property for the post (so that the script doesn't try to send the tweet again the next time it runs) and commits the change to the repo.
note

Big thanks to the official netlify-plugin-github-dispatch plugin! I borrowed heavily from this code, and slimmed it down to solve my specific problem.

Early Results

I'm about three months into this workflow and it has been a total game-changer for me. My account is more consistently active on Twitter than ever before.

And even though I don't get much interaction on these tweets, they are helping, and every little bit helps to boost the visibility of each piece of content I'm putting out there, which makes it feel more worthwhile to me.

While you're welcome to take this code and make it work for you. If you do, let me know. I've been considering building a solution that could be more turnkey, but would need real use cases to work against.

Let's Connect

Keep Reading

Use Netlify Functions to Send Email Notifications

Learn the basics of sending custom email notifications using Netlify functions and your email service of choice.

May 06, 2021

How I Scaled a Hybrid Application using the Jamstack

I built an app for a one-day event that did not account properly for scale and took a huge performance hit. This is how we overcame that performance struggle using the Jamstack.

Apr 01, 2020

A Netlify Function That Sends Conditional Email Notifications

Conditional email notifications may be immortal, but we can still figure out how to implement them on emerging Jamstack websites.

May 30, 2019