Skip to content

How to run the web server#





implementation group: '', name: 'whatsapp-api-webhook-server-java', version: '0.0.1'


How to initialize an object#

Set server options in application.yml. The WebhookToken attribute is optional and does not need to be assigned a value, but it must be in application.yml. If you don't want to set a password, you can simply leave the webhookToken parameter without a value.

  webhookToken: 1a2b3c4d5e
  port: 8080

How to run the web server#

Applications will start listening the port immediately after running the main method; for this, do not forget to add the @ComponentScan(basePackages = "com.greenapi.server") annotation.

Link to example:

@ComponentScan(basePackages = "com.greenapi.server")
public class WhatsappApiServerExample {
     public static void main(String[] args) {, args);

The handler function class must implement the WebhookHandler interface and be a bean named whatsappWebhookHandler. To do this, set the @Component(value = "whatsappWebhookHandler") annotation on the handler function class.

Link to example:

@Component(value = "whatsappWebhookHandler")
public class WebhookHandlerExample implements WebhookHandler {

     public void handle(Notification notification) {
         System.out.println("START " + notification);
         System.out.println("END " + notification);

Webhook URL: {{your host}}/whatsapp/async/webhook If you want your handle() handler function to be executed asynchronously.

Webhook URL: {{your host}}/whatsapp/webhook If you want your handle() handler function to be called for each webhook sequentially in one thread.

Since each notification is automatically cast to a java object, you can filter the notification by any field yourself. A description of the structure of notification objects can be found at this link: Documentation For convenience, all types of hooks and messages are named similarly to the documentation:

Java object Webhook's json object
TextMessageWebhook TextMessage
TemplateMessageWebhook TemplateMessage
StickerMessageWebhook StickerMessage
ReactionMessageWebhook ReactionMessage
QuotedMessageWebhook QuotedMessage
PollUpdateMessageWebhook PollUpdateMessage
PollMessageWebhook PollMessage
LocationMessageWebhook LocationMessage
ListMessageWebhook ListMessage
GroupInviteMessageWebhook GroupInviteMessage
FileMessageWebhook imageMessage, videoMessage, documentMessage, audioMessage
ExtendedTextMessageWebhook ExtendedTextMessage
ButtonsMessageWebhook ButtonsMessage
ContactMessageWebhook ContactMessage
ContactsArrayMessageWebhook ContactMessage
TemplateButtonsReplyMessageWebhook TemplateButtonsReplyMessage
ButtonsResponseMessageWebhook ButtonsResponseMessage
ListResponseMessageWebhook ListResponseMessage

Running the application#

For JAR file:

java -jar your_app.jar

If using Maven, run from the project directory:

./mvnw spring-boot:run