public virtual void Dispose() { TelnyxConfiguration.SetApiBase(this.origApiBase); TelnyxConfiguration.SetApiKey(this.origApiKey); TelnyxMockHandler.StopTelnyxMock(); }
public TelnyxMockFixture() { if (TelnyxMockHandler.StartTelnyxMock()) { this.port = TelnyxMockHandler.Port.ToString(); } else { this.port = Environment.GetEnvironmentVariable("TELNYX_MOCK_PORT") ?? "12111"; } IConfiguration config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build(); this.telnyx_api_key = config["TelnyxApiKey"]; if (string.IsNullOrEmpty(this.telnyx_api_key)) { this.telnyx_api_key = Environment.GetEnvironmentVariable("TelnyxApiKey"); } else { Environment.SetEnvironmentVariable("TelnyxApiKey", this.telnyx_api_key); } this.EnsureTelnyxMockMinimumVersion(); this.origApiBase = TelnyxConfiguration.GetApiBase(); this.origApiKey = TelnyxConfiguration.GetApiKey(); TelnyxConfiguration.SetApiBase($"http://localhost:{this.port}/v2"); TelnyxConfiguration.SetApiKey(this.telnyx_api_key); }
/// <summary> /// GetRequestMessage. /// </summary> /// <param name="url">url.</param> /// <param name="method">method.</param> /// <param name="requestOptions">requestOptions.</param> /// <returns>http request message.</returns> public static HttpRequestMessage GetRequestMessage(string url, HttpMethod method, RequestOptions requestOptions) { requestOptions.ApiKey = requestOptions.ApiKey ?? TelnyxConfiguration.GetApiKey(); var request = BuildRequest(method, url); request.Headers.Add( "Authorization", GetAuthorizationHeaderValue(requestOptions.ApiKey)); if (requestOptions.IdempotencyKey != null) { request.Headers.Add("Idempotency-Key", requestOptions.IdempotencyKey); } if (requestOptions.TelnyxVersion != null) { request.Headers.Add("Telnyx-Version", requestOptions.TelnyxVersion); } else { request.Headers.Add("Telnyx-Version", TelnyxConfiguration.TelnyxApiVersion); } var client = new Client(request); client.ApplyUserAgent(); client.ApplyClientData(); return(request); }
public async Task <IActionResult> Post(object messageBody) { // Deserialize incoming message dynamic message = JsonConvert.DeserializeObject(messageBody.ToString()); EventType eventType = ToEnum <EventType>(message.data.event_type.ToString()); // Respond only to received messages, not status updates if (eventType == EventType.MessageReceived) { // Determing how to repond to sender string responseText; switch (message.data.payload.text.ToString().ToLower()) { case "pizza": responseText = "Chicago pizza is the best"; break; case "ice cream": responseText = "I prefer gelato"; break; default: responseText = "Please send either the word ‘pizza’ or ‘ice cream’ for a different response"; break; } // Create return message string to = message.data.payload.to[0].phone_number; string from = message.data.payload.from.phone_number; TelnyxConfiguration.SetApiKey(TELNYX_API_KEY); NewMessagingSenderId options = new NewMessagingSenderId { From = to, To = from, Text = responseText }; // Send message back to sender MessagingSenderIdService service = new MessagingSenderIdService(); try { MessagingSenderId messageResponse = await service.CreateAsync(options); Logger.LogInformation($"Sent message with ID: {messageResponse.Id}"); } catch (TelnyxException ex) { Logger.LogInformation(ex.Message); } } return(Ok()); }
static async Task Main(string[] args) { Console.WriteLine("Starting Examples..."); IConfiguration config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build() .LoadAppSettingsIntoEnvironmentVariables(); TelnyxConfiguration.SetApiBase($"https://api.telnyx.com/v2"); TelnyxConfiguration.SetApiKey(config["TelnyxApiKey"]); Console.WriteLine("MessagesExample..."); MessagesExample messagesExample = new MessagesExample(); await messagesExample.SendMessage(); messagesExample.RetrieveMessage(); Console.WriteLine("MessagingProfilesExample..."); MessagingProfilesExample messagingProfilesExample = new MessagingProfilesExample(); messagingProfilesExample.List(); messagingProfilesExample.ListAllMessagingProfilePhoneNumbers(); messagingProfilesExample.Create(); messagingProfilesExample.Update(); messagingProfilesExample.Delete(); Console.WriteLine("NumberOrderExample..."); NumberOrderExample numberOrderExample = new NumberOrderExample(); numberOrderExample.ListNumberOrder(); numberOrderExample.CreateNumberOrder(); Console.WriteLine("NumberReservationExample..."); NumberReservationExample numberReservationExample = new NumberReservationExample(); numberReservationExample.CreateNumberReservation(); numberReservationExample.ListNumberReservation(); Console.WriteLine("NumberSearchExample..."); NumberSearchExample numberSearchExample = new NumberSearchExample(); numberSearchExample.ListNumberService(); Console.WriteLine("PhoneNumbersExample..."); PhoneNumbersExample phoneNumbersExample = new PhoneNumbersExample(); phoneNumbersExample.GetPhoneNumber(); phoneNumbersExample.ListNumberOrder(); phoneNumbersExample.UpdatePhoneNumber(); }
static async Task Main(string[] args) { Console.WriteLine("Starting Examples..."); IConfiguration config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build() .LoadAppSettingsIntoEnvironmentVariables(); TelnyxConfiguration.SetApiBase("https://api.telnyx.com/v2"); TelnyxConfiguration.SetApiKey(config["TelnyxApiKey"]); Console.WriteLine("MessagesExample..."); MessagesExample messagesExample = new MessagesExample(); await messagesExample.SendMessage(); messagesExample.RetrieveMessage(); Console.WriteLine("MessagingProfilesExample..."); MessagingProfilesExample messagingProfilesExample = new MessagingProfilesExample(); messagingProfilesExample.ListPaged(); messagingProfilesExample.List(); messagingProfilesExample.ListAllMessagingProfilePhoneNumbers(); messagingProfilesExample.Create(); messagingProfilesExample.Update(); messagingProfilesExample.Delete(); Console.WriteLine("MessagingProfilesMetricsExample..."); //Optional add your own messaging profile ID await messagingProfilesExample.GetDetailAsync(); await messagingProfilesExample.ListOverviewAsync(); Console.WriteLine("NumberOrderExample..."); NumberOrderExample numberOrderExample = new NumberOrderExample(); numberOrderExample.ListNumberOrder(); numberOrderExample.CreateNumberOrder(); Console.WriteLine("NumberReservationExample..."); NumberReservationExample numberReservationExample = new NumberReservationExample(); numberReservationExample.CreateNumberReservation(); numberReservationExample.ListNumberReservation(); Console.WriteLine("NumberSearchExample..."); NumberSearchExample numberSearchExample = new NumberSearchExample(); numberSearchExample.ListNumberService(); numberSearchExample.ListNumberServicePaged(); Console.WriteLine("PhoneNumbersExample..."); PhoneNumbersExample phoneNumbersExample = new PhoneNumbersExample(); phoneNumbersExample.GetPhoneNumber(); phoneNumbersExample.ListNumberOrder(); phoneNumbersExample.UpdatePhoneNumber(); Console.WriteLine("CallControlExample..."); CallControlExample callControlExample = new CallControlExample(); callControlExample.Dial(); callControlExample.SetCallControlId("v2:ZKoCq-ggJPRhO3H9KxQa5zVQphVX8Hx9d_FRl2b-W2dQfVUHfhe13g"); callControlExample.Speak(); callControlExample.Bridge(); callControlExample.ForkingStart(); callControlExample.ForkingStop(); callControlExample.GatherUsingAudio(); callControlExample.GatherUsingSpeak(); callControlExample.Hangup(); callControlExample.PlaybackStart(); callControlExample.PlaybackStop(); callControlExample.RecordStart(); callControlExample.RecordStop(); callControlExample.Reject(); callControlExample.SendDTMF(); callControlExample.Transfer(); Console.WriteLine("ConferenceCommandsExample..."); ConferenceCommandsExample conferenceCommandsExample = new ConferenceCommandsExample(); conferenceCommandsExample.SetCallControlId("v2:ZKoCq-ggJPRhO3H9KxQa5zVQphVX8Hx9d_FRl2b-W2dQfVUHfhe13g"); conferenceCommandsExample.Create(); conferenceCommandsExample.List(); Console.WriteLine("NumberConfigurationExample.."); NumberConfigurationExample numConfigExample = new NumberConfigurationExample(); await numConfigExample.ListPhoneNumbersWithPagingAsync(); await numConfigExample.ListPhoneNumbersWithFiltersAsync(); await numConfigExample.ListMessagingOptionsAsync(); await numConfigExample.ListVoiceSettingsWithFiltersAsync(); Console.WriteLine("CallControlApplicationExample..."); CallControlApplicationsExample callControlApplicationsExample = new CallControlApplicationsExample(); callControlApplicationsExample.List(); callControlApplicationsExample.Create(); callControlApplicationsExample.Get(); callControlApplicationsExample.Delete(); callControlApplicationsExample.Update(); Console.WriteLine("OutboundVoiceProfilesExample..."); OutboundVoiceProfilesExample outboundVoiceProfilesExample = new OutboundVoiceProfilesExample(); outboundVoiceProfilesExample.List(); outboundVoiceProfilesExample.Create(); outboundVoiceProfilesExample.Get(); outboundVoiceProfilesExample.Delete(); outboundVoiceProfilesExample.Update(); Console.WriteLine("Connections Example...."); ConnectionsExample connectionsExample = new ConnectionsExample(); await connectionsExample.ListConnectionsAsync(); await connectionsExample.ListCredConnectionsAsync(); await connectionsExample.ListIPConnectionsAsync(); await connectionsExample.ListIPsAsync(); await connectionsExample.ListFQDNConnectionsAsync(); await connectionsExample.ListFQDNsAsync(); Console.WriteLine("NumberLookupExample..."); NumberLookupExample numberLookupExample = new NumberLookupExample(); numberLookupExample.Get(); await numberLookupExample.GetAsync(); Console.WriteLine("MobileOperatorNetworksExample..."); MobileOperatorNetworksExample mobileOperatorNetworksExample = new MobileOperatorNetworksExample(); mobileOperatorNetworksExample.List(); await mobileOperatorNetworksExample.ListAsync(); Console.WriteLine("OTAUpdatesExample..."); OTAUpdatesExample oTAUpdatesExample = new OTAUpdatesExample(); oTAUpdatesExample.Get(); await oTAUpdatesExample.GetAsync(); oTAUpdatesExample.List(); await oTAUpdatesExample.ListAsync(); Console.WriteLine("WDRReportsExample..."); WDRReportsExample wDRReportsExample = new WDRReportsExample(); wDRReportsExample.Get(); await wDRReportsExample.GetAsync(); wDRReportsExample.List(); await wDRReportsExample.ListAsync(); wDRReportsExample.Create(); await wDRReportsExample.CreateAsync(); wDRReportsExample.Delete(); await wDRReportsExample.DeleteAsync(); Console.WriteLine("SimCardsExample..."); SimCardsExample simCardsExample = new SimCardsExample(); simCardsExample.Get(); await simCardsExample.GetAsync(); simCardsExample.List(); await simCardsExample.ListAsync(); simCardsExample.Delete(); await simCardsExample.DeleteAsync(); simCardsExample.Enable(); await simCardsExample.EnableAsync(); simCardsExample.Disable(); await simCardsExample.DisableAsync(); simCardsExample.Register(); await simCardsExample.RegisterAsync(); simCardsExample.BulkUpdateNetworkPreference(); await simCardsExample.BulkUpdateNetworkPreferenceAsync(); simCardsExample.GetNetworkPreference(); await simCardsExample.GetNetworkPreferenceAsync(); simCardsExample.SetNetworkPreference(); await simCardsExample.SetNetworkPreferenceAsync(); simCardsExample.DeleteNetworkPreference(); await simCardsExample.DeleteNetworkPreferenceAsync(); Console.WriteLine("Start Webhook Example...."); await ReceiveAndHandleWebhook(); Console.WriteLine("TelephonyCredentialExample..."); TelephonyCredentialExample telephonyCredentialExample = new TelephonyCredentialExample(); telephonyCredentialExample.Get(); await telephonyCredentialExample.GetAsync(); telephonyCredentialExample.List(); await telephonyCredentialExample.ListAsync(); telephonyCredentialExample.Create(); await telephonyCredentialExample.CreateAsync(); telephonyCredentialExample.Update(); await telephonyCredentialExample.UpdateAsync(); telephonyCredentialExample.Delete(); await telephonyCredentialExample.DeleteAsync(); telephonyCredentialExample.GetToken(); await telephonyCredentialExample.GetTokenAsync(); Console.WriteLine("2FA Verification Example..."); var verificationExample = new VerificationExample(); await verificationExample.RunVerification(); Console.WriteLine("Fax Example..."); var faxExample = new FaxExample(); faxExample.ReceiveWebhook(); Console.WriteLine("HostedNumber Orders Example..."); var hostedExample = new HostedNumbersExample(); await hostedExample.CreatedHostedNumberAsync(new List <string> { "+17735556766" }); /*Only call with your credentials*/ //GetWebhook(); }