Skip to content

Commit

Permalink
Merge pull request #41 from pankajjangid05/development
Browse files Browse the repository at this point in the history
Removed static fcmtoken from notification
  • Loading branch information
pankajjangid05 authored May 25, 2023
2 parents 11ceb76 + eda3a7d commit ab9ff09
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class FirebaseNotificationService {

public static final String url = "https://fcm.googleapis.com/fcm/send";

private long sentCount;
private long notSentCount;

/**
* Send FCM Notification to token with title & body
* @param token
Expand All @@ -32,10 +35,9 @@ public Mono<Boolean> sendNotificationMessage(String serviceKey, String token, St
httpHeaders.set("Content-Type", "application/json");
})
.build();
String token1 = "d6oo7uBfIHlJvQktBLpF31:APA91bEXkLLFFgoesrBC4yfMahjvFz8AWBqL_C-uS-91_qMm2GohIwZ4EdpB6BoDCIps6xhrlpVuYlWHiXEsElVfLagwaWg1LAIb1wbNnXAvD0c6GozuEtk14VN5oX1gmMwMDQf-EEeG";;
ObjectMapper mapper = new ObjectMapper();
ObjectNode node = mapper.createObjectNode();
node.put("to", token1);
node.put("to", token);
node.put("collapse_key", "type_a");
// Notification Key Enable and Disable from Payload
if (notificationKeyEnable != null && notificationKeyEnable.equalsIgnoreCase("true")) {
Expand All @@ -53,7 +55,7 @@ public Mono<Boolean> sendNotificationMessage(String serviceKey, String token, St
dataNode.put("title", title);
dataNode.put("externalId", channelMessageId);
dataNode.put("destAdd", phone);
dataNode.put("fcmDestAdd", token1);
dataNode.put("fcmDestAdd", token);
dataNode.put("click_action", click_action);

if (data != null) {
Expand All @@ -71,10 +73,12 @@ public Mono<Boolean> sendNotificationMessage(String serviceKey, String token, St
try {
ObjectNode resultNode = (ObjectNode) mapper.readTree(response);
if (resultNode.get("success") != null && Integer.parseInt(resultNode.get("success").toString()) >= 1) {
log.info("Notification triggered success : " + phone + " fcm token : " + token1 + " FCM Response : " + resultNode.toString());
sentCount++;
log.info("Notification triggered success : " + phone + " fcm token : " + token + " FCM Response : " + resultNode.toString() + " :: sent count : " + sentCount);
return true;
} else {
log.error("Notification not sent : " + phone + " fcm Token : " + token1 + " error :" + resultNode.toString());
notSentCount++;
log.error("Notification not sent : " + phone + " fcm Token : " + token + " error :" + resultNode.toString() + " :: count : " + notSentCount);
}
} catch (JsonProcessingException jsonMappingException) {
log.error("Exception in sendNotificationMessage: " + jsonMappingException.getMessage());
Expand Down

0 comments on commit ab9ff09

Please sign in to comment.