Class WhatsAppOtpIncomingIntentHandler

java.lang.Object
com.whatsapp.otp.android.sdk.WhatsAppOtpIncomingIntentHandler

public class WhatsAppOtpIncomingIntentHandler extends Object
Class to handle intents coming from WhatsApp
  • Constructor Details

    • WhatsAppOtpIncomingIntentHandler

      public WhatsAppOtpIncomingIntentHandler()
  • Method Details

    • processOtpCode

      public void processOtpCode(android.content.Intent intent, Consumer<String> onCodePresent, BiConsumer<WhatsAppOtpError,Exception> errorHandler)
      Process code using the onCodePresent if the code is present or handle error using errorHandler if the code is not present, if the intent is not valid, or if something else doesn't work out while extracting the code from the intent.
      Parameters:
      intent - whatsapp intent
      onCodePresent - function that receives the code if the code is present
      errorHandler - function to handle error scenarios
    • getOtpCodeFromWhatsAppIntent

      @Nullable public String getOtpCodeFromWhatsAppIntent(@NonNull android.content.Intent intent)
      Extract code from WhatsAppIntent
      Parameters:
      intent - WhatsApp intent
      Returns:
      the code
      Throws:
      InvalidWhatsAppOtpIntentException - if intent is not from WhatsApp
    • processOtpDebugSignals

      public void processOtpDebugSignals(@NonNull android.content.Intent intent, @NonNull Consumer<DebugSignal> debugSignalConsumer, @NonNull BiConsumer<WhatsAppOtpError,Exception> errorHandler)
      Process debug signals using the debugSignalConsumer if debug signals are present or handle the error using errorHandler if the debugs signals are not present.

      The debugSignalConsumer receives a DebugSignal as a parameter which contains the key and message of the debug signal.

      The errorHandler gets a WhatsAppOtpError and a Exception - if any - stating the error.

      Parameters:
      intent - a WhatsApp intent.
      debugSignalConsumer - a consumer for the debug signal
      errorHandler - a consumer for handling errors that may occur while extracting the debug signal
    • getDebugSignalFromWhatsAppIntent

      public DebugSignal getDebugSignalFromWhatsAppIntent(@NonNull android.content.Intent intent)
      Extract DebugSignal from WhatsApp Intent
      Parameters:
      intent - WhatsApp intent
      Returns:
      extracted debug signal
    • isIntentFromWhatsApp

      public boolean isIntentFromWhatsApp(@NonNull android.content.Intent intent)
      Check if the intent is from WhatsApp app by checking its pending intent creator package
      Parameters:
      intent - intent
      Returns:
      true if the intent is from whatsapp, either com.whatsapp or com.whatsapp.w4b
    • isIntentFromWhatsApp

      public boolean isIntentFromWhatsApp(@NonNull android.content.Intent intent, @NonNull WhatsAppClientType... clientType)
      Check if the intent is from WhatsApp app by checking its pending intent creator package
      Parameters:
      intent - intent
      clientType - client type which can be CONSUMER, BUSINESS or both
      Returns:
      true if the intent is from the specified app type