diff --git a/src/main/java/com/meta/cp4m/message/FBMessageHandler.java b/src/main/java/com/meta/cp4m/message/FBMessageHandler.java index 68772b7..e555416 100644 --- a/src/main/java/com/meta/cp4m/message/FBMessageHandler.java +++ b/src/main/java/com/meta/cp4m/message/FBMessageHandler.java @@ -44,7 +44,7 @@ public class FBMessageHandler implements MessageHandler { private final String appSecret; private final String accessToken; - private final String owningPageID; + @Nullable private final String owningPageID; private final Deduplicator messageDeduplicator = new Deduplicator<>(10_000); private Function baseURLFactory = @@ -63,7 +63,7 @@ public class FBMessageHandler implements MessageHandler { } }; - public FBMessageHandler(String verifyToken, String pageAccessToken, String appSecret, String owningPageID) { + public FBMessageHandler(String verifyToken, String pageAccessToken, String appSecret, @Nullable String owningPageID) { this.verifyToken = verifyToken; this.appSecret = appSecret; this.accessToken = pageAccessToken; @@ -74,7 +74,7 @@ public FBMessageHandler(String verifyToken, String pageAccessToken, String appSe this.verifyToken = verifyToken; this.appSecret = appSecret; this.accessToken = pageAccessToken; - this.owningPageID = "-1"; + this.owningPageID = null; } FBMessageHandler(FBMessengerConfig config) { @@ -220,7 +220,7 @@ private void send(String message, Identifier recipient, Identifier sender) throw try { bodyString = MAPPER.writeValueAsString(body); url = - new URIBuilder(baseURLFactory.apply(owningPageID.equals("-1") ? sender : Identifier.from(owningPageID))) + new URIBuilder(baseURLFactory.apply(owningPageID == null ? sender : Identifier.from(owningPageID))) .addParameter("access_token", accessToken) .build(); } catch (JsonProcessingException | URISyntaxException e) { diff --git a/src/main/java/com/meta/cp4m/message/FBMessengerConfig.java b/src/main/java/com/meta/cp4m/message/FBMessengerConfig.java index 6ebc8d2..7ab7878 100644 --- a/src/main/java/com/meta/cp4m/message/FBMessengerConfig.java +++ b/src/main/java/com/meta/cp4m/message/FBMessengerConfig.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Preconditions; +import org.jetbrains.annotations.Nullable; import java.util.Optional; import java.util.UUID; @@ -20,6 +21,7 @@ public class FBMessengerConfig implements HandlerConfig { private final String verifyToken; private final String appSecret; private final String pageAccessToken; + @Nullable private final String owningPageID; private FBMessengerConfig( @@ -27,7 +29,7 @@ private FBMessengerConfig( @JsonProperty("verify_token") String verifyToken, @JsonProperty("app_secret") String appSecret, @JsonProperty("page_access_token") String pageAccessToken, - @JsonProperty("owning_page_id") String owningPageID) { + @JsonProperty("owning_page_id") @Nullable String owningPageID) { Preconditions.checkArgument(name != null && !name.isBlank(), "name cannot be blank"); Preconditions.checkArgument( @@ -41,10 +43,10 @@ private FBMessengerConfig( this.verifyToken = verifyToken; this.appSecret = appSecret; this.pageAccessToken = pageAccessToken; - this.owningPageID = owningPageID == null || owningPageID.isBlank() ? "-1" : owningPageID; + this.owningPageID = owningPageID; } - public static FBMessengerConfig of(String verifyToken, String appSecret, String pageAccessToken, String owningPageID) { + public static FBMessengerConfig of(String verifyToken, String appSecret, String pageAccessToken, @Nullable String owningPageID) { // human readability of the name only matters when it's coming from a config return new FBMessengerConfig( UUID.randomUUID().toString(), verifyToken, appSecret, pageAccessToken, owningPageID); @@ -53,7 +55,7 @@ public static FBMessengerConfig of(String verifyToken, String appSecret, String public static FBMessengerConfig of(String verifyToken, String appSecret, String pageAccessToken) { // human readability of the name only matters when it's coming from a config return new FBMessengerConfig( - UUID.randomUUID().toString(), verifyToken, appSecret, pageAccessToken, "-1"); + UUID.randomUUID().toString(), verifyToken, appSecret, pageAccessToken, null); } @Override