Skip to content

Commit

Permalink
feat(NotificationUtils): Pass surveyId with trip survey notifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed Oct 29, 2024
1 parent 740fdc7 commit 6c55481
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class NotificationUtils {
public static final String OTP_ADMIN_DASHBOARD_FROM_EMAIL = getConfigPropertyAsText("OTP_ADMIN_DASHBOARD_FROM_EMAIL");
private static final String PUSH_API_KEY = getConfigPropertyAsText("PUSH_API_KEY");
private static final String PUSH_API_URL = getConfigPropertyAsText("PUSH_API_URL");
private static final String TRIP_SURVEY_ID = getConfigPropertyAsText("TRIP_SURVEY_ID");

/**
* Although SMS are 160 characters long and Twilio supports sending up to 1600 characters,
Expand Down Expand Up @@ -79,7 +80,7 @@ public static String sendPush(OtpUser otpUser, String textTemplate, Object templ
if (PUSH_API_KEY == null || PUSH_API_URL == null) return null;
try {
String body = TemplateUtils.renderTemplate(textTemplate, templateData);
return otpUser.pushDevices > 0 ? sendPush(otpUser, body, tripName, tripId) : "OK";
return otpUser.pushDevices > 0 ? sendPush(otpUser, body, tripName, tripId, null) : "OK";
} catch (TemplateException | IOException e) {
// This catch indicates there was an error rendering the template. Note: TemplateUtils#renderTemplate
// handles Bugsnag reporting/error logging, so that is not needed here.
Expand All @@ -101,7 +102,7 @@ public static String sendTripSurveyPush(OtpUser otpUser, MonitoredTrip trip) {
org.opentripplanner.middleware.i18n.Message.TRIP_SURVEY_NOTIFICATION.get(locale),
tripTime
);
return otpUser.pushDevices > 0 ? sendPush(otpUser, body, trip.tripName, trip.id) : "OK";
return otpUser.pushDevices > 0 ? sendPush(otpUser, body, trip.tripName, trip.id, TRIP_SURVEY_ID) : "OK";
}

/**
Expand All @@ -110,15 +111,17 @@ public static String sendTripSurveyPush(OtpUser otpUser, MonitoredTrip trip) {
* @param body message body
* @param tripName Monitored trip name to show in notification title
* @param tripId Monitored trip ID
* @param surveyId Survey ID
* @return "OK" if message was successful (null otherwise)
*/
static String sendPush(OtpUser toUser, String body, String tripName, String tripId) {
static String sendPush(OtpUser toUser, String body, String tripName, String tripId, String surveyId) {
try {
NotificationInfo notificationInfo = new NotificationInfo(
toUser,
body,
tripName,
tripId
tripId,
surveyId
);
var jsonBody = new Gson().toJson(notificationInfo);
var httpResponse = HttpUtils.httpRequestRawResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void canSendPushNotification() {
user,
"Tough little ship!",
"Titanic",
"trip-id"
"trip-id",
"survey-id"
);
LOG.info("Push notification (ret={}) sent to {}", ret, user.email);
Assertions.assertNotNull(ret);
Expand Down

0 comments on commit 6c55481

Please sign in to comment.