--- name: agent-teams description: Interact with Microsoft Teams - send messages, read channels, manage reactions version: 2.43.0 allowed-tools: Bash(agent-teams:*) metadata: openclaw: requires: bins: - agent-teams install: - kind: node package: agent-messenger bins: [agent-teams] --- # Agent Teams A TypeScript CLI and SDK for Microsoft Teams. Work/school channels, directory and files use Graph; chats use the Skype messaging service and search uses Substrate. ## Quick Start ```bash # Sign in for channel, directory, file and search operations agent-teams auth login --email user@example.com --account-type work # Get team snapshot agent-teams snapshot # Send a message agent-teams message send "Hello from AI agent!" # List channels agent-teams channel list ``` ## Authentication Choose authentication by the required operations: 1. **`agent-teams auth login`** (work/school **or** personal Microsoft accounts) — device-code sign-in. Open the printed URL, enter the code, and approve in your browser. No desktop app or browser extraction needed. It prompts for your Microsoft email (or pass `--email `) and auto-detects work vs personal, then starts the matching flow; pass `--account-type work|personal` to force it and skip detection. Only `auth login` stores the AAD refresh token required by `message search`. 2. **`agent-teams auth extract`** supplies a Skype token from desktop/browser cookies for chats and legacy discovery. It cannot mint Graph/Substrate tokens, so channel, member and file commands fall back to the older Teams CSA routes and `message search` is unavailable. Automatic extraction can happen when no device-code account is stored. If any stored account uses device-code, automatic extraction is suppressed, including when another account type is selected. A failed refresh therefore cannot overwrite a deliberate login with another desktop/browser identity. Tokens are short-lived. Device-code accounts refresh silently for the selected account. If refresh fails, reconnect explicitly with `auth login`. Running `auth extract` explicitly can discard the account's AAD refresh credentials; do not use it as a generic channel/search repair wrapper. ### Non-interactive `auth login` (agents / CI) When there's no TTY, `auth login` splits into two calls: ```bash # 1. Start — returns verification_uri, user_code, and device_code as JSON. # Pass --email to auto-detect the account type (no prompt without a TTY), # or --account-type work|personal to force it. agent-teams auth login --email # 2. After the user approves in a browser, finish with the device_code agent-teams auth login --device-code ``` `--client-id ` overrides the AAD client ID on either call (or set `AGENT_TEAMS_CLIENT_ID`). `--account-type ` selects the account (default `work`); it is preserved across the two-call flow, so pass it to both calls when signing in to a personal account non-interactively. ### Multi-Team Support ```bash # List all available teams agent-teams team list # Switch to a different team agent-teams team switch # Show current team agent-teams team current # Check auth status (includes token expiry info) agent-teams auth status ``` ### Multi-Account Support (Work / Personal) ```bash # Switch between work and personal accounts agent-teams auth switch-account work agent-teams auth switch-account personal # Use a specific account for one command (without switching) agent-teams snapshot --account work ``` ## Memory The agent maintains a `~/.config/agent-messenger/MEMORY.md` file as persistent memory across sessions. This is agent-managed — the CLI does not read or write this file. Use the `Read` and `Write` tools to manage your memory file. ### Reading Memory At the **start of every task**, read `~/.config/agent-messenger/MEMORY.md` using the `Read` tool to load any previously discovered team IDs, channel IDs, user IDs, and preferences. - If the file doesn't exist yet, that's fine — proceed without it and create it when you first have useful information to store. - If the file can't be read (permissions, missing directory), proceed without memory — don't error out. ### Writing Memory After discovering useful information, update `~/.config/agent-messenger/MEMORY.md` using the `Write` tool. Write triggers include: - After discovering team IDs and names (from `team list`, `snapshot`, etc.) - After discovering useful channel IDs and names (from `channel list`, `snapshot`, etc.) - After discovering user IDs and names (from `user list`, `user me`, etc.) - After the user gives you an alias or preference ("call this the standup channel", "my main team is X") - After discovering channel structure (standard vs private channels) When writing, include the **complete file content** — the `Write` tool overwrites the entire file. ### What to Store - Team IDs with names - Channel IDs with names and team context - User IDs with display names - User-given aliases ("standup channel", "main team") - Account preferences (work vs personal) - Any user preference expressed during interaction ### What NOT to Store Never store tokens, credentials, or any sensitive data. Never store full message content (just IDs and channel context). Never store file upload contents. ### Handling Stale Data If a memorized ID returns an error (channel not found, team not found), remove it from `MEMORY.md`. Don't blindly trust memorized data — verify when something seems off. Prefer re-listing over using a memorized ID that might be stale. ### Format / Example ```markdown # Agent Messenger Memory ## Teams - `team-id-1` — Acme Corp (default, work account) - `team-id-2` — Side Project (personal account) ## Channels (Acme Corp) - `channel-id-1` — General - `channel-id-2` — Engineering - `channel-id-3` — Standups ## Users (Acme Corp) - `user-id-1` — Alice (engineering lead) - `user-id-2` — Bob (backend) ## Aliases - "standup" → `channel-id-3` (Standups in Acme Corp) - "main team" → `team-id-1` (Acme Corp) ## Notes - User prefers work account by default - Main team is "Acme Corp" ``` > Memory lets you skip repeated `channel list` and `team list` calls. When you already know an ID from a previous session, use it directly. ## Commands ### Auth Commands ```bash # Sign in via device code (work/school or personal Microsoft accounts). agent-teams auth login agent-teams auth login --device-code # finish a non-interactive login # Extract token from Teams desktop app or browser (usually automatic) agent-teams auth extract agent-teams auth extract --debug agent-teams auth extract --browser-profile ~/browser-data agent-teams auth extract --browser-profile ~/work-profile --browser-profile ~/personal-profile # --browser-profile accepts repeatable or comma-separated Chromium profile/user-data dirs # Check auth status (includes token expiry info) agent-teams auth status # Logout from Microsoft Teams agent-teams auth logout # Switch between work and personal accounts agent-teams auth switch-account agent-teams auth switch-account work agent-teams auth switch-account personal ``` ### Whoami Command ```bash # Show current authenticated user agent-teams whoami agent-teams whoami --pretty ``` Output includes the authenticated user's identity information. ### Message Commands ```bash # Send a message agent-teams message send agent-teams message send 19:abc123@thread.tacv2 "Hello world" # Send a rich-text message written in markdown agent-teams message send "## Deploy done - service A - service B" --format markdown # List messages agent-teams message list agent-teams message list 19:abc123@thread.tacv2 --limit 50 # Get a single message by ID (add --thread for a reply) agent-teams message get agent-teams message get --thread # Delete a message (add --thread for a reply) agent-teams message delete --force agent-teams message delete --thread --force # Search messages across Teams (requires `auth login` — see Authentication) agent-teams message search agent-teams message search "deploy" --limit 10 --from 0 ``` `message search` requires an `auth login` account: it queries Microsoft's Substrate search API with an AAD token that `auth extract` (cookie-based) cannot provide. Cookie-only accounts get a clear error telling you to run `auth login`. `--limit` is a positive integer (default 20); `--from` is a non-negative offset for pagination (default 0). ### Channel Commands ```bash # List channels in a team agent-teams channel list # Get channel info agent-teams channel info agent-teams channel info 19:abc123@thread.tacv2 # Get channel history (alias for message list) agent-teams channel history --limit 100 ``` ### Chat Commands For personal Microsoft accounts (`@outlook.com` / `@live.com`) that have no teams or channels — only 1:1, group, and self chat threads. Work accounts can use these too for their 1:1 and group chats. ```bash # List 1:1, group, and self chats agent-teams chat list # Get chat message history (follows pages, returns an array) agent-teams chat history --limit 100 # Read one page at a time; returns { "messages": [...], "next_cursor": "..." } agent-teams chat history --page --limit 50 agent-teams chat history --cursor "$NEXT_CURSOR" --limit 50 # Get a single chat message agent-teams chat get # Send a message to a chat agent-teams chat send "Hello" agent-teams chat send "**Important**: see the [board](https://example.com)" --format markdown # Edit one of your own chat messages agent-teams chat edit "Updated text" agent-teams chat edit "Fixed \`bug\`" --format markdown ``` Chat IDs look like `19:guid1_guid2@unq.gbl.spaces` (1:1) or `19:guid@thread.tacv2` (group). Get them from `chat list`. The `48:notes` chat (`type: self`) is your personal "to me" notes thread. `chat edit` only works on your own messages, and only for chats — Teams channel messages are not editable through this API. ### Message Content (text, HTML, files) Messages from `chat history`, `chat get`, `message list/get/replies`, and `channel history` include: - `content` — plain text (paragraphs as newlines, links as `text (url)`; numeric and common named entities such as `&`, ` `, `—` are decoded, rarer named entities stay literal) - `html` — the original HTML, only for rich-text messages; use it to see where images sit in the text - `files` — every downloadable URL in the message: inline images first (in order), then attachments - `raw_content`, `content_type`, `mentions`, `attachments` — the server representation, kept alongside the rendered fields (not in `chat get`; the full server object is SDK-only as `raw`) (`edited_at`/`deleted_at` and thread fields appear on channel messages when set) `message search` results carry `id`, `channel_id`, `thread_id`, `author`, `content` (indexed preview), `timestamp`, optional `team_name`/`channel_name`/`permalink`. Download any `files` entry with `agent-teams file download [output-path]`. ### Message Formatting `message send`, `chat send`, and `chat edit` accept `--format ` (default `text`). In `text` mode the content is HTML-escaped, so `<`, `>`, and `&` are sent literally. In `markdown` mode the content is converted to HTML before sending. Supported syntax: | Syntax | Renders as | | --- | --- | | `# Heading` through `#### Heading` | headings | | `##### Heading`, `###### Heading` | **not supported** — indistinguishable from body text | | `**bold**`, `_italic_`, `***bold italic***` | emphasis | | `` `inline code` `` | inline code | | triple-backtick fence | fenced code block, without syntax highlighting | | `- item` | bulleted list | | `1. item` | numbered list | | `> quote` | blockquote | | `[label](https://example.com)` | link | | `---` | horizontal rule | Heading levels 5 and 6 are unusable: the Teams client renders `
` and `
` at body size, so they are indistinguishable from surrounding text. Only go as deep as `####`. Fenced code blocks render as monospaced blocks but are never syntax-highlighted — a language tag (` ```ts `) is accepted and then ignored. Both behaviors were verified against a live account. Links are restricted to `http:`, `https:`, `mailto:`, root-relative (`/`), and anchor (`#`) URLs; anything else renders as plain text. In `html` mode content is filtered through a tag whitelist. This supports formatting, but raw `` markup alone is not a notification mention: Graph requires a matching `mentions` payload that the current send interface does not expose. Allowed tags: `at`, `a`, `b`, `i`, `u`, `s`, `strong`, `em`, `code`, `pre`, `br`, `p`, `ul`, `ol`, `li`, `blockquote`, `h1`–`h6`, `hr`. `` only keeps its `id` attribute; `` only keeps `href`, and only when it matches the same URL whitelist as markdown mode; every other tag keeps no attributes at all. Anything not on the list — `