Jul 10 2023 09:29 AM - edited Jul 10 2023 09:30 AM
I am using SendActivityNotification as below:
var requestBody = new Microsoft.Graph.Users.Item.Teamwork.SendActivityNotification.SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.EntityUrl,
Value = $"https://graph.microsoft.com/v1.0/users/{user.Id}/teamwork/installedApps/{installationId}",
},
ActivityType = "taskCreated",
PreviewText = new ItemBody
{
Content = "New Task Created",
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "taskId",
Value = "Task 12322",
},
},
};
await graphClient.Users[user.Id].Teamwork.SendActivityNotification.PostAsync(requestBody);
Where graphClient was created using client accessToken "on behalf of" OAuth flow
I got an error that "The recipient of the notification cannot be the same as the sender of the notification."
I do want to be able to send notification to current Teams logged user about events happened in my application.
What I am doing wrong?
Jul 10 2023 10:13 PM
@vovanb -Thanks for reporting your issue.
We will check this at our end and will get back to you.
Jul 11 2023 03:11 AM
@vovanb -To ensure that the recipient of the notification is not the same as the sender.
Could you please try with the code like below, as here mentioned the recipient -
// Code snippets are only available for the latest version. Current version is 5.x
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 AadUserNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
UserId = "569363e2-4e49-4661-87f2-16f245c5d66a",
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "taskId",
Value = "12322",
},
},
};
await graphClient.Chats["{chat-id}"].SendActivityNotification.PostAsync(requestBody);
Reference Document-Send activity feed notifications to users in Microsoft Teams - Microsoft Graph | Microsoft Learn
Jul 13 2023 03:34 AM
Jul 13 2023 03:36 AM
Jul 13 2023 05:25 AM
Jul 13 2023 05:34 AM
Jul 18 2023 06:38 AM
@Sayali-MSFT please note I was able to successfully to construct Graph API request and I got 202 response
https://developer.microsoft.com/en-us/graph/graph-explorer?request=teamwork%2FsendActivityNotificati...
but nothing happen in Teams
Jul 18 2023 11:30 PM
Jul 19 2023 04:32 AM
This is where I am struggling to convert Graph API to C# version. Could you provide example in C# for the below post call https://graph.microsoft.com/v1.0/teamwork/sendActivityNotificationToRecipients
In examples you provided I did found such implemntation.
Jul 19 2023 05:27 AM
@vovanb -please have look into the below sample to implement the sendActivityNotificationToRecipients
Sample Link-Microsoft-Teams-Samples/samples/graph-activity-feed-broadcast/csharp/ActivityFeedBroadcast/Controlle...
Jul 19 2023 05:55 AM - edited Jul 19 2023 05:57 AM
Below what I did :
1. Using example Sample link-https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/03dae3d9e7fe34ca968abdc530ebef95132f490b/samples/graph-activity-feed/csharp/ActivityFeedNotification/Controllers/HomeController.cs#L72 I got:
Cannot read the value '1' as a quoted JSON string value
This is because in example Source = TeamworkActivityTopicSource.Text, converted to 1
So this example does not work
2. I create below code to simulate Graph API example I provided - similar to Graph no activities appear in Teams:
var requestBody = new Microsoft.Graph.Teamwork.SendActivityNotificationToRecipients.SendActivityNotificationToRecipientsPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.EntityUrl,
Value = "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/12438DD2-E2C5-4CCC-B480-79D0672F86C7",
},
ActivityType = "approvalRequired",
PreviewText = new ItemBody
{
Content = "Internal spending team has a pending finance approval requests",
},
Recipients = new List<TeamworkNotificationRecipient>
{
new AadUserNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
UserId = userId,
}
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "approvalTaskId",
Value = "5",
},
},
};
await graphClient.Teamwork.SendActivityNotificationToRecipients.PostAsync(requestBody);
SO all examples I used does not send notification or failed.
Can you guys create simple sample which can send notification to logged user?
Jul 26 2023 11:21 PM
Aug 21 2023 03:09 AM
Aug 21 2023 06:26 AM - edited Aug 21 2023 06:26 AM
@Sayali-MSFT thanks for links, BUT this examples do not working. I can not send notification to logged user.
Is it working for you? Did you try?
Aug 31 2023 06:44 AM
@vovanb -Currently, we are not able to send the notification to be logged on user.
Could you please help by suggesting this feature on - Microsoft Teams · Community
Aug 31 2023 07:51 AM
sorry, did not understand your response - so it is not possible to use that API at all? Then it is a bug?
Sep 01 2023 02:40 AM
@vovanb -No, currently it is not possible. This is a kind of feature request, so could you please raise the feature request on Microsoft Teams · Community
Sep 02 2023 01:58 AM
I am completely lost here. What is purpose of SendActivityNotification API? To whom I can send notification? When it should work? Nothing from your code example did not work for me?
Why this API created?
Sep 06 2023 01:24 AM