@sedge-hq/web
v0.3.1
Published
Web pages, values, feeds and live streams for sedge: tell me when this page or price changes, something new is posted, or a stream pushes a message.
Maintainers
Readme
@sedge-hq/web
The web for sedge, the always-on agent. Four signals:
web-page: a page whose text changes (a status page, release notes), with what was added; optionally only when it mentions something.web-value: one value on a page or from an API (a price, a stock count, a status), or several named ones, reported when it changes; and the site going down and coming back.feed: new posts on an RSS or Atom feed (a blog, releases, a forum).stream: messages pushed over server-sent events or a WebSocket (ntfy, Gotify, Home Assistant, any live feed), each one an event.
In sedge, say "tell me when the Bun release notes change", "tell me when this kettle drops
under £50", "tell me about new posts on this blog" or "wake me for urgent ntfy messages on my
alerts topic".
web-page and feed
Both learn what's there first and report only what's new. Settings: url, and minutes between
looks (default 15 for a page, 30 for a feed); web-page also takes contains, to stay quiet
until the changed page mentions it. Details: url (and for a page, the lines removed).
web-value
It reads the page or API every minutes (default 10), learns the value on the first look, and
reports each change with the value before and after.
selectpicks the value: a CSS selector on a page (.price,#stock,#stock li:nth-child(2)), with@attributeto read an attribute instead of the text (meta[itemprop="price"]@content); or a path into JSON (data.price,items[0].name,rates["EUR"]). Left out, it's the whole JSON answer, or the page's text.fieldsreads several values at once, each asname = selector or path(price = .price,stock = .availability), and reports the ones that changed together.method,bodyandheadersmake it an API call: abodyis POSTed (JSON getsContent-Type: application/json), so a GraphQL query is{"query": "{ … }"}. Headers areName: value.tokengoes to your keychain and is sent asAuthorization: Bearer <token>, or wherever{token}appears in the address, a header or the body instead (X-Api-Key: {token}).account, instead oftoken: an account you signed in to with sedge, with any OAuth provider, your own included (see Signing in). Its current token is used the same way.failures(default 3): after that many failed looks in a row (an error, a timeout, a selector that matches nothing) it reports the sitedown, once, andupwhen it answers again.0turns this off.
Text that is plainly a number is read as one: $1,299.00, 12,99 €, 1 299,50 and 45%
become 1299, 12.99, 1299.5 and 45; 1.2k or 3 left stay text. So a condition like
value < 500 works on a price.
Details: event (changed, down or up), url, value (the new value, or an object of the
fields), previous, and for fields changed (their names); down has error and failures,
up has downFor (minutes).
Pages are read as HTML, without running their scripts: a value a page only fills in with
JavaScript isn't there to read. Its API usually is; point web-value at that instead.
stream
It connects to url and keeps the connection, reconnecting with backoff (1 second up to 5
minutes, or what the server asks) when it drops.
- An
https://address must answer withtext/event-stream(server-sent events). It sendsLast-Event-IDwhen it reconnects, also after a restart, so a server that keeps events sends what was missed. - A
ws://orwss://address is a WebSocket.sendlists messages to send once connected, in order;{token}in them stands for the token. headersandtokenwork as forweb-value.skipdrops messages whose SSE event, or JSONeventortype, is one of these (defaultkeepalive,ping,pong,heartbeat,open,auth_required,auth_ok).
Details: url, event (the SSE event's name, when it has one), id (the SSE id), and data
(JSON as values, text otherwise), so data.priority >= 4 picks urgent ntfy messages.
- ntfy:
https://ntfy.sh/<topic>/sse. - Gotify:
wss://<server>/stream?token={token}, with the client token astoken. - Home Assistant:
wss://<home>/api/websocket, a long-lived access token astoken, andsend{"type": "auth", "access_token": "{token}"}then{"id": 1, "type": "subscribe_events", "event_type": "state_changed"}. Add the conditiondata.type = eventso only events wake sedge.
Signing in
Every signal here takes an optional account: the name of an account you signed in to in the
browser, with any OAuth 2 provider, your own included
(Accounts).
Each request carries its current token as Authorization: Bearer <token> (or where {token}
appears, for web-value and stream), and sedge renews it when it's due. Give a token or an
account, not both. A 401 tells sedge the token was refused, so accounts can say to sign in
again.
Channels and signals · MIT
