### Basic usage Source: https://www.twilio.com/docs/voice/twiml/transcription.md A minimal example showing how to initiate a real-time transcription session with a status callback URL. ```xml ``` -------------------------------- ### Start a Recording Source: https://www.twilio.com/docs/voice/twiml/recording.md Examples of initiating a call recording using the TwiML structure across various SDKs and raw XML. ```js const VoiceResponse = require('twilio').twiml.VoiceResponse; const response = new VoiceResponse(); const start = response.start(); start.recording({ channels: 'dual', recordingStatusCallback: 'https://example.com/your-callback-url', }); response.say('The recording has started.'); console.log(response.toString()); ``` ```py from twilio.twiml.voice_response import Recording, VoiceResponse, Say, Start response = VoiceResponse() start = Start() start.recording( channels='dual', recording_status_callback='https://example.com/your-callback-url' ) response.append(start) response.say('The recording has started.') print(response) ``` ```cs using System; using Twilio.TwiML; using Twilio.TwiML.Voice; class Example { static void Main() { var response = new VoiceResponse(); var start = new Start(); start.Recording(channels: "dual", recordingStatusCallback: "https://example.com/your-callback-url"); response.Append(start); response.Say("The recording has started."); Console.WriteLine(response.ToString()); } } ``` ```java import com.twilio.twiml.voice.Recording; import com.twilio.twiml.VoiceResponse; import com.twilio.twiml.voice.Say; import com.twilio.twiml.voice.Start; import com.twilio.twiml.TwiMLException; public class Example { public static void main(String[] args) { Recording recording = new Recording.Builder().channels("dual") .recordingStatusCallback("https://example.com/your-callback-url") .build(); Start start = new Start.Builder().recording(recording).build(); Say say = new Say.Builder("The recording has started.").build(); VoiceResponse response = new VoiceResponse.Builder().start(start) .say(say).build(); try { System.out.println(response.toXml()); } catch (TwiMLException e) { e.printStackTrace(); } } } ``` ```php start(); $start->recording(['channels' => 'dual', 'recordingStatusCallback' => 'https://example.com/your-callback-url']); $response->say('The recording has started.'); echo $response; ``` ```rb require 'twilio-ruby' response = Twilio::TwiML::VoiceResponse.new response.start do |start| start.recording(channels: 'dual', recording_status_callback: 'https://example.com/your-callback-url') end response.say(message: 'The recording has started.') puts response ``` ```xml The recording has started. ``` -------------------------------- ### Install Twilio Node.js SDK Source: https://www.twilio.com/docs/voice/make-calls Use npm to install the Twilio library for Node.js. ```bash npm install twilio ``` -------------------------------- ### Install Serverless Plugin Source: https://www.twilio.com/docs/voice/sdks/android/get-started.md Install the required Twilio Serverless plugin for the CLI. ```bash twilio plugins:install @twilio-labs/plugin-serverless ``` -------------------------------- ### Default TwiML Say Verb Source: https://www.twilio.com/docs/voice/twiml/say/text-speech.md Example of a verb using account-level default voice and language settings. ```xml Hello. I am a man! ``` -------------------------------- ### Generate SSML with Twilio SDKs Source: https://www.twilio.com/docs/voice/twiml/say/text-speech.md Examples demonstrating how to programmatically build complex SSML structures within a verb using Twilio's official SDKs and raw XML. ```java import com.twilio.twiml.VoiceResponse; import com.twilio.twiml.voice.Say; import com.twilio.twiml.TwiMLException; import com.twilio.twiml.voice.SsmlW; import com.twilio.twiml.voice.SsmlSayAs; import com.twilio.twiml.voice.SsmlProsody; import com.twilio.twiml.voice.SsmlEmphasis; import com.twilio.twiml.voice.SsmlS; import com.twilio.twiml.voice.SsmlPhoneme; import com.twilio.twiml.voice.SsmlP; import com.twilio.twiml.voice.SsmlSub; import com.twilio.twiml.voice.SsmlBreak; public class Example { public static void main(String[] args) { SsmlBreak ssmlBreak = new SsmlBreak.Builder().strength(SsmlBreak .Strength.X_WEAK).time("100ms").build(); SsmlPhoneme ssmlPhoneme = new SsmlPhoneme.Builder("Words to speak") .alphabet(SsmlPhoneme.Alphabet.X_SAMPA).ph("pɪˈkɑːn").build(); SsmlP ssmlP = new SsmlP.Builder("Words to speak").build(); SsmlProsody ssmlProsody = new SsmlProsody.Builder("Words to speak") .pitch("-10%").rate("85%").volume("-6dB").build(); SsmlSub ssmlSub = new SsmlSub.Builder("Words to be substituted") .alias("alias").build(); SsmlS ssmlS = new SsmlS.Builder("Words to speak").build(); SsmlSayAs ssmlSayAs = new SsmlSayAs.Builder("Words to speak") .interpretAs(SsmlSayAs.InterpretAs.SPELL_OUT).build(); SsmlW ssmlW = new SsmlW.Builder("Words to speak").build(); SsmlEmphasis ssmlEmphasis = new SsmlEmphasis .Builder("Words to emphasize").level(SsmlEmphasis.Level.MODERATE) .build(); Say say = new Say.Builder("Hi").voice(Say.Voice.POLLY_JOANNA) .break_(ssmlBreak).emphasis(ssmlEmphasis).p(ssmlP) .addText("aaaaaa").phoneme(ssmlPhoneme).addText("bbbbbbb") .prosody(ssmlProsody).s(ssmlS).sayAs(ssmlSayAs).sub(ssmlSub) .w(ssmlW).build(); VoiceResponse response = new VoiceResponse.Builder().say(say).build(); try { System.out.println(response.toXml()); } catch (TwiMLException e) { e.printStackTrace(); } } } ``` ```php say('Hi', ['voice' => 'Polly.Joanna']); $say->break_(['strength' => 'x-weak', 'time' => '100ms']); $say->emphasis('Words to emphasize', ['level' => 'moderate']); $say->p('Words to speak'); $say->append('aaaaaa'); $say->phoneme('Words to speak', ['alphabet' => 'x-sampa', 'ph' => 'pɪˈkɑːn']); $say->append('bbbbbbb'); $say->prosody('Words to speak', ['pitch' => '-10%', 'rate' => '85%', 'volume' => '-6dB']); $say->s('Words to speak'); $say->say_as('Words to speak', ['interpret-as' => 'spell-out']); $say->sub('Words to be substituted', ['alias' => 'alias']); $say->w('Words to speak'); echo $response; ``` ```ruby require 'twilio-ruby' response = Twilio::TwiML::VoiceResponse.new response.say(voice: 'Polly.Joanna', message: 'Hi') do |say| say.break(strength: 'x-weak', time: '100ms') say.emphasis(words: 'Words to emphasize', level: 'moderate') say.p(words: 'Words to speak') say.add_text('aaaaaa') say.phoneme('Words to speak', alphabet: 'x-sampa', ph: 'pɪˈkɑːn') say.add_text('bbbbbbb') say.prosody(words: 'Words to speak', pitch: '-10%', rate: '85%', volume: '-6dB') say.s(words: 'Words to speak') say.say_as('Words to speak', interpretAs: 'spell-out') say.sub('Words to be substituted', alias: 'alias') say.w(words: 'Words to speak') end puts response ``` ```xml Hi Words to emphasize

Words to speak

aaaaaa Words to speak bbbbbbb Words to speak Words to speak Words to speak Words to be substituted Words to speak
``` -------------------------------- ### Generate SSML with TwiML Source: https://www.twilio.com/docs/voice/twiml/say/text-speech.md Example of the resulting TwiML structure when using various SSML tags within a verb. ```xml Hi Words to emphasize

Words to speak

aaaaaa Words to speak bbbbbbb Words to speak Words to speak Words to speak Words to be substituted Words to speak
``` -------------------------------- ### Language Mapped TwiML Say Verb Source: https://www.twilio.com/docs/voice/twiml/say/text-speech.md Example of a verb using a configured language mapping to automatically select a voice. ```xml Hello. I am Emma! ``` -------------------------------- ### Initialize Environment Configuration Source: https://www.twilio.com/docs/voice/sdks/android/get-started.md Create the .env file from the provided example template. ```bash cp Server/.env.example Server/.env ``` -------------------------------- ### Get Start Time (Android) Source: https://www.twilio.com/docs/voice/sdks/mobile-preflight-test.md Call the `getStartTime()` method to get the preflight test start time as a Unix timestamp in milliseconds. ```java PreflightTest.getStartTime() ``` -------------------------------- ### Start the server Source: https://www.twilio.com/docs/voice/sdks/react-native/reference-components.md Launches the backend server required for the reference components. ```bash npm run server ``` -------------------------------- ### Get Start Time (iOS) Source: https://www.twilio.com/docs/voice/sdks/mobile-preflight-test.md Access the `startTime` property to get the preflight test start time as a Unix timestamp in milliseconds. ```swift TVOPreflightTest.startTime ``` -------------------------------- ### Install Dependencies and Run Source: https://www.twilio.com/docs/voice/quickstart/server.md Commands to fetch required modules and execute the Go script. ```bash go get ``` ```bash go run make_call.go ``` -------------------------------- ### Example Start Message Source: https://www.twilio.com/docs/voice/media-streams/websocket-messages.md A JSON representation of the start message containing stream metadata and custom parameters. ```json { "event": "start", "sequenceNumber": "1", "start": { "accountSid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "streamSid": "MZXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "callSid": "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "tracks": [ "inbound" ], "mediaFormat": { "encoding": "audio/x-mulaw", "sampleRate": 8000, "channels": 1 }, "customParameters": { "FirstName": "Jane", "LastName": "Doe", "RemoteParty": "Bob" } }, "streamSid": "MZXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" } ``` -------------------------------- ### Run the Go Application Source: https://www.twilio.com/docs/voice/quickstart/server.md Starts the local web server on the configured port. ```bash go run main.go ``` -------------------------------- ### Initialize Go project Source: https://www.twilio.com/docs/voice/make-calls Create a new directory and initialize a Go module for the project. ```bash mkdir make-call cd make-call go mod init make-call ``` -------------------------------- ### Retrieve and filter calls by start date Source: https://www.twilio.com/docs/voice/api/call-resource.md Examples for listing completed calls filtered by a specific start date across multiple programming languages. ```js // Download the helper library from https://www.twilio.com/docs/node/install const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio"; // Find your Account SID and Auth Token at twilio.com/console // and set the environment variables. See http://twil.io/secure const accountSid = process.env.TWILIO_ACCOUNT_SID; const authToken = process.env.TWILIO_AUTH_TOKEN; const client = twilio(accountSid, authToken); async function listCall() { const calls = await client.calls.list({ startTime: new Date("2009-07-06 00:00:00"), status: "completed", limit: 20, }); calls.forEach((c) => console.log(c.end)); } listCall(); ``` ```python # Download the helper library from https://www.twilio.com/docs/python/install import os from twilio.rest import Client from datetime import datetime # Find your Account SID and Auth Token at twilio.com/console # and set the environment variables. See http://twil.io/secure account_sid = os.environ["TWILIO_ACCOUNT_SID"] auth_token = os.environ["TWILIO_AUTH_TOKEN"] client = Client(account_sid, auth_token) calls = client.calls.list( status="completed", start_time=datetime(2009, 7, 6, 0, 0, 0), limit=20 ) for record in calls: print(record.end) ``` ```csharp // Install the C# / .NET helper library from twilio.com/docs/csharp/install using System; using Twilio; using Twilio.Rest.Api.V2010.Account; using System.Threading.Tasks; class Program { public static async Task Main(string[] args) { // Find your Account SID and Auth Token at twilio.com/console // and set the environment variables. See http://twil.io/secure string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"); TwilioClient.Init(accountSid, authToken); var calls = await CallResource.ReadAsync( status: CallResource.StatusEnum.Completed, startTime: new DateTime(2009, 7, 6, 0, 0, 0, DateTimeKind.Utc), limit: 20); foreach (var record in calls) { Console.WriteLine(record.End); } } } ``` ```java // Install the Java helper library from twilio.com/docs/java/install import java.time.ZoneId; import java.time.ZonedDateTime; import com.twilio.Twilio; import com.twilio.rest.api.v2010.account.Call; import com.twilio.base.ResourceSet; public class Example { // Find your Account SID and Auth Token at twilio.com/console // and set the environment variables. See http://twil.io/secure public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID"); public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN"); public static void main(String[] args) { Twilio.init(ACCOUNT_SID, AUTH_TOKEN); ResourceSet calls = Call.reader() .setStatus(Call.Status.COMPLETED) .setStartTime(ZonedDateTime.of(2009, 7, 6, 0, 0, 0, 0, ZoneId.of("UTC"))) .limit(20) .read(); for (Call record : calls) { System.out.println(record.getEnd()); } } } ``` -------------------------------- ### Configure profanityFilter in TwiML Source: https://www.twilio.com/docs/voice/twiml/transcription.md Examples showing how to set the profanityFilter attribute when starting a transcription. ```js const VoiceResponse = require('twilio').twiml.VoiceResponse; const response = new VoiceResponse(); const start = response.start(); start.transcription({ statusCallbackUrl: 'https://example.com/your-callback-url', profanityFilter: false, transcriptionEngine: 'google', }); console.log(response.toString()); ``` ```py from twilio.twiml.voice_response import VoiceResponse, Start, Transcription response = VoiceResponse() start = Start() start.transcription( status_callback_url='https://example.com/your-callback-url', profanity_filter=False, transcription_engine='google') response.append(start) print(response) ``` ```cs using System; using Twilio.TwiML; using Twilio.TwiML.Voice; class Example { static void Main() { var response = new VoiceResponse(); var start = new Start(); start.Transcription(statusCallbackUrl: "https://example.com/your-callback-url", profanityFilter: false, transcriptionEngine: "google"); response.Append(start); Console.WriteLine(response.ToString()); } } ``` ```java import com.twilio.twiml.VoiceResponse; import com.twilio.twiml.voice.Start; import com.twilio.twiml.voice.Transcription; import com.twilio.twiml.TwiMLException; public class Example { public static void main(String[] args) { Transcription transcription = new Transcription.Builder().statusCallbackUrl("https://example.com/your-callback-url").profanityFilter(false).transcriptionEngine("google").build(); Start start = new Start.Builder().transcription(transcription).build(); VoiceResponse response = new VoiceResponse.Builder().start(start).build(); try { System.out.println(response.toXml()); } catch (TwiMLException e) { e.printStackTrace(); } } } ``` ```go package main import ( "fmt" "github.com/twilio/twilio-go/twiml" ) func main() { twiml, _ := twiml.Voice([]twiml.Element{ &twiml.VoiceStart{ InnerElements: []twiml.Element{ &twiml.VoiceTranscription{ ProfanityFilter: "false", StatusCallbackUrl: "https://example.com/your-callback-url", TranscriptionEngine: "google", }, }, }, }) fmt.Print(twiml) } ``` ```php start(); $start->transcription(['statusCallbackUrl' => 'https://example.com/your-callback-url', 'profanityFilter' => 'false', 'transcriptionEngine' => 'google']); echo $response; ``` ```rb require 'twilio-ruby' response = Twilio::TwiML::VoiceResponse.new response.start do |start| start.transcription(status_callback_url: 'https://example.com/your-callback-url', profanity_filter: false, transcription_engine: 'google') end puts response ``` ```xml ``` -------------------------------- ### Initialize Go project and install Twilio library Source: https://www.twilio.com/docs/voice/quickstart/server.md Initializes a Go module and installs the Twilio Go helper library. ```bash go mod init twilio-example && go get github.com/twilio/twilio-go ``` -------------------------------- ### Example Call Log JSON Response Source: https://www.twilio.com/docs/voice/tutorials/how-to-retrieve-call-logs/java.md This is an example of the JSON structure returned when retrieving a call log. It includes details such as call SID, direction, duration, start and end times, and associated URIs. ```json { "calls": [ { "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "answered_by": "machine_start", "api_version": "2010-04-01", "caller_name": "callerid1", "date_created": "Fri, 18 Oct 2019 17:00:00 +0000", "date_updated": "Fri, 18 Oct 2019 17:01:00 +0000", "direction": "outbound-api", "duration": "4", "end_time": "Fri, 18 Oct 2019 17:03:00 +0000", "forwarded_from": "calledvia1", "from": "+13051416799", "from_formatted": "(305) 141-6799", "group_sid": "GPdeadbeefdeadbeefdeadbeefdeadbeef", "parent_call_sid": "CAdeadbeefdeadbeefdeadbeefdeadbeef", "phone_number_sid": "PNdeadbeefdeadbeefdeadbeefdeadbeef", "price": "-0.200", "price_unit": "USD", "sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0", "start_time": "Fri, 18 Oct 2019 17:02:00 +0000", "status": "completed", "subresource_uris": { "notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0/Notifications.json", "recordings": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0/Recordings.json", "payments": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0/Payments.json", "events": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0/Events.json", "siprec": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0/Siprec.json", "streams": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0/Streams.json", "transcriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0/Transcriptions.json", "user_defined_message_subscriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0/UserDefinedMessageSubscriptions.json", "user_defined_messages": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0/UserDefinedMessages.json" }, "to": "+13051913581", "to_formatted": "(305) 191-3581", "trunk_sid": "TKdeadbeefdeadbeefdeadbeefdeadbeef", "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0.json", "queue_time": "1000" }, { "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "answered_by": "human", "api_version": "2010-04-01", "caller_name": "callerid2", "date_created": "Fri, 18 Oct 2019 16:00:00 +0000", "date_updated": "Fri, 18 Oct 2019 16:01:00 +0000", "direction": "inbound", "duration": "3", "end_time": "Fri, 18 Oct 2019 16:03:00 +0000", "forwarded_from": "calledvia2", "from": "+13051416798", "from_formatted": "(305) 141-6798", "group_sid": "GPdeadbeefdeadbeefdeadbeefdeadbeee", "parent_call_sid": "CAdeadbeefdeadbeefdeadbeefdeadbeee", "phone_number_sid": "PNdeadbeefdeadbeefdeadbeefdeadbeee", "price": "-0.100", "price_unit": "JPY", "sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0", "start_time": "Fri, 18 Oct 2019 16:02:00 +0000", "status": "completed", "subresource_uris": { "notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0/Notifications.json" } } ] } ``` -------------------------------- ### Initialize SIP Application Template Source: https://www.twilio.com/docs/voice/sip/quickstart.md Creates a new project directory using the sip-quickstart template. ```bash twilio serverless:init acme --template="sip-quickstart" ``` -------------------------------- ### Clone and install dependencies Source: https://www.twilio.com/docs/voice/sdks/react-native/reference-components.md Initializes the reference components project by cloning the repository and installing required packages. ```bash git clone https://github.com/twilio/twilio-voice-react-native-reference-components.git cd twilio-voice-react-native-reference-components npm install ``` -------------------------------- ### List Call Summaries Source: https://www.twilio.com/docs/voice/voice-insights/api/call/call-summaries-resource.md Examples of how to retrieve a list of call summaries filtered by carrier and start time. ```go // Download the helper library from https://www.twilio.com/docs/go/install package main import ( "fmt" "github.com/twilio/twilio-go" insights "github.com/twilio/twilio-go/rest/insights/v1" "os" ) func main() { // Find your Account SID and Auth Token at twilio.com/console // and set the environment variables. See http://twil.io/secure // Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment client := twilio.NewRestClient() params := &insights.ListCallSummariesParams{} params.SetToCarrier("AT&T Wireless") params.SetStartTime("4h") params.SetLimit(20) resp, err := client.InsightsV1.ListCallSummaries(params) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { for record := range resp { if resp[record].AccountSid != nil { fmt.Println(*resp[record].AccountSid) } else { fmt.Println(resp[record].AccountSid) } } } } ``` ```php insights->v1->callSummaries->read( [ "toCarrier" => "AT&T Wireless", "startTime" => "4h", ], 20, ); foreach ($callSummaries as $record) { print $record->accountSid; } ``` ```ruby # Download the helper library from https://www.twilio.com/docs/ruby/install require 'twilio-ruby' # Find your Account SID and Auth Token at twilio.com/console # and set the environment variables. See http://twil.io/secure account_sid = ENV['TWILIO_ACCOUNT_SID'] auth_token = ENV['TWILIO_AUTH_TOKEN'] @client = Twilio::REST::Client.new(account_sid, auth_token) call_summaries = @client .insights .v1 .call_summaries .list( to_carrier: 'AT&T Wireless', start_time: '4h', limit: 20 ) call_summaries.each do |record| puts record.account_sid end ``` -------------------------------- ### CLI and API Request Examples Source: https://www.twilio.com/docs/voice/sip/api/sip-credentiallistmapping-resource.md Command line and raw HTTP request examples for interacting with the resource. ```bash # Install the twilio-cli from https://twil.io/cli twilio api:core:sip:domains:auth:calls:credential-list-mappings:list \ --domain-sid SDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ``` ```bash curl -X GET "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/SIP/Domains/SDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Auth/Calls/CredentialListMappings.json?PageSize=20" \ -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN ``` -------------------------------- ### Query Calls with SDKs Source: https://www.twilio.com/docs/voice/api/call-resource.md Examples for filtering calls by status and start time using official Twilio helper libraries. ```csharp // Install the C# / .NET helper library from twilio.com/docs/csharp/install using System; using Twilio; using Twilio.Rest.Api.V2010.Account; using System.Threading.Tasks; class Program { public static async Task Main(string[] args) { // Find your Account SID and Auth Token at twilio.com/console // and set the environment variables. See http://twil.io/secure string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"); TwilioClient.Init(accountSid, authToken); var calls = await CallResource.ReadAsync( status: CallResource.StatusEnum.Completed, startTimeAfter: new DateTime(2009, 7, 6, 0, 0, 0, DateTimeKind.Utc), limit: 20); foreach (var record in calls) { Console.WriteLine(record.End); } } } ``` ```java // Install the Java helper library from twilio.com/docs/java/install import java.time.ZoneId; import java.time.ZonedDateTime; import com.twilio.Twilio; import com.twilio.rest.api.v2010.account.Call; import com.twilio.base.ResourceSet; public class Example { // Find your Account SID and Auth Token at twilio.com/console // and set the environment variables. See http://twil.io/secure public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID"); public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN"); public static void main(String[] args) { Twilio.init(ACCOUNT_SID, AUTH_TOKEN); ResourceSet calls = Call.reader() .setStatus(Call.Status.COMPLETED) .setStartTimeAfter(ZonedDateTime.of(2009, 7, 6, 0, 0, 0, 0, ZoneId.of("UTC"))) .limit(20) .read(); for (Call record : calls) { System.out.println(record.getEnd()); } } } ``` ```go // Download the helper library from https://www.twilio.com/docs/go/install package main import ( "fmt" "github.com/twilio/twilio-go" api "github.com/twilio/twilio-go/rest/api/v2010" "os" "time" ) func main() { // Find your Account SID and Auth Token at twilio.com/console // and set the environment variables. See http://twil.io/secure // Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment client := twilio.NewRestClient() params := &api.ListCallParams{} params.SetStatus("completed") params.SetStartTimeAfter(time.Date(2009, 7, 6, 0, 0, 0, 0, time.UTC)) params.SetLimit(20) resp, err := client.Api.ListCall(params) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { for record := range resp { if resp[record].End != nil { fmt.Println(*resp[record].End) } else { fmt.Println(resp[record].End) } } } } ``` ```php calls->read( [ "status" => "completed", "startTimeAfter" => new \DateTime("2009-07-06T00:00:00Z"), ], 20, ); foreach ($calls as $record) { print $record->end; } ``` ```ruby # Download the helper library from https://www.twilio.com/docs/ruby/install require 'twilio-ruby' # Find your Account SID and Auth Token at twilio.com/console # and set the environment variables. See http://twil.io/secure account_sid = ENV['TWILIO_ACCOUNT_SID'] auth_token = ENV['TWILIO_AUTH_TOKEN'] @client = Twilio::REST::Client.new(account_sid, auth_token) calls = @client .api .v2010 .calls .list( status: 'completed', start_time_after: Time.new(2009, 7, 6, 0, 0, 0), limit: 20 ) calls.each do |record| puts record.end end ``` -------------------------------- ### Initialize .NET Project Source: https://www.twilio.com/docs/voice/make-calls Commands to create a new .NET project and install the required Twilio NuGet package. ```bash mkdir make-call cd make-call dotnet new app dotnet add package Twilio ``` -------------------------------- ### Create a unidirectional Stream on a live call Source: https://www.twilio.com/docs/voice/api/stream-resource.md Implementation examples for starting a media stream using Node.js and Python SDKs. ```javascript // Download the helper library from https://www.twilio.com/docs/node/install const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio"; // Find your Account SID and Auth Token at twilio.com/console // and set the environment variables. See http://twil.io/secure const accountSid = process.env.TWILIO_ACCOUNT_SID; const authToken = process.env.TWILIO_AUTH_TOKEN; const client = twilio(accountSid, authToken); async function createStream() { const stream = await client .calls("CAXXXXXXXXXXXXXXXXXXXXXXXXXXX") .streams.create({ name: "My Media Stream", url: "wss://example.com/a-websocket-server", }); console.log(stream.sid); } createStream(); ``` ```python # Download the helper library from https://www.twilio.com/docs/python/install import os from twilio.rest import Client # Find your Account SID and Auth Token at twilio.com/console # and set the environment variables. See http://twil.io/secure account_sid = os.environ["TWILIO_ACCOUNT_SID"] auth_token = os.environ["TWILIO_AUTH_TOKEN"] client = Client(account_sid, auth_token) stream = client.calls("CAXXXXXXXXXXXXXXXXXXXXXXXXXXX").streams.create( name="My Media Stream", url="wss://example.com/a-websocket-server" ) print(stream.sid) ``` -------------------------------- ### Configure environment variables Source: https://www.twilio.com/docs/voice/sdks/javascript/reference-components.md Example .env file configuration for the reference components. ```text # Port number to run the server on PORT=3030 # Twilio account sid ACCOUNT_SID=ACxxxxxxxxxxxxxx # Twilio API key API_KEY_SID=SKxxxxxxxxxxxxxx # Twilio API secret API_KEY_SECRET=xxxxxxxxxxxxxx # Twilio TwiML App SID # The Voice Request URL must point to one of the /twiml endpoints listed later in this guide. # For details, see https://www.twilio.com/docs/voice/sdks/javascript#twiml-applications APP_SID=APxxxxxxxxxxxxxx # Twilio auth token AUTH_TOKEN=xxxxxxxxxxxxxx # Caller ID CALLER_ID=+11234567890 # Public base URL that Twilio can reach. # If you run the components locally, use a tunneling service such as ngrok. # Do not include the scheme (https:// or wss://) in the URL. CALLBACK_BASE_URL=foo.ngrok.dev # Default identity to use DEFAULT_IDENTITY=alice # twilio-voice-ai-conversation # See https://platform.openai.com/settings/organization/api-keys OPENAI_API_KEY="sk-proj......." ``` -------------------------------- ### Configure inboundTrackLabel across languages Source: https://www.twilio.com/docs/voice/twiml/transcription.md Examples of setting inbound and outbound track labels within a TwiML Start Transcription block. ```js const VoiceResponse = require('twilio').twiml.VoiceResponse; const response = new VoiceResponse(); const start = response.start(); start.transcription({ statusCallbackUrl: 'https://example.com/your-callback-url', inboundTrackLabel: 'agent', outboundTrackLabel: 'customer', }); console.log(response.toString()); ``` ```py from twilio.twiml.voice_response import VoiceResponse, Start, Transcription response = VoiceResponse() start = Start() start.transcription( status_callback_url='https://example.com/your-callback-url', inbound_track_label='agent', outbound_track_label='customer') response.append(start) print(response) ``` ```cs using System; using Twilio.TwiML; using Twilio.TwiML.Voice; class Example { static void Main() { var response = new VoiceResponse(); var start = new Start(); start.Transcription(statusCallbackUrl: "https://example.com/your-callback-url", inboundTrackLabel: "agent", outboundTrackLabel: "customer"); response.Append(start); Console.WriteLine(response.ToString()); } } ``` ```java import com.twilio.twiml.VoiceResponse; import com.twilio.twiml.voice.Start; import com.twilio.twiml.voice.Transcription; import com.twilio.twiml.TwiMLException; public class Example { public static void main(String[] args) { Transcription transcription = new Transcription.Builder().statusCallbackUrl("https://example.com/your-callback-url").inboundTrackLabel("agent").outboundTrackLabel("customer").build(); Start start = new Start.Builder().transcription(transcription).build(); VoiceResponse response = new VoiceResponse.Builder().start(start).build(); try { System.out.println(response.toXml()); } catch (TwiMLException e) { e.printStackTrace(); } } } ``` ```go package main import ( "fmt" "github.com/twilio/twilio-go/twiml" ) func main() { twiml, _ := twiml.Voice([]twiml.Element{ &twiml.VoiceStart{ InnerElements: []twiml.Element{ &twiml.VoiceTranscription{ InboundTrackLabel: "agent", OutboundTrackLabel: "customer", StatusCallbackUrl: "https://example.com/your-callback-url", }, }, }, }) fmt.Print(twiml) } ``` ```php start(); $start->transcription(['statusCallbackUrl' => 'https://example.com/your-callback-url', 'inboundTrackLabel' => 'agent', 'outboundTrackLabel' => 'customer']); echo $response; ``` ```rb require 'twilio-ruby' response = Twilio::TwiML::VoiceResponse.new response.start do |start| start.transcription(status_callback_url: 'https://example.com/your-callback-url', inbound_track_label: 'agent', outbound_track_label: 'customer') end puts response ``` ```xml ``` -------------------------------- ### Basic implementation Source: https://www.twilio.com/docs/voice/twiml/refer.md Examples showing how to initiate a SIP transfer using the verb across various programming languages. ```js const VoiceResponse = require('twilio').twiml.VoiceResponse; const response = new VoiceResponse(); const refer = response.refer(); refer.sip('sip:alice@example.com'); console.log(response.toString()); ``` ```py from twilio.twiml.voice_response import Refer, VoiceResponse response = VoiceResponse() refer = Refer() refer.sip('sip:alice@example.com') response.append(refer) print(response) ``` ```cs using System; using Twilio.TwiML; using Twilio.TwiML.Voice; class Example { static void Main() { var response = new VoiceResponse(); var refer = new Refer(); refer.Sip(new Uri("sip:alice@example.com")); response.Append(refer); Console.WriteLine(response.ToString()); } } ``` ```java import com.twilio.twiml.voice.Refer; import com.twilio.twiml.voice.ReferSip; import com.twilio.twiml.VoiceResponse; import com.twilio.twiml.TwiMLException; public class Example { public static void main(String[] args) { ReferSip refersip = new ReferSip.Builder("sip:alice@example.com") .build(); Refer refer = new Refer.Builder().sip(refersip).build(); VoiceResponse response = new VoiceResponse.Builder().refer(refer) .build(); try { System.out.println(response.toXml()); } catch (TwiMLException e) { e.printStackTrace(); } } } ``` ```go package main import ( "fmt" "github.com/twilio/twilio-go/twiml" ) func main() { twiml, _ := twiml.Voice([]twiml.Element{ &twiml.VoiceRefer{ InnerElements: []twiml.Element{ &twiml.VoiceSip{ SipUrl: "sip:alice@example.com", }, }, }, }) fmt.Print(twiml) } ``` ```php refer(); $refer->sip('sip:alice@example.com'); echo $response; ``` ```rb require 'twilio-ruby' response = Twilio::TwiML::VoiceResponse.new response.refer do |refer| refer.sip('sip:alice@example.com') end puts response ``` ```xml sip:alice@example.com ``` -------------------------------- ### Initialize Ruby Project Source: https://www.twilio.com/docs/voice/quickstart/server.md Commands to initialize a Gemfile and install necessary dependencies. ```bash bundle init ``` ```bash bundle add puma twilio-ruby sinatra ```