Skip to content

Commit

Permalink
Issue #1230 - incoming wabp sticker
Browse files Browse the repository at this point in the history
  • Loading branch information
nbartels committed Jul 3, 2022
1 parent e878afb commit 7a08e13
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 10 deletions.
12 changes: 8 additions & 4 deletions src/main/lombok/com/restfb/types/whatsapp/platform/Message.java
Expand Up @@ -28,10 +28,7 @@
import com.restfb.Facebook;
import com.restfb.json.JsonObject;
import com.restfb.types.AbstractFacebookType;
import com.restfb.types.whatsapp.platform.message.Image;
import com.restfb.types.whatsapp.platform.message.MessageType;
import com.restfb.types.whatsapp.platform.message.Text;
import com.restfb.types.whatsapp.platform.message.Video;
import com.restfb.types.whatsapp.platform.message.*;

import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -74,6 +71,11 @@ public class Message extends AbstractFacebookType {

private JsonObject system;

@Getter
@Setter
@Facebook
private Sticker sticker;

@Getter
@Setter
@Facebook
Expand Down Expand Up @@ -101,4 +103,6 @@ public boolean isText() {
public boolean isImage() { return image != null; }

public boolean isVideo() { return video != null; }

public boolean isSticker() { return sticker != null; }
}
@@ -0,0 +1,54 @@
/*
* 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 Sticker extends AbstractFacebookType {

/**
* ID for the sticker
*/
@Getter
@Setter
@Facebook
private String id;

/**
* image/webp
*/
@Getter
@Setter
@Facebook("mime_type")
private String mimeType;

/**
* Hash for the sticker
*/
@Getter
@Setter
@Facebook
private String sha256;
}
42 changes: 36 additions & 6 deletions src/test/java/com/restfb/types/WABPwebhookTest.java
Expand Up @@ -21,6 +21,12 @@
*/
package com.restfb.types;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Date;

import org.junit.jupiter.api.Test;

import com.restfb.AbstractJsonMapperTests;
import com.restfb.types.webhook.ChangeValue;
import com.restfb.types.webhook.WebhookEntry;
Expand All @@ -29,13 +35,9 @@
import com.restfb.types.whatsapp.platform.Contact;
import com.restfb.types.whatsapp.platform.Message;
import com.restfb.types.whatsapp.platform.message.Image;
import com.restfb.types.whatsapp.platform.message.Video;
import com.restfb.types.whatsapp.platform.message.MessageType;
import org.junit.jupiter.api.Test;

import java.util.Date;

import static org.assertj.core.api.Assertions.assertThat;
import com.restfb.types.whatsapp.platform.message.Sticker;
import com.restfb.types.whatsapp.platform.message.Video;

class WABPwebhookTest extends AbstractJsonMapperTests {

Expand Down Expand Up @@ -118,6 +120,34 @@ void incomingMessageVideo() {
assertThat(message.getFrom()).isEqualTo("491234567890");
}

@Test
void incomingMessageSticker() {
WhatsappMessagesValue change = getWHObjectFromJson("webhook-incoming-message-sticker", WhatsappMessagesValue.class);
assertThat(change).isInstanceOf(WhatsappMessagesValue.class);

checkContact(change);

checkMetaData(change);

// check Message
assertThat(change.getMessages()).hasSize(1);
Message message = change.getMessages().get(0);
assertThat(message.getSticker()).isNotNull();
assertThat(message.isImage()).isFalse();
assertThat(message.isText()).isFalse();
assertThat(message.isVideo()).isFalse();
assertThat(message.isSticker()).isTrue();

Sticker image = message.getSticker();
assertThat(image.getId()).isEqualTo("1122990445227715");
assertThat(image.getMimeType()).isEqualTo("image\\/webp");
assertThat(image.getSha256()).isEqualTo("RZEEl5HVWT4S6C0PoOgjYCQVDWs5esIMJsjcDYI80ZE=");

assertThat(message.getTimestamp()).isEqualTo(new Date(1653253313000L));
assertThat(message.getType()).isEqualTo(MessageType.sticker);
assertThat(message.getFrom()).isEqualTo("491234567890");
}

private void checkMetaData(WhatsappMessagesValue change) {
// check Metadata
assertThat(change.getMetadata()).isNotNull();
Expand Down
@@ -0,0 +1,41 @@
{
"object": "whatsapp_business_account",
"entry": [
{
"id": "101809759215303",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "1234567891",
"phone_number_id": "10634295353625"
},
"contacts": [
{
"profile": {
"name": "TestUser"
},
"wa_id": "491234567890"
}
],
"messages": [
{
"from": "491234567890",
"id": "wamid.HBgNNDkxNTIwOTgzMzM5OBUCABIYHGDEHJVFHJEVCFHJEVBCMTkyODk1OEIyAA==",
"timestamp": "1653253313",
"type": "sticker",
"sticker": {
"mime_type": "image\\/webp",
"sha256": "RZEEl5HVWT4S6C0PoOgjYCQVDWs5esIMJsjcDYI80ZE=",
"id": "1122990445227715"
}
}
]
},
"field": "messages"
}
]
}
]
}

0 comments on commit 7a08e13

Please sign in to comment.