# Microsoft Teams Channel Alerts

## Objective

Post operational and customer alerts into a chosen Microsoft Teams channel.

A Teams destination for selected app events, with explicit tenant, team, and channel selection and reliable delivery.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Make the destination explicit at setup: the operator picks the tenant, then the team, then the channel, from lists the app fetched under that operator's own authorisation. Do not accept a pasted destination identifier as configuration.
2. Confirm the connection by posting a test message the operator acknowledges, and record which account authorised it so anyone can see whose credentials the integration depends on.
3. Keep every message inside the provider's payload and card size limits. Truncate long user content at a defined boundary and link back to the full record, rather than letting an oversized post be rejected silently.
4. Store credentials server-side, refresh them ahead of expiry, and when a refresh fails, disable the destination and tell an operator inside the app exactly which connection needs reauthorising.
5. If a Slack brief is also applied to this app, share its event-selection and routing layer and let this brief own only Teams formatting and delivery. Two independent alert configurations will drift and double-post the same event.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Tenant, team, and channel must each be chosen explicitly. A guessed default posts customer data into whichever channel happened to be first in the list.
- Payloads over the provider's size limit are rejected outright. Truncate deliberately with a link to the full record rather than discovering the ceiling during an incident.
- Credentials expire, and the account that authorised them may leave the organisation. Refresh proactively, and on failure disable the destination with an operator-visible reason instead of retrying silently forever.
- An ambiguous delivery failure, such as a timeout after the request was accepted, must be deduplicated on the event identifier, or the same incident is announced twice.
- User-supplied text must be escaped before it is placed in a rich card, so a message cannot inject formatting, an image, or a link the sender never wrote.
- Rate limits and transient provider failures need bounded backoff, and delivery must never block the user action that generated the event.
- Everyone in the channel sees the alert. Exclude anything the whole membership should not read, and prefer a link to the record over the record's contents.
- A channel that has been deleted, or that the app has lost access to, must disable itself and surface in the app rather than accumulating failed jobs.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] Tenant, team, and channel are selected explicitly at setup and confirmed with a test message.
- [ ] Messages stay within provider size limits, truncating with a link rather than failing.
- [ ] Credentials are stored server-side and refreshed before they expire.
- [ ] A failed refresh or lost channel access disables the destination and tells an operator why.
- [ ] An ambiguous delivery failure never results in a duplicate post.
- [ ] User-supplied text cannot alter card formatting or inject links.
- [ ] Alert delivery never blocks the user action that produced the event.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
