WhatsappWeb4j is a standalone library built to interact with WhatsappWeb. This means that no browser, application or any additional software is necessary to use this library. This library was built for Java 15 and JakartaEE 9. Support for Java 11, the latest LTS as of this date, will come soon. Any help to this library welcomed as long as the coding style of the project is respected.
Add this dependency to your dependencies in the pom:
<dependency>
<groupId>it.auties</groupId>
<artifactId>whatsappweb4j</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Add this dependency to your build.gradle:
implementation 'it.auties:whatsappweb4j:1.0-SNAPSHOT'
To use this library, start by initializing an instance of WhatsappAPI like this:
var api = new WhatsappAPI();
Alternatively, you can provide a custom configuration like this:
var configuration = WhatsappConfiguration.builder()
.whatsappTag("whatsapp")
.async(false)
.build()
var api = new WhatsappAPI(configuration);
Now register your listeners:
api.registerListener(new YourAwesomeListener());
Alternatively, you can annotate your listeners with @RegisterListener:
import it.auties.whatsapp4j.listener.RegisterListener;
import it.auties.whatsapp4j.listener.WhatsappListener;
@RegisterListener
public class YourAwesomeListener implements WhatsappListener {
}
IMPORTANT: Only listeners that provide a no arguments constructor can be annotated with @RegisterListener
then enable auto-detection:
api.autodetectListeners();
Open a connection with WhatsappWeb's WebSocket using:
api.connect();
To disconnect from WhatsappWeb's WebSocket use:
api.disconnect();
To disconnect and then reconnect to WhatsappWeb's WebSocket use:
api.reconnect();
To disconnect and invalidate the credentials linked with this session use:
api.logout();