0

Getting duplicate push notifications while sending one push notification through AWS Pinpoint Service using FCM channel pinpoint.sendMessage method. pushing notification on an FCM token but getting two different request IDs. Push Notification callback Reponse

Why does this happen?

How can stop to send duplicate notification from node server?. and I am using "aws-sdk": "^2.1266.0". Any help would be appreciated.

code sample to send push notification :

export const sendPushNotification = async (userId: number, payload: RealTimeNotificationPayload) => {

    const deviceTokens = await getAllDeviceTokensForUser(userId);
    logInfo('deviceTokens==', deviceTokens)
    const tokensTobeRemoved = [];

    const pushNotificationPromises = deviceTokens.map(async (deviceToken) => {
        const pinpoint = new AWS.Pinpoint();

        const params = {
            ApplicationId: commonConfig.aws.pinPointApplicationId,
            MessageRequest: {
                Addresses: {
                    [deviceToken]: {
                        ChannelType: PushNotifications.ChannelType.GCM
                    }
                },
                MessageConfiguration: {
                    GCMMessage: {
                        RawContent: JSON.stringify({
                            notification: {
                                title: "Title",
                                body: "Test body"
                            }
                        }),
                        Priority: 'medium',
                        SilentPush: false,
                        TimeToLive: 30,
                    } as AWS.Pinpoint.GCMMessage
                }
            }
        } as AWS.Pinpoint.Types.SendMessagesRequest;

        logInfo('params.MessageRequest==', params.MessageRequest.MessageConfiguration)

        await pinpoint.sendMessages(params, async function (err, data) {
            if (err) {
                logError(err, `Error while sending push notification device token ${deviceToken}`);
            }
            else {
                if (checkIfTokenInvalid(deviceToken, data)) {
                    tokensTobeRemoved.push(deviceToken);
                }
                console.log("Response data==> ", JSON.stringify(data, null, 4));
                logInfo('data==', deviceToken, data.MessageResponse.Result[deviceToken].DeliveryStatus)
            }
        }).promise();
    })

    await Promise.all(pushNotificationPromises);
    logInfo('tokensTobeRemoved==', tokensTobeRemoved)
    if (tokensTobeRemoved.length) {
        await deleteInvalidDeviceTokens(tokensTobeRemoved);
    }
}

0 Answers0