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)
| 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. |
| 181 | func (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. |
| 216 | type NoopEnqueuer struct{} |
no test coverage detected