Some updates to ActivityBot
-
Some updates to ActivityBot
https://shkspr.mobi/blog/2026/03/some-updates-to-activitybot/I couple of years ago, I developed ActivityBot - the simplest way to build Mastodon Bots. It is a single PHP file which can run an entire ActivityPub server and it is less than 80KB.
It works! You can follow
@openbenches@bot.openbenches.orgto see the latest entries on OpenBenches.org, and@colours@colours.bots.edent.telfor a slice of colour in your day, and@solar@solar.bots.edent.telto see what my solar panels are up to.This is so easy to use. Copy the PHP file (and a
.envand.htaccess) to literally any web host running PHP 8.5 and you have a fully-fledged bot which can post to Mastodon.Grab the code and start today!
Features
Over the years I've added a few more features to it, so I thought I'd run through what they are. Note, this is all hand-written. No sycophantic plagiarism machines were involved in this code or blog post. I just really like emoji, OK
๏ธ
Be discovered on the FediverseThis is the big one, you can find
@example@example.viii.fion your favourite Fediverse client. This is thanks to its WebFinger support.
Be followed by other accountsNo point being discovered if you can't be followed. This accepts follow requests and sends back a signed accept.
Be unfollowed by accountsSometimes people want to unfollow. Too bad, so sad. Again, this will accept the undo request and delete the unfollowing user's information.
Send messages to the FediverseIf a bot can be followed, but never posts, does it make a sound? This sends a post to all of your followers' (shared) inboxes. Includes some HTML formatting.
Send direct messages to usersNot every message is for the wider public. If you want a bot which sends you a private message, this'll set the visibility correctly.
Attach images & alt text to a message 

A picture is worth a thousand words. But those pictures are meaningless without alt text. Attach as many images as you like. Note, most Mastodon services only accept a maximum of four.
Video Upload 

No transcoding or anything fancy. Upload a video and it'll be sent to your followers.
Audio Upload 

Same as video. Raw audio posted to your followers' feeds.
๏ธ Autolink URls, hashtags, and @ mentionsIncluding URls, tags, and mentions are mostly autolinked correctly. There's a lot of fuzziness in how it works.
๐งต Threads
You can reply to specific messages in order to create a thread.
Follow, Unfollow, Block, and Unblock other accountsIt might be useful for you to remove followers or follow specific accounts.
๏ธ Delete posted messages and their attachments 

We all make mistakes. This will delete your post along with any attachments and send that delete message to everyone. Note, because of the federated nature of the Fediverse, you cannot guarantee that a remote server will delete anything.
๏ธ Edit Posts 

If you don't want to delete and re-post, you can edit your existing posts.
Bridge to BlueSky with your domain name via Bridgy FedNot everyone is on the Fediverse. If you want to bridge to BlueSky, you can use the Bridgy Fed service.
Move followers from an old account and to a new account 

Perhaps you started as
@electric@sex.pantsbut now you want to become@chaste@nunslife.biz- no worries! You can tell followers you've moved and what your new name is.Similarly, if ActivityBot is no longer right for you, it's simple to tell your existing follower to move to your new account.
๏ธ Allow quote posts 

Rather than just reposting your message, this sets the quote policy to allow people to share your message and attach some commentary of your own.
Show followersYour follower count isn't just a number, it is a living list of who chooses to follow you.
๏ธ Content Warnings 

Perhaps you want to hide a bit of what you're saying. Add a content warning to hide part of your message.
Verify cryptographic signaturesHTTP Message Signatures is hard. I think I've mostly got it sorted.
๐ชต Log sent messages and errors
This is primarily a learning aide, so have a rummage through the logs and see what's going on.
Clear logs when there are too manyActivityPub is a chatty protocol. Your server can easily fill up with hundreds of thousands of messages from others. This regularly prunes down to something more manageable.
#๏ธโฃ Hashed passwords for posting


Bit of a guilty moment here. I was originally storing the password in plaintext. Naughty! Passwords are now salted and hashed.
Basic website for showing postsA nice-enough looking front end if people want to view the posts directly on your domain.
Some Deficiencies
Not every piece of software is perfect. ActivityBot is less perfect than most things. Here are some of the things it can't do and, perhaps, will never do. If you'd like to help tackle any of these, fork the code from my git repo!
Retry Failed MessagesA proper Mastodon server will keep trying to send messages to unresponsive hosts. ActivityBot is one-and-done. If a remote server didn't respond in time, or was offline, or something else went wrong - it may not get the message.
Reposts / Announce / QuoteYou cannot boost other posts, or even your own. Nor can you send quote posts.
Act On InstructionsThis is a basic bot. It contains no logic. If you send it a message asking it to take action, it will not. You will need to build something else to make it truly interactive.
Receive MessagesIn fact, other than the follow / unfollow stuff, the bot can't receive any messages from the Fediverse. It doesn't know when a post has been replied to, liked, or reposted.
Set Post VisibilityYour posts are either public or a DM. There's no support for things like quiet followers.
Create PollsEveryone loves to vote on meaningless polls - but this is quite a hard problem for ActivityBot. It would need to keep track of votes, prevent double voting, and probably some other difficult stuff.
๏ธ Change Quote Post VisibilityAs quote posts are still quite new to Mastodon, I'm not sure how best to implement this.
Proper HTML / Markdown SupportAutolinking names, hashtags, and links just about works - but not very reliably. In theory the bot could parse Markdown and create richly formatted HTML from it. But that may require an external library which would bloat the size. Perhaps posting raw HTML could work?
๏ธ Focus Points for ImagesPerhaps of less use now, but still of interest to people?
Other StuffI don't know what I don't know. Maybe some stuff is total broken? Maybe it is wildly out of spec? If you spot something dodgy, please let me know or raise a Pull Request.
#ActivityBot #ActivityPub #mastodon #php -
T tag-activitypub@relay.fedi.buzz shared this topic
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better ๐
Register Login