Skip to content

Commit

Permalink
fix video object in message template, new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bindambc committed Mar 26, 2023
1 parent bdcfc1e commit 10bbfee
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 63 deletions.
74 changes: 74 additions & 0 deletions src/main/java/com/whatsapp/api/domain/messages/Video.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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 Video.
*/
@JsonInclude(Include.NON_NULL)
public class Video {

@JsonProperty("id")
private String id;
@JsonProperty("link")
private String link;

/**
* Instantiates a new Video.
*/
public Video() {
}

/**
* Instantiates a new Video.
*
* @param id the id
* @param link the link
*/
public Video(String id, String link) {
this.id = id;
this.link = link;
}

/**
* Gets id.
*
* @return the id
*/
public String getId() {
return id;
}

/**
* Sets id.
*
* @param id the id
* @return the id
*/
public Video 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 Video setLink(String link) {
this.link = link;
return this;
}
}
58 changes: 18 additions & 40 deletions src/main/java/com/whatsapp/api/domain/messages/VideoParameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,46 @@
* The type Video parameter.
*/
public class VideoParameter extends Parameter {
@JsonProperty("video")
private Video video;

@JsonProperty("id")
private String id;
@JsonProperty("link")
private String link;

/**
* Instantiates a new Parameter.
*/
protected VideoParameter() {
public VideoParameter() {
super(ParameterType.VIDEO);
}

/**
* Instantiates a new Video parameter.
*
* @param id the id
* @param link the link
*/
public VideoParameter(String id, String link) {
super(ParameterType.VIDEO);
this.id = id;
this.link = link;
}

/**
* Gets id.
*
* @return the id
*/
public String getId() {
return id;
}

/**
* Sets id.
* Instantiates a new Video parameter.
*
* @param id the id
* @return the id
* @param type the type
* @param video the video
*/
public VideoParameter setId(String id) {
this.id = id;
return this;
public VideoParameter(ParameterType type, Video video) {
super(type);
this.video = video;
}

/**
* Gets link.
* Gets video.
*
* @return the link
* @return the video
*/
public String getLink() {
return link;
public Video getVideo() {
return video;
}

/**
* Sets link.
* Sets video.
*
* @param link the link
* @return the link
* @param video the video
* @return the video
*/
public VideoParameter setLink(String link) {
this.link = link;
public VideoParameter setVideo(Video video) {
this.video = video;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.whatsapp.api.WhatsappApiFactory;
import com.whatsapp.api.domain.templates.BodyComponent;
import com.whatsapp.api.domain.templates.ButtonComponent;
import com.whatsapp.api.domain.templates.Example;
import com.whatsapp.api.domain.templates.FooterComponent;
import com.whatsapp.api.domain.templates.HeaderComponent;
import com.whatsapp.api.domain.templates.MessageTemplate;
import com.whatsapp.api.domain.templates.QuickReplyButton;
import com.whatsapp.api.domain.templates.type.Category;
import com.whatsapp.api.domain.templates.type.HeaderFormat;
import com.whatsapp.api.domain.templates.type.LanguageType;
Expand All @@ -27,25 +25,18 @@ public static void main(String[] args) throws JsonProcessingException {

var template = new MessageTemplate();

template.setName("auth_code_2")//
template.setName("auth_app")//
.setCategory(Category.AUTHENTICATION)//
.setLanguage(LanguageType.EN_US)//
.addComponent(new HeaderComponent()//
.setFormat(HeaderFormat.TEXT).setText("Your authentication code for {{1}}")//
.setExample(new Example().addHeaderTextExamples("App X")))//
.setFormat(HeaderFormat.IMAGE).setExample(new Example().addHeaderHandleExamples("4::aW1hZ2UvanBlZw==:ARbzAaeBdkTpPbPQcqoRsHvmI1iJnyxkjZBXVACmVZBGfIOSNOqujojIUCIciq0OttnlTqKZNfbTV81PmOJ2t-eIrJ0MCQFNP5pfMJvAdd-PZQ:e:1680186259:3449824985304722:100002914375136:ARYJQLBIIVIUS1MCM1w"))
)//
.addComponent(new BodyComponent()//
.setText("Please use the code {{1}} to sign in to your account. Do not provide this code to third parties.")//
.setText("Hello, scan the QR code or use the code {{1}} to authenticate on the website.")//
.setExample(new Example()//
.addBodyTextExamples("784-H45-7R4")))//
.addComponent(new FooterComponent().setText("Did you not request the code? Click on 'Not me'"))//
.addComponent(new ButtonComponent()//
.addButton(new QuickReplyButton("Not me"))//


)//

.addComponent(new FooterComponent().setText("Do not share this message with anyone.'"));//

;

System.out.println(new ObjectMapper().writeValueAsString(template));
var response = whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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.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.TextParameter;
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 SendTemplateAuthMessageExample {
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.PT_BR))//
.setName("auth_app")//
.addComponent(new HeaderComponent()//
.addParameter(new ImageParameter()//
.setImage(new Image("554066036582230", null))
)

).addComponent(//
new BodyComponent()//
.addParameter(new TextParameter("T87-G74-876")))//

);
System.out.println(new ObjectMapper().writeValueAsString(message));

whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);
}
}
Loading

0 comments on commit 10bbfee

Please sign in to comment.