> ## Documentation Index
> Fetch the complete documentation index at: https://compass.docs.sunnyscoach.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Email Response Time Statistics

> Returns detailed response time metrics for emails within the specified date range.   - Includes both **first response** and **overall response** time statistics.   - Also reports SLA(Service Level Agreement currently 15 mins) compliance breakdown (responses within SLA vs. after SLA).   - If no/invalid startDate or endDate is provided, the system defaults to the last 7 days (a week from today).


Returns detailed response time metrics for emails within the specified date range. Includes both first response and overall response time statistics. Also reports SLA (Service Level Agreement - currently 15 mins) compliance breakdown.

## Request

### Headers

| Name          | Type   | Required | Description  |
| ------------- | ------ | -------- | ------------ |
| Authorization | string | Yes      | Bearer token |

### Path Parameters

| Parameter | Type   | Required | Description                                                           |
| --------- | ------ | -------- | --------------------------------------------------------------------- |
| startDate | string | Yes      | Start date for the report (ISO 8601). Defaults to 7 days before today |
| endDate   | string | Yes      | End date for the report (ISO 8601). Defaults to today                 |

#### Parameter Format

* **Format**: `YYYY-MM-DDTHH:mm:ss.sssZ` (ISO 8601)
* **Timezone**: UTC
* **Default**: Last 7 days if not provided

## Response

### 200 OK - Successfully retrieved response time statistics

```json theme={null}
{
  "message": "",
  "data": {
    "firstResponse": {
      "min": 2,
      "max": 180,
      "average": 25.5,
      "median": 18.2,
      "withinSLA": 85,
      "outsideSLA": 15
    },
    "overallResponse": {
      "min": 5,
      "max": 240,
      "average": 45.8,
      "median": 38.5,
      "withinSLA": 72,
      "outsideSLA": 28
    }
  }
}
```

### 400 Bad Request

```json theme={null}
{
  "error": {
    "code": "INVALID_DATE_RANGE",
    "message": "Invalid date range or malformed request"
  }
}
```

### 401 Unauthorized

```json theme={null}
{
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Missing or invalid token"
  }
}
```

### 500 Internal Server Error

```json theme={null}
{
  "error": {
    "code": "SERVER_ERROR",
    "message": "Internal server error"
  }
}
```

## Example

```bash theme={null}
curl -X GET 'http://localhost:2000/email-meter/stats/response-times/2025-10-01T00:00:00.000Z/2025-10-20T23:59:59.000Z' \
  -H 'Authorization: Bearer your-jwt-token'
```

## Data Fields Explained

### First Response Metrics

| Field      | Type    | Description                           |
| ---------- | ------- | ------------------------------------- |
| min        | number  | Minimum first response time (minutes) |
| max        | number  | Maximum first response time (minutes) |
| average    | number  | Average first response time (minutes) |
| median     | number  | Median first response time (minutes)  |
| withinSLA  | integer | Count of responses within 15 minutes  |
| outsideSLA | integer | Count of responses after 15 minutes   |

### Overall Response Metrics

| Field      | Type    | Description                                |
| ---------- | ------- | ------------------------------------------ |
| min        | number  | Minimum overall response time (minutes)    |
| max        | number  | Maximum overall response time (minutes)    |
| average    | number  | Average overall response time (minutes)    |
| median     | number  | Median overall response time (minutes)     |
| withinSLA  | integer | Count of final responses within 15 minutes |
| outsideSLA | integer | Count of final responses after 15 minutes  |

## SLA Compliance

### Current SLA: 15 Minutes

* **Within SLA**: Response sent within 15 minutes
* **Outside SLA**: Response sent after 15 minutes
* **First Response**: Time to first reply in conversation
* **Overall Response**: Time to final resolution

### SLA Calculations

```
SLA Compliance Rate = (withinSLA / (withinSLA + outsideSLA)) * 100
```

## Use Cases

* **Service Quality**: Monitor email response performance
* **SLA Reporting**: Track compliance with service level agreements
* **Team Performance**: Evaluate agent response times
* **Process Improvement**: Identify areas needing faster responses
* **Customer Satisfaction**: Correlate response times with satisfaction

## Performance Metrics

### Response Time Categories

* **Excellent**: \< 5 minutes
* **Good**: 5-15 minutes (within SLA)
* **Needs Improvement**: 15-60 minutes
* **Poor**: > 60 minutes

### Benchmarking

* Compare against industry standards
* Track improvement over time
* Identify peak performance periods
* Monitor team performance trends

## Best Practices

1. **Monitoring**: Regularly check SLA compliance
2. **Alerts**: Set up alerts for SLA breaches
3. **Analysis**: Analyze patterns in delayed responses
4. **Training**: Use data for agent training
5. **Optimization**: Identify bottlenecks in response process

## Related Endpoints

* Use `/email-meter/stats/agents-detailed` for agent-specific response times
* Use `/email-meter/stats/hourly-trends` for time-of-day analysis
* Use `/email-meter/stats/clients/response-times` for client-specific analysis

## Notes

* All response times are calculated in minutes
* Times are based on business hours by default
* Weekends and holidays may be excluded based on configuration
* Automated responses are excluded from calculations
* Response times include only human-to-human interactions


## OpenAPI

````yaml GET /email-meter/stats/response-times/{startDate}/{endDate}
openapi: 3.0.3
info:
  title: COMPASS API
  version: 1.0.0
  description: OpenAPI specification for the Compass backend routes.
servers:
  - url: http://localhost:2000
    description: Local development server
security: []
tags:
  - name: Auth
    description: >-
      Authentication and session management endpoints (OAuth and session
      validation)
  - name: Users
    description: Operations for managing user records
  - name: Departments
    description: Operations for managing departments
  - name: Email Meter
    description: APIs to get Email Meter Stats
  - name: HubSpot Tickets
    description: Feedback APIs
  - name: Permissions
    description: Permissions APIs
  - name: Transcription
    description: Transcription APIs
paths:
  /email-meter/stats/response-times/{startDate}/{endDate}:
    get:
      tags:
        - Email Meter
      summary: Get email response time statistics
      description: >
        Returns detailed response time metrics for emails within the specified
        date range.   - Includes both **first response** and **overall
        response** time statistics.   - Also reports SLA(Service Level Agreement
        currently 15 mins) compliance breakdown (responses within SLA vs. after
        SLA).   - If no/invalid startDate or endDate is provided, the system
        defaults to the last 7 days (a week from today).
      parameters:
        - name: startDate
          in: path
          required: true
          description: Start date for the report (ISO 8601 format).
          schema:
            type: string
            format: date-time
          example: '2025-10-01T00:00:00.000Z'
        - name: endDate
          in: path
          required: true
          description: End date for the report (ISO 8601 format).
          schema:
            type: string
            format: date-time
          example: '2025-10-20T23:59:59.000Z'
      responses:
        '200':
          description: Successfully retrieved response time statistics
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: ''
                  data:
                    type: object
                    properties:
                      first:
                        type: object
                        description: >-
                          Statistics for the first response time to incoming
                          emails.
                        properties:
                          min:
                            type: number
                            format: float
                            description: Minimum response time in hours
                            example: 0.5
                          max:
                            type: number
                            format: float
                            description: Maximum response time in hours
                            example: 24
                          average:
                            type: number
                            format: float
                            description: Average response time in hours
                            example: 4.2
                          median:
                            type: number
                            format: float
                            description: Median response time in hours
                            example: 3.9
                      overall:
                        type: object
                        description: Statistics for all responses (not just the first).
                        properties:
                          min:
                            type: number
                            format: float
                            example: 0.3
                          max:
                            type: number
                            format: float
                            example: 26.5
                          average:
                            type: number
                            format: float
                            example: 5.8
                          median:
                            type: number
                            format: float
                            example: 5
                      sla:
                        type: object
                        description: SLA performance metrics
                        properties:
                          withinSLA:
                            type: integer
                            description: Number of responses that met the SLA
                            example: 180
                          afterSLA:
                            type: integer
                            description: Number of responses that exceeded the SLA
                            example: 20
                          percentage:
                            type: number
                            format: float
                            description: Percentage of responses within SLA
                            example: 90
        '400':
          description: Invalid date range or malformed request
        '401':
          description: Unauthorized (missing or invalid token)
        '500':
          description: Server error
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````