Send activity feed notifications to users in Microsoft Teams
Cikk
The Microsoft Teams activity feed notifies users of changes to enable them to triage items that require attention. Activity feed notifications in Teams include the following features:
Native integration with Teams that brings the user seamlessly into the Tab app and provides additional user engagement from the Teams Activity pane to your app.
Operating system notifications in Teams desktop and mobile clients that include a pop-up and sound.
Customizable notification content that enables you to show more or less preview content to the user.
Ability to deep link your tab, personal app, bot message, or Adaptive Card to a notification to increase user engagement with your app.
Ability to send activity feed notifications to multiple recipients, such as batch notifications to a group of users.
You can use the activity feed notification APIs in Microsoft Graph to extend this functionality to your apps. In this way, you can provide richer experiences and engage users by helping them stay up to date with changes in the tools and workflows they use.
The activity feed notification APIs in Microsoft Graph enable the following use cases:
News - Keep users updated with the latest information, such as new assignments or new posts.
Collaboration - Show users a preview in the notification banner when someone shares a file or @ mentions them in a comment.
Reminders - Send notifications to users about events or tasks.
Alerts - Send notifications that require urgent or immediate attention, such as a past due date or high priority work item.
You can use activity feed notifications to do the following:
Notify individuals about customized content that requires their attention.
Show rich content in a Tab app or URL.
Support complex user interactions.
Send delegated notifications from the user who initiated a notification.
Teams handles the localization for notifications.
Components of activity feed notifications
Activity feed notifications in Teams are comprised of multiple pieces of information displayed together, as shown in the following image.
The following table describes the components.
Component
Description
Avatar
Shows who initiated the activity.
Activity type or app icon
The type of activity. For app notifications, the line icon is replaced with an app icon.
Title: Actor + reason
Actor is the name of the user or app that initiated the activity. Reason describes the activity.
Timestamp
Shows when the activity happened.
Text preview
Shows a truncated line from the start of the notification.
Topic
Associated resource or the text value of the topic from the request body.
The following image shows an example of an activity feed notification in Teams. In this example, a user shared a post in an app.
Types of activity feed notification cards
The following tabs show the types of activity feed notification cards that you can display. For app-generated notifications, the user logo is replaced with the app logo.
Requirements for using the activity feed notification APIs
Activity feed APIs work with a Teams app. The following are the requirements for sending activity feed notifications:
The Teams app manifest must have the Microsoft Entra app ID added to the webApplicationInfo section. For more information, see manifest schema.
Activity notifications can be sent with or without activity types declared in the app manifest.
By default, you can use the activity notification APIs without declaring the activities section in the manifest. The systemDefault activity type is reserved, allowing you to provide free-form text in the Actor+Reason line of the activity feed notification. For more information, see Send customizable activity feed notifications.
If you want to send a templated notification in the traditional mode, activity types must be declared in the Activities section. For more information, see Manifest schema.
The Teams app must be installed for the recipient, either personally or in a team or chat they're part of. For more information, see Teams app installation.
Permissions
You can use delegated or application permissions to send activity notifications. When you use application permissions, we recommend that you use resource-specific consent (RSC) because the TeamsActivity.Send.User permission allows the user to consent to send activity notifications. You must declare RSC permissions in your Teams app manifest schema.
Teams app manifest updates
This section describes the changes that you need to make to the Teams app manifest to implement activity feed notifications. You need to use the Teams app manifest version 1.7 or greater.
Resource associated with the Azure AD app. It is also known as a reply or redirect URI in the Microsoft Entra admin center app registration overview.
Note
You might get an error if multiple Teams apps in the same scope (team, chat, or user) use the same Microsoft Entra app. Make sure that you're using unique Microsoft Entra apps.
Activities update
You must define the activities property in your app manifest to post a user activity feed.
"activities":
{
"activityTypes": [
{
"type": "taskCreated",
"description": "Task Created Activity",
"templateText": "{actor} created task {taskId} for you"
},
{
"type": "approvalRequired",
"description": "Deployment requires your approval",
"templateText": "{actor} created a new deployment {deploymentId}"
}
]
}
Parameter
Type
Description
type
string
The type needs to be unique in a specific manifest.
description
string
Human-readable short description. The description is visible on the Microsoft Teams client.
templateText
string
Template text for the activity notification. You can declare your parameters by encapsulating parameters in curly brackets {}.
Note
actor is a special parameter that always takes the caller's name. In delegated calls, actor is the user's name. In application-only calls, it takes the name of the Teams app.
The reserved systemDefault activity type should not be provided in the activities section of the manifest. The reserved activity type can provide free-form text in the Actor+Reason line of the activity feed notification. For more information, see Send customizable activity feed notifications.
Teams apps can be installed in a team, a chat, or for a user personally, and can be distributed in multiple ways. For details, see Teams app distribution methods. Typically, sideloading is preferred for development purposes. After development, you can choose the right distribution method based on whether you want to distribute to one tenant or all tenants.
To show activity feed notifications on iOS and Android clients, the app must be included in the allow list. Only third-party apps are supported.
Because a Teams app can be installed for a user, in a team, or in a chat, the notifications can be sent in three contexts. For details about how to send notifications in each context, see the following topics:
For details about what topics are supported for each scenario, see the specific APIs. Custom text-based topics are supported for all scenarios.
Note
The activity icon is based on the context in which the request is made. If the request is made with delegated permissions, the user's photo appears as the avatar, while the Teams app icon appears as the activity icon. In an application-only context, the Teams app icon is used as the avatar, and the activity icon is omitted.
Example 1: Notify a user about a task created in a chat
The following example shows how you can send an activity feed notification for a new task created in a chat. In this case, the Teams app must be installed in a chat with Id chatId and user 569363e2-4e49-4661-87f2-16f245c5d66a must also be part of the chat.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Chats.Item.SendActivityNotification;
using Microsoft.Graph.Models;
var requestBody = new SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.EntityUrl,
Value = "https://graph.microsoft.com/v1.0/chats/{chatId}",
},
ActivityType = "taskCreated",
PreviewText = new ItemBody
{
Content = "New Task Created",
},
Recipient = new AadUserNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
UserId = "569363e2-4e49-4661-87f2-16f245c5d66a",
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "taskId",
Value = "12322",
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Chats["{chat-id}"].SendActivityNotification.PostAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.chats.item.sendactivitynotification.SendActivityNotificationPostRequestBody sendActivityNotificationPostRequestBody = new com.microsoft.graph.chats.item.sendactivitynotification.SendActivityNotificationPostRequestBody();
TeamworkActivityTopic topic = new TeamworkActivityTopic();
topic.setSource(TeamworkActivityTopicSource.EntityUrl);
topic.setValue("https://graph.microsoft.com/v1.0/chats/{chatId}");
sendActivityNotificationPostRequestBody.setTopic(topic);
sendActivityNotificationPostRequestBody.setActivityType("taskCreated");
ItemBody previewText = new ItemBody();
previewText.setContent("New Task Created");
sendActivityNotificationPostRequestBody.setPreviewText(previewText);
AadUserNotificationRecipient recipient = new AadUserNotificationRecipient();
recipient.setOdataType("microsoft.graph.aadUserNotificationRecipient");
recipient.setUserId("569363e2-4e49-4661-87f2-16f245c5d66a");
sendActivityNotificationPostRequestBody.setRecipient(recipient);
LinkedList<KeyValuePair> templateParameters = new LinkedList<KeyValuePair>();
KeyValuePair keyValuePair = new KeyValuePair();
keyValuePair.setName("taskId");
keyValuePair.setValue("12322");
templateParameters.add(keyValuePair);
sendActivityNotificationPostRequestBody.setTemplateParameters(templateParameters);
graphClient.chats().byChatId("{chat-id}").sendActivityNotification().post(sendActivityNotificationPostRequestBody);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Chats\Item\SendActivityNotification\SendActivityNotificationPostRequestBody;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopic;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopicSource;
use Microsoft\Graph\Generated\Models\ItemBody;
use Microsoft\Graph\Generated\Models\AadUserNotificationRecipient;
use Microsoft\Graph\Generated\Models\KeyValuePair;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('entityUrl'));
$topic->setValue('https://graph.microsoft.com/v1.0/chats/{chatId}');
$requestBody->setTopic($topic);
$requestBody->setActivityType('taskCreated');
$previewText = new ItemBody();
$previewText->setContent('New Task Created');
$requestBody->setPreviewText($previewText);
$recipient = new AadUserNotificationRecipient();
$recipient->setOdataType('microsoft.graph.aadUserNotificationRecipient');
$recipient->setUserId('569363e2-4e49-4661-87f2-16f245c5d66a');
$requestBody->setRecipient($recipient);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('taskId');
$templateParametersKeyValuePair1->setValue('12322');
$templateParametersArray []= $templateParametersKeyValuePair1;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->chats()->byChatId('chat-id')->sendActivityNotification()->post($requestBody)->wait();
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.chats.item.send_activity_notification.send_activity_notification_post_request_body import SendActivityNotificationPostRequestBody
from msgraph.generated.models.teamwork_activity_topic import TeamworkActivityTopic
from msgraph.generated.models.teamwork_activity_topic_source import TeamworkActivityTopicSource
from msgraph.generated.models.item_body import ItemBody
from msgraph.generated.models.aad_user_notification_recipient import AadUserNotificationRecipient
from msgraph.generated.models.key_value_pair import KeyValuePair
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = SendActivityNotificationPostRequestBody(
topic = TeamworkActivityTopic(
source = TeamworkActivityTopicSource.EntityUrl,
value = "https://graph.microsoft.com/v1.0/chats/{chatId}",
),
activity_type = "taskCreated",
preview_text = ItemBody(
content = "New Task Created",
),
recipient = AadUserNotificationRecipient(
odata_type = "microsoft.graph.aadUserNotificationRecipient",
user_id = "569363e2-4e49-4661-87f2-16f245c5d66a",
),
template_parameters = [
KeyValuePair(
name = "taskId",
value = "12322",
),
],
)
await graph_client.chats.by_chat_id('chat-id').send_activity_notification.post(request_body)
Example 2: Notify a user about a task created in a team
The following example shows how you can send an activity feed notification for a team. This example notifies the team owner about a new task created that requires their attention.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Teams.Item.SendActivityNotification;
using Microsoft.Graph.Models;
var requestBody = new SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.EntityUrl,
Value = "https://graph.microsoft.com/v1.0/teams/{teamId}",
},
ActivityType = "taskCreated",
PreviewText = new ItemBody
{
Content = "New Task Created",
},
Recipient = new AadUserNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
UserId = "569363e2-4e49-4661-87f2-16f245c5d66a",
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "taskId",
Value = "12322",
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Teams["{team-id}"].SendActivityNotification.PostAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.teams.item.sendactivitynotification.SendActivityNotificationPostRequestBody sendActivityNotificationPostRequestBody = new com.microsoft.graph.teams.item.sendactivitynotification.SendActivityNotificationPostRequestBody();
TeamworkActivityTopic topic = new TeamworkActivityTopic();
topic.setSource(TeamworkActivityTopicSource.EntityUrl);
topic.setValue("https://graph.microsoft.com/v1.0/teams/{teamId}");
sendActivityNotificationPostRequestBody.setTopic(topic);
sendActivityNotificationPostRequestBody.setActivityType("taskCreated");
ItemBody previewText = new ItemBody();
previewText.setContent("New Task Created");
sendActivityNotificationPostRequestBody.setPreviewText(previewText);
AadUserNotificationRecipient recipient = new AadUserNotificationRecipient();
recipient.setOdataType("microsoft.graph.aadUserNotificationRecipient");
recipient.setUserId("569363e2-4e49-4661-87f2-16f245c5d66a");
sendActivityNotificationPostRequestBody.setRecipient(recipient);
LinkedList<KeyValuePair> templateParameters = new LinkedList<KeyValuePair>();
KeyValuePair keyValuePair = new KeyValuePair();
keyValuePair.setName("taskId");
keyValuePair.setValue("12322");
templateParameters.add(keyValuePair);
sendActivityNotificationPostRequestBody.setTemplateParameters(templateParameters);
graphClient.teams().byTeamId("{team-id}").sendActivityNotification().post(sendActivityNotificationPostRequestBody);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Teams\Item\SendActivityNotification\SendActivityNotificationPostRequestBody;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopic;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopicSource;
use Microsoft\Graph\Generated\Models\ItemBody;
use Microsoft\Graph\Generated\Models\AadUserNotificationRecipient;
use Microsoft\Graph\Generated\Models\KeyValuePair;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('entityUrl'));
$topic->setValue('https://graph.microsoft.com/v1.0/teams/{teamId}');
$requestBody->setTopic($topic);
$requestBody->setActivityType('taskCreated');
$previewText = new ItemBody();
$previewText->setContent('New Task Created');
$requestBody->setPreviewText($previewText);
$recipient = new AadUserNotificationRecipient();
$recipient->setOdataType('microsoft.graph.aadUserNotificationRecipient');
$recipient->setUserId('569363e2-4e49-4661-87f2-16f245c5d66a');
$requestBody->setRecipient($recipient);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('taskId');
$templateParametersKeyValuePair1->setValue('12322');
$templateParametersArray []= $templateParametersKeyValuePair1;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->teams()->byTeamId('team-id')->sendActivityNotification()->post($requestBody)->wait();
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.teams.item.send_activity_notification.send_activity_notification_post_request_body import SendActivityNotificationPostRequestBody
from msgraph.generated.models.teamwork_activity_topic import TeamworkActivityTopic
from msgraph.generated.models.teamwork_activity_topic_source import TeamworkActivityTopicSource
from msgraph.generated.models.item_body import ItemBody
from msgraph.generated.models.aad_user_notification_recipient import AadUserNotificationRecipient
from msgraph.generated.models.key_value_pair import KeyValuePair
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = SendActivityNotificationPostRequestBody(
topic = TeamworkActivityTopic(
source = TeamworkActivityTopicSource.EntityUrl,
value = "https://graph.microsoft.com/v1.0/teams/{teamId}",
),
activity_type = "taskCreated",
preview_text = ItemBody(
content = "New Task Created",
),
recipient = AadUserNotificationRecipient(
odata_type = "microsoft.graph.aadUserNotificationRecipient",
user_id = "569363e2-4e49-4661-87f2-16f245c5d66a",
),
template_parameters = [
KeyValuePair(
name = "taskId",
value = "12322",
),
],
)
await graph_client.teams.by_team_id('team-id').send_activity_notification.post(request_body)
Example 3: Notify a user about an event using a custom topic
As the previous examples show, you can link to different team or chat aspects. However, if you want to link to an aspect that is not part of the team or Microsoft Graph doesn't represent it, or if you want to customize the name, you can set the source of the topic to text and pass in a custom value for it. Additionally, webUrl is required when you use topic source as text.
The Yammer notification example shown earlier uses a custom topic because Microsoft Graph does not support Yammer's resources.
Note
webUrl must start with the Microsoft Teams domain (teams.microsoft.com, for example).
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Teams.Item.SendActivityNotification;
using Microsoft.Graph.Models;
var requestBody = new SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.Text,
Value = "Deployment Approvals Channel",
WebUrl = "https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000",
},
ActivityType = "approvalRequired",
PreviewText = new ItemBody
{
Content = "New deployment requires your approval",
},
Recipient = new AadUserNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
UserId = "569363e2-4e49-4661-87f2-16f245c5d66a",
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "deploymentId",
Value = "6788662",
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Teams["{team-id}"].SendActivityNotification.PostAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.teams.item.sendactivitynotification.SendActivityNotificationPostRequestBody sendActivityNotificationPostRequestBody = new com.microsoft.graph.teams.item.sendactivitynotification.SendActivityNotificationPostRequestBody();
TeamworkActivityTopic topic = new TeamworkActivityTopic();
topic.setSource(TeamworkActivityTopicSource.Text);
topic.setValue("Deployment Approvals Channel");
topic.setWebUrl("https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000");
sendActivityNotificationPostRequestBody.setTopic(topic);
sendActivityNotificationPostRequestBody.setActivityType("approvalRequired");
ItemBody previewText = new ItemBody();
previewText.setContent("New deployment requires your approval");
sendActivityNotificationPostRequestBody.setPreviewText(previewText);
AadUserNotificationRecipient recipient = new AadUserNotificationRecipient();
recipient.setOdataType("microsoft.graph.aadUserNotificationRecipient");
recipient.setUserId("569363e2-4e49-4661-87f2-16f245c5d66a");
sendActivityNotificationPostRequestBody.setRecipient(recipient);
LinkedList<KeyValuePair> templateParameters = new LinkedList<KeyValuePair>();
KeyValuePair keyValuePair = new KeyValuePair();
keyValuePair.setName("deploymentId");
keyValuePair.setValue("6788662");
templateParameters.add(keyValuePair);
sendActivityNotificationPostRequestBody.setTemplateParameters(templateParameters);
graphClient.teams().byTeamId("{team-id}").sendActivityNotification().post(sendActivityNotificationPostRequestBody);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Teams\Item\SendActivityNotification\SendActivityNotificationPostRequestBody;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopic;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopicSource;
use Microsoft\Graph\Generated\Models\ItemBody;
use Microsoft\Graph\Generated\Models\AadUserNotificationRecipient;
use Microsoft\Graph\Generated\Models\KeyValuePair;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('text'));
$topic->setValue('Deployment Approvals Channel');
$topic->setWebUrl('https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000');
$requestBody->setTopic($topic);
$requestBody->setActivityType('approvalRequired');
$previewText = new ItemBody();
$previewText->setContent('New deployment requires your approval');
$requestBody->setPreviewText($previewText);
$recipient = new AadUserNotificationRecipient();
$recipient->setOdataType('microsoft.graph.aadUserNotificationRecipient');
$recipient->setUserId('569363e2-4e49-4661-87f2-16f245c5d66a');
$requestBody->setRecipient($recipient);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('deploymentId');
$templateParametersKeyValuePair1->setValue('6788662');
$templateParametersArray []= $templateParametersKeyValuePair1;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->teams()->byTeamId('team-id')->sendActivityNotification()->post($requestBody)->wait();
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.teams.item.send_activity_notification.send_activity_notification_post_request_body import SendActivityNotificationPostRequestBody
from msgraph.generated.models.teamwork_activity_topic import TeamworkActivityTopic
from msgraph.generated.models.teamwork_activity_topic_source import TeamworkActivityTopicSource
from msgraph.generated.models.item_body import ItemBody
from msgraph.generated.models.aad_user_notification_recipient import AadUserNotificationRecipient
from msgraph.generated.models.key_value_pair import KeyValuePair
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = SendActivityNotificationPostRequestBody(
topic = TeamworkActivityTopic(
source = TeamworkActivityTopicSource.Text,
value = "Deployment Approvals Channel",
web_url = "https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000",
),
activity_type = "approvalRequired",
preview_text = ItemBody(
content = "New deployment requires your approval",
),
recipient = AadUserNotificationRecipient(
odata_type = "microsoft.graph.aadUserNotificationRecipient",
user_id = "569363e2-4e49-4661-87f2-16f245c5d66a",
),
template_parameters = [
KeyValuePair(
name = "deploymentId",
value = "6788662",
),
],
)
await graph_client.teams.by_team_id('team-id').send_activity_notification.post(request_body)
The following example shows how you can send an activity feed notification to all team members. This example notifies the team members about a new event.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Teams.Item.SendActivityNotification;
using Microsoft.Graph.Models;
var requestBody = new SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.Text,
Value = "Weekly Virtual Social",
WebUrl = "https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000",
},
PreviewText = new ItemBody
{
Content = "It will be fun!",
},
ActivityType = "eventCreated",
Recipient = new TeamMembersNotificationRecipient
{
OdataType = "microsoft.graph.teamMembersNotificationRecipient",
TeamId = "7155e3c8-175e-4311-97ef-572edc3aa3db",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Teams["{team-id}"].SendActivityNotification.PostAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.teams.item.sendactivitynotification.SendActivityNotificationPostRequestBody sendActivityNotificationPostRequestBody = new com.microsoft.graph.teams.item.sendactivitynotification.SendActivityNotificationPostRequestBody();
TeamworkActivityTopic topic = new TeamworkActivityTopic();
topic.setSource(TeamworkActivityTopicSource.Text);
topic.setValue("Weekly Virtual Social");
topic.setWebUrl("https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000");
sendActivityNotificationPostRequestBody.setTopic(topic);
ItemBody previewText = new ItemBody();
previewText.setContent("It will be fun!");
sendActivityNotificationPostRequestBody.setPreviewText(previewText);
sendActivityNotificationPostRequestBody.setActivityType("eventCreated");
TeamMembersNotificationRecipient recipient = new TeamMembersNotificationRecipient();
recipient.setOdataType("microsoft.graph.teamMembersNotificationRecipient");
recipient.setTeamId("7155e3c8-175e-4311-97ef-572edc3aa3db");
sendActivityNotificationPostRequestBody.setRecipient(recipient);
graphClient.teams().byTeamId("{team-id}").sendActivityNotification().post(sendActivityNotificationPostRequestBody);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Teams\Item\SendActivityNotification\SendActivityNotificationPostRequestBody;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopic;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopicSource;
use Microsoft\Graph\Generated\Models\ItemBody;
use Microsoft\Graph\Generated\Models\TeamMembersNotificationRecipient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('text'));
$topic->setValue('Weekly Virtual Social');
$topic->setWebUrl('https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000');
$requestBody->setTopic($topic);
$previewText = new ItemBody();
$previewText->setContent('It will be fun!');
$requestBody->setPreviewText($previewText);
$requestBody->setActivityType('eventCreated');
$recipient = new TeamMembersNotificationRecipient();
$recipient->setOdataType('microsoft.graph.teamMembersNotificationRecipient');
$recipient->setTeamId('7155e3c8-175e-4311-97ef-572edc3aa3db');
$requestBody->setRecipient($recipient);
$graphServiceClient->teams()->byTeamId('team-id')->sendActivityNotification()->post($requestBody)->wait();
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.teams.item.send_activity_notification.send_activity_notification_post_request_body import SendActivityNotificationPostRequestBody
from msgraph.generated.models.teamwork_activity_topic import TeamworkActivityTopic
from msgraph.generated.models.teamwork_activity_topic_source import TeamworkActivityTopicSource
from msgraph.generated.models.item_body import ItemBody
from msgraph.generated.models.team_members_notification_recipient import TeamMembersNotificationRecipient
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = SendActivityNotificationPostRequestBody(
topic = TeamworkActivityTopic(
source = TeamworkActivityTopicSource.Text,
value = "Weekly Virtual Social",
web_url = "https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000",
),
preview_text = ItemBody(
content = "It will be fun!",
),
activity_type = "eventCreated",
recipient = TeamMembersNotificationRecipient(
odata_type = "microsoft.graph.teamMembersNotificationRecipient",
team_id = "7155e3c8-175e-4311-97ef-572edc3aa3db",
),
)
await graph_client.teams.by_team_id('team-id').send_activity_notification.post(request_body)
Example 5: Notify the channel members about an event
The following example shows how you can send an activity feed notification to all channel members. This example notifies the channel members about a new event.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Teams.Item.SendActivityNotification;
using Microsoft.Graph.Models;
var requestBody = new SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.Text,
Value = "Weekly Virtual Social",
WebUrl = "https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000",
},
PreviewText = new ItemBody
{
Content = "It will be fun!",
},
ActivityType = "eventCreated",
Recipient = new ChannelMembersNotificationRecipient
{
OdataType = "microsoft.graph.channelMembersNotificationRecipient",
TeamId = "7155e3c8-175e-4311-97ef-572edc3aa3db",
ChannelId = "19:0ea5de04de4743bcb4cd20cb99235d99@thread.tacv2",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Teams["{team-id}"].SendActivityNotification.PostAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.teams.item.sendactivitynotification.SendActivityNotificationPostRequestBody sendActivityNotificationPostRequestBody = new com.microsoft.graph.teams.item.sendactivitynotification.SendActivityNotificationPostRequestBody();
TeamworkActivityTopic topic = new TeamworkActivityTopic();
topic.setSource(TeamworkActivityTopicSource.Text);
topic.setValue("Weekly Virtual Social");
topic.setWebUrl("https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000");
sendActivityNotificationPostRequestBody.setTopic(topic);
ItemBody previewText = new ItemBody();
previewText.setContent("It will be fun!");
sendActivityNotificationPostRequestBody.setPreviewText(previewText);
sendActivityNotificationPostRequestBody.setActivityType("eventCreated");
ChannelMembersNotificationRecipient recipient = new ChannelMembersNotificationRecipient();
recipient.setOdataType("microsoft.graph.channelMembersNotificationRecipient");
recipient.setTeamId("7155e3c8-175e-4311-97ef-572edc3aa3db");
recipient.setChannelId("19:0ea5de04de4743bcb4cd20cb99235d99@thread.tacv2");
sendActivityNotificationPostRequestBody.setRecipient(recipient);
graphClient.teams().byTeamId("{team-id}").sendActivityNotification().post(sendActivityNotificationPostRequestBody);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Teams\Item\SendActivityNotification\SendActivityNotificationPostRequestBody;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopic;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopicSource;
use Microsoft\Graph\Generated\Models\ItemBody;
use Microsoft\Graph\Generated\Models\ChannelMembersNotificationRecipient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('text'));
$topic->setValue('Weekly Virtual Social');
$topic->setWebUrl('https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000');
$requestBody->setTopic($topic);
$previewText = new ItemBody();
$previewText->setContent('It will be fun!');
$requestBody->setPreviewText($previewText);
$requestBody->setActivityType('eventCreated');
$recipient = new ChannelMembersNotificationRecipient();
$recipient->setOdataType('microsoft.graph.channelMembersNotificationRecipient');
$recipient->setTeamId('7155e3c8-175e-4311-97ef-572edc3aa3db');
$recipient->setChannelId('19:0ea5de04de4743bcb4cd20cb99235d99@thread.tacv2');
$requestBody->setRecipient($recipient);
$graphServiceClient->teams()->byTeamId('team-id')->sendActivityNotification()->post($requestBody)->wait();
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.teams.item.send_activity_notification.send_activity_notification_post_request_body import SendActivityNotificationPostRequestBody
from msgraph.generated.models.teamwork_activity_topic import TeamworkActivityTopic
from msgraph.generated.models.teamwork_activity_topic_source import TeamworkActivityTopicSource
from msgraph.generated.models.item_body import ItemBody
from msgraph.generated.models.channel_members_notification_recipient import ChannelMembersNotificationRecipient
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = SendActivityNotificationPostRequestBody(
topic = TeamworkActivityTopic(
source = TeamworkActivityTopicSource.Text,
value = "Weekly Virtual Social",
web_url = "https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000",
),
preview_text = ItemBody(
content = "It will be fun!",
),
activity_type = "eventCreated",
recipient = ChannelMembersNotificationRecipient(
odata_type = "microsoft.graph.channelMembersNotificationRecipient",
team_id = "7155e3c8-175e-4311-97ef-572edc3aa3db",
channel_id = "19:0ea5de04de4743bcb4cd20cb99235d99@thread.tacv2",
),
)
await graph_client.teams.by_team_id('team-id').send_activity_notification.post(request_body)
The following example shows how you can send an activity feed notification to all chat members. This example notifies the chat members about a new event.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Chats.Item.SendActivityNotification;
using Microsoft.Graph.Models;
var requestBody = new SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.Text,
Value = "Weekly Virtual Social",
WebUrl = "https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000",
},
PreviewText = new ItemBody
{
Content = "It will be fun!",
},
ActivityType = "eventCreated",
Recipient = new ChatMembersNotificationRecipient
{
OdataType = "microsoft.graph.chatMembersNotificationRecipient",
ChatId = "19:d65713bc498c4a428c71ef9353e6ce20@thread.v2",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Chats["{chat-id}"].SendActivityNotification.PostAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.chats.item.sendactivitynotification.SendActivityNotificationPostRequestBody sendActivityNotificationPostRequestBody = new com.microsoft.graph.chats.item.sendactivitynotification.SendActivityNotificationPostRequestBody();
TeamworkActivityTopic topic = new TeamworkActivityTopic();
topic.setSource(TeamworkActivityTopicSource.Text);
topic.setValue("Weekly Virtual Social");
topic.setWebUrl("https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000");
sendActivityNotificationPostRequestBody.setTopic(topic);
ItemBody previewText = new ItemBody();
previewText.setContent("It will be fun!");
sendActivityNotificationPostRequestBody.setPreviewText(previewText);
sendActivityNotificationPostRequestBody.setActivityType("eventCreated");
ChatMembersNotificationRecipient recipient = new ChatMembersNotificationRecipient();
recipient.setOdataType("microsoft.graph.chatMembersNotificationRecipient");
recipient.setChatId("19:d65713bc498c4a428c71ef9353e6ce20@thread.v2");
sendActivityNotificationPostRequestBody.setRecipient(recipient);
graphClient.chats().byChatId("{chat-id}").sendActivityNotification().post(sendActivityNotificationPostRequestBody);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Chats\Item\SendActivityNotification\SendActivityNotificationPostRequestBody;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopic;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopicSource;
use Microsoft\Graph\Generated\Models\ItemBody;
use Microsoft\Graph\Generated\Models\ChatMembersNotificationRecipient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('text'));
$topic->setValue('Weekly Virtual Social');
$topic->setWebUrl('https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000');
$requestBody->setTopic($topic);
$previewText = new ItemBody();
$previewText->setContent('It will be fun!');
$requestBody->setPreviewText($previewText);
$requestBody->setActivityType('eventCreated');
$recipient = new ChatMembersNotificationRecipient();
$recipient->setOdataType('microsoft.graph.chatMembersNotificationRecipient');
$recipient->setChatId('19:d65713bc498c4a428c71ef9353e6ce20@thread.v2');
$requestBody->setRecipient($recipient);
$graphServiceClient->chats()->byChatId('chat-id')->sendActivityNotification()->post($requestBody)->wait();
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.chats.item.send_activity_notification.send_activity_notification_post_request_body import SendActivityNotificationPostRequestBody
from msgraph.generated.models.teamwork_activity_topic import TeamworkActivityTopic
from msgraph.generated.models.teamwork_activity_topic_source import TeamworkActivityTopicSource
from msgraph.generated.models.item_body import ItemBody
from msgraph.generated.models.chat_members_notification_recipient import ChatMembersNotificationRecipient
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = SendActivityNotificationPostRequestBody(
topic = TeamworkActivityTopic(
source = TeamworkActivityTopicSource.Text,
value = "Weekly Virtual Social",
web_url = "https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000",
),
preview_text = ItemBody(
content = "It will be fun!",
),
activity_type = "eventCreated",
recipient = ChatMembersNotificationRecipient(
odata_type = "microsoft.graph.chatMembersNotificationRecipient",
chat_id = "19:d65713bc498c4a428c71ef9353e6ce20@thread.v2",
),
)
await graph_client.chats.by_chat_id('chat-id').send_activity_notification.post(request_body)
Example 7: Notify multiple users about pending finance approval requests
The following example shows how to send an activity feed notification to multiple users in bulk. This example notifies multiple stakeholders about pending finance approval requests.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Teamwork.SendActivityNotificationToRecipients;
using Microsoft.Graph.Models;
var requestBody = new SendActivityNotificationToRecipientsPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.EntityUrl,
Value = "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/{teamsAppId}",
},
ActivityType = "pendingFinanceApprovalRequests",
PreviewText = new ItemBody
{
Content = "Internal spending team has a pending finance approval requests",
},
Recipients = new List<TeamworkNotificationRecipient>
{
new AadUserNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
UserId = "569363e2-4e49-4661-87f2-16f245c5d66a",
},
new AadUserNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
UserId = "ab88234e-0874-477c-9638-d144296ed04f",
},
new AadUserNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
UserId = "01c64f53-69aa-42c7-9b7f-9f75195d6bfc",
},
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "pendingRequestCount",
Value = "5",
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Teamwork.SendActivityNotificationToRecipients.PostAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.teamwork.sendactivitynotificationtorecipients.SendActivityNotificationToRecipientsPostRequestBody sendActivityNotificationToRecipientsPostRequestBody = new com.microsoft.graph.teamwork.sendactivitynotificationtorecipients.SendActivityNotificationToRecipientsPostRequestBody();
TeamworkActivityTopic topic = new TeamworkActivityTopic();
topic.setSource(TeamworkActivityTopicSource.EntityUrl);
topic.setValue("https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/{teamsAppId}");
sendActivityNotificationToRecipientsPostRequestBody.setTopic(topic);
sendActivityNotificationToRecipientsPostRequestBody.setActivityType("pendingFinanceApprovalRequests");
ItemBody previewText = new ItemBody();
previewText.setContent("Internal spending team has a pending finance approval requests");
sendActivityNotificationToRecipientsPostRequestBody.setPreviewText(previewText);
LinkedList<TeamworkNotificationRecipient> recipients = new LinkedList<TeamworkNotificationRecipient>();
AadUserNotificationRecipient teamworkNotificationRecipient = new AadUserNotificationRecipient();
teamworkNotificationRecipient.setOdataType("microsoft.graph.aadUserNotificationRecipient");
teamworkNotificationRecipient.setUserId("569363e2-4e49-4661-87f2-16f245c5d66a");
recipients.add(teamworkNotificationRecipient);
AadUserNotificationRecipient teamworkNotificationRecipient1 = new AadUserNotificationRecipient();
teamworkNotificationRecipient1.setOdataType("microsoft.graph.aadUserNotificationRecipient");
teamworkNotificationRecipient1.setUserId("ab88234e-0874-477c-9638-d144296ed04f");
recipients.add(teamworkNotificationRecipient1);
AadUserNotificationRecipient teamworkNotificationRecipient2 = new AadUserNotificationRecipient();
teamworkNotificationRecipient2.setOdataType("microsoft.graph.aadUserNotificationRecipient");
teamworkNotificationRecipient2.setUserId("01c64f53-69aa-42c7-9b7f-9f75195d6bfc");
recipients.add(teamworkNotificationRecipient2);
sendActivityNotificationToRecipientsPostRequestBody.setRecipients(recipients);
LinkedList<KeyValuePair> templateParameters = new LinkedList<KeyValuePair>();
KeyValuePair keyValuePair = new KeyValuePair();
keyValuePair.setName("pendingRequestCount");
keyValuePair.setValue("5");
templateParameters.add(keyValuePair);
sendActivityNotificationToRecipientsPostRequestBody.setTemplateParameters(templateParameters);
graphClient.teamwork().sendActivityNotificationToRecipients().post(sendActivityNotificationToRecipientsPostRequestBody);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Teamwork\SendActivityNotificationToRecipients\SendActivityNotificationToRecipientsPostRequestBody;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopic;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopicSource;
use Microsoft\Graph\Generated\Models\ItemBody;
use Microsoft\Graph\Generated\Models\TeamworkNotificationRecipient;
use Microsoft\Graph\Generated\Models\AadUserNotificationRecipient;
use Microsoft\Graph\Generated\Models\KeyValuePair;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new SendActivityNotificationToRecipientsPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('entityUrl'));
$topic->setValue('https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/{teamsAppId}');
$requestBody->setTopic($topic);
$requestBody->setActivityType('pendingFinanceApprovalRequests');
$previewText = new ItemBody();
$previewText->setContent('Internal spending team has a pending finance approval requests');
$requestBody->setPreviewText($previewText);
$recipientsTeamworkNotificationRecipient1 = new AadUserNotificationRecipient();
$recipientsTeamworkNotificationRecipient1->setOdataType('microsoft.graph.aadUserNotificationRecipient');
$recipientsTeamworkNotificationRecipient1->setUserId('569363e2-4e49-4661-87f2-16f245c5d66a');
$recipientsArray []= $recipientsTeamworkNotificationRecipient1;
$recipientsTeamworkNotificationRecipient2 = new AadUserNotificationRecipient();
$recipientsTeamworkNotificationRecipient2->setOdataType('microsoft.graph.aadUserNotificationRecipient');
$recipientsTeamworkNotificationRecipient2->setUserId('ab88234e-0874-477c-9638-d144296ed04f');
$recipientsArray []= $recipientsTeamworkNotificationRecipient2;
$recipientsTeamworkNotificationRecipient3 = new AadUserNotificationRecipient();
$recipientsTeamworkNotificationRecipient3->setOdataType('microsoft.graph.aadUserNotificationRecipient');
$recipientsTeamworkNotificationRecipient3->setUserId('01c64f53-69aa-42c7-9b7f-9f75195d6bfc');
$recipientsArray []= $recipientsTeamworkNotificationRecipient3;
$requestBody->setRecipients($recipientsArray);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('pendingRequestCount');
$templateParametersKeyValuePair1->setValue('5');
$templateParametersArray []= $templateParametersKeyValuePair1;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->teamwork()->sendActivityNotificationToRecipients()->post($requestBody)->wait();
Example 8: Send a notification to a user using the systemDefault activity type
The following example shows how you can send an activity notification for a team without activity types defined in the manifest. You have the flexibility to provide free-form text here. For more information, see Reserved activity types.
This example notifies the team owner to take a short break. Modify the value in templateParameters to customize the notification for various scenarios.
POST https://graph.microsoft.com/v1.0/teams/{teamId}/sendActivityNotification
Content-Type: application/json
{
"topic": {
"source": "entityUrl",
"value": "https://graph.microsoft.com/v1.0/teams/{teamId}"
},
"activityType": "systemDefault",
"previewText": {
"content": "Take a break"
},
"recipient": {
"@odata.type": "microsoft.graph.aadUserNotificationRecipient",
"userId": "569363e2-4e49-4661-87f2-16f245c5d66a"
},
"templateParameters": [
{
"name": "systemDefaultText",
"value": "You need to take a short break"
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Teams.Item.SendActivityNotification;
using Microsoft.Graph.Models;
var requestBody = new SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.EntityUrl,
Value = "https://graph.microsoft.com/v1.0/teams/{teamId}",
},
ActivityType = "systemDefault",
PreviewText = new ItemBody
{
Content = "Take a break",
},
Recipient = new AadUserNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
UserId = "569363e2-4e49-4661-87f2-16f245c5d66a",
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "systemDefaultText",
Value = "You need to take a short break",
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Teams["{team-id}"].SendActivityNotification.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphteams "github.com/microsoftgraph/msgraph-sdk-go/teams"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphteams.NewSendActivityNotificationPostRequestBody()
topic := graphmodels.NewTeamworkActivityTopic()
source := graphmodels.ENTITYURL_TEAMWORKACTIVITYTOPICSOURCE
topic.SetSource(&source)
value := "https://graph.microsoft.com/v1.0/teams/{teamId}"
topic.SetValue(&value)
requestBody.SetTopic(topic)
activityType := "systemDefault"
requestBody.SetActivityType(&activityType)
previewText := graphmodels.NewItemBody()
content := "Take a break"
previewText.SetContent(&content)
requestBody.SetPreviewText(previewText)
recipient := graphmodels.NewAadUserNotificationRecipient()
userId := "569363e2-4e49-4661-87f2-16f245c5d66a"
recipient.SetUserId(&userId)
requestBody.SetRecipient(recipient)
keyValuePair := graphmodels.NewKeyValuePair()
name := "systemDefaultText"
keyValuePair.SetName(&name)
value := "You need to take a short break"
keyValuePair.SetValue(&value)
templateParameters := []graphmodels.KeyValuePairable {
keyValuePair,
}
requestBody.SetTemplateParameters(templateParameters)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
graphClient.Teams().ByTeamId("team-id").SendActivityNotification().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.teams.item.sendactivitynotification.SendActivityNotificationPostRequestBody sendActivityNotificationPostRequestBody = new com.microsoft.graph.teams.item.sendactivitynotification.SendActivityNotificationPostRequestBody();
TeamworkActivityTopic topic = new TeamworkActivityTopic();
topic.setSource(TeamworkActivityTopicSource.EntityUrl);
topic.setValue("https://graph.microsoft.com/v1.0/teams/{teamId}");
sendActivityNotificationPostRequestBody.setTopic(topic);
sendActivityNotificationPostRequestBody.setActivityType("systemDefault");
ItemBody previewText = new ItemBody();
previewText.setContent("Take a break");
sendActivityNotificationPostRequestBody.setPreviewText(previewText);
AadUserNotificationRecipient recipient = new AadUserNotificationRecipient();
recipient.setOdataType("microsoft.graph.aadUserNotificationRecipient");
recipient.setUserId("569363e2-4e49-4661-87f2-16f245c5d66a");
sendActivityNotificationPostRequestBody.setRecipient(recipient);
LinkedList<KeyValuePair> templateParameters = new LinkedList<KeyValuePair>();
KeyValuePair keyValuePair = new KeyValuePair();
keyValuePair.setName("systemDefaultText");
keyValuePair.setValue("You need to take a short break");
templateParameters.add(keyValuePair);
sendActivityNotificationPostRequestBody.setTemplateParameters(templateParameters);
graphClient.teams().byTeamId("{team-id}").sendActivityNotification().post(sendActivityNotificationPostRequestBody);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Teams\Item\SendActivityNotification\SendActivityNotificationPostRequestBody;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopic;
use Microsoft\Graph\Generated\Models\TeamworkActivityTopicSource;
use Microsoft\Graph\Generated\Models\ItemBody;
use Microsoft\Graph\Generated\Models\AadUserNotificationRecipient;
use Microsoft\Graph\Generated\Models\KeyValuePair;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('entityUrl'));
$topic->setValue('https://graph.microsoft.com/v1.0/teams/{teamId}');
$requestBody->setTopic($topic);
$requestBody->setActivityType('systemDefault');
$previewText = new ItemBody();
$previewText->setContent('Take a break');
$requestBody->setPreviewText($previewText);
$recipient = new AadUserNotificationRecipient();
$recipient->setOdataType('microsoft.graph.aadUserNotificationRecipient');
$recipient->setUserId('569363e2-4e49-4661-87f2-16f245c5d66a');
$requestBody->setRecipient($recipient);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('systemDefaultText');
$templateParametersKeyValuePair1->setValue('You need to take a short break');
$templateParametersArray []= $templateParametersKeyValuePair1;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->teams()->byTeamId('team-id')->sendActivityNotification()->post($requestBody)->wait();
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.teams.item.send_activity_notification.send_activity_notification_post_request_body import SendActivityNotificationPostRequestBody
from msgraph.generated.models.teamwork_activity_topic import TeamworkActivityTopic
from msgraph.generated.models.teamwork_activity_topic_source import TeamworkActivityTopicSource
from msgraph.generated.models.item_body import ItemBody
from msgraph.generated.models.aad_user_notification_recipient import AadUserNotificationRecipient
from msgraph.generated.models.key_value_pair import KeyValuePair
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = SendActivityNotificationPostRequestBody(
topic = TeamworkActivityTopic(
source = TeamworkActivityTopicSource.EntityUrl,
value = "https://graph.microsoft.com/v1.0/teams/{teamId}",
),
activity_type = "systemDefault",
preview_text = ItemBody(
content = "Take a break",
),
recipient = AadUserNotificationRecipient(
odata_type = "microsoft.graph.aadUserNotificationRecipient",
user_id = "569363e2-4e49-4661-87f2-16f245c5d66a",
),
template_parameters = [
KeyValuePair(
name = "systemDefaultText",
value = "You need to take a short break",
),
],
)
await graph_client.teams.by_team_id('team-id').send_activity_notification.post(request_body)
The systemDefault activity type is reserved and can't be used in the manifest while declaring Activities. You can use the systemDefault activity type to:
Easily test new scenarios and/or quickly try the activity feed notification APIs without defining activity types in your app manifest.
For Store apps, save time and streamline the process because you don't need to constantly adjust activity types in your app manifest. The systemDefault activity type is ready to use from the get-go.
Keep in mind that with the systemDefault activity type, you can't:
Utilize the built-in localization features provided by manifests.
Rely on sending customizable notifications with the systemDefault activity type. Users can turn off all notifications from your app with a toggle in the Microsoft Teams client settings, which can hinder communication between your app and its users.
We still recommend templated notifications for recurring and large batches of notifications because they require activity templates in the manifest.
The systemDefault reserved activity type remains available, regardless of the activity types listed in your app's manifest.
Customize how the notifications alert you
Microsoft Teams users can customize the notifications they see in their feed, as a banner, and so on. Notifications generated through activity feed APIs can also be customized. Users can choose how they're notified via settings in Microsoft Teams. Teams apps appear in the list for the user to choose from, as shown in the following screenshot.
Users can choose Edit next to an app and customize the notifications, as shown in the following example. The description field in the Teams app manifest is displayed.
FAQs
Who needs to install the Teams app?
The target user must have the Teams app that is sending notifications installed.
Can a user send notifications to themselves?
No, a user can't send notifications to themselves. For this scenario, use application permissions.
Can a Teams app control how the notifications are shown to the user?
No, only users are allowed to change notification settings.
I installed my app; why don't I see notification settings under the user account?
The settings appear after the Teams app sends the first notification. This reduces the number of settings that users see.
I started getting a 409 (conflict) error; how do I resolve it?
Conflict errors primarily occur when multiple Teams apps installed in the same scope (team, chat, user, and so on) have the same Microsoft Entra appId in the webApplicationInfo section of the manifest. When this happens, you get an error like Found multiple applications with the same Microsoft Entra App ID 'Your Microsoft Entra AppId'.. Make sure that you use unique Microsoft Entra apps for unique Teams apps. You can install the same Teams app in multiple scopes (team + user, for example).