Generate random webhook_id and add copy button#11568
Generate random webhook_id and add copy button#11568bramkragten merged 23 commits intohome-assistant:devfrom
Conversation
|
@esev Nice! And nicely isolated from other changes proposed in #56446. I've reviewed the existing doc, and while the changes in this PR don't require doc changes, I'm proposing some revisions to better set up for other possible (hopeful!) changes for webhooks. I'll add details that align with this PR, without requiring it to be submitted first. Doc PR here: home-assistant/home-assistant.io#21506 |
| import { mdiContentCopy } from "@mdi/js"; | ||
| import { html, LitElement } from "lit"; | ||
| import { customElement, property } from "lit/decorators"; | ||
| import { PaperInputElement } from "@polymer/paper-input/paper-input"; |
There was a problem hiding this comment.
| import { PaperInputElement } from "@polymer/paper-input/paper-input"; | |
| import type { PaperInputElement } from "@polymer/paper-input/paper-input"; |
src/panels/config/automation/trigger/types/ha-automation-trigger-webhook.ts
Show resolved
Hide resolved
src/panels/config/automation/trigger/types/ha-automation-trigger-webhook.ts
Outdated
Show resolved
Hide resolved
src/panels/config/automation/trigger/types/ha-automation-trigger-webhook.ts
Show resolved
Hide resolved
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
src/panels/config/automation/trigger/types/ha-automation-trigger-webhook.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Zack Barett <zackbarett@hey.com>
src/panels/config/automation/trigger/types/ha-automation-trigger-webhook.ts
Show resolved
Hide resolved
src/panels/config/automation/trigger/types/ha-automation-trigger-webhook.ts
Outdated
Show resolved
Hide resolved
| if (webhookId === DEFAULT_WEBHOOK_ID) { | ||
| webhookId = this._generateWebhookId(); | ||
| const newTrigger = { ...this.trigger, webhook_id: webhookId }; | ||
| fireEvent(this, "value-changed", { value: newTrigger }); |
There was a problem hiding this comment.
the render method cannot have side effects. Do this in willUpdate instead.
There was a problem hiding this comment.
Thanks for this. That helped clean this up in 43d6c49.
| import { HomeAssistant } from "../../../../../types"; | ||
| import { handleChangeEvent } from "../ha-automation-trigger-row"; | ||
|
|
||
| const DEFAULT_WEBHOOK_ID = "default webhook id"; |
There was a problem hiding this comment.
Why not make this an empty string ?
There was a problem hiding this comment.
It is now. The (incorrect) way I was doing it before in render caused clearing the textfield contents to regenerate the ID. Probably not what the user wanted. Your suggestion to use willUpdate made this a lot simpler. Thanks!
src/panels/config/automation/trigger/types/ha-automation-trigger-webhook.ts
Outdated
Show resolved
Hide resolved
| .path=${mdiContentCopy} | ||
| ></ha-icon-button> | ||
| </paper-input> | ||
| <div class="helper-text"> |
There was a problem hiding this comment.
Use ha-textfield isntead of paper-input and you will be able to use the built-in helper text property. https://github.com/material-components/material-web/tree/master/packages/textfield#helper-text
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
src/panels/config/automation/trigger/types/ha-automation-trigger-webhook.ts
Show resolved
Hide resolved
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
|
Enabled design preview so it's easy to see how it will look: https://6202ebd9de68c100648f18de--home-assistant-gallery.netlify.app/#automation/editor-trigger (to try in local development: I think that we need to add a |
|
Will handle the margin globally |

Proposed change
Webhooks IDs are a little like passwords in that it is safest if they are not guessable by others. This PR attempts to keep users safe by default by auto-generating the webhook_id when a new webhook trigger is created. I've also added a copy-to-clipboard button for the webhook URL to encourage use of the default value by making it the simplest action.
Users still have the ability to override the default, randomly generated, webhook_id if they desire to do so. This PR adds the text "Treat this ID like a password: keep it secret, and make it hard to guess", so users are aware of the safest way to generate their own webhook_ids.
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: