Loading repository data…
Loading repository data…
Bindambc / repository
Whatsapp business api SDK, written in java. This SDK implements the Official Whatsapp Cloud API and WhatsApp Business Management API. These allows you to: manage your WhatsApp Business Account assets, such as message templates and phone numbers; send messages to your contacts, such as simple text messages, messages with buttons...
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
Whatsapp business api SDK, written in java. This SDK implements the Official Whatsapp Cloud API and WhatsApp Business Management API. These allows you to:
The WhatsApp Business API allows medium and large businesses to communicate with their customers at scale. Using the API, businesses can build systems that connect thousands of customers with agents or bots, enabling both programmatic and manual communication. Additionally, you can integrate the API with numerous backend systems, such as CRM and marketing platforms.The library is designed to be simple and flexible, making it ideal for a wide range of use cases.
This SDK supports WhatsApp Business API versions from v16.0 onwards.
:warning: This project is still under construction. Contributions are welcome.
See javadoc
:warning: this library is compatible with java 17+.
1. Add the JitPack repository to your build file:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
2. Add the following Maven dependency to your project's pom.xml:
<dependency>
<groupId>com.github.Bindambc</groupId>
<artifactId>whatsapp-business-java-api</artifactId>
<version>v0.6.1</version>
</dependency>
1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
2. Add the dependency
dependencies {
implementation 'com.github.Bindambc:whatsapp-business-java-api:v0.6.1'
}
3. Install library into your Maven's local repository by running mvn install
Alternatively, you can clone this repository and run the examples.
There are two client classes that can be used to interact with the API:
WhatsappBusinessCloudApi, a synchronous/blocking WhatsApp Business Platform Cloud API client;Send and receive messages using a cloud-hosted version of the WhatsApp Business Platform. The Cloud API allows you to implement WhatsApp Business APIs without the cost of hosting of your own servers and also allows you to more easily scale your business messaging.
WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestUtils.TOKEN);
WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(ApiVersion.V19_0);
WhatsappBusinessManagementApi, a synchronous/blocking WhatsApp Business Management API client;The WhatsApp Business Management API allows you to programmatically manage your WhatsApp Business Account assets, such as message templates and phone numbers.
WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN);
WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(ApiVersion.V19_0);
These can be instantiated through the corresponding factory method of WhatsappApiFactory, by passing the token, which can be created following the instructions at whatsapp.
You can add a proxy to the api by calling the method setHttpProxy(...) of class WhatsappApiServiceGenerator
public static void setHttpProxy(String host, int port, String username, String pwd)
Call this method before create the api instance like:
// Set http proxy with credentials before the creation of the api instance
WhatsappApiServiceGenerator.setHttpProxy("<YOUR_PROXY_HOST>", "<YOUR_PROXY_PORT>", "<YOUR_PROXY_USERNAME>", "<YOUR_PROXY_PWD>");
// Create the api instance
WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi();
WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN);
// Set http proxy without credentials before the creation of the api instance
WhatsappApiServiceGenerator.setHttpProxy("localhost", 8080, null,null);
WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi();
var message = MessageBuilder.builder()//
.setTo(PHONE_NUMBER_1)//
.buildTextMessage(new TextMessage()//
.setBody(Formatter.bold("Hello world!") + "\nSome code here: \n" + Formatter.code("hello world code here"))//
.setPreviewUrl(false));
MessageResponse messageResponse = whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);
System.out.println(messageResponse);
WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN);
// Set http proxy with credentials before the creation of the api instance
WhatsappApiServiceGenerator.setHttpProxy("localhost", 8080, "username", "password");
WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi();
var message = MessageBuilder.builder()//
.setTo(PHONE_NUMBER_1)//
.buildTextMessage(new TextMessage()//
.setBody(Formatter.bold("Hello world!") + "\nSome code here: \n" + Formatter.code("hello world code here"))//
.setPreviewUrl(false));
MessageResponse messageResponse = whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);
System.out.println(messageResponse);
WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestUtils.TOKEN);
WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi();
var message = MessageBuilder.builder()//
.setTo(PHONE_NUMBER_1)//
.buildTextMessage(new TextMessage()//
.setBody(Formatter.bold("Hello world!") + "\nSome code here: \n" + Formatter.code("hello world code here"))//
.setPreviewUrl(false));
whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);
Result:
