It does seem to know about ActivityPub :drgn_think_cool:
const express = require('express');
const bodyParser = require('body-parser');
const {
fromObject,
toObject,
Actor,
Collection,
Link,
OrderedCollection,
OrderedCollectionPage,
getId,
getType
} = require('activitypub');
const app = express();
app.use(bodyParser.json());
const actor = new Actor({
id: 'http://localhost:3000/actor',
type: 'Person',
name: 'Bot',
inbox: 'http://localhost:3000/inbox',
outbox: 'http://localhost:3000/outbox'
});
app.post('/inbox', (req, res) => {
const { body } = req;
const object = fromObject(body);
const objectType = getType(object);
if (objectType === 'Create') {
// handle creation of an object
} else if (objectType === 'Follow') {
// handle follow request
} else if (objectType === 'Like') {
// handle like request
}
res.send('OK');
});
app.get('/outbox', (req, res) => {
const collection = new OrderedCollection({
id: 'http://localhost:3000/outbox',
totalItems: 10,
first: new OrderedCollectionPage({
id: 'http://localhost:3000/outbox?page=1',
type: 'OrderedCollectionPage',
partOf: 'http://localhost:3000/outbox',
items: [
// array of objects that have been created by the bot
]
})
});
res.json(toObject(collection));
});
app.listen(3000);
GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.
All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.