Embed compliance registration in your app
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.
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:
- From their servers, the ISV calls the Twilio ComplianceInquiry Initialize API resource. This returns a session token and session ID.
- In their web app, the ISV creates a React component or JavaScript instance that renders a form in an
iframetag. This form connects to the compliance inquiry in Twilio through the ID and token. - The end customer completes and submits their compliance request through the ISV web app.
- 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.
To deploy Compliance Embed, complete two activities:
- 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.
- 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:
- Create a paid Twilio account, if needed. You can't use a trial account.
- Get an approved Trust Hub Primary Customer Profile in the Twilio Console with a Business Identity of ISV or Reseller.
- Add Persona to the allow list on your firewall. To manage compliance, Twilio uses this service.
- Create a Content Security Policy (CSP) for your web app as another layer of security.
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.
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
sessionIdandsessionTokenproperties. - The Toll-Free Verification, Secondary Customer Profile, and Regulatory Compliance Bundle resources return these values in the
inquiry_idandinquiry_session_tokenproperties.
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
sessionIdandsessionTokenproperty values. - For the Toll-Free Verification, Secondary Customer Profile, Regulatory Compliance Bundle resources, use the
inquiry_idandinquiry_session_tokenproperty values.
Always fetch sessions from your backend server
Don't make Initialize resource requests from the browser. That would expose your Twilio API credentials.
Prerequisites
-
Install React 19 or later.
-
Install Node 22 or later.
-
Install
@twilio/twilio-compliance-embed-reactand its peer dependencies. -
Install persona-react
1npm install @twilio/twilio-compliance-embed-react \2react 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:
1import { TwilioComplianceEmbed } from "@twilio/twilio-compliance-embed-react";23function VerificationPage() {4return (5<TwilioComplianceEmbed6sessionId="{your-session-ID}"7sessionToken="{your-session-token}"8onReady={() => console.log("Ready")}9onComplete={() => 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. 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, create placeholder values for variables, or polyfill, 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, 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.
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:
startpage-changedocument-uploadone-time-link-sentone-time-link-startone-time-link-exit
1onEvent: (event) => {2console.log(event.name, event.data);3}
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.
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.
Error codes can change during the beta
Don't write logic that depends on a specific code value.
The SDKs render the compliance form inside an iframe tag that Persona serves.
Three conditions might impact your end customer experience:
- If your app sets a Content Security Policy (CSP), set following HTTP header1 for the page that contains the
iframe:Content-Security-Policy: frame-src 'self' https://*.withpersona.com; - Programs that collect identity documents require camera access. To allow camera use, include the following HTTP header1:
Permissions-Policy: camera=(self "https://*.withpersona.com")
- Some browsers block third-party cookies by default. Test your integration with strict privacy settings.
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.
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:
| Legacy | Replacement | See also |
|---|---|---|
inquiryId | sessionId | |
inquirySessionToken | sessionToken | |
onInquirySubmitted() | onSubmit({ outcome }) | Submission result |
onError() | onError({ code, message, sessionId }) | Error handling |
onEvent(eventName, metaData) | onEvent({ name, data }). | Events |
className | frameHeight, 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).
- Your customer initiates the ComplianceInquiry interface in your site.
- Your server requests the session ID and the ephemeral session token from the Twilio API.
- Your server returns those values to your web app, which then passes them to the SDK.
- Your web app, through the SDK, launches and loads the ComplianceInquiry form.