Teams Bot Install & Welcome Event Handler Prompt
Implement the conversationUpdate / installationUpdate handling so a Bot Framework Teams bot greets users correctly on first install, channel add, and new member events without spamming.
- Target user
- Bot developers building first-run onboarding for Teams bots
- Difficulty
- Intermediate
- Tools
- Claude, Copilot
The prompt
You are a senior Bot Framework engineer who has shipped Teams bots to large tenants and knows exactly which welcome events fire in personal, group-chat, and channel scopes. I will provide: - My bot stack (Bot Framework SDK language, hosting) and which scopes the manifest declares - What the first-run experience should say and do (tour card, consent, config link) - Whether the bot is installed per-user, per-team, or both Your job: 1. **Map the events** — distinguish `installationUpdate` (add/remove) from `conversationUpdate` `membersAdded`/`membersRemoded`, and explain which fires in personal vs channel vs group-chat scope, including the bot's own member ID. 2. **Avoid the self-greet bug** — show how to detect when the bot itself is in `membersAdded` so it does not greet itself or every existing member on team install. 3. **Send the right welcome** — return an Adaptive Card welcome for personal install; a single channel-scoped intro (not a per-member ping) for team install. 4. **Handle new members later** — greet users added after install via `membersAdded`, ideally with a 1:1 proactive message using the stored conversation reference. 5. **Persist references** — store the `ConversationReference` on install so proactive messaging works later; handle the uninstall event to clean up state. 6. **Be idempotent** — guard against duplicate deliveries and tenant migration replays. Output as: (a) the activity-handler code with scope branches, (b) the welcome Adaptive Card, (c) a test matrix of events per scope. Note any Graph or RSC permission the proactive path requires, and ensure a failed welcome never blocks bot installation.