Forum Discussion
Issue with AzureCommunicationChat - Unwanted Push Notifications for the Sender
Hello everyone,
We are currently integrating AzureCommunicationChat into our iOS and Android applications and are facing issues with push notifications using Azure Notifications Hub. We would appreciate any help or suggestions you can provide.
The problem arises when a user sends a chat message or creates a new chat thread—both the sender and the recipient receive a push notification. However, the sender should not be expecting or receiving this push notification.
We have attempted to intercept the push notification to prevent it from displaying when the app is in the foreground.
Unfortunately, this solution only works if the user logs in from a single device, which is not our case. Consequently, the sender is receiving the push notification on other devices.
Does anyone have any ideas or suggestions to address this undesired behavior?
We appreciate your assistance in advance.
Best regards,
Mattia La Spina
1 Reply
- samy_vanderspikkenBrass Contributor
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!