Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Integrate the Transcription Viewer App


(warning)

Warning

Public Beta

Voice Intelligence is currently available as a public beta release. Some features are not yet implemented and others may be changed before the product is declared as Generally Available. Beta products are not covered by a Twilio SLA.

Learn more about beta product support(link takes you to an external page).

This guide will show you how to integrate Voice Intelligence Transcription Viewer applet into your own web app. It is intended to be used by developers and system integrators and assumes you have a working Voice Intelligence Service.

The Transcription Viewer is a web applet that your web app can retrieve, initialize, and present within its own UI. It allows a user to read a transcript of a recorded conversation that took place between a customer and one of your customer support agents.

You can present the Transcription Viewer as part of that UI or in a separate window that pops up when required. This guide shows you how to achieve both. In each case, your app requests the Transcription Viewer code by calling a specific URL and including an authorization token as a URL parameter.


Prerequisites

prerequisites page anchor

To follow along with this guide, you should have the following elements set up and ready to use:

  • Twilio account credentials, specifically your Account SID and your Auth Token, which you can get from the Console .
  • A configured Voice Intelligence Service.
  • The SID of your Service.
  • Access to transcripts that you would like to view.

Each time you wish to initialize and present the Transcription Viewer, you need to:

  1. Fetch the SID of the transcript you would like to present.
  2. Use your Account SID, Auth Token, and some metadata from the transcript to acquire a one-time token.
  3. Pass the one-time token as a URL query parameter to initialize the Transcription Viewer.

Let's run through each of these steps now.

1. Fetch the transcript SID

1-fetch-the-transcript-sid page anchor

There are a number of ways that you can acquire the SID of the transcript you'd like to view, so choose the one that best fits your application.

Option 1: Get a transcript for a particular call

option-1-get-a-transcript-for-a-particular-call page anchor

If your application already has a call SID, you can look up the transcript SID by passing the call SID as a URL query parameter, callSid. This will narrow the search down to the transcript generated by that call.

Look under EXAMPLE JSON RESPONSE in the code column to the right. The returned data contains the key transcripts whose value is an array containing, in this case, one JSON object. The value of the object's sid key is the transcript SID you need. It starts with GT.

Get a transcript by call SID

get-a-transcript-by-call-sid page anchor
curl

_10
curl -X GET "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcripts?CallSid=CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&PageSize=20" \
_10
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

Output

_45
{
_45
"transcripts": [
_45
{
_45
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"sid": "GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"recording_sid": "REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"model_sid": "GIXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"date_created": "2010-08-31T20:36:28Z",
_45
"date_updated": "2010-08-31T20:36:28Z",
_45
"status": "queued",
_45
"transcript_status": "queued",
_45
"call_sid": "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"confidence": null,
_45
"data_logging": false,
_45
"environment": "production",
_45
"language_locale": "en-US",
_45
"price": "1.0",
_45
"price_unit": "USD",
_45
"service_sid": "GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"start_time": "2010-08-31T20:36:28Z",
_45
"lup_outputs": {},
_45
"lup_applied_models": {},
_45
"call_direction": "inbound",
_45
"call_from": "+14153168853",
_45
"call_to": "+14153168853",
_45
"call_duration": "14",
_45
"call_start_time": "2020-10-05T23:56:07Z",
_45
"participants": {},
_45
"has_sensitive_view": true,
_45
"url": "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcripts/GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"links": {
_45
"sentences": "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcripts/GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sentences"
_45
}
_45
}
_45
],
_45
"meta": {
_45
"key": "transcripts",
_45
"page": 0,
_45
"page_size": 50,
_45
"first_page_url": "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcripts?AfterDateCreated=2019-11-22T23%3A46%3A00Z&PageSize=50&Page=0",
_45
"next_page_url": "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcripts?AfterDateCreated=2019-11-22T23%3A46%3A00Z&PageSize=50&Page=1",
_45
"previous_page_url": "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcripts?AfterDateCreated=2019-11-22T23%3A46%3A00Z&PageSize=50&Page=0",
_45
"url": "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcripts?AfterDateCreated=2019-11-22T23%3A46%3A00Z&PageSize=50&Page=0"
_45
}
_45
}

Option 2: Get all transcripts

option-2-get-all-transcripts page anchor

If you don't have a call SID, you can make the same request described above, but without the callSid query parameter. This will return all your transcriptions, so you need to be able to identify the one you want so you can extract its SID.

Again, under EXAMPLE JSON RESPONSE for the code sample, the returned data contains a transcripts key whose value is an array containing, in this case, a single JSON object (for a single transcription). The value of the object's sid key is the transcript SID you need, starting with GT.

Get a transcript by transcript SID

get-a-transcript-by-transcript-sid page anchor
curl

_10
curl -X GET "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcripts?PageSize=20" \
_10
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

Output

_45
{
_45
"transcripts": [
_45
{
_45
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"sid": "GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"recording_sid": "REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"model_sid": "GIXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"date_created": "2010-08-31T20:36:28Z",
_45
"date_updated": "2010-08-31T20:36:28Z",
_45
"status": "queued",
_45
"transcript_status": "queued",
_45
"call_sid": "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"confidence": null,
_45
"data_logging": false,
_45
"environment": "production",
_45
"language_locale": "en-US",
_45
"price": "1.0",
_45
"price_unit": "USD",
_45
"service_sid": "GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"start_time": "2010-08-31T20:36:28Z",
_45
"lup_outputs": {},
_45
"lup_applied_models": {},
_45
"call_direction": "inbound",
_45
"call_from": "+14153168853",
_45
"call_to": "+14153168853",
_45
"call_duration": "14",
_45
"call_start_time": "2020-10-05T23:56:07Z",
_45
"participants": {},
_45
"has_sensitive_view": true,
_45
"url": "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcripts/GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"links": {
_45
"sentences": "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcripts/GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sentences"
_45
}
_45
}
_45
],
_45
"meta": {
_45
"key": "transcripts",
_45
"page": 0,
_45
"page_size": 50,
_45
"first_page_url": "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcripts?AfterDateCreated=2019-11-22T23%3A46%3A00Z&PageSize=50&Page=0",
_45
"next_page_url": "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcripts?AfterDateCreated=2019-11-22T23%3A46%3A00Z&PageSize=50&Page=1",
_45
"previous_page_url": "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcripts?AfterDateCreated=2019-11-22T23%3A46%3A00Z&PageSize=50&Page=0",
_45
"url": "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcripts?AfterDateCreated=2019-11-22T23%3A46%3A00Z&PageSize=50&Page=0"
_45
}
_45
}

Option 3: Receive a notification when a transcription completes

option-3-receive-a-notification-when-a-transcription-completes page anchor

To use this option, you'll need the URL of your web service that listens for GET or POST requests. When you make the following API call, it causes a request to be made to your URL — the one set as the value of the WebhookUrl parameter — whenever a transcription task completes. You'll find the transcript SID in the JSON data sent to your URL.

Receive a webhook when a transcription completes

receive-a-webhook-when-a-transcription-completes page anchor
curl

_10
curl -X POST "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Hooks" \
_10
--data-urlencode "WebhookUrl=https://example.com" \
_10
--data-urlencode "WebhookVerb=GET" \
_10
--data-urlencode "WebhookType=lit_results_available" \
_10
--data-urlencode "FriendlyName=friendly_name" \
_10
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

Output

_12
{
_12
"sid": "EWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_12
"service_sid": "GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_12
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_12
"friendly_name": "friendly name",
_12
"webhook_url": "http://www.mysite.com/callback",
_12
"webhook_verb": "POST",
_12
"webhook_type": "lit_results_available",
_12
"date_created": "2020-09-02T11:54:24Z",
_12
"date_updated": "2020-09-02T11:54:24Z",
_12
"url": "https://ai.twilio.com/v1/Services/GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Hooks/EWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_12
}

2. Acquire a one-time token

2-acquire-a-one-time-token page anchor

Each Transcription Viewer session requires a new one-time token. This is a short-lived, single-use key that is used to authorize Transcription Viewer to access the transcript.

(error)

Danger

The request to acquire a token requires your global Twilio account credentials, so server-side usage requires a secure environment. Do not expose your Twilio account credentials to clients.

You request the one-time token by making a call to the endpoint:


_10
https://ai.twilio.com/v1/Tokens

You use your Twilio Account SID and Auth Token to authorize the request, which is submitted as JSON. The JSON includes a grants array containing an object. This object must include your service SID and the transcript SID as key-value pairs. Check out the examples below to see how the request body JSON is formatted.

In addition to service and transcript SIDs, you can include a user ID in the one-time token request's metadata section. This is optional. The user SID should be used to identify the user who will be opening the Transcription Viewer. This usage is shown in the examples below.

You can also choose to have Transcription Viewer display a button which, when clicked, allows the Agent to download the audio from which the transcript was made. To add this button, include an isDownloadButtonVisible key in the one-time token request's metadata section and set its value to true. Again, this is shown in the examples below.

You may also specify a custom token expiry period, called a TTL (Time To Live). The default value is one minute, and that's what's applied to the first of the following examples. The second example sets a TTL of 10 minutes (600 seconds) by adding an ott_ttl field to the request body.

With this data, you can acquire a one-time token. The basic structure of the request is shown below. The request JSON also includes a mandatory product field — this indicates the app you're requesting the token for. Please use annotator as its value.

(information)

Info

The one-time token is used internally by Transcription Viewer to acquire a fully privileged and scoped access token for use during the lifetime of its session. It can be used once only. It's purpose is to avoid embedding a fully privileged access token in client-side code.

Request a one-time token.

request-a-one-time-token page anchor
curl

_10
curl -X POST 'https://ai.twilio.com/v1/Tokens' \
_10
-u $ACCOUNT_SID:$AUTH_TOKEN \
_10
-H 'content-type: application/json' \
_10
-d '{"grants": [{ "product": "annotator", "service_sid": "GA00000000000000000000000000000000", "transcript_sid": "GT00000000000000000000000000000000", "metadata": { "userId": "Jason Bourne", "isDownloadButtonVisible": true }}]}'

Output

_10
{
_10
"token": "eyJ6a...",
_10
"expiration": "2020-08-27T17:22:00Z"
_10
}

Request a one-time token with a 10-minute TTL.

request-a-one-time-token-with-a-10-minute-ttl page anchor
Node.js
curl

_13
fetch("https://ai.twilio.com/v1/Tokens", {
_13
"headers": {
_13
"authorization": `Basic ${btoa(ACCOUNT_SID + ":" + AUTH_TOKEN)}`,
_13
"content-type": "application/json"
_13
},
_13
"body": JSON.stringify({
_13
"ott_ttl": 600,
_13
"grants": [{
_13
"product": "intelligence-discovery"
_13
}]
_13
}),
_13
"method": "POST"
_13
});

Output

_10
{
_10
"token": "eyJ6a...",
_10
"expiration": "2020-08-27T17:22:00Z"
_10
}

3. Initialize the Transcription Viewer app

3-initialize-the-transcription-viewer-app page anchor

Once you've acquired a one-time token, pass it as a URL query parameter with your request for Transcription Viewer. The latest build of Transcription Viewer is available here:


_10
https://assets.twilio.com/public_assets/annotator/latest/index.html

To request Transcription Viewer with the one-time token, just add a token parameter to the URL as follows:


_10
https://assets.twilio.com/public_assets/annotator/latest/index.html?token=$TOKEN

This assumes your token is stored in an environment variable called $TOKEN. You can now use this URL directly, or via an iframe in your web page HTML, as the following examples show.

Example 1: Use the Transcription Viewer in a standalone window

example-1-use-the-transcription-viewer-in-a-standalone-window page anchor

If your app will present Transcription Viewer in its own window, your application should open a new window and load its contents with the latest Transcription Viewer build, as shown above. Make sure you include the one-time token as a URL query parameter.

You might, for instance, choose to have your service redirect to this URL right after acquiring the token.

The entire flow might then be:

  1. An Agent views a UI with a list of transcripts to view.
  2. The Agent selects a transcript. This triggers a request to a backend service propagating the transcript SID and the service SID.
  3. The backend service reads these SIDs from the request and uses locally-stored Twilio account credentials to generate a one-time token.
  4. The backend service redirects the browser to the latest Transcription Viewer build with the token appended to the app's URL.

Example 2: Embed the Transcription Viewer inside your web app

example-2-embed-the-transcription-viewer-inside-your-web-app page anchor

The Transcription Viewer can be embedded in an HTML iframe. To do so, add the URL and appended token to the iframe markup like this:


_10
<iframe src="https://assets.twilio.com/public_assets/annotator/latest/index.html?token=<YOUR_ONE-TIME_TOKEN>">

To achieve this, your server will likely need to retrieve and then dynamically embed the token into the HTML.

The entire flow might then be:

  1. An Agent views a UI with the list of transcripts to view.
  2. The Agent selects a transcript. This triggers a request to a backend service propagating the transcript SID and the service SID.
  3. The backend service reads these SIDs from the request and uses locally stored Twilio account credentials to generate a one-time token.
  4. The backend service renders an HTML page that contains the iframe snippet above.

What is a one-time token?

The one-time token (OTT) is used internally by the Transcripiton Viewer app to acquire a fully privileged access token for use during the lifetime of a search operation. It is short lived — approximately one minute — and can be used once only. It's purpose is to avoid embedding a fully privileged access token in client-side code.

How is token refresh handled?

Token refresh is not supported during preview. The one-time token is exchanged for a token with a time to live of one hour.


Rate this page: