diff --git a/README.md b/README.md index 6c36940..581db42 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,20 @@ matterbridge_gateways: - { status: "movies", discord: [{ srv: "status-pub", ch: "movies" }] } ``` +# API + +To use the Matterbridge API it must be enabled with `matterbridge_api_enabled: true`. +Currently only a single API (called `api`) is supported. + +It can be used in a gateway like this: + +``` +- { discord: [{ srv: "vac", ch: "waku" }], api: ["api"]} +``` + +The API is running on port 4242 by default (`matterbridge_api_port`). More info +about the API can be found on the [Matterbridge wiki](https://github.com/42wim/matterbridge/wiki/Api). + # Known Issues If your bridge is posting in a Discord channel but doesn't receive mesages from it you might have to adjust the channel-level permissions to give the bot message read rights. diff --git a/defaults/main.yml b/defaults/main.yml index 99b1b52..0420b0d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -7,6 +7,10 @@ matterbridge_debug: false matterbridge_nick: bridge matterbridge_ens_name: bridge.stateofus.eth +# configuration for API +matterbridge_api_enabled: false +matterbridge_api_port: 4242 + # configuration for gateways matterbridge_gateways: [] diff --git a/tasks/consul.yml b/tasks/consul.yml index 1342bc5..559e16d 100644 --- a/tasks/consul.yml +++ b/tasks/consul.yml @@ -11,3 +11,17 @@ name: 'MatterBridge health' type: 'script' script: '/usr/bin/pgrep -xl matterbridge' + +- name: Create Consul service definition for API + include_role: name=consul-service + when: '{{ matterbridge_api_enabled }}' + vars: + consul_config_name: '{{ matterbridge_cont_name }}-api' + consul_services: + - name: '{{ matterbridge_cont_name }}-api' + tags: ['matterbridge', 'bridge'] + checks: + - id: '{{ matterbridge_cont_name }}-api-health' + name: 'MatterBridge API health' + type: 'script' + script: 'curl --fail http://localhost:{{ matterbridge_api_port }}/api/health' diff --git a/tasks/container.yml b/tasks/container.yml index cd8cbf4..d928b92 100644 --- a/tasks/container.yml +++ b/tasks/container.yml @@ -10,6 +10,9 @@ restart: '{{ config_file.changed or cont_restart }}' volumes: - '{{ matterbridge_cont_vol }}/matterbridge.yaml:/matterbridge.yaml' + ports: '{{ [lookup("vars", "docker_api_port")] if lookup("vars", "matterbridge_api_enabled") else [] }}' command: | -conf=/matterbridge.yaml {% if matterbridge_debug %}-debug{% endif %} + vars: + docker_api_port: '{{ matterbridge_api_port }}:{{ matterbridge_api_port }}' diff --git a/templates/matterbridge.yaml.j2 b/templates/matterbridge.yaml.j2 index 7a62d17..1a988bf 100644 --- a/templates/matterbridge.yaml.j2 +++ b/templates/matterbridge.yaml.j2 @@ -12,6 +12,13 @@ general: {{ matterbridge_bridges | to_nice_yaml }} {% endif %} +{% if matterbridge_api_enabled %} +api.api: + BindAddress: 0.0.0.0:{{ matterbridge_api_port }} + Buffer: 1000 + RemoteNickFormat: '{NICK}@api' +{% endif %} + ####################################### # These are auto generated by Ansible # ####################################### @@ -31,6 +38,7 @@ gateway: - account: "api.{{ api_name }}" channel: "api" {% endfor %} + {% if gtw.get("gitter", false) %} - account: "gitter.autobot"