picoclaw/pkg/channels/matrix/init.go

39 lines
919 B
Go
Raw Normal View History

2026-03-07 17:44:24 +00:00
package matrix
import (
"path/filepath"
2026-03-07 17:44:24 +00:00
"github.com/sipeed/picoclaw/pkg/bus"
"github.com/sipeed/picoclaw/pkg/channels"
"github.com/sipeed/picoclaw/pkg/config"
)
func init() {
channels.RegisterFactory(
config.ChannelMatrix,
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.MatrixSettings)
if !ok {
return nil, channels.ErrSendFailed
}
cryptoDatabasePath := c.CryptoDatabasePath
if cryptoDatabasePath == "" {
cryptoDatabasePath = filepath.Join(cfg.WorkspacePath(), "matrix")
}
ch, err := NewMatrixChannel(bc, c, b, cryptoDatabasePath)
if err != nil {
return nil, err
}
if channelName != config.ChannelMatrix {
ch.SetName(channelName)
}
return ch, nil
},
)
2026-03-07 17:44:24 +00:00
}