Class WhatsAppClient


  • public class WhatsAppClient
    extends java.lang.Object
    Class that handles the processing of the notification object. This class is responsible for performing Webhook verification, as well parsing the notification object.
    Author:
    katusiimeconrad
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String challenge
      Used to verify the webhook.
      private java.lang.String mode
      Stores the mode of the request e.g.
      private java.lang.String verificationToken
      A token set by the application to use for authentication with the whatsapp endpoint.
      private java.lang.String verify_token
      The secret key used to verify the webhook.
    • Constructor Summary

      Constructors 
      Constructor Description
      WhatsAppClient​(java.lang.String verificationToken)  
    • Field Detail

      • mode

        private java.lang.String mode
        Stores the mode of the request e.g. "subscribe" or "unsubscribe".
      • verify_token

        private java.lang.String verify_token
        The secret key used to verify the webhook. To be set in the webhook configuration in WhatsApp.
      • challenge

        private java.lang.String challenge
        Used to verify the webhook.
      • verificationToken

        private java.lang.String verificationToken
        A token set by the application to use for authentication with the whatsapp endpoint. Set by me in this application
    • Constructor Detail

      • WhatsAppClient

        public WhatsAppClient​(java.lang.String verificationToken)
    • Method Detail

      • doAuth

        public java.lang.String doAuth​(java.util.Map<java.lang.String,​java.lang.String> params)
                                throws java.lang.Exception
        Performs the authentication of the webhook. By extracting the token from the request and comparing it to the token set in the webhook configuration.
        Returns:
        challenge
        Throws:
        java.lang.Exception
      • getNotification

        public MessageEntity getNotification​(NotificationObject notificationObject)
                                      throws java.lang.Exception
        Handles the receiving of the notifications from the whatsapp webhook.

        Receives the body of the request and extracts Message, From, To, Type and Id. Can be modified to extract more information from the request.

        Returns the Notification object to the Caller.

        Guide : ...

        Parameters:
        notificationObject - - the body of the request
        Returns:
        Throws:
        java.lang.Exception
      • getVerificationToken

        public java.lang.String getVerificationToken()
      • setVerificationToken

        public void setVerificationToken​(java.lang.String verificationToken)