diff --git a/docs/msgextras.md b/docs/msgextras.md index 92e01d7..7e8151b 100644 --- a/docs/msgextras.md +++ b/docs/msgextras.md @@ -13,6 +13,7 @@ Some of the namespaces are used by official clients: | `client::*` | Reserved | | [`client::display`](#clientdisplay) | Changes how client displays information | | [`client::notification`](#clientnotification) | Customizes the notification | +| [`client::action`](#clientaction) | Adds action buttons to the message | | `android::*` | Reserved | | [`android::action`](#androidaction) | React to events | | `ios::*` | Reserved | @@ -106,6 +107,71 @@ Some of the namespaces are used by official clients: | -------------- | ------ | --------------------------------------------------------------------------------------------------------------------- | | gotify/android | v2.3.0 | You may have to expand the notification. Added with [gotify/android#200](https://github.com/gotify/android/pull/200). | +## `client::action` + +### `buttons` + +`buttons` (array): Buttons shown with the message. A button sends an HTTP request when it is clicked. + +| Field | Type | Description | +| ---------------- | ------ | ------------------------------------------------------------------------------------------------ | +| `label` | string | **Required**; The text of the button. | +| `http` | object | **Required**; The HTTP request sent when the button is clicked. | +| `http`.`method` | string | **Required**; The HTTP method, e.g. `GET`, `POST` or `PUT`, case-insensitive. | +| `http`.`url` | string | **Required**; The URL of the request. Only `http` and `https` URLs are valid. | +| `http`.`headers` | object | Headers of the request, a map of header name to string value. | +| `http`.`body` | string | The body of the request. Set a matching `Content-Type` header. Not allowed for `GET` and `HEAD`. | + +Clients should not send cookies or other credentials with the request. +The methods `CONNECT`, `TRACE` and `TRACK` are not supported. +The web UI doesn't show invalid buttons and shows the parsing error below the message instead. + +> **Note**: Anyone who can send messages to an application can make the user's client send requests +> to any URL by adding buttons. Clients therefore only send the request after the user clicked the button, +> and should show the target of the request (e.g. as a tooltip). +> +> The web UI sends the request from the browser, so the target must allow +> [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) requests from the Gotify origin, +> including the `Access-Control-Allow-Headers` for custom headers. + +#### Example + +```json +{ + "title": "home assistant", + "message": "You've left the house but the heater is still powered on.", + "extras": { + "client::action": { + "buttons": [ + { + "label": "Power off", + "http": { + "method": "post", + "url": "https://example.com/power_off?id=5", + "headers": {"Authorization": "bearer token"} + } + }, + { + "label": "Dismiss", + "http": { + "method": "post", + "url": "https://example.com/dismiss", + "headers": {"Content-Type": "application/json"}, + "body": "{\"id\": 5}" + } + } + ] + } + } +} +``` + +#### Support + +| Client | since | description | +| ---------------- | ----- | -------------------------------------------------------------------------------------------------- | +| gotify/server ui | TBD | Added with [gotify/server#1088](https://github.com/gotify/server/pull/1088). Requests via `fetch`. | + ## `android::action` ### `onReceive`.`intentUrl`