Integrate With SMS Providers
Overview
DIGIT ships with SMSCountry as the default SMS provider. This document explains how to integrate with other SMS providers.
Steps
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).
Update the 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" }
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 thegetFinalMessage()
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.
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);
}
}
}
}
}
Checklist - Summary
Last updated
Was this helpful?