Forum Discussion

vovanb's avatar
vovanb
Copper Contributor
Jul 10, 2023

send notification for user

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?

 

  • 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

      • vovanb's avatar
        vovanb
        Copper Contributor
        Hi
        I do not see difference between example I sent and you provided. I need to notify my user (which I logged in ) about new task created. so - notification should be sent to me. How to do it?

Resources