From bb251ee8566203d035e9c1d27453cba618b7b042 Mon Sep 17 00:00:00 2001 From: v-nikitach Date: Tue, 24 Mar 2026 17:16:34 +0530 Subject: [PATCH 1/8] updated code snippets and SDK reference links --- .../graph-proactive-bots-and-messages.md | 105 ++++++++++++------ 1 file changed, 74 insertions(+), 31 deletions(-) diff --git a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md index 117805e55b3..2320050d9a0 100644 --- a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md +++ b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md @@ -5,7 +5,7 @@ ms.localizationpriority: medium author: akjo ms.topic: overview ms.owner: vishachadha -ms.date: 12/15/2022 +ms.date: 03/24/2026 --- # Send proactive installation messages @@ -191,51 +191,94 @@ The following code provides an example of sending proactive messages: # [C#](#tab/dotnet) -* [SDK reference](/dotnet/api/microsoft.bot.builder.cloudadapterbase.continueconversationasync?view=botbuilder-dotnet-stable&preserve-view=true#microsoft-bot-builder-cloudadapterbase-continueconversationasync(system-string-microsoft-bot-schema-activity-microsoft-bot-builder-botcallbackhandler-system-threading-cancellationtoken)) +*[SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=csharp) * [Sample code reference](https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/graph-meeting-notification/csharp/MeetingNotification/Controllers/NotificationController.cs#L112) ```csharp -public async Task SendNotificationToAllUsersAsync(ITurnContext turnContext, CancellationToken cancellationToken) -{ - int msgSentCount = 0; +using Microsoft.Teams.Api; +using Microsoft.Teams.Apps; - // Send notification to all the members. - foreach (var conversationReference in _conversationReferences.Values) - { - await turnContext.Adapter.ContinueConversationAsync(_configuration["MicrosoftAppId"], conversationReference, BotCallback, cancellationToken); - msgSentCount++; - } +// Store conversation IDs (e.g., during install event) - return msgSentCount; -} +var conversationStorage = new Dictionary(); +app.OnInstall(async context => +{ + var userId = context.Activity.From.AadObjectId; + var conversationId = context.Activity.Conversation.Id; + conversationStorage[userId] = conversationId; + await context.Send("Hi! I will send you proactive notifications."); +}); -private async Task BotCallback(ITurnContext turnContext, CancellationToken cancellationToken) -{ - // Sends an activity to the sender of the incoming activity. - await turnContext.SendActivityAsync("Proactive hello."); -} +// Send proactive message from anywhere + +public static async Task SendProactiveNotification(string userId) +{ + var conversationId = conversationStorage.GetValueOrDefault(userId); + if (conversationId is null) return; + + await app.Send(conversationId, "Proactive hello."); +} ``` # [Node.js](#tab/nodejs) -* [SDK reference](/javascript/api/botbuilder/cloudadapter?view=botbuilder-ts-latest&preserve-view=true#botbuilder-cloudadapter-continueconversationasync) +* [SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=typescript) * [Sample code reference](https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/bot-initiate-thread-in-channel/nodejs/bots/teamsStartNewThreadInChannel.js#L20) ```javascript -server.get('/api/notify', async (req, res) => { - for (const conversationReference of Object.values(conversationReferences)) { +import { MessageActivity } from '@microsoft/teams.api'; +import { App } from '@microsoft/teams.apps'; - // Sends a proactive message to a conversation. - await adapter.continueConversationAsync(process.env.MicrosoftAppId, conversationReference, async context => { - await context.sendActivity('proactive hello'); - }); - } - res.setHeader('Content-Type', 'text/html'); - res.writeHead(200); - res.write('

Proactive messages have been sent.

'); - res.end(); -}); +const app = new App(); + +// Store conversation IDs +const conversationStorage = new Map(); + + +// Capture conversation ID when app is installed +app.on('install.add', async ({ activity, send }) => { + conversationStorage.set(activity.from.aadObjectId!, activity.conversation.id); + await send('Hi! I will send you proactive notifications.'); +}); + +// Send proactive message from anywhere +const sendProactiveNotification = async (userId: string) => { + const conversationId = conversationStorage.get(userId); + if (!conversationId) return; + const activity = new MessageActivity('Proactive hello.'); + await app.send(conversationId, activity); +}; +``` + +# [Python](#tab/python) + +*[SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=typescript) + +```python +from microsoft_teams.api import MessageActivityInput +from microsoft_teams.apps import App + +app = App() + + +# Store conversation IDs +conversation_storage: dict[str, str] = {} + + +@app.on_install_add +async def handle_install(ctx): + user_id = ctx.activity.from_property.aad_object_id + conversation_storage[user_id] = ctx.activity.conversation.id + await ctx.send("Hi! I will send you proactive notifications.") + +# Send proactive message from anywhere +async def send_proactive_notification(user_id: str): + conversation_id = conversation_storage.get(user_id, "") + if not conversation_id: + return + activity = MessageActivityInput(text="Proactive hello.") + await app.send(conversation_id, activity) ``` --- From 4a7c9ca11f23ce6691deaee3e628de7ed2f0528f Mon Sep 17 00:00:00 2001 From: v-nikitach Date: Tue, 24 Mar 2026 17:29:22 +0530 Subject: [PATCH 2/8] Update graph-proactive-bots-and-messages.md --- .../graph-proactive-bots-and-messages.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md index 2320050d9a0..8f71ad6f5c6 100644 --- a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md +++ b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md @@ -191,7 +191,7 @@ The following code provides an example of sending proactive messages: # [C#](#tab/dotnet) -*[SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=csharp) +* [SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=csharp) * [Sample code reference](https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/graph-meeting-notification/csharp/MeetingNotification/Controllers/NotificationController.cs#L112) @@ -253,7 +253,7 @@ const sendProactiveNotification = async (userId: string) => { # [Python](#tab/python) -*[SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=typescript) +* [SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=typescript) ```python from microsoft_teams.api import MessageActivityInput From 464474f83667873cd660941e8ee856161450e403 Mon Sep 17 00:00:00 2001 From: v-nikitach Date: Wed, 25 Mar 2026 17:07:16 +0530 Subject: [PATCH 3/8] Made changes in the content --- .../graph-proactive-bots-and-messages.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md index 8f71ad6f5c6..723dd680a1f 100644 --- a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md +++ b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md @@ -5,7 +5,7 @@ ms.localizationpriority: medium author: akjo ms.topic: overview ms.owner: vishachadha -ms.date: 03/24/2026 +ms.date: 03/25/2026 --- # Send proactive installation messages @@ -149,7 +149,7 @@ If the user has Microsoft Teams running, app installation occurs immediately. A ### Retrieve the conversation `chatId` -When your app is installed for the user, the bot receives a `conversationUpdate` [event notification](../../resources/bot-v3/bots-notifications.md#team-member-or-bot-addition) that contains the necessary information to send the proactive message. +When your app is installed for the user, the bot receives an **install** activity. Use the `OnInstall` handler (C#) or `install.add` event (Node.js/Python) in the [Teams SDK](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging) to capture the `conversationId` needed to send the proactive message. **Microsoft Graph page reference:** [Get chat](/graph/api/chat-get?view=graph-rest-v1.0&tabs=http&preserve-view=true) @@ -183,7 +183,7 @@ When your app is installed for the user, the bot receives a `conversationUpdate` ### Send proactive messages -Your bot can [send proactive messages](/azure/bot-service/bot-builder-howto-proactive-message?view=azure-bot-service-4.0&tabs=csharp&preserve-view=true) after the bot has been added for a user or a team, and has received all the user information. +Your bot can [send proactive messages](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging) after the bot has been added for a user or a team, and has received all the user information. ## Code snippets @@ -192,7 +192,6 @@ The following code provides an example of sending proactive messages: # [C#](#tab/dotnet) * [SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=csharp) - * [Sample code reference](https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/graph-meeting-notification/csharp/MeetingNotification/Controllers/NotificationController.cs#L112) ```csharp @@ -221,12 +220,12 @@ public static async Task SendProactiveNotification(string userId) } ``` -# [Node.js](#tab/nodejs) +# [Typescript](#tab/typescript) * [SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=typescript) * [Sample code reference](https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/bot-initiate-thread-in-channel/nodejs/bots/teamsStartNewThreadInChannel.js#L20) -```javascript +```typescript import { MessageActivity } from '@microsoft/teams.api'; import { App } from '@microsoft/teams.apps'; @@ -253,7 +252,7 @@ const sendProactiveNotification = async (userId: string) => { # [Python](#tab/python) -* [SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=typescript) +* [SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=python) ```python from microsoft_teams.api import MessageActivityInput @@ -297,7 +296,7 @@ async def send_proactive_notification(user_id: str): ## See also * [Manage app setup policies in Microsoft Teams](/microsoftteams/teams-app-setup-policies#create-a-custom-app-setup-policy) -* [Send proactive notifications to users SDK v4](/azure/bot-service/bot-builder-howto-proactive-message?view=azure-bot-service-4.0&tabs=csharp&preserve-view=true) +* [Proactive messaging with Teams SDK](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging) * [Send activity feed notifications to users in Microsoft Teams](/graph/teams-send-activityfeednotifications) * [Add app to team - Microsoft Graph v1.0](/graph/api/team-post-installedapps?view=graph-rest-1.0&tabs=http&preserve-view=true) * [Microsoft Teams service limits](/graph/throttling-limits#microsoft-teams-service-limits) From 317cd9c7f05aaef09addb738281a7aa7051a0bee Mon Sep 17 00:00:00 2001 From: v-nikitach Date: Thu, 26 Mar 2026 17:22:10 +0530 Subject: [PATCH 4/8] Update graph-proactive-bots-and-messages.md --- .../graph-proactive-bots-and-messages.md | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md index 723dd680a1f..497cf99245c 100644 --- a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md +++ b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md @@ -5,7 +5,7 @@ ms.localizationpriority: medium author: akjo ms.topic: overview ms.owner: vishachadha -ms.date: 03/25/2026 +ms.date: 03/26/2026 --- # Send proactive installation messages @@ -199,7 +199,6 @@ using Microsoft.Teams.Api; using Microsoft.Teams.Apps; // Store conversation IDs (e.g., during install event) - var conversationStorage = new Dictionary(); app.OnInstall(async context => { @@ -210,12 +209,10 @@ app.OnInstall(async context => }); // Send proactive message from anywhere - public static async Task SendProactiveNotification(string userId) { var conversationId = conversationStorage.GetValueOrDefault(userId); if (conversationId is null) return; - await app.Send(conversationId, "Proactive hello."); } ``` @@ -229,12 +226,9 @@ public static async Task SendProactiveNotification(string userId) import { MessageActivity } from '@microsoft/teams.api'; import { App } from '@microsoft/teams.apps'; -const app = new App(); - // Store conversation IDs const conversationStorage = new Map(); - // Capture conversation ID when app is installed app.on('install.add', async ({ activity, send }) => { conversationStorage.set(activity.from.aadObjectId!, activity.conversation.id); @@ -258,13 +252,9 @@ const sendProactiveNotification = async (userId: string) => { from microsoft_teams.api import MessageActivityInput from microsoft_teams.apps import App -app = App() - - # Store conversation IDs conversation_storage: dict[str, str] = {} - @app.on_install_add async def handle_install(ctx): user_id = ctx.activity.from_property.aad_object_id From 9e3195ba080759e5b0266481cd43ca5d1d9d819b Mon Sep 17 00:00:00 2001 From: v-nikitach Date: Thu, 26 Mar 2026 17:44:34 +0530 Subject: [PATCH 5/8] Update graph-proactive-bots-and-messages.md --- .../graph-proactive-bots-and-messages.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md index 497cf99245c..48961d87da6 100644 --- a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md +++ b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md @@ -191,12 +191,13 @@ The following code provides an example of sending proactive messages: # [C#](#tab/dotnet) -* [SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=csharp) +* [SDK reference](https://learn.microsoft.com/en-us/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=csharp) * [Sample code reference](https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/graph-meeting-notification/csharp/MeetingNotification/Controllers/NotificationController.cs#L112) ```csharp using Microsoft.Teams.Api; using Microsoft.Teams.Apps; +// ... // Store conversation IDs (e.g., during install event) var conversationStorage = new Dictionary(); @@ -217,7 +218,7 @@ public static async Task SendProactiveNotification(string userId) } ``` -# [Typescript](#tab/typescript) +# [TypeScript](#tab/typescript) * [SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=typescript) * [Sample code reference](https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/bot-initiate-thread-in-channel/nodejs/bots/teamsStartNewThreadInChannel.js#L20) From 3d4fc24d2af1038b5feb8b087a3baed9958e7081 Mon Sep 17 00:00:00 2001 From: v-nikitach Date: Thu, 26 Mar 2026 18:06:44 +0530 Subject: [PATCH 6/8] Update graph-proactive-bots-and-messages.md --- .../graph-proactive-bots-and-messages.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md index 48961d87da6..c5e6c25f845 100644 --- a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md +++ b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md @@ -191,7 +191,7 @@ The following code provides an example of sending proactive messages: # [C#](#tab/dotnet) -* [SDK reference](https://learn.microsoft.com/en-us/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=csharp) +* [SDK reference](https://learn.microsoft.com/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=csharp) * [Sample code reference](https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/graph-meeting-notification/csharp/MeetingNotification/Controllers/NotificationController.cs#L112) ```csharp @@ -220,12 +220,13 @@ public static async Task SendProactiveNotification(string userId) # [TypeScript](#tab/typescript) -* [SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=typescript) +* [SDK reference](https://learn.microsoft.com/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=typescript) * [Sample code reference](https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/bot-initiate-thread-in-channel/nodejs/bots/teamsStartNewThreadInChannel.js#L20) ```typescript import { MessageActivity } from '@microsoft/teams.api'; import { App } from '@microsoft/teams.apps'; +// ... // Store conversation IDs const conversationStorage = new Map(); @@ -247,11 +248,12 @@ const sendProactiveNotification = async (userId: string) => { # [Python](#tab/python) -* [SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=python) +* [SDK reference](https://learn.microsoft.com/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=python) ```python from microsoft_teams.api import MessageActivityInput from microsoft_teams.apps import App +# ... # Store conversation IDs conversation_storage: dict[str, str] = {} From c4dd12cf31dc07dcd0c49a35227360673814ec31 Mon Sep 17 00:00:00 2001 From: v-nikitach Date: Thu, 26 Mar 2026 18:19:22 +0530 Subject: [PATCH 7/8] Update graph-proactive-bots-and-messages.md --- .../graph-proactive-bots-and-messages.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md index c5e6c25f845..bbd3f8a8f90 100644 --- a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md +++ b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md @@ -191,7 +191,7 @@ The following code provides an example of sending proactive messages: # [C#](#tab/dotnet) -* [SDK reference](https://learn.microsoft.com/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=csharp) +* [SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=csharp) * [Sample code reference](https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/graph-meeting-notification/csharp/MeetingNotification/Controllers/NotificationController.cs#L112) ```csharp @@ -220,7 +220,7 @@ public static async Task SendProactiveNotification(string userId) # [TypeScript](#tab/typescript) -* [SDK reference](https://learn.microsoft.com/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=typescript) +* [SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=typescript) * [Sample code reference](https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/bot-initiate-thread-in-channel/nodejs/bots/teamsStartNewThreadInChannel.js#L20) ```typescript @@ -248,7 +248,7 @@ const sendProactiveNotification = async (userId: string) => { # [Python](#tab/python) -* [SDK reference](https://learn.microsoft.com/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=python) +* [SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=python) ```python from microsoft_teams.api import MessageActivityInput From ce1719da744f73b8dbfbb5d6568475b63a9993ab Mon Sep 17 00:00:00 2001 From: v-nikitach Date: Thu, 9 Apr 2026 09:17:14 +0530 Subject: [PATCH 8/8] Update graph-proactive-bots-and-messages.md --- .../graph-proactive-bots-and-messages.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md index bbd3f8a8f90..07d798adfcf 100644 --- a/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md +++ b/msteams-platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages.md @@ -251,8 +251,8 @@ const sendProactiveNotification = async (userId: string) => { * [SDK reference](/microsoftteams/platform/teams-sdk/essentials/sending-messages/proactive-messaging?tabs=minimal&pivots=python) ```python -from microsoft_teams.api import MessageActivityInput -from microsoft_teams.apps import App +from microsoft_teams.api import InstalledActivity, MessageActivityInput +from microsoft_teams.apps import ActivityContext # ... # Store conversation IDs @@ -260,7 +260,7 @@ conversation_storage: dict[str, str] = {} @app.on_install_add async def handle_install(ctx): - user_id = ctx.activity.from_property.aad_object_id + user_id = ctx.activity.from_.aad_object_id conversation_storage[user_id] = ctx.activity.conversation.id await ctx.send("Hi! I will send you proactive notifications.")