Enable New SMS/In-app Notifications

Overview

This step-by-step guide helps you enable notifications (like “complaint resolved”, “complaint assigned”) through SMS and InApp channels using localisation, Code configuration, and Notification services.

Example Use Case

When a complaint is resolved, we want to send this SMS to the citizen:

"Dear Citizen, Your complaint for {complaint_type} with ID {id} submitted on {date} has been resolved by {emp_name}. If you are not satisfied with the service, you can RE-OPEN complaints through mSeva mobile App (download here - {download_link}) or your local municipal web portal or by calling your nearest municipal office."

Steps

1

Add the notification message to localisation

  • Add your SMS or notification message (with placeholders like {id}, {date}) to the Localisation master.

  • Use the Localisation Upsert API (provided in the Postman collection).

  • Updated domain url in api call.

  • Example Entry:

    {
      "code": "PGR_CITIZEN_RESOLVE_RESOLVED_SMS_MESSAGE",
      "message": "Dear Citizen, Your complaint for {complaint_type} with ID {id} submitted on {date} has been resolved by {emp_name}.",
      "module": "rainmaker-pgr",
      "locale": "en_IN"
    }

Tip: To support multiple languages, add the same code with different locale values (e.g., hi_IN for Hindi, or en_IN for English or pa_IN for Punjabi.

2

Replace placeholders with real data in the code

  • The code fetches the message and replaces placeholders like {id} with actual complaint details.

  • In the backend, usually in NotificationService.java inside the getFinalMessage() function.

  • Use simple replace logic - refer sample below:

    if (messageForEmployee != null) {
        messageForEmployee = messageForEmployee.replace("{complaint_type}", localisedComplaint);
        messageForEmployee = messageForEmployee.replace("{id}", serviceWrapper.getService().getServiceRequestId());
        messageForEmployee = messageForEmployee.replace("{date}", date.format(formatter));
        messageForEmployee = messageForEmployee.replace("{download_link}", appLink);
    }
    
    if (messageForEmployee.contains("{emp_name}")) {
        messageForEmployee = messageForEmployee.replace("{emp_name}",
           fetchUserByUUID(
             request.getWorkflow().getAssignes().get(0),
             request.getRequestInfo(),
             request.getService().getTenantId()
           ).getName());
    }
  • Each notification is personalised to the citizen and complaint.

3

Send the notification

  • Send the final message to both SMS and InApp (User Events) services.

  • InApp: Use the user-events service (for app notifications/inbox). Sample code snippet for InApp (User Events) below:

if (!StringUtils.isEmpty(finalMessage)) {
    if (config.getIsUserEventsNotificationEnabled() != null && config.getIsUserEventsNotificationEnabled()) {
        for (Map.Entry<String, List<String>> entry : finalMessage.entrySet()) {
            for (String msg : entry.getValue()) {
                EventRequest eventRequest = enrichEventRequest(request, msg);
                if (eventRequest != null) {
                    notificationUtil.sendEventNotification(tenantId, eventRequest);
                }
            }
        }
    }
}
  • SMS: Use the notification-sms service. Sample code snippet for SMS - notification-sms below:

if (config.getIsSMSEnabled() != null && config.getIsSMSEnabled()) {

    // Loop through each recipient group (CITIZEN or EMPLOYEE)
    for (Map.Entry<String, List<String>> entry : finalMessage.entrySet()) {

        if (entry.getKey().equalsIgnoreCase(CITIZEN)) {
            // Send SMS to CITIZEN
            for (String msg : entry.getValue()) {
                List<SMSRequest> smsRequests = new ArrayList<>();
                smsRequests = enrichSmsRequest(citizenMobileNumber, msg);

                if (!CollectionUtils.isEmpty(smsRequests)) {
                    notificationUtil.sendSMS(tenantId, smsRequests);
                }
            }
         } else {
            // Send SMS to EMPLOYEE or other recipients
            for (String msg : entry.getValue()) {
                List<SMSRequest> smsRequests = new ArrayList<>();
                smsRequests = enrichSmsRequest(employeeMobileNumber, msg);

                if (!CollectionUtils.isEmpty(smsRequests)) {
                    notificationUtil.sendSMS(tenantId, smsRequests);
                }
            }
        }
    }
}

Note: The code handles both channels. Make sure these are enabled in your configuration:

isUserEventsNotificationEnabled: true
isSMSNotificationEnabled: true

Checklist - Summary

Last updated

Was this helpful?