feat(api): add webhook and telegram actions - #143
Open
arminfauland wants to merge 1 commit into
Open
Conversation
Scrape Dojo could not talk to the outside world during a run. The `notify` action reaches an open browser tab only, which is fine while you are watching the UI but useless for scheduled scrapes — nobody sees a modal at 07:00. Adds two actions and a shared helper: - `webhook` — send an HTTP request to any URL. Methods, headers, JSON or raw bodies, timeout, retries with exponential backoff. - `telegram` — send a Telegram message via a bot. A thin layer over the same helper, so retries and timeouts behave identically. - `_helpers/http-request.helper.ts` — the shared request logic. Details worth knowing: - Only transient failures are retried (network errors, timeouts, 408/429/5xx). A 400 or 404 is not retried — repeating a malformed request does not make it valid. - Credentials are kept out of the log. Header values are never logged, query strings are stripped, and the Telegram bot token in the URL path is masked as `bot•••`. Two tests assert this. - Failures are non-fatal by default: a missed notification should not throw away an otherwise successful scrape. `failOnError: true` opts into the stricter behaviour. - Telegram answers HTTP 200 with `ok: false` for rejected messages, e.g. on malformed MarkdownV2. That is treated as a failure rather than silently swallowed. - Messages longer than 4096 characters are truncated, since Telegram rejects them outright. Includes 30 tests and documentation in EN and DE. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LixHBPkhb8h5oDdMqSG4se
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
Scrape Dojo currently has no way to reach the outside world during a run. The
notifyaction sends to an open browser tab, which works while you are watching the UI — but a scheduled scrape at 07:00 has nobody watching. There is also no generic HTTP action at all, so there is no workaround either.This adds two actions and the shared helper behind them:
webhooktelegram_helpers/http-request.helper.tsDecisions worth reviewing
Only transient failures are retried — network errors, timeouts, and
408/429/500/502/503/504. A400or404is not retried, because repeating a malformed request does not make it valid.Credentials stay out of the log. Header values are never logged, query strings are stripped, and the Telegram bot token in the URL path is masked as
bot•••. Two tests assert this explicitly.Failures are non-fatal by default. A missed notification should not discard an otherwise successful scrape.
failOnError: trueopts into the stricter behaviour. I am happy to flip the default if you would rather have it the other way round.Telegram answers
200withok: falsefor rejected messages — malformed MarkdownV2 is the usual cause. That is treated as a failure rather than silently swallowed.Messages over 4096 characters are truncated, since Telegram rejects them outright. A warning goes to the log when it happens.
Testing
nx lint apicleanDocumentation
apps/docsin EN and DE, plus both overview tables. Includes a short "how to get a bot token" section fortelegram, since that is the first hurdle for self-hosters.The README does not list actions, so nothing to change there.
config/scrapes.schema.jsontypesactionas a free-form string rather than an enum, so no schema change is needed either — andpnpm create:schemacurrently fails on 472 pre-existing type errors in spec files onmain, which I have deliberately left alone.Why this shape
I built the generic
webhookaction first and madetelegrama thin layer on top, rather than writing a Telegram-specific action. That way the useful part stands on its own even if you would rather not carry a vendor-specific action — feel free to droptelegram.action.tsand keep the rest.Follow-up I would like to offer
The case that actually motivated this is
waitForOtp: when Amazon asks for a verification code, the prompt only appears in the UI and the action times out after 120 seconds. For an unattended run that means it fails silently. A follow-up PR could forward notifications and OTP requests to an outbound channel via environment variables, so the OTP prompt reaches the user wherever they are — without any config change per scrape. Happy to open that separately if the idea appeals.