Distributed Press CLI
Send Posts

Send Posts

Use Staticpub Template

  1. Fork the Repository: Visit the staticpub.distributed.press (opens in a new tab) repository on GitHub and click the "Fork (opens in a new tab)" button to create your own copy.

  2. Clone Your Fork:

git clone https://github.com/hyphacoop/staticpub.distributed.press.git
cd staticpub.distributed.press
  1. Replace Domain, Username, and Name:

For Linux Users:

find . -type f -exec sed -i 's/staticpub\.distributed\.press/yourdomain\.com/g; s/dp/username/g; s/"Distributed Press"/"Your Name"/g' {} +

For macOS Users:

find . -type f -exec sed -i '' 's/staticpub\.distributed\.press/yourdomain\.com/g; s/dp/username/g; s/"Distributed Press"/"Your Name"/g' {} +

This will replace:

  • staticpub.distributed.pressyourdomain.com
  • dpyourusername
  • Distributed PressYour Name

Make sure to update the publicKeyPem field in the following files with your actual public key from the .dprc configuration file:

  • about.jsonld
  • about-ipns.jsonld

How to Find Your Public Key:

  1. Open your .dprc file (generated during setup).
  2. Copy the value of "publicKeyPem" (including the BEGIN and END lines).
  3. Paste it into the publicKeyPem field in the JSON files mentioned above.

Example:

    "publicKey": {
      "@context": "https://w3id.org/security/v1",
      "@type": "Key",
      "id": "https://staticpub.distributed.press/about.jsonld#main-key",
      "owner": "https://staticpub.distributed.press/about.jsonld",
      "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nYOUR_PUBLIC_KEY_HERE\n-----END PUBLIC KEY-----\n"
    }

Replace YOUR_PUBLIC_KEY_HERE with your actual public key from .dprc.

For using the Social Inbox, you need to generate a keypair and register your ActivityPub actor.

Generate a Keypair

Run the following command to generate a new RSA keypair:

dp-cli generate-keypair

Purpose:
This keypair is used for authenticating your interactions with the Social Inbox and the fediverse at large, ensuring secure communication and verifying your identity.

Note:
If you only plan to use the DP API for static file publishing, generating a keypair might not be necessary. However, it's recommended for enhanced security and functionality when interacting with the Social Inbox.

This will generate a keypair and save it to your .dprc configuration file.

⚠️ Publish the Staticpub Template

Make sure your site is published before registering an actor and sending a post, as this is a prerequisite for proper functionality and includes your public key for signing.

Please follow the steps from this section:

Additionally, ensure that the WebFinger /.well-known file is correctly published for your domain. To automate this process, you can set up GitHub Actions (opens in a new tab) in the workflows directory.

Alternatively, you can use the staticpub's publish.yml (opens in a new tab). Be sure to update the site_url and add your secret DISTRIBUTED_PRESS_TOKEN in the workflow configuration.

Register Your Actor

Register your ActivityPub actor with the Social Inbox:

dp-cli register-actor

This will register your actor with the Social Inbox and save the details to your configuration.

Send a Post to Followers

Published the template? Now, let's send a post to your followers:

dp-cli send-post ./path_to_activity.json

Example (as per the staticpub template):

dp-cli send-post ./posts/helloworld.jsonld

Patch a Site

After publishing your site and registering your actor, you might need to update your site with new content or activities. Use the patch command to add the note/activity JSON and update the outbox with the new activity.

dp-cli patch -i <site-id> ./path_to_patch_folder

Configuration

The CLI uses a configuration file named .dprc to store API URLs, authentication tokens, keypairs, and actor information. The configuration file follows the format expected by the rc module (opens in a new tab), which loads configuration options in a flexible way.

Your .dprc file should look like this:

{
  "dpApiUrl": "https://api.distributed.press/v1",
  "socialInboxUrl": "https://social.distributed.press/v1",
  "authToken": "<your-auth-token>",
  "keypair": {
    "publicKeyPem": "<your-public-key>",
    "privateKeyPem": "<your-private-key>"
  },
  "domain": "<your-site-domain>",
  "actorUsername": "<your-actor-username>",
  "actorUrl": "<your-actor-url>",
  "publicKeyId": "<your-public-key-id>"
}
  • dpApiUrl: The base URL for the Distributed Press API.
  • socialInboxUrl: The base URL for the Social Inbox.
  • authToken: Your authentication token for API access.
  • keypair: Your public and private keys for secure interactions.
  • domain: Your custom domain for the site, e.g., example.com.
  • actorUsername: Your ActivityPub actor username.
  • actorUrl: The URL of your actor.
  • publicKeyId: The ID of your public key.

Ensure that your .dprc file is not committed to version control to keep your credentials secure.

Commands

generate-keypair

Description:
Generate a new RSA keypair and save it to your configuration.

Usage:

dp-cli generate-keypair

register-actor

Description:
Register your ActivityPub actor with the Social Inbox.

Usage:

dp-cli register-actor

Prompts:

  1. Enter your actor username:
    (e.g., "@username@yourdomain.com")

  2. Enter your actor URL:
    (e.g., "https://yourdomain.com/actor (opens in a new tab)")

  3. Enter your public key ID:
    (e.g., "https://yourdomain.com/actor#main-key (opens in a new tab)")

send-post

Send an activity post to your followers and publish it on the DP site:

dp-cli send-post --path ./path_to_activity.json

Output:

Sending a post to followers...
Post sent successfully!
Response: { ... }