eallion

大大的小蜗牛

机会总是垂青于有准备的人!
mastodon
github
twitter
steam
telegram
keybase
email

Mastodon sync to Memos

Latest script: https://gist.github.com/eallion/bf8861eb3292c2351c1067fba3198c26

Update: Added an example for the Baota panel.

TL;DR#

Jump directly to this page script content to view the script code.

Introduction#

I don't know if I'm lucky or unlucky, but just as I was preparing to make Memos my main tool in my workflow, I encountered the v0.19.0 version update, which brought a series of major issues. Besides the robustness of the new version of Memos being questioned, even the server hosting it was affected; I couldn't run it on a physical machine with 64G of memory. As netizens said, Memos seems more like a practice project. I decisively abandoned it. What’s wrong with tools like Google Keep and Obsidian? Not confining all tasks to one tool is indeed a bit troublesome, but All in one basically equals All in boom.
Now I see Memos as a way to back up my Mastodon (one of the methods).

I have always liked the proactive push solution of Webhook, which is simpler, more environmentally friendly, and more immediate than passive pull solutions like RSS and Cron jobs. Mainly, the feeling of having control is very satisfying.

Next, I will introduce how to use Webhook to sync tweets from Mastodon to Memos. I am using a Shell Script, which is a very simple script that only performs some common-sense logical judgments and may not be perfect. It can also be implemented using Node.js, Python, etc.

Tested Versions#

Mastodon requires its own instance or an account with admin privileges to create a Webhook to use this method.

Installation Tools#

Please install the tools on the server. If there are errors, please install other corresponding tools based on the error logs.

  • sudo apt install jq
  • sudo apt install lynx

Webhook Tools#

Go to https://{INSTANCE}/admin/webhooks on Mastodon to create a Webhook.
You can select only the status:created event; replies and reblogs also count as this event.
Fill in the destination URL with the link of your deployed Webhook, such as: https://webhook.example.com/hooks/mastodon-sync-to-memos
For Baota, it is: https://webhook.mybtserver.com:8888/hook?access_key=ACCESSKEY
It is recommended to bind a domain name to the Mastodon Webhook destination URL; otherwise, Sidekiq may not be able to handle it.

Script Content#

Save the script content below to a .sh file on the server, such as ~/mastodon_sync_to_memos.sh in the current user's Home directory (~), and configure the following content. Please make sure to replace:

  • MEMOS_HOST=""
  • MEMOS_ACCESS_TOKEN=""
  • MEMOS_VISIBILITY=""
  • MASTODON_INSTANCE=""
  • MASTODON_ID=""
  • SKIP_MASTODON_REPLY=
  • SKIP_MASTODON_REBLOG=
  • HOME_DIR=~
  • FILE_PATH=$HOME_DIR/.mastodon_memos_id.json

Find Mastodon ID: https://INSTANCE/api/v1/accounts/lookup?acct=USERNAME

Baota Panel#

If using the Webhook plugin in the Baota panel, you can directly copy the above script content into the script of the Webhook plugin. There is no need to manually create a .sh file on the server.

JSON Data File Content#

When the script is run for the first time, it will create a file ~/.mastodon_memos_id.json in the current user's Home directory ~ and initialize it. This file will subsequently record the binding relationship between Mastodon ID and Memos ID. If you do not want to create it in the Home directory, you need to modify the HOME_DIR= and FILE_PATH= parameters.

After data is generated in the production environment, an example:

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.