### C#: Connect to ConversationRelay with Parameters Source: https://www.twilio.com/docs/voice/twiml/connect/conversationrelay Implement this C# example to connect to the ConversationRelay service and pass custom parameters for the WebSocket setup. ```csharp using System; using Twilio.TwiML; using Twilio.TwiML.Voice; class Example { static void Main() { var response = new VoiceResponse(); var connect = new Connect(); var conversationrelay = new ConversationRelay(url: "wss://mywebsocketserver.com/websocket"); conversationrelay.Parameter(name: "foo", value: "bar"); conversationrelay.Parameter(name: "hint", value: "Annoyed customer"); connect.Append(conversationrelay); response.Append(connect); Console.WriteLine(response.ToString()); } } ``` -------------------------------- ### Install and Use Twilio CLI for Serverless Projects Source: https://www.twilio.com/docs/serverless/functions-assets These commands guide you through installing the Twilio CLI and its Serverless plugin, initializing a new project from a template, and deploying it. This is useful for quickly bootstrapping and deploying serverless applications. ```bash # Install the Twilio CLI npm install -g twilio-cli # Install the Serverless plugin twilio plugins:install @twilio-labs/plugin-serverless # Initialize a new project based off of a pre-configured # template and configure it twilio serverless:init example --template=hello-messaging cd example # Deploy your app in seconds! twilio serverless:deploy ``` -------------------------------- ### Make a Call - Go Source: https://www.twilio.com/docs/voice Initiate a phone call using the Twilio Go helper library. This example shows how to create a new REST client and set parameters for making a call. ```APIDOC ## Make a Call - Go ### Description Initiate a phone call using the Twilio Go helper library. This example shows how to create a new REST client and set parameters for making a call. ### Method client.Api.CreateCall() ### Parameters - **from** (string) - Required - The phone number to use as the caller ID. - **to** (string) - Required - The phone number to call. - **url** (string) - Required - The URL that Twilio will request when the call is answered, containing TwiML instructions. ### Request Example ```go params := &api.CreateCallParams{} params.SetFrom("+15558675310") params.SetTo("+15017122661") params.SetUrl("http://demo.twilio.com/docs/voice.xml") resp, err := client.Api.CreateCall(params) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { if resp.Sid != nil { fmt.Println(*resp.Sid) } else { fmt.Println(resp.Sid) } } ``` ### Response #### Success Response (200) - **Sid** (string) - The unique ID of the created call. ``` -------------------------------- ### Make a Call - Python Source: https://www.twilio.com/docs/voice Initiate a phone call using the Twilio Python helper library. This example demonstrates setting up the client and creating a call to a specified number, with a URL for TwiML instructions. ```APIDOC ## Make a Call - Python ### Description Initiate a phone call using the Twilio Python helper library. This example demonstrates setting up the client and creating a call to a specified number, with a URL for TwiML instructions. ### Method client.calls.create() ### Parameters - **from** (string) - Required - The phone number to use as the caller ID. - **to** (string) - Required - The phone number to call. - **url** (string) - Required - The URL that Twilio will request when the call is answered, containing TwiML instructions. ### Request Example ```python call = client.calls.create( from_="+15558675310", to="+15017122661", url="http://demo.twilio.com/docs/voice.xml", ) print(call.sid) ``` ### Response #### Success Response (200) - **sid** (string) - The unique ID of the created call. ``` -------------------------------- ### Make a Call - C# Source: https://www.twilio.com/docs/voice Initiate a phone call using the Twilio C# helper library. This example shows how to initialize the Twilio client and asynchronously create a call. ```APIDOC ## Make a Call - C# ### Description Initiate a phone call using the Twilio C# helper library. This example shows how to initialize the Twilio client and asynchronously create a call. ### Method CallResource.CreateAsync() ### Parameters - **from** (PhoneNumber) - Required - The phone number to use as the caller ID. - **to** (PhoneNumber) - Required - The phone number to call. - **url** (Uri) - Required - The URL that Twilio will request when the call is answered, containing TwiML instructions. ### Request Example ```csharp var call = await CallResource.CreateAsync( from: new Twilio.Types.PhoneNumber("+15558675310"), to: new Twilio.Types.PhoneNumber("+15017122661"), url: new Uri("http://demo.twilio.com/docs/voice.xml")); Console.WriteLine(call.Sid); ``` ### Response #### Success Response (200) - **Sid** (string) - The unique ID of the created call. ``` -------------------------------- ### Fetch Phone Number Line Type Intelligence in Ruby Source: https://www.twilio.com/docs/lookup/quickstart This Ruby example shows how to retrieve line type intelligence for a phone number. Install the twilio-ruby helper library and set your TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN environment variables. ```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) phone_number = @client .lookups .v2 .phone_numbers('+14159929960') .fetch(fields: 'line_type_intelligence') puts phone_number.line_type_intelligence ``` -------------------------------- ### Make a Call - PHP Source: https://www.twilio.com/docs/voice Initiate a phone call using the Twilio PHP helper library. This example demonstrates initializing the client and creating a call with specified 'to', 'from', and 'url' parameters. ```APIDOC ## Make a Call - PHP ### Description Initiate a phone call using the Twilio PHP helper library. This example demonstrates initializing the client and creating a call with specified 'to', 'from', and 'url' parameters. ### Method $twilio->calls->create() ### Parameters - **to** (string) - Required - The phone number to call. - **from** (string) - Required - The phone number to use as the caller ID. - **url** (string) - Required - The URL that Twilio will request when the call is answered, containing TwiML instructions. ### Request Example ```php $call = $twilio->calls->create( "+15017122661", // To "+15558675310", // From ["url" => "http://demo.twilio.com/docs/voice.xml"] ); print $call->sid; ``` ### Response #### Success Response (200) - **sid** (string) - The unique ID of the created call. ``` -------------------------------- ### Fetch Phone Number Line Type Intelligence in Go Source: https://www.twilio.com/docs/lookup/quickstart This Go example shows how to get line type intelligence for a phone number. Download the Twilio Go helper library and set your TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN environment variables. ```go // Download the helper library from https://www.twilio.com/docs/go/install package main import ( "fmt" "github.com/twilio/twilio-go" lookups "github.com/twilio/twilio-go/rest/lookups/v2" "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 := &lookups.FetchPhoneNumberParams{} params.SetFields("line_type_intelligence") resp, err := client.LookupsV2.FetchPhoneNumber("+14159929960", params) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { if resp.LineTypeIntelligence != (lookups.LineTypeIntelligenceInfo{}) { fmt.Println(resp.LineTypeIntelligence) } else { fmt.Println(resp.LineTypeIntelligence) } } } ``` -------------------------------- ### Make a Call - Java Source: https://www.twilio.com/docs/voice Initiate a phone call using the Twilio Java helper library. This example demonstrates initializing the Twilio client and creating a call. ```APIDOC ## Make a Call - Java ### Description Initiate a phone call using the Twilio Java helper library. This example demonstrates initializing the Twilio client and creating a call. ### Method Call.creator().create() ### Parameters - **to** (PhoneNumber) - Required - The phone number to call. - **from** (PhoneNumber) - Required - The phone number to use as the caller ID. - **url** (URI) - Required - The URL that Twilio will request when the call is answered, containing TwiML instructions. ### Request Example ```java Call call = Call.creator(new com.twilio.type.PhoneNumber("+15017122661"), new com.twilio.type.PhoneNumber("+15558675310"), URI.create("http://demo.twilio.com/docs/voice.xml")) .create(); System.out.println(call.getSid()); ``` ### Response #### Success Response (200) - **sid** (string) - The unique ID of the created call. ``` -------------------------------- ### Develop and Run Twilio Serverless App Locally Source: https://www.twilio.com/docs/serverless/functions-assets This sequence installs the Twilio CLI and Serverless plugin, initializes a new project, and starts a local development server. It's the recommended approach for developing and testing your serverless application before deployment. ```bash # Install the Twilio CLI npm install -g twilio-cli # Install the Serverless plugin twilio plugins:install @twilio-labs/plugin-serverless # Initialize a new project with the name my-app twilio serverless:init my-app cd my-app # Now you're ready to develop and interact with your app locally! twilio serverless:start ``` -------------------------------- ### Go: Connect to ConversationRelay with Parameters Source: https://www.twilio.com/docs/voice/twiml/connect/conversationrelay This Go program shows how to configure a ConversationRelay connection with custom parameters, which will be sent in the WebSocket setup message. ```go package main import ( "fmt" "github.com/twilio/twilio-go/twiml" ) func main() { twiml, _ := twiml.Voice([]twiml.Element{ &twiml.VoiceConnect{ InnerElements: []twiml.Element{ &twiml.VoiceConversationRelay{ InnerElements: []twiml.Element{ &twiml.VoiceParameter{ Name: "foo", Value: "bar", }, &twiml.VoiceParameter{ Name: "hint", Value: "Annoyed customer", }, }, }, }, }, }) fmt.Print(twiml) } ```