Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Notification String Checks and Add Alert ID #192

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading