# Chat Routes

This package organizes chat-related API endpoints by concern and provider specificity.

## File Structure

| File | Description |
|---|---|
| `__init__.py` | Package init — re-exports routers from each module |
| `config.py` | Configuration CRUD for chat providers |
| `generic.py` | Provider-agnostic operations (channels, messaging, questionnaires) |
| `slack.py` | Slack-specific endpoints (OAuth, event subscriptions, dev utilities) |

## Endpoints

### Configuration CRUD (`config.py`, prefix `/chat`)

| Method | Path | Description |
|---|---|---|
| GET | `/chat/config` | List all chat configurations |
| POST | `/chat/config` | Create a new chat configuration |
| GET | `/chat/config/{config_id}` | Get a specific configuration |
| PATCH | `/chat/config/{config_id}` | Update a configuration |
| DELETE | `/chat/config/{config_id}` | Delete a configuration |
| PUT | `/chat/config/{config_id}/enable` | Enable a configuration (disables all others) |
| PUT | `/chat/config/{config_id}/secret` | Update secrets (client_secret, signing_secret) |

### Provider-Agnostic Operations (`generic.py`, prefix `/chat`)

These endpoints delegate to whichever provider is active via the `get_chat_provider` factory.

| Method | Path | Description |
|---|---|---|
| POST | `/chat/test` | Test the active provider connection |
| GET | `/chat/channels` | List available channels |
| POST | `/chat/send` | Send a message to a channel |
| POST | `/chat/questionnaire` | Create and start a questionnaire |
| GET | `/chat/questionnaire` | List all questionnaires |
| GET | `/chat/questionnaire/{questionnaire_id}` | Get a specific questionnaire |

### Slack-Specific (`slack.py`, prefix `/chat/slack`)

These endpoints use Slack-specific APIs and cannot be reused for other providers.

| Method | Path | Description |
|---|---|---|
| GET | `/chat/slack/authorize` | Initiate Slack OAuth flow |
| GET | `/chat/slack/callback` | Handle Slack OAuth callback |
| POST | `/chat/slack/events` | Receive Slack event subscriptions (webhooks) |

## Adding a New Provider

To add support for a new provider (e.g., Microsoft Teams):

1. Create `teams.py` in this directory with `prefix="/chat/teams"` for provider-specific endpoints (OAuth, webhooks).
2. Implement `TeamsChatProvider` extending `ChatProviderInterface` in `src/fidesplus/service/chat_provider/`.
3. Register the new provider in the factory (`src/fidesplus/service/chat_provider/factory.py`).
4. Export the new router from `__init__.py` and register it in `main.py`.

The provider-agnostic endpoints in `generic.py` will work automatically with the new provider via the factory — no changes needed.
