diff --git a/src/main/lombok/com/restfb/types/whatsapp/platform/Message.java b/src/main/lombok/com/restfb/types/whatsapp/platform/Message.java index c28888070..e12b2ffbb 100644 --- a/src/main/lombok/com/restfb/types/whatsapp/platform/Message.java +++ b/src/main/lombok/com/restfb/types/whatsapp/platform/Message.java @@ -49,7 +49,10 @@ public class Message extends AbstractFacebookType { @Facebook private Button button; - private JsonObject context; + @Getter + @Setter + @Facebook + private Context context; @Getter @Setter @@ -160,6 +163,10 @@ public boolean hasReferral() { return referral != null; } + public boolean hasContext() { + return context != null; + } + public boolean isSystem() { return system != null; } diff --git a/src/main/lombok/com/restfb/types/whatsapp/platform/message/Context.java b/src/main/lombok/com/restfb/types/whatsapp/platform/message/Context.java new file mode 100644 index 000000000..cd7677bb5 --- /dev/null +++ b/src/main/lombok/com/restfb/types/whatsapp/platform/message/Context.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2010-2022 Mark Allen, Norbert Bartels. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.restfb.types.whatsapp.platform.message; + +import com.restfb.Facebook; +import com.restfb.types.AbstractFacebookType; +import lombok.Getter; +import lombok.Setter; + +public class Context extends AbstractFacebookType { + + /** + * Set to true if the message received by the business has been forwarded + */ + @Getter + @Setter + @Facebook + private boolean forwarded; + + /** + * Set to true if the message received by the business has been forwarded more than 5 times. + */ + @Getter + @Setter + @Facebook("frequently_forwarded") + private boolean frequentlyForwarded; + + /** + * The WhatsApp ID for the customer who replied to an inbound message + */ + @Getter + @Setter + @Facebook + private String from; + + /** + * The message ID for the sent message for an inbound reply + */ + @Getter + @Setter + @Facebook + private String id; +} diff --git a/src/test/java/com/restfb/types/WABPwebhookTest.java b/src/test/java/com/restfb/types/WABPwebhookTest.java index 6088403ed..1e5a5664f 100644 --- a/src/test/java/com/restfb/types/WABPwebhookTest.java +++ b/src/test/java/com/restfb/types/WABPwebhookTest.java @@ -231,10 +231,18 @@ void incomingMessageButton() { assertThat(message.isVoice()).isFalse(); assertThat(message.isButton()).isTrue(); + assertThat(message.hasContext()).isTrue(); + Button image = message.getButton(); assertThat(image.getText()).isEqualTo("No"); assertThat(image.getPayload()).isEqualTo("No-Button-Payload"); + Context context = message.getContext(); + assertThat(context.getFrom()).isEqualTo("PHONE_NUMBER"); + assertThat(context.getId()).isEqualTo("wamid.ID"); + assertThat(context.isForwarded()).isFalse(); + assertThat(context.isFrequentlyForwarded()).isFalse(); + assertThat(message.getTimestamp()).isEqualTo(new Date(1653253313000L)); assertThat(message.getType()).isEqualTo(MessageType.button); assertThat(message.getFrom()).isEqualTo("491234567890"); diff --git a/src/test/resources/json/whatsapp/webhook-incoming-message-button.json b/src/test/resources/json/whatsapp/webhook-incoming-message-button.json index eb8b79d9c..0b39db78a 100644 --- a/src/test/resources/json/whatsapp/webhook-incoming-message-button.json +++ b/src/test/resources/json/whatsapp/webhook-incoming-message-button.json @@ -28,6 +28,10 @@ "button": { "text": "No", "payload": "No-Button-Payload" + }, + "context": { + "from": "PHONE_NUMBER", + "id": "wamid.ID" } } ]