Tool:Bridgebot
Description | A bot for bridging IRC and other chat platform channels |
Keywords | irc, golang |
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, and Discord.
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
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
SAL
2024-04-27
- 23:00 wmbot~bd808@tools-bastion-12: Made ZNC jump hosts to test T305487 again
- 22:57 wmbot~bd808@tools-bastion-12: Build new znc image to pick up irssi client config
2024-04-25
- 21:32 wmbot~bd808@tools-bastion-12: Started `bridgebot` job (T363028)
- 21:31 wmbot~bd808@tools-bastion-12: built new image from f4022bd9 (T363028)
... (more)
Common problems
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.
toolforge-repos/wikibugs2-znc and bnc job
The tool's bnc
job runs an image built from gitlab:toolforge-repos/wikibugs2-znc. This irc bouncer is used to work around issues like irc disconnect/reconnect loops that caused problems for the service in the past.
A manually created Service object is used to allow matterbridge running in the bridgebot
job's Pod to connect to ZNC running in the bnc
job's Pod. With this Service in place anything in the brigebot namespace can connect ZNC at bnc:6667
.
kind: Service
apiVersion: v1
metadata:
name: bnc
spec:
selector:
app.kubernetes.io/name: bnc
ports:
- protocol: TCP
port: 6667
targetPort: 6667
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-bridgebot/znc:latest
cpu: 250m
mem: 256Mi
continuous: true
emails: none
mount: none
no-filelog: true
# 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.