picoclaw/pkg/channels/slack_webhook/init.go

33 lines
757 B
Go
Raw Normal View History

package slackwebhook
import (
"github.com/sipeed/picoclaw/pkg/bus"
"github.com/sipeed/picoclaw/pkg/channels"
"github.com/sipeed/picoclaw/pkg/config"
)
func init() {
channels.RegisterFactory(
config.ChannelSlackWebHook,
func(channelName, channelType string, cfg *config.Config, b *bus.MessageBus) (channels.Channel, error) {
bc := cfg.Channels[channelName]
decoded, err := bc.GetDecoded()
if err != nil {
return nil, err
}
c, ok := decoded.(*config.SlackWebhookSettings)
if !ok {
return nil, channels.ErrSendFailed
}
ch, err := NewSlackWebhookChannel(bc, c, b)
if err != nil {
return nil, err
}
if channelName != config.ChannelSlackWebHook {
ch.SetName(channelName)
}
return ch, nil
},
)
}