Important
The blueprints and code samples provided in this section are for reference and demonstration purposes only, delivered on an "as-is" basis. While these resources help illustrate how to connect Veridas services with third-party platforms, the final implementation, testing, and ongoing maintenance are the sole responsibility of the client. Our team does not guarantee continuous updates, long-term compatibility, or dedicated technical support for these sample integrations.
Important
The following is a text extracted directly from the Veridas "Twilio IVR Blueprint" repository, which includes all the artifacts required for the deployment of the Twilio IVR Blueprint. If you are interested in deploying Twilio IVR Blueprint in your Twilio environment, please contact the Veridas team to gain access to the repository and begin your integration.
Twilio IVR Blueprint¶
This project contains all required resources to deploy Veridas Twilio IVR Blueprint into a Twilio account.
This blueprint shows how to integrate Veridas voice authentication into an IVR built with Twilio. Under the hood, it uses the following Veridas services:
- VSS (Veridas Streaming Service): for receiving and processing audio from Twilio via Twilio Media Streams (WebSocket).
- VCSP (Veridas Credential Service Provider): for generating, storing, and managing biometric credentials and handling authentication.
The deployment provides a Twilio Function that can be used to build a voice authentication scenario, and an example Studio Flow that uses it: the first call from a phone number enrolls the caller's voice, and later calls from the same number verify it.
Architecture¶
- Studio Flow (
src/modules/studio_flow.json.tpl): drives the call. It greets the caller, decides between enrollment and verification, asks the caller to speak, and announces the result. - Function (
src/modules/veridas_client.js): called by the flow. It starts and stops the Media Stream of the call and calls the VSS and VCSP REST APIs.
How the Media Stream authenticates
Twilio Media Streams cannot add headers to the WebSocket connection, so it cannot send the Veridas API key. Instead, every time the flow starts a Media Stream, the Function gets a short-lived OAuth2 access token from Veridas and adds it to the path of the Media Streams URL (wss://<base_url host>/vss/api/v1/streams/media_streams/<token>). The token is short-lived, it is only needed to open the connection, and it never reaches the Studio Flow.
Requirements¶
- A Twilio account with a phone number with voice capability.
- Terraform.
bash,curlandjq, used by Terraform to upload and deploy the Function code (on Windows, use WSL).- Data provided by Veridas:
- Veridas API URL (e.g.
https://api.veridas.com). - Veridas API key. - OAuth2 client ID and client secret, used to authenticate the Media Streams.
Deploy instructions¶
1. Create a new terraform environment¶
Twilio IVR Blueprint uses Terraform as a tool to deploy all the necessary Twilio resources and maintain change control.
The entire source code is located within the src folder, which contains two subdirectories:
modules: Contains the Terraform module with all the logic for creating resources, the Function code and the Studio Flow.environments: Contains environment-specific "root modules" (dev, staging, prod). Each environment has its ownmain.tfthat calls the module and aterraform.tfvarswith environment-specific variables.
There already exists a default environment that can be used, but for the sake of learning, let's create another environment and let's name it "sandbox". To do this, just create a new folder called sandbox within environments and copy the main.tf and variables.tf from the default environment.
2. Fill in terraform variables¶
Using the template located in src/environments/terraform.tfvars.template, create a new terraform.tfvars file within the src/environments/sandbox/ directory and fill it with the following values:
- twilio_account_sid: Account SID of the Twilio account (Console home page > Account Info).
- twilio_auth_token: Auth Token of the Twilio account.
- environment: Optional suffix for resource names, so several environments can coexist in the same account (e.g.
sandbox). Letters, digits and hyphens only. - base_url: URL provided by Veridas pointing to Veridas services.
- apikey: API Key provided by Veridas to authenticate within Veridas services.
- veridas_client_id, veridas_client_secret: OAuth2 client credentials provided by Veridas to authenticate the Media Streams.
Warning
terraform.tfvars and the Terraform state hold secrets. Never commit them; the repository .gitignore already excludes them.
3. Deploy resources¶
Once the environment is fully described, from src/environments/sandbox/ run:
terraform init
This prepares the project directory by initializing the backend and downloading the providers. After that, to deploy the resources:
terraform apply
Uploading and building the Function code takes about a minute. When it finishes, Terraform prints the Function URL and the Studio Flow SID.
Note
If any change is required, run terraform apply again after applying the corresponding changes to the source code. Terraform will keep track of the changes for you, and it uploads and deploys the Function code again whenever veridas_client.js or its variables change.
When you don't need deployed resources anymore you can destroy them by running:
terraform destroy
Important
It is highly recommended that the client reviews which resources will be created, modified, or deleted in their Twilio account before applying.
4. Assign a phone number¶
Once deployed, a new Veridas Voice Authentication sandbox Studio Flow will be available in your Twilio account. Assign it to a phone number (Phone Numbers > Manage > Active numbers > your number > Voice Configuration > A call comes in: Studio Flow, Veridas Voice Authentication sandbox) and start using it by making calls.
Phone numbers are not managed by Terraform on purpose: removing a phone number from Terraform releases it from the account. Before running terraform destroy, assign the number back to its previous configuration.
This Studio Flow is just an example that demonstrates what you can do with Veridas Twilio IVR Blueprint and how to do it. Feel free to integrate voice authentication in your existing flows by using the deployed Twilio Function API.
Deployed resources¶
| Resource Type | Name / Identifier | Purpose |
|---|---|---|
| Functions service | twilio_serverless_services_v1.veridas (veridas-ivr[-<environment>]) |
Hosts the Function. Created with Add my Twilio Credentials enabled, so the Function can start and stop Media Streams. |
| Functions environment | twilio_serverless_services_environments_v1.ui (ui) |
Holds the environment variables and the deployed build, and provides the https://veridas-ivr-XXXX.twil.io domain. It uses the same name as the environments created from the Console. |
| Environment variables | twilio_serverless_services_environments_variables_v1.veridas |
BASE_URL, APIKEY, VERIDAS_CLIENT_ID and VERIDAS_CLIENT_SECRET, read by the Function at runtime. Only visible to users of your Twilio account. |
| Function code and deployment | terraform_data.function_deployment |
Runs deploy_function.sh, which uploads veridas_client.js as the /veridas_client Function (protected), builds it and deploys it to the environment. The Twilio Terraform provider has no resources for these steps. |
| Studio Flow | twilio_studio_flows_v2.example_flow (Veridas Voice Authentication[ <environment>]) |
Example flow for the enrollment and verification scenario. |
Protected means that the Function only accepts requests signed by your Twilio account, such as the ones from Studio.
Studio Flow behaviour¶
- Anonymous callers: callers without caller ID (
anonymous,restricted,unknown, Twilio's special numbers for withheld caller IDs, or empty) are told so and the call ends, because the caller's number identifies the voice credential. - Speech required: 10 seconds of net speech to enroll and 5 seconds to verify (
net_speech_durationin theset_enroll_varsandset_auth_varswidgets). - Thresholds:
authenticity_threshold(anti-spoofing) andbiometric_threshold(voice match) are0.8(enroll_fnandmatching_fnwidgets). - Waiting for speech: while the caller speaks, the flow checks the VSS session every 2 seconds without interrupting. If VSS has not finished after 6 checks, it asks once for more speech. After 14 checks it ends the call with an error message (
check_poll_limitwidget). - Media Stream: it is stopped as soon as VSS has the voice sample (
stop_capture_fn), or on any error while it runs (stop_stream_fn). - Language: prompts are in English (
en-US, voicealice). Change thesay-playwidgets to use another language or voice.
Integrating with Twilio Flex (optional)¶
The example flow ends the call after the result. In a contact center with Twilio Flex, the call can be transferred to an agent together with the biometric result:
-
In the Studio editor, add a Send to Flex widget: - Workflow:
Assign to Anyone(created when Flex is enabled, in theFlex Task Assignmentworkspace). - Channel:Voice. - Attributes, so that the agent sees the result in the task:```json { "type": "inbound", "name": "{{trigger.call.From}}", "veridas_enrolled": "{{flow.variables.account_exists}}", "veridas_match": "{{widgets.matching_fn.parsed.match}}", "veridas_spoof": "{{widgets.matching_fn.parsed.spoof}}" } ``` -
Change the transitions that go to
goodbye_say, which says goodbye and hangs up, so that they go to a Say/Play widget such as "Transferring you to an agent", and from there to Send to Flex. The Media Stream is already stopped at that point. - Export the flow and copy its definition to
src/modules/studio_flow.json.tpl, replacing the Function domain with${function_base_url}, so thatterraform applykeeps your changes.
Troubleshooting¶
| Symptom | Where to look / cause |
|---|---|
| The call says "An unexpected error occurred" | Studio > Flows > Veridas Voice Authentication > Executions shows the widgets the call went through and what the Function answered. For the Function's own errors, open the service in Functions and Assets > Services, enable Live logs and call again. |
Function log: OAuth2 token request failed: HTTP 401 |
Wrong veridas_client_id or veridas_client_secret. |
The flow keeps asking for speech and ends with an error; Twilio error 31920 in Monitor > Logs > Errors |
Twilio could not open the Media Stream WebSocket. Check base_url, and that the OAuth2 credentials belong to the same Veridas account as the API key. |
terraform apply fails in terraform_data.function_deployment |
deploy_function.sh prints the Twilio API error. Check that curl and jq are installed. Run terraform apply again once fixed. |
Twilio Function API¶
The deployed Function (veridas_client) exposes an internal API invoked by the Studio Flow with "Make HTTP Request" widgets. The action parameter determines which operation to execute.
Invocation
- Method:
POST - Content-Type:
application/x-www-form-urlencoded - Input: form-encoded body, which must include:
-
action: operation to perform (see below). - The parameters required by the action (see below). - Output: JSON object with the action result, readable in Studio as
{{widgets.<widget_name>.parsed.<field>}}.
Supported actions
| Action | Parameters | Description | Output |
|---|---|---|---|
start_stream |
call_sid, net_speech_duration |
Starts a Twilio Media Stream on the active call, authenticated with a new access token, and registers it as a VSS session. Combines the Amazon-equivalent vss_create_session + vss_create_stream into a single step. |
{ "stream_id": "<MZxxx>" } |
stop_stream |
call_sid, stream_id |
Stops the Twilio Media Stream. | {} |
vss_read_session |
stream_id |
Reads the VSS session status. | { "status": "<status>" } or { "status": "finished", "sample": "<audio_file>" } |
vcsp_read_account |
subject_id |
Checks whether a voice credential exists for the caller. | { "exists": "true" \| "false" } |
vcsp_delete_account |
subject_id |
Deletes the caller's voice credential. | {} |
vcsp_enroll |
sample, subject_id, authenticity_threshold |
Enrolls the caller's voice in VCSP. | { "spoof": "true" \| "false" } |
vcsp_one_to_one_matching |
sample, subject_id, authenticity_threshold, biometric_threshold |
Performs 1:1 biometric matching against the caller's stored credential. | { "spoof": "true" \| "false", "match": "true" \| "false" } |
Notes
subject_idis always{{trigger.call.From}}(the caller's number). The Function replaces any character other than letters, digits,_or-with_.stream_idis the Twilio Media Stream SID (MZxxx) returned bystart_stream. It is passed to all subsequentvss_read_sessionandstop_streamcalls.- All boolean outputs (
exists,spoof,match) are strings ("true"/"false") for direct comparison in Studio's "Split Based On" widget. - The Function has no npm dependencies of its own: it uses the global
fetch()API of the Node.js runtime and the Twilio client provided bycontext.getTwilioClient(). - VSS session statuses:
waiting_for_streamandprocessing_stream(keep polling),finished(proceed to biometrics),error/cancelled(error path). - An unsupported
action, or an error from a Veridas API, makes the Function return HTTP 500, which triggers thefailedtransition of the widget in Studio.