immers-space / activitypub-express

Modular ActivityPub implementation as Express JS middleware to easily add decentralization and federation to Node apps
MIT License
295 stars 22 forks source link

Code examples #56

Open DePasqualeOrg opened 2 years ago

DePasqualeOrg commented 2 years ago

It would be great to have some code examples for creating an actor, creating an activity, following an actor, and other common actions. Based on the info in the readme, I'm not sure how to use this library after starting up the server.

albjeremias commented 1 year ago

is there any app using this lib? maybe can take a look, ill guide myself with the tests..

Found it: https://github.com/immers-space/guppe/blob/main/index.js :rocket:

wmurphyrd commented 1 year ago

is there any app using this lib? maybe can take a look, ill guide myself with the tests..

Just added links to two apps using this library: https://github.com/immers-space/activitypub-express#next-steps-and-examples

Fmstrat commented 3 months ago

@wmurphyrd Thank you for the example apps. Is there a "basic" demonstration of use somewhere? For instance, by tracing through the code I've figured out (I think) that this is how one would follow a user:

...
await app.listen(80, () => {
    console.log(`Listening on domain.com:80`)
    apex.offlineMode = false
    apex.startDelivery();
})
...
const myUser = await apex.store.getObject(`https://domain.com/u/me`, true);
await apex.store.saveObject(myUser);
const toBeFollowedUserId = `https://domain.com/u/you`;
const toBeFollowedUser = await apex.store.getObject(id);
const followActivity = await apex.buildActivity('Follow', myUser.id, toBeFollowedUserId, { object: toBeFollowedUser });
apex.addToOutbox(myUser, followActivity);

However the Mongo record doesn't have a value entry, so it never actually delivers anything, and I'm stuck. This is likely me doing something wrong since there's no basic code example to follow.

It would be really helpful to have a super-simplistic:

Fmstrat commented 3 months ago

Note: My issues seem to revolve around this library doesn't work out of the box. All the mongo calls use things like result.value and result.ok, which do not exist in the installed libraries. In them, result is the JSON object returned, and it is null otherwise.