Open ntfy notifications in the app and notify chats that need the operator
Run notifications now always click through to pipelines://run/<id>; a valid PIPELINES_WEB_PUBLIC_URL adds an "Open in browser" ntfy view action instead of replacing the click. Queued rows derive links from the run id at delivery, so legacy rows holding a web URL still open the app. Unresolved chat questions/forms and permission requests publish one async, bounded notification to the system destination (pipelines://chat/<id> plus the browser action), deduplicated per form/request id across reconnects and replays. stage.PublishNtfy gains optional, strictly validated view actions. Server tests now clear the operator's real ntfy environment.
This commit is contained in:
+30
-19
@@ -73,7 +73,7 @@ func (r *runner) notifyStep(id int64, name, workspace string, policy *protocol.N
|
||||
return
|
||||
}
|
||||
receipt := &receipts[len(receipts)-1]
|
||||
result, err := stage.PublishNtfy(ctx, "system", title, summary, filename, data, runAttentionClick(id))
|
||||
result, err := stage.PublishNtfy(ctx, "system", title, summary, filename, data, runAttentionClick(id), runAttentionViews(id)...)
|
||||
if err != nil {
|
||||
receipt.Status = "failed"
|
||||
receipt.Diagnostic = err.Error()
|
||||
@@ -294,21 +294,34 @@ func (r *runner) forgetAttention(id int64) {
|
||||
delete(r.attentionSent, id)
|
||||
}
|
||||
|
||||
// Prefer the operator's authenticated web origin. Never infer a public address
|
||||
// from a request Host, the unauthenticated API listener or the ntfy server URL.
|
||||
// Older Android-only installations retain their deep link until configured.
|
||||
// runAttentionClick is the notification tap target for a run: always the native
|
||||
// app deep link, so a tap on the phone opens the Pipelines app.
|
||||
func runAttentionClick(id int64) string {
|
||||
if raw := os.Getenv("PIPELINES_WEB_PUBLIC_URL"); raw != "" {
|
||||
base := publicNtfyBase(raw)
|
||||
if base == "" {
|
||||
log.Printf("notification web link unavailable: PIPELINES_WEB_PUBLIC_URL must be an HTTP(S) origin without credentials, query or fragment")
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%s/runs/%d", base, id)
|
||||
}
|
||||
return fmt.Sprintf("pipelines://run/%d", id)
|
||||
}
|
||||
|
||||
// runAttentionViews is the optional "Open in browser" action for a run.
|
||||
func runAttentionViews(id int64) []stage.NtfyView {
|
||||
return webAttentionViews(fmt.Sprintf("/runs/%d", id))
|
||||
}
|
||||
|
||||
// webAttentionViews returns an "Open in browser" ntfy action for path on the
|
||||
// operator's authenticated web origin, or nothing when none is configured.
|
||||
// Never infer a public address from a request Host, the unauthenticated API
|
||||
// listener or the ntfy server URL.
|
||||
func webAttentionViews(path string) []stage.NtfyView {
|
||||
raw := os.Getenv("PIPELINES_WEB_PUBLIC_URL")
|
||||
if raw == "" {
|
||||
return nil
|
||||
}
|
||||
base := publicNtfyBase(raw)
|
||||
if base == "" {
|
||||
log.Printf("notification web link unavailable: PIPELINES_WEB_PUBLIC_URL must be an HTTP(S) origin without credentials, query or fragment")
|
||||
return nil
|
||||
}
|
||||
return []stage.NtfyView{{Label: "Open in browser", URL: base + path}}
|
||||
}
|
||||
|
||||
// notifyRun publishes one run-level attention notification to the operator's
|
||||
// already-configured "system" destination. It is the run counterpart of
|
||||
// notifyStep and reuses the same PublishNtfy machinery, destination and token
|
||||
@@ -386,14 +399,12 @@ func (r *runner) deliverRunNotificationBatch(now time.Time, limit int) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
// State transitions enqueue their intent inside the store transaction,
|
||||
// before notifyRun can supply a server-configured URL. Resolve that
|
||||
// legacy placeholder here too, including pending intents after restart.
|
||||
if os.Getenv("PIPELINES_WEB_PUBLIC_URL") != "" && n.Click == fmt.Sprintf("pipelines://run/%d", n.RunID) {
|
||||
n.Click = runAttentionClick(n.RunID)
|
||||
}
|
||||
// Links are derived from the run id at delivery, not from the stored
|
||||
// click: rows queued by older servers may hold a web URL (or nothing),
|
||||
// and the web origin is server configuration that can change.
|
||||
n.Click = runAttentionClick(n.RunID)
|
||||
ctx, cancel := context.WithTimeout(r.ctx, 30*time.Second)
|
||||
result, publishErr := stage.PublishNtfy(ctx, n.Channel, n.Title, n.Body, "", nil, n.Click)
|
||||
result, publishErr := stage.PublishNtfy(ctx, n.Channel, n.Title, n.Body, "", nil, n.Click, runAttentionViews(n.RunID)...)
|
||||
cancel()
|
||||
messageID, _ := result["message_id"].(string)
|
||||
save, done := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
|
||||
Reference in New Issue
Block a user