Documentation
¶
Overview ¶
Package support implements an enterprise support ticketing system with priority routing, SLA tracking, and webhook notifications.
Index ¶
- func TenantFromContext(ctx context.Context) (string, bool)
- func ValidTransition(from, to Status) bool
- type API
- func (a *API) AddComment(w http.ResponseWriter, r *http.Request)
- func (a *API) CloseTicket(w http.ResponseWriter, r *http.Request)
- func (a *API) CreateTicket(w http.ResponseWriter, r *http.Request)
- func (a *API) GetTicket(w http.ResponseWriter, r *http.Request)
- func (a *API) ListTickets(w http.ResponseWriter, r *http.Request)
- func (a *API) RegisterRoutes(mux *http.ServeMux)
- type AddCommentRequest
- type AuthFunc
- type Breach
- type BreachHandler
- type BreachType
- type Comment
- type CreateTicketRequest
- type EventType
- type Priority
- type Router
- type RoutingRule
- type SLAPolicy
- type SLATracker
- type Status
- type Store
- type Ticket
- type WebhookDispatcher
- type WebhookEvent
- type WebhookTarget
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TenantFromContext ¶ added in v1.12.0
TenantFromContext returns the authenticated tenant ID from the request context.
func ValidTransition ¶
ValidTransition reports whether transitioning from one status to another is allowed.
Types ¶
type API ¶
type API struct {
Store *Store
Router *Router
SLA *SLATracker
Webhooks *WebhookDispatcher
Auth AuthFunc
}
API provides HTTP handlers for the customer support portal.
func (*API) AddComment ¶
func (a *API) AddComment(w http.ResponseWriter, r *http.Request)
AddComment handles POST /support/tickets/{id}/comments.
func (*API) CloseTicket ¶
func (a *API) CloseTicket(w http.ResponseWriter, r *http.Request)
CloseTicket handles POST /support/tickets/{id}/close.
func (*API) CreateTicket ¶
func (a *API) CreateTicket(w http.ResponseWriter, r *http.Request)
CreateTicket handles POST /support/tickets.
func (*API) GetTicket ¶
func (a *API) GetTicket(w http.ResponseWriter, r *http.Request)
GetTicket handles GET /support/tickets/{id}.
func (*API) ListTickets ¶
func (a *API) ListTickets(w http.ResponseWriter, r *http.Request)
ListTickets handles GET /support/tickets?customer_id=...
func (*API) RegisterRoutes ¶
RegisterRoutes registers all ticket API endpoints on the given mux.
type AddCommentRequest ¶
AddCommentRequest is the JSON body for adding a comment.
type AuthFunc ¶ added in v1.12.0
AuthFunc validates a Bearer token and returns the associated tenant ID. If the token is invalid, it returns an empty string and false.
type Breach ¶
type Breach struct {
TicketID string
Type BreachType
Priority Priority
Deadline time.Time
BreachedAt time.Time
}
Breach records an SLA violation.
type BreachHandler ¶
type BreachHandler func(Breach)
BreachHandler is called when an SLA breach is detected.
type BreachType ¶
type BreachType string
BreachType indicates which SLA target was breached.
const ( BreachResponse BreachType = "response" BreachResolution BreachType = "resolution" )
type Comment ¶
type Comment struct {
ID string `json:"id"`
Author string `json:"author"`
Body string `json:"body"`
CreatedAt time.Time `json:"created_at"`
}
Comment is a message attached to a ticket.
type CreateTicketRequest ¶
type CreateTicketRequest struct {
CustomerID string `json:"customer_id"`
Subject string `json:"subject"`
Body string `json:"body"`
Priority Priority `json:"priority"`
}
CreateTicketRequest is the JSON body for creating a ticket.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router assigns tickets to teams or individuals based on priority.
func NewRouter ¶
NewRouter creates a router with the given fallback assignee used when no priority-specific rule matches.
type RoutingRule ¶
RoutingRule maps a priority to an assignee (team or individual).
type SLAPolicy ¶
type SLAPolicy struct {
Priority Priority
ResponseTime time.Duration // max time to first response (triage)
ResolutionTime time.Duration // max time to resolution
}
SLAPolicy defines response and resolution time targets for a priority level.
func DefaultSLAPolicies ¶
func DefaultSLAPolicies() []SLAPolicy
DefaultSLAPolicies returns standard enterprise SLA targets.
type SLATracker ¶
type SLATracker struct {
// contains filtered or unexported fields
}
SLATracker monitors tickets against SLA policies and fires breach alerts.
func NewSLATracker ¶
func NewSLATracker(policies []SLAPolicy) *SLATracker
NewSLATracker creates a tracker with the given policies.
func (*SLATracker) Check ¶
func (s *SLATracker) Check(t *Ticket, now time.Time) []Breach
Check evaluates whether a ticket has breached its SLA at the given time. It returns any breaches found.
func (*SLATracker) CheckAll ¶
func (s *SLATracker) CheckAll(store *Store, now time.Time) []Breach
CheckAll evaluates all tickets in a store for SLA breaches.
func (*SLATracker) OnBreach ¶
func (s *SLATracker) OnBreach(h BreachHandler)
OnBreach registers a handler that is called when a breach is detected.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a thread-safe in-memory ticket store.
func (*Store) AddComment ¶
AddComment appends a comment to the ticket.
func (*Store) ListByCustomer ¶
ListByCustomer returns all tickets for a customer, ordered by creation time (newest first).
type Ticket ¶
type Ticket struct {
ID string `json:"id"`
CustomerID string `json:"customer_id"`
Subject string `json:"subject"`
Body string `json:"body"`
Priority Priority `json:"priority"`
Status Status `json:"status"`
AssignedTo string `json:"assigned_to,omitempty"`
Comments []Comment `json:"comments,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ResolvedAt time.Time `json:"resolved_at,omitempty"`
ClosedAt time.Time `json:"closed_at,omitempty"`
}
Ticket is the core data model for a support ticket.
type WebhookDispatcher ¶
type WebhookDispatcher struct {
// contains filtered or unexported fields
}
WebhookDispatcher sends events to registered webhook targets.
func NewWebhookDispatcher ¶
func NewWebhookDispatcher() *WebhookDispatcher
NewWebhookDispatcher creates a dispatcher with a default HTTP client.
func (*WebhookDispatcher) Dispatch ¶
func (d *WebhookDispatcher) Dispatch(ctx context.Context, event WebhookEvent) []error
Dispatch sends an event to all matching targets. It returns errors for any failed deliveries but does not stop on first failure.
func (*WebhookDispatcher) Register ¶
func (d *WebhookDispatcher) Register(target WebhookTarget)
Register adds a webhook target.
func (*WebhookDispatcher) Targets ¶
func (d *WebhookDispatcher) Targets() []WebhookTarget
Targets returns the list of registered webhook targets.
type WebhookEvent ¶
type WebhookEvent struct {
Type EventType `json:"type"`
Timestamp time.Time `json:"timestamp"`
Payload interface{} `json:"payload"`
}
WebhookEvent is the payload sent to registered webhook endpoints.
type WebhookTarget ¶
type WebhookTarget struct {
Name string // e.g. "slack", "pagerduty"
URL string
Events []EventType // empty means all events
}
WebhookTarget is a registered endpoint for receiving notifications.