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:
@@ -75,6 +75,7 @@ type CreateSessionRequest struct {
|
||||
ChannelID string `json:"channel_id"`
|
||||
RootID string `json:"root_id,omitempty"`
|
||||
AgentID string `json:"agent_id"`
|
||||
BotUserID string `json:"bot_user_id,omitempty"`
|
||||
}
|
||||
|
||||
// handleCreateSession creates a new custom_livestatus post and starts tracking.
|
||||
@@ -98,8 +99,20 @@ func (p *Plugin) handleCreateSession(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Create the custom post
|
||||
// Create the custom post — UserId is required
|
||||
// Use the bot user ID passed in the request, or fall back to plugin bot
|
||||
userID := req.BotUserID
|
||||
if userID == "" {
|
||||
// Try to get plugin's own bot
|
||||
userID = p.getBotUserID()
|
||||
}
|
||||
if userID == "" {
|
||||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "bot_user_id required (no plugin bot available)"})
|
||||
return
|
||||
}
|
||||
|
||||
post := &model.Post{
|
||||
UserId: userID,
|
||||
ChannelId: req.ChannelID,
|
||||
RootId: req.RootID,
|
||||
Type: "custom_livestatus",
|
||||
|
||||
Reference in New Issue
Block a user