Skip to contentSkip to navigationSkip to topbar
Page tools
Useful for sharing or LLM
Accelerate development with AI

On this page
Looking for more inspiration?Visit the

Embed compliance registration in your app


(new)

Check individual feature for Beta status

Compliance Embed is at a different release stage for each program. Toll-Free Verification and Secondary Customer Profiles are Public Beta. US A2P 10DLC and Regulatory Compliance Bundles are Private Beta. The information contained in this document is subject to change. Some features are not yet implemented and others may be changed before a program is declared as Generally Available. See each program's guide for its current release stage.

To use the Compliance Embeddable API, request access(link takes you to an external page).

With global regulatory requirements frequently changing across jurisdictions, navigating compliance is an expensive, ongoing challenge. While maintaining internal compliance tooling consumes significant engineering resources, complex requirements lead to customer confusion and registration drop-offs. To address these challenges, Compliance Embed shifts development and regulatory management burden away from your team.

While Twilio manages the underlying registration workflow infrastructure, your end customers can manage their registration and verification requests.

To allow the end customers of an Independent Software Vendor (ISV) to comply with regulations, Twilio provides the Compliance Embed solution. The Compliance Embed provides an unbranded, self-service solution designed to integrate seamlessly into an ISV-hosted web app.

To create this self-service experience, ISVs complete the following activities:

  1. From their servers, the ISV calls the Twilio ComplianceInquiry Initialize API resource. This returns a session token and session ID.
  2. In their web app, the ISV creates a React component or JavaScript instance that renders a form in an iframe tag. This form connects to the compliance inquiry in Twilio through the ID and token.
  3. The end customer completes and submits their compliance request through the ISV web app.
  4. If it succeeds, the end customer can send messages. If it fails, the end customer can, in most cases, resubmit their request through the ISV's web app.

Compliance Embed can use your branding. Twilio manages the compliance logic and regulatory question flows, but you can match the end-user experience to match your brand design, typography, and color palette. Custom themes require Twilio support(link takes you to an external page).


How the Compliance Embed works

how-the-compliance-embed-works page anchor

To deploy Compliance Embed, complete two activities:

  1. Start a compliance session. To initialize a ComplianceInquiry, make a request to Twilio's API. The response includes a session ID and a session token. The endpoint and request parameters differ per program, so you need to refer to the guide for your program.
  2. Add a compliance form to your app. Embed the form using the React or JavaScript SDK, passing the session ID and session token. This process works the same for every program.

Before you begin, complete the following tasks:

  1. Create a paid Twilio account(link takes you to an external page), if needed. You can't use a trial account.
  2. Get an approved Trust Hub Primary Customer Profile in the Twilio Console(link takes you to an external page) with a Business Identity of ISV or Reseller.
  3. Add Persona(link takes you to an external page) to the allow list on your firewall. To manage compliance, Twilio uses this service.
  4. Create a Content Security Policy (CSP)(link takes you to an external page) for your web app as another layer of security.

Authenticate with Twilio API

api-auth page anchor

You must authenticate all requests using Twilio's REST API credentials with HTTP Basic Auth.

  • Use your account SID as the username and your token as the password.
  • The account SID can be either your primary Twilio Account SID or a subaccount SID.

The registration binds to the Account SID you provided in the credentials after completion of the ComplianceInquiry.


Initiate a compliance session

server page anchor

To initiate a compliance session, make an HTTPS POST request for the compliance program that needs approval:

To expedite compliance registration, you can pre-populate customer entity data during initialization.

The Initialize ComplianceInquiry resource for each program returns the session ID and token.

  • The US A2P 10DLC resource returns these values in the sessionId and sessionToken properties.
  • The Toll-Free Verification, Secondary Customer Profile, and Regulatory Compliance Bundle resources return these values in the inquiry_id and inquiry_session_token properties.

Write integration code into your app

client page anchor

After you initialize a session on the server, embed the form in your app using one of the Compliance Embed SDKs. To embed the form, use the React SDK for React apps or the JavaScript SDK for any other framework. The SDKs need the session ID and session token returned from the Initialize ComplianceInquiry resources.

  • For the US A2P 10DLC resource, use the sessionId and sessionToken property values.
  • For the Toll-Free Verification, Secondary Customer Profile, Regulatory Compliance Bundle resources, use the inquiry_id and inquiry_session_token property values.
(warning)

Always fetch sessions from your backend server

Don't make Initialize resource requests from the browser. That would expose your Twilio API credentials.

React SDKJavaScript SDK

Prerequisites

  • Install React 19 or later.

  • Install Node 22 or later.

  • Install @twilio/twilio-compliance-embed-react(link takes you to an external page) and its peer dependencies.

  • Install persona-react(link takes you to an external page)

    1
    npm install @twilio/twilio-compliance-embed-react \
    2
    react react-dom persona-react

Create a TwilioComplianceEmbed React component

To render a TwilioComplianceEmbed component for your form, include the session values that you received from the Initialize API request:

1
import { TwilioComplianceEmbed } from "@twilio/twilio-compliance-embed-react";
2
3
function VerificationPage() {
4
return (
5
<TwilioComplianceEmbed
6
sessionId="{your-session-ID}"
7
sessionToken="{your-session-token}"
8
onReady={() => console.log("Ready")}
9
onComplete={() => console.log("Complete")}
10
/>
11
);
12
}
  • When mounted, the component renders the form.
  • When unmounted, the component cleans up.
  • To control visibility, use standard React patterns.

When the persona-react module loads, it references the browser's global variable self(link takes you to an external page). This self exists only in the browser. As modern web frameworks render web pages on the server before sending them to your browser, this could cause your server to crash. As a solution during server-side rendering, these frameworks, like Next.js(link takes you to an external page), create placeholder values for variables, or polyfill(link takes you to an external page), browser globals, like self.

If you run Node.js without a framework, it throws a ReferenceError when importing persona-react. To prevent this error, delay the import until the code runs in the end customer's browser. This requires using useEffect(link takes you to an external page), which only executes in the browser and never the server. In addition, if using Next.js, disable server-side rendering on that component with ssr: false.

To learn about the React SDK parameters, see the React SDK README(link takes you to an external page).


The onEvent callback receives one JSON document with one required name field and one optional JSON data object. The name field returns one of the following values:

  • start
  • page-change
  • document-upload
  • one-time-link-sent
  • one-time-link-start
  • one-time-link-exit

Example call to get event data

example-call-to-get-event-data page anchor
1
onEvent: (event) => {
2
console.log(event.name, event.data);
3
}

Page change event

page-change-event page anchor

The page-change event includes the height of the current page as pageHeight in its data object. The event expresses the pageHeight value as a positive integer representing the screen pixels. If you render inline with the JavaScript SDK, resize your container with this value as the user moves through the flow. The React SDK handles resizing for you.


The onSubmit callback receives a JSON document with an outcome field with values like success, failed, or review-pending. When the end customer reaches the final screen, this triggers the callback. This happens independent of onComplete. Each final screen fires onSubmit at most once per instance.


Handle errors

errors page anchor

The onError callback receives an object with a numeric code and a human-readable message. It also includes a sessionId for runtime errors, but not for configuration errors.

To handle these errors, log the code and message and provide your customer a way to retry.

(new)

Error codes can change during the beta

Don't write logic that depends on a specific code value.


Consider end customer browser issues

consider-end-customer-browser-issues page anchor

The SDKs render the compliance form inside an iframe tag that Persona serves.

Three conditions might impact your end customer experience:

  1. If your app sets a Content Security Policy (CSP)(link takes you to an external page), set following HTTP header1 for the page that contains the iframe:
    Content-Security-Policy: frame-src 'self' https://*.withpersona.com;
  2. Programs that collect identity documents require camera access. To allow camera use, include the following HTTP header1:
    Permissions-Policy: camera=(self "https://*.withpersona.com")
  3. Some browsers block third-party cookies by default. Test your integration with strict privacy settings.

Apply your branding to the compliance form

apply-your-branding-to-the-compliance-form page anchor

To style the embedded form consistent with your brand, target the iframe tag through a selector your web app controls. An example would be .your-classname > iframe. Don't rely on internal class names. These change without notice.


Migrate from the legacy SDK

migrate-from-the-legacy-sdk page anchor

The legacy @twilio/twilio-compliance-embed package (version 2.1.3) remains in maintenance mode. It doesn't get new features. When building new integrations, use the React SDK or the JavaScript SDK.

If you integrated with the legacy package, replace the package with the React or JavaScript package then update your properties and callbacks:

LegacyReplacementSee also
inquiryIdsessionId
inquirySessionTokensessionToken
onInquirySubmitted()onSubmit({ outcome })Submission result
onError()onError({ code, message, sessionId })Error handling
onEvent(eventName, metaData)onEvent({ name, data }).Events
classNameframeHeight, frameWidth, language, and iframeTitle.

Twilio secures the exchange of all sensitive information through your app, your server, and the Twilio API. Sensitive information includes credentials, permanent resource identifiers, and personally identifiable information (PII).

  1. Your customer initiates the ComplianceInquiry interface in your site.
  2. Your server requests the session ID and the ephemeral session token from the Twilio API.
  3. Your server returns those values to your web app, which then passes them to the SDK.
  4. Your web app, through the SDK, launches and loads the ComplianceInquiry form.
  1. Each web server differs in how they pass HTTP headers. To learn how your web server passes HTTP headers, see your web server documentation. ↩ ↩2