fix: plugin bot user + await plugin detection before session scan

- Add EnsureBotUser on plugin activate (fixes 'Unable to find user' error)
- Accept bot_user_id in create session request
- Await plugin health check before starting session monitor
  (prevents race where sessions detect before plugin flag is set)
- Plugin now creates custom_livestatus posts with proper bot user
This commit is contained in:
sol
2026-03-07 22:25:59 +00:00
parent 42755e73ad
commit 7aebebf193
4 changed files with 56 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"sync"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/plugin"
)
@@ -18,16 +19,37 @@ type Plugin struct {
// store wraps KV store operations for session persistence.
store *Store
// botUserID is the plugin's bot user ID (created on activation).
botUserID string
}
// OnActivate is called when the plugin is activated.
func (p *Plugin) OnActivate() error {
p.store = NewStore(p.API)
// Ensure plugin bot user exists
botID, appErr := p.API.EnsureBotUser(&model.Bot{
Username: "livestatus",
DisplayName: "Live Status",
Description: "OpenClaw Live Status plugin bot",
})
if appErr != nil {
p.API.LogWarn("Failed to ensure bot user", "error", appErr.Error())
} else {
p.botUserID = botID
p.API.LogInfo("Plugin bot user ensured", "botUserID", botID)
}
p.API.LogInfo("OpenClaw Live Status plugin activated")
return nil
}
// getBotUserID returns the plugin's bot user ID.
func (p *Plugin) getBotUserID() string {
return p.botUserID
}
// OnDeactivate is called when the plugin is deactivated.
func (p *Plugin) OnDeactivate() error {
// Mark all active sessions as interrupted