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

# Teams Account Linking

> How the Teams SDK connector knows which Genesis account a Teams sender is: a link code from Profile, or recognition by email for the email domains you trust.

An agent in Microsoft Teams (the Teams SDK connector, `teams_v2`) works only for people with a Genesis account. Each sender's turn runs as their own Genesis account, with that account's roles and grants. Teams tells Genesis who the sender is (their Microsoft 365 tenant and Entra object id, both vouched for by the Bot Framework token); a **link** ties that Teams account to a Genesis account. A sender with no link gets no turn, only a private message with the steps to connect.

A link is made in one of two ways:

* **A link code.** The person opens Genesis, clicks their initials → **Connected Accounts** → **Generate Teams link code**, and sends the code to the agent in a 1:1 chat in Teams. This always works while the connector and sign-in are on.
* **Recognition by email.** Where you trust an email domain, a person whose Teams email is in it is linked the first time they write to the agent (in a 1:1 chat, or by mentioning it in a group chat or channel), with no code. Messages among colleagues that don't mention the agent never link anyone. This is off until you list a domain.

## Recognize people by email

Set `teams_v2.trusted_email_domains` to the email domains of your organization's people, for example `["example.com"]` (**Settings → Advanced Settings**, the config API, or a config file). Empty, the default, turns recognition by email off.

When a sender has no link, the connector recognizes them by email only when all of these hold:

| Rule | Why |
| - | - |
| The email comes from Teams' own roster for the conversation, read by Genesis with the app's credentials. | Nothing the sender's client writes into a message is trusted as their email. |
| The sender's tenant is this deployment's own: `teams_v2.app_tenant_id`, or one listed in `teams.allowed_tenant_ids`. | With neither set, no tenant is trusted and nobody is recognized by email. |
| The email (or, without one, the user principal name) is a single mailbox in a listed domain, compared whole. | A subdomain of a listed domain is not included; list it too if you want it. Guests, anonymous members and Entra guest names (`#EXT#`) are never matched. |
| Exactly one active, full Genesis account has that email, ignoring case. | No email, two accounts with it, the system identity, a SCIM-deactivated account or a Slack-only account never match. |
| The Teams account has no link, and was never unlinked by its owner; the Genesis account has no link from another Teams account. | Recognition by email never moves or adds to a link a person made or removed. |
| Sign-in is on. | With sign-in off every request is the local operator, whom no Teams turn runs as. |

When they all hold, the turn runs as that account, the link is recorded marked as made by email, and the Audit Log shows a `teams_identity.linked_by_email` row. Otherwise the sender gets the usual steps to connect with a link code, as before. If Teams' roster does not answer, the sender gets the steps too, and no turn.

A link made by email is honoured only while it would still be made: taking its domain off the list, removing the tenant, turning sign-in off, or changing the account's email stops it at once. The sender is then told their link can't be used, and can unlink it and link again with a code.

## What a person sees in Profile

**Profile → Connected Accounts → Microsoft Teams** lists each linked Teams account. A link made by email reads **Recognized by email: `<email>`**; a code link shows the tenant and user ids. Either can be removed with **Unlink**. Unlinking a Teams account also stops recognition by email for it: the connector does not link it by email again, and a link code links it again.

## Links in Teams

Teams opens a link only when it points at an `https://` address. When Genesis's address (`GENESIS_PUBLIC_BASE_URL`) is plain `http://`, as on a local server, the connector writes it out instead, for people to copy: the connect steps read "Sign in to Genesis at [http://localhost:8080](http://localhost:8080).", an answer's links to Genesis show their label and address, and cards show the address in their text in place of an **Open in Genesis** button.

## Troubleshooting

| Symptom | Check |
| - | - |
| People in a listed domain still get the link-code steps. | `teams_v2.app_tenant_id` or `teams.allowed_tenant_ids` names their tenant; sign-in is on; their Genesis account's email is exactly their Teams email (or user principal name); no second account has it; they did not unlink that Teams account before. |
| "Your Teams account is linked to a Genesis account that can't be used." | The account is inactive or deactivated, or the link was made by email and its domain, tenant or the account's email changed since. Unlink it in Profile and link again with a code, or ask an administrator. |
| Someone was recognized as the wrong person. | Their Teams email names that Genesis account. Unlink it from that account's Profile (the Teams account is then not matched by email again), and correct the account's email. |
