chat: sendActivityNotification
Article
03/02/2023
17 minutes to read
8 contributors
Feedback
In this article
Namespace: microsoft.graph
Send an activity feed notification in scope of a chat. For more details about sending notifications and the requirements for doing so, see sending Teams activity notifications .
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
TeamsActivity.Send
Delegated (personal Microsoft account)
Not supported.
Application
TeamsActivity.Send
HTTP request
POST /chats/{chatId}/sendActivityNotification
Name
Description
Authorization
Bearer {token}. Required.
Content-Type
application/json. Required.
Request body
In the request body, supply JSON representation of the parameters.
The following table shows the parameters that can be used with this action.
The following resources are supported when setting the source
value of the topic property to entityURL
:
Note: The entity URL must be the same as or a child resource of the chat in the URL. Additionally, the Teams app must be installed in the chat.
Response
If successful, this action returns a 204 No Content
response code.
Examples
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. For more details, see sending Teams activity notifications .
Request
The following example shows the request.
POST https://graph.microsoft.com/v1.0/chats/{chatId}/sendActivityNotification
Content-Type: application/json
{
"topic": {
"source": "entityUrl",
"value": "https://graph.microsoft.com/v1.0/chats/{chatId}"
},
"activityType": "taskCreated",
"previewText": {
"content": "New Task Created"
},
"recipient": {
"@odata.type": "microsoft.graph.aadUserNotificationRecipient",
"userId": "569363e2-4e49-4661-87f2-16f245c5d66a"
},
"templateParameters": [
{
"name": "taskId",
"value": "Task 12322"
}
]
}
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Chats.Item.SendActivityNotification.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 TeamworkNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
AdditionalData = new Dictionary<string, object>
{
{
"userId" , "569363e2-4e49-4661-87f2-16f245c5d66a"
},
},
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "taskId",
Value = "Task 12322",
},
},
};
await graphClient.Chats["{chat-id}"].SendActivityNotification.PostAsync(requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
const options = {
authProvider,
};
const client = Client.init(options);
const sendActivityNotification = {
topic: {
source: 'entityUrl',
value: 'https://graph.microsoft.com/v1.0/chats/{chatId}'
},
activityType: 'taskCreated',
previewText: {
content: 'New Task Created'
},
recipient: {
'@odata.type': 'microsoft.graph.aadUserNotificationRecipient',
userId: '569363e2-4e49-4661-87f2-16f245c5d66a'
},
templateParameters: [
{
name: 'taskId',
value: 'Task 12322'
}
]
};
await client.api('/chats/{chatId}/sendActivityNotification')
.post(sendActivityNotification);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
TeamworkActivityTopic topic = new TeamworkActivityTopic();
topic.source = TeamworkActivityTopicSource.ENTITY_URL;
topic.value = "https://graph.microsoft.com/v1.0/chats/{chatId}";
String activityType = "taskCreated";
ItemBody previewText = new ItemBody();
previewText.content = "New Task Created";
AadUserNotificationRecipient recipient = new AadUserNotificationRecipient();
recipient.userId = "569363e2-4e49-4661-87f2-16f245c5d66a";
LinkedList<KeyValuePair> templateParametersList = new LinkedList<KeyValuePair>();
KeyValuePair templateParameters = new KeyValuePair();
templateParameters.name = "taskId";
templateParameters.value = "Task 12322";
templateParametersList.add(templateParameters);
graphClient.chats("{chatId}")
.sendActivityNotification(ChatSendActivityNotificationParameterSet
.newBuilder()
.withTopic(topic)
.withActivityType(activityType)
.withChainId(null)
.withPreviewText(previewText)
.withTemplateParameters(templateParametersList)
.withRecipient(recipient)
.build())
.buildRequest()
.post();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewSendActivityNotificationPostRequestBody()
topic := graphmodels.NewTeamworkActivityTopic()
source := graphmodels.ENTITYURL_TEAMWORKACTIVITYTOPICSOURCE
topic.SetSource(&source)
value := "https://graph.microsoft.com/v1.0/chats/{chatId}"
topic.SetValue(&value)
requestBody.SetTopic(topic)
activityType := "taskCreated"
requestBody.SetActivityType(&activityType)
previewText := graphmodels.NewItemBody()
content := "New Task Created"
previewText.SetContent(&content)
requestBody.SetPreviewText(previewText)
recipient := graphmodels.NewTeamworkNotificationRecipient()
additionalData := map[string]interface{}{
"userId" : "569363e2-4e49-4661-87f2-16f245c5d66a",
}
recipient.SetAdditionalData(additionalData)
requestBody.SetRecipient(recipient)
keyValuePair := graphmodels.NewKeyValuePair()
name := "taskId"
keyValuePair.SetName(&name)
value := "Task 12322"
keyValuePair.SetValue(&value)
templateParameters := []graphmodels.KeyValuePairable {
keyValuePair,
}
requestBody.SetTemplateParameters(templateParameters)
graphClient.ChatsById("chat-id").SendActivityNotification().Post(context.Background(), requestBody, nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Import-Module Microsoft.Graph.Teams
$params = @{
Topic = @{
Source = "entityUrl"
Value = "https://graph.microsoft.com/v1.0/chats/{chatId}"
}
ActivityType = "taskCreated"
PreviewText = @{
Content = "New Task Created"
}
Recipient = @{
"@odata.type" = "microsoft.graph.aadUserNotificationRecipient"
UserId = "569363e2-4e49-4661-87f2-16f245c5d66a"
}
TemplateParameters = @(
@{
Name = "taskId"
Value = "Task 12322"
}
)
}
Send-MgChatActivityNotification -ChatId $chatId -BodyParameter $params
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$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 TeamworkNotificationRecipient();
$recipient->set@odatatype('microsoft.graph.aadUserNotificationRecipient');
$additionalData = [
'userId' => '569363e2-4e49-4661-87f2-16f245c5d66a',
];
$recipient->setAdditionalData($additionalData);
$requestBody->setRecipient($recipient);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('taskId');
$templateParametersKeyValuePair1->setValue('Task 12322');
$templateParametersArray []= $templateParametersKeyValuePair1;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->chatsById('chat-id')->sendActivityNotification()->post($requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
The following example shows the response.
HTTP/1.1 204 No Content
Example 2: Notify a user about an approval needed in a chat message
Similar to the previous example, this example uses entityUrl
for the topic
. However, in this case, it links to a message in the chat. The message can contain a card with the approval button on it.
Request
The following example shows the request.
POST https://graph.microsoft.com/v1.0/chats/{chatId}/sendActivityNotification
Content-Type: application/json
{
"topic": {
"source": "entityUrl",
"value": "https://graph.microsoft.com/v1.0/chats/{chatId}/messages/{messageId}"
},
"activityType": "approvalRequired",
"previewText": {
"content": "Deployment requires your approval"
},
"recipient": {
"@odata.type": "microsoft.graph.aadUserNotificationRecipient",
"userId": "569363e2-4e49-4661-87f2-16f245c5d66a"
},
"templateParameters": [
{
"name": "approvalTaskId",
"value": "2020AAGGTAPP"
}
]
}
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Chats.Item.SendActivityNotification.SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.EntityUrl,
Value = "https://graph.microsoft.com/v1.0/chats/{chatId}/messages/{messageId}",
},
ActivityType = "approvalRequired",
PreviewText = new ItemBody
{
Content = "Deployment requires your approval",
},
Recipient = new TeamworkNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
AdditionalData = new Dictionary<string, object>
{
{
"userId" , "569363e2-4e49-4661-87f2-16f245c5d66a"
},
},
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "approvalTaskId",
Value = "2020AAGGTAPP",
},
},
};
await graphClient.Chats["{chat-id}"].SendActivityNotification.PostAsync(requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
const options = {
authProvider,
};
const client = Client.init(options);
const sendActivityNotification = {
topic: {
source: 'entityUrl',
value: 'https://graph.microsoft.com/v1.0/chats/{chatId}/messages/{messageId}'
},
activityType: 'approvalRequired',
previewText: {
content: 'Deployment requires your approval'
},
recipient: {
'@odata.type': 'microsoft.graph.aadUserNotificationRecipient',
userId: '569363e2-4e49-4661-87f2-16f245c5d66a'
},
templateParameters: [
{
name: 'approvalTaskId',
value: '2020AAGGTAPP'
}
]
};
await client.api('/chats/{chatId}/sendActivityNotification')
.post(sendActivityNotification);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
TeamworkActivityTopic topic = new TeamworkActivityTopic();
topic.source = TeamworkActivityTopicSource.ENTITY_URL;
topic.value = "https://graph.microsoft.com/v1.0/chats/{chatId}/messages/{messageId}";
String activityType = "approvalRequired";
ItemBody previewText = new ItemBody();
previewText.content = "Deployment requires your approval";
AadUserNotificationRecipient recipient = new AadUserNotificationRecipient();
recipient.userId = "569363e2-4e49-4661-87f2-16f245c5d66a";
LinkedList<KeyValuePair> templateParametersList = new LinkedList<KeyValuePair>();
KeyValuePair templateParameters = new KeyValuePair();
templateParameters.name = "approvalTaskId";
templateParameters.value = "2020AAGGTAPP";
templateParametersList.add(templateParameters);
graphClient.chats("{chatId}")
.sendActivityNotification(ChatSendActivityNotificationParameterSet
.newBuilder()
.withTopic(topic)
.withActivityType(activityType)
.withChainId(null)
.withPreviewText(previewText)
.withTemplateParameters(templateParametersList)
.withRecipient(recipient)
.build())
.buildRequest()
.post();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewSendActivityNotificationPostRequestBody()
topic := graphmodels.NewTeamworkActivityTopic()
source := graphmodels.ENTITYURL_TEAMWORKACTIVITYTOPICSOURCE
topic.SetSource(&source)
value := "https://graph.microsoft.com/v1.0/chats/{chatId}/messages/{messageId}"
topic.SetValue(&value)
requestBody.SetTopic(topic)
activityType := "approvalRequired"
requestBody.SetActivityType(&activityType)
previewText := graphmodels.NewItemBody()
content := "Deployment requires your approval"
previewText.SetContent(&content)
requestBody.SetPreviewText(previewText)
recipient := graphmodels.NewTeamworkNotificationRecipient()
additionalData := map[string]interface{}{
"userId" : "569363e2-4e49-4661-87f2-16f245c5d66a",
}
recipient.SetAdditionalData(additionalData)
requestBody.SetRecipient(recipient)
keyValuePair := graphmodels.NewKeyValuePair()
name := "approvalTaskId"
keyValuePair.SetName(&name)
value := "2020AAGGTAPP"
keyValuePair.SetValue(&value)
templateParameters := []graphmodels.KeyValuePairable {
keyValuePair,
}
requestBody.SetTemplateParameters(templateParameters)
graphClient.ChatsById("chat-id").SendActivityNotification().Post(context.Background(), requestBody, nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Import-Module Microsoft.Graph.Teams
$params = @{
Topic = @{
Source = "entityUrl"
Value = "https://graph.microsoft.com/v1.0/chats/{chatId}/messages/{messageId}"
}
ActivityType = "approvalRequired"
PreviewText = @{
Content = "Deployment requires your approval"
}
Recipient = @{
"@odata.type" = "microsoft.graph.aadUserNotificationRecipient"
UserId = "569363e2-4e49-4661-87f2-16f245c5d66a"
}
TemplateParameters = @(
@{
Name = "approvalTaskId"
Value = "2020AAGGTAPP"
}
)
}
Send-MgChatActivityNotification -ChatId $chatId -BodyParameter $params
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('entityurl'));
$topic->setValue('https://graph.microsoft.com/v1.0/chats/{chatId}/messages/{messageId}');
$requestBody->setTopic($topic);
$requestBody->setActivityType('approvalRequired');
$previewText = new ItemBody();
$previewText->setContent('Deployment requires your approval');
$requestBody->setPreviewText($previewText);
$recipient = new TeamworkNotificationRecipient();
$recipient->set@odatatype('microsoft.graph.aadUserNotificationRecipient');
$additionalData = [
'userId' => '569363e2-4e49-4661-87f2-16f245c5d66a',
];
$recipient->setAdditionalData($additionalData);
$requestBody->setRecipient($recipient);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('approvalTaskId');
$templateParametersKeyValuePair1->setValue('2020AAGGTAPP');
$templateParametersArray []= $templateParametersKeyValuePair1;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->chatsById('chat-id')->sendActivityNotification()->post($requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
The following example shows the response.
HTTP/1.1 204 No Content
Example 3: Notify a user about an approval needed in a chat message using user principal name
Similar to the previous example, this example uses entityUrl
for the topic
. However, in this case, it links to a message in the chat. The message can contains a card with the approval button on it.
Request
The following example shows the request.
POST https://graph.microsoft.com/v1.0/chats/{chatId}/sendActivityNotification
Content-Type: application/json
{
"topic": {
"source": "entityUrl",
"value": "https://graph.microsoft.com/v1.0/chats/{chatId}/messages/{messageId}"
},
"activityType": "approvalRequired",
"previewText": {
"content": "Deployment requires your approval"
},
"recipient": {
"@odata.type": "microsoft.graph.aadUserNotificationRecipient",
"userId": "jacob@contoso.com"
},
"templateParameters": [
{
"name": "approvalTaskId",
"value": "2020AAGGTAPP"
}
]
}
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Chats.Item.SendActivityNotification.SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.EntityUrl,
Value = "https://graph.microsoft.com/v1.0/chats/{chatId}/messages/{messageId}",
},
ActivityType = "approvalRequired",
PreviewText = new ItemBody
{
Content = "Deployment requires your approval",
},
Recipient = new TeamworkNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
AdditionalData = new Dictionary<string, object>
{
{
"userId" , "jacob@contoso.com"
},
},
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "approvalTaskId",
Value = "2020AAGGTAPP",
},
},
};
await graphClient.Chats["{chat-id}"].SendActivityNotification.PostAsync(requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
const options = {
authProvider,
};
const client = Client.init(options);
const sendActivityNotification = {
topic: {
source: 'entityUrl',
value: 'https://graph.microsoft.com/v1.0/chats/{chatId}/messages/{messageId}'
},
activityType: 'approvalRequired',
previewText: {
content: 'Deployment requires your approval'
},
recipient: {
'@odata.type': 'microsoft.graph.aadUserNotificationRecipient',
userId: 'jacob@contoso.com'
},
templateParameters: [
{
name: 'approvalTaskId',
value: '2020AAGGTAPP'
}
]
};
await client.api('/chats/{chatId}/sendActivityNotification')
.post(sendActivityNotification);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
TeamworkActivityTopic topic = new TeamworkActivityTopic();
topic.source = TeamworkActivityTopicSource.ENTITY_URL;
topic.value = "https://graph.microsoft.com/v1.0/chats/{chatId}/messages/{messageId}";
String activityType = "approvalRequired";
ItemBody previewText = new ItemBody();
previewText.content = "Deployment requires your approval";
AadUserNotificationRecipient recipient = new AadUserNotificationRecipient();
recipient.userId = "jacob@contoso.com";
LinkedList<KeyValuePair> templateParametersList = new LinkedList<KeyValuePair>();
KeyValuePair templateParameters = new KeyValuePair();
templateParameters.name = "approvalTaskId";
templateParameters.value = "2020AAGGTAPP";
templateParametersList.add(templateParameters);
graphClient.chats("{chatId}")
.sendActivityNotification(ChatSendActivityNotificationParameterSet
.newBuilder()
.withTopic(topic)
.withActivityType(activityType)
.withChainId(null)
.withPreviewText(previewText)
.withTemplateParameters(templateParametersList)
.withRecipient(recipient)
.build())
.buildRequest()
.post();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewSendActivityNotificationPostRequestBody()
topic := graphmodels.NewTeamworkActivityTopic()
source := graphmodels.ENTITYURL_TEAMWORKACTIVITYTOPICSOURCE
topic.SetSource(&source)
value := "https://graph.microsoft.com/v1.0/chats/{chatId}/messages/{messageId}"
topic.SetValue(&value)
requestBody.SetTopic(topic)
activityType := "approvalRequired"
requestBody.SetActivityType(&activityType)
previewText := graphmodels.NewItemBody()
content := "Deployment requires your approval"
previewText.SetContent(&content)
requestBody.SetPreviewText(previewText)
recipient := graphmodels.NewTeamworkNotificationRecipient()
additionalData := map[string]interface{}{
"userId" : "jacob@contoso.com",
}
recipient.SetAdditionalData(additionalData)
requestBody.SetRecipient(recipient)
keyValuePair := graphmodels.NewKeyValuePair()
name := "approvalTaskId"
keyValuePair.SetName(&name)
value := "2020AAGGTAPP"
keyValuePair.SetValue(&value)
templateParameters := []graphmodels.KeyValuePairable {
keyValuePair,
}
requestBody.SetTemplateParameters(templateParameters)
graphClient.ChatsById("chat-id").SendActivityNotification().Post(context.Background(), requestBody, nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Import-Module Microsoft.Graph.Teams
$params = @{
Topic = @{
Source = "entityUrl"
Value = "https://graph.microsoft.com/v1.0/chats/{chatId}/messages/{messageId}"
}
ActivityType = "approvalRequired"
PreviewText = @{
Content = "Deployment requires your approval"
}
Recipient = @{
"@odata.type" = "microsoft.graph.aadUserNotificationRecipient"
UserId = "jacob@contoso.com"
}
TemplateParameters = @(
@{
Name = "approvalTaskId"
Value = "2020AAGGTAPP"
}
)
}
Send-MgChatActivityNotification -ChatId $chatId -BodyParameter $params
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('entityurl'));
$topic->setValue('https://graph.microsoft.com/v1.0/chats/{chatId}/messages/{messageId}');
$requestBody->setTopic($topic);
$requestBody->setActivityType('approvalRequired');
$previewText = new ItemBody();
$previewText->setContent('Deployment requires your approval');
$requestBody->setPreviewText($previewText);
$recipient = new TeamworkNotificationRecipient();
$recipient->set@odatatype('microsoft.graph.aadUserNotificationRecipient');
$additionalData = [
'userId' => 'jacob@contoso.com',
];
$recipient->setAdditionalData($additionalData);
$requestBody->setRecipient($recipient);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('approvalTaskId');
$templateParametersKeyValuePair1->setValue('2020AAGGTAPP');
$templateParametersArray []= $templateParametersKeyValuePair1;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->chatsById('chat-id')->sendActivityNotification()->post($requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
The following example shows the response.
HTTP/1.1 204 No Content
Example 4: Notify a user about an event in relation to a chat
As shown in the previous examples, you can link to different aspects of the chat. However, if you want to link to an aspect that is not part of the chat, or is not represented by Microsoft Graph, you can set the source of the topic
to text
and pass in a custom value for it. Also, webUrl
is required when setting topic
source to text
.
Request
The following example shows the request.
POST https://graph.microsoft.com/v1.0/chats/{chatId}/sendActivityNotification
Content-Type: application/json
{
"topic": {
"source": "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": "deploymentApprovalRequired",
"previewText": {
"content": "New deployment requires your approval"
},
"recipient": {
"@odata.type": "microsoft.graph.aadUserNotificationRecipient",
"userId": "569363e2-4e49-4661-87f2-16f245c5d66a"
},
"templateParameters": [
{
"name": "deploymentId",
"value": "6788662"
}
]
}
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Chats.Item.SendActivityNotification.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 = "deploymentApprovalRequired",
PreviewText = new ItemBody
{
Content = "New deployment requires your approval",
},
Recipient = new TeamworkNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
AdditionalData = new Dictionary<string, object>
{
{
"userId" , "569363e2-4e49-4661-87f2-16f245c5d66a"
},
},
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "deploymentId",
Value = "6788662",
},
},
};
await graphClient.Chats["{chat-id}"].SendActivityNotification.PostAsync(requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
const options = {
authProvider,
};
const client = Client.init(options);
const sendActivityNotification = {
topic: {
source: '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: 'deploymentApprovalRequired',
previewText: {
content: 'New deployment requires your approval'
},
recipient: {
'@odata.type': 'microsoft.graph.aadUserNotificationRecipient',
userId: '569363e2-4e49-4661-87f2-16f245c5d66a'
},
templateParameters: [
{
name: 'deploymentId',
value: '6788662'
}
]
};
await client.api('/chats/{chatId}/sendActivityNotification')
.post(sendActivityNotification);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
TeamworkActivityTopic topic = new TeamworkActivityTopic();
topic.source = TeamworkActivityTopicSource.TEXT;
topic.value = "Deployment Approvals Channel";
topic.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";
String activityType = "deploymentApprovalRequired";
ItemBody previewText = new ItemBody();
previewText.content = "New deployment requires your approval";
AadUserNotificationRecipient recipient = new AadUserNotificationRecipient();
recipient.userId = "569363e2-4e49-4661-87f2-16f245c5d66a";
LinkedList<KeyValuePair> templateParametersList = new LinkedList<KeyValuePair>();
KeyValuePair templateParameters = new KeyValuePair();
templateParameters.name = "deploymentId";
templateParameters.value = "6788662";
templateParametersList.add(templateParameters);
graphClient.chats("{chatId}")
.sendActivityNotification(ChatSendActivityNotificationParameterSet
.newBuilder()
.withTopic(topic)
.withActivityType(activityType)
.withChainId(null)
.withPreviewText(previewText)
.withTemplateParameters(templateParametersList)
.withRecipient(recipient)
.build())
.buildRequest()
.post();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewSendActivityNotificationPostRequestBody()
topic := graphmodels.NewTeamworkActivityTopic()
source := graphmodels.TEXT_TEAMWORKACTIVITYTOPICSOURCE
topic.SetSource(&source)
value := "Deployment Approvals Channel"
topic.SetValue(&value)
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"
topic.SetWebUrl(&webUrl)
requestBody.SetTopic(topic)
activityType := "deploymentApprovalRequired"
requestBody.SetActivityType(&activityType)
previewText := graphmodels.NewItemBody()
content := "New deployment requires your approval"
previewText.SetContent(&content)
requestBody.SetPreviewText(previewText)
recipient := graphmodels.NewTeamworkNotificationRecipient()
additionalData := map[string]interface{}{
"userId" : "569363e2-4e49-4661-87f2-16f245c5d66a",
}
recipient.SetAdditionalData(additionalData)
requestBody.SetRecipient(recipient)
keyValuePair := graphmodels.NewKeyValuePair()
name := "deploymentId"
keyValuePair.SetName(&name)
value := "6788662"
keyValuePair.SetValue(&value)
templateParameters := []graphmodels.KeyValuePairable {
keyValuePair,
}
requestBody.SetTemplateParameters(templateParameters)
graphClient.ChatsById("chat-id").SendActivityNotification().Post(context.Background(), requestBody, nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Import-Module Microsoft.Graph.Teams
$params = @{
Topic = @{
Source = "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 = "deploymentApprovalRequired"
PreviewText = @{
Content = "New deployment requires your approval"
}
Recipient = @{
"@odata.type" = "microsoft.graph.aadUserNotificationRecipient"
UserId = "569363e2-4e49-4661-87f2-16f245c5d66a"
}
TemplateParameters = @(
@{
Name = "deploymentId"
Value = "6788662"
}
)
}
Send-MgChatActivityNotification -ChatId $chatId -BodyParameter $params
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$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('deploymentApprovalRequired');
$previewText = new ItemBody();
$previewText->setContent('New deployment requires your approval');
$requestBody->setPreviewText($previewText);
$recipient = new TeamworkNotificationRecipient();
$recipient->set@odatatype('microsoft.graph.aadUserNotificationRecipient');
$additionalData = [
'userId' => '569363e2-4e49-4661-87f2-16f245c5d66a',
];
$recipient->setAdditionalData($additionalData);
$requestBody->setRecipient($recipient);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('deploymentId');
$templateParametersKeyValuePair1->setValue('6788662');
$templateParametersArray []= $templateParametersKeyValuePair1;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->chatsById('chat-id')->sendActivityNotification()->post($requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
The following example shows the response.
HTTP/1.1 204 No Content
Example 5: Notify the chat members about a task created in a chat
The following example shows how you can send an activity feed notification to all chat members. This example is similar to previous examples. However, in this case, the recipient is a chatMembersNotificationRecipient . Note that the chatId specified in the recipient must match the chatId specified in the request URL.
Request
The following example shows the request.
POST https://graph.microsoft.com/v1.0/chats/19:1c3af46e9e0f4a5293343c8813c47619@thread.v2/sendActivityNotification
Content-Type: application/json
{
"topic": {
"source": "entityUrl",
"value": "https://graph.microsoft.com/v1.0/chats/19:1c3af46e9e0f4a5293343c8813c47619@thread.v2"
},
"activityType": "taskCreated",
"previewText": {
"content": "New Task Created"
},
"recipient": {
"@odata.type": "microsoft.graph.chatMembersNotificationRecipient",
"chatId": "19:1c3af46e9e0f4a5293343c8813c47619@thread.v2"
},
"templateParameters": [
{
"name": "taskId",
"value": "Task 12322"
}
]
}
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Chats.Item.SendActivityNotification.SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.EntityUrl,
Value = "https://graph.microsoft.com/v1.0/chats/19:1c3af46e9e0f4a5293343c8813c47619@thread.v2",
},
ActivityType = "taskCreated",
PreviewText = new ItemBody
{
Content = "New Task Created",
},
Recipient = new TeamworkNotificationRecipient
{
OdataType = "microsoft.graph.chatMembersNotificationRecipient",
AdditionalData = new Dictionary<string, object>
{
{
"chatId" , "19:1c3af46e9e0f4a5293343c8813c47619@thread.v2"
},
},
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "taskId",
Value = "Task 12322",
},
},
};
await graphClient.Chats["{chat-id}"].SendActivityNotification.PostAsync(requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
const options = {
authProvider,
};
const client = Client.init(options);
const sendActivityNotification = {
topic: {
source: 'entityUrl',
value: 'https://graph.microsoft.com/v1.0/chats/19:1c3af46e9e0f4a5293343c8813c47619@thread.v2'
},
activityType: 'taskCreated',
previewText: {
content: 'New Task Created'
},
recipient: {
'@odata.type': 'microsoft.graph.chatMembersNotificationRecipient',
chatId: '19:1c3af46e9e0f4a5293343c8813c47619@thread.v2'
},
templateParameters: [
{
name: 'taskId',
value: 'Task 12322'
}
]
};
await client.api('/chats/19:1c3af46e9e0f4a5293343c8813c47619@thread.v2/sendActivityNotification')
.post(sendActivityNotification);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
TeamworkActivityTopic topic = new TeamworkActivityTopic();
topic.source = TeamworkActivityTopicSource.ENTITY_URL;
topic.value = "https://graph.microsoft.com/v1.0/chats/19:1c3af46e9e0f4a5293343c8813c47619@thread.v2";
String activityType = "taskCreated";
ItemBody previewText = new ItemBody();
previewText.content = "New Task Created";
ChatMembersNotificationRecipient recipient = new ChatMembersNotificationRecipient();
recipient.chatId = "19:1c3af46e9e0f4a5293343c8813c47619@thread.v2";
LinkedList<KeyValuePair> templateParametersList = new LinkedList<KeyValuePair>();
KeyValuePair templateParameters = new KeyValuePair();
templateParameters.name = "taskId";
templateParameters.value = "Task 12322";
templateParametersList.add(templateParameters);
graphClient.chats("19:1c3af46e9e0f4a5293343c8813c47619@thread.v2")
.sendActivityNotification(ChatSendActivityNotificationParameterSet
.newBuilder()
.withTopic(topic)
.withActivityType(activityType)
.withChainId(null)
.withPreviewText(previewText)
.withTemplateParameters(templateParametersList)
.withRecipient(recipient)
.build())
.buildRequest()
.post();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewSendActivityNotificationPostRequestBody()
topic := graphmodels.NewTeamworkActivityTopic()
source := graphmodels.ENTITYURL_TEAMWORKACTIVITYTOPICSOURCE
topic.SetSource(&source)
value := "https://graph.microsoft.com/v1.0/chats/19:1c3af46e9e0f4a5293343c8813c47619@thread.v2"
topic.SetValue(&value)
requestBody.SetTopic(topic)
activityType := "taskCreated"
requestBody.SetActivityType(&activityType)
previewText := graphmodels.NewItemBody()
content := "New Task Created"
previewText.SetContent(&content)
requestBody.SetPreviewText(previewText)
recipient := graphmodels.NewTeamworkNotificationRecipient()
additionalData := map[string]interface{}{
"chatId" : "19:1c3af46e9e0f4a5293343c8813c47619@thread.v2",
}
recipient.SetAdditionalData(additionalData)
requestBody.SetRecipient(recipient)
keyValuePair := graphmodels.NewKeyValuePair()
name := "taskId"
keyValuePair.SetName(&name)
value := "Task 12322"
keyValuePair.SetValue(&value)
templateParameters := []graphmodels.KeyValuePairable {
keyValuePair,
}
requestBody.SetTemplateParameters(templateParameters)
graphClient.ChatsById("chat-id").SendActivityNotification().Post(context.Background(), requestBody, nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Import-Module Microsoft.Graph.Teams
$params = @{
Topic = @{
Source = "entityUrl"
Value = "https://graph.microsoft.com/v1.0/chats/19:1c3af46e9e0f4a5293343c8813c47619@thread.v2"
}
ActivityType = "taskCreated"
PreviewText = @{
Content = "New Task Created"
}
Recipient = @{
"@odata.type" = "microsoft.graph.chatMembersNotificationRecipient"
ChatId = "19:1c3af46e9e0f4a5293343c8813c47619@thread.v2"
}
TemplateParameters = @(
@{
Name = "taskId"
Value = "Task 12322"
}
)
}
Send-MgChatActivityNotification -ChatId $chatId -BodyParameter $params
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('entityurl'));
$topic->setValue('https://graph.microsoft.com/v1.0/chats/19:1c3af46e9e0f4a5293343c8813c47619@thread.v2');
$requestBody->setTopic($topic);
$requestBody->setActivityType('taskCreated');
$previewText = new ItemBody();
$previewText->setContent('New Task Created');
$requestBody->setPreviewText($previewText);
$recipient = new TeamworkNotificationRecipient();
$recipient->set@odatatype('microsoft.graph.chatMembersNotificationRecipient');
$additionalData = [
'chatId' => '19:1c3af46e9e0f4a5293343c8813c47619@thread.v2',
];
$recipient->setAdditionalData($additionalData);
$requestBody->setRecipient($recipient);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('taskId');
$templateParametersKeyValuePair1->setValue('Task 12322');
$templateParametersArray []= $templateParametersKeyValuePair1;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->chatsById('chat-id')->sendActivityNotification()->post($requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
The following example shows the response.
HTTP/1.1 204 No Content
See also