Repository navigation
Basic production setup
Before you start, you'll want to set up a Mastodon account that you can use for testing. Preferably this would be an account on botsin.space, seeing as that's the most popular instance in the Fediverse for bots (that I know of). You'll have to request an account as registrations are restricted. There are other bot-friendly instances of Mastodon, though they'll likely also have an approval requirement as well for new accounts.
Once you have a Mastodon account set up on a bot-friendly instance, follow the instructions below to get started.
-
- Once logged into your instance, head to the Development section of the Mastodon preferences found at https://your-instance.org/settings/applications.
- In the Your applications section, click New Application.
- Fill out the Application name, and Application website fields. Suggested values are postodon and the URL of this repo, respectively.
- Uncheck all permissions in the Scopes section
- Enable the following permissions:
- read:notifications (Check if someone's mentioned your slash command)
- write:statuses (So the bot is able to post)
- write:notifications (Allows the clearing of notifications to prevent duplicate replies. This will no longer be required in a later version.)
- Once the scopes have been set, scroll to the bottom of the page and click Submit
- Now back in the Your applications page, click the name of your application:
- On this page you will find the Access token. Keep this page open for one of the later steps.
This section will be written as if you were setting up postodon to be run in a production environment.
postodon gets its configuration via variables that are set in a provided .env or environment variable file. Make sure to create this before running postodon. Your app will not function otherwise.
The file, as the title indicates, should be named exactly .env. In this file you should include the following, changing the relevant values as you see fit. Beneath this code snippet you'll find an explanation of each variable.
ACCESS_TOKEN=3x4mP1et0kEnFR0mY0ur1N574nC3_358nfnslDee
INSTANCE_URL=botinstance.example.com
COMMAND=/yourcommand
REPLY_INTERVAL=5000
POST_INTERVAL=86400000
ACCESS_TOKEN this is the value that you saw in step 8 of the Get an API key for your bot section.
INSTANCE_URL is the url at which your bot account/application was created.
COMMAND is the command you want your bot to respond to with a random post
REPLY_INTERVAL is the interval at which postodon will check for commands to reply to (in milliseconds)
POST_INTERVAL is the interval at which postodon will post a random status (in milliseconds)
postodon's daily messages are composed of two parts: an intro and content. When postodon creates a post(status), it picks a random intro, a random 'content', and then concatenates them with two newlines in between.
postodon loads the intros and content by reading the intros.txt and content.txt files, respectively, and each new line of text is separated into it's own entry of intro or content. To add intros or content to post, just put more text on a new line in one of those files.
Example:
intros.txt
This is an intro
This is another intro
This is a third one
Above is the intros.txt file. If I wanted to add another intro for postodon to pick from, I just add another intro on another line.
This is an intro
This is another intro
This is a third one
This is a new intro
If you want all statuses to have the same intro, simply only include a single one
This is what will be posted as an "intro" for every post
Same goes with the content.
To start postodon via Docker CLI, run the following:
docker run --name postodon bnolet/postodon --env-file ./env --volume ./intros.txt:/usr/src/intros.txt --volume ./content.txt:/usr/src/content.txt
To start postodon directly in npm, follow the instructions below:
Clone the repo and go into the local folder for the repo:
git clone https://github.com/BNolet/postodon.git
cd postodon // move to copied code folder
Move the supplemental files into the src folder:
mv ~/path/to/.env src/.env
mv ~/path/to/intros.txt src/intros.txt
mv ~/path/to/content.txt src/content.txt
Install the required nodejs modules and start postodon:
npm install
npm run start