Introduction

One of the cool things about Mastodon, Notion and RSS is great API availability and nice Go libraries covering these APIs:

Pretty early after migrating to Mastodon, I started thinking about a little project that would use these APIs: a tool that automatically toots links to new blog posts appearing in an RSS feed. Obviously as with most things something like this already exists: mastofeed. But I wanted to put my own spin on it and play with the APIs. One afternoon of hacking later and I had mastosync.

Disclaimer: Please use this small script at your own risk. I wrote it up quickly in one afternoon and make no guarantees to its usefulness, correctness etc.

Setup

You need to set up a sync directory. You can do that easily by running

mastosync init

It will create the “.mastosync” directory. In there you will find the file “config.yaml”. You need to specify your mastodon credentials and your RSS feeds together with toot templates that go with each feed. The RSS feeds list order is respected and important. If you have subfeeds in your blog with specific tags, you can specify them ahead of the general blog feed and specify the tags you want in your toots in the templates. That way mastosync will use the more specific templates instead of the general template without the tags.

Catchup

Presumably you already have RSS feeds and don’t want mastosync to suddenly toot out all the items in them. To avoid that you should let mastosync catchup:

mastosync catchup

This will record all the existing items in the RSS feeds as already “tooted”.

Sync

After “init” and “catchup”, you can run

mastosync sync

and if there are new items in any of the specified feeds, they will be tooted. You can “–dryrun” the sync first.

Use it in a cronjob or similar for hands-free syncing between RSS and Mastodon.

Save

That first afternoon of hacking was a lot of fun and I wanted to continue, so I implemented a save toot function that saves a toot to a Notion page.

For example

mastosync save https://mastodon.social/@mcnees/110453472152448317

will create a Notion page with that whole thread (when you want to save a thread, give it the last toot and it will work itself backwards all the way to the first). You need to configure a couple more things in the “.mastosync/config.yaml” for this to work: Notion API keys and Google Drive credentials (where the media attachments from the toot end up, Notion does not support uploading media from the API). Speaking of attachments and my choice of saving them to Google Drive: the URLs to those files do not have filename and extension, something that Notion requires. So I had to write a small proxy called rialto that converts URLs with filenames into Google Drive URLs.