default button name
This commit is contained in:
11
README.md
11
README.md
@@ -62,6 +62,7 @@ It's designed to be run as a Docker container and integrated with Traefik v3 for
|
||||
* `VAPID_SUBJECT`: A `mailto:` or `https:` URL identifying you or your application (e.g., `mailto:admin@yourdomain.com`). Used by push services to contact you.
|
||||
* `PORT`: (Default: `3000`) The internal port the Node.js app listens on. Traefik will map to this.
|
||||
* `SUBSCRIPTIONS_FILE`: (Default: `/app/subscriptions.json`) The path *inside the container* where the button-to-subscription mapping is stored.
|
||||
* `DEFAULT_BUTTON_NAME`: (Default: `game-button`) The default button name to use when the `Button-Name` header is not provided in the webhook request.
|
||||
* `BASIC_AUTH_USERNAME`: (Optional) Username for Basic Authentication. If set along with `BASIC_AUTH_PASSWORD`, authentication will be enabled for `/webhook` and `/subscribe`.
|
||||
* `BASIC_AUTH_PASSWORD`: (Optional) Password for Basic Authentication. If set along with `BASIC_AUTH_USERNAME`, authentication will be enabled.
|
||||
* `ALLOWED_ORIGINS`: Comma-separated list of domains allowed by CORS. Include your PWA's domain if it needs to interact directly (e.g., for setup). Example: `https://my-pwa.com`.
|
||||
@@ -150,11 +151,11 @@ In your Flic app or Flic Hub SDK interface:
|
||||
* **Description:** Adds or updates the Web Push subscription associated with a specific Flic button ID.
|
||||
* **Authentication:** Optional Basic Authentication via `Authorization` header if `BASIC_AUTH_USERNAME` and `BASIC_AUTH_PASSWORD` are configured.
|
||||
* **Request Body:** JSON object containing:
|
||||
* `button_id` (string, required): The unique identifier for the Flic button (lowercase recommended, e.g., "game", "lights").
|
||||
* `button_id` (string, optional): The unique identifier for the Flic button (lowercase recommended, e.g., "game-button", "lights-button"). If not provided, the value of `DEFAULT_BUTTON_NAME` environment variable will be used as a fallback.
|
||||
* `subscription` (object, required): The [PushSubscription object](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription) obtained from the browser's Push API.
|
||||
```json
|
||||
{
|
||||
"button_id": "game",
|
||||
"button_id": "game-button", // Optional, defaults to DEFAULT_BUTTON_NAME environment variable
|
||||
"subscription": {
|
||||
"endpoint": "https://your_pwa_push_endpoint...",
|
||||
"expirationTime": null,
|
||||
@@ -167,7 +168,7 @@ In your Flic app or Flic Hub SDK interface:
|
||||
```
|
||||
* **Responses:**
|
||||
* `201 Created`: Subscription saved successfully.
|
||||
* `400 Bad Request`: Missing or invalid `button_id` or `subscription` object in the request body.
|
||||
* `400 Bad Request`: Missing or invalid `subscription` object in the request body.
|
||||
* `401 Unauthorized`: Missing or invalid Basic Authentication credentials (if authentication is enabled).
|
||||
* `500 Internal Server Error`: Failed to save the subscription to the file.
|
||||
|
||||
@@ -177,7 +178,7 @@ In your Flic app or Flic Hub SDK interface:
|
||||
* **URL Parameters:**
|
||||
* `click_type` (required): The type of button press (e.g., `SingleClick`, `DoubleClick`, or `Hold`).
|
||||
* **Required Headers:**
|
||||
* `Button-Name` (required): The identifier of the Flic button (sent by the Flic system).
|
||||
* `Button-Name`: The identifier of the Flic button (sent by the Flic system). If not provided, the value of `DEFAULT_BUTTON_NAME` environment variable will be used as a fallback.
|
||||
* **Optional Headers:**
|
||||
* `Timestamp`: Timestamp of the button event (sent by the Flic system).
|
||||
* `Button-Battery-Level`: The battery level percentage of the button (sent by the Flic system).
|
||||
@@ -202,7 +203,7 @@ In your Flic app or Flic Hub SDK interface:
|
||||
|
||||
Once your service is up and running, you can test the webhook endpoint using curl or any API testing tool. This example assumes Basic Authentication is enabled.
|
||||
|
||||
**Note:** Replace `<username>`, `<password>`, `<your_domain>`, and `<button_name>` with your actual values.
|
||||
**Note:** Replace `<username>`, `<password>`, `<your_domain>`, and `<button_name>` with your actual values. The `Button-Name` header is optional and will default to the value of `DEFAULT_BUTTON_NAME` if not provided.
|
||||
|
||||
```bash
|
||||
# Generate Base64 credentials (run this once)
|
||||
|
||||
Reference in New Issue
Block a user