Skip to content

Commit c79442d

Browse files
authored
Merge pull request #112 from vcon-dev/VCON-255
Refactor webhook configuration and logging
2 parents c08f476 + 701f731 commit c79442d

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

server/links/webhook/__init__.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55

66
logger = init_logger(__name__)
77

8+
# Example configuration:
9+
# default_options = {
10+
# "webhook-urls": ["https://your-webhook-endpoint.com"],
11+
# "headers": {
12+
# "Authorization": "Bearer YourToken",
13+
# "x-conserver-api-token": "your-api-token",
14+
# },
15+
# }
16+
817
default_options = {
9-
"webhook-urls": ["https://eo91qivu6evxsty.m.pipedream.net"],
10-
"auth_header": "Bearer ThompsonsClamBar",
11-
"api_token": "default-api-token",
18+
"webhook-urls": [],
19+
"headers": {},
1220
}
1321

1422

@@ -17,23 +25,30 @@ def run(
1725
link_name,
1826
opts=default_options,
1927
):
20-
logger.debug("Starting transcribe::run")
28+
logger.debug("Starting webhook::run")
2129

2230
vcon_redis = VconRedis()
2331
vCon = vcon_redis.get_vcon(vcon_uuid)
2432

2533
# The webhook needs a stringified JSON version.
2634
json_dict = vCon.to_dict()
2735

36+
# Build headers from configuration
37+
headers = opts.get("headers", {})
38+
39+
# Validate webhook URLs are configured
40+
webhook_urls = opts.get("webhook-urls", [])
41+
if not webhook_urls:
42+
logger.warning(
43+
f"webhook plugin: no webhook-urls configured for vcon {vcon_uuid}, skipping"
44+
)
45+
return vcon_uuid
46+
2847
# Post this to each webhook url
29-
for url in opts["webhook-urls"]:
48+
for url in webhook_urls:
3049
logger.info(
3150
f"webhook plugin: posting vcon {vcon_uuid} to webhook url: {url}"
3251
)
33-
headers = {
34-
"Authorization": opts.get("auth_header"),
35-
"x-conserver-api-token": opts.get("api_token"),
36-
}
3752
resp = requests.post(url, json=json_dict, headers=headers)
3853
logger.info(
3954
f"webhook plugin response for {vcon_uuid}: {resp.status_code} {resp.text}"

0 commit comments

Comments
 (0)