Mastobot: a Mastodon Bot for Readwise and Obsidian

I’ve had a love affair with Readwise for a while, enough to write some code to extend it. I wrote a Python script to save Readwise highlights to my Obsidian vault, switched to the Readwise Official plugin when they released it, wrote another script sending Shortform highlights to Readwise, and then was happy when the two companies established an official integration thanks to me introducing them.

Maybe I should have learned to just be patient and wait for the awesome Readwise team to build integrations I want, but remembered I’m not that patient. This is about how I created a Mastodon bot to send Mastodon posts I like to my Readwise account, and, by extension, to my Obsidian vault.

You might say there’s a pattern here.

The problem

I’ve been dabbling in Mastodon for a while, but only recently got extremely involved with it when I decided to start and maintain a Mastodon server, pkm.social, for the personal knowledge management community.

Readwise already has an awesome Twitter integration that I really enjoyed. Basically, once you’ve set it up, sending any tweet to @readwise adds it to your Readwise account. This means that whenever someone says something actually meaningful or interesting on Twitter, I can make sure it gets sent to Readwise, and then from there to my notes in Obsidian.

I wanted the same setup for Mastodon.

The result

First, the end result: I managed to get Mastodon posts I send to my bot to be sent to my Readwise account. Here are some early posts in the “Tweets” section of my Readwise Library:

And here are the resulting notes in Obsidian, also automatically synced and formatted:

The solution

Next, here’s how to set it up.

Pre-requisites

You’ll need a few things to get started:

  • A Mastodon account (I use and co-host pkm.social for free)
  • A Readwise account (Here’s an affiliate link)
  • Familiarity with GitHub, the command line, Node.js (although I’m not a Node.js developer, so you don’t have to be, either)
  • The willingness/ability to leave a Node.js script running on a server somewhere

Setup

  1. Clone my Mastobot repository.
  2. In your Mastodon account settings, go to the Development section for your Mastodon server (e.g. https://pkm.social/settings/applications) and click New Application.
  3. Fill in the application name (this can be anything you want), leave everything else the same, and then click Save Changes.
  4. Click on the application you just created, and note your client key, client secret, and access token. You’ll need these later.
  5. In this repository, copy the contents of .env.sample to a new file called .env.

It should look like this:

ACCESS_TOKEN=
CLIENT_SECRET=
CLIENT_KEY=
READWISE_TOKEN=
DOMAIN=
  1. Fill out the fields in .env with the information you just obtained from your Mastodon account.
  2. For the READWISE_TOKEN field, enter your Readwise access token.
  3. For the DOMAIN field, enter your Mastodon server’s domain (e.g. https://pkm.social).
  4. Run npm install to install the dependencies.
  5. Run node bot.js to start the bot.
  6. In Mastodon, find a post you like and reply to it with @accountname Your comment here. Within a few minutes, the original post you replied to will be sent to your Readwise account as a highlight and your comment as a note.

Limitations

This workflow is not without its limitations:

  • You need to keep the script running somewhere to be able to use it. I considered using a polling approach, but decided I wanted to experiment with Mastodon’t streaming API, which would also be more responsive, so I went with that.
  • Right now, because the bot takes environment variables about your particular setup, it’s not as versatile as the official Twitter implementation. As it is, it’s for one person’s use only.
  • It uses the “Tweets” category in Readwise, which is not ideal, but I can’t really do anything about that until they give Mastodon its own category. This isn’t really a big deal.
  • Right now, the bot doesn’t support images or other media embedded to posts.

I may address some of these issues, but for now, I’m just happy with the result. I fully expect that the Readwise team will eventually be able to flesh this out into a more robust integration, so I’m hesitant to spend too much more effort now that I’ve got it doing the minimum of what I wanted.

Resources

If you’re interested in doing this for yourself, here are some resources that might be useful:

Note: I’ve included affiliate links for Readwise in this post, in accordance with my Ethics Statement.

See Also