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

Method Dispatcher

coderd/notifications/dispatch/smtp.go:62–89  ·  view source on GitHub ↗
(payload types.MessagePayload, titleTmpl, bodyTmpl string, helpers template.FuncMap)

Source from the content-addressed store, hash-verified

60}
61
62func (s *SMTPHandler) Dispatcher(payload types.MessagePayload, titleTmpl, bodyTmpl string, helpers template.FuncMap) (DeliveryFunc, error) {
63 // First render the subject & body into their own discrete strings.
64 subject, err := markdown.PlaintextFromMarkdown(titleTmpl)
65 if err != nil {
66 return nil, xerrors.Errorf("render subject: %w", err)
67 }
68
69 htmlBody := markdown.HTMLFromMarkdown(bodyTmpl)
70 plainBody, err := markdown.PlaintextFromMarkdown(bodyTmpl)
71 if err != nil {
72 return nil, xerrors.Errorf("render plaintext body: %w", err)
73 }
74
75 // Then, reuse these strings in the HTML & plain body templates.
76 payload.Labels["_subject"] = subject
77 payload.Labels["_body"] = htmlBody
78 htmlBody, err = render.GoTemplate(htmlTemplate, payload, helpers)
79 if err != nil {
80 return nil, xerrors.Errorf("render full html template: %w", err)
81 }
82 payload.Labels["_body"] = plainBody
83 plainBody, err = render.GoTemplate(plainTemplate, payload, helpers)
84 if err != nil {
85 return nil, xerrors.Errorf("render full plaintext template: %w", err)
86 }
87
88 return s.dispatch(subject, htmlBody, plainBody, payload.UserEmail), nil
89}
90
91// dispatch returns a DeliveryFunc capable of delivering a notification via SMTP.
92//

Callers 2

TestSMTPFunction · 0.95

Calls 2

dispatchMethod · 0.95
ErrorfMethod · 0.45

Tested by 2

TestSMTPFunction · 0.76