|
package slack |
|
|
|
import ( |
|
"fmt" |
|
"net/url" |
|
"strings" |
|
"text/template" |
|
|
|
"github.com/google/uuid" |
|
"github.com/slack-go/slack/slackutilsx" |
|
"github.com/target/goalert/notification" |
|
) |
|
|
|
|
|
type userGroupError struct { |
|
ErrorID uuid.UUID |
|
GroupID string |
|
ScheduleID string |
|
ScheduleName string |
|
Missing []notification.User |
|
|
|
callbackFunc func(string, ...url.Values) string |
|
} |
|
|
|
|
|
func (e userGroupError) ErrorRef() string { |
|
return fmt.Sprintf("`SlackUGErrorID=%s`", e.ErrorID.String()) |
|
} |
|
|
|
|
|
func (e userGroupError) GroupRef() string { |
|
return fmt.Sprintf("<!subteam^%s>", e.GroupID) |
|
} |
|
|
|
|
|
func (e userGroupError) MissingUserRefs() string { |
|
var refs []string |
|
for _, u := range e.Missing { |
|
urlStr := e.callbackFunc(fmt.Sprintf("users/%s", url.PathEscape(u.ID))) |
|
refs = append(refs, slackLink(urlStr, u.Name)) |
|
} |
|
return strings.Join(refs, ", ") |
|
} |
|
|
|
|
|
func (e userGroupError) ScheduleRef() string { |
|
urlStr := e.callbackFunc(fmt.Sprintf("schedules/%s", url.PathEscape(e.ScheduleID))) |
|
return slackLink(urlStr, e.ScheduleName) |
|
} |
|
|
|
|
|
func slackLink(url, label string) string { |
|
return fmt.Sprintf("<%s|%s>", slackutilsx.EscapeMessage(url), slackutilsx.EscapeMessage(label)) |
|
} |
|
|
|
|
|
var userGroupErrorMissing = template.Must(template.New("userGroupErrorMissing").Parse(`Hey everyone! I couldn't update {{.GroupRef}} because I couldn't find the following user(s) in Slack: {{.MissingUserRefs}} |
|
|
|
If you could have them add a SLACK_DM contact method from their respective GoAlert profile page(s), that would be great! Hopefully I'll be able to update the user-group next time.`)) |
|
|
|
|
|
var userGroupErrorEmpty = template.Must(template.New("userGroupErrorEmpty").Parse(`Hey everyone! I couldn't update {{.GroupRef}} because there is nobody on-call for {{.ScheduleRef}}. |
|
|
|
Since a Slack user-group cannot be empty, I'm going to leave it as-is for now.`)) |
|
|
|
|
|
var userGroupErrorUpdate = template.Must(template.New("userGroupErrorUpdate").Parse(`Hey everyone! I couldn't update {{.GroupRef}} because I ran into a problem. Maybe touch base with the GoAlert admin(s) to see if they can help? I'm sorry for the inconvenience! |
|
|
|
Here's the ID I left with the error in my logs so they can find it: |
|
{{.ErrorRef}}`)) |
|
|