2025-12-26 17:56:42 +03:00

47 lines
938 B
Go

package plugin
import (
"fmt"
"github.com/mattermost/mattermost/server/public/model"
)
func (p *Plugin) ensureBot() error {
const botUsername = "sentry"
user, appErr := p.API.GetUserByUsername(botUsername)
if appErr == nil && user != nil {
if !user.IsBot {
return fmt.Errorf("user @%s exists but is not a bot", botUsername)
}
p.botUserID = user.Id
return nil
}
bot := &model.Bot{
Username: botUsername,
DisplayName: "Sentry",
Description: "Sentry notifications bot",
}
createdBot, appErr := p.API.CreateBot(bot)
if appErr != nil {
p.API.LogError("Failed to create Sentry bot", "error", appErr.Error())
return appErr
}
p.botUserID = createdBot.UserId
return nil
}
func (p *Plugin) getChannelForProject(project string) (string, error) {
key := "sentry:project:" + project
data, appErr := p.API.KVGet(key)
if appErr != nil || data == nil {
return "", appErr
}
return string(data), nil
}