View as Markdown

Texts and reminders · Reference

Text consent for Kotlin

com.provenanceauth:text-consent puts the consent to text step and box in your own Android app, as two Jetpack Compose composables: TextConsentStep before your request screen and TextConsent on your sign-up or intake screen. Each records with surface: "kotlin". The library needs Android 7.0 (API 24) or later.

This package isn't on Maven Central yet. Until then, every request in these docs runs over HTTP against the sandbox.

With access to the private Provenance repository, which your Provenance contact grants, install from it:

git clone https://github.com/michaelnbane-jpg/provenance.git provenance
// settings.gradle
includeBuild("provenance/kotlin/provenance-text-consent")
// your app's build.gradle
implementation("com.provenanceauth:text-consent:1.0.0")

TextConsentStep

The opt-in step a company's app shows before its own request screen, under Provenance asks. It reads the request, shows Texts from with your company's name and the masked phone, Provenance's wording with Terms · Privacy, Not now and Text me, Next with the request, and the Provenance mark.

import com.provenanceauth.textconsent.TextConsentStep
import com.provenanceauth.textconsent.TextConsentStepSource

TextConsentStep(
    baseUrl = apiUrl,
    source = TextConsentStepSource.CaptureEmbedToken(captureToken, publishableKey),
) { outcome ->
    showRequestScreen()
}
ParameterTypeWhat it is
baseUrlStringYour Provenance API's base URL
sourceTextConsentStepSourceThe request: CaptureEmbedToken(embedToken, publishableKey) or CaptureLink(token)
transportTextConsentTransportOptional. The HTTP client; HttpUrlConnectionTransport() by default
onError(TextConsentException) -> UnitOptional. A refusal or a network failure
onFinish(TextConsentStepOutcome) -> UnitCalled once when the step ends; show your request screen then

Mint the embed token on your backend with { "widget": "capture", "object_id": "capr_…" }, as for the capture widget. The capture link's token is the part after /capture/ in the request's link.

TextConsentStepOutcomeWhen
AGREEDText me recorded the consent
NOT_NOWNot now: nothing was sent and nothing is stored
NOT_OFFEREDThe request offers no step, or it couldn't be read: the composable draws nothing and finishes at once

The step is offered only when your mode is Provenance asks, you're on the Pro plan or above, the request carries a phone with text in its channels, and that phone has no consent for you and no stop. A refused Text me stays on the step with the reason under the wording.

TextConsent

The consent box for your own form, in either mode. One box, unticked on every load, with the wording beside it, Terms · Privacy and the Provenance mark. Ticking it with a valid phone records a box consent; unticking withdraws it. On the Free plan it draws nothing.

import com.provenanceauth.textconsent.TextConsent

TextConsent(
    baseUrl = apiUrl,
    publishableKey = publishableKey,
    embedToken = textConsentToken,
    phone = mobile,
) { consentId ->
    viewModel.consentId = consentId
}
ParameterTypeWhat it is
baseUrlStringYour Provenance API's base URL
publishableKeyStringA publishable key with no allowed origins: an app sends no Origin
embedTokenStringA token your backend minted with { "widget": "text_consent", "object_id": "<box_id>" }
phoneStringThe mobile number your screen collected: E.164, or ten US digits
onConsented(String) -> UnitOptional. The record's id after a tick
onWithdrawn(String) -> UnitOptional. The record's id after an untick
onError(TextConsentException) -> UnitOptional. A refusal or a network failure

Read the record from your backend with GET /v1/account/text_consents/{id} before you rely on it. It shows as Your app in Agreed to texts, with no form_origin.

Neither composable takes a colour, font, modifier or checked argument: the wording, the box and the mark can't be restyled or pre-ticked. Both follow the system's light or dark setting. The library declares the INTERNET permission.

The calls they make

ComposableReadRecordUndo
TextConsentStep, embed tokenGET /v1/embed/capture_request ?surface=kotlinPOST /v1/embed/text_consents { step: true, wording_version, surface }None: a consent is withdrawn by the person
TextConsentStep, capture linkGET /v1/attest/capture_links ?surface=kotlinPOST /v1/public/text_consents { link_token, wording_version, surface }None
TextConsentGET /v1/embed/text_consents/form ?surface=kotlinPOST /v1/embed/text_consents { phone, wording_version, surface }POST /v1/embed/text_consents/{id}/withdraw

The step never sends a phone: the token decides your account, the request and its phone. Every call sends User-Agent: provenance-kotlin/1.0.0 (text-consent). TextConsentClient makes the same calls without a composable, and TextConsentStepModel and TextConsentBoxModel hold the composables' state as StateFlows for your own layout or tests.

TextConsentException

FieldWhat it is
codeThe API's error code, such as plan_required or parameter_invalid, or network_error when nothing came back
messageA sentence you can show
statusThe HTTP status, or 0 with no answer

See also