Skip to content

Commit

Permalink
Issue #1233 - context added to incoming WABP button message
Browse files Browse the repository at this point in the history
  • Loading branch information
nbartels committed Jul 28, 2022
1 parent 5c15cc3 commit 63a5f27
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
Expand Up @@ -49,7 +49,10 @@ public class Message extends AbstractFacebookType {
@Facebook
private Button button;

private JsonObject context;
@Getter
@Setter
@Facebook
private Context context;

@Getter
@Setter
Expand Down Expand Up @@ -160,6 +163,10 @@ public boolean hasReferral() {
return referral != null;
}

public boolean hasContext() {
return context != null;
}

public boolean isSystem() {
return system != null;
}
Expand Down
@@ -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;
}
8 changes: 8 additions & 0 deletions src/test/java/com/restfb/types/WABPwebhookTest.java
Expand Up @@ -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");
Expand Down
Expand Up @@ -28,6 +28,10 @@
"button": {
"text": "No",
"payload": "No-Button-Payload"
},
"context": {
"from": "PHONE_NUMBER",
"id": "wamid.ID"
}
}
]
Expand Down

0 comments on commit 63a5f27

Please sign in to comment.