diff --git a/src/main/java/org/opentripplanner/middleware/otp/response/LocalizedAlert.java b/src/main/java/org/opentripplanner/middleware/otp/response/LocalizedAlert.java index 369c9d0ab..ad48cd680 100644 --- a/src/main/java/org/opentripplanner/middleware/otp/response/LocalizedAlert.java +++ b/src/main/java/org/opentripplanner/middleware/otp/response/LocalizedAlert.java @@ -11,6 +11,8 @@ public class LocalizedAlert { public Date effectiveEndDate; + public String id; + @Override public int hashCode() { return Objects.hash(alertHeaderText, alertDescriptionText, alertUrl, effectiveStartDate, effectiveEndDate); diff --git a/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java b/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java index 7e4c0fcb2..12ecb24f9 100644 --- a/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java +++ b/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java @@ -1,5 +1,6 @@ package org.opentripplanner.middleware.utils; +import com.google.gson.Gson; import com.sparkpost.Client; import com.sparkpost.model.responses.Response; import com.twilio.Twilio; @@ -80,14 +81,8 @@ public static String sendPush(OtpUser otpUser, String textTemplate, Object templ */ static String sendPush(String toUser, String body) { try { - var jsonBody = String.format( - "{\"user\":\"%s\",\"message\":\"%s\"}", - toUser, - body - // Escape carriage returns and trim message length (iOS limitation). - .replace("\n", "\\n") - .substring(0, PUSH_MESSAGE_MAX_LENGTH - 1) - ); + NotificationInfo notifInfo = new NotificationInfo(toUser, body.substring(0, Math.min(PUSH_MESSAGE_MAX_LENGTH, body.length()))); + var jsonBody = new Gson().toJson(notifInfo); Map headers = Map.of( "Accept", "application/json", "Content-Type", "application/json" @@ -151,9 +146,9 @@ public static String sendSMS(String toPhone, String body) { toPhoneNumber, fromPhoneNumber, // Trim body to max message length - body.substring(0, SMS_MAX_LENGTH - 1) + body.substring(0, Math.min(SMS_MAX_LENGTH, body.length())) ).create(); - LOG.debug("SMS ({}) sent successfully", message.getSid()); + LOG.info("SMS ({}) sent successfully", message.getSid()); return message.getSid(); // TODO: Is there a more specific exception we're ok with here? } catch (Exception e) { @@ -329,4 +324,13 @@ public static int getPushInfo(String toUser) { return 0; } + static class NotificationInfo { + public String user; + public String message; + + public NotificationInfo(String user, String message) { + this.user = user; + this.message = message; + } + } } diff --git a/src/main/resources/latest-spark-swagger-output.yaml b/src/main/resources/latest-spark-swagger-output.yaml index 4cf74df2b..d3bc90e19 100644 --- a/src/main/resources/latest-spark-swagger-output.yaml +++ b/src/main/resources/latest-spark-swagger-output.yaml @@ -2437,6 +2437,8 @@ definitions: effectiveEndDate: type: "string" format: "date" + id: + type: "string" MonitoredTrip: type: "object" properties: