Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions server/links/webhook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
}


Expand All @@ -17,23 +25,30 @@ 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)

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

# 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}"
)
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}"
Expand Down