ValidateSlackWebhookURL validates the URL matches the expected Slack webhook URL format as defined by https://docs.slack.dev/messaging/sending-messages-using-incoming-webhooks/ Ex. "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
(webhookURL string)
| 30 | // https://docs.slack.dev/messaging/sending-messages-using-incoming-webhooks/ |
| 31 | // Ex. "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX" |
| 32 | func ValidateSlackWebhookURL(webhookURL string) error { |
| 33 | u, err := url.Parse(webhookURL) |
| 34 | if err != nil { |
| 35 | return err |
| 36 | } |
| 37 | |
| 38 | if u.Scheme != "https" || |
| 39 | u.Host != "hooks.slack.com" || |
| 40 | !strings.HasPrefix(u.Path, "/services/") { |
| 41 | return ErrInvalidSlackWebhookURL |
| 42 | } |
| 43 | |
| 44 | return nil |
| 45 | } |