How to Integrate WhatsApp for Sending Messages in Your Application
Prerequisites
Key Components of the Integration
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TemplateDto {
private String name;
private LanguageDto language;
private List<ComponentDto> components;
public TemplateDto(LanguageDto language, List<ComponentDto> components) {
this.name = AppConstant.TEMPLATE; // Customizable template name
this.language = language; // Customizable language
this.components = components;
}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RequestDto {
private String messaging_product = "whatsapp";
private String recipient_type = "individual";
private String to;
private String type = "template";
private TemplateDto template;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ParameterDto {
private String type;
private String text;
public ParameterDto(String text) {
this.type = "text";
this.text = text;
}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class LanguageDto {
private String code = "en_US";
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ComponentDto {
private String type;
private String sub_type;
private int index;
private List<ParameterDto> parameters;
public ComponentDto(List<ParameterDto> parameters) {
this.type = "body";
this.parameters = parameters;
}
public ComponentDto(String subType, List<ParameterDto> parameters) {
this.type = subType;
this.sub_type = "url";
this.index = 0;
this.parameters = parameters;
}
}Steps to Send a WhatsApp Message
Customization
Testing the Integration
Conclusion
Last updated