Home - teeworlds-nats/bridge GitHub Wiki

"Bridge" – A bridge between the DDRaceNetwork game and external services.
As of the writing of this page (06/20/2025), existing integrations include Telegram support.


How args Works

The args object is distributed hierarchically:

  1. It starts at the Econ service level.
  2. Merges with the args level of Handler.
  3. Propagates further from Handler to other components.

Basic Configuration

Econ

nats:
  server:
    - nats://127.0.0.1:4222

econ:
  host: 127.0.0.1:8303
  password: econ_password  # Replace with actual Econ password

args:
  server_name: fng-1
  message_thread_id: 1379  # Integer only (Telegram thread ID)

Handler

nats:
  server:
    - nats://127.0.0.1:4222

paths:
  - from: tw.econ.read.*
    regex:
      - "\\[chat]: \\d+:-?\\d+:(.*): (.*)"       # Teeworlds chat format
      - "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2} I chat: \\d+:-?\\d+:([^:]+): (.*)$"  # DDNet chat format
      - "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2} I chat: \\*\\*\\* '(.*?)' (.*)$"     # DDNet join/leaved
    to:
      - tw.tg.{{message_thread_id}}  # Dynamic NATS topic for Telegram
    args:  # Merges with parent args
      server_name: Test

args: {}  # Inherited by all paths if not overridden

Automatic Configuration

Econ

nats:
  server:
    - "nats://127.0.0.1:4222"
  from:
    - "tw.{{type}}.write.{{server_name}}"
    - "tw.sync"
  to:
    - "tw.{{type}}.read.{{server_name}}"

  # Required value to be sent to all "econ" services, not just one of the queues.
  queue: ""

econ:
  host: "{{server_name}}.{{type}}-tw:8000" # Excellent solution if you have your own DNS server (Kubernetes handles this in my case when service names match args.server_name)
  password: econ_password # Replace with actual Econ password
  first_commands:
    - "say [SYSTEM] ECON Bridge connected!"
  tasks:
    - command: "bans_save bans"
      delay: 300
    - command: "" # attempt to send a message to the server to re-establish the connection if it fails to send it
      delay: 5

args:
  server_name: "fng-1"
  type: "fng"
  message_thread_id: 1379  # Integer only (Telegram thread ID)

Handler

nats:
  server:
    - nats://127.0.0.1:4222

paths:
  - from: tw.econ.read.*
    regex:
      - "^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) (I|E) ([a-z]+): (.*)"
    to:
      - tw.DDnet.{{2}}.{{3}}  # {{0}} - Original full message text
    args:
      message_text: "{{3}}"    # {{0}} - Corresponds to paths[?].to's {{1}}
      message_regex: "^\\d+:-?\\d+:([^:]+: .+)$"
      not_starts_with: "***"

Sends to dynamic subjects:
tw.DDnet.{{level}}.{{log_type}}

Common combinations:

  • I.chat / I.game / I.server
  • E.* (all error types)

Additional Links

TODO URLs