Tool:Bridgebot

From Wikitech
Jump to navigation Jump to search
Toolforge tools
Crystal Clear app package utilities.png
Description A bot for bridging IRC and other chat platform channels
Keywords irc, golang
Maintainer(s) BryanDavis (View all)
Source code https://github.com/42wim/matterbridge
License Apache License 2.0
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 Mattermost.

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:

IRC
  • account: wm-bridgebot
  • nicks: wm-bridgebot, wm-bb
Telegram
Discord

Maintenance

The bot runs from Toolforge under the "bridgebot" account as a kubernetes pod. The Kubernetes container is managed by a custom deployment.

$HOME/etc/deployment.yaml
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: bridgebot.bot
  namespace: tool-bridgebot
  labels:
    name: bridgebot.bot
    toolforge: tool
spec:
  replicas: 1
  selector:
    matchLabels:
      name: bridgebot.bot
      toolforge: tool
  template:
    metadata:
      labels:
        name: bridgebot.bot
        toolforge: tool
    spec:
      containers:
        - name: bot
          image: docker-registry.tools.wmflabs.org/toolforge-buster-sssd:latest
          resources:
            limits:
              cpu: 1
              memory: 1Gi
            requests:
              cpu: 1
              memory: 1Gi
          command:
            - "/data/project/bridgebot/bin/bb.sh"
            - "run"
          workingDir: /data/project/bridgebot
          env:
            - name: HOME
              value: /data/project/bridgebot
          imagePullPolicy: Always
$ ssh login.toolforge.org
$ become bridgebot

:# Deploying
$ bin/bb.sh start
Starting bridgebot k8s deployment...

:# Quick restart (pod delete)
$ bin/bb.sh restart
Restarting bridgebot pod...

:# "Full" restart (Deployment delete; Deployment create)
$ bin/bb.sh stop
Stopping bridgebot k8s deployment...
$ bin/bb.sh start
Starting bridgebot k8s deployment...

:# Upgrading the golang binary
$ cd $HOME/bin
$ wget https://github.com/42wim/matterbridge/releases/download/v{$version}/matterbridge-{$version}-linux-64bit
$ chmod a+x matterbridge-{$version}-linux-64bit
$ vim bb.sh
  update the MATTERBRIDGE=... line to the new version
  :wq
$ $HOME/bin/bb.sh restart

Joining a new channel

Maintainers of the tool can configure the bot to join a new channel;

$ ssh login.tools.wmflabs.org
$ become bridgebot
$ vim matterbridge.toml
:# Add a new "[[gateway]]" section defining the gateway name and the channels to bridge
$ kubectl delete po/$(kubectl get pods | grep Running | awk '{print $1}')

Telegram

If one side of the bridge is Telegram you will need these things to be done:

  1. Have an admin of the Telegram channel invite the "@wmtelegram_bot" user to the channel
  2. Follow the log output of the bot: `kubectl logs -f $(kubectl get pods | grep Running | awk '{print $1}')`
  3. Have someone in the Telegram channel talk to the bot
  4. Collect the Telegram "Channel" id number from the DEBUG log output
    [85656] DEBUG telegram:     <= Message is config.Message{Text:"@wmtelegram_bot I need you to see this message so I can finish https://phabricator.wikimedia.org/T258078", Channel:"-1001308089610", Username:"bd808", UserID:"419968011", Avatar:"https://tools-static.wmflabs.org/bridgebot/4a263e14/419968011.png", Account:"telegram.bridgebot", Event:"", Protocol:"", Gateway:"", ParentID:"", Timestamp:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}, ID:"86", Extra:map[string][]interface {}{}}

Discord

If one side of the bridge is Discord you will need these things to be done:

  1. Have an admin of the Discord server invite the bot to their server using the bot's invite link

remotenickformat.tengo

A tengo script is used to do per-channel customization of nick formats used when cross-posting messages between services.

Note: this script is read from disk each time the bot needs to send a message across a bridge, so edits should be made carefully. Any syntax errors in the script will stop messages from passing across all bridges until they are corrected.

$HOME/remotenickformat.tengo
/**
 * The script will have the following global variables:
 * to modify: result
 * to read: channel, bridge, gateway, protocol, nick
 */

ret := "[" + protocol + "] <" + nick + "> "

if gateway == "ukwiki-discord-telegram" {
  protos := immutable({
    discord: "дс",
    telegram: "тг"
  })
  proto := protos[protocol]
  ret = "[" + (proto == undefined ? protocol : proto) + "] <" + nick + "> "

} else if gateway == "wikipedia-abstract-irc-telegram" {
  ret = "<" + nick + "> "

}

result = ret