98 lines
3.4 KiB
Go
98 lines
3.4 KiB
Go
package v1
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gochat/gochat/internal/service"
|
|
applogger "github.com/gochat/gochat/pkg/logger"
|
|
"github.com/gochat/gochat/pkg/response"
|
|
)
|
|
|
|
// ConversationInsightHandler handles Captain conversation analysis endpoints.
|
|
// Reference: M12 PRD §Captain AI — Participant Analysis, Action Items, Label Suggestion
|
|
type ConversationInsightHandler struct {
|
|
svc *service.ConversationInsightService
|
|
}
|
|
|
|
// NewConversationInsightHandler creates a new ConversationInsightHandler.
|
|
func NewConversationInsightHandler(svc *service.ConversationInsightService) *ConversationInsightHandler {
|
|
return &ConversationInsightHandler{svc: svc}
|
|
}
|
|
|
|
// AnalyzeParticipants analyzes participants in a conversation.
|
|
// POST /api/v1/accounts/:account_id/captain/insights/participants
|
|
func (h *ConversationInsightHandler) AnalyzeParticipants(c *gin.Context) {
|
|
accountID, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
|
if err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, "invalid_account_id", "Invalid account ID")
|
|
return
|
|
}
|
|
|
|
var req service.ParticipantAnalysisRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, "invalid_request", err.Error())
|
|
return
|
|
}
|
|
|
|
result, err := h.svc.AnalyzeParticipants(c.Request.Context(), uint(accountID), &req)
|
|
if err != nil {
|
|
applogger.L().Errorf("ConversationInsightHandler.AnalyzeParticipants failed: %v", err)
|
|
response.AbortWithStatusError(c, http.StatusInternalServerError, "analysis_failed", "Failed to analyze participants")
|
|
return
|
|
}
|
|
|
|
response.OK(c, result)
|
|
}
|
|
|
|
// ExtractActionItems extracts action items from a conversation.
|
|
// POST /api/v1/accounts/:account_id/captain/insights/action_items
|
|
func (h *ConversationInsightHandler) ExtractActionItems(c *gin.Context) {
|
|
accountID, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
|
if err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, "invalid_account_id", "Invalid account ID")
|
|
return
|
|
}
|
|
|
|
var req service.ActionItemsRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, "invalid_request", err.Error())
|
|
return
|
|
}
|
|
|
|
result, err := h.svc.ExtractActionItems(c.Request.Context(), uint(accountID), &req)
|
|
if err != nil {
|
|
applogger.L().Errorf("ConversationInsightHandler.ExtractActionItems failed: %v", err)
|
|
response.AbortWithStatusError(c, http.StatusInternalServerError, "action_items_failed", "Failed to extract action items")
|
|
return
|
|
}
|
|
|
|
response.OK(c, result)
|
|
}
|
|
|
|
// SuggestLabels suggests labels and priority for a conversation.
|
|
// POST /api/v1/accounts/:account_id/captain/insights/label_suggestion
|
|
func (h *ConversationInsightHandler) SuggestLabels(c *gin.Context) {
|
|
accountID, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
|
if err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, "invalid_account_id", "Invalid account ID")
|
|
return
|
|
}
|
|
|
|
var req service.LabelSuggestionRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.AbortWithStatusError(c, http.StatusBadRequest, "invalid_request", err.Error())
|
|
return
|
|
}
|
|
|
|
result, err := h.svc.SuggestLabels(c.Request.Context(), uint(accountID), &req)
|
|
if err != nil {
|
|
applogger.L().Errorf("ConversationInsightHandler.SuggestLabels failed: %v", err)
|
|
response.AbortWithStatusError(c, http.StatusInternalServerError, "label_suggestion_failed", "Failed to suggest labels")
|
|
return
|
|
}
|
|
|
|
response.OK(c, result)
|
|
}
|