Skip to content

Commit

Permalink
Merge pull request #192 from ibi-group/fix-notif-string-checks
Browse files Browse the repository at this point in the history
Fix Notification String Checks and Add Alert ID
  • Loading branch information
binh-dam-ibigroup authored Nov 13, 2023
2 parents a685f63 + 0d73cb2 commit d81418f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<String, String> headers = Map.of(
"Accept", "application/json",
"Content-Type", "application/json"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/latest-spark-swagger-output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,8 @@ definitions:
effectiveEndDate:
type: "string"
format: "date"
id:
type: "string"
MonitoredTrip:
type: "object"
properties:
Expand Down

0 comments on commit d81418f

Please sign in to comment.