Skip to content

Commit 0978d26

Browse files
authored
feat: fetch responses from mastodon and bluesky (#23)
* feat: collect mastodon responses * feat: queue operations for marking and deleting * feat: delete response from queue when processed * feat: fetch and render responses * feat: response template for webmentions * feat: collect urls when hooks are fired * improvement: bluesky - get url from did * feat: collect bluesky responses * feat: panel queue view * feat: allow up to for images for mastodon and bluesky #22 * feat: skip adding url to external posts #17
1 parent 1c81bab commit 0978d26

40 files changed

+3680
-233
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
/.gitattributes export-ignore
1010
/.gitignore export-ignore
1111
/.htaccess export-ignore
12+
/.nvmrc export-ignore
13+
/.prettierrc export-ignore
14+
/.releaserc export-ignore
1215
/index.site.php export-ignore
1316
/package.json export-ignore
1417
/package-lock.json export-ignore

DEVELOPERS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Infos for developers
2+
3+
Use `composer install` to install all dependencies. This creates an Kirby environment so you can test the plugin in the browser. You have to run a webserver for that and point it to the plugin root.
4+
5+
Before pushing changes run `composer run build-release` this will run all unittests and remove dev dependencies.
6+
7+
You can run the unittests by running: `composer test`. You can also use filters to only test specific things: `composer test -- --filter 'MastodonReceiver` for example

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Kirby IndieConnector
22

3-
#### Send and receive Webmentions, send Mastodon and Bluesky posts or act like an ActivityPub instance
3+
#### Send and receive Webmentions, send Mastodon and Bluesky posts (POSSE) and get back responses, or act like an ActivityPub instance
44

55
![GitHub release](https://img.shields.io/github/release/mauricerenck/indieConnector.svg?maxAge=1800) ![License](https://img.shields.io/github/license/mashape/apistatus.svg) ![Kirby Version](https://img.shields.io/badge/Kirby-4%2B-black.svg)
66

@@ -10,8 +10,8 @@ IndieConnector is your interface to the IndieWeb. It'll help you to:
1010

1111
- Receive Webmentions
1212
- Send Webmentions
13-
- Post to Mastodon
14-
- Post to Bluesky
13+
- Post to Mastodon and Bluesky (POSSE)
14+
- Collect responses from Mastodon and Bluesky
1515
- Act like a ActivityPub Instance
1616

1717
This plugins handles all the stuff around Webmentions and then normalizes the format and triggers a hook. Other plugins can then subscribe to this hook and use the data.
@@ -35,7 +35,8 @@ Use one of these three methods to install the plugin:
3535
- [Sending Webmentions](docs/sending.md)
3636
- [Activate the Panel view](docs/panel-view.md)
3737
- [Post to Mastodon or Bluesky](docs/mastodon.md)
38-
- [Reply via Mastodon](docs/mastodon-replies.md)
38+
- [Collect replies from Mastodon and Bluesky](docs/collecting-responses.md)
39+
- [Get replies using brid.gy](docs/mastodon-replies.md)
3940
- [Be a Mastodon Instance](docs/activitypub.md) (ActivityPub)
4041
- [Subscribe to the hook](docs/hook.md)
4142
- [Using webmention.io](docs/webmentionio.md)
@@ -48,6 +49,8 @@ Use one of these three methods to install the plugin:
4849

4950
- [x] Kirby 5 ready
5051
- [x] Manual queue cleanup
52+
- [x] Get replies from Mastodon and Bluesky without brid.gy
53+
- [x] Option for using Kirby UUID permalinks in Mastodon/Bluesky posts
5154
- [ ] Queue for sending webmentions
5255
- [ ] Queue for sending mastodon posts
5356
- [ ] Queue for sending bluesky posts
@@ -56,5 +59,3 @@ Use one of these three methods to install the plugin:
5659
- [ ] Manual post to Mastodon and Bluesky
5760
- [ ] Block hosts from within the panel
5861
- [ ] Post complete texts to Mastodon and Bluesky splitted in threads
59-
- [ ] Option for using Kirby UUID permalinks in Mastodon/Bluesky posts
60-
- [ ] Get replies from Mastodon and Bluesky without brid.gy

blueprints/fields/block-webmentions.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@ fields:
1414
label: Mastodon URL
1515
type: url
1616
width: 1/3
17+
blueskyStatusUrl:
18+
label: Bluesky URL
19+
type: url
20+
width: 1/3
21+
icSkipUrl:
22+
label: Skip posting URL
23+
type: toggle
24+
default: false
25+
width: 1/3

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"Composer\\Config::disableProcessTimeout",
5454
"@php -S localhost:8000 kirby/router.php"
5555
],
56-
"test": "vendor/bin/phpunit --testdox",
56+
"test": "vendor/bin/phpunit --testdox --colors=always tests \"$@\"",
5757
"build-test-package": "git archive HEAD -o indieConnector.zip --worktree-attributes",
5858
"build-composer": "composer install --no-dev --optimize-autoloader",
5959
"build-release": [
@@ -62,4 +62,4 @@
6262
"npm run build"
6363
]
6464
}
65-
}
65+
}

docs/collecting-responses.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Collecting Responses
2+
3+
Collect likes, reposts and replies from Mastodon or Bluesky and show them on your pages.
4+
5+
**This feature requires a SQLite database. [Learn how to set it up here](database.md)**
6+
7+
When you use the IndieConnector to create posts on Mastodon or Bluesky whenever you publish a page (POSSE), you can now collect responses from those posts and show them as comments or in any other form on your pages.
8+
9+
To use this feature you have to at least enable it in your config.php:
10+
11+
```php
12+
'mauricerenck.indieConnector.responses.enabled' => true
13+
'mauricerenck.indieConnector.secret' => 'YOUR-SECRET
14+
```
15+
16+
From now on the Response Collector will remember all post URLs. It will do so whenever the IndieConnector creates a new post on Mastodon or Bluesky or when you manually fill the Mastodon or Bluesky URL fields.
17+
18+
## Collecting Responses
19+
20+
To collect new reponses, you have to call a Webhook. The URL is:
21+
22+
```
23+
https://example.com/indieConnector/cron/queue-responses?secret=YOUR-SECRET
24+
```
25+
26+
Of course you have to change `example.com` to match your host and `YOUR-SECRET` to match the secret your set in your `config.php`.
27+
28+
The plugin will then check the next 10 post URLs it knows and which haven't been check in the last hour.
29+
30+
You can change how many URLs are checked and after how many minutes they should be checked again by setting:
31+
32+
```php
33+
'mauricerenck.indieConnector.responses.limit' => 20
34+
'mauricerenck.indieConnector.responses.ttl' => 120
35+
```
36+
37+
To check 20 posts in row check for the same URLs again after two hours (or 120 minutes).
38+
39+
Depending on how frequently you want to check for responses you should adjust those values and schedule the cronjob which calls the Webhook URL.
40+
41+
## Parse Responses
42+
43+
New reposnes will be added to a queue. To process that queue, you have to call another Webhook:
44+
45+
```
46+
https://example.com/indieConnector/cron/fetch-responses?secret=YOUR-SECRET
47+
```
48+
49+
This Webhook will process 50 responses in a row. You can change that by setting:
50+
51+
```php
52+
'mauricerenck.indieConnector.responses.queue.limit' => 100
53+
```
54+
55+
New reponses will be processed as Webmention, so after setting everything up, you should see those reponses on the Panel View of IndieConnector in case you enabled it.
56+
57+
## brid.gy
58+
59+
If you used brid.gy to collect respones, please make sure to deactivate it, otherwise you might end up with duplicates.

docs/mastodon-replies.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Replies via Mastodon
22

3-
If you want to enable people to reply to your posts via Mastodon, you currently have to use brid.gy to do so. I am currently working on a solution that will allow you to do this without brid.gy.
3+
If you want to enable people to reply to your posts via Mastodon, ~~you currently have to use brid.gy to do so. I am currently working on a solution that will allow you to do this without brid.gy.~~ [there is now a native solution for that](docs/collecting-responses.md).
44

5+
You can sill use brid.gy.
56
Sign up for [brid.gy](https://brid.gy/) and sign in with with Mastodon. Choose cross posting. Follow all the steps. Brid.gy will then send you Webmentions whenever someone replies, likes or boosts your Mastodon post. This webmentions will then be collected by IndieConnector.
67

78
### Set the URL of your Mastodon post

docs/options.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
| ----------------------- | ----------------- | -------------------------------------------------------------------- |
6464
| `post.prefereLanguage` | `-` | Use another language than your default language to use the text from |
6565
| `post.usePermalinkUrl` | `false` | Use the permalink url instead of the page url |
66+
| `post.skipUrl` | `false` | NEVER add the url to the post |
67+
| `post.skipUrlTemplates` | `[]` | Do not add the url to the post when using the given templates |
6668
| `post.textfields` | `['description']` | Text source fields for posting elsewhere |
6769
| `post.imagefield` | `''` | Image source field for posting elsewhere, must be one image |
6870
| `post.allowedTemplates` | `[]` | Set templates allowed to send webmentions |
@@ -90,6 +92,15 @@
9092
| `bluesky.handle` | `‘‘` | Your user handle |
9193
| `bluesky.password` | `‘‘` | Your bluesky app password |
9294

95+
## Collecting responses ([details](responses.md))
96+
97+
| Option | Default | Description |
98+
| ----------------------- | ------- | ----------------------------------------------------------------- |
99+
| `responses.enabled` | `false` | Enable collecting responses |
100+
| `responses.limit` | `10` | Number of posts to check for responses |
101+
| `responses.ttl` | `60` | Minutes after which a post url should be re-checked for responses |
102+
| `responses.queue.limit` | `50` | Number of items to process per run |
103+
93104
## ActivityPub beta ([details](activitiypub.md))
94105

95106
| Option | Default | Description |

index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace mauricerenck\IndieConnector;
44

5-
use Kirby;
5+
use Kirby\Cms\App as Kirby;
66

77
@require_once __DIR__ . '/dependencies/indieweb-comments.php';
88
@include_once __DIR__ . '/vendor/autoload.php';
@@ -15,6 +15,9 @@
1515
'webmention-endpoint' => __DIR__ . '/snippets/webmention-endpoint.php',
1616
'activitypub-wm' => __DIR__ . '/snippets/activitypub-webmention.php',
1717
],
18+
'templates' => [
19+
'indie-post-response' => __DIR__ . '/templates/pages/response.php',
20+
],
1821
'tags' => require_once __DIR__ . '/plugin/kirbytags.php',
1922
'blueprints' => [
2023
'indieconnector/fields/webmentions' => __DIR__ . '/blueprints/fields/block-webmentions.yml',

0 commit comments

Comments
 (0)