Skip to content

feat(ui): render message action buttons (client::action, #494) - #1088

Open
EinfacheSache wants to merge 4 commits into
gotify:masterfrom
EinfacheSache:feat/action-buttons
Open

EinfacheSache wants to merge 4 commits into
gotify:masterfrom
EinfacheSache:feat/action-buttons

Conversation

@EinfacheSache

@EinfacheSache EinfacheSache commented Nov 17, 2026 •

Copy link
Copy Markdown

Implements the web UI part of #494 using the format from #494 (comment).

"extras": {
  "client::action": {
    "buttons": [
      {"label": "Approve", "http": {"method": "post", "url": "https://example.com/approve?id=5", "headers": {"Authorization": "bearer token"}}}
    ]
  }
}

action buttons

Behavior

  • Buttons are rendered below the message content. A tooltip shows METHOD host.
  • Clicking sends the request with fetch (method, url, headers). The button is disabled while the request runs, and the result is reported in a snackbar (success, HTTP error status, or network/CORS error).
  • method is case-insensitive and defaults to POST. Allowed methods are GET, POST, PUT, PATCH and DELETE.

Safety

  • Only http:/https: URLs are accepted, so javascript:, data: and similar URLs are dropped.
  • credentials: "omit" and referrerPolicy: "no-referrer" are set, so no cookies or Gotify URL leak to the target.
  • Invalid buttons are skipped silently: a missing or empty label, a missing URL, or an unknown method. Non-string header values are dropped.
  • Requests come from the browser, so the target needs to allow CORS (e.g. Access-Control-Allow-Origin and Access-Control-Allow-Headers for custom headers). I'll document this in a docs PR for gotify/website, so other clients (Android, iGotify) can follow the same format.

Tests

  • src/message/extras.test.ts: unit tests for parsing and validation.
  • src/tests/message-actions.test.ts: e2e test with a local HTTP target. It checks that the buttons render, that a click sends the right method, path and header, and that the success and failure snackbars appear.
  • The full UI suite (CI=true yarn test) passes locally, along with tsc, lint and testformat.

I haven't touched the Android client.

Render the HTTP action buttons defined in
extras["client::action"].buttons as proposed in gotify#494.

Clicking a button sends the configured request via fetch (method, url,
headers, body). Only http(s) URLs are accepted, invalid buttons are
skipped and reported in a warning. Cookies are not sent (credentials:
omit) and the result is reported via a snackbar.
@jmattheis

Copy link
Copy Markdown
Member

I've made some changes and:

  • added zod for parsing the object.
  • body param for defining the request body
  • show parsing errors in the message
  • remove POST default (explicit is almost always better)

Could you have a look at it?

@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.65%. Comparing base (01086b9) to head (741ea98).
⚠️ Report is 24 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1088      +/-   ##
==========================================
- Coverage   81.68%   81.65%   -0.04%     
==========================================
  Files          69       69              
  Lines        3260     3260              
==========================================
- Hits         2663     2662       -1     
- Misses        597      598       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

GET/HEAD requests with a body and the methods CONNECT, TRACE and TRACK
make fetch throw before anything is sent. The user saw "network error
or CORS" for these buttons. Report them as parsing errors instead.
A button with `open.url` instead of `http` opens the url in a new tab,
e.g. a status page. Only http(s) urls are allowed, the target is shown
in the tooltip and the tab is opened with noopener/noreferrer.
EinfacheSache added a commit to EinfacheSache/website that referenced this pull request Nov 22, 2026
@EinfacheSache

Copy link
Copy Markdown
Author

Thanks a lot, your changes look good to me. Types, lint, unit and e2e tests pass locally.

I added two commits on top:

  • Reject requests fetch can't send: GET/HEAD with a body and the methods CONNECT/TRACE/TRACK always fail in fetch with a TypeError before anything is sent. The user saw "network error or CORS" for these. They're now reported as parsing errors like other invalid buttons.
  • Buttons that open a URL: {"label": "Status page", "open": {"url": "https://status.example.com"}} opens the URL in a new tab instead of sending a request. It's useful for "service X is down → open status page", which the web UI can't do today (it doesn't support client::notification.click.url). It's a separate commit, so if you'd rather discuss the format first or have it in its own PR, I'll drop it.

I've updated the docs in gotify/website#108 to match (method required, body, open).

@jmattheis

Copy link
Copy Markdown
Member

The extra validation is okay, but please remove the open URL thingy. This should be already covered by a normal markdown link, therefore I don't want to include this right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants