From 2039b038a55b640013f310a22541f59ad5604534 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Date: Sun, 4 Jan 2026 01:18:21 +0530 Subject: [PATCH 1/2] Refactor webhook configuration and logging - Updated default_options to allow for dynamic webhook URLs and headers. - Improved logging message to reflect the correct context in the run function. - Removed hardcoded authorization headers in favor of configurable headers. This change enhances flexibility in webhook integration and improves code clarity. --- server/links/webhook/__init__.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/server/links/webhook/__init__.py b/server/links/webhook/__init__.py index a40bf52..31ac306 100644 --- a/server/links/webhook/__init__.py +++ b/server/links/webhook/__init__.py @@ -5,10 +5,18 @@ logger = init_logger(__name__) +# Example configuration: +# default_options = { +# "webhook-urls": ["https://your-webhook-endpoint.com"], +# "headers": { +# "Authorization": "Bearer YourToken", +# "x-conserver-api-token": "your-api-token", +# }, +# } + default_options = { - "webhook-urls": ["https://eo91qivu6evxsty.m.pipedream.net"], - "auth_header": "Bearer ThompsonsClamBar", - "api_token": "default-api-token", + "webhook-urls": [], + "headers": {}, } @@ -17,7 +25,7 @@ def run( link_name, opts=default_options, ): - logger.debug("Starting transcribe::run") + logger.debug("Starting webhook::run") vcon_redis = VconRedis() vCon = vcon_redis.get_vcon(vcon_uuid) @@ -25,15 +33,14 @@ def run( # The webhook needs a stringified JSON version. json_dict = vCon.to_dict() + # Build headers from configuration + headers = opts.get("headers", {}) + # Post this to each webhook url for url in opts["webhook-urls"]: logger.info( f"webhook plugin: posting vcon {vcon_uuid} to webhook url: {url}" ) - headers = { - "Authorization": opts.get("auth_header"), - "x-conserver-api-token": opts.get("api_token"), - } resp = requests.post(url, json=json_dict, headers=headers) logger.info( f"webhook plugin response for {vcon_uuid}: {resp.status_code} {resp.text}" From 701f731a170edba5de2b19b55c456eda6889a8c7 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Date: Sun, 4 Jan 2026 16:19:19 +0530 Subject: [PATCH 2/2] Enhance webhook URL validation and logging - Added validation to check for configured webhook URLs before processing. - Improved logging to warn when no webhook URLs are provided, enhancing error handling. This change ensures that the webhook integration behaves more predictably and provides clearer feedback in the logs. --- server/links/webhook/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/links/webhook/__init__.py b/server/links/webhook/__init__.py index 31ac306..16b433c 100644 --- a/server/links/webhook/__init__.py +++ b/server/links/webhook/__init__.py @@ -36,8 +36,16 @@ def run( # Build headers from configuration headers = opts.get("headers", {}) + # Validate webhook URLs are configured + webhook_urls = opts.get("webhook-urls", []) + if not webhook_urls: + logger.warning( + f"webhook plugin: no webhook-urls configured for vcon {vcon_uuid}, skipping" + ) + return vcon_uuid + # Post this to each webhook url - for url in opts["webhook-urls"]: + for url in webhook_urls: logger.info( f"webhook plugin: posting vcon {vcon_uuid} to webhook url: {url}" )