Add alerts, currency conversion and notifications.

Items fire when a page is available from an accepted seller at or below
max_price, converted with the ECB's daily rates when the page uses
another currency. A per-item cooldown, kept in the state file, holds
back repeat alerts unless the price drops. Alerts go to Discord, ntfy
and JSON webhooks with retries, and to the desktop;
'dibs notify test' sends a sample.
This commit is contained in:
Overlord committed 2026-10-14 11:55:27 +02:00
1 parent 2175c0e5aa
commit 8f0eda5d4d
16 files changed
+1409 -15

No files matched your search

+86
View File
@@ -0,0 +1,86 @@
package notify
import (
"time"
"git.security-command.org/Overlord/dibs/internal/alert"
)
// PayloadVersion changes only when a field is removed or changes meaning.
// New fields may appear in any version.
const PayloadVersion = 1
// Payload is the body of a "json" webhook, POSTed as application/json.
//
// {
// "version": 1,
// "test": false,
// "item": "Metro 2039 CE",
// "shop": "amazon",
// "url": "https://www.amazon.de/dp/B0HMX2FSTF",
// "title": "Metro 2039 Collector's Edition (PS5)",
// "price": 129.99,
// "currency": "EUR",
// "converted_price": null,
// "converted_currency": null,
// "previous_price": null,
// "previous_currency": null,
// "seller": "first_party",
// "cart_link": "https://www.amazon.de/gp/aws/cart/add.html?ASIN.1=B0HMX2FSTF&Quantity.1=1",
// "time": "2026-10-14T09:30:00Z"
// }
//
// Every key is always present; values that do not apply are null.
type Payload struct {
Version int `json:"version"`
// Test is true for the sample alert of `dibs notify test`.
Test bool `json:"test"`
Item string `json:"item"`
Shop string `json:"shop"`
// URL is the product page.
URL string `json:"url"`
Title *string `json:"title"`
// Price is null when the page shows none, which only fires items without
// max_price.
Price *float64 `json:"price"`
Currency *string `json:"currency"`
// ConvertedPrice is the price in the item's currency, when the page uses
// another one.
ConvertedPrice *float64 `json:"converted_price"`
ConvertedCurrency *string `json:"converted_currency"`
// PreviousPrice is set when the item fires again during its cooldown
// because the price dropped below the previous alert's.
PreviousPrice *float64 `json:"previous_price"`
PreviousCurrency *string `json:"previous_currency"`
// Seller is "first_party", "fulfilled", "third_party" or "unknown".
Seller string `json:"seller"`
CartLink *string `json:"cart_link"`
// Time is when the page was checked, in UTC.
Time time.Time `json:"time"`
}
func NewPayload(a alert.Alert) Payload {
return Payload{
Version: PayloadVersion,
Test: a.Test,
Item: a.Item,
Shop: a.Shop,
URL: a.URL,
Title: orNull(a.Title),
Price: a.Price,
Currency: orNull(a.Currency),
ConvertedPrice: a.Converted,
ConvertedCurrency: orNull(a.ConvertedCurrency),
PreviousPrice: a.PreviousPrice,
PreviousCurrency: orNull(a.PreviousCurrency),
Seller: a.Seller,
CartLink: orNull(a.CartLink),
Time: a.Time.UTC().Truncate(time.Second),
}
}
func orNull(s string) *string {
if s == "" { return nil }
return &s
}