Tool:Bridgebot
Description | A bot for bridging IRC and other chat platform channels |
Keywords | irc, golang, matrix, telegram, discord |
Maintainer(s) | BryanDavis (View all) |
Source code | gitlab:toolforge-repos/bridgebot |
License | GNU General Public License 3.0 or later |
Issues | Open tasks · Report a bug |
Admin log | Tools.bridgebot/SAL |
Bridgebot is a deployment of the FLOSS matterbridge software. It can be used to relay messages between multiple different chat systems. The current deployment in Toolforge is bridging various Wikimedia related channels across platforms including Libera.Chat, Telegram, Discord and Matrix.
Bot accounts
The bot must be invited/added to chat channels in order to create bridges. Currently the bot has these accounts on various chat platforms:
- libera.chat IRC
-
- account: wm-bridgebot
- nicks: wm-bridgebot, wm-bb
- Telegram
-
- account: @wmtelegram_bot
- Discord
-
- bot account: wm-bb#9216
- invite link: https://discord.com/api/oauth2/authorize?client_id=744713247218860063&permissions=67497024&scope=bot
- Matrix
-
- account: @wm-bb:matrix.org
Maintenance
$ ssh login.toolforge.org
$ become bridgebot
$ toolforge jobs list
+----------------+------------------+----------------------------+
| Job name: | Job type: | Status: |
+----------------+------------------+----------------------------+
| static-cleaner | schedule: @daily | Waiting for scheduled time |
| bnc | continuous | Running |
| bridgebot | continuous | Running |
+----------------+------------------+----------------------------+
$ kubectl logs --all-containers=true --ignore-errors --max-log-requests 10 --prefix=true \
--since=10m --follow \
--selector 'app.kubernetes.io/name in (bridgebot, bnc)'
To deploy new code or config changes, first build a new container image:
$ toolforge build start https://gitlab.wikimedia.org/toolforge-repos/bridgebot
Then restart the bridgebot
job:
$ toolforge jobs restart bridgebot
Joining a new channel
Maintainers of the tool can configure the bot to join a new channel by adding a new [[gateway]]
section to etc/bridgebot.toml, making a new build, and restarting the bridgebot
job.
Telegram
If one side of the bridge is Telegram you will need these things to be done:
- Have an admin of the Telegram group invite the "@wmtelegram_bot" user to the group
- Have someone in the Telegram group post the message
/chatId
(This command is case-sensitive.) - Collect the Telegram "Chat" id number from @wmtelegram_bot's reply to the bot command
- File a task like phab:T303563
Discord
If one side of the bridge is Discord you will need these things to be done:
- Have an admin of the Discord server invite the bot to their server using the bot's invite link
Matrix
Nothing special needs to be done to bridge a Matrix room as long as the bot account is able to join the room. Note that the bridge is known to relay previously sent Matrix messages, which could be an issue when bridging rooms with significant history. (It's possible that tweaking the room's history visibility settings may avoid this, to be tested...)
SAL
2024-09-17
- 15:51 wmbot~bd808@tools-bastion-12: toolforge jobs restart bnc
- 15:49 wmbot~bd808@tools-bastion-12: toolforge jobs restart bridgebot
2024-07-05
- 20:55 wmbot~bd808@tools-bastion-12: Restarted bridgebot job to pick up new container build (T368317, MR!8)
- 17:00 wmbot~bd808@tools-bastion-12: Replaced tool-bridgebot/znc container with tool-containers/bnc container (T366970)
2024-06-24
- 19:12 wmbot~lucaswerkmeister@tools-bastion-13: toolforge jobs restart bridgebot # *without* new image; bot had stopped bridging cloud IRC a... (more)
Common problems
Media shared in bridged channels is exposed to the world
Bridgebot is configured to use the Toolforge static file service as a "mediaserver". This means that when messages with attached media (images, movies, etc) are shared with an IRC channel bridgebot will save the media into the tool's $HOME/www/static
directory and then post a message to the IRC channel including the tools-static.wmflabs.org/bridgebot/...
URL to that media. This is all handled natively by the upstream software and can only be configured at the instance level meaning that the feature cannot be disabled for an individual bridge.
A side effect of the use of tools-static and the way that matterbridge organizes the media in sub-directories is that all shared media can be browsed by anyone who knows the root URL to the static media collection. This is generally seen by the Bridgebot maintainers as something that allows the Wikimedia community to patrol shared media if they would like, but it can be considered data leaking by others. A partial mitigation for the exposure is that a daily cleanup job deletes media after 30 days.
Duplicate messages being sent from irc to other bridges
The bot can get into a state where every message that it sees from irc gets sent multiple times to other bridged channels. This is caused by incorrect handling of irc server connection messages by the bot when the intermediate ZNC service reconnects to libra.chat. The fix is simply to restart the bot:
$ ssh login.toolforge.org
$ become bridgebot
$ toolforge jobs restart bridgebot
$ dologmsg 'Double IRC messages to other bridges'
You can combine this into a single command:
$ ssh login.toolforge.org -- become bridgebot "toolforge jobs restart bridgebot && dologmsg 'Double IRC messages to other bridges'"
Technical details
The bot runs from Toolforge under the "bridgebot" account as a pair of jobs each running a build service managed container. One job runs ZNC via gitlab:toolforge-repos/wikibugs2-znc and the other runs matterbridge via gitlab:toolforge-repos/bridgebot. Various credentials are stored in toolforge envvars.
There used to be a relatively complex hand build set of Deployments that powered the tool that may be of interest to some.
toolforge-repos/bridgebot and bridgebot job
The tool's bridgebot
job runs an image built from gitlab:toolforge-repos/bridgebot. The repo contains tiny golang application that wraps the upstream matterbridge application. As of 2024-04-25, the version of matterbridge that is imported is actually a local soft fork from gitlab:toolforge-repos/bridgebot-matterbridge.
bnc job
The tool's bnc
job runs the image from tool-containers/bnc:latest. This irc bouncer is used to work around issues like irc disconnect/reconnect loops that caused problems for the service in the past.
jobs.yaml
# https://wikitech.wikimedia.org/wiki/Help:Toolforge/Jobs_framework
---
# ZNC bouncer to sit between matterbridge and libra.chat
# https://gitlab.wikimedia.org/toolforge-repos/wikibugs2-znc
- name: bnc
command: bouncer
image: tool-containers/bnc:latest
cpu: 250m
mem: 256Mi
continuous: true
emails: none
mount: none
no-filelog: true
port: 6667
# Matterbridge in our custom container
- name: bridgebot
command: bot
image: tool-bridgebot/tool-bridgebot:latest
cpu: "1"
mem: 1G
continuous: true
emails: onfailure
mount: all
no-filelog: true
# Mount is needed for storing media
# Delete old media files once per day
# https://github.com/42wim/matterbridge/wiki/Mediaserver-setup-(advanced)#sidenote
- name: static-cleaner
# >- means replace newlines with spaces (folded), no newline at end (strip)
command: >-
/usr/bin/find
/data/project/bridgebot/www/static
-mindepth 1
-mtime +30
-delete
>/dev/null
2>>/data/project/bridgebot/logs/static-cleaner.err
;
true
# ^ find exits nonzero due to not deleting nonempty subdirs;
# `true` hides this
image: bookworm
schedule: "@daily"
emails: none
mount: all
no-filelog: true
remotenickformat.tengo
The etc/remotenickformat.tengo tengo script is used to do per-channel customization of nick formats used when cross-posting messages between services.
Note: Any syntax errors in the script will stop messages from passing across all bridges until they are corrected.