File size: 1,576 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package alert

import (
	"context"

	"github.com/target/goalert/notification/nfydest"
	"github.com/target/goalert/validation"
)

const (
	DestTypeAlert = "builtin-alert"

	ParamSummary = "summary"
	ParamDetails = "details"
	ParamDedup   = "dedup"
	ParamClose   = "close"

	FallbackIconURL = "builtin://alert"
)

var _ nfydest.Provider = (*Store)(nil)

func (s *Store) ID() string { return DestTypeAlert }
func (s *Store) TypeInfo(ctx context.Context) (*nfydest.TypeInfo, error) {
	return &nfydest.TypeInfo{
		Type:            DestTypeAlert,
		Name:            "Alert",
		Enabled:         true,
		SupportsSignals: true,
		DynamicParams: []nfydest.DynamicParamConfig{{
			ParamID: ParamSummary,
			Label:   "Summary",
			Hint:    "Short summary of the alert (used for things like SMS).",
		}, {
			ParamID: ParamDetails,
			Label:   "Details",
			Hint:    "Full body (markdown) text of the alert.",
		}, {
			ParamID: ParamDedup,
			Label:   "Dedup",
			Hint:    "Stable identifier for de-duplication and closing existing alerts.",
		}, {
			ParamID: ParamClose,
			Label:   "Close",
			Hint:    "If true, close an existing alert.",
		}},
	}, nil
}

func (s *Store) DisplayInfo(ctx context.Context, args map[string]string) (*nfydest.DisplayInfo, error) {
	return &nfydest.DisplayInfo{
		IconURL:     FallbackIconURL,
		IconAltText: "Alert",
		Text:        "Create new alert",
	}, nil
}

func (s *Store) ValidateField(ctx context.Context, fieldID, value string) error {
	// Alert destination has no valid required fields.
	return validation.NewGenericError("unknown field ID")
}