# Captcha

The Captcha module presents a CAPTCHA challenge during onboarding to verify human interaction and reduce automated abuse. It then returns the user's response to your app.<br /><br />In Dashboard, Captcha isn't a standalone module. Instead, enable "OTP configuration" in the module settings when adding the Email or Phone module. How you use this module depends on your [integration pattern](https://developer.incode.com/docs/android-common-implementation-patterns#integration-patterns). In Patterns 1 and 2, you add the module to a `FlowConfig` in code as shown on this page. In Pattern 3, you define your modules and configuration in Dashboard as a Flow or Workflow and reference it by ID with `startFlow()` or `startWorkflow()` as shown on [Run Flows Configured in Dashboard](https://developer.incode.com/docs/android-run-flows-configured-online).&#x20;

## Add Captcha

Add the module with `addCaptcha()`.

```kotlin
flowConfigBuilder.addCaptcha()
```
```java
flowConfigBuilder.addCaptcha();
```

### Example

The example below adds Captcha as the only step in the flow and listens for the result through `onCaptchaCollected()`.

```kotlin
val flowConfig = FlowConfig.Builder()
    .addCaptcha()
    .build()

val onboardingListener = object : OnboardingListener() {
    override fun onCaptchaCollected(captchaResult: CaptchaResult) {
        // CAPTCHA step completed. Process the result.
    }
}

IncodeWelcome.getInstance()
    .startOnboarding(activityContext, sessionConfig, flowConfig, onboardingListener)
```
```java
FlowConfig flowConfig = new FlowConfig.Builder()
    .addCaptcha()
    .build();

IncodeWelcome.OnboardingListener onboardingListener = new IncodeWelcome.OnboardingListener() {
    @Override
    public void onCaptchaCollected(@NonNull CaptchaResult captchaResult) {
        // CAPTCHA step completed. Process the result.
    }
};

IncodeWelcome.getInstance()
    .startOnboarding(activityContext, sessionConfig, flowConfig, onboardingListener);
```

## Configuration Options

Captcha has no configurable options. It is added with `addCaptcha()` and has no `Builder`. For the class reference, see `Captcha` in [API Reference](https://developer.incode.com/docs/android-api-reference\\).

## Result

Captcha delivers a `CaptchaResult` to the `onCaptchaCollected(CaptchaResult)` callback on the `OnboardingListener`. This callback is declared by `CaptchaListener`. Key fields include:

- `captchaResponse`: The CAPTCHA response string. Can be `null` when `resultCode` is not `SUCCESS`.
- Fields inherited from `BaseResult`:
  - `resultCode`: The `ResultCode` for this result.
  - `error`: When `resultCode` is `ERROR`, the `Throwable` that caused it; otherwise, `null`.
  - `deviceStats`: The `DeviceStats` snapshot of the device state when the result was produced.
  - `motionStatus`: Device motion assessment during capture. One of the following:
    - `UNCLEAR`: Motion could not be determined; the default.
    - `PASS`: Device motion was within acceptable limits.
    - `FAIL`: Excessive device motion was detected.

Errors surface via `OnboardingListener.onError(Throwable)`. Captcha does not define a module-specific exception subtype. Failures are reported with the generic `Throwable` carried in `CaptchaResult.error`. This same `Throwable` is also available on the shared `onError` path.

For all fields, see `CaptchaResult` in [API Reference](https://developer.incode.com/docs/android-api-reference).
