Skip to content

Commit

Permalink
Replace some strings with enums
Browse files Browse the repository at this point in the history
  • Loading branch information
sgdesmet committed Jan 2, 2024
1 parent 5c2c310 commit bb88267
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.whatsapp.api.domain.webhook;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.whatsapp.api.domain.webhook.type.InteractiveType;

import static com.fasterxml.jackson.annotation.JsonFormat.Feature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE;

/**
* The type Interactive.
Expand All @@ -11,11 +15,12 @@
* @param buttonReply Used on Webhooks related to Reply Buttons. Contains a {@link ButtonReply} reply object.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonFormat(with = READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE)
public record Interactive(

@JsonProperty("list_reply") ListReply listReply,

@JsonProperty("type") String type,
@JsonProperty("type") InteractiveType type,

@JsonProperty("button_reply") ButtonReply buttonReply) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.whatsapp.api.domain.webhook;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.whatsapp.api.domain.webhook.type.WebhookType;

import java.util.List;

import static com.fasterxml.jackson.annotation.JsonFormat.Feature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE;

/**
* This class is a representation of the json object sent by the WhatsApp webhook.
* Whenever a trigger event occurs, the WhatsApp Business Platform sees the event and sends a notification to a Webhook URL you have previously specified.
Expand All @@ -15,5 +19,6 @@
* @see <a href="https://developers.facebook.com/docs/whatsapp/cloud-api/guides/set-up-webhooks">Webhooks Setup Guide</a> to more details.
**/
@JsonIgnoreProperties(ignoreUnknown = true)
public record WebHookEvent(@JsonProperty("entry") List<Entry> entry, @JsonProperty("object") String object) {
@JsonFormat(with = READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE)
public record WebHookEvent(@JsonProperty("entry") List<Entry> entry, @JsonProperty("object") WebhookType object) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.whatsapp.api.domain.webhook.type;

import com.fasterxml.jackson.annotation.JsonEnumDefaultValue;

public enum InteractiveType {
button_reply, list_reply,
@JsonEnumDefaultValue
unknown
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.whatsapp.api.domain.webhook.type;

import com.fasterxml.jackson.annotation.JsonEnumDefaultValue;

public enum WebhookType {
whatsapp_business_account,
@JsonEnumDefaultValue
unknown
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void testDeserializationStickerMessage() throws IOException, URISyntaxException

var obj = WebHook.constructEvent(payload);

Assertions.assertEquals("whatsapp_business_account", obj.object());
Assertions.assertEquals("whatsapp_business_account", obj.object().name());
Assertions.assertFalse(obj.entry().isEmpty());
Assertions.assertEquals("880480571844883", obj.entry().get(0).id());

Expand All @@ -229,7 +229,7 @@ void testDeserializationVideoMessage() throws IOException, URISyntaxException {

var obj = WebHook.constructEvent(payload);

Assertions.assertEquals("whatsapp_business_account", obj.object());
Assertions.assertEquals("whatsapp_business_account", obj.object().name());
Assertions.assertFalse(obj.entry().isEmpty());
Assertions.assertEquals("880480571844883", obj.entry().get(0).id());

Expand Down

0 comments on commit bb88267

Please sign in to comment.