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

Integrate the Transcription Viewer App


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 recording

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

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

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 Recording SID

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

_10
curl -X GET "https://intelligence.twilio.com/v2/Transcripts?SourceSid=REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
_10
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

Output

_60
{
_60
"transcripts": [
_60
{
_60
"status": "completed",
_60
"sid": "GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_60
"service_sid": "GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_60
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_60
"redaction": false,
_60
"data_logging": false,
_60
"media_start_time": null,
_60
"language_code": "en-US",
_60
"customer_key": "",
_60
"url": "https://intelligence.twilio.com/v2/Transcripts/GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_60
"duration": 24,
_60
"date_updated": "2024-03-15T09:57:23Z",
_60
"date_created": "2024-03-15T09:55:33Z",
_60
"channel": {
_60
"media_properties": {
_60
"source_sid": "REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_60
"media_url": null
_60
},
_60
"participants": [
_60
{
_60
"user_id": null,
_60
"channel_participant": 1,
_60
"media_participant_id": null,
_60
"image_url": "",
_60
"full_name": "Holly Rays",
_60
"role": "customer",
_60
"email": ""
_60
},
_60
{
_60
"user_id": "akelley",
_60
"channel_participant": 2,
_60
"media_participant_id": null,
_60
"image_url": "",
_60
"full_name": "Adam Kelley",
_60
"role": "agent",
_60
"email": ""
_60
}
_60
],
_60
"type": "voice"
_60
},
_60
"links": {
_60
"media": "https://intelligence.twilio.com/v2/Transcripts/GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media",
_60
"sentences": "https://intelligence.twilio.com/v2/Transcripts/GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sentences",
_60
"operator_results": "https://intelligence.twilio.com/v2/Transcripts/GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/OperatorResults"
_60
}
_60
}
_60
],
_60
"meta": {
_60
"key": "transcripts",
_60
"page": 0,
_60
"page_size": 50,
_60
"first_page_url": "https://intelligence.twilio.com/v2/Transcripts?SourceSid=REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&PageSize=50&Page=0",
_60
"next_page_url": "https://intelligence.twilio.com/v2/Transcripts?SourceSid=REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&PageSize=50&Page=1",
_60
"previous_page_url": null,
_60
"url": "https://intelligence.twilio.com/v2/Transcripts?SourceSid=REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&PageSize=50&Page=0"
_60
}
_60
}

Option 2: Get all transcripts

option-2-get-all-transcripts page anchor

If you don't have a Recording SID, you can make the same request described above, but without the SourceSid 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://intelligence.twilio.com/v2/Transcripts?PageSize=20" \
_10
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

Output

_60
{
_60
"transcripts": [
_60
{
_60
"status": "completed",
_60
"sid": "GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_60
"service_sid": "GAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_60
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_60
"redaction": false,
_60
"data_logging": false,
_60
"media_start_time": null,
_60
"language_code": "en-US",
_60
"customer_key": "",
_60
"url": "https://intelligence.twilio.com/v2/Transcripts/GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_60
"duration": 24,
_60
"date_updated": "2024-03-15T09:57:23Z",
_60
"date_created": "2024-03-15T09:55:33Z",
_60
"channel": {
_60
"media_properties": {
_60
"source_sid": "REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_60
"media_url": null
_60
},
_60
"participants": [
_60
{
_60
"user_id": null,
_60
"channel_participant": 1,
_60
"media_participant_id": null,
_60
"image_url": "",
_60
"full_name": "Holly Rays",
_60
"role": "customer",
_60
"email": ""
_60
},
_60
{
_60
"user_id": "akelley",
_60
"channel_participant": 2,
_60
"media_participant_id": null,
_60
"image_url": "",
_60
"full_name": "Adam Kelley",
_60
"role": "agent",
_60
"email": ""
_60
}
_60
],
_60
"type": "voice"
_60
},
_60
"links": {
_60
"media": "https://intelligence.twilio.com/v2/Transcripts/GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media",
_60
"sentences": "https://intelligence.twilio.com/v2/Transcripts/GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sentences",
_60
"operator_results": "https://intelligence.twilio.com/v2/Transcripts/GTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/OperatorResults"
_60
}
_60
}
_60
],
_60
"meta": {
_60
"key": "transcripts",
_60
"page": 0,
_60
"page_size": 20,
_60
"first_page_url": "https://intelligence.twilio.com/v2/Transcripts?SourceSid=REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&PageSize=20&Page=0",
_60
"next_page_url": "https://intelligence.twilio.com/v2/Transcripts?SourceSid=REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&PageSize=20&Page=1",
_60
"previous_page_url": null,
_60
"url": "https://intelligence.twilio.com/v2/Transcripts?SourceSid=REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&PageSize=20&Page=0"
_60
}
_60
}

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 to set up the WebhookUrl parameter on your Service. You'll find the transcript_sid in the JSON data sent to your URL when a transcription completes.

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: