Skip to main content

ActivityPub

This service allows you to create an ActivityPub server with data stored in a triple store.

Features

  • Store activities, actors and objects in the triple store
  • Allow to create actors when new WebIDs are created
  • Side effects are supported for Create, Update, Delete, Follow, Like activities, as well replies

Dependencies

Sub-services

  • ActivityService
  • ActivitiesWatcherService
  • ActorService
  • ApiService
  • CollectionService
  • CollectionsRegistryService
  • FollowService
  • InboxService
  • LikeService
  • ObjectService
  • OutboxService
  • ReplyService

Other services

Mixins

Install

$ yarn add @semapps/activitypub

Usage

const { ActivityPubService } = require('@semapps/activitypub');

module.exports = {
mixins: [ActivityPubService],
settings: {
baseUri: 'http://localhost:3000/',
queueServiceUrl: null,
activateTombestones: true
}
};

Configure the LDP containers

The containers for actors and objects are handled through the LDP service. You need to define containers with ActivityStreams's actors and objects in the acceptedTypes. Alternatively, you can load the default containers from the @semapps/activitypub package as below:

const { LdpService } = require('@semapps/ldp');
const { containers: apContainers } = require('@semapps/activitypub');

module.exports = {
mixins: [LdpService],
settings: {
baseUrl: process.env.SEMAPPS_HOME_URL,
containers: ['/my-container', ...apContainers]
}
};

Queue federation POSTs

If you want to make sure no data is lost when trying to POST to remote ActivityPub servers, you can set the dispatch.queueServiceUrl settings.

The Bull task manager will queue the task and you will be able to retry it if it fails.

Create actors on account creations

An ActivityPub actor is automatically created when a auth.registered event is detected.

By default, it will:

  • Append the as:Person type, unless another ActivityStreams actor type is detected
  • Use the slug of the actor as the as:preferredUsername property

You can adapt this behaviour to your needs with the selectActorData setting. This function receives the data provided on signup (as JSON-LD), and must return the properties (with their full URI) to be appended. For example:

const selectActorData = userData => ({
'http://www.w3.org/1999/02/22-rdf-syntax-ns#type': 'https://www.w3.org/ns/activitystreams#Person',
'https://www.w3.org/ns/activitystreams#name': userData['foaf:name'],
'https://www.w3.org/ns/activitystreams#preferredUsername': userData['foaf:nick']
});

Note: If no type or as:preferredUsername is returned by this function, it will behave as described above.

Additionally, the ActivityPub services will append all the ActivityPub-specific properties (publicKey, followers, following, likes...)

Settings

PropertyTypeDefaultDescription
baseUriStringrequiredBase URI of your web server
selectActorDataFunctionReceives the data provided on signup (as JSON-LD), and must return the properties (with full URI) to be appended to the actor profile (see above).
queueServiceUrlStringRedis connection string. If set, the Bull task manager will be used to handle federation POSTs.
activateTombestonesBooleantrueIf true, all deleted resources will be replaced with a Tombstone, except for containers which have disabled this

Events

The following events are emitted by the different ActivityPub sub-services.

activitypub.follow.added

Sent after an actor follows another one.

Payload
PropertyTypeDescription
followerStringURI of the actor being followed
followingStringURI of the actor following

activitypub.follow.removed

Sent after an actor stops following another one.

Payload
PropertyTypeDescription
followerStringURI of the actor not being followed anymore
followingStringURI of the actor following

activitypub.inbox.received

Sent after an actor receives an activity in his inbox.

Payload
PropertyTypeDescription
activityObjectActivity payload
recipientsArrayList of recipients URIs
localBooleanTrue if activity was sent by a local actor

activitypub.like.added

Sent after an actor likes an object

Payload
PropertyTypeDescription
actorUriStringURI of the actor
objectUriStringURI of the object

activitypub.like.removed

Sent after an actor stops liking an object

Payload
PropertyTypeDescription
actorUriStringURI of the actor
objectUriStringURI of the object

activitypub.outbox.posted

Sent after an actor sends an activity through his outbox.

Payload
PropertyTypeDescription
activityObjectActivity payload