-
-
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 Document objetct in message templates; - fix tests; - add new tests.
- Loading branch information
Showing
7 changed files
with
261 additions
and
46 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
src/main/java/com/whatsapp/api/domain/messages/Document.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,99 @@ | ||
package com.whatsapp.api.domain.messages; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* The type Document. | ||
*/ | ||
@JsonInclude(Include.NON_NULL) | ||
public class Document { | ||
|
||
@JsonProperty("id") | ||
private String id; | ||
@JsonProperty("link") | ||
private String link; | ||
|
||
@JsonProperty("filename") | ||
private String fileName; | ||
|
||
/** | ||
* Instantiates a new Document. | ||
* | ||
* @param id the id | ||
* @param link the link | ||
* @param fileName the file name | ||
*/ | ||
public Document(String id, String link, String fileName) { | ||
this.id = id; | ||
this.link = link; | ||
this.fileName = fileName; | ||
} | ||
|
||
/** | ||
* Instantiates a new Document. | ||
*/ | ||
public Document() { | ||
} | ||
|
||
/** | ||
* Gets id. | ||
* | ||
* @return the id | ||
*/ | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* Sets id. | ||
* | ||
* @param id the id | ||
* @return the id | ||
*/ | ||
public Document setId(String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets link. | ||
* | ||
* @return the link | ||
*/ | ||
public String getLink() { | ||
return link; | ||
} | ||
|
||
/** | ||
* Sets link. | ||
* | ||
* @param link the link | ||
* @return the link | ||
*/ | ||
public Document setLink(String link) { | ||
this.link = link; | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets file name. | ||
* | ||
* @return the file name | ||
*/ | ||
public String getFileName() { | ||
return fileName; | ||
} | ||
|
||
/** | ||
* Sets file name. | ||
* | ||
* @param fileName the file name | ||
* @return the file name | ||
*/ | ||
public Document setFileName(String fileName) { | ||
this.fileName = fileName; | ||
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
54 changes: 54 additions & 0 deletions
54
src/test/java/com/whatsapp/api/examples/SendTemplateUtilityDocumentMessageExample.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,54 @@ | ||
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.ButtonTextParameter; | ||
import com.whatsapp.api.domain.messages.Document; | ||
import com.whatsapp.api.domain.messages.DocumentParameter; | ||
import com.whatsapp.api.domain.messages.HeaderComponent; | ||
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.TextParameter; | ||
import com.whatsapp.api.domain.messages.type.ButtonSubType; | ||
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 SendTemplateUtilityDocumentMessageExample { | ||
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("new_classes_pdf")// | ||
.addComponent(new HeaderComponent()// | ||
.addParameter(new DocumentParameter()// | ||
.setDocument(new Document()// | ||
.setFileName("Class.pdf").setId("928860901494862")// | ||
))// | ||
).addComponent(// | ||
new BodyComponent()// | ||
.addParameter(new TextParameter("Mauricio Binda")))// | ||
.addComponent(new ButtonComponent()// | ||
.setIndex(0)// | ||
.setSubType(ButtonSubType.URL)// | ||
.addParameter(new ButtonTextParameter("career-academy/?trk_ref=globalnav")))// | ||
|
||
); | ||
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
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
Oops, something went wrong.