diff --git a/src/main/java/com/meta/cp4m/message/FBMessage.java b/src/main/java/com/meta/cp4m/message/FBMessage.java index 8846130..618d7b4 100644 --- a/src/main/java/com/meta/cp4m/message/FBMessage.java +++ b/src/main/java/com/meta/cp4m/message/FBMessage.java @@ -10,6 +10,7 @@ import com.meta.cp4m.Identifier; import java.time.Instant; +import org.checkerframework.checker.nullness.qual.Nullable; public record FBMessage( Instant timestamp, @@ -17,5 +18,17 @@ public record FBMessage( Identifier senderId, Identifier recipientId, String message, - Role role) - implements Message {} + Role role, + @Nullable String accessToken) + implements Message { + + public FBMessage( + Instant timestamp, + Identifier instanceId, + Identifier senderId, + Identifier recipientId, + String message, + Role role) { + this(timestamp, instanceId, senderId, recipientId, message, role, null); + } +} diff --git a/src/main/java/com/meta/cp4m/message/FBMessageHandler.java b/src/main/java/com/meta/cp4m/message/FBMessageHandler.java index a84625b..6a4369c 100644 --- a/src/main/java/com/meta/cp4m/message/FBMessageHandler.java +++ b/src/main/java/com/meta/cp4m/message/FBMessageHandler.java @@ -158,12 +158,14 @@ private List postHandler(Context ctx, JsonNode body) { @Override public void respond(FBMessage message) throws IOException { List chunkedText = CHUNKER.chunks(message.message()).toList(); + String accessToken = message.accessToken() == null ? this.accessToken : message.accessToken(); for (String text : chunkedText) { - send(text, message.recipientId(), message.senderId()); + send(text, message.recipientId(), message.senderId(), accessToken); } } - private void send(String message, Identifier recipient, Identifier sender) throws IOException { + private void send(String message, Identifier recipient, Identifier sender, String accessToken) + throws IOException { URI url; ObjectNode body = MAPPER.createObjectNode(); body.put("messaging_type", "RESPONSE").putObject("recipient").put("id", recipient.toString());