forked from molecule-ai/molecule-core
Implement SlackAdapter satisfying the ChannelAdapter interface: - ValidateConfig: rejects any webhook_url that doesn't start with https://hooks.slack.com/ — returns "invalid Slack webhook URL" so the handler surfaces 400 {"error":"invalid config: invalid Slack webhook URL"} - SendMessage: HTTP POST JSON {"text":"..."} to the webhook URL with a 10s timeout; rejects invalid-prefix URLs at send time too (defence in depth) - ParseWebhook: handles both slash-command (form-encoded) and Events API (JSON) payloads; no-ops on url_verification and non-message events - StartPolling: returns nil immediately (Slack doesn't support polling via Incoming Webhooks) Register "slack" in the adapter registry. Twelve unit tests cover Type/DisplayName, happy-path validation, every bad-URL variant (wrong scheme, wrong host, SSRF lookalike, empty string), empty webhook in SendMessage, StartPolling nil return, and registry lookup/listing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
27 lines
729 B
Go
27 lines
729 B
Go
package channels
|
|
|
|
// Registry of all available channel adapters.
|
|
// To add a new platform: implement ChannelAdapter, register here.
|
|
var adapters = map[string]ChannelAdapter{
|
|
"telegram": &TelegramAdapter{},
|
|
"slack": &SlackAdapter{},
|
|
}
|
|
|
|
// GetAdapter returns the adapter for a channel type.
|
|
func GetAdapter(channelType string) (ChannelAdapter, bool) {
|
|
a, ok := adapters[channelType]
|
|
return a, ok
|
|
}
|
|
|
|
// ListAdapters returns metadata about all available adapters.
|
|
func ListAdapters() []map[string]string {
|
|
result := make([]map[string]string, 0, len(adapters))
|
|
for _, a := range adapters {
|
|
result = append(result, map[string]string{
|
|
"type": a.Type(),
|
|
"display_name": a.DisplayName(),
|
|
})
|
|
}
|
|
return result
|
|
}
|