feat(reports): derive analytics aggregates
This commit is contained in:
@@ -187,6 +187,7 @@ func (h *AnalyticsHandler) ConversationTraffic(c *gin.Context) {
|
||||
|
||||
response.OK(c, result)
|
||||
}
|
||||
|
||||
// BotSummary returns bot-level summary metrics.
|
||||
// GET /api/v1/accounts/:account_id/reports/bot_summary
|
||||
// Reference: Chatwoot reports#bot_summary
|
||||
@@ -226,12 +227,7 @@ func (h *AnalyticsHandler) Conversations(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
since, until, ok := parseDateRange(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.svc.GetConversationsByType(c.Request.Context(), accountID, reportType, since, until)
|
||||
result, err := h.svc.GetConversationsByType(c.Request.Context(), accountID, reportType, time.Time{}, time.Time{})
|
||||
if err != nil {
|
||||
applogger.L().Errorf("Conversations report: %v", err)
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to generate conversations report")
|
||||
@@ -341,8 +337,13 @@ func (h *AnalyticsHandler) OutgoingMessagesCount(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
groupBy := c.Query("group_by")
|
||||
if groupBy != "agent" && groupBy != "team" && groupBy != "inbox" && groupBy != "label" {
|
||||
response.AbortWithStatusError(c, http.StatusUnprocessableEntity, response.ErrBadRequest, "invalid group_by")
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.svc.GetOutgoingMessagesCount(c.Request.Context(), accountID, since, until)
|
||||
result, err := h.svc.GetOutgoingMessagesCountGrouped(c.Request.Context(), accountID, since, until, groupBy)
|
||||
if err != nil {
|
||||
applogger.L().Errorf("Outgoing messages count report: %v", err)
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to generate outgoing messages count")
|
||||
|
||||
@@ -2,6 +2,7 @@ package v1
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@@ -30,19 +31,23 @@ func (h *LiveReportHandler) ConversationMetrics(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Chatwoot supports team_id filter
|
||||
teamIDStr := c.Query("team_id")
|
||||
teamID := uint(0)
|
||||
if teamIDStr := c.Query("team_id"); teamIDStr != "" {
|
||||
parsed, err := strconv.ParseUint(teamIDStr, 10, 64)
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid team_id")
|
||||
return
|
||||
}
|
||||
teamID = uint(parsed)
|
||||
}
|
||||
|
||||
result, err := h.svc.GetConversationMetrics(c.Request.Context(), accountID)
|
||||
result, err := h.svc.GetConversationMetricsForTeam(c.Request.Context(), accountID, teamID)
|
||||
if err != nil {
|
||||
applogger.L().Errorf("Live conversation metrics: %v", err)
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to get conversation metrics")
|
||||
return
|
||||
}
|
||||
|
||||
// Chatwoot also filters by team_id if provided — TODO: implement team filter
|
||||
_ = teamIDStr
|
||||
|
||||
response.OK(c, result)
|
||||
}
|
||||
|
||||
@@ -72,4 +77,4 @@ func (h *LiveReportHandler) GroupedConversationMetrics(c *gin.Context) {
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user