5

Script that uses Postmill's webhooks to announce new submissions in Matrix channels

Submitted by emma in hacking

A brief how-to guide for those who want this in their own Matrix channels:

  1. Follow the instructions at t2bot.io.

  2. Install this script somewhere so it's accessible via the web. Copy the URL retrieved through !webhook to the WEBHOOK_URL constant in the script. Change SECRET to something unguessable.

  3. In Postmill, go to your forum -> toolbox -> webhooks, add a new webhook, set 'URL' to the URL of the script you installed, and 'secret' to the SECRET constant you chose in step two. Set 'event' to 'new submission'.

If everything works, a new bot should join the Matrix channel and announce new submissions next time someone posts one.

Comments

You must log in or register to comment.

1

sqewl wrote (edited )

This is works great, thanks.

Except one issue I noticed when running this on my server is that this line gave me an error:

if (!hash_equals($_SERVER['HTTP_X_POSTMILL_SECRET'] ?? '', SECRET)) {
    http_response_code(403);

    die('{"error": "get out"}');
}

When I removed it, it ran properly. I don't know much about php so not sure what caused it but I'll need to figure something out to keep the script secure. I will see if I can research to figure it out, but would be glad to get your input.

3

emma wrote

What's the error? Only thing I can think of is your server is running PHP 5.x (that snippet requires PHP 7.0 or newer).