静的ファイルと小さなRubyスクリプトを使ってMastodonの投稿に対してリプライを送るサンプルコードです。
これは、2018年にEugen Rochkoさんが書いたHow to implement a basic ActivityPub serverを実際にやってみたものです。Eugenさんの記事はActivityPubの小さなチュートリアルになっています。
なお、Eugenさんの記事のままだとDigestフィールドが足りないので、deliver.rb
ではそこを修正しています。
- How to implement a basic ActivityPub server - Official Mastodon Blog
- Fixed the signature by adding the missing digest in the signed text and header. · 1da6f95efa - the-pub - Codeberg.org
- Blog post "how-to-implement-a-basic-activitypub-server" misses the field
Digest
· Issue #17299 · mastodon/mastodon
まず、Eugenさんの記事How to implement a basic ActivityPub server - Official Mastodon Blogを読みます。
Webサイトを用意します。私はhttps://mono.hyuki.net/
を使っていますが、もちろん自分が管理しているWebサイトを使います。
actor
を適宜書き換えてhttps://mono.hyuki.net/actor
に設置します。publicKeyPem
は以下の手順で作成したpublic.pem
の内容を書きますが、改行は\n
という二文字に置き換えます。
openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -outform PEM -pubout -out public.pem
webfinger
を適宜書き換えてhttps://mono.hyuki.net/.well-known/webfinger
に設置します。
create-hello-world.json
を適宜書き換えますが、Webサイトに設置する必要はありません。deliver.rb
からアクセスできる場所に置いておきます。
deliver.rb
を適宜書き換えてからruby deliver.rb
を実行します。これで、create-hello-world.json
で指定したMastodonの投稿にHello world
というリプライが送られます(下図参照)。
cf. https://social.hyuki.net/@hyuki/109426998835310225