Teams Bot Mention Parsing & Command Grammar Prompt
Design robust @-mention stripping and a forgiving command grammar for a ChatOps bot so noisy channel mentions, formatting entities, and typos still resolve to the right action.
- Target user
- Developers building command-driven ChatOps bots in Teams channels
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior ChatOps engineer who has built Teams bots whose command parsing just works, even when users mangle the syntax. I will provide: - My intended commands (e.g. deploy, rollback, ack, silence, status) and their args - Whether the bot runs in channels, group chats, or 1:1 - Example messy real-world messages users actually send - My current naive parser and where it breaks Your job: 1. **Strip the mention correctly** — explain that in channels the bot's display name appears in the text with a matching `entities[]` mention object, and that you must remove it using the mention entity offsets/text, not a brittle string replace. Show code that strips all `mention` entities (including replies that mention other users) before parsing. 2. **Normalize** — collapse whitespace, decode HTML entities Teams injects, drop trailing punctuation, and lowercase the verb while preserving arg casing. 3. **A forgiving grammar** — define a small command grammar (verb + flags + positional args), with aliases (`rollback`/`undo`), and fuzzy matching for near-miss verbs that asks "did you mean rollback?" instead of failing silently. 4. **Arg parsing** — handle `--flag value`, `--flag=value`, quoted multi-word values, and sensible defaults; validate enums (env must be one of dev/stage/prod) with helpful errors. 5. **Disambiguation + help** — when a command is ambiguous or incomplete, reply with an Adaptive Card prompting for the missing arg rather than dumping a usage wall. Provide a `help` that lists commands contextually. 6. **Safety gates** — require explicit confirmation for destructive verbs (rollback prod), and ignore mentions of the bot that are clearly not commands (someone quoting it). 7. **Tests** — turn my messy examples into a table of input → parsed intent, including the cases that currently break. Output: (a) the mention-stripping function using entity offsets, (b) the normalize + parse pipeline, (c) the grammar/alias/fuzzy-match spec, (d) the disambiguation card, (e) a test table built from my real messages. Bias toward: resilience to messy input, never executing destructive commands on ambiguous parses, helpful nudges over silent failures.