@ImDad@botsin.space and @InspiroBot@botsin.space
- Ananas – bot framework that handles scheduled posting, reply posting, bot config, and more
- Mastodon.py – mastodon interaction library that powers Ananas. Whether it's uploading media, posting toots, or looking up user profiles, any mastodon interactions Ananas does will use Mastodon.py methods
To run the bots locally you need:
- docker
- the internet
- a mastodon application's client id, client secret, and access token
Click here if you don't know how to get client ids, secrets, and access tokens
Bot accounts start out as regular old Mastodon accounts. Be careful what instance you create a bot account on though; many instances don't allow bots. I'd recommend using https://botsin.space, since it's intended specifically for hosting bots.
Don't just create an application on your normal mastodon account; the bots will start posting as you when you run them! For development purposes, it's probably best to create a single testing/throwaway account.
- Register the account, just like you normally would
- Once you're logged in, click Edit Profile
- In the settings side-menu, click Development
- Click New Application. Anything that externally interacts with mastodon is an "Application", including Bots.
- Fill out the application form:
- Give your bot application a name. I would just use the same name as your bot. For our example, I'd use ReplyBot.
- Website and Redirect URI aren't important for us
- Ensure you've got the scopes enabled. You should only need read and write, but there's no harm in having follow enabled too
- Make note of the
client key
,client secret
andaccess token
that are shown once you save the application, you'll need those soon!
There are two ways to pass in your client ids, secrets, and access tokens.
Your specific bot's client keys will be sourced automatically from a .env.local
file in the working directory, if it exists. Don't worry, .env.local is gitignored, so you won't accidentally commit your keys.
here's an example .env.local
file:
# the domain the mastobots will be hosted on
MASTOBOTS_DOMAIN=botsin.space
# your main mastodon account, for errors to be reported to
MASTOBOTS_ADMIN=your@main.mastodon.account
INSPIROBOT_CLIENT_ID=yourInspirobotClientKey
INSPIROBOT_CLIENT_SECRET=yourInspirobotClientSecret
INSPIROBOT_ACCESS_TOKEN=yourInspirobotAccessToken
DADBOT_CLIENT_ID=yourDadbotClientId
DADBOT_CLIENT_SECRET=yourDadbotClientSecret
DADBOT_ACCESS_TOKEN=yourDadbotAccessToken
To run the bots with the config, simply:
docker build -t mastobots .
docker run docker run -it mastobots
The .env.local will be copied into the image when docker build
runs, and will be applied during startup.
docker build -t mastobots .
docker run docker run \
-e INSPIROBOT_CLIENT_ID=yourInspirobotClientKey \
-e INSPIROBOT_CLIENT_SECRET=yourInspirobotClientSecret \
-e INSPIROBOT_ACCESS_TOKEN=yourInspirobotAccessToken \
-e DADBOT_CLIENT_ID=yourDadbotClientId \
-e DADBOT_CLIENT_SECRET=yourDadbotClientSecret \
-e DADBOT_ACCESS_TOKEN=yourDadbotAccessToken \
-e MASTOBOTS_DOMAIN=botsin.space \
-e MASTOBOTS_ADMIN=your@main.mastodon.account \
-it mastobots