Install Maubot For Matrix
Install Maubot For Matrix
org/2020/04/01/how-to-install-and-run-bots-for-the-matrix-network/
https://git.interhacker.space/alban/maubot-installer
https://git.interhacker.space/alban/maubot-installer/raw/branch/master/plugins-install.sh
INTERESANT
https://github.com/maubot/supportportal
After indicating your chosen subdomain, you can go for default answers, including the matrix.org
homeserver, and should be fine for the rest of this tutorial.
Et voilà ! You should have a maubot instance running with Letsencrypt on
https://botsinspace.example.com
Creating your first bot
Once the maubot instance is up, understanding the maubot concepts will help you configure it.
Plugins
Plugins are the bots “brains”. They are python code and configuration files, ran in background by
maubot. Ther are stored on the server as mbp files, which are archives using a zip compression.
Clients
Clients are the bots “physical presence”. They are in fact user accounts on matrix servers, no more
no less.
Instances
Instances are associations of a plugin and a client. Once you have an instance, you have a bot!
So let’s start creating our first instance!
Add a plugin
The project page lists a number of plugins based on the maubot framework.
To install a plugin, you have two options.
Option 1. Use the web interface
Log in your maubot instance, click on the plugins “⊕” button. A big UPLOAD button (cf.
screenshot) shows up, click on it, select a plugin zip file on your disk, and there you go !
The maubot plugin menu
Easy right?
Well except one thing: where do you get that zip file in the first place? From the github “Get a zip
copy of the project” button of a plugin page? Well, nuhuh, nope, that won’t work. Maubot will
reject that zip file. Why?
The github zip file contains the file “in a directory” called “$projectname-$branch” and maubot
expects files to be at the root of the zip archive.
So, the right way to go is:
٭Download a zip file from a plugin repository home page
٭Extract it locally
٭Enter the newly created directory
٭Select all its files and sub-directories
٭Create a new zip archive with these
٭Upload that zip file to maubot.
Or if you will, plugins might available as “mbp” files in the “release” section of their github page.
Sadly, they’re not always up to date, so you might be left with a manual job to do.
Option 2. Use the command line interface
Well seeing this could be a bit complex and annoying to repeat we came up with a script in the
“maubot installer” project, called plugin-install.sh
You will need to use a config file or edit the variables at the beginning of the script for it to work
though.
Once you’ve done it you just have to
٭Run the script
٭Select a plugin in the list
٭Login (once only) with your maubot user and password
٭And the script will call the “mbc” executable provided by maubot.
It is worth mentioning that some plugins might require a few additional dependencies. For example
the trump plugin required to run an install command in the virtualenv of the project:
cd /opt/maubot
source bin/activate
pip install Pillow
But now, you should have at least one plugin available. Let’s head to the next stop.
Add a client
We won’t cover here the run-your-own-bot-factory approach, which requires running your own
synapse server, in other word running your own matrix instance. So we will create an account on an
existing server and retrieve its token used for interacting with the API.
We will use the default web interface https://riot.im/app and request a free matrix.org account.
The Riot.im
home
You have to pick a username, for example rook_the_bot, which will provide a matrix
identifier/address such as “@rook_the_bot:matrix.org” after creation.
plugins-install.sh
#!/bin/bash
# CONFIG MANAGEMENT
declare -A botList
botList[https://github.com/maubot/jesaribot]="A simple bot that replies with an
image when you say "jesari"."
botList[https://github.com/maubot/sed]="A bot to do sed-like replacements."
botList[https://github.com/maubot/factorial]="A bot to calculate unexpected
factorials."
botList[https://github.com/maubot/media]="A bot that replies with the MXC URI of
images you send it."
botList[https://github.com/maubot/dice]="A combined dice rolling and calculator
bot."
botList[https://github.com/maubot/karma]="A user karma tracker bot."
botList[https://github.com/maubot/xkcd]="A bot to view xkcd comics."
botList[https://github.com/maubot/echo]="A bot that echoes pings and other
stuff."
botList[https://github.com/maubot/rss]="A bot that posts RSS feed updates to
Matrix."
botList[https://github.com/TomCasavant/RedditMaubot]="A bot that condescendingly
corrects a user when they enter an r/subreddit without providing a link to that
subreddit"
botList[https://github.com/TomCasavant/GiphyMaubot]="A bot that generates a gif
(from giphy) given search terms"
botList[https://github.com/jeffcasavant/MaubotTrumpTweet]="A bot that generates
a Trump tweet with the given content"
botList[https://github.com/TomCasavant/PollMaubot]="A bot that will create a
simple poll for users in a room"
botList[https://github.com/dvdgsng/UrbanMaubot]="A bot that fetches definitions
from [Urban Dictionary](https://www.urbandictionary.com/)."
botList[https://github.com/maubot/reminder]="A bot to remind you about things."
botList[https://github.com/maubot/translate]="A bot to translate words."
botList[https://github.com/maubot/reactbot]="A bot that responds to messages
that match predefined rules."
botList[https://github.com/maubot/exec]="A bot that executes code."
botList[https://github.com/maubot/commitstrip]="A bot to view CommitStrips."
botList[https://github.com/maubot/supportportal]="A bot to manage customer
support on Matrix."
botList[https://github.com/maubot/gitlab]="A GitLab client and webhook
receiver."
botList[https://github.com/maubot/github]="A GitHub client and webhook
receiver."
install=y
case $REPLY in
([0-9]*)
URL=${indexedArray[$REPLY]}
[[ -z "$URL" ]] && echo "Invalid choice. Try again." &&
continue
zipURL="$URL/archive/master.zip"
tempDir=$(mktemp -d)
projectName=$(basename $URL)
cd "$tempDir"
info "Downloading file"
wget -q "$zipURL" &>/dev/null
info "Converting"
unzip master.zip &>/dev/null
cd "$projectName-master"
zip -r archive * &>/dev/null
mv archive.zip "$tempDir"
info "Ready to upload"
cd "$install_dir"
read -e -n 1 -i y -p "Do you want to login in maubot
[Y/n]? " login
[[ "n" != ${login:-y} ]] && echo -e "Here are your
config credentials: \n Username $maubot_user\n Password $maubot_pass\n
Server $server_address\n" && "$install_dir/bin/mbc" login
"$install_dir/bin/mbc" upload "$tempDir/archive.zip" -s
"$server_address"
rm -rf "$tempDir"
;;
(x)
install=n
;;
(*)
echo "Unknown choice '$REPLY'. Try again."
;;
esac
done
The riot account creation interface
One your mail is validated, log in the web interface and head to the settings page to retrieve the
token.
A Riot settings menu link
You will find it token at the end of the “Help & About” page: click on the <click to reveal> link,
and copy the string that appears.
Riot token finally shows up!
Time to head back to your maubot instance, and click on the Client “⊕” button. Fill the requested
informations : the username you created and the access token are mandatory. Validate.
The maubot client menu
And that’s it. You’re ready for the last stage.
Add an instance
Head your maubot instance and client on the Instances “⊕” button.
The maubot instance menu
Just pick a client and a plugin before validating.
And now you should have your first bot ready! Congratulations!