-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #58 - fix incorrect serialization of parameter currency.
- fix null value on DocumentParameter; - added new test.
- Loading branch information
Showing
8 changed files
with
326 additions
and
50 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
src/main/java/com/whatsapp/api/domain/messages/Currency.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.whatsapp.api.domain.messages; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* The type Currency. | ||
*/ | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class Currency { | ||
@JsonProperty("fallback_value") | ||
private String fallbackValue; | ||
@JsonProperty("code") | ||
private String code; | ||
@JsonProperty("amount_1000") | ||
private long amount1000; | ||
|
||
/** | ||
* Instantiates a new Currency. | ||
*/ | ||
public Currency() { | ||
} | ||
|
||
/** | ||
* Instantiates a new Currency. | ||
* | ||
* @param fallbackValue the fallback value | ||
* @param code the code | ||
* @param amount1000 the amount 1000 | ||
*/ | ||
public Currency(String fallbackValue, String code, long amount1000) { | ||
this.fallbackValue = fallbackValue; | ||
this.code = code; | ||
this.amount1000 = amount1000; | ||
} | ||
|
||
/** | ||
* Gets fallback value. | ||
* | ||
* @return the fallback value | ||
*/ | ||
public String getFallbackValue() { | ||
return fallbackValue; | ||
} | ||
|
||
/** | ||
* Sets fallback value. | ||
* | ||
* @param fallbackValue the fallback value | ||
* @return the fallback value | ||
*/ | ||
public Currency setFallbackValue(String fallbackValue) { | ||
this.fallbackValue = fallbackValue; | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets code. | ||
* | ||
* @return the code | ||
*/ | ||
public String getCode() { | ||
return code; | ||
} | ||
|
||
/** | ||
* Sets code. | ||
* | ||
* @param code the code | ||
* @return the code | ||
*/ | ||
public Currency setCode(String code) { | ||
this.code = code; | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets amount 1000. | ||
* | ||
* @return the amount 1000 | ||
*/ | ||
public long getAmount1000() { | ||
return amount1000; | ||
} | ||
|
||
/** | ||
* Sets amount 1000. | ||
* | ||
* @param amount1000 the amount 1000 | ||
* @return the amount 1000 | ||
*/ | ||
public Currency setAmount1000(long amount1000) { | ||
this.amount1000 = amount1000; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/java/com/whatsapp/api/domain/messages/DocumentParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/java/com/whatsapp/api/domain/messages/HeaderComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/test/java/com/whatsapp/api/examples/SendTemplateMarketingMessageExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.whatsapp.api.examples; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.whatsapp.api.TestConstants; | ||
import com.whatsapp.api.WhatsappApiFactory; | ||
import com.whatsapp.api.domain.messages.BodyComponent; | ||
import com.whatsapp.api.domain.messages.ButtonComponent; | ||
import com.whatsapp.api.domain.messages.ButtonPayloadParameter; | ||
import com.whatsapp.api.domain.messages.Currency; | ||
import com.whatsapp.api.domain.messages.CurrencyParameter; | ||
import com.whatsapp.api.domain.messages.DateTime; | ||
import com.whatsapp.api.domain.messages.DateTimeParameter; | ||
import com.whatsapp.api.domain.messages.HeaderComponent; | ||
import com.whatsapp.api.domain.messages.Image; | ||
import com.whatsapp.api.domain.messages.ImageParameter; | ||
import com.whatsapp.api.domain.messages.Language; | ||
import com.whatsapp.api.domain.messages.Message.MessageBuilder; | ||
import com.whatsapp.api.domain.messages.TemplateMessage; | ||
import com.whatsapp.api.domain.messages.type.ButtonSubType; | ||
import com.whatsapp.api.domain.messages.type.CalendarType; | ||
import com.whatsapp.api.domain.templates.type.LanguageType; | ||
import com.whatsapp.api.impl.WhatsappBusinessCloudApi; | ||
|
||
import static com.whatsapp.api.TestConstants.PHONE_NUMBER_1; | ||
import static com.whatsapp.api.TestConstants.PHONE_NUMBER_ID; | ||
|
||
public class SendTemplateMarketingMessageExample { | ||
public static void main(String[] args) throws JsonProcessingException { | ||
WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); | ||
|
||
WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); | ||
|
||
|
||
var message = MessageBuilder.builder()// | ||
.setTo(PHONE_NUMBER_1)// | ||
.buildTemplateMessage(// | ||
new TemplateMessage()// | ||
.setLanguage(new Language(LanguageType.EN_US))// | ||
.setName("marketing_music_2")// | ||
.addComponent(new HeaderComponent()// | ||
.addParameter(new ImageParameter()// | ||
.setImage(new Image()// | ||
.setId("3196424913981611")// | ||
) | ||
)).addComponent(// | ||
new BodyComponent()// | ||
.addParameter(new DateTimeParameter()// | ||
.setDateTime(new DateTime()// | ||
.setCalendar(CalendarType.GREGORIAN)// | ||
.setDayOfMonth(26)// | ||
.setMonth(3)// | ||
.setYear(2023)// | ||
.setHour(10) | ||
.setMinute(50) | ||
.setDayOfWeek(1).setFallbackValue("May 10th, 2023")// | ||
))// | ||
.addParameter(new CurrencyParameter()// | ||
.setCurrency(new Currency("$35", "USD", 30000))))// | ||
|
||
.addComponent(new ButtonComponent()// | ||
.setIndex(0)// | ||
.setSubType(ButtonSubType.QUICK_REPLY)// | ||
.addParameter(new ButtonPayloadParameter("OP_SHN_454584")))// | ||
.addComponent(new ButtonComponent()// | ||
.setIndex(1)// | ||
.setSubType(ButtonSubType.QUICK_REPLY)// | ||
.addParameter(new ButtonPayloadParameter("OP_SPR_454585")))// | ||
); | ||
System.out.println(new ObjectMapper().writeValueAsString(message)); | ||
|
||
whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.