Skip to content

expose aiohttp request to @webhook_trigger functions#842

Merged
craigbarratt merged 3 commits into
custom-components:masterfrom
JayNewstrom:webhook-request-kwarg
May 11, 2026
Merged

expose aiohttp request to @webhook_trigger functions#842
craigbarratt merged 3 commits into
custom-components:masterfrom
JayNewstrom:webhook-request-kwarg

Conversation

@JayNewstrom
Copy link
Copy Markdown
Contributor

Add the underlying aiohttp.web.Request to the kwargs passed to @webhook_trigger user functions (and to the str_expr filter). Lets scripts inspect headers, method, query string, and re-read the raw body via await request.read() -- enabling HMAC signature validation, which previously wasn't possible since only the parsed payload was exposed.

Backward compatible: existing functions that don't declare request are unaffected.

Add the underlying aiohttp.web.Request to the kwargs passed to
@webhook_trigger user functions (and to the str_expr filter). Lets
scripts inspect headers, method, query string, and re-read the raw
body via `await request.read()` -- enabling HMAC signature
validation, which previously wasn't possible since only the parsed
payload was exposed.

Backward compatible: existing functions that don't declare `request`
are unaffected.
@craigbarratt
Copy link
Copy Markdown
Member

Thanks for the PR. Can you also update custom_components/pyscript/stubs/pyscript_builtins.py?

@JayNewstrom
Copy link
Copy Markdown
Contributor Author

Thanks for the review -- updated.

@JayNewstrom
Copy link
Copy Markdown
Contributor Author

The alternative here is to add headers as a map, and raw_payload to kwargs. Less flexible/powerful, but the targeted fields I'd need to do hmac validation for the webhooks. Happy to make the change if you'd prefer.

@JayNewstrom
Copy link
Copy Markdown
Contributor Author

I guess another alternative to solve my use case would be to add params to the webhook trigger annotation for the webhook secret and header name. Given those the validation could happen inside the pyscript code. But maybe that's too involved on the pyscript side.

@craigbarratt craigbarratt merged commit d5f4041 into custom-components:master May 11, 2026
6 checks passed
@craigbarratt
Copy link
Copy Markdown
Member

Thanks for the PR!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants