Forum Discussion
App Validation Issue - Bot must send a proactive welcome message in personal scope
I'm working on a bot application for MS Teams using the Python SDK and encountered a challenge with app validation and the proactive welcome message requirement.
What Happened:
- Initially, our bot handled the welcome message through on_installation_update, but app validation failed with the error: "Bot must send a proactive welcome message in personal scope."
- To satisfy validation, we added on_members_added_activity to send the welcome message for personal scope, which resolved the validation error.
- However, this created a new problem: on_members_added_activity is being triggered when we call the Graph API to query chats or users:
{graph_url}/me/chats $filter=chatType eq 'oneOnOne' and installedApps/any(a:a/teamsApp/id eq '{teams_app_id}')
{graph_url}/users/{user_id}/chats $filter=chatType eq 'oneOnOne' and installedApps/any(a:a/teamsApp/id eq '{teams_app_id}') - According to a Stack Overflow discussion (https://stackoverflow.com/questions/57496329/proactive-messaging-bot-in-teams-without-mentioning-the-bot-beforehand), this appears to be a known issue: calling this API triggers a conversation update event even though there were no actual updates, resulting in duplicate events and duplicate welcome messages.
Questions:
- What is the official/recommended way to handle known issue: calling this API triggers a conversation update event?
- Whats the recommended way to read personal chat history of a user?
- Should we be using a different approach for this app validation requirement?
Any guidance or pointers to official documentation would be greatly appreciated!
4 Replies
- ParamZCopper Contributor
Thanks Nivedipa-MSFT , Based on your recommendation, I have implemented the following changes to address the issues. These modifications appear to have resolved the problems.
Graph API queries may generate unexpected conversationUpdate events:I've implemented deduplication logic in on_members_added_activity. Started saving conversation ID in a conversation reference db table after triggering welcome messages. Logic checks whether a conversation ID exists in our conversation reference table before triggering welcome messages.
Reading Chat History :
Used user id and bot id from context to construct chat idconversation_reference = turn_context.activity.get_conversation_reference()
user_id = conversation_reference.user.aad_object_id
bot_id = conversation_reference.bot.id
# Strip the "28:" prefix from bot_id
if bot_id and bot_id.startswith("28:"):
bot_id = bot_id[3:]
chat_id = (f"19:{user_id}_{bot_id}@unq.gbl.spaces")
messages_url = (
f"{graph_url}/me/chats/{chat_id}/messages?"
"$top=10&$orderby=createdDateTime desc"
)
messages_response = requests.get(messages_url, headers=headers)
App Validation – Proper Procedure:
For one-on-one chats, used on_members_added_activity to detect when the bot joins and trigger the welcome flow.
For other scenarios (like team channels or group chats), use on_installation_update to handle the bot's installation event. - Nivedipa-MSFT
Microsoft
Hello @ParamZ - Could you please confirm if the information above was helpful, or do you still need any additional details?
- Nivedipa-MSFT
Microsoft
Hello @ParamZ - Thanks for bringing this issue to our attention.
1.Graph API queries may generate unexpected conversationUpdate events.
Recommended Solution: Use event deduplication based on activity ID and conversation ID to avoid sending duplicate welcome messages.2.Reading Chat History – Suggested Method:
Best Practice: Save conversation references when the bot is installed, rather than polling the Graph API.
Alternative: Opt for webhooks or change notifications instead of using /me/chats queries.3.App Validation – Proper Procedure:
Primary Method: Utilize on_installation_update for sending welcome messages to meet validation requirements.
Fallback: Apply on_members_added_activity with deduplication as needed for special cases.References:
Design and control conversation flow - Bot Service | Microsoft Learn
Teams Store Validation Guidelines - Teams | Microsoft Learn
Please let us know if you have any further query here.- ParamZCopper Contributor
Thank you for the clarification.
Now I understand that for app validation, I need to keep the personal chat welcome message in on_members_added_activity and implement deduplication based on conversation ID. My planned approach is to create a database table that stores the tenant ID and conversation ID when a welcome message is sent, then remove the entry on app uninstall. This should prevent duplicate welcome messages triggered by the Graph API queries. I'll test this implementation and report back on the results.
I still have some confusion about point 2 regarding reading chat history using conversation references. From my testing, the conversation reference and chat ID appear to be different for one-to-one chats. Could you point me to sample code or detailed documentation on this topic? (Ideally showing how to use conversation references to get chat history).Thank you for your support.