Forum Discussion
Issue with AzureCommunicationChat - Unwanted Push Notifications for the Sender
If I understand your question correctly, both the sender and the recipient receive push notifications when a user sends a chat message or creates a new chat thread using AzureCommunicationChat with Azure Notification Hubs in a multi-device scenario?
If that's is the case then you need to Modify the code responsible for sending push notifications (push notification server) to the Azure notification hub. When sending push notifications, include custom payloads that contain user identifiers (e.g., user IDs or usernames) for both the sender and the recipient. Modify your Azure Function or backend code to inspect these identifiers. If you use Azure function then you can use the following code:
// Sample Azure Function code (C#)
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
ILogger log)
{
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var notificationPayload = JsonConvert.DeserializeObject<NotificationPayload>(requestBody);
// Check if sender and recipient are the same
if (notificationPayload.SenderUserId != notificationPayload.RecipientUserId)
{
// Send the notification using Azure Notification Hubs
// Your notification sending logic here
// ...
}
return new OkResult();
}
This only works if your setup, is the following:
Please let me know if this helps!