MCPcopy Index your code
hub / github.com/coder/coder / buildPayload

Method buildPayload

coderd/notifications/enqueuer.go:181–213  ·  view source on GitHub ↗

buildPayload creates the payload that the notification will for variable substitution and/or routing. The payload contains information about the recipient, the event that triggered the notification, and any subsequent actions which can be taken by the recipient.

(metadata database.FetchNewMessageMetadataRow, labels map[string]string, data map[string]any, targets []uuid.UUID)

Source from the content-addressed store, hash-verified

179// The payload contains information about the recipient, the event that triggered the notification, and any subsequent
180// actions which can be taken by the recipient.
181func (s *StoreEnqueuer) buildPayload(metadata database.FetchNewMessageMetadataRow, labels map[string]string, data map[string]any, targets []uuid.UUID) (*types.MessagePayload, error) {
182 payload := types.MessagePayload{
183 Version: "1.2",
184
185 NotificationName: metadata.NotificationName,
186 NotificationTemplateID: metadata.NotificationTemplateID.String(),
187
188 UserID: metadata.UserID.String(),
189 UserEmail: metadata.UserEmail,
190 UserName: metadata.UserName,
191 UserUsername: metadata.UserUsername,
192
193 Labels: labels,
194 Data: data,
195 Targets: targets,
196
197 // No actions yet
198 }
199
200 // Execute any templates in actions.
201 out, err := render.GoTemplate(string(metadata.Actions), payload, s.helpers)
202 if err != nil {
203 return nil, xerrors.Errorf("render actions: %w", err)
204 }
205 metadata.Actions = []byte(out)
206
207 var actions []types.TemplateAction
208 if err = json.Unmarshal(metadata.Actions, &actions); err != nil {
209 return nil, xerrors.Errorf("new message metadata: parse template actions: %w", err)
210 }
211 payload.Actions = actions
212 return &payload, nil
213}
214
215// NoopEnqueuer implements the Enqueuer interface but performs a noop.
216type NoopEnqueuer struct{}

Callers 1

EnqueueWithDataMethod · 0.95

Calls 4

GoTemplateFunction · 0.92
StringMethod · 0.45
ErrorfMethod · 0.45
UnmarshalMethod · 0.45

Tested by

no test coverage detected