Getting follow feature
Published: 2024-08-09 15:35:53 +1000 +1000

Since our server is entirely static, we are unable to directly process follow requests from ActivityPub platforms without some form of server-side processing. However, once a user sends a follow request to our static user, any content we publish can be shared with their Inbox.

There are three possible solutions to this problem:

  1. Setting manuallyApprovesFollowers to false in Actor object - Might not work with some platforms
  2. Adding requested follower to followers.json without sending Accept activity to origin server
  3. Periodically boots up a backend server and process the request

Setting ManuallyApprovesFollowers Tag

Some ActivityPub platforms, like Mastodon, can detect whether a user on another platform supports automatic acceptance of follow requests. This is determined by checking the manuallyApprovesFollowers field within the actor object of that user. To set this up, you can configure your actor object as follows:

{
	"@context": "https://www.w3.org/ns/activitystreams",
	"type": "Person",
	"preferredUsername": "noah",
	"id": "https://noah.netlify.app/noah/actor.json",
	"inbox": "https://noah.netlify.app/noah/inbox.json",
	"outbox": "https://noah.netlify.app/noah/outbox.json",
	"followers": "https://noah.netlify.app/noah/followers.json",
	"following": "https://noah.netlify.app/noah/following.json",
	"publicKey": {
		"id": "https://noah.netlify.app/noah/actor.json#main-key", 
		"owner": "https://noah.netlify.app/noah/actor.json",
		"publicKeyPem": "..."
	},
	"manuallyApprovesFollowers": false
}

Setting "manuallyApprovesFollowers": false indicates to some ActivityPub platforms that the user of your instance automatically approves follow requests. This eliminates the need to send back an Accept activity.

Adding Requested Follower Without Accept Activity

When a user of an instance send out a follow request to our static hosted server. It enables us to share any already existing posts on our static site with that particular users by sending a Create activity to his/her inbox. However, to access to his/her outbox, we need to have access to that user actor object to retrieve the inbox url. It’s important that we have a way to store those information. See Publishing Post to understand how to share contents with other users.

Running Backend To Process Follow Request

To handle sending Accept activities back to followed users, we can set up a simple backend server on our local computer. This server would be available for a limited time each day. Additionally, we can provide a basic contact method on our static site, allowing followed users to notify us about follow requests so that we can address them appropriately.

Example Program of Accept Activity

import request 
from ActivityHandler import *

# URL pointing to your actor object
actor_id = "https://noah.netlify.app/noah/actor.json"

# Path to the private key generated using the "generate-keys.js" algorithm
private_key_path = "..."


# Activity Information 
# Retrieved from our local backend server 
follow_id = "..."

handler = ActivityHandler(actor_id, private_key_path)
handler.send_accept_activity(
	follow_id=follow_id
)

References


See also