Working with Mastodon

Updated 19 July 2019

Proxy configuration

Access to other federated resources can be configured via a proxy. Add the necessary settings:



Restart Mastodon:

/etc/init.d/mastodon-web restart

Using bots to organize groups

A bot mastodon-bot-autoresponder will be used to organized groups

Creating and configuring a bot

Create the mastodonbot user:

useradd -d /var/calculate/mastodonbot mastodonbot

Clone the repository containing the bot source code for the user:

su - mastodonbot

git clone mastodon-group-bot

Set up a virtual environment for Python and enable it

cd mastodon-group-bot

python3 -m venv env

source env/bin/activate

Set the dependencies for the bot

pip install beautifulsoup4==4.6.0

Create a basic script to start the daemon:

# Copyright 2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

name="Mastodon Group Bot daemon"
description="Mastodon Group Bot daemon"
command_args=" -c config.$BOTNAME.json"

depend() {
    use net

start_pre() {
    checkpath -f -o mastodonbot -m 0600 /var/log/mastodon-group-bot-$BOTNAME.log

Set the permissions for the daemon to start:

chmod 755 /etc/init.d/mastodon-group-bot

Adding your bot to Mastodon

Register the bot as an application on your server. To do this, open your browser and login to Mastodon under the name the bot will be using. Now run

su - mastodonbot

cd mastodon-group-bot

source env/bin/activate

Choose your action:
[r]: register an app to get client_id and client_secret
[a]: authenticate to get access_token
if you're setting up a bot for the first time, choose [r].
> r
App name [autoresponder]: examplebot
Instance base URL []:
App registered.
client_id: eidNondeabryievrewkasfakuvcorigovpefNifZibr
client_secret: jokpinshedCauHalsishpEbodIatsilyethjuOvtyfs
While you're at it, do you want to also authenticate?
y/n> y
Visit the following link, authenticate, and bring back the code that the page gives you afterwards.
NB: that code is *not* your access token.
> MT-afgOKW4wffDpGjXUEB1dm135mcSwX9zql4c3ictM
Got access token: cNsH2V8AVJrrovdePEK7GFy6PA7ywHErU1xkwuIX5UM
Success, authenticated as newbot.


To get the access code, ~~MT-afgOKW4wffDpGjXUEB1dm135mcSwX9zql4c3ictM~ click on the generated link.

Confirming access for bot

Obtaining a token for bot

At registration time, you will get:

  • client_id = eidNondeabryievrewkasfakuvcorigovpefNifZibr
  • client_secret = jokpinshedCauHalsishpEbodIatsilyethjuOvtyfs
  • access_token = cNsH2V8AVJrrovdePEK7GFy6PA7ywHErU1xkwuIX5UM

Configure your bot:

    "base_url": "",
    "client_id": "eidNondeabryievrewkasfakuvcorigovpefNifZibr",
    "client_secret": "oeCMH9L_OeuuuV699334Rgea3o_0R3kYhfCKu9ZYCh4",
    "access_token": "cNsH2V8AVJrrovdePEK7GFy6PA7ywHErU1xkwuIX5UM",
    "message": "Hello, I'm a group bot. Follow me and then write something, and I will boost it. The admins of the group are:",
    "message_welcome": "Welcome our new member: ",
    "admins": [],
    "state_file": "/var/calculate/mastodonbot/mastodon-group-bot/state.examplebot"

Create a symlink pointing to examplebot:

ln -sf mastodon-group-bot /etc/init.d/mastodon-group-bot.examplebot

Launch your bot and add it to autostart:

/etc/init.d/mastodon-group-bot.examplebot start

rc-update add mastodon-group-bot.examplebot